Lecture 7 R code - mlloyd23/bio211_JAN2018 GitHub Wiki
##SCRIPT FOR LECTURE 7
##Wrap up transformations
#We will need the rcompanion package, which may require devtools to install
install.packages("devtools")
library(devtools)
install.packages("rcompanion")
library(rcompanion)
###########################################################
##Using river turbidity data example from http://rcompanion.org/handbook/
##########################################################
Input =("
location turbidity
a 1.0
a 1.2
a 1.1
a 1.1
a 2.4
a 2.2
a 2.6
a 4.1
a 5.0
a 10.0
b 4.0
b 4.1
b 4.2
b 4.1
b 5.1
b 4.5
b 5.0
b 15.2
b 10.0
b 20.0
c 1.1
c 1.1
c 1.2
c 1.6
c 2.2
c 3.0
c 4.0
c 10.5
")
data = read.table(textConnection(Input),header=TRUE)
plotNormalHistogram()
#attempt anova on untransformed data
anova<-
##sqrt transformation
sqrt<-
plotNormalHistogram()
#log
log<-
plotNormalHistogram()
#power transformation performs iterative power transformations
#and re-tests to shapiro.wilk test to optimize the distribution
T_tuk = transformTukey(data$turbidity, plotit = FALSE)
plotNormalHistogram(T_tuk)
data<-cbind()
head(data)
#anova on transformed data
anova.transformed<-
####################################################
##ONTO NON-PARAMETRIC TESTS
####################################################
##Man whitney-u wilxoc ranked sum
##independent t-test on non-normal data
#mtcars dataset
#disp=displacement which means nothing to me
#because I know nothing about cars
#am is auto (=0) or manual (=1) transmisison
head(mtcars)
hist(mtcars$disp)
shapiro.test(mtcars$disp)
qqnorm(mtcars$disp)
qqline(mtcars$disp)
boxplot()
wilcox.test()
###The above code is the same as below. Two ways to run the same test
auto<-subset(mtcars, am=="0")
man<-subset(mtcars, am=="1")
wilcox.test(auto$disp,man$disp)
#how does this compare to a traditional t-test?
t.test()
#wilcox signed rank
#paired non-parametric t-test
#back to mpg data
head(mpg)
hist(mpg$cty)
hist(mpg$hwy)
wilcox.test()
#How does this compared to a traditional t-test?
t.test()
#Kruskal-Wallis
#ANOVA on non-normal data
head(mpg)
kruskal.test()