I get the impression you're just trying to basically do a repeated measures ANOVA but using multi-level modelling. You'll generally need to look up information on multiple regression and understand that well in order to step into the world of multi-level modelling. You should look through the site at the many many questions on using lmer
.
Your model is incorrect. You want:
m <- lmer( diversity ~ treatment * time + (1|id) )
Given your description, time is not a grouping variable. The parentheses is where you specify your random effects structure(s) but only your grouping or nesting goes after the vertical bar. In your case the data are grouped by id. The random effect here is id and the intercept (1
) varies across across it but none of your effects like time or treatment do. You may want to know if there is a random effect of time and / or treatment, allowing those to vary by id as well. For example, letting time and the intercept vary by id would be:
m <- lmer( diversity ~ treatment * time + (1+time|id) )
but there are other options. To see a further explanation of various random effect structures search the site and you shall find.
You should plot your data and check to see if the effect of time is some simple function (like linear or log) and include it as that. And you could test the function the standard way comparing categorical time predictor model to function time predictor model to see if categorical had more explanatory power, anova(modelTimeLogline, modelTimeCat)
.
Also, with your model specification you're not checking if your effect is present at all time points in the coefficients. It will only tell you if it's present at time point 0 because you have an interaction term.
m <- lmer( diversity ~ treatment * time + (1|id) )
anova(m)
That will give you an assessment of both the main effects and interaction as F values in a sequential ANOVA. If you need the main effect coefficient for the model then you first need to run just this model:
lmer(diversity ~ treatment + time + (1|id) + (1|time))
Note that it does not matter at all that the interaction is significant when it is in the model in order for the main effect coefficients to be uninterpretable. There's more you should know about multiple regression in order to do more advanced analysis like this.