Exercise 1

  1. In one sample t-test, it is assumed that the data ~ N(\(\mu\), \(\sigma\)) and we wish to test that the null hypothesis \(H_0: \mu=\mu_0\)

Here is the daily energy intake for 11 women in KJ: 5260, 5470, 6180, 6340, 6180, 6515, 6805, 7515, 7515, 8230, 8770. Create a vector from this data.

dailyIntake <- c(5260, 5470, 6180, 6340, 6180, 6515, 6805, 7515, 7515, 8230, 8770)
  1. Find mean, standard deviation, and quartiles of the above data.
mean(dailyIntake)
## [1] 6798.182
sd(dailyIntake)
## [1] 1102.287
quantile(dailyIntake)
##   0%  25%  50%  75% 100% 
## 5260 6180 6515 7515 8770
  1. Given that \(\mu_0=7725\) KJ. Do the following t-test with \(H_0:mu=7725\)
t.test(dailyIntake, mu=7725)
## 
##  One Sample t-test
## 
## data:  dailyIntake
## t = -2.7887, df = 10, p-value = 0.01916
## alternative hypothesis: true mean is not equal to 7725
## 95 percent confidence interval:
##  6057.655 7538.708
## sample estimates:
## mean of x 
##  6798.182
  1. Result and Conclusion:
    1. What is the t score? The t score is -2.7887
    2. What do you interpret from p value? p < 0.05, that means that the data deviates significally from the mean 7725. we can reject the null hypothesis and support the claim of the alternative hypothesis that the true mean is not 7725.

Exercise 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 1. Store the data in a dataframe(add stringsAsFactors = FALSE)

american.bp <- c(3, 5, 2, 1, 4, 4, 6, 3, 5, 4)
european.bp <- c(6, 5, 7, 7, 6, 3, 4, 6, 5, 4)
bp.survey <- data.frame("bp" = c(american.bp, european.bp), "group"=rep(c("American",  "European"), each = 10), stringsAsFactors = FALSE)
  1. New graphing! Install the package “yarrr”
library(yarrr)
yarrr::pirateplot(bp~group, data= bp.survey, ylab="Number of Body Piercings", xlab="Group", main= "Body Piercing Survey", theme= 2, point.o=0.8, cap.beans= TRUE)

  1. Conduct a two-sided t-test comparing the vectors American and European and save the results in an object called bp.test
bp.test <- t.test(x=american.bp, y=european.bp, alternative = "two.sided")
bp.test
## 
##  Welch Two Sample t-test
## 
## data:  american.bp and european.bp
## 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, 26, 36

  1. Create a data frame with the vectors old and young
old <- c(45, 38, 52, 48, 25, 39, 51, 46, 55, 46)
young <- c(34, 22, 15, 27, 37, 41, 24, 19, 26, 36)
oy.survey <- data.frame(old, young)
  1. Do the two sample t-test and print the results.
t.test(old,young)
## 
##  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
  1. Graph with cap.beans the two arrays:
    • xlab: old and young
    • ylab: Age
    • Title: Life Satisfaction Survey
yarrr::pirateplot(old~young, data=oy.survey, xlab= "Old and Young", ylab= "Age", main= "Life Satisfaction Survey")