# anovaR - model1 = lm(grow ~ nem anova(model1 check...

This preview shows pages 1–2. Sign up to view the full content.

Sheet1 Page 1 # Example: One-way ANOVA model (4 treatments) # Just copy and paste these commands into the R command # window to see the results. # Do nematodes affect plant growth? # "scan" the response data into a vector grow <- scan() 10.8 9.1 13.5 9.2 11.1 11.1 8.2 11.3 5.4 4.6 7.4 5.0 5.8 5.3 3.2 7.5 # Create the "factor" vector of treatments. # Make sure the order matches the order # of the responses. nem <- factor(rep(x=c("A","B","C","D"), times=c(4,4,4,4))) # display the data data.frame(nem, grow) boxplot(grow~nem) # box plot comparing nematodes # useful function - split data in first argument by factor in second argument split(grow,nem) # apply sample means function to split data smean<-sapply(split(grow,nem),"mean") # within group sample standard deviations ssd<-sapply(split(grow,nem),"sd") # Conditions look ok for pooling - the largest sd is smaller than # twice the smallest sd # Here's a quick way to the get the ANOVA table using the # lm function and anova function

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: model1 = lm(grow ~ nem) anova(model1) # check normality of residuals x11() qqnorm(model1\$residuals) # Some other model summary statistics, including coefficients for the # "reference cell" parameterization - here Diet A is the reference category summary(model1) # Contrast : planned comparison Sheet1 Page 2 n<-c(4,4,4,4) #number of sample in each group a<-c(3,-1,-1,-1) #contrast coefficients c<-sum(a*smean) sp<-sqrt(2.78) #pooled sample variance is the MSE from anova table se<-sp*sqrt(sum(a^2/n)) t<-c/se df<-12 pvalue<-1-pt(t,df) #Another way to do contrast test : install the package "gregmisc" library(gregmisc) fit.contrast(model1,nem,c(3,-1,-1,-1)) # Multiple comparisons, with simultaneous confidence level of 95% for the 6 comparisons TukeyHSD(aov(model1)) # plot the simultaneous confidence intervals for differences plot(TukeyHSD(aov(model1))) # for more information enter "help(TukeyHSD)"...
View Full Document

## This note was uploaded on 09/11/2011 for the course STAT 200 taught by Professor Agniel during the Spring '09 term at University of Illinois at Urbana–Champaign.

### Page1 / 2

anovaR - model1 = lm(grow ~ nem anova(model1 check...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online