dwmw {trouBBlme4SolveR} | R Documentation |
Solver for (generalized) linear MM warnings
Description
Updates a (possibly generalized) linear mixed model computed with the
library lme4 functions lmer
or glmer
, in order to
elude some singularity or convergence problems informed by distinct
warnings or messages.
Usage
dwmw(lmmodel,
boundary_check = TRUE, scale = FALSE, scale_info = TRUE,
tol = 1e-4, max_message_iter = 7, max_nAGQ = 6,
next_optimizer = "bobyqa", next_optCtrl = list(maxfun = 2e5),
when_next = max_message_iter - 1, verbose = FALSE)
Arguments
lmmodel |
The model of interest, output of either
|
boundary_check |
A length 1 boolean object ( |
scale |
A length 1 boolean object ( |
scale_info |
A length 1 boolean object ( |
tol |
A numeric value (default is |
max_message_iter |
A numeric value (default is |
max_nAGQ |
A numeric value (default is |
next_optimizer |
An optimizer (default is |
next_optCtrl |
A |
when_next |
A numeric value not greater than
|
verbose |
A length 1 boolean object ( |
specifying if function iterations and model updating should be verbose.
Details
If the model does not generate any warning or message, dwmw
returns itself. The function rescales numeric predictors if some
warning or message suggests it and the scale
argument is
TRUE
. If the model fails to converge, it only updates the starting
values for the parameters in the model through the first
when_next - 1
iterations, while it also updates the optimizer
and their arguments through the next iterations.
If the model is singular (there is a
"boundary (singular)"-alike message) and boundary_check
is TRUE
, the formula is updated removing the random effects
which cause the model to be singular. If all the random effects are
removed, a linear or generalized linear model is computed according to
the lmmodel
object.
If the model has subclass glmerMod
, a single scalar random
effect and converges but it is nearly unidentifiable with a very large
eigenvalue, then nAGQ
is increased one unity while nAGQ
<= max_nAGQ
(and only in this case, allowing the iterations to exceed
max_message_iter
until nAGQ == max_nAGQ
).
Value
Generally, an object of class
merMod
, being either an object of
subclass glmerMod
or an object of subclass
lmerMod
, corresponding to the input lmmodel
argument. When all random effects are removed, an object of
class glm
or lm
depending also on the input
lmmodel
.
Author(s)
Iago Giné-Vázquez, iago.gin-vaz@protonmail.com
See Also
lmer
, glmer
,
merMod
lmerControl
,
convergence
, troubleshooting
,
isSingular
, lm
and
glm
.
Examples
if(requireNamespace("nlme")){
library(lme4)
data(Orthodont, package = "nlme")
Orthodont$nsex <- as.numeric(Orthodont$Sex == "Male")
Orthodont$nsexage <- with(Orthodont, nsex*age)
## Without using dwmw, the next model is singular
fmo <- lmer(distance ~ age + (age|Subject) + (0+nsex|Subject) +
(0 + nsexage|Subject), data = Orthodont)
summary(fmo)
## Using dwmw, we remove the singularity of the model
fmo1 <- dwmw(lmer(distance ~ age + (age|Subject) + (0+nsex|Subject) +
(0 + nsexage|Subject), data = Orthodont))
summary(fmo1)
## It also can be used on the output object
fmo2 <- dwmw(fmo)
summary(fmo2)
}