Lecture 8 R code - mlloyd23/bio211_JAN2018 GitHub Wiki


###REVIEW POST HOC TESTS
#back to the ToothGrowth data
#perform anova: test for effect of dose?
head(ToothGrowth)
ToothGrowth$dose<-as.factor(ToothGrowth$dose)

anova.dose.test<-aov()
summary(anova.dose.test)

boxplot()

#post-hoc tukey
tukey.test<-TukeyHSD()
tukey.test


#And Dunn test for non-normal data using mpg data
kruskal.test() 

#required FSA
install.packages("FSA")
library(FSA)

post.hoc.dunn = dunnTest()
post.hoc.dunn


###NOW ONTO CORRELATIONS
phys.data<-read.table("human_phys.txt", header=TRUE)

head(data)

#look for some normal data
hist(phys.data$BR_before)
hist(phys.data$BR_after)

shapiro.test(phys.data$BR_before)
shapiro.test(phys.data$BR_after)

#have a look a the relationship between the two variables
plot()

#test the relationship between the two variables
cor.test()

#same as running the following:
cor.test()


##Correlations with non-normal data
seed.data<-read.table("Seeds.txt", header=TRUE)

hist(seed.data$Distance)
hist(seed.data$Time)

#Are Distance and Time correlated?
plot()

#run Spearmen correlation
cor.test()

#compare to traditional Pearson's correlation
cor.test()

#Linear regression
model<-lm()
summary()

plot()

#add best fit line
int =  
slope = 
abline()