Exercise 1:

  1. In one sample t-test, it is assumet that the ~N(\(\mu\),\(\sigma\)) and we wish to test the null hypothesis \(H_0:\mu=\mu_0\)
womenEnergyIntake <- c(5260,5470,6180,6390,6515,6805,7515,7515,8230,8770)


2. Mean:

mean(womenEnergyIntake)
## [1] 6865

Standard Deviation:

sd(womenEnergyIntake)
## [1] 1139.213

Quartiles:

quantile(womenEnergyIntake)
##     0%    25%    50%    75%   100% 
## 5260.0 6232.5 6660.0 7515.0 8770.0


3.Given that \(\mu_0 = 7725\)KJ Do the following t-test with \(H_0:\mu\)= 7725

t.test(womenEnergyIntake, mu= 7725)
## 
##  One Sample t-test
## 
## data:  womenEnergyIntake
## t = -2.3872, df = 9, p-value = 0.04074
## alternative hypothesis: true mean is not equal to 7725
## 95 percent confidence interval:
##  6050.056 7679.944
## sample estimates:
## mean of x 
##      6865


4. Result and Conclusion:
(a) What is the t score? t = -2.3872
(b) What do you interpret from p value? We reject the null hypothesis.

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

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)

1.Create the data frame

bp.survey <- data.frame("bp"=c(American.bp, European.bp),"group"=rep(c("American","European"), each=10), stringAsfactors = FALSE)


2.Graphing using yarr

library(yarrr)
yarrr::pirateplot(bp~group, data=bp.survey, ylab= "Number of Body Piercing", xlab="Group", main="Body Piercing Survey", theme=2, point.o = .8, cap.beans = TRUE)


3.Two-sided 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)
ages <- data.frame("age"=c(old, young),"group"=rep(c("Old","Young"), each=10), stringAsfactors = FALSE)


2.Two sample t-test:

t.test(x=old, y=young, alternative = "two.sided")
## 
##  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


3. Graph with cap.beans and the two arrays.

yarrr::pirateplot(age~group, data=ages, ylab= "Age", xlab="Old and Young", main="Life Satisfaction Survey", theme=2, point.o = .8, cap.beans = TRUE)