0

I'm using the lmer package to build a model and want to check for correlations between random effects.

First I build a tibble:

id <- rep(1:6, each=4) 
group <- rep(c("A","B"), each=12)
type <- rep(c("pencil", "pencil", "pen", "pen"), times=6)
color <- rep (c ("blue", "red"), times = 12)
dv <- c(-24.3854453, 17.0358639, -15.5174479, 8.6462489, -7.0561166, 3.3524410, 21.6199364, -6.1020999, 13.2464223, 20.3740206, 22.8571793, -6.6159629, 18.7898553, -8.2504319, 17.9571641, 2.9555213, -19.5516738, -0.5845135, 9.6041710, -4.1301420, 4.1740094, -24.2496521, 7.4432948, -0.8290391)
sample_data <- as_tibble(cbind(id, group, type, color, dv)

Here is my sample_data:

    id   group   type   color  dv
    1    A       pencil blue   0.05925979
    1    A       pencil red    4.60326151
    1    A       pen    blue   -20.72000620
    1    A       pen    red    -15.27612843    
    2    A       pencil blue   -0.68719576
    2    A       pencil red    16.34200026
    2    A       pen    blue   18.23954687
    2    A       pen    red    21.02837383
    3    A       pencil blue   -22.28695974
    3    A       pencil red    -18.36587259
    3    A       pen    blue   -15.13952913
    3    A       pen    red    19.95919637
    4    B       pencil blue   -19.52410412
    4    B       pencil red    -3.25912890
    4    B       pen    blue   -12.11669400
    4    B       pen    red    15.93333896
    5    B       pencil blue   -17.93575204
    5    B       pencil red    -8.58879605
    5    B       pen    blue    8.89757943
    5    B       pen    red    -13.42995221
    6    B       pencil blue   12.03769124
    6    B       pencil red    -10.28876053
    6    B       pen    blue    7.69523239
    6    B       pen    red    -2.94621122

Now I run my model and summarize it:

test.model <- lmer(dv ~ 1 + group * type * color + (1 * type * color | id), data = sample_data,  REML = FALSE)
summary(test.model)

Here's my output:

Linear mixed model fit by maximum likelihood . t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: dv ~ 1 + group * type * color + (1 * type * color | id)
   Data: test

     AIC      BIC   logLik deviance df.resid 
   204.7    216.5    -92.4    184.7       14 

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.16529 -0.45429  0.09296  0.62406  1.62720 

Random effects:
 Groups   Name        Variance Std.Dev.
 id       (Intercept)   4.975   2.23   
 Residual             124.228  11.15   
Number of obs: 24, groups:  id, 6

Fixed effects:
                            Estimate Std. Error       df t value Pr(>|t|)  
(Intercept)                  -0.6679     6.5626  23.8937  -0.102   0.9198  
groupA                       -0.6894     9.2809  23.8937  -0.074   0.9414  
typepencil                  -10.3603     9.1005  18.0000  -1.138   0.2699  
colorblue                    12.3361     9.1005  18.0000   1.356   0.1920  
groupA:typepencil            25.3050    12.8700  18.0000   1.966   0.0649 .
groupA:colorblue             -1.3256    12.8700  18.0000  -0.103   0.9191  
typepencil:colorblue         -0.1705    12.8700  18.0000  -0.013   0.9896  
groupA:typepencil:colorblue -30.4925    18.2010  18.0000  -1.675   0.1112  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) groupA typpnc colrbl grpA:t grpA:c typpn:
groupA      -0.707                                          
typepencil  -0.693  0.490                                   
colorblue   -0.693  0.490  0.500                            
grpA:typpnc  0.490 -0.693 -0.707 -0.354                     
gropA:clrbl  0.490 -0.693 -0.354 -0.707  0.500              
typpncl:clr  0.490 -0.347 -0.707 -0.707  0.500  0.500       
grpA:typpn: -0.347  0.490  0.500  0.500 -0.707 -0.707 -0.707

I want to check the correlations for random effects, but I don't see the usual "Corr" column (usually appears next to "St.Dev." in the output under "Random effects"). Where is it?

v8289
  • 1
  • 1

1 Answers1

0

I think that the problem stems from the random effects part of your model. You currently have:

(1 * type * color | id)

However, the standard formula is:

(1 + type * color | id)

When I run this, I get an error about the number of observations being less than the number of random effects (the interaction makes the random effects structure too complex for your sample dataset). Using a less complex random effects structure, (1 + type + color | id), I am able to get the Corr column that you are looking for:

Linear mixed model fit by maximum likelihood . t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: dv ~ 1 + group * type * color + (1 + type + color | id)
   Data: sample_data

     AIC      BIC   logLik deviance df.resid 
   203.8    221.5    -86.9    173.8        9 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-1.5320 -0.7217  0.1363  0.7089  1.3920 

Random effects:
 Groups   Name        Variance Std.Dev. Corr       
 id       (Intercept) 130.22   11.411              
          typepencil   15.49    3.936    0.42      
          colorred    219.98   14.832   -1.00 -0.37
 Residual              41.79    6.464              
Number of obs: 24, groups:  id, 6

Fixed effects:
                           Estimate Std. Error      df t value Pr(>|t|)   
(Intercept)                   9.653      7.572   6.888   1.275  0.24368   
groupB                        2.015     10.708   6.888   0.188  0.85617   
typepencil                  -15.718      5.747  14.358  -2.735  0.01582 * 
colorred                    -11.010     10.059   7.985  -1.095  0.30562   
groupB:typepencil             5.187      8.127  14.358   0.638  0.53333   
groupB:colorred              -1.326     14.226   7.985  -0.093  0.92805   
typepencil:colorred          30.663      7.465  11.996   4.108  0.00145 **
groupB:typepencil:colorred  -30.492     10.556  11.996  -2.889  0.01362 * 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) groupB typpnc colrrd grpB:t grpB:c typpn:
groupB      -0.707                                          
typepencil  -0.174  0.123                                   
colorred    -0.922  0.652  0.117                            
grpB:typpnc  0.123 -0.174 -0.707 -0.083                     
gropB:clrrd  0.652 -0.922 -0.083 -0.707  0.117              
typpncl:clr  0.246 -0.174 -0.649 -0.371  0.459  0.262       
grpB:typpn: -0.174  0.246  0.459  0.262 -0.649 -0.371 -0.707
convergence code: 0
Model failed to converge with max|grad| = 0.00237651 (tol = 0.002, component 1)

I still get a warning about the model failing to converge. This is likely again due to the random effects structure being too complex for your sample dataset: lmer(dv ~ 1 + group * type * color + (1 | id), data = sample_data, REML = FALSE) gives no such warning.

Hope that helps?

arranjdavis
  • 657
  • 8
  • 16
  • Aha! That makes sense, thanks for catching the syntax error! – v8289 Aug 18 '20 at 23:02
  • You are welcome, if you don't mind, could you please accept the answer (or let me know if anything else is unclear)? Just click the check mark below the up/down vote arrows. – arranjdavis Aug 19 '20 at 17:55