One way ANOVA in R: Difference between revisions

From Powers Wiki
(Created page with "The one way analysis of variance is used to test if three or more means are equal. One way ANOVA is an extension of two independent samples t-test. ===using R=== *Open the R ...")
 
No edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 3: Line 3:
===using R===
===using R===
*Open the R console
*Open the R console
*Change the working directory to the directory where your file presents using the following command"
*Change the working directory to the directory where your file is"


setwd('C:/Users/yourfolder')
    setwd('C:/Users/yourfolder')


*Read the file: E.g the file used here is smaple.csv. The file has three groups with the following format
*Read the file: E.g the file used here is smaple.csv. The file has three groups with the following format


{| class="wikitable"
  {| class="wikitable"
|-
|-
! Header 1
! Header 1
Line 24: Line 24:
|}
|}
* Read the file and name it (e.g metab)
* Read the file and name it (e.g metab)
metab <- read.csv ("sample.csv, header= T)
    metab <- read.csv ("sample.csv, header= T)
* confirm the file is imported. When you call for metab and press enter you should see the table
* confirm the file is imported. When you call for metab and press enter you should see the table
*make box plot
*make box plot
boxplot(metab)
    boxplot(metab)
*Then use the following command to conduct one way anova and Tukey's test  
*Then use the following command to conduct one way anova and Tukey's test  
smetab <- stack(metab) <br>
    smetab <- stack(metab) <br>
names(smetab) <- c("length", "group") <br>
    names(smetab) <- c("length", "group") <br>
smetab <br>
    smetab <br>
av1<-aov(length ~ group, data=smetab) <br>
    av1<-aov(length ~ group, data=smetab) <br>
summary(av1) <br>
    summary(av1) <br>
tk<- TukeyHSD(av1) <br>
    tk<- TukeyHSD(av1) <br>
tk <br>
    tk <br>
 
[[category:Data_Processing_and_Analysis]]

Latest revision as of 06:24, 20 January 2022

The one way analysis of variance is used to test if three or more means are equal. One way ANOVA is an extension of two independent samples t-test.

using R

  • Open the R console
  • Change the working directory to the directory where your file is"
   setwd('C:/Users/yourfolder')
  • Read the file: E.g the file used here is smaple.csv. The file has three groups with the following format
Header 1 Header 2 Header 3
a b c
d e f
  • Read the file and name it (e.g metab)
   metab <- read.csv ("sample.csv, header= T)
  • confirm the file is imported. When you call for metab and press enter you should see the table
  • make box plot
   boxplot(metab)
  • Then use the following command to conduct one way anova and Tukey's test
   smetab <- stack(metab) 
names(smetab) <- c("length", "group")
smetab
av1<-aov(length ~ group, data=smetab)
summary(av1)
tk<- TukeyHSD(av1)
tk