Changes between Version 1 and Version 2 of SOPs/anova
- Timestamp:
- 05/24/13 11:47:53 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SOPs/anova
v1 v2 10 10 11 11 {{{ 12 #Eg. testing 4 different strains by creating a dataframe 13 PA7<-c(56,60,44,53) 14 PA7_dGra15<-c(29,38,18,35) 15 PA7_Rop16l<-c(11,25,7,18) 16 PA7_Rop16l_dGra15<-c(26,44,20,32) 17 strains<-data.frame(PA7, PA7_dGra15, PA7_Rop16l, PA7_Rop16l_dGra15) 18 strains_stack<-stack(strains) 19 20 #Eg. from Mathias' Stats Lecture 21 brainweight <- read.csv("brain_weights.csv",header=TRUE) 12 # Input data from a tab-delimited text file of the format 13 # weight group 14 # 56 a 15 # 29 b 16 # ... 17 strains = read.delim("brain_weights.txt",header=TRUE) 22 18 19 # Input data for 4 different groups by creating a dataframe by hand 20 a = c(56,60,44,53) 21 b = c(29,38,18,35) 22 c = c(11,25,7,18) 23 d = c(26,44,20,32) 24 strains.frame = data.frame(a, b, c, d) 25 strains = stack(strains.frame) 26 colnames(strains) = c("weight", "group") 23 27 }}} 24 28 25 29 ==== Creating an ANOVA Table ==== 26 * Use the command //anova// or //aov// with summary. The first arg is the dependent var, followed by ~, and then by independent variable(s) 30 * Use the command //anova// or //aov// with summary. The first argument is the dependent variable, followed by ~, and then by independent variable(s). 31 * 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) 27 32 28 29 33 {{{ 30 #column headers were not given above, default are "values" and "ind" 31 anova(lm(values~ind, data=strains_stack)) 32 #or save to file 33 x<-anova(lm(values~ind, data=strains_stack)) 34 write.table(x, file="strains1_anova.txt", quote=F) 35 36 #Eg. from Mathias' Stats Lecture 37 summary(aov(Weight~Group)) 34 # Syntax 1 35 anova( lm(weight ~ group, data=strains) ) 38 36 37 # Syntax 2 38 summary( aov(weight ~ group, data=strains) ) 39 39 }}} 40 40 … … 46 46 47 47 {{{ 48 TukeyHSD(aov(values~ind, data=strains_stack)) 49 50 #Eg. from Mathias' Stats Lecture 51 TukeyHSD(aov(brainweight$Weight~brainweight$Group)) 52 53 48 TukeyHSD( aov(weight ~ group, data=strains) ) 54 49 }}} 55 50 56 51 ==== Dunnett ==== 57 52 * Useful if you want to compare a reference group to all other groups (instead of doing an all vs. all comparison) 58 * The first group is used as the reference group, so name your groups so this is the case. 53 * The first group ("a" in this example) is used as the reference group, so name your groups so this is the case. 54 55 {{{ 56 library(multcomp) 57 summary(glht(lm(weight ~ group, data=strains), linfct=mcp(group="Dunnett"))) 58 }}} 59 60 == One-way ANOVA == 59 61 60 62 61 {{{62 library(multcomp)63 summary(glht(lm(Weight ~ Group, data=brainweight), linfct=mcp(Group="Dunnett")))64 65 }}}