== One-way ANOVA == See the [http://www.graphpad.com/support/faqid/1745/ Prism help page] for some general considerations. Note that ANOVA and post-hoc tests can be performed in Prism too. ==== Reading in Data ==== * Use read.* or create appropriate dataframe {{{ # Input data from a tab-delimited text file of the format # weight group # 56 a # 29 b # ... strains = read.delim("brain_weights.txt",header=TRUE) # Input data for 4 different groups by creating a dataframe by hand a = c(56,60,44,53) b = c(29,38,18,35) c = c(11,25,7,18) d = c(26,44,20,32) strains.frame = data.frame(a, b, c, d) strains = stack(strains.frame) colnames(strains) = c("weight", "group") }}} ==== Creating an ANOVA Table ==== * Use the command //anova// or //aov// with summary. The first argument is the dependent variable, followed by ~, and then by independent variable(s). * So if we want to set up a model where weight is a function of the group (e.g., the weight potentially depends on the group) {{{ # Syntax 1 anova( lm(weight ~ group, data=strains) ) # Syntax 2 summary( aov(weight ~ group, data=strains) ) }}} == 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(weight ~ group, data=strains) ) }}} ==== 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 ("a" in this example) is used as the reference group, so name your groups so this is the case. {{{ library(multcomp) summary(glht(lm(weight ~ group, data=strains), linfct=mcp(group="Dunnett"))) }}} == Repeated-measures ANOVA == Repeated-measures ANOVA is typically needed if multiple measurements are made on the same sample (such as assaying a mouse's weight during a time course). == Two-way ANOVA == Two-way ANOVA should be used for experiments where to different factors are being varied (such as comparing different treatments of different genotypes of mice). ==== Reading in Data ==== * Use read.* or create appropriate dataframe {{{ # Input data from a tab-delimited text file of the format # weight treatment genotype # 56 a ko # 29 b wt # 60 a wt # ... strains = read.delim("brain_weights.txt",header=TRUE) }}} ==== Creating an ANOVA Table ==== * Use the command //anova// or //aov// with summary. The first argument is the dependent variable, followed by ~, and then by independent variable(s). * So if we want to set up a model where weight is a function of the group (e.g., the weight potentially depends on the group) {{{ # Syntax 1 anova( lm(weight ~ group * genotype, data=strains) ) anova( lm(weight ~ genotype * group, data=strains) ) # Syntax 2 summary( aov(weight ~ group * genotype, data=strains) ) summary( aov(weight ~ genotype * group, data=strains) ) }}} == Post-Test: Comparing All Pairs of Means ==