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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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 # &quot;reference cell&quot; parameterization - here Diet A is the reference category summary(model1) # Contrast : planned comparison Sheet1 Page 2 n&lt;-c(4,4,4,4) #number of sample in each group a&lt;-c(3,-1,-1,-1) #contrast coefficients c&lt;-sum(a*smean) sp&lt;-sqrt(2.78) #pooled sample variance is the MSE from anova table se&lt;-sp*sqrt(sum(a^2/n)) t&lt;-c/se df&lt;-12 pvalue&lt;-1-pt(t,df) #Another way to do contrast test : install the package &quot;gregmisc&quot; 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 &quot;help(TukeyHSD)&quot;...
View Full Document

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 Right Arrow Icon
Ask a homework question - tutors are online