week 7 labs Abhinaya Malempati 1.

#load the data
library(oibiostat)
data("swim")
swim$velocity.diff[1]
## [1] 0.08
#calculate d.bar
d.bar = mean(swim$velocity.diff)
d.bar
## [1] 0.0775
#use r as a calculator
d.bar = mean(swim$velocity.diff)
delta.0 = 0
s.d = sd(swim$velocity.diff)
n = length(swim$velocity.diff)
t.stat = (d.bar - delta.0)/(s.d/sqrt(n))
t.stat
## [1] 12.31815
#calculate the p-value
2*pt(t.stat, df = n - 1, lower.tail = FALSE)
## [1] 8.885414e-08
## [1] 8.885414e-08
#use r as a calculator
d.bar = mean(swim$velocity.diff)
s.d = sd(swim$velocity.diff)
n = length(swim$velocity.diff)
t.star = qt(0.975, df = n - 1)
m = t.star * (s.d/sqrt(n))
d.bar - m; d.bar + m
## [1] 0.06365244
## [1] 0.09134756
#two-sample syntax
t.test(swim$wet.suit.velocity, swim$swim.suit.velocity, 
       alternative = "two.sided", paired = TRUE)
## 
##  Paired t-test
## 
## data:  swim$wet.suit.velocity and swim$swim.suit.velocity
## t = 12.318, df = 11, p-value = 8.885e-08
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  0.06365244 0.09134756
## sample estimates:
## mean difference 
##          0.0775
#alternatively, one-sample syntax
t.test(swim$velocity.diff, mu = 0, alternative = "two.sided")
## 
##  One Sample t-test
## 
## data:  swim$velocity.diff
## t = 12.318, df = 11, p-value = 8.885e-08
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.06365244 0.09134756
## sample estimates:
## mean of x 
##    0.0775
t.test(swim$wet.suit.velocity, swim$swim.suit.velocity,
mu = 0, alternative = "two.sided", paired = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  swim$wet.suit.velocity and swim$swim.suit.velocity
## t = 1.3688, df = 21.974, p-value = 0.1849
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.03992937  0.19492937
## sample estimates:
## mean of x mean of y 
##  1.506667  1.429167

When the swim data is analyzed as if it were independent two-group data, the p-value is 0.31, which is greater than the standard significance threshold of 0.05. As a result, the data do not significantly diverge from the null hypothesis, which holds that there is no obvious difference in swim velocities between groups. The 95% confidence interval for the difference in mean swim velocities is -0.0399 to 0.1949. This interval includes zero, confirming that there is no statistically significant difference in mean swim velocities between the two groups. The average swim velocity for athletes wearing wetsuits is around 1.506667 m/s, whereas the average swim velocity for athletes wearing swimsuits is around 1.429167 m/s. The p-value, which above the conventional significance level, indicates that this variation in means is not statistically significant. According to this data, there is no compelling evidence that the new wetsuit design increased swim velocities during the 2000 Olympics.

#load the data
library(oibiostat)
data("dds.discr")
log_expenditures <- log(dds.discr$expenditures)
ethnic_group <- ifelse(dds.discr$ethnicity == "Hispanic", "Hispanic", "White Non-Hispanic")
t.test(log_expenditures ~ ethnic_group, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  log_expenditures by ethnic_group
## t = -9.0168, df = 998, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group Hispanic and group White Non-Hispanic is not equal to 0
## 95 percent confidence interval:
##  -0.9244775 -0.5940060
## sample estimates:
##           mean in group Hispanic mean in group White Non-Hispanic 
##                         8.558491                         9.317733
mean(log_expenditures[ethnic_group == "Hispanic"])
## [1] 8.558491
mean(log_expenditures[ethnic_group == "White Non-Hispanic"])
## [1] 9.317733

a.The 95% confidence interval for the difference in mean log-expenditures between Hispanics and White Non-Hispanics is (-0.9244775, -0.5940060).

b.The mean log-expenditures for Hispanics is 8.558491, and for White Non-Hispanics is 9.317733.

  1. If age is a factor, do two separate t-tests for the two largest age cohorts (13-17 and 22-50) to test the null hypothesis of no change in mean expenditures. The result includes a t-value and a p-value, which can be used to determine the significance of the differences.