For this exam you will be using the file “tick.csv” found on canvas:

Ticks use large mammals as hosts and the presence of mammals represents an important vector for tick-borne diseases and humans. Tick presence may also be influenced by environmental factors. The tick.csv file has a number of different variables that can be analyzed, below are a list of the important variables for this study:

Treatment - what type of animals were allowed within the plot? CONT (control, no exclosure), LMH (total exclosure, no mammals), MESO (exclosion of large herbivores >15kg), and MEGA (exclusion of Elephants and Giraffes)

Rain - average rainfall (mm/year)

Total - total number of ticks found across 3 study species

PART 1a: How does treatment of mammals influence the total number of ticks found? Answer the questions below:

NOTE: for each prompt, I need to see code in order to give you credit! NOTE: you can perform all of these tasks in one code chunk or many code chunks, this is up to you

  1. Code: bring in the dataset and name it “tick”
tick <- read.csv("ticks.csv", header = TRUE)
str(tick)
## 'data.frame':    180 obs. of  11 variables:
##  $ Period   : num  11 11 11 11 11 11 11 11 11 11 ...
##  $ Date     : chr  "20/08/2014" "20/08/2014" "20/08/2014" "21/08/2014" ...
##  $ Month    : chr  "Aug" "Aug" "Aug" "Aug" ...
##  $ Level    : int  2 2 2 3 3 3 1 1 1 2 ...
##  $ Replicate: int  4 5 6 7 8 9 1 2 3 4 ...
##  $ Treatment: chr  "CONT" "CONT" "CONT" "CONT" ...
##  $ Total    : int  1 1 1 0 0 5 4 0 1 37 ...
##  $ RHPU     : int  0 0 0 0 0 4 3 0 0 0 ...
##  $ RHPR     : int  0 0 0 0 0 0 0 0 0 1 ...
##  $ RHPV     : int  1 1 1 0 0 1 1 0 1 36 ...
##  $ Rain     : int  580 580 580 440 440 440 640 640 640 580 ...
table(tick$Treatment)
## 
## CONT  LMH MEGA MESO 
##   45   45   45   45
  1. Question: what type of test would be appropriate to run in order to compare total ticks by treatment type? Why?
  1. Question: what assumptions need to be tested before running the test?
  1. Code: test all assumptions from 3
#histogram 
hist(tick$Total,
     main = "Total Ticks Distribution",
     xlab = "Total Number of Ticks",
     col = "orchid")

#Shapiro-Wilk test
shapiro.test(tick$Total)
## 
##  Shapiro-Wilk normality test
## 
## data:  tick$Total
## W = 0.64898, p-value < 2.2e-16
#Levene's test
library(car)
## Loading required package: carData
leveneTest(Total ~ Treatment, data = tick)
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   3   7.506 9.346e-05 ***
##       176                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  1. Question: interpret the results of 4. (tell me if assumptions are met or not)
  1. Code: Regardless of your answer to 5*, run the test you propose in 2
tickANOVA <- aov(Total ~ Treatment,
          data = tick)
summary(tickANOVA)
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## Treatment     3   3387  1128.9    8.67 2.13e-05 ***
## Residuals   176  22915   130.2                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  1. Question: what does the output of 6 tell you about ticks and treatment?
  1. Question: do you need to run post-hoc analysis? Why or why not?
  1. Code: if you answered YES to 8, run that analysis here
TukeyHSD(tickANOVA)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Total ~ Treatment, data = tick)
## 
## $Treatment
##                diff         lwr       upr     p adj
## LMH-CONT  11.844444   5.6050266 18.083862 0.0000115
## MEGA-CONT  3.177778  -3.0616401  9.417196 0.5508095
## MESO-CONT  5.355556  -0.8838623 11.594973 0.1201486
## MEGA-LMH  -8.666667 -14.9060845 -2.427249 0.0022968
## MESO-LMH  -6.488889 -12.7283067 -0.249471 0.0380749
## MESO-MEGA  2.177778  -4.0616401  8.417196 0.8020299
  1. Question: if you ran 9, tell me what the output tells us about the treatments
  1. Create a visual that helps tell the story of how treatment influences ticks
boxplot(Total ~ Treatment,
        data = tick,
        main = "Tick Population based on Treatment",
        xlab = "Treatment",
        ylab = "Total Number of Ticks",
        col = c("lightsalmon", "orangered2", "red3", "red4"))

PART 1b: violations of assumptions. Answer the questions below:

  1. Code: choose a transformation method of your choice and apply it to the “total” column
tick$logTotal <- log(tick$Total + 1)
  1. Code: re-test the assumptions from Part 1a Q4
#histogram 
hist(tick$logTotal,
     main = "Total Ticks Distribution",
     xlab = "Total Number of Ticks",
     col = "darkorchid")

#Shapiro-Wilk test
shapiro.test(tick$logTotal)
## 
##  Shapiro-Wilk normality test
## 
## data:  tick$logTotal
## W = 0.98087, p-value = 0.01424
#Levene's test
library(car)
leveneTest(logTotal ~ Treatment, data = tick)
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)  
## group   3  2.3584 0.0733 .
##       176                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  1. Question: are the assumptions met?
  1. Code: Run the alternative non-parametric test appropriate for this data
kruskal.test(Total ~ Treatment,
             data = tick)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  Total by Treatment
## Kruskal-Wallis chi-squared = 23.869, df = 3, p-value = 2.66e-05
  1. Question: what does the output of 4 tell us about ticks and treatment?

PART 2: does environment influence ticks?

  1. Question: what type of test would be appropriate to run in order to compare total ticks by rain? Why?
  1. Code: run the test
tickReg <- lm(Total ~ Rain, data = tick)

summary(tickReg)
## 
## Call:
## lm(formula = Total ~ Rain, data = tick)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -12.471  -6.593  -2.959   2.163  76.041 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 23.50781    5.95874   3.945 0.000115 ***
## Rain        -0.02508    0.01065  -2.356 0.019565 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.97 on 178 degrees of freedom
## Multiple R-squared:  0.03024,    Adjusted R-squared:  0.02479 
## F-statistic:  5.55 on 1 and 178 DF,  p-value: 0.01957
  1. Question: using the output from 2, tell me what the model says about ticks and rainfall. Include in your answer an interpretation of the p-value and an interpretation of the R^2 value
  1. Code: create a visual that shows the relationship between rainfall and ticks
plot(x = tick$Rain,
     y = tick$Total,
     pch = 16,
     col = "blue",
     xlab = "Average Rainfall (mm/year)",
     ylab = "Tick Abundance",
     main = "Relationship Between Rainfall and Tick Abundance")

5. Code: add a best fit line to help visualize the pattern

plot(x = tick$Rain,
     y = tick$Total,
     pch = 16,
     col = "blue",
     xlab = "Average Rainfall (mm/year)",
     ylab = "Tick Abundance",
     main = "Relationship Between Rainfall and Tick Abundance")

abline(tickReg,
       col = "red",
       lwd = 2)

6. Question: Do ticks prefer wet or dry climates? - According to the linear regression line of best fit, ticks prefer drier climates due to the indirect relationship between tick abundance and rainfall. 7. Code: predict the number of ticks observed in a region that experiences 500 mm/year mean rainfall

newtick <- data.frame(Rain = 500)

predict(tickReg,
        newdata = newtick)
##        1 
## 10.96561