Excercise 1
Here is the daily energy intake for 11 women in KJ: 5260, 5470, 5640, 6180, 6390, 6515, 6805, 7515, 7515, 8230, 8770. Create a vector from this data.
daily.intake=c(5260, 5470, 5640, 6180, 6390, 6515, 6805, 7515, 7515, 8230, 8770)
summary(daily.intake)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 5260 5910 6515 6754 7515 8770
t.test(daily.intake, mu=7725)
##
## One Sample t-test
##
## data: daily.intake
## t = -2.8208, df = 10, p-value = 0.01814
## alternative hypothesis: true mean is not equal to 7725
## 95 percent confidence interval:
## 5986.348 7520.925
## sample estimates:
## mean of x
## 6753.636
Excercise 2: Body piercing data for
American: 3,5,2,1,4,4,6,3,5,4 European: 6,5,7,7,6,3,4,6,5,4
American = c(3,5,2,1,4,4,6,3,5,4)
European =c(6,5,7,7,6,3,4,6,5,4)
Create the Data Frame
bp.survey = data.frame("bp"=c(American, European),"group"= rep(c("American", "European"), each = 10), stringsAsFactors = FALSE)
library(yarrr)
yarrr::pirateplot(bp~group, data = bp.survey, ylab = "# of Body Piercing", xlab="Group", main="Body Piercing Survey", theme = 2, point.o=0.8, cap.beans = TRUE)
bp.test = t.test(x=American, y = European, alternative = "two.sided")
bp.test
##
## Welch Two Sample t-test
##
## data: American and European
## t = -2.5228, df = 17.783, p-value = 0.0214
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -2.9335927 -0.2664073
## sample estimates:
## mean of x mean of y
## 3.7 5.3
Independent Exercise
Here are the data for old and young ages: Old: 45,38,52,48,25,39,51,46,55,46 Young: 34,22,15,27,37,41,24,19,36,36
old = c(45,38,52,48,25,39,51,46,55,46)
young = c(34,22,15,27,37,41,24,19,26,36)
old_young = data.frame("Age"=c(old, young),"group"= rep(c("Old", "Young"), each = 10), stringsAsFactors = FALSE)
old_young_test = t.test(x = old,y = young, alternative = "two.sided")
old_young_test
##
## Welch Two Sample t-test
##
## data: old and young
## t = 4.2575, df = 17.995, p-value = 0.0004739
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 8.307131 24.492869
## sample estimates:
## mean of x mean of y
## 44.5 28.1
yarrr::pirateplot(Age~group, data = old_young, ylab = "Age", xlab="Old and Young", main="Life Satisfaction Survey", theme = 2, point.o=0.8, cap.beans = TRUE)