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)
mean(dailyIntake)
## [1] 6798.182
sd(dailyIntake)
## [1] 1102.287
quantile(dailyIntake)
## 0% 25% 50% 75% 100%
## 5260 6180 6515 7515 8770
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
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)
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)
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
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
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)
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
yarrr::pirateplot(old~young, data=oy.survey, xlab= "Old and Young", ylab= "Age", main= "Life Satisfaction Survey")