Changes between Version 1 and Version 2 of SOPs/anova


Ignore:
Timestamp:
05/24/13 11:47:53 (12 years ago)
Author:
gbell
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SOPs/anova

    v1 v2  
    1010
    1111{{{
    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# ...
     17strains = read.delim("brain_weights.txt",header=TRUE)
    2218
     19# Input data for 4 different groups by creating a dataframe by hand
     20a = c(56,60,44,53)
     21b = c(29,38,18,35)
     22c = c(11,25,7,18)
     23d = c(26,44,20,32)
     24strains.frame = data.frame(a, b, c, d)
     25strains = stack(strains.frame)
     26colnames(strains) = c("weight", "group")
    2327}}}
    2428 
    2529==== 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)
    2732
    28  
    2933{{{
    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
     35anova( lm(weight ~ group, data=strains) )
    3836
     37# Syntax 2
     38summary( aov(weight ~ group, data=strains) )
    3939}}}
    4040
     
    4646
    4747{{{
    48   TukeyHSD(aov(values~ind, data=strains_stack))
    49  
    50   #Eg. from Mathias' Stats Lecture
    51   TukeyHSD(aov(brainweight$Weight~brainweight$Group))
    52  
    53 
     48TukeyHSD( aov(weight ~ group, data=strains) )
    5449}}}
    5550
    5651==== Dunnett ====
    5752  * 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{{{
     56library(multcomp)
     57summary(glht(lm(weight ~ group, data=strains), linfct=mcp(group="Dunnett")))
     58}}}
     59
     60== One-way ANOVA ==
    5961
    6062
    61 {{{
    62   library(multcomp)
    63   summary(glht(lm(Weight ~ Group, data=brainweight), linfct=mcp(Group="Dunnett")))
    64 
    65 }}}