Thursday, May 21, 2015

How to do Dunnett Test in R


rm(list=ls())


install.packages("multcomp")
library("multcomp")

weight <- read.csv("~/Desktop/Pat-Mat-WT-Weight.csv", head=TRUE)
weight$Genotype <- as.factor(weight$Genotype)

low_fat <- subset(weight, Food=="CE-2")
high_fat <- subset(weight, Food =="D12492")

time_point <- c(4:17)

high_results <- lapply(time_point, function(x) {
 summary(glht(aov(high_fat[,x] ~ Genotype, high_fat), linfct=mcp(Genotype="Dunnett")))
})

sink(file="high_results.txt") 
high_results
sink(NULL) 


ls(summary(glht(aov(high_fat[,4] ~ Genotype, high_fat), linfct=mcp(Genotype="Dunnett"))))
summary(glht(aov(high_fat[,4] ~ Genotype, high_fat), linfct=mcp(Genotype="Dunnett")))$vcov


low_results <- lapply(time_point, function(x) {
  summary(glht(aov(low_fat[,x] ~ Genotype, low_fat), linfct=mcp(Genotype="Dunnett")))
})


sink(file="low_results.txt") 
low_results
sink(NULL) 

cwd()
File Link