deer = read.csv("Deer.csv")
aragorn = rnorm(50, mean=180, sd=10)
gimli = rnorm(50, mean=132, sd = 15)
legolas = rnorm(50, mean=195, sd=15)
Run a t-test to compare the Legolas actors to the set of Aragorns and then to the set of Gimlis. Do you find evidence for significant differences?
t.test(legolas, aragorn, alternative="two.sided")
##
## Welch Two Sample t-test
##
## data: legolas and aragorn
## t = 5.0087, df = 84.264, p-value = 2.974e-06
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 8.954966 20.746866
## sample estimates:
## mean of x mean of y
## 192.1601 177.3092
The low p value of the t-test means that there is evidence for significant differences in the heights of the sets of actors.
t.test(legolas, gimli, alternative="two.sided")
##
## Welch Two Sample t-test
##
## data: legolas and gimli
## t = 18.829, df = 89.492, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 51.72471 63.92864
## sample estimates:
## mean of x mean of y
## 192.1601 134.3335
The low p value of the t-test means that there is evidence for significant differences in the heights of the sets of actors.
Rerun the variance test (F-test) to compare the group of Gimli and Legolas actors. Do these groups have different variance?
var.test(gimli, legolas)
##
## F test to compare two variances
##
## data: gimli and legolas
## F = 0.52866, num df = 49, denom df = 49, p-value = 0.02771
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.2999996 0.9315912
## sample estimates:
## ratio of variances
## 0.5286558
As the p value is above 0.05, there is likely not a difference in variance.
Redo the correlation for the sepal length and sepal width for the Iris dataset, but for the three individual species. Are these correlated?
vers = subset(iris, Species == "versicolor")
cor(vers$Sepal.Length, vers$Sepal.Width)
## [1] 0.5259107
As the correlation value is 0.526, there is a positive correlation between the variables for the species versicolor
virg = subset(iris, Species == "virginica")
cor(virg$Sepal.Length, virg$Sepal.Width)
## [1] 0.4572278
As the correlation value is 0.457, there is a positive correlation between the variables for the species virginica
set = subset(iris, Species == "setosa")
cor(set$Sepal.Length, set$Sepal.Width)
## [1] 0.7425467
As the correlation value is 0.743, there is a positive correlation between the variables for the species setosa
Using the deer dataset and the chisq.test() function, test: (1) If there are significant differences in the number of deer caught per month
table(deer$Month)
##
## 1 2 3 4 5 6 7 8 9 10 11 12
## 256 165 27 3 2 35 11 19 58 168 189 188
chisq.test(table(deer$Month))
##
## Chi-squared test for given probabilities
##
## data: table(deer$Month)
## X-squared = 997.07, df = 11, p-value < 2.2e-16
As the p value is very low, there are significant differences in the number of deer caught per month. (2) If the cases of tuberculosis are uniformly distributed across all farms
table(deer$Farm, deer$Tb)
##
## 0 1
## AL 10 3
## AU 23 0
## BA 67 5
## BE 7 0
## CB 88 3
## CRC 4 0
## HB 22 1
## LCV 0 1
## LN 28 6
## MAN 27 24
## MB 16 5
## MO 186 31
## NC 24 4
## NV 18 1
## PA 11 0
## PN 39 0
## QM 67 7
## RF 23 1
## RN 21 0
## RO 31 0
## SAL 0 1
## SAU 3 0
## SE 16 10
## TI 9 0
## TN 16 2
## VISO 13 1
## VY 15 4
chisq.test(table(deer$Farm, deer$Tb))
## Warning in chisq.test(table(deer$Farm, deer$Tb)): Chi-squared approximation may
## be incorrect
##
## Pearson's Chi-squared test
##
## data: table(deer$Farm, deer$Tb)
## X-squared = 129.09, df = 26, p-value = 1.243e-15
As the p value is very low, the cases of tuberculosis are not uniformly distributed across all farms.