I've run multiple models for my data, and the sqrt tranformation is the best fit. However, when I try to run an emmeans on it, it states that my random variable is not in the reference grid. This happens for all the lmer models I'm using (with or without transofrmations) but not when I run the emmeans on the other models (aov, lm, glmer). Sample of my data, including only the variable I'm interested in:
Soil,Treatment,Nuptake
Haverhill,Control1,27081.46
Haverhill,Control1,5387.66
Haverhill,Control1,7550.94
Haverhill,Control1,13112.55
Haverhill,CanolaMeal50kgha,53000.02
Haverhill,CanolaMeal50kgha,64134.78
Haverhill,CanolaMeal50kgha,74807.12
Haverhill,CanolaMeal50kgha,34556.01
Oxbow,Control1,8315.87
Oxbow,Control1,na
Oxbow,Control1,9995.51
Oxbow,Control1,8370.4
Oxbow,CanolaMeal50kgha,24646.73
Oxbow,CanolaMeal50kgha,73189.65
Oxbow,CanolaMeal50kgha,34348.63
Oxbow,CanolaMeal50kgha,90335.24
My model with the sqrt transformation:
Mod3c<- lmer(sqrt(Nuptake)~Treatment*(1|Soil),data=Pots1,na.action = na.exclude)
I ran the same model with Treatment+(1|Soil) - both work and have the same rsq value, anova output and shapiro-wilk residual values.
The emmeans I'm trying to run is:
Mod3em <- emmeans(Mod3c,~Treatment|Soil, data=Pots1)
#Error in emmeans(Mod3c, ~Treatment | Soil, data = Pots1) : No variable named Soil in the reference grid
I want to run the emmeans function with a cld to be able to plot my data with SE bars. Is there a way to rewrite the emmeans or the model so that it allows me to get the emmeans for my data by 'treatment' (fixed effect) and by 'soil' (random effect)?
emmeansonly works with the fixed factors in the model. If you really want results for each soil, that suggests that it is a factor of interest and as such, it should be in the model as a fixed effect.