Skip to content

Commit

Permalink
better error message for matrix-valued responses
Browse files Browse the repository at this point in the history
  • Loading branch information
bbolker committed Oct 8, 2023
1 parent 1544665 commit 53b54e6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions R/modular.R
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ lFormula <- function(formula, data=NULL, REML = TRUE,
}
mf$formula <- fr.form
fr <- eval(mf, parent.frame())
if (is.matrix(y <- model.response(fr)) && ncol(y) > 1) {
stop("can't handle matrix-valued responses: consider using refit()")
}
if (nrow(fr) == 0L) stop("0 (non-NA) cases")
## convert character vectors to factor (defensive)
fr <- factorize(fr.form, fr, char.only=TRUE)
Expand Down
21 changes: 15 additions & 6 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@
\title{lme4 News}
\encoding{UTF-8}

\section{CHANGES IN VERSION 1.1-35 (2023-07-04}{
\section{CHANGES IN VERSION 1.1-35}{
\subsection{NEW FEATURES}{
\item \code{predict.merMod} now has a \code{se.fit} method, which
computes the standard errors of the predictions, conditional on the
estimated \code{theta} (variance-covariance) parameters
}
\itemize{
\item \code{predict.merMod} now has a \code{se.fit} method, which
computes the standard errors of the predictions, conditional on the
estimated \code{theta} (variance-covariance) parameters
}
} % new features
\subsection{USER-VISIBLE CHANGES}{
\itemize{
\item using \code{lmer} with a matrix-valued response now throws
a more informative error message, directing the user to
\code{?refit}
}
} % user-visible changes
} % 1.1-35

\section{CHANGES IN VERSION 1.1-34 (2023-07-04}{
\section{CHANGES IN VERSION 1.1-34 (2023-07-04)}{
\subsection{BUG FIXES}{
\itemize{
\item \code{summary(<merMod>)} now records if \code{correlation} was
Expand Down
2 changes: 1 addition & 1 deletion man/refit.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fit1 <- lmer(y ~ x+(1|f), data = d,
control= lmerControl(check.conv.grad="ignore",
check.conv.hess="ignore"))
## combine fit to first response with fits to remaining responses
res <- c(fit1,lapply(as.data.frame(Y[,-1]), refit, object=fit1))
res <- c(fit1, lapply(as.data.frame(Y[,-1]), refit, object=fit1))

## Ex. 2: refitting simulated data using data that contain NA values ------
sleepstudyNA <- sleepstudy
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-lmer.R
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,10 @@ test_that("test for zero non-NA cases", {
expect_error(lmer(Reaction ~ Days + (1| Subject), data_bad),
"0 \\(non-NA\\) cases")
})

##
test_that("catch matrix-valued responses", {
dd <- data.frame(x = rnorm(1000), batch = factor(rep(1:20, each=50)))
dd$y <- matrix(rnorm(1e4), ncol = 10)
expect_error(lmer(y ~ x + (1|batch), dd), "matrix-valued")
})

0 comments on commit 53b54e6

Please sign in to comment.