簡體   English   中英

R:線性混合效果的事后比較 model

[英]R: Posthoc comparison for linear mixed effects model

我的線性混合效果 model 的事后比較遇到了問題。 我將嘗試用一個快速構建的不完美示例來解釋它:

這是我的示例數據:

Variable<-as.factor(rep(c(1,2,3),5))
Random<-rep(c(1,2,2),5)
Result<-rnorm(15,mean=10,sd=2)

Data<-as.data.frame(cbind(Variable,Random,Result))

實際上,我的 model 中包含了幾個固定和隨機效果,但這足以說明我的問題:

library(lme4)
LME=lmer(Result~Variable+(1|Random))
summary(LME)

查看固定效果 output 與截距相比,我只得到變量不同級別的意義

Fixed effects:
            Estimate Std. Error      df t value Pr(>|t|)    
(Intercept)   9.5104     1.3685 12.0000   6.949 1.54e-05 ***
Variable2     0.9155     1.9354 12.0000   0.473    0.645    
Variable3     1.7386     1.9354 12.0000   0.898    0.387    

但是,我現在想將變量級別 1 與級別 2 以及變量級別 2 與級別 3 進行比較,因此我嘗試了以下操作:

library(multcomp)
summary(glht(LME, linfct=c("Variable2-Variable1=0","Variable3-Variable2=0")))

給我留下這個錯誤:

Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'object' in selecting a method for function 'summary': multcomp:::chrlinfct2matrix: variable(s) ‘Variable1’ not found

如果我排除變量級別 1 並且只查看 2 到 3 的比較,則代碼可以正常工作:

summary(glht(LME, linfct=c("Variable3-Variable2=0")))

     Simultaneous Tests for General Linear Hypotheses

Fit: lmer(formula = Result ~ Variable + (1 | Random))

Linear Hypotheses:
                           Estimate Std. Error z value Pr(>|z|)
Variable3 - Variable2 == 0   0.8231     1.6694   0.493    0.622
(Adjusted p values reported -- single-step method)

我還可以運行帶有 Tukey 對比的 linfct function:

summary(glht(LME, linfct= mcp(Variable="Tukey")),test=adjusted("none"))

     Simultaneous Tests for General Linear Hypotheses

Multiple Comparisons of Means: Tukey Contrasts


Fit: lmer(formula = Result ~ Variable + (1 | Random))

Linear Hypotheses:
           Estimate Std. Error z value Pr(>|z|)
2 - 1 == 0   0.9155     1.9354   0.473    0.636
3 - 1 == 0   1.7386     1.9354   0.898    0.369
3 - 2 == 0   0.8231     1.6694   0.493    0.622
(Adjusted p values reported -- none method)

看到我對 3 與 1 的比較不感興趣,我只會使用其他 2 個 p 值並分步調整它們,但這並不是我真正想要的解決方案。 我的數據產生的不僅僅是此處顯示的兩個比較,因此帶有 Tukey 對比的選項會給我留下很多我並不真正感興趣的比較。

有沒有辦法從LME獲得Variable1 在固定效果中,它作為 Intercept 包含,用Intercept替換Variable1或我能想到的任何組合都沒有奏效。 或者通常有更好的方法來實現我正在尋找的比較?

任何幫助將不勝感激!

你真的已經得到了你想要的。 在這種情況下,由於Variable=1是參考組,它的系數固定為 0,方差為 0。因此,檢驗Variable1=Variable2=0是否真的只是檢驗Variable2=0 同樣與Variable3 您可以從以下兩段代碼生成相同的 output 的事實中看出這一點:

summary(glht(LME, linfct=c("Variable2=0","Variable3=0", "Variable3-Variable2=0")))

# Simultaneous Tests for General Linear Hypotheses
# Fit: lmer(formula = Result ~ Variable + (1 | Random))
# Linear Hypotheses:
#                            Estimate Std. Error z value Pr(>|z|)
# Variable2 == 0              -0.6524     2.0145  -0.324    0.942
# Variable3 == 0              -2.0845     2.0145  -1.035    0.545
# Variable3 - Variable2 == 0  -1.4321     1.1199  -1.279    0.396
# (Adjusted p values reported -- single-step method)

summary(glht(LME, linfct=mcp(Variable="Tukey")))

# Simultaneous Tests for General Linear Hypotheses
# Multiple Comparisons of Means: Tukey Contrasts
# Fit: lmer(formula = Result ~ Variable + (1 | Random))
# Linear Hypotheses:
#            Estimate Std. Error z value Pr(>|z|)
# 2 - 1 == 0  -0.6524     2.0145  -0.324    0.942
# 3 - 1 == 0  -2.0845     2.0145  -1.035    0.545
# 3 - 2 == 0  -1.4321     1.1199  -1.279    0.396
# (Adjusted p values reported -- single-step method)

因此,如果您只想與參考進行調整后的比較,您可以執行以下操作:

summary(glht(LME, linfct=c("Variable2=0","Variable3=0")))

# Simultaneous Tests for General Linear Hypotheses
# Fit: lmer(formula = Result ~ Variable + (1 | Random))
# Linear Hypotheses:
#                Estimate Std. Error z value Pr(>|z|)
# Variable2 == 0  -0.6524     2.0145  -0.324    0.889
# Variable3 == 0  -2.0845     2.0145  -1.035    0.404
# (Adjusted p values reported -- single-step method)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM