2024-03-21

Introduction

What is Hypothesis Testing?

  • Hypothesis testing is a statistical method used to make inferences about population parameters based on sample data.
  • It involves formulating null and alternative hypotheses, calculating test statistics, and determining the significance of results.

Null and Alternative Hypotheses

Null Hypothesis (\(H_0\))

  • \(H_0\): There is no difference or no effect.

Alternative Hypothesis (\(H_1\))

  • \(H_1\): There is a difference or an effect.

Test Statistic

  • A test statistic measures the strength of evidence against the null hypothesis.

  • It is calculated from sample data and compared to a critical value or p-value.

\[ \text{Test Statistic} = \frac{\text{Sample Statistic} - \text{Population Parameter}}{\text{Standard Error of Sample Statistic}} \]

  • Commonly used test statistics include z-score, t-score, and chi-square statistic.

  • Example:

    • If we want to test the mean height of adults, we can use the t-test statistic.

Type 1 vs Type 2 Errors

  • Type I Error: Rejecting the null hypothesis when it is actually true.

  • Type II Error: Failing to reject the null hypothesis when it is actually false.

  • The significance level (α) determines the probability of making a Type I Error .

  • The power (1-β) determines the probability of correctly rejecting a false null hypothesis.

  • Example:

    • Type I Error: Convicting an innocent person.

    • Type II Error: Failing to convict a guilty person.

One-Tailed vs Two-Tailed Tests

One-Tailed Test

  • Examines the hypothesis in one direction.
  • Used when the researcher has a specific directional expectation.

Two-Tailed Test

  • Examines the hypothesis in both directions.
  • Used when the researcher is interested in differences regardless of direction.

P-value

  • The p-value is the probability of obtaining a test statistic as extreme as, or more extreme than, the observed value under the null hypothesis.
  • It measures the strength of evidence against the null hypothesis.

\[ \text{p-value} = P(\text{Test Statistic} \geq \text{Observed Value} \, | \, H_0) \]

  • If the p-value is small (typically less than the significance level \(\alpha\)), it suggests strong evidence against the null hypothesis, leading to its rejection.
  • Conversely, if the p-value is large, it indicates weak evidence against the null hypothesis, and we fail to reject it.

Hypothesis Testing Steps

  1. State the null and alternative hypotheses.

  2. Choose a significance level (α).

  3. Select an appropriate test statistic and its distribution.

  4. Calculate the test statistic and p-value.

  5. Compare the p-value with the significance level.

  6. Make a decision and draw conclusions.

Decision Rule

  • Based on the p-value and significance level (\(\alpha\)).
  • If p-value ≤ \(\alpha\): Reject \(H_0\).
  • If p-value > \(\alpha\): Fail to reject \(H_0\).

Example: One-Sample Z-Test

  • Null Hypothesis (\(H_0\)): Population mean weight = 150 pounds.
  • Alternative Hypothesis (\(H_1\)): Population mean weight ≠ 150 pounds.
  • Sample Mean: 155 pounds
  • Sample Size: 50
  • Standard Deviation: 10 pounds
  • Significance Level (\(\alpha\)): 0.05

Sample R Code for One-Sample Z-Test

sample_mean <- 155
population_mean <- 150
sample_size <- 50
standard_deviation <- 10

# Calculate test statistic
test_statistic <- (sample_mean - population_mean) / (standard_deviation / sqrt(sample_size))

# Calculate p-value
p_value <- 2 * (1 - pnorm(abs(test_statistic)))

# Decision rule
alpha <- 0.05
if (p_value <= alpha) {
  cat("Reject Null Hypothesis")
} else {
  cat("Fail to Reject Null Hypothesis")
}

Output of Sample Code

## Reject Null Hypothesis

Plotly Visualization of Hypothesis Testing

Illustrating Hypothesis Testing with ggplot

Plot 1: Normal Distribution

  • The first plot displays the standard normal distribution, a fundamental distribution often encountered in hypothesis testing. .

Plot 2: Distribution with Rejection

  • The second plot illustrates a distribution with rejection regions, highlighting areas where the null hypothesis would be rejected based on a significance level