配对t检验与简单混合模型的关系

机器算法验证 r 混合模式 t检验
2022-03-25 23:34:04

我对这个问题的赏金将在接下来的 24 小时内到期。

我有一个心理数据集,传统上将使用配对样本 t 检验对其进行分析。实验的设计是,我对给定变量在条件之间的差异感兴趣。39(subjects)×7(targets)×2(conditions)

传统的方法是对目标进行平均,这样我每个参与者有 2 个观察值,然后使用配对 t 检验比较这些平均值。

我想使用混合模型方法,因为它在该领域变得越来越流行(即Baayen, Davidson & Bates, 2008),所以我拟合的第一个模型,我认为应该近似于 t 检验的结果,是一个将作为固定效应,并随机截取(即。显然,完整模型还将包括的随机截取。conditionsubjectsvar=α+βcondition+Intercept(subject)+ϵtargets

但是,我很难理解为什么我在两种方法之间取得了截然不同的结果。谁能解释这里发生了什么?我也见过(我理解的)一个类似的问题,这里有一个关于相关结构的答案,我没有能力理解。如果这也是这里的问题,如果有人可以建议一些资源来阅读此内容,我将不胜感激。

编辑:我在这里发布了示例数据和 R 脚本

编辑 #2 - 添加赏金

一些额外的点:

  • 我只是在分析正确的反应(把它想象成类似于反应时间),所以会有缺失的案例——并不是每个参与者都提供每个条件的 7 个数据点。
    • 当我分析所有响应时,而不仅仅是正确的响应,两个结果之间的差异会减少,但不会消除。这向我表明,失踪案件是这里的一个因素。
  • 变量不是正态分布的。在我的最终模型中,我使用 Box-Cox 变换对其进行缩放,但为了与 t 检验保持一致,我在这里省略了它。
  • 正如@PeterFlom 所指出的,这两种方法之间的差异很大,但我认为这是因为 t 检验被应用于聚合数据(每个参与者 2 个观察值,每个条件 1 个),而混合模型是适用于原始分数(观察值,个)。df<14<7
  • @BenBolker 指出 t 值也有很大差异。

我的分析代码如下。

>library(dplyr)
>subject_means = group_by(data, subject, condition) %>% summarise(var=mean(var))
>t.test(var ~ condition, data=subject_means, paired=T)

    Paired t-test

data:  var by condition
t = -1.3394, df = 37, p-value = 0.1886
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -0.14596388  0.02978745
sample estimates:
mean of the differences 
            -0.05808822 

>library(lme4)
>lm.0 = lmer(var ~ (1|subject), data=data)
>lm.1 = lmer(var ~ condition + (1|subject), data=data)
>anova(lm.0, lm.1)

Data: data
Models:
object: var ~ (1 | subject)
..1: var ~ condition + (1 | subject)
       Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(>Chisq)  
object  3 489.09 501.23 -241.55   483.09                           
..1     4 485.81 502.00 -238.90   477.81 5.2859      1     0.0215 *

>library(lmerTest)
>summary(lm.1)$coef

              Estimate Std. Error        df  t value     Pr(>|t|)
(Intercept) 0.11862462 0.02878027  98.60659 4.121734 7.842075e-05
condition   0.09580546 0.04161237 400.27441 2.302331 2.182890e-02

特别注意,p 值从t 检验中的跃迁到任一方法p=.188p=.021lmer


我已经尝试过,但未能提供一个可重复的示例,使用包anorexia中的数据集MASS,所以我认为问题是我的数据的特殊问题,但我不明白是什么。

# Borrowing from http://ww2.coastal.edu/kingw/statistics/R-tutorials/dependent-t.html
>data(anorexia, package="MASS")
>ft = subset(anorexia, subset=(Treat=="FT"))
>wgt = c(ft$Prewt, ft$Postwt)
>pre.post = rep(c("pre","post"),c(17,17))
>subject = rep(LETTERS[1:17],2)
>t.test(wgt~pre.post, data=ft.new, paired=T)

    Paired t-test

data:  wgt by pre.post
t = 4.1849, df = 16, p-value = 0.0007003
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  3.58470 10.94471
sample estimates:
mean of the differences 
               7.264706 

>m = lmer(wgt ~ pre.post + (1|subject), data=ft.new)
>summary(m)$coef

             Estimate Std. Error       df   t value     Pr(>|t|)
(Intercept) 90.494118   1.689013 26.17129 53.578096 0.0000000000
pre.postpre -7.264706   1.735930 15.99968 -4.184908 0.0007002806
1个回答

我认为问题在于配对t检验的计算方式。试试这个:

t.test(all_by_sub$var[all_by_sub$condition==1], all_by_sub$var[all_by_sub$condition==0], paired=TRUE)

这给出了:

data:  all_by_sub$var[all_by_sub$condition == 1] and all_by_sub$var[all_by_sub$condition == 0]
t = 2.0529, df = 37, p-value = 0.0472
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 0.0009400428 0.1435297005
sample estimates:
mean of the differences 
             0.07223487 

显然,在配对t检验t.test中计算 x 减去 y 。这就是为什么估计的符号和t值是相反的。除此之外,混合模型的估计值(0.072 对 0.082)和 t 值(2.05 对 2.19)都非常接近 t 检验的结果:

            Estimate Std. Error      df t value Pr(>|t|)
(Intercept)    0.118      0.028 106.772   4.159    0.000
condition      0.082      0.037 462.992   2.192    0.029