2016-06-10 110 views
1

我試圖從由混合效果模型的摘要調用創建的對象中包含的固定效果表中提取單個元素(具體爲p值)。從nlme/lme4輸出中提取固定效果的p值

玩具數據:

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) 

現在創建一個模型

require(nlme) 

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

modelLME 

當我們調用它,我們得到的輸出

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 

現在我可以提取參數估計值的固定效果通過

fixef(modelLME) 

但我該如何提取p值?

要提取整個隨機效應表我們稱之爲

VarCorr(modelLME) 

,然後通過該子集功能[,]提取表中的各個元素。但我不知道VarCorr()與固定效果的等效函數是什麼。

回答

4

您可以提取p值:

modelLME$tTable[,5] 

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

一般來說,看着str(modelLME)有助於尋找不同的組件。

+1

謝謝@beetroot。我確實運行了'name(modelLME)',但是並不清楚'tTable'是固定效果表。另外,使用'VarCorr'調用的隨機效果表沒有列在此函數調用的元素列表中,所以我不確定固定效果是否也是。但他們是。乾杯。 – llewmills