2013-02-27 148 views
2

我试图用lmer函数来研究在3种不同条件(cond = 0,1,2)之间的反应时间(RT)是否存在交互效应,患者(患者)的目标(目标=假或真)。在R中使用lmer函数改变截距

我写了下面的公式:

lmer(RT~cond*target+(1|Patient)) 

我的问题是,该功能的默认截距是COND = 0和目标=假,而我想拦截是COND = 0和目标=真(为了查看cond0 * target = True和cond1 * target = True是否有显着差异)。

我真的很感谢你的帮助。

这里是输出I具有

stu3<-lmer(RT~cond*target+(1|Patient), 
    data=subset(ss, Groupe=="ugs" & primeable ==TRUE  & 
      Correct==TRUE & NoPrac==TRUE)) 

pvals.fnc(stu3) 


$fixed 
        Estimate MCMCmean HPD95lower HPD95upper pMCMC Pr(>|t|) 
(Intercept)   0.5511 0.5513  0.5258  0.5807 0.0001 0.0000 
cond1    0.0618 0.0619  0.0498  0.0741 0.0001 0.0000 
cond2    0.0285 0.0285  0.0142  0.0438 0.0002 0.0001 
targetFALSE   0.1389 0.1389  0.1239  0.1549 0.0001 0.0000 
cond1:targetFALSE -0.0752 -0.0751 -0.0943 -0.0545 0.0001 0.0000 
cond2:targetFALSE -0.0788 -0.0786 -0.0998 -0.0564 0.0001 0.0000 

$random 
    Groups  Name Std.Dev. MCMCmedian MCMCmean HPD95lower HPD95upper 
1 Patient (Intercept) 0.0610  0.0583 0.0599  0.0425  0.0797 
2 Residual    0.1674  0.1674 0.1674  0.1650  0.1699 

基于我的数据,被选择的截距是cond0:targetTRUE,并在输出其他级别是cond1:targetFALSEcond2:targetFALSE

+0

所以'cond1'参数应完全对应于差的测试COND之间'== 0'和'当'target'为'TRUE'时(假设你没有做任何聪明的事情......),这就是你想要的。 – 2013-02-27 23:53:26

回答

1

看看标准的“要素管理”是有效的:

target=factor(target, levels=c("TRUE", "FALSE") 
lmer(RT~cond*target+(1|Patient)) 

(我会用“改变基准水平”,而不是“改变拦截”这句话,但我想这是真的一样的过程。我怀疑短语“更改参考级别”会让你在MarkMail Rhelp或SO搜索中找到很少的点击。)

+0

,并小心精确匹配的水平 - 即你的因子水平“TRUE”和“FALSE”,或“”True“和”False“,或”TRUE“和”FALSE“ ...? – 2013-02-27 20:54:03

+0

我在“目标”是一个逻辑向量的假设下构建了我的建议,在这种情况下,他们会写作,但如果他们是Ben害怕的因素(和你写的那样),那么请遵照他的建议并确保他们匹配拼写。在你的数据元素上提供str()总是最好的。 – 2013-02-27 20:59:05

+0

因子水平为TRUE且FALSE为Ben。我试图按照你的建议迪宁,但它只是切换的东西:这一次拦截是交互cond0 * targetTrue,但它比较它cond1 * targetFalse。 – Alba 2013-02-27 21:07:31

1

如果我理解正确,那么你的模型已经在做你想在target==TRUE之内的解释了。

"(Intercept)"  -> target==TRUE, cond==0 (even if model matrix contains all conds) 
"cond1"    -> target==TRUE, cond==1 on top of cond==0 
"cond2"    -> target==TRUE, cond==2 on top of cond==0 
"targetFALSE"  -> target==FALSE, cond==0 (even if model matrix contains all conds) 
"cond1:targetFALSE" -> target==FALSE, cond==1 on top of cond==0 
"cond2:targetFALSE" -> target==FALSE, cond==2 on top of cond==0 

所以不方面"(Intercept)""cond1""cond2"检测到的有趣的差异:如果我是正确的,你可以在你的例子如下翻译模型项?看看getME(stu3,'X')中的固定效应模型矩阵结构可能会有所帮助。

下面是我构建的一个示例数据,用于测试您的案例。请注意,我建立了三个不同的回应:一个没有任何效果,一个只具有target==TRUE效果,另一个具有target==TRUE的效果,并且与target==TRUE以及cond的不同级别具有交互效果。在fit1fit2检测到人工引入的效果:

set.seed(0) 
struct <- expand.grid(target = c(FALSE,TRUE), cond = as.factor(0:2), patient = LETTERS[1:20]) 
attach(struct) 
ranpatient <- rep(rnorm(20), each=6) 
rerror <- rnorm(120) 
# Just random noise 
response0 <- ranpatient + rerror 
# When target==TRUE we increment the response by 1 and add errors 
response1 <- 1*target + ranpatient + rerror 
# When target==TRUE we increment the response by 1, 
# to which we also add an interaction effect condition {0,1,2} * target {0,1} 
# notice that numeric transformation of cond {0,1,2} transforms to ranks {1,2,3} 
response2 <- 1*target + target*(as.numeric(cond)-1) + ranpatient + rerror 

dat <- data.frame(cond, target, patient, response0, response1, response2) 
detach(struct) 

require(lme4) 
fit0 <- lmer(response0 ~ cond*target + (1|patient), data=dat) 
fit1 <- lmer(response1 ~ cond*target + (1|patient), data=dat) 
fit2 <- lmer(response2 ~ cond*target + (1|patient), data=dat) 

head(dat) 
round(coef(summary(fit0)),2) # Notice low t values 
round(coef(summary(fit1)),2) # High t value for targetTRUE 
round(coef(summary(fit2)),2) # High t value for interaction cond0/1/2 with targetTRUE 
# Notice how cond==1 adds 1, and cond==2 adds 2 in comparison to cond==0 when targetTRUE 
# Notice also that coefficient "cond2:targetTRUE" is incremental to term "targetTRUE", not "cond1:targetTRUE" 
head(getME(fit2,'X')) # Columns correspond to the fixed effect terms 

随着输出

> head(dat) 
    cond target patient response0 response1 response2 
1 0 FALSE  A 1.038686 1.038686 1.038686 
2 0 TRUE  A 1.640350 2.640350 2.640350 
3 1 FALSE  A 1.396291 1.396291 1.396291 
4 1 TRUE  A 2.067144 3.067144 4.067144 
5 2 FALSE  A 1.205848 1.205848 1.205848 
6 2 TRUE  A 1.766562 2.766562 4.766562 
> round(coef(summary(fit0)),2) # Notice low t values 
       Estimate Std. Error t value 
(Intercept)   -0.13  0.31 -0.40 
cond1    0.18  0.29 0.62 
cond2    0.00  0.29 0.00 
targetTRUE   0.00  0.29 -0.01 
cond1:targetTRUE  0.13  0.41 0.32 
cond2:targetTRUE  0.08  0.41 0.19 
> round(coef(summary(fit1)),2) # High t value for targetTRUE 
       Estimate Std. Error t value 
(Intercept)   -0.13  0.31 -0.40 
cond1    0.18  0.29 0.62 
cond2    0.00  0.29 0.00 
targetTRUE   1.00  0.29 3.42 
cond1:targetTRUE  0.13  0.41 0.32 
cond2:targetTRUE  0.08  0.41 0.19 
> round(coef(summary(fit2)),2) # High t value for interaction cond0/1/2 with targetTRUE 
       Estimate Std. Error t value 
(Intercept)   -0.13  0.31 -0.40 
cond1    0.18  0.29 0.62 
cond2    0.00  0.29 0.00 
targetTRUE   1.00  0.29 3.42 
cond1:targetTRUE  1.13  0.41 2.75 
cond2:targetTRUE  2.08  0.41 5.04 
> # Notice how cond==1 adds 1, and cond==2 adds 2 in comparison to cond==0 when targetTRUE 
> # Notice also that coefficient "cond2:targetTRUE" is incremental to term "targetTRUE", not "cond1:targetTRUE" 
> head(getME(fit2,'X')) # Columns correspond to the fixed effect terms 
    [,1] [,2] [,3] [,4] [,5] [,6] 
[1,] 1 0 0 0 0 0 
[2,] 1 0 0 1 0 0 
[3,] 1 1 0 0 0 0 
[4,] 1 1 0 1 1 0 
[5,] 1 0 1 0 0 0 
[6,] 1 0 1 1 0 1 
+1

这一切都对我有意义。我会问的唯一调整是使用访问器方法:'coef(summary())'而不是'@ coefs'和'getME(。,“X”)''而不是'@ X' – 2013-02-28 13:33:27

+0

感谢您的建议!我会记住它。我现在纠正了上面的代码和输出。 – 2013-02-28 14:18:48