##### Random Effects ###import the data datum=read.csv(file.choose()) head(datum) ###Import appropriate package # random- and mixed-effects models can't be analysized with lm # analyze with either lme in the nlme package # or with lmer in the lme4 package library(nlme) ###load the nlme package help(lme) ###check out the lme function ###create a random-effects model results=lme(Abundance~1,data=datum,random=~1|Year) ### random effect model # no fixed effects included, hence reason for ~1 in formula # random effects listed separately summary(results) ### look at output # notice summary out put similar to lm, but with estimates for se for random effects ###Test whether random effects are significant source of variation # Compare more complex model (with random effect) to simpler model (no random effect) results2=lm(Abundance~1,data=datum) # must use lm - lme MUST have a random effect anova(results,results2) # notice that test is done using likelihood, rather than sse ###Repeat analysis using lmer library(lme4) help(lmer) ### check out lmer function ### create a random-effects model in lmer results3=lmer(Abundance~1+(1|Year),data=datum) # simliar to lme, but random effects # included in formula statement. summary(results3)