本文介绍了如何将 Afex 或汽车 ANOVA 模型转换为 lmer?观察到的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

afex 包中,我们可以找到这个方差分析的例子:

In the afex package we can find this example of ANOVA analysis:

data(obk.long, package = "afex")
# estimate mixed ANOVA on the full design:
# can be written in any of these ways:

aov_car(value ~ treatment * gender + Error(id/(phase*hour)), data = obk.long,
        observed = "gender")

aov_4(value ~ treatment * gender + (phase*hour|id), data = obk.long,
        observed = "gender")

aov_ez("id", "value", obk.long, between = c("treatment", "gender"),
       within = c("phase", "hour"), observed = "gender")

我的问题是,如何在 lme4 中编写相同的模型?特别是,我不知道如何包含观察到的"术语?

My question is, How can I write the same model in lme4?In particular, I don't know how to include the "observed" term?

如果我只是写

lmer(value ~ treatment * gender + (phase*hour|id), data = obk.long,
     observed = "gender")

我收到一条错误消息,提示 Observed 不是一个有效的选项.

I get an error telling that observed is not a valid option.

此外,如果我只是删除观察到的选项 lmer 会产生错误:

Furthermore, if I just remove the observed option lmer produces the error:

错误:观察次数 (=240)

在 lmer 语法中,我在哪里指定介于"或内"变量?.据我所知,您只需将因变量写在左侧,将所有其他变量写在右侧,误差项为 (1|id).

Where in the lmer syntax do I specify the "between" or "within" variable?. As far as I know you just write the dependent variable on the left side and all other variables on the right side, and the error term as (1|id).

包car"使用 idata 作为主题内变量.

The package "car" uses the idata for the intra-subject variable.

推荐答案

我可能对经典方差分析理论了解得不够完整,无法完全回答这个问题,但我会尝试一下.首先,有几点:

I might not know enough about classical ANOVA theory to answer this question completely, but I'll take a crack. First, a couple of points:

  • observed 参数似乎只与效应量的计算相关.
  • the observed argument appears only to be relevant for the computation of effect size.

观察到:字符"向量指示哪些变量是观察(即测量)与实验相比被操纵.报告的默认效果大小(广义eta-squared) 需要正确指定所观察的 [原文如此](与操纵相反)变量.

...所以我认为你可以安全地忽略它.

... so I think you'd be safe leaving it out.

  • 如果你想覆盖错误,你可以使用
  control=lmerControl(check.nobs.vs.nRE="ignore")

...但这可能不是正确的前进方向.

... but this probably isn't the right way forward.

认为但不确定这是正确的方法:

I think but am not sure that this is the right way:

m1 <- lmer(value ~ treatment * gender + (1|id/phase:hour), data = obk.long,
    control=lmerControl(check.nobs.vs.nRE="ignore",
                            check.nobs.vs.nlev="ignore"),
    contrasts=list(treatment=contr.sum,gender=contr.sum))

这指定了 phasehour 的交互在 id 内变化.残差方差和(在 id 内逐小时)方差是混淆的(这就是为什么我们需要覆盖的 lmerControl() 规范),所以不要相信那些特定的方差估计.但是,治疗和性别的主要影响应该处理相同.如果你加载 lmerTest 而不是 lmer 并运行 summary(m1)anova(m1) 它会给你afex 计算的固定(性别和治疗)效应的相同自由度 (10).

This specifies that the interaction of phase and hour varies within id. The residual variance and (phase by hour within id) variance are confounded (which is why we need the overriding lmerControl() specification), so don't trust those particular variance estimates. However, the main effects of treatment and gender should be handled just the same. If you load lmerTest instead of lmer and run summary(m1) or anova(m1) it gives you the same degrees of freedom (10) for the fixed (gender and treatment) effects that are computed by afex.

lme 给出了类似的答案,但需要事先构建逐小时交互:

lme gives comparable answers, but needs to have the phase-by-hour interaction constructed beforehand:

library(nlme)
obk.long$ph <- with(obk.long,interaction(phase,hour))
m2 <- lme(value ~ treatment * gender,
             random=~1|id/ph, data = obk.long,
    contrasts=list(treatment=contr.sum,gender=contr.sum))
anova(m2,type="marginal")

我不知道如何重建 afex 对随机效应的测试.

I don't know how to reconstruct afex's tests of the random effects.

这篇关于如何将 Afex 或汽车 ANOVA 模型转换为 lmer?观察到的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 23:31