2024-03-18

Introduction to Hypothesis Testing

  • Hypothesis testing is a statistical method used to make inferences about population parameters based on sample data.
  • It involves making a hypothesis about the population parameter and then using sample data to assess the likelihood of the hypothesis being true.
  • The two main types of hypotheses are the null hypothesis (\(H_0\)) and the alternative hypothesis (\(H_1\)).

Null Hypothesis (\(H_0\))

  • The null hypothesis represents the status quo or the assumption being tested.
  • Denoted as \(H_0\), it typically states that there is no effect or no difference.
  • Example: \(H_0: \mu = 50\), where \(\mu\) represents the population mean.

Alternative Hypothesis (\(H_1\))

  • The alternative hypothesis contradicts the null hypothesis.
  • Denoted as \(H_1\), it represents what we believe to be true if the null hypothesis is rejected.
  • Example: \(H_1: \mu \neq 50\) (two-tailed test) or \(H_1: \mu > 50\) (one-tailed test).

\[ Z = \frac{\bar{X} - \mu}{\frac{\sigma}{\sqrt{n}}} \]

\[ t_{n-1} = \frac{\bar{X} - \mu}{\frac{S}{\sqrt{n}}} \]

Steps in Hypothesis Testing

  1. Formulate the null and alternative hypotheses.
  2. Choose a significance level (\(\alpha\)).
  3. Collect sample data and calculate the test statistic.
  4. Determine the critical value or p-value.
  5. Make a decision and interpret the results.

Example: Hypothesis Testing for Mean

Suppose we want to test whether the mean weight of apples in a sample is significantly different from 150 grams.

  • Null hypothesis (\(H_0\)): The mean weight of apples is 150 grams.
  • Alternative hypothesis (\(H_1\)): The mean weight of apples is not equal to 150 grams.

Example (Continued)

  • Suppose we collect a sample of 50 apples and find that the sample mean weight is 155 grams with a standard deviation of 10 grams. We set the significance level at \(\alpha = 0.05\).
sample_mean <- 155
population_mean <- 150
sample_sd <- 10
n <- 50
t_stat <- (sample_mean - population_mean) / (sample_sd / sqrt(n))
p_value <- 2 * pt(abs(t_stat), df = n - 1, lower.tail = FALSE)
print(t_stat)
## [1] 3.535534
print(p_value)
## [1] 0.000900003

Plotly Plot R Code

# Generating additional sample data for demonstration
set.seed(123)
data <- data.frame(Weight = rnorm(100, mean = 150, sd = 10),
Size = rnorm(100, mean = 10, sd = 2),
Color = factor(sample(c("Red", "Green", "Blue"), 100, replace = TRUE)))

Plotly Plot

GG Plot 1

GG Plot 2