Lab 7: Hypothesis Testing for Large Samples

Author

Instructor Name

Published

September 6, 2025

Student Name:

Introduction: Large Sample Hypothesis Testing

This laboratory focuses exclusively on hypothesis testing procedures for large samples (n ≥ 30). We will explore the complete hypothesis testing framework and apply t-tests for mean comparisons, leveraging the Central Limit Theorem which provides robustness to distributional assumptions in large samples.

Learning Objectives

Upon completion of this laboratory, students will be able to:

  • Understand and apply the eight-step hypothesis testing framework
  • Perform one-sample t-tests for large samples
  • Interpret hypothesis test results in practical contexts
  • Calculate tests using both raw data and summary statistics
  • Understand the role of the Central Limit Theorem in large sample inference
  • Construct and interpret confidence intervals for population means

Time Allocation (Total: 90 minutes)

  • Part 1: Hypothesis Testing Framework (30 minutes)
  • Part 2: Large Sample Applications (30 minutes)
  • Part 3: Confidence Intervals and Practical Interpretation (30 minutes)

Part 1: Hypothesis Testing Framework

1.1 The Eight-Step Hypothesis Testing Framework

A systematic approach to hypothesis testing ensures comprehensive and reproducible analysis:

  1. Problem Description: State null and alternative hypotheses in practical context
    • Example: “The mean height of first graders exceeds 42 inches”
    • Importance: Connects statistical analysis to real-world questions
  2. Symbolic Formulation: Express hypotheses using standard statistical notation
    • Example: H₀: μ = 42, H₁: μ > 42
    • Importance: Provides precise mathematical specification
  3. Significance Level: Specify the Type I error tolerance (α)
    • Typical value: α = 0.05 (5% risk of false positive)
    • Importance: Controls the probability of rejecting a true null hypothesis
  4. Test Selection: Choose appropriate statistical test and verify assumptions
    • For large samples: t-test (Central Limit Theorem provides robustness)
    • Assumptions: Random sampling, independence, large sample size (n ≥ 30)
  5. Decision Rule: Define rejection criteria based on test statistics or p-values
    • Example: Reject H₀ if p-value < 0.05
    • Importance: Provides objective decision-making criteria
  6. Test Execution: Perform the statistical test and obtain results
    • Components: Test statistic, p-value, confidence interval
    • Importance: Actual computation of statistical evidence
  7. Conclusion: State decision in context of the original problem
    • Example: “Evidence suggests mean height exceeds 42 inches”
    • Importance: Connects statistical results back to research question
  8. Error Analysis: Discuss potential Type I or Type II errors
    • Type I: False positive (rejecting true H₀)
    • Type II: False negative (failing to reject false H₀)
    • Importance: Acknowledges limitations and uncertainty

1.2 Large Sample Hypothesis Testing (n ≥ 30)

For large samples, we primarily use: - T-test: When population standard deviation is unknown (uses sample s)

The Central Limit Theorem ensures sampling distribution normality for large samples regardless of population distribution shape, making t-tests robust for n ≥ 30.

1.3 Data Import and Preparation

# Load first grade data for large sample analysis
# Data URL: https://math214.netlify.app/data/Lab7/firstgrade.csv
firstgrade_data <- read.csv("../data/Lab7/firstgrade.csv")

# Create summary statistics function
create_summary_stats <- function(data) {
  data %>%
    pivot_longer(cols = c(Height, Weight),
                 names_to = "Variable",
                 values_to = "Value") %>%
    group_by(Variable) %>%
    summarise(
      Sample_Size = n(),
      Mean = mean(Value),
      SD = sd(Value),
      Min = min(Value),
      Q1 = quantile(Value, 0.25),
      Median = median(Value),
      Q3 = quantile(Value, 0.75),
      Max = max(Value),
      IQR = IQR(Value)
    ) %>%
    mutate(across(where(is.numeric), ~round(., 2)))
}

# Generate comprehensive summary using group_by()
summary_stats <- create_summary_stats(firstgrade_data)

summary_stats |> knitr::kable(caption= "First Grade Data Summary Statistics")
First Grade Data Summary Statistics
Variable Sample_Size Mean SD Min Q1 Median Q3 Max IQR
Height 73 43.91 8.33 30 38.5 43.50 48.0 72 9.5
Weight 73 43.57 2.96 31 42.0 43.75 45.5 51 3.5
# Display built-in summary for comparison
tibble(
  Summary = names(summary(firstgrade_data$Height)),
  Height = as.character(summary(firstgrade_data$Height))
) |> knitr::kable(caption= "Built-in Summary for Height")
Built-in Summary for Height
Summary Height
Min. 30
1st Qu. 38.5
Median 43.5
Mean 43.9075342465753
3rd Qu. 48
Max. 72
tibble(
  Summary = names(summary(firstgrade_data$Weight)),
  Weight = as.character(summary(firstgrade_data$Weight))
) |> knitr::kable(caption= "Built-in Summary for Weight")
Built-in Summary for Weight
Summary Weight
Min. 31
1st Qu. 42
Median 43.75
Mean 43.5650684931507
3rd Qu. 45.5
Max. 51

Part 2: Large Sample Applications

2.1 T-test Implementation

For large samples, the t-test is appropriate regardless of population distribution shape due to the Central Limit Theorem:

# Example t-test for height data
test_result <- t.test(firstgrade_data$Height, mu = 42, alternative = "greater", conf.level = 0.95)

# Create results table
test_results_table <- tibble(
  Component = c("Test Statistic", "P-value", "Sample Mean", "Confidence Interval Lower", "Confidence Interval Upper"),
  Value = c(
    round(test_result$statistic, 3),
    round(test_result$p.value, 4),
    round(test_result$estimate, 2),
    round(test_result$conf.int[1], 2),
    round(test_result$conf.int[2], 2)
  )
)

test_results_table |> knitr::kable(caption= "One-Sample T-Test Results")
One-Sample T-Test Results
Component Value
Test Statistic 1.9560
P-value 0.0272
Sample Mean 43.9100
Confidence Interval Lower 42.2800
Confidence Interval Upper Inf
# Display full test output for reference
test_result

    One Sample t-test

data:  firstgrade_data$Height
t = 1.9558, df = 72, p-value = 0.02718
alternative hypothesis: true mean is greater than 42
95 percent confidence interval:
 42.28236      Inf
sample estimates:
mean of x 
 43.90753 

2.2 Using Built-in Test Summaries

R provides comprehensive test summaries that can be converted into tables:

# Function to create test summary table
create_test_summary <- function(test_result, variable_name) {
  tibble(
    Variable = variable_name,
    Test_Statistic = round(test_result$statistic, 3),
    P_Value = round(test_result$p.value, 4),
    Sample_Mean = round(test_result$estimate, 2),
    CI_Lower = round(test_result$conf.int[1], 2),
    CI_Upper = round(test_result$conf.int[2], 2),
    Degrees_Freedom = test_result$parameter
  )
}

# Perform tests and create summary tables
height_test <- t.test(firstgrade_data$Height, mu = 42, alternative = "greater")
weight_test <- t.test(firstgrade_data$Weight, mu = 43, alternative = "greater")

# Create comprehensive test summary table
test_summary <- bind_rows(
  create_test_summary(height_test, "Height"),
  create_test_summary(weight_test, "Weight")
)

test_summary |> knitr::kable(caption= "Comprehensive Test Summary Table")
Comprehensive Test Summary Table
Variable Test_Statistic P_Value Sample_Mean CI_Lower CI_Upper Degrees_Freedom
Height 1.956 0.0272 43.91 42.28 Inf 72
Weight 1.630 0.0538 43.57 42.99 Inf 72
# Display built-in test summaries
height_test

    One Sample t-test

data:  firstgrade_data$Height
t = 1.9558, df = 72, p-value = 0.02718
alternative hypothesis: true mean is greater than 42
95 percent confidence interval:
 42.28236      Inf
sample estimates:
mean of x 
 43.90753 
weight_test

    One Sample t-test

data:  firstgrade_data$Weight
t = 1.6297, df = 72, p-value = 0.05376
alternative hypothesis: true mean is greater than 43
95 percent confidence interval:
 42.98732      Inf
sample estimates:
mean of x 
 43.56507 

Part 3: Confidence Intervals and Practical Interpretation

3.1 Confidence Intervals for Means

Confidence intervals provide range estimates for population parameters:

# Function to calculate confidence intervals
calculate_ci <- function(data, variable_name) {
  var_data <- data[[variable_name]]
  n <- length(var_data)
  mean_val <- mean(var_data)
  se <- sd(var_data) / sqrt(n)
  margin <- qt(0.975, n-1) * se

  tibble(
    Variable = variable_name,
    Mean = round(mean_val, 2),
    SE = round(se, 3),
    Lower_Bound = round(mean_val - margin, 2),
    Upper_Bound = round(mean_val + margin, 2),
    Width = round(2 * margin, 2)
  )
}

# Calculate confidence intervals for both variables
ci_summary <- bind_rows(
  calculate_ci(firstgrade_data, "Height"),
  calculate_ci(firstgrade_data, "Weight")
)


ci_summary
# A tibble: 2 × 6
  Variable  Mean    SE Lower_Bound Upper_Bound Width
  <chr>    <dbl> <dbl>       <dbl>       <dbl> <dbl>
1 Height    43.9 0.975        42.0        45.8  3.89
2 Weight    43.6 0.347        42.9        44.3  1.38
# Using t.test for comparison
t.test(firstgrade_data$Height)$conf.int
[1] 41.96326 45.85181
attr(,"conf.level")
[1] 0.95
t.test(firstgrade_data$Weight)$conf.int
[1] 42.87388 44.25626
attr(,"conf.level")
[1] 0.95

3.2 Summary Statistics Testing

When only summary statistics are available, we can still perform hypothesis tests:

# Example using summary statistics
summary_test <- tsum.test(mean.x = 6.45, s.x = 4, n.x = 45,
          alternative = 'greater', mu = 6, conf.level = 0.95)

# Create summary statistics test table
summary_test_table <- tibble(
  Component = c("Sample Mean", "Sample SD", "Sample Size", "Test Statistic", "P-value", "Confidence Interval Lower", "Confidence Interval Upper"),
  Value = c(
    6.45,
    4,
    45,
    round(summary_test$statistic, 3),
    round(summary_test$p.value, 4),
    round(summary_test$conf.int[1], 2),
    round(summary_test$conf.int[2], 2)
  )
)


summary_test_table
# A tibble: 7 × 2
  Component                  Value
  <chr>                      <dbl>
1 Sample Mean                6.45 
2 Sample SD                  4    
3 Sample Size               45    
4 Test Statistic             0.755
5 P-value                    0.227
6 Confidence Interval Lower  5.45 
7 Confidence Interval Upper NA    
summary_test

    One-sample t-Test

data:  Summarized x
t = 0.75467, df = 44, p-value = 0.2272
alternative hypothesis: true mean is greater than 6
95 percent confidence interval:
 5.448104       NA
sample estimates:
mean of x 
     6.45 

Assessment (Total: 50 points)

Section A: Formative Understanding (15 points)

A1. Explain the complete eight-step hypothesis testing framework. Discuss why each step is important and provide examples of common mistakes made at each stage. (4 points)

A2. Explain the Central Limit Theorem and its importance in large sample hypothesis testing. Why does the CLT make t-tests robust for n ≥ 30, even when the population distribution is non-normal? (4 points)

A3. Compare and contrast the z-test and t-test procedures. When should each be used, and what are the key assumptions underlying each method? Include discussion of when the t-distribution approaches the normal distribution. (4 points)

A4. Discuss the interpretation of confidence intervals in hypothesis testing. How do confidence intervals complement p-values in providing a complete picture of statistical results? (3 points)

Section B: Application and Analysis (20 points)

B1. The state department of education claims the mean height of first graders is 42 inches. A researcher believes the mean height in their region exceeds 42 inches. Using the first grade height data with α = 0.05, conduct a complete hypothesis test following the eight-step framework. (5 points)

# Your code and analysis here

B2. Repeat the analysis for first grade weights, testing the claim that the mean weight exceeds 43 pounds with α = 0.05. Compare your results with the height analysis and discuss any differences in statistical significance. (5 points)

# Your code and analysis here

B3. Construct and interpret 95% confidence intervals for both the mean height and mean weight of first graders. Discuss what these intervals tell us about the precision of our estimates and how they relate to the hypothesis tests conducted in B1 and B2. (5 points)

# Your code and analysis here

B4. Generate summary statistics tables for both height and weight data. Create a comprehensive comparison table that includes mean, standard deviation, and sample size. Discuss how these descriptive statistics inform the hypothesis testing results. (5 points)

# Your code and analysis here

Section C: Statistical Synthesis (15 points)

C1. Write a comprehensive guide (200-250 words) for researchers on conducting hypothesis tests with large samples. Include discussion of when t-tests are appropriate, how to interpret results, and the role of the Central Limit Theorem in ensuring valid inference. (7 points)

C2. Design a practical scenario where a researcher might use summary statistics (mean, standard deviation, sample size) rather than raw data for hypothesis testing. Explain the procedure and discuss the advantages and limitations of this approach. (4 points)

C3. Create a decision framework for selecting appropriate statistical tests based on sample size and data characteristics. Include specific guidance for when different hypothesis testing approaches should be used in large sample contexts. (4 points)

Submission Guidelines:

  • Complete R Markdown document with all code and analysis
  • Proper execution of all hypothesis tests following the eight-step framework
  • Professional writing with clear analytical narrative
  • Appropriate confidence interval interpretation
  • Comprehensive interpretation of results in context
  • Knitted HTML document submitted via designated platform