在 R 中,我正在寻找一种方法来估计使用 kenward-rogers 或 satterthwaite 自由度和 SE 的 lmer
模型的线性对比的置信区间。
例如,我可以使用 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 *
允许 time1 的 CI,如:
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.lmerMod
和 pbkrtest::get_Lb_ddf
)。就个人而言,如果要测试的对比不是很“简单”,我会选择后者,因为我发现 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 ]
关于r - lmer 线性对比 : Kenward Rogers or Satterthwaite DF and SE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32130516/