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
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
tick <- read.csv("~/Desktop/BIN510-files/ticks.csv")
head(tick)
## Period Date Month Level Replicate Treatment Total RHPU RHPR RHPV Rain
## 1 11 20/08/2014 Aug 2 4 CONT 1 0 0 1 580
## 2 11 20/08/2014 Aug 2 5 CONT 1 0 0 1 580
## 3 11 20/08/2014 Aug 2 6 CONT 1 0 0 1 580
## 4 11 21/08/2014 Aug 3 7 CONT 0 0 0 0 440
## 5 11 21/08/2014 Aug 3 8 CONT 0 0 0 0 440
## 6 11 21/08/2014 Aug 3 9 CONT 5 4 0 1 440
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 ...
boxplot(Total ~ Treatment,
data = tick,
main = "Total Ticks & Treatment",
xlab = "Treatment",
ylab = "Total Ticks",
col= c("lightblue","blue","darkblue","royalblue"))
by(tick$Total, tick$Treatment, shapiro.test)
## tick$Treatment: CONT
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.77549, p-value = 7.169e-07
##
## ------------------------------------------------------------
## tick$Treatment: LMH
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.73066, p-value = 9.644e-08
##
## ------------------------------------------------------------
## tick$Treatment: MEGA
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.902, p-value = 0.001094
##
## ------------------------------------------------------------
## tick$Treatment: MESO
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.81293, p-value = 4.633e-06
library(car)
## Warning: package 'car' was built under R version 4.4.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.4.3
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
Question: interpret the results of 4. (tell me if assumptions are met or not) Answer: The assumptions were not met, The Shapiro-Wilk tests showed that the data were not normall distributed since the p-value was lower than 0.05. Levene’s test showed that the variances were not equal.
Code: Regardless of your answer to 5*, run the test you propose in 2
tick_aov <- aov(Total ~ Treatment, data = tick)
summary(tick_aov)
## 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
TukeyHSD(tick_aov)
## 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
boxplot(Total ~ Treatment,
data = tick ,
main = "Total Number of Ticks by Treatment",
xlab = "Treatment",
ylab = "Total Number of Ticks",
col= c("red","pink","hotpink","darkred"))
tick$logTotal <- log1p(tick$Total)
by(tick$logTotal, tick$Treatment, shapiro.test)
## tick$Treatment: CONT
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.96219, p-value = 0.1481
##
## ------------------------------------------------------------
## tick$Treatment: LMH
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.96636, p-value = 0.2126
##
## ------------------------------------------------------------
## tick$Treatment: MEGA
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.96382, p-value = 0.1707
##
## ------------------------------------------------------------
## tick$Treatment: MESO
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.97739, p-value = 0.5179
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
by(tick$logTotal, tick$Treatment, shapiro.test)
## tick$Treatment: CONT
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.96219, p-value = 0.1481
##
## ------------------------------------------------------------
## tick$Treatment: LMH
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.96636, p-value = 0.2126
##
## ------------------------------------------------------------
## tick$Treatment: MEGA
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.96382, p-value = 0.1707
##
## ------------------------------------------------------------
## tick$Treatment: MESO
##
## Shapiro-Wilk normality test
##
## data: dd[x, ]
## W = 0.97739, p-value = 0.5179
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
Question: are the assumptions met? Answer: After the log transformation, the assumptions were met. The Shapiro-Wilk tests had p-values greater than 0.05 for all treatment groups. Which meant that the data was normally distributed. Levene’s test was also greater than 0.05 (p = 0.0733). Which meant that the variances were equal.
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
tick2 <- lm(Total ~ Rain, data = tick)
summary(tick2)
##
## 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
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 Answer: The regression model showed that rainfall was significant to the total number of ticks p = 0.0196. The R2 value was 0.03024, which means that rainfall explains approximately 3.02% of the variation in the total number of ticks.
Code: create a visual that shows the relationship between rainfall and ticks
tick_plot <- lm(Total ~ Rain, data = tick)
plot(tick$Rain,
tick$Total,
main = "Rainfall versus Total Number of Ticks",
xlab = "Mean Rainfall (mm/year)",
ylab = "Total Number of Ticks")
tick_plot <- lm(Total ~ Rain, data = tick)
plot(tick$Rain,
tick$Total,
main = "Rainfall vs. Total Number of Ticks",
xlab = "Mean Rainfall (mm/year)",
ylab = "Total Number of Ticks")
abline(tick_plot, col = "blue")
Question: Do ticks prefer wet or dry climates? Answer: Since there is a negative relationship between rainfall and total ticks, the data suggests that ticks are more common in drier climates.
Code: predict the number of ticks observed in a region that experiences 500 mm/year mean rainfall
predict(tick_plot, newdata = data.frame(Rain = 500))
## 1
## 10.96561