简体   繁体   English

使用 lmer() 进行重复测量方差分析的问题

[英]Issue with using lmer() for a repeated measures ANOVA

I am trying to use lmer() to perform a sort of repeated measures ANOVA.我正在尝试使用lmer()来执行一种重复测量方差分析。 I sampled the same pools multiple times throughout the year, and am trying to see if there is a difference in a response variable (body size) based on the sampling date, with pool as a random effect.我在一年中多次采样相同的池,并试图查看基于采样日期的响应变量(体型)是否存在差异,池作为随机效应。 My issue in this case is that I am getting separate estimates and p-values for my fixed effects (sampling dates), instead of the single estimate and p-value I would normally get from this type of model.在这种情况下,我的问题是我获得了固定效应(采样日期)的单独估计值和 p 值,而不是我通常从此类模型中获得的单个估计值和 p 值。

require(lme4)
df <- data.frame(wing_length = c(5.1, 4.9, 4.7, 4.6, 5.1,2.4,4.3,4.4),
  date = c('Jan','Jan','Feb','Feb','Mar','Mar','Apr','Apr'),
  pool = c('1','2','1','2','1','2','1','2'))
mod <- lmer(wing_length ~ date + (1|pool),df)

summary(mod)

The summary output gives me various estimates and p-values for the different dates, but I was expecting one single estimate and p-value that tells me whether there is a difference in the mean wing length based on date.摘要输出为我提供了不同日期的各种估计值和 p 值,但我期待一个单独的估计值和 p 值,它告诉我基于日期的平均机翼长度是否存在差异。

I think my issue comes from my data format or some misunderstanding of what I am trying to do with this function.我认为我的问题来自我的数据格式或对我试图用这个函数做什么的一些误解。

Thank you for any advice you can offer.感谢您提供的任何建议。

You will need to convert date from a factor to an integer variable.您需要将date从因子转换为整数变量。 Otherwise, lmer will automatically create dummmies.否则, lmer将自动创建假人。

library(lme4)
df <- data.frame(wing_length = c(5.1, 4.9, 4.7, 4.6, 5.1,2.4,4.3,4.4),
                 date = c('Jan','Jan','Feb','Feb','Mar','Mar','Apr','Apr'),
                 pool = c('1','2','1','2','1','2','1','2'))

df$date <- match(tolower(df$date), tolower(month.abb))
mod <- lmer(wing_length ~ date + (1|pool),df)

summary(mod)

Note that converting date to an integer will produce a different model--one where you are estimating the month trend instead of individual month effects (fixed effects).请注意,将date转换为整数将产生一个不同的模型——您估计月份趋势而不是单个月份效应(固定效应)的模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM