2

I am trying to extract individual elements (p-values specifically) from the fixed effects table contained within the object created by the summary call of a mixed-effects model.

Toy data:

set.seed(1234)
score <- c(rnorm(8, 20, 3), rnorm(8, 35, 5))
rep <- rep(c(0,1,2,3), each = 8)
group <- rep(0:1, times = 16)
id <- factor(rep(1:8, times = 4))

df <- data.frame(id, group, rep, score)

Now create a model

require(nlme)

modelLME <- summary(lme(score ~ group*rep, data = df, random = ~ rep|id))

modelLME

When we call it we get the output

Linear mixed-effects model fit by REML
 Data: df 
       AIC      BIC    logLik
  219.6569 230.3146 -101.8285

Random effects:
 Formula: ~rep | id
 Structure: General positive-definite, Log-Cholesky parametrization
            StdDev       Corr  
(Intercept) 2.664083e-04 (Intr)
rep         2.484345e-05 0     
Residual    7.476621e+00       

Fixed effects: score ~ group * rep 
                Value Std.Error DF   t-value p-value
(Intercept) 22.624455  3.127695 22  7.233587  0.0000
group       -1.373324  4.423229  6 -0.310480  0.7667
rep          2.825635  1.671823 22  1.690152  0.1051
group:rep    0.007129  2.364315 22  0.003015  0.9976
 Correlation: 
          (Intr) group  rep   
group     -0.707              
rep       -0.802  0.567       
group:rep  0.567 -0.802 -0.707

Standardized Within-Group Residuals:
        Min          Q1         Med          Q3         Max 
-1.86631781 -0.74498367  0.03515508  0.76672652  1.91896578 

Number of Observations: 32
Number of Groups: 8 

Now I can extract the parameter estimates for the fixed effects via

fixef(modelLME)

but how do I extract the p-values?

To extract the entire random effects table we would call

VarCorr(modelLME)

and then extract individual elements within that table via the subsetting function [,]. But I don't know what the equivalent function to VarCorr() is for the fixed effects.

llewmills
  • 2,959
  • 3
  • 31
  • 58

1 Answers1

5

You can extract the p-values with:

modelLME$tTable[,5]

    (Intercept)           group             rep       group:rep 
0.0000003012047 0.7666983225269 0.1051210824864 0.9976213300628 

Generally, looking at str(modelLME) helps to find the different components.

erc
  • 10,113
  • 11
  • 57
  • 88
  • 1
    Thank you @beetroot. I did run `names(modelLME)` but it wasn't immediately clear that `tTable` was the fixed effects table. Also the random effects table , which one calls using `VarCorr` is not listed in the list of elements called up by this function, so I wasn't sure if the fixed effects would be either. But they are. Cheers. – llewmills Jun 10 '16 at 19:54