pirates <- read.table("http://nathanieldphillips.com/wp-content/uploads/2015/05/pirate_survey_noerrors.txt", sep = "\t", header = T, stringsAsFactors = F)
#pirates
head(pirates)
## id sex headband age college tattoos tchests.found parrots.lifetime
## 1 1 female yes 35 JSSFP 18 8 9
## 2 2 male yes 21 CCCC 6 5 1
## 3 3 female yes 27 CCCC 12 8 1
## 4 4 male yes 19 CCCC 9 8 1
## 5 5 male yes 31 CCCC 11 2 13
## 6 6 male yes 21 CCCC 7 1 0
## favorite.pirate sword.type sword.speed
## 1 Blackbeard cutlass 0.0638977084
## 2 Blackbeard cutlass 0.5601675763
## 3 Anicetus cutlass 0.0005400172
## 4 Jack Sparrow cutlass 3.8770396912
## 5 Jack Sparrow cutlass 0.5080594239
## 6 Jack Sparrow cutlass 0.6248019344
#2 - Conduct a one-sample t-test to test whether or not the mean age of pirates is significantly different from 25. What is the test statistic, p-value, and 95% confidence interval? (Note: access these directly from the object, don’t type them manually). What is your conclusion?
t.test(x = pirates$age,
mu=25,
alternative= "g")
##
## One Sample t-test
##
## data: pirates$age
## t = 14.507, df = 999, p-value < 2.2e-16
## alternative hypothesis: true mean is greater than 25
## 95 percent confidence interval:
## 27.34393 Inf
## sample estimates:
## mean of x
## 27.644
#t(999)= 14.507, p<0.001, 95% CI= [27.344, Inf]
#3 - Conduct a one-sample t-test to test whether or not the mean number of parrots owned by pirates is different from 2.7. What is the test statistic, p-value, and 95% confidence interval? (Note: access these directly from the object, don’t type them manually). Write the conclusion using APA style.
t.test(x = pirates$parrots.lifetime,
mu= 2.7,
alternative= "g" )
##
## One Sample t-test
##
## data: pirates$parrots.lifetime
## t = 0.72977, df = 999, p-value = 0.2329
## alternative hypothesis: true mean is greater than 2.7
## 95 percent confidence interval:
## 2.615845 Inf
## sample estimates:
## mean of x
## 2.767
# t(999) = 0.729, p = 0.233, 95% CI = [2.616, Inf]
#4 - A pirate from Captain Chunk’s Canon Crew (CCCC) claims that pirates from his college have faster sword speeds than pirates from Jack Sparrow’s School of Fashion and Piratry (JSSFP). Test this claim by conducting the appropriate (one-tailed!) two-sample test and report the result using APA format.
swordspeed.CCCC <- subset(pirates, subset = college == "CCCC")$sword.speed
swordspeed.JSSFP <- subset(pirates, subset = college == "JSSFP")$sword.speed
test.result <- t.test(x= swordspeed.CCCC,
y= swordspeed.JSSFP,
alternative = "g")
test.result
##
## Welch Two Sample t-test
##
## data: swordspeed.CCCC and swordspeed.JSSFP
## t = -1.4524, df = 540.34, p-value = 0.9265
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
## -0.5732584 Inf
## sample estimates:
## mean of x mean of y
## 1.068027 1.336603
# t(540.34) = -1.453, p = 0.9265, 95% CI = [-0.573, Inf]
#True difference in means greater than 0!
#5 - According to a recent blog post on Piratebook, pirates whose favorite pirate is Blackbeard have more tattoos than pirates whose favorite pirate is Jack Sparrow. Test this claim by conducting the appropriate test and reporting the result in APA format. Important! Do this test once using the t.test(x, y) notation, and once using the t.test(formula, data) notation.
favoritepirate.blackbeard <- subset(pirates, subset = favorite.pirate =="Blackbeard")$tattoos
favoritepirate.jacksparrow <- subset(pirates, subset = favorite.pirate =="Jack Sparrow")$tattoos
test.result <- t.test (x = favoritepirate.blackbeard,
y = favoritepirate.jacksparrow,
alternative = "l")
test.result
##
## Welch Two Sample t-test
##
## data: favoritepirate.blackbeard and favoritepirate.jacksparrow
## t = 0.033306, df = 137.3, p-value = 0.5133
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf 0.6561283
## sample estimates:
## mean of x mean of y
## 9.620000 9.607064
test.result <- t.test(formula = tattoos ~ favorite.pirate,
subset = favorite.pirate %in% c("Jack Sparrow", "Blackbeard"),data = pirates, alternative= "l")
test.result
##
## Welch Two Sample t-test
##
## data: tattoos by favorite.pirate
## t = 0.033306, df = 137.3, p-value = 0.5133
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf 0.6561283
## sample estimates:
## mean in group Blackbeard mean in group Jack Sparrow
## 9.620000 9.607064
# t(137.3) = 0.033, p = 0.513, 95% CI [-Inf, 0.656]
# True difference in meand is less than 0
#6 - Is there a relationship between a pirate’s age and the number of treasure chests he/she’s found? Test this by conducting the appropriate test and report your results in APA format.
test.result <- cor.test(x = pirates$age,
y = pirates$tchests.found)
test.result
##
## Pearson's product-moment correlation
##
## data: pirates$age and pirates$tchests.found
## t = 2.8263, df = 998, p-value = 0.004802
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.02726784 0.15027323
## sample estimates:
## cor
## 0.08911029
# t(998)=2.826, p = 0.005, 95% CI = [0.027, 0.150]
# True correlation is not equal to 0!
#7 - Repeat the previous test just for pirates who have owned less than 10 parrots and whose favorite pirate is Jack Sparrow. Report your results in APA format.
head(pirates)
## id sex headband age college tattoos tchests.found parrots.lifetime
## 1 1 female yes 35 JSSFP 18 8 9
## 2 2 male yes 21 CCCC 6 5 1
## 3 3 female yes 27 CCCC 12 8 1
## 4 4 male yes 19 CCCC 9 8 1
## 5 5 male yes 31 CCCC 11 2 13
## 6 6 male yes 21 CCCC 7 1 0
## favorite.pirate sword.type sword.speed
## 1 Blackbeard cutlass 0.0638977084
## 2 Blackbeard cutlass 0.5601675763
## 3 Anicetus cutlass 0.0005400172
## 4 Jack Sparrow cutlass 3.8770396912
## 5 Jack Sparrow cutlass 0.5080594239
## 6 Jack Sparrow cutlass 0.6248019344
test.result2 <- cor.test (formula= ~ age + tchests.found,
subset = favorite.pirate %in% c("Jack Sparrow") & parrots.lifetime < 10,
data = pirates,
alternative = "two.sided")
test.result2
##
## Pearson's product-moment correlation
##
## data: age and tchests.found
## t = 1.88, df = 437, p-value = 0.06077
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.004053305 0.181639084
## sample estimates:
## cor
## 0.08957122
# t(437) = 1.88, p = 0.061, 95% CI [-0.004, 0.182]
# True correlation is not equal to 0
#8 - Is there a relationship between the college a pirate went to and his favorite pirate? Test this by conducting the appropirate test and report your results in APA format
test.results <- with(pirates, chisq.test(x= college, y= favorite.pirate))
test.results
##
## Pearson's Chi-squared test
##
## data: college and favorite.pirate
## X-squared = 44.596, df = 5, p-value = 1.753e-08
#X-squared(5) = 44.596, p < 0.001