'data.frame': 1182 obs. of 9 variables:
$ Farm : chr "AL" "AL" "AL" "AL" ...
$ Month : int 10 10 10 10 10 10 10 10 10 10 ...
$ Year : int 0 0 0 0 0 0 0 0 0 0 ...
$ Sex : int 1 1 1 1 1 1 1 1 1 1 ...
$ clas1_4: int 4 4 3 4 4 4 4 4 4 4 ...
$ LCT : num 191 180 192 196 204 190 196 200 197 208 ...
$ KFI : num 20.4 16.4 15.9 17.3 NA ...
$ Ecervi : num 0 0 2.38 0 0 0 1.21 0 0.8 0 ...
$ Tb : int 0 0 0 0 NA 0 NA 1 0 0 ...
head(deer)
Farm Month Year Sex clas1_4 LCT KFI Ecervi Tb
1 AL 10 0 1 4 191 20.45 0.00 0
2 AL 10 0 1 4 180 16.40 0.00 0
3 AL 10 0 1 3 192 15.90 2.38 0
4 AL 10 0 1 4 196 17.30 0.00 0
5 AL 10 0 1 4 204 NA 0.00 NA
6 AL 10 0 1 4 190 16.30 0.00 0
1. t-test: Legolas vs Aragorn & Legolas vs Gimli
# Simulate actor heights using the lecture setupset.seed(5680)aragorn <-rnorm(50, mean =180, sd =10)gimli <-rnorm(50, mean =132, sd =15)legolas <-rnorm(50, mean =195, sd =15)# Compare Legolas and Aragornt.test(legolas, aragorn, alternative ="two.sided")
Welch Two Sample t-test
data: legolas and aragorn
t = 7.134, df = 97.754, p-value = 1.713e-10
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
13.34126 23.62431
sample estimates:
mean of x mean of y
196.0965 177.6137
# Compare Legolas and Gimlit.test(legolas, gimli, alternative ="two.sided")
Welch Two Sample t-test
data: legolas and gimli
t = 22.38, df = 97.867, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
55.17697 65.91455
sample estimates:
mean of x mean of y
196.0965 135.5507
Legolas vs Aragorn
(p < 0.05) Therefore, there is a statistically significant difference between the Legolas and Aragorn actor groups.
Legolas vs Gimli
(p < 0.05) Therefore, there is a statistically significant difference between the Legolas and Gimli actor groups.
2. F-test: Gimli vs Legolas
# Compare the variances of Gimli and Legolasvar.test(gimli, legolas)
F test to compare two variances
data: gimli and legolas
F = 1.0767, num df = 49, denom df = 49, p-value = 0.797
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.6109822 1.8972882
sample estimates:
ratio of variances
1.076666
Gimli vs Legolas
(p > 0.05) Therefore, there is no statistically significant difference in variance between the Gimli and Legolas actor groups.
3. Correlation tests: Sepal Length and Sepal Width by Species
# Split the iris data by speciessetosa <-subset(iris_data, Species =="setosa")versicolor <-subset(iris_data, Species =="versicolor")virginica <-subset(iris_data, Species =="virginica")# Correlation test for setosacor.test(setosa$Sepal.Length, setosa$Sepal.Width)
Pearson's product-moment correlation
data: setosa$Sepal.Length and setosa$Sepal.Width
t = 7.6807, df = 48, p-value = 6.71e-10
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.5851391 0.8460314
sample estimates:
cor
0.7425467
# Correlation test for versicolorcor.test(versicolor$Sepal.Length, versicolor$Sepal.Width)
Pearson's product-moment correlation
data: versicolor$Sepal.Length and versicolor$Sepal.Width
t = 4.2839, df = 48, p-value = 8.772e-05
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.2900175 0.7015599
sample estimates:
cor
0.5259107
# Correlation test for virginicacor.test(virginica$Sepal.Length, virginica$Sepal.Width)
Pearson's product-moment correlation
data: virginica$Sepal.Length and virginica$Sepal.Width
t = 3.5619, df = 48, p-value = 0.0008435
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.2049657 0.6525292
sample estimates:
cor
0.4572278
Setosa
(p < 0.05) Therefore, Sepal Length and Sepal Width are significantly correlated in Setosa.
Versicolor
(p < 0.05) Therefore, Sepal Length and Sepal Width are significantly correlated in Versicolor.
Virginica
(p < 0.05) Therefore, Sepal Length and Sepal Width are significantly correlated in Virginica.
4. Chi-squared tests: Deer Data
# Test whether deer caught per month are uniformly distributedmonth_counts <-table(factor(deer$Month, levels =1:12))month_counts