在R中,我正在寻找一种方法来估计使用kenward-rogers或satterthwaite自由度和SE的lmer模型线性对比的置信区间。
例如,我可以使用t值(使用来自KR的df )和SE为混合模型中的固定效应参数计算CI,比如SAS和R。
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?的线性对比中获得SE或CI?
发布于 2015-08-21 08:17:21
为此,您至少有两个选项:使用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]。
https://stackoverflow.com/questions/32130516
复制相似问题