R aov Function


aov() function is for analysis of variance (ANOVA).

aov(formula, data=NULL, ...)


formula: a formula specifying the model
data: the data frame containing the variables specified in the formula

Following is a csv file example, we will do ANOVA analysis:

(Download the data file)

Let first read in the data from the file:

>x <- read.csv("anova.csv",header=T,sep="\t")


One way ANOVA analysis:

> a = aov(Expression~Subtype, data=x)
> summary(a)

Df Sum Sq Mean Sq F value Pr(>F)
Subtype 2 4.75 2.3769 3.991 0.0196 *
Residuals 278 165.59 0.5956
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Please pay attention to the formula format, dependant variance "Expression" is in front of the independant variance "Subtype".

Report the means and the number of subjects:

>print(model.tables(a,"means"),digits=2)

Tables of means
Grand mean
-0.3053381
Subtype
A B C
-0.18 -0.39 -0.49
rep 143.00 75.00 63.00



Two way ANOVA analysis:

> a = aov(Expression~Subtype*Age, data=x)
> summary(a)

Df Sum Sq Mean Sq F value Pr(>F)
Subtype 2 4.75 2.377 3.975 0.0199 *
Age 1 0.09 0.095 0.159 0.6905
Subtype:Age 2 1.04 0.518 0.866 0.4217
Residuals 275 164.46 0.598
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Here, dependant variance is "Expression", "Subtype" and "Age" are independant variances.

Report the means and the number of subjects:

>print(model.tables(a,"means"),digits=2)

Tables of means
Grand mean
-0.3053381
Gender
f m
-0.39 -0.22
rep 135.00 146.00
Subtype
A B C
-0.22 -0.36 -0.44
rep 143.00 75.00 63.00
Gender:Subtype
Subtype
Gender A B C
f 0 0 -1
rep 40 49 46
m 0 -1 0
rep 103 26 17

endmemo.com © 2024  | Terms of Use | Privacy | Home