Make new random effect terms for prediction
mkNewReTrms.Rd
Rebuilds the random effect terms
Arguments
- object
a fitted
merMod
object- newdata
data frame for which to create new RE terms object
- re.form
(formula,
NULL
, orNA
) specify which random effects to condition on when predicting. IfNULL
, include all random effects; ifNA
or~0
, include no random effects- na.action
function determining what should be done with missing values for fixed effects in
newdata
- allow.new.levels
(logical) if new levels (or NA values) in
newdata
are allowed. If FALSE (default), such new values innewdata
will trigger an error; if TRUE, then the prediction will use the unconditional (population-level) values for data with previously unobserved levels (or NAs)- sparse
generate sparse contrast matrices?
Value
a list
with components
- Zt
transpose of the sparse model matrix for the random effects
- theta
initial values of the covariance parameters
- Lind
an integer vector of indices determining the mapping of the elements of the
theta
vector to the"x"
slot ofLambdat
- Gp
a vector indexing the association of elements of the conditional mode vector with random-effect terms; if
nb
is the vector of numbers of conditional modes per term (i.e. number of groups times number of effects per group),Gp
isc(0,cumsum(nb))
(and converselynb
isdiff(Gp)
)- lower
lower bounds on the covariance parameters
- Lambdat
transpose of the sparse relative covariance factor
- flist
list of grouping factors used in the random-effects terms
- cnms
a list of column names of the random effects according to the grouping factors
- Ztlist
list of components of the transpose of the random-effects model matrix, separated by random-effects term
- nl
names of the terms (in the same order as
Zt
, i.e. reflecting thereorder.terms
argument)
Note
mkNewReTrms
is used in the context of prediction, to
generate a new "random effects terms" object from an already fitted
model
Examples
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
nd <- data.frame(Days = 5, Subject = "new")
try(mkNewReTrms(fm1, newdata = nd))
#> Error in levelfun(r, n, allow.new.levels = allow.new.levels) :
#> new levels detected in newdata: new
t1 <- mkNewReTrms(fm1, newdata = nd, allow.new.levels = TRUE)