Lecture 6 R code - mlloyd23/bio211_JAN2018 GitHub Wiki

#Transformations population sampling board data
#Lecture 6

#Before we get started with the sampling data, look at some simulated normal data
#simulated normal data
norm <- rnorm(100)
hist(norm)
norm
shapiro.test(norm)

#qq plots
qqnorm(norm)
qqline(norm)

#install the rcompanion package to use plotNormalHistogram() function
library(devtools)
install.packages("rcompanion")
library(rcompanion)

data<-read.table("sampling.txt", header=TRUE)
head(data)

plotNormalHistogram(data$Value)

#make variables for counts of each color
green<-
pink<-
red<-
blue<-

#Visual tests of normality
plotNormalHistogram()

#qq plots
qqnorm()
qqline()


#Quantitative tests for normality; 
shapiro.test()


#Let's try a square root transformation
sqrt<-sqrt()
plotNormalHistogram()

#test for normality
shapiro.test()

#What about a log transformation?
log<-log()
plotNormalHistogram()
shapiro.test()

#Arcsine-square root with proportion data
#simulate some proportional data
prop.data <- seq(-1, 1, length = 20)

plotNormalHistogram()
arcsine<-asin(sqrt(abs(prop.data)))

shapiro.test()


###########################################################
##Using river turbidity data
##########################################################
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


##sqrt transformation


#log


#Tukey’s Ladder of Powers transformation
T_tuk = transformTukey()

#anova on transformed data