[R-sig-ME] Problem specifying uncorrelated random intercepts and slopes for a multi-df covariate
Ben Bolker
bbo|ker @end|ng |rom gm@||@com
Wed Aug 3 21:15:26 CEST 2022
From the help file (help("||", package = "lme4"):
Because ‘||’ works at the level of formula parsing, it has no way
of knowing whether a variable is a factor. It just takes the terms
within a random-effects term and literally splits them into the
intercept and separate no-intercept terms, e.g. ‘(1+x+y|f)’ would
be split into ‘(1|f) + (0+x|f) + (0+y|f)’. However, ‘||’ will
fail to break up factors into separate terms; the ‘dummy’ function
can be useful in this case, although it is not as convenient as
‘||’.
afex::lmer_alt() may do what you want:
‘lmer_alt’ is simply a wrapper for mixed that only returns the
‘"lmerModLmerTest"’ or ‘"merMod"’ object and correctly uses the
‘||’ notation for removing correlations among factors. This
function otherwise behaves like ‘g/lmer’ (as for ‘mixed’, it calls
‘glmer’ as soon as a ‘family’ argument is present). Use
‘afex_options’‘("lmer_function")’ to set which function for
estimation should be used. This option determines the class of the
returned object (i.e., ‘"lmerModLmerTest"’ or ‘"merMod"’).
On 2022-08-03 3:10 PM, Juho Kristian Ruohonen wrote:
> Dear List,
>
> This is a logistic GLMM with 1 grouping factor + 8 fixed-effect covariates.
> One of the fixed effects, namely x2, has three unordered categories. This
> is the covariate for whose 2 non-reference categories I want to estimate
> random slopes, along with the random intercepts with which I don't expect
> the slopes to be correlated. But I fail:
>
>
>
> *> VarCorr(glmer(y ~ (x2||id) + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8,
> family = binomial, data = mydata, control = glmerControl(optimizer =
> "optimx", optCtrl = list(method = "nlm")), nAGQ = 1))*
>
>
> *boundary (singular) fit: see help('isSingular')*
>
>
>
>
> * Groups Name Std.Dev. Corr id (Intercept) 0.00000
> id.1 x2A 0.76331 x2B 0.75422
> 0.931 x2C 0.56139 0.807 0.967*
>
> ^ Why is it reporting correlations when I told it not to? And why is it
> reporting the intercept variance as zero (which is wholly implausible)? And
> why is it reporting a "random slope" for the reference category of x2? It's
> the reference category, for crying out loud! It's not supposed to get an
> estimate.
>
> Consultation of the lme4 manual
> <https://cran.r-project.org/web/packages/lme4/vignettes/lmer.pdf> (page 7)
> suggests the following alternative syntax for specifying random slopes
> uncorrelated with the random intercepts:
>
> *> VarCorr(glmer(y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + (1|id) +
> (0+x2|id), family = binomial, data = mydata, control =
> glmerControl(optimizer = "optimx", optCtrl = list(method = "nlm")), nAGQ =
> 1))*
>
> *boundary (singular) fit: see help('isSingular')*
>
>
>
>
>
> * Groups Name Std.Dev. Corr id (Intercept) 0.00000
> id.1 x2A 0.76331 x2B 0.75422
> 0.931 x2C 0.56139 0.807 0.967*
>
> ^ The exact same strangeness persists. Correlations are being estimated
> against my wishes, and there's a nonsensical parameter supposedly
> ostensibly representing the reference category, plus an implausible zero
> value reported on the random intercepts. What am I doing wrong?
>
> Best,
>
> Juho
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
More information about the R-sig-mixed-models
mailing list