Tuesday, September 11, 2012

t-test, anova

//t-test
apply(matrix, 1, function(x){t.test(x ~ factor(t(facts)))$p.value})
apply(matrix, 1, function(x){t.test(x ~ factor(t(facts)))$statistic})

//one way anova
apply(matrix,1,function(x){anova(aov(x~factor))$Pr})
apply(matrix,1,function(x){anova(aov(x~factor))$F})

//two way anova without interactions
apply(matrix,1,function(x){anova(aov(x~farea+ftreat))$Pr})
apply(matrix,1,function(x){anova(aov(x~farea+ftreat))$F})

//two way anova with interactions
apply(matrix,1,function(x){anova(aov(x~farea+ftreat+farea*ftreat))$Pr})
apply(matrix,1,function(x){anova(aov(x~farea+ftreat+farea*ftreat))$F})


http://en.wikipedia.org/wiki/F-test#One-way_ANOVA_example

No comments: