lme给出了可比的答案,但需要事先构建按小时的交互: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检验.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")My question is, How can I write the same model in lme4?In particular, I don't know how to include the "observed" term?If I just write lmer(value ~ treatment * gender + (phase*hour|id), data = obk.long, observed = "gender")I get an error telling that observed is not a valid option.Furthermore, if I just remove the observed option lmer produces the error: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).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:the observed argument appears only to be relevant for the computation of effect size.... so I think you'd be safe leaving it out.if you want to override the error you can use 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))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 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")I don't know how to reconstruct afex's tests of the random effects. 这篇关于怎么把Afex或汽车ANOVA模型转换成lmer?观察变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-25 01:09