#####Nested designs and Pseudoreplication ### import data - dataset 1 datum=read.csv(file.choose()) head(datum) ### model without random effect of field results=lm(Biomass~Treatment,data=datum) ### model with random effect of field library(nlme) results2=lme(Biomass~Treatment,data=datum,random=(~1|Field)) ###Is effect of field significant? anova(results2,results) ###No, so can we remove it? anova(results) ### model incorrectly assumes you have 18 samples for testing effect of treatment anova(results2) ### model correctly assumes you have 6 samples for test effect of treatment # Alternative - average within fields (don't include field in analysis) # Field is sample, only need random effect if multiple samples from each field ### import data - dataset 2 datum=read.csv(file.choose()) head(datum) ###analyze data, plots nested within fields results=lme(Biomass~Treatment,data=datum,random=~1|Field/Plot) summary(results) ###analyze data, just plots (don't account for fields results=lme(Biomass~Treatment,data=datum,random=~1|Plot) summary(results) #Note that number of plots is incorrect due to the way we numbered plots in data