Excercise 1

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

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)
  1. Find mean, standard deviation and quartiles of the above data.
summary(daily.intake)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    5260    5910    6515    6754    7515    8770
  1. Given that \(\mu_0 = 7725\)KJ Do the following t test with \(H_0: \mu = 7725\) t.test(data name ,\(\mu = 7725\))
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
  1. Result and conclusion:
  1. What is the t score? -2.8208
  2. What do you interpret from p values? .01814 < .05 With a 95% confidence we fail to reject the null hypothesis. Which means the data deviates significantly from the mean 7725.

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

  1. Store the data in a dataframe (add stringsAsFactors = FALSE)
  2. New graphing! Install the package “yarr”
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)

  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, 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

  1. Create
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)
  1. Two sample t-test
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
  1. Graph with capp.beans the two arrays
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)