Q1
aragorn = rnorm(50, mean=180, sd=10)
gimli = rnorm(50, mean=132, sd=15)
legolas = rnorm(50, mean=195, sd=15)
t.test(legolas, gimli, alternative="two.sided")
##
## Welch Two Sample t-test
##
## data: legolas and gimli
## t = 23.041, df = 97.678, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 55.25330 65.66839
## sample estimates:
## mean of x mean of y
## 192.9446 132.4838
#p-value < 2.2e-16, significant
t.test(legolas, aragorn, alternative="two.sided")
##
## Welch Two Sample t-test
##
## data: legolas and aragorn
## t = 5.084, df = 93.333, p-value = 1.896e-06
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 7.558008 17.245792
## sample estimates:
## mean of x mean of y
## 192.9446 180.5427
#p-value = 9.141e-06, significant
Q2
var.test(legolas,gimli)
##
## F test to compare two variances
##
## data: legolas and gimli
## F = 1.1219, num df = 49, denom df = 49, p-value = 0.6889
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.6366447 1.9769781
## sample estimates:
## ratio of variances
## 1.121888
#p-value = 0.7697, No significant difference.
Q3
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
iris = read.csv("iris.csv")
str(iris)
## 'data.frame': 150 obs. of 6 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : chr "setosa" "setosa" "setosa" "setosa" ...
## $ Code : int 1 1 1 1 1 1 1 1 1 1 ...
setosa = iris %>% filter(Species == "setosa")
versicolor = iris %>% filter(Species == "versicolor")
virginica = iris %>% filter(Species == "virginica")
cor.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
#p-value = 6.71e-10 and cor = 0.742546. Significantly correlated.
cor.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
#p-value = 8.772e-05 and cor = 0.5259107. Significantly correlated.
cor.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
#p-value = 0.0008435 and cor = 0.4572278
cor.test(iris$Sepal.Length, iris$Sepal.Width)
##
## Pearson's product-moment correlation
##
## data: iris$Sepal.Length and iris$Sepal.Width
## t = -1.4403, df = 148, p-value = 0.1519
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.27269325 0.04351158
## sample estimates:
## cor
## -0.1175698
#I wanted to rerun the original for myself, it is interesting to see how the data all interferes with itself when you don't separate out the different species.
Q4
deer = read.csv("Deer.csv")
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
#X-squared = 997.07 and p-value < 2.2e-16, significant
table(deer$Tb)
##
## 0 1
## 784 110
table((deer$Farm))
##
## AL AU BA BE CB CRC HB LCV LN MAN MB MO NC NV PA PN
## 15 37 98 19 93 16 35 2 34 76 41 278 32 35 11 45
## QM RF RN RO SAL SAU SE TI TN VISO VY
## 75 34 25 44 1 3 26 21 31 15 40
chisq.test(table(deer$Tb, deer$Farm))
## Warning in chisq.test(table(deer$Tb, deer$Farm)): Chi-squared approximation may
## be incorrect
##
## Pearson's Chi-squared test
##
## data: table(deer$Tb, deer$Farm)
## X-squared = 129.09, df = 26, p-value = 1.243e-15
#X-squared = 129.09 and p-value = 1.243e-15, significant.