[R-sig-ME] Advice on Mixed Models

Ben Bolker bbolker at gmail.com
Sat Mar 11 00:59:52 CET 2017



On 17-03-08 02:01 PM, Rose Rosei wrote:
> Dear Advisors
> 
> Would you please advise me. I would like to fit my model, but I struggled
> to do it
> 
> 
>   A= Applicant = 10 persons
>   S= Stream ( four levels, 1, 2)

  Not sure what "four levels, 1, 2" means here.  Do you mean "four
levels, 1-4" ... ?

>   D= Day   (1,2)
>  S1= Session ( 1,2)
>  Q = Qestion ( 1-to 8)
>  Applicants are crossed in Questions, but Applicants nested in Stream,
>   nested in Day, nested in session (S1). All variables are a a random factor

  You need to know that **with modern mixed-model machinery (e.g. nlme,
lme4 as opposed to aov() in R) it is not in general practical to
estimate random-effects terms for variables with fewer than 5 or 6 levels**.
See e.g. http://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#singular-fit

> 
>    I want to calculate SD for A, S, D, S1 and Q, and their interaction
> .score=dependent variable
> 
>  I have used the following codes, but it seems they are wrong.
> 
>  lmer(score~ (1|A)+(1|S)+(1+D)+(1|S1)+(1|Q)+(1|A/S)+1|S/D)+(1|D/S1)+(1|S1/Q),
> R)

  (1|S1/D/S/A) gives "Applicants nested in Stream, nested in Day, nested
in session (S1)".  As I said above, it would be wiser if possible to use
S1+ (1|S1:D/S/A) (i.e. treat session as a fixed effect).
I would probably handle questions via (1|Q); if each applicant receives
each question no more than once within a session/day/stream combination,
then the S1:D:S:A:Q interaction will be handled by the residual variance
term.

In addition to the problems stated above, many of these terms are
redundant.  The nesting syntax (1|A/S) expands to (1|A) + (1|A:S) (i.e.
variability among levels of A, and variability among the interacting
levels of A and S). Fitting a crossed term as compactly as possible
would use (1|A*S), but I think this doesn't actually work: (1|A) + (1|S)
or (1|A:S) or (1|A/S)+(1|S) both describe crossed random effects of A
and S.  You may also have the nesting order backwards: (1|A/S) means
"Stream nested within Applicants", not "Applicants nested within Stream".


> 
> Linear mixed model fit by REML ['lmerMod']
> Formula: score ~ (1 | A) + (1 | S) + (1 + D) + (1 | S1) + (1 | Q) + (1 |
>     A/S) + (1 | S/D) + (1 | D/S1) + (1 | S1/Q)
>    Data: R
> REML criterion at convergence: 192.4591
> Random effects:
>  Groups   Name        Std.Dev.
>  Q.S1     (Intercept) 0.000e+00
>  A        (Intercept) 2.383e-01
>  S.A      (Intercept) 7.692e-01
>  A.1      (Intercept) 8.399e-01
>  Q        (Intercept) 0.000e+00
>  S1.D     (Intercept) 1.386e-08
>  D.S      (Intercept) 0.000e+00
>  S1       (Intercept) 0.000e+00
>  D        (Intercept) 9.498e-01
>  S        (Intercept) 0.000e+00
>  S1.1     (Intercept) 0.000e+00
>  S.1      (Intercept) 0.000e+00
>  Residual             6.722e-01
> Number of obs: 80, groups:
> Q:S1, 16; A, 10; S:A, 10; Q, 8; S1:D, 4; D:S, 4; S1, 2; D, 2; S, 2
> Fixed Effects:
> (Intercept)            D
>     1.61458     -0.07292
> convergence code 0; 2 optimizer warnings; 0 lme4 warnings
> 
>    Very much appreciated for your help.
> looking forward to hearing from you.
>    Rose
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-mixed-models at 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