wiki:SOPs/anova

Version 1 (modified by trac, 12 years ago) ( diff )

--

One-way ANOVA

See the Prism help page for some general considerations.

Reading in Data

  • Use read.* or create appropriate dataframe
  #Eg. testing 4 different strains by creating a dataframe
  PA7<-c(56,60,44,53)
  PA7_dGra15<-c(29,38,18,35)
  PA7_Rop16l<-c(11,25,7,18)
  PA7_Rop16l_dGra15<-c(26,44,20,32)
  strains<-data.frame(PA7, PA7_dGra15, PA7_Rop16l, PA7_Rop16l_dGra15)
  strains_stack<-stack(strains)
  
  #Eg. from Mathias' Stats Lecture
  brainweight <- read.csv("brain_weights.csv",header=TRUE)

Creating an ANOVA Table

  • Use the command anova or aov with summary. The first arg is the dependent var, followed by ~, and then by independent variable(s)

 #column headers were not given above, default are "values" and "ind"
  anova(lm(values~ind, data=strains_stack))
  #or save to file
  x<-anova(lm(values~ind, data=strains_stack))
  write.table(x, file="strains1_anova.txt", quote=F)
  
  #Eg. from Mathias' Stats Lecture
  summary(aov(Weight~Group))

Post-Test: Comparing All Pairs of Means

Tukey

  • "Tukey's method is more conservative but may miss real differences too often" - Intuitive Biostatistics (p.259)
  TukeyHSD(aov(values~ind, data=strains_stack))
  
  #Eg. from Mathias' Stats Lecture
  TukeyHSD(aov(brainweight$Weight~brainweight$Group))
  

Dunnett

  • Useful if you want to compare a reference group to all other groups (instead of doing an all vs. all comparison)
  • The first group is used as the reference group, so name your groups so this is the case.
  library(multcomp)
  summary(glht(lm(Weight ~ Group, data=brainweight), linfct=mcp(Group="Dunnett")))

Note: See TracWiki for help on using the wiki.