#clean the environment rm(list=ls()) #make sure the working directory is correct getwd() setwd("C:/Users/aamahama/Desktop/") #make sure you have not exceeded the number of lines that you can print getOption("max.print") options(max.print=1000000) #install the package for linear mixed equations install.packages("lme4") #load the lme4 package for use library(lme4) #Next load in the data set from a spreadsheet (excel.csv) ds2<-read.csv("ds 2.csv",header=T) #designate some variables as factor variables attach(ds2) ds2$env<-factor(ds2$env) ds2$line<-factor(ds2$line) ds2$blk<-factor(ds2$blk) summary(ds2) detach(ds2) # Compare with type III MM attach(ds2) anova(lm(yld~ env +line + mat + env*line)) #could also calculate the lsmeans for comparisons with predicted values.insert lsmeans code here. #output to a file sink("anova of ds2.txt") anova(lm(yld~env+line+mat+env*line)) sink() #designate the mixed linear model for the data ds2.mixmodel = lmer(yld ~ env+mat+(1|line/env)) ds2.mixmodel #output random effects from DS4. ranef(ds2.mixmodel)