6.8 Manually Computing a t-Test

In a warehouse full of power packs labeled as 12 volts we randomly measure the voltage of 7. Here is the data:

Code
voltage <- c(11.77, 11.90, 11.64, 11.84, 12.13, 11.99,  11.77)
voltage
## [1] 11.77 11.90 11.64 11.84 12.13 11.99 11.77
  1. Find the mean and the standard deviation.
Code
sample_mean <- mean(voltage)
sample_sd   <- sd(voltage)
n           <- length(voltage)

test_statistic <- (sample_mean - 12) / (sample_sd / sqrt(n))
test_statistic
## [1] -2.247806
  1. Using qt(), compute the t critical value for a hypothesis test for this sample.
Code
qt(0.025, df=n-1)
## [1] -2.446912
  1. Define a test statistic, \(t\), for testing whether the population mean is 12.
Code
test_statistic
## [1] -2.247806
  1. Calculate the p-value using the t statistic.
Code
pt(test_statistic, df=n-1)
## [1] 0.03281943
  1. Should you reject the null? Argue this in two different ways. (Following convention, set \(\alpha = .05\).)
Code
test_stat_function <- function(data, null_hypothesis) { 
  sample_mean <- mean(data)
  sample_sd   <- sd(data)
  n           <- length(data)
  
  test_statistic <- (sample_mean - null_hypothesis) / (sample_sd / sqrt(n))
  return(test_statistic)
}
Code
test_stat_function(data=voltage, null_hypothesis=12) %>% 
  pt(df=length(voltage)-1) * 2
## [1] 0.06563885
Code
t.test(
  x           = voltage, 
  alternative = 'two.sided', 
  mu          = 12)
## 
##  One Sample t-test
## 
## data:  voltage
## t = -2.2478, df = 6, p-value = 0.06564
## alternative hypothesis: true mean is not equal to 12
## 95 percent confidence interval:
##  11.71357 12.01215
## sample estimates:
## mean of x 
##  11.86286
  1. Suppose you were to use a normal distribution instead of a t-distribution to test your hypothesis. What would your p-value be for the z-test?

  2. Without actually computing it, say whether a 95% confidence interval for the mean would include 12 volts.

  3. Compute a 95% confidence interval for the mean.