This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
pirates <- read.table ("http://nathanieldphillips.com/wp-content/uploads/2015/05/pirate_survey_noerrors.txt",sep = "\t", header = T, stringsAsFactors = F)
results.age <- t.test(x=pirates$age, mu=25, alternative = "t")
results.age$statistic
## t
## 14.5068
results.age$p.value
## [1] 2.044261e-43
results.age$conf.int
## [1] 27.28634 28.00166
## attr(,"conf.level")
## [1] 0.95
# t = 14.5068, df = 999
# p-value < 2.2e-16
#95 percent confidence interval:27.28634 28.00166
# alternative hypothesis: true mean is not equal to 25
# conclusion: the mean age is significantly different from 25 (two.tailed test).
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.
results.parrots <- t.test(x=pirates$parrots.lifetime, mu=2.7, alternative = "t")
results.parrots
##
## One Sample t-test
##
## data: pirates$parrots.lifetime
## t = 0.7298, df = 999, p-value = 0.4657
## alternative hypothesis: true mean is not equal to 2.7
## 95 percent confidence interval:
## 2.586837 2.947163
## sample estimates:
## mean of x
## 2.767
#APA-Style t(999) = 0,7298, p= 0,47, 95% CI =[-2.59,2.95], two-tailed test
#conclusion: The mean number of parrots is not different from 2.7.
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.
college.swordspeed <-t.test(formula = sword.speed ~ college, subset=college %in% c("CCCC","JSSFP"), data = pirates, alternative = "l")
college.swordspeed
##
## Welch Two Sample t-test
##
## data: sword.speed by college
## t = -1.4524, df = 540.345, p-value = 0.07348
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf 0.03610759
## sample estimates:
## mean in group CCCC mean in group JSSFP
## 1.068027 1.336603
#APA-Style t(540) = -1.4524, p= 0,07348, 95% CI =[1.068027,1.336603], one-tailed test
#conclusion: Pirates from the CCCC do not have a faster sword.speed than those of the JSSFP college as the p value is not significant.
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.
#first way t.test(x,y)
tattoos.Blackbeard <- subset(pirates, favorite.pirate == "Blackbeard")$tattoos
tattoos.JackSparrow <- subset(pirates, favorite.pirate == "Jack Sparrow")$tattoos
tattoos.favorite.pirate <- t.test(x = tattoos.Blackbeard,
y = tattoos.JackSparrow, alternative = "g")
tattoos.favorite.pirate
##
## Welch Two Sample t-test
##
## data: tattoos.Blackbeard and tattoos.JackSparrow
## t = 0.0333, df = 137.3, p-value = 0.4867
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
## -0.6302564 Inf
## sample estimates:
## mean of x mean of y
## 9.620000 9.607064
# g because the text says more
#second way t.test(formula, data)
favorite.pirate.tattoos<-t.test(formula = tattoos ~ favorite.pirate, subset=favorite.pirate %in% c("Blackbeard","Jack Sparrow"), data = pirates, alternative = "g")
favorite.pirate.tattoos
##
## Welch Two Sample t-test
##
## data: tattoos by favorite.pirate
## t = 0.0333, df = 137.3, p-value = 0.4867
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
## -0.6302564 Inf
## sample estimates:
## mean in group Blackbeard mean in group Jack Sparrow
## 9.620000 9.607064
#APA-Style t(137.3) =0.0333 ,p= 0.4867 95% CI =[-0.6302564,Inf],
#conclusion: Pirates whose favorite pirate is Blackbeard have not significantly more tattoos than those pirates whose favorite pirate is Jack Sparrow (one.tailed test).
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.
age.treasure <- cor.test(x = pirates$age,
y = pirates$tchests.found)
age.treasure
##
## 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
#r(998) = 0.09, p< .01
#conclusion: There is a positive significant (but small) relation between pirates age and the number of tresures chests found.
subset.parrots10 <- subset(pirates, parrots.lifetime < 10 & favorite.pirate == "Jack Sparrow")
age.treasure2 <- cor.test(x =subset.parrots10$age,
y = subset.parrots10$tchests.found)
age.treasure2
##
## Pearson's product-moment correlation
##
## data: subset.parrots10$age and subset.parrots10$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
#conclusion:There is not significant correlation between age and treasures found for this subset (pirats who own less than 10 parrots and have Jack Sparrow as a favorite).
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