I am trying to use lmer()
to perform a sort of repeated measures ANOVA. 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.
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.
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. Otherwise, lmer
will automatically create dummmies.
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.