11/15/2024

Introduction

  • Definition: The p-value is a fundamental concept in statistics, used extensively in hypothesis testing. It helps researchers determine the significance of their results in relation to a null hypothesis.
  • Purpose: It provides a threshold for rejecting or not rejecting the null hypothesis. A small p-value (typically ≤ 0.05) suggests that the observed data is unlikely under the null hypothesis, potentially leading us to reject H0.
  • Common Use: Widely used in scientific fields (medicine, psychology, and economics) to assess the validity of research findings.
  • The smaller the p-value, the stronger the evidence against the null hypothesis.

Example of Hypothesis Testing with p-value

Let’s say we want to test if a coin is fair (null hypothesis \(H_0\)) or if it is biased towards heads (alternative hypothesis \(H_1\)).

\[ H_0: p = 0.5 \quad \text{vs.} \quad H_1: p \neq 0.5 \]

Binomial Test Explanation

  • In a binomial test, we evaluate whether the observed proportion \(\hat{p}\) significantly deviates from the hypothesized probability under \(H_0\).
  • The probability of observing \(k\) heads out of \(n\) trials under \(H_0\) is given by:

\[ P(X = k) = \binom{n}{k} p^k (1 - p)^{n - k} \]

  • We calculate the p-value by summing the probabilities of observing results as extreme or more extreme than the observed result, assuming \(H_0\) is true.

p-value Calculation and Code Example

In R, we can calculate the p-value using the binomial test for the observed number of heads.

library(ggplot2)
library(plotly)

# Data for 100 flips of a coin
set.seed(123)
n <- 100
observed_heads <- 60
p_hat <- observed_heads / n

# Perform a binomial test
test_result <- binom.test(observed_heads, n, p = 0.5)
test_result$p.value
## [1] 0.05688793

Plotting the binomial distribution

Cumulative Probability Distribution

Interpreting the p-value

The calculated p-value indicates the probability of observing 60 or more heads if the coin is fair.

  • If \(p\text{-value} < 0.05\):
    • We reject \(H_0\) and conclude the coin may be biased.
  • If \(p\text{-value} > 0.05\):
    • We fail to reject \(H_0\) and conclude there’s insufficient evidence of bias.

3D Plotly binomial distribution

Understanding the p-value in Hypothesis Testing

  • The p-value is essential in hypothesis testing, helping researchers evaluate if their results could occur under the null hypothesis \(H_0\).

  • A small p-value provides strong evidence against \(H_0\), suggesting that the observed results are unlikely due to chance alone.

  • Important: The p-value is not the probability that \(H_0\) is true. Instead, it is the probability of observing data as extreme as ours, assuming \(H_0\) is true.

Analysis

1. Setting up the Hypothesis Test

  • We wanted to test whether a coin is fair, meaning it has an equal chance of landing heads or tails.
  • Hypotheses:
    • Null Hypothesis (H₀): The coin is fair (\(p = 0.5\)).
    • Alternative Hypothesis (H₁): The coin is biased (\(p \neq 0.5\)).

2. Observed Results

  • We flipped the coin 100 times and observed 60 heads.
  • If the coin were fair, we would expect about 50 heads out of 100 flips, so observing 60 heads raises questions about potential bias.

Continued

3. Calculating the p-value

  • We used a binomial test to calculate the probability of observing 60 or more heads if the coin is fair.
  • The resulting p-value quantifies how likely it is to see 60 heads or an even more extreme result under the null hypothesis.

4. Interpreting the p-value

  • If the p-value is less than or equal to 0.05, we reject \(H_0\) and conclude that the coin might be biased.
  • If the p-value is greater than 0.05, we do not have enough evidence to say the coin is biased.

Conclusion

  • Based on our calculation, the p-value informs us about whether the observed deviation (60 heads) is significant or could be due to chance.
  • For this example:
    • If the p-value ≤ 0.05: The result is statistically significant, and we have grounds to question the fairness of the coin.
    • If the p-value > 0.05: The result could reasonably occur by chance, so we do not reject \(H_0\), indicating no strong evidence of bias.

This analysis helps us understand if the observed result of 60 heads suggests a biased coin or if it falls within the range of expected outcomes for a fair coin.