lmer 线性对比:Kenward Rogers 或 Satterthwaite DF 和 SE

lmer linear contrasts : Kenward Rogers or Satterthwaite DF and SE

在 R 中,我正在寻找一种方法来估计 lmer 使用 kenward-rogers 或 satterthwaite 自由度和 SE 的模型的线性对比的置信区间。

例如,我可以使用 t 值(来自 KR 的 df)和 SE,在混合模型(如 SAS 和 R)中计算固定效应参数的 CI。

mod<-lmerTest::lmer(y~time1+treatment+time1:treatment+(1|PersonID),data=data)
lmerTest::summary(mod,ddf = "Kenward-Roger")

这个输出:

Fixed effects:
                Estimate Std. Error      df t value Pr(>|t|)    
(Intercept)      49.0768     1.0435 56.4700  47.029  < 2e-16 ***
time1             5.8224     0.5963 48.0000   9.764 5.51e-13 ***
treatment         1.6819     1.4758 56.4700   1.140   0.2592    
time1:treatment   2.0425     0.8433 48.0000   2.422   0.0193 * 

允许 CI 时间 1,例如:

5.8224+abs(qt(0.05/2, 48))*0.5963 #7.021342
5.8224-abs(qt(0.05/2, 48))*0.5963 #4.623458

我想对固定系数的线性对比做同样的事情。这是 p 值,但没有 SE 输出。

pbkrtest::KRmodcomp(mod,matrix(c(0,0,1,0),nrow = 1)) 

         stat     ndf     ddf F.scaling p.value
Ftest  1.2989  1.0000 56.4670         1  0.2592

有没有办法从使用这种 df 的 lmer 线性对比中获得 SE 或 CI?

为此,您至少有两个选择:使用 lsmeans 包,或手动执行(使用函数 vcovAdj.lmerModpbkrtest::get_Lb_ddf)。个人来说,如果要测试的对比度不是很"simple",我会选择后者,因为我觉得lsmeans中的语法有点复杂。

举例说明,取下面的模型:

library(pbkrtest)
library(lme4)
library(nlme) # for the 'Orthodont' data

# 'age' is a numeric variable, while 'Sex' and 'Subject' are factors
model <- lmer(distance ~ age : Sex + (1 | Subject), data = Orthodont)

Linear mixed model fit by REML ['lmerMod']
Formula: distance ~ age:Sex + (1 | Subject)
…
Fixed Effects:
    (Intercept)    age:SexMale  age:SexFemale  
        16.7611         0.7555         0.5215 

我们希望从中获得有关男性和女性年龄系数差异的统计数据(即 age:SexMale - age:SexFemale)。

使用 lsmeans:

library(lsmeans)
# Evaluate the contrast at a value of 'age' set to 1,
# so that the resulting value is equal to the regression coefficient
lsm = lsmeans(model, pairwise ~ age : Sex, at = list(age = 1))$contrast

产生:

contrast           estimate         SE    df t.ratio p.value
1,Male - 1,Female 0.2340135 0.06113276 42.64   3.828  0.0004

或者,手动计算:

# Specify the contrasts: age:SexMale - age:SexFemale
# Must have the same order as the fixed effects in the model
K = c("(Intercept)" = 0, "age:SexMale" = 1, "age:SexFemale" = -1)

# Retrieve the adjusted variance-covariance matrix, to calculate the SE
V = pbkrtest::vcovAdj.lmerMod(model, 0)

# Point estimate, SE and df
point_est = sum(K * fixef(model))
SE = sqrt(sum(K * (V %*% K)))
df = pbkrtest::get_Lb_ddf(model, K)

alpha = 0.05 # significance level

# Calculate confidence interval for the difference between the 'age' coefficients for males and females
Delta_age_CI = point_est + SE * qt(c(0.5 * alpha, 1 - 0.5 * alpha), df)

将导致点估计等于 0.2340135、SE 0.06113276、df 42.63844 和置信区间 [0.1106973, 0.3573297]