Hypothesis Testing for \(\mu_1-\mu_2\)

Exercise 1. Several neurosurgeons wanted to determine whether a dynamic system (Z-plate) reduced operative time relative to a static system (ALPS plate). The operative times, in minutes, for 14 dynamic replications of the operation and 9 static replications were obtained and are given below. The neurosurgeons believe the collection of all operative times with either device would be roughly normally distributed.

\[Dynamic: 370, 360, 510, 445, 290, 315, 490, 345, 450, 505, 335, 280, 325, 535\] \[Static: 430, 445, 455, 455, 490, 535, 505, 445, 420\]

Numeric summaries of the samples:

System Sample Mean Sample Median Sample Variance Sample Size (n)
Dynamic 396.8 365 7917.72 14
Static 464.4 455 1421.528 9
  1. Graph the data as you see fit. Why did you choose the graph(s) you did? How do those graphs align with the assumption that the populations of operative times are approximately normal that the neurosurgeons think is reasonable?
Dynamic <- c(370, 360, 510, 445, 290, 315, 490, 345,
           450, 505, 335, 280, 325, 535)
Static <- c(430, 445, 455, 455, 490, 535, 505, 445, 420)

# View numeric summaries
summary(Dynamic); var(Dynamic)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   280.0   327.5   365.0   396.8   480.0   535.0
## [1] 7917.72
summary(Static); var(Static)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   420.0   445.0   455.0   464.4   490.0   535.0
## [1] 1421.528
qqnorm(Dynamic)

hist(Dynamic)

qqnorm(Static)

hist(Static)

  1. Perform a two independent sample t test for means at the 5% level allowing the population variances to differ. You can use approximate degrees of freedom 18.882 or 18. As part of this test, specify your hypotheses, calculate a test statistic and p value by hand and make a conclusion in the context of the question. Check your computations with t.test in R.
pt(-2.51497, df=18.882)
## [1] 0.01056356
t.test(Dynamic, Static, mu=0, alternative = 'less', var.equal=F, conf.level=0.05)
## 
##  Welch Two Sample t-test
## 
## data:  Dynamic and Static
## t = -2.5154, df = 18.882, p-value = 0.01055
## alternative hypothesis: true difference in means is less than 0
## 5 percent confidence interval:
##       -Inf -114.1837
## sample estimates:
## mean of x mean of y 
##  396.7857  464.4444
  1. A two-sided t confidence interval for \(\mu_D-\mu_S\) allowing population variances to vary is reported as (-103.38, -31.82). Identify the level of the two-sided confidence interval. You can use the summary measures given earlier, and assume the t degrees of freedom is 18. Interpret this confidence interval in the context of the question.
pt(1.3302, df=18, lower.tail = F)
## [1] 0.1000308
  1. The samples’ data made us less confident in the surgeons’ assumptions that the populations of procedure times were close to normally distributed. So, use the bootstrap code below to perform a bootstrap hypothesis test of the hypotheses \(H_0: \mu_D-\mu_S \ge 0\) vs \(H_A: \mu_D-\mu_S<0\) and compare the assumptions, test statistic, p value, and conclusions of this test to the Welch’s you performed in part (b).
Dynamic <- c(370, 360, 510, 445, 290, 315, 490, 345,
           450, 505, 335, 280, 325, 535)
Static <- c(430, 445, 455, 455, 490, 535, 505, 445, 420)

# 1. Calculate data summaries and t_obs
# Let group 1 = Dynamic, group 2 = Static
xbar1 <- mean(Dynamic)
s1 <- sd(Dynamic)
n1 <- length(Dynamic)
xbar2 <- mean(Static)
s2 <- sd(Static)
n2 <- length(Static)

t_obs <- (xbar1-xbar2)/sqrt((s1^2/n1) + s2^2/n2)
t_obs
## [1] -2.515387
# Specify number of bootstrap samples, create a vector
# to store t_hat values
B <- 5000
t_hat <- numeric(B)

set.seed(371) # set the seed for the random samples to be drawn
# Bootstrap loop
for(i in 1:B){
  # 2. Draw a SRS of size n1/n2 from data, with replacement
  x1_star <- sample(Dynamic, size = n1, replace = T)
  x2_star <- sample(Static, size = n2, replace = T)
  
  # 3. Calculate resampled mean and sd
  xbar1_star <- mean(x1_star)
  s1_star <- sd(x1_star)
  xbar2_star <- mean(x2_star)
  s2_star <- sd(x2_star)
  
  # 4. Calculate t_hat, and store it in vector
  t_hat_numer <- (xbar1_star-xbar2_star) - (xbar1-xbar2)
  t_hat_denom <- sqrt((s1_star^2/n1) + (s2_star^2/n2))
  
  t_hat[i] <- t_hat_numer / t_hat_denom
}


# Compute 1-sided p-value...
t_obs = -2.515387
sum(t_hat < t_obs)/5000
## [1] 0.0122
  1. Suppose after the data is collected it comes to your attention that Surgeon D performed all of the Dynamic system operations and Surgeon S performed all of the Static operations. What, if any, concerns do you have about this method of data collection?

Hypothesis Testing for Paired Data

Exercise 2. Scientists want to know if a specific bean plant variety shows evidence of having a different mean carbohydrate concentration in its shoot than in its root. Six bean plants had their carbohydrate concentration (in percent by weight) measured both in the shoot and in the root. The following results were obtained. A graph of the data is provided.

Plant Shoot Root
1 4.42 3.76
2 5.81 5.40
3 4.65 3.91
4 4.77 4.29
5 5.25 4.69
6 4.75 3.93
Shoot <- c(4.42, 5.81, 4.65, 4.77, 5.25, 4.75)
Root <- c(3.76, 5.40, 3.91, 4.29, 4.69, 3.93)

# Vector of 1's and 2's to separate out the 
# standard/diverse points on the x axis
ones <- rep(1, 6)
twos <- rep(2, 6)


# Plot all points
plot(c(ones, twos), c(Shoot, Root),
     ylim = c(3.5, 6), xlim = c(0.8, 2.2),
     xaxt = "n", xlab = "", ylab = "Percentage")
# Change x-axis labels
axis(1, at = c(1, 2), labels = c("Shoot", "Root"))
# Create lines to join all 8 pairs of points
for(i in 1:6){
  lines(c(1, 2), c(Shoot[i], Root[i]))
}

  1. Explain why we need to consider the sample of differences (Shoot-Root) instead of the two samples of data seperately when making inference. Based on the sampling choice and question of interest, what inference strategies could we consider?
  1. Construct the relevent histogram and qqnorm plots to check the normality assumptions of the matched-pair t test. Explain whether or not the normality assumption of the matched-pair t test seems to be well met.
qqnorm(Root-Shoot)

hist(Root-Shoot)

  1. Does this data give us strong evidence that the mean carbohydrate concentration in the shoot is different than that in the root? Conduct a paired t test of the hypotheses: \(H_0: \mu_{d} = 0\) vs \(H_A: \mu_{d} \neq 0\). Compute the test statistic, degrees of freedom, and p value “by hand”. Check your answers using t.test(). Draw a conclusion in the context of the question at a 1% significance level.
mean(Root-Shoot)
## [1] -0.6116667
sd(Root-Shoot)
## [1] 0.1567695
2*pt(-9.55716, df=5)
## [1] 0.0002123339
t.test(Root, Shoot, mu=0, paired=T, conf.level=0.01)
## 
##  Paired t-test
## 
## data:  Root and Shoot
## t = -9.5572, df = 5, p-value = 0.0002123
## alternative hypothesis: true mean difference is not equal to 0
## 1 percent confidence interval:
##  -0.6125097 -0.6108236
## sample estimates:
## mean difference 
##      -0.6116667
  1. The scientists decide to also perform a Wilcoxon Signed Rank test. The hypotheses are: \(H_0:\) the distributions of carbohydrate concentration is the same for the shoot and the root vs \(H_A:\) the distributions have the same shape but the distribution for Shoot is shifted relative to the one for Root. Perform the test in R and report the test statistic and p value. Compare the evidence against the null to that found with the t test in part (d).
wilcox.test(Root, Shoot, paired = T )
## 
##  Wilcoxon signed rank exact test
## 
## data:  Root and Shoot
## V = 0, p-value = 0.03125
## alternative hypothesis: true location shift is not equal to 0