Probability: Known model → predict likelihood of outcomes
Inference: Observed data → draw conclusions about model
“Is what we observed surprising if the coin is fair?”
How confident are you in a poll predicting an election?
Polls report point estimates, e.g., “Candidate A: 52%, Candidate B: 48%”, but always with uncertainty
That 4-point lead might seem convincing — but with a margin of error (say ±3%), the true difference might be much smaller
There’s a real probability that the candidate who appears behind is actually ahead
Code
set.seed(42)library(tidyverse)sim_poll <-rnorm(10000, mean =0.04, sd =0.03)ggplot(data.frame(lead = sim_poll), aes(x = lead)) +geom_histogram(bins =60, fill ="#3182bd", color="grey") +geom_vline(xintercept =0, color ="red", linetype ="dashed") +labs(title ="Simulated Election Poll Lead (4% ± 3%)",x ="Lead for Candidate A", y ="Frequency") +theme_minimal()
Inference Essentials
Population and Sample
The population is a large set of objects with measurable quantities.
A sample is a small subset of the population.
The goal of the statistical approach is to analyze the sample to draw conclusions about the population.
Random Sample
To make inferences from the sample to the population, we assume the population follows a probability distribution F, with unknown parameter(s).
say that the population is distributed as a Normal distribution with parameters \(\mu\) and \(\sigma^2\): knowing the parameters is all it takes to characterize the distribution of the population (parametric approach).
By randomly selecting elements, the associated values are treated as random variables distributed according to F.
Definition:
A set of independent, identically distributed random variables \(X_1, X_2, \ldots, X_n \sim F\) is called a random sample from distribution F.
From Sample to Population
Point Estimate: Uses sample data to estimate a population parameter.
Confidence Interval: Adds a margin of error to the point estimate.
Hypothesis Test: Tests two opposing hypotheses about a population parameter.
Definition of a Point Estimator
Let \(X\) be a r.v. from a known distribution family (Normal, Binomial…), with unknown parameter \(\theta\).
Use a random sample \(X_1, X_2, \ldots, X_n\).
A known function \(T(\cdot)\) estimates the parameter \(\theta\): \(\hat{\theta} = T(X_1, \ldots, X_n)\)
Point Estimators
Estimator A
No Bias, Low variability
Point Estimators
Estimator B
No Bias, High variability
Point Estimators
Estimator C
Bias, High variability
Point Estimators
Estimator D
Bias, Low variability
Ideal Estimator
An ideal estimator is:
Unbiased: Its expected value equals the true parameter.
Efficient: Has low variance around the parameter.
Natural estimator
if the target parameter is the population mean, then the natural estimator is the sample mean
if the target parameter is the population proportion, then the natural estimator is the sample proportion
Sample Mean Distribution
Given a population (e.g., workers) with a measurable variable (e.g., income):
Let \(X_1, X_2, ..., X_n\) be i.i.d. with distribution \(F\), parameters \(\mu\), \(\sigma^2\).
Sample mean: \(\bar{X} = \frac{1}{n} \sum X_i\)
population and random samples
Code
library(tidyverse)library(patchwork)set.seed(123)n=50n_s=15toy_data <-tibble(values =rnorm(1000000, mean =5, sd =2)) |>mutate(what="population")sample_data <-sample_n(toy_data, n*n_s, replace =TRUE) |>mutate(what=fct_inorder(rep(paste0("sample_",1:n_s),each=n)))# plot population and samplepop_pl=toy_data |>ggplot(aes(x=values)) +geom_histogram(fill="gold",bins =100,color="darkgrey",alpha=.5) +labs(title ="population distribution N(5, 2)",x ="", y ="count") +geom_vline(aes(xintercept =5), color ="indianred", linetype ="dashed") +theme_minimal()+facet_wrap(~what, scales ="free_y",ncol=1) sample_means <- sample_data |>group_by(what) |>summarise(mean_val =mean(values))sam_pl = sample_data |>ggplot(aes(x = values, y =after_stat(density))) +geom_histogram(aes(fill = what), bins =100, alpha =0.5) +# Sample mean linegeom_vline(data = sample_means, aes(xintercept = mean_val), color ="indianred", linetype ="dashed", linewidth =0.3) +# Population mean line (μ = 5)geom_vline(xintercept =5, color ="blue", linetype ="solid", linewidth =0.3) +labs(title ="Random Samples (size = 100)",x ="",y ="density" ) +theme_minimal() +theme(legend.position ="none",plot.title =element_text(hjust =0.5, size =5) ) +facet_wrap(~what, ncol =5)(pop_pl/sam_pl)
The sample mean \(\bar{X}\)
\(\bar{X}\) bounces around the population mean \(\mu\), but there is more to it…
Code
library(tidyverse)library(gganimate)set.seed(123)n <-50# sample sizen_s <-100# number of samplestrue_mean <-5# Generate samplessample_data <-tibble(sample_id =rep(1:n_s, each = n),values =rnorm(n * n_s, mean = true_mean, sd =2)) |>group_by(sample_id) |>mutate(sample_mean =mean(values))# Plotanim <-ggplot(sample_data, aes(x = values, fill =as.factor(sample_id))) +geom_histogram(aes(y =after_stat(density)), bins =50, color ="white") +geom_vline(aes(xintercept = sample_mean), color ="dodgerblue", linetype ="solid" ) +geom_vline(xintercept = true_mean, color ="indianred", linetype ="dashed") +labs(title ='Sample {closest_state}', x ='Value', y ='Density') +theme_minimal() +theme(legend.position ="none" ) +transition_states(sample_id, transition_length =1, state_length =1) +ease_aes('sine-in-out')# Animate!anim_file <-animate(anim, nframes =50, fps =5, width =600, height =400, renderer =gifski_renderer())anim_save("figures/sample_animation.gif", animation = anim_file)
The sample mean \(\bar{X}\)
by drawing many samples from the population, say 10000, computing the mean for each sample, and plotting the distribution of these sample means, we can see that:
the sample mean distribution approaches a normal distribution with mean \(\mu=5\) and standard deviation \(\frac{\sigma}{\sqrt{n}}\).
(In this case, \(\sigma=2\) and \(n=50\), so \(\frac{\sigma}{\sqrt{n}}=\frac{2}{\sqrt{50}}=0.283\).)
Interval Estimators - Confidence Intervals
Confidence Interval Example
For sample mean \(\bar{X}\): \[
P(\bar{X} - \text{ME} < \mu < \bar{X} + \text{ME}) = \text{confidence level}
\] ME = Margin of Error
Consider the sample mean estimator \(\bar{X}\), whose expected value is \(E(\bar{X}) = \mu\) and whose standard deviation is \[\text{sd}(\bar{X}) = \sqrt{\frac{\sigma^2}{n}} = \frac{\sigma}{\sqrt{n}}.\]
Suppose that the signal from an MRI (Magnetic Resonance Imaging) machine is transmitted from a source A to a destination B. The signal emitted has intensity \(\mu\).
The intensity of the signal is perceived at B according to a Normal distribution with mean \(\mu\) and standard deviation \(\sigma = 3\).
In other words, due to transmission noise, the signal intensity received at B differs from that emitted at A, with a mean of \(\mu = 0\) and a standard deviation of \(\sigma = 3\).
Suppose that \(n = 10\) transmissions were performed from A to B, and the signal intensity at the destination was recorded.
Given a confidence interval, and fixing the width of the interval at \(b\), determine the sample size \(n\) needed.
Recall that the bounds of the confidence interval for the mean are given by: \[\bar{X} \pm Z_{\alpha/2} \cdot \frac{\sigma}{\sqrt{n}}\]
Therefore, the total width of the interval is: \[2 \cdot Z_{\alpha/2} \cdot \frac{\sigma}{\sqrt{n}} = b\]
Solving for \(n\): \[2 \cdot Z_{\alpha/2} \cdot \frac{\sigma}{b} = \sqrt{n} \quad \Longrightarrow \quad n = \left(2 \cdot Z_{\alpha/2} \cdot \frac{\sigma}{b}\right)^2\]
What sample size is needed to obtain a 95% confidence interval for the population mean \(\mu\), with a total width of \(b = 0.01\), given that \(\sigma = 2\)? \[
n = (784)^2 = 614,656
\]
Unknown Variance - Use Student’s t
If the population standard deviation \(\sigma\) is not known, it must be estimated using the sample standard deviation \(s\) of the sample mean \(\bar{X}\). Thus, the sample standard deviation is given by:
and it follows a Student’s t-distribution with \(n - 1\) degrees of freedom.
Unknown Variance - Use Student’s t
Example 3 - Unknown Variance
An agency needs to assess the concentration level of a toxic substance, PCB, in breast milk. To do this, a sample of 20 mothers is considered, and the concentration level of the substance in their milk is studied.
PCB concentration in 20 samples:
\[16,0,0,2,3,6,8,2,5,0,12,10,5,7,2,3,8,17,9,1\]
\[
\bar{x} = 5.8,\ S = 5.085, \ n = 20, t_{\alpha/2,n-1} = 2.093
\]
We calculate the confidence interval as:
{x} t_{/2} = 5.8 = 5.8
Therefore, the confidence interval estimates are: \(\left[3.42,\ 8.18\right]\)
Let \(p\) be the proportion of statistical units in the population that exhibit a certain characteristic. The corresponding sample statistic is the sample proportion: = where \(x\) is the number of units in the sample that exhibit the characteristic.
The sample proportion \(\hat{p}\) satisfies:
Expected value: \(E[\hat{p}] = p\)
Standard deviation: \(\sigma_{\hat{p}} = \sqrt{\frac{p(1 - p)}{n}}\)
the confidence interval for the population proportion is given by: Z_{/2} _{}
Since the true value of \(p\) is unknown, the standard deviation is estimated by: S_{} =
Therefore, the confidence interval becomes: Z_{/2}
Example - CI for Proportion
A survey was conducted to determine the proportion of students who passed a certain exam. 82 out of 100 students passed. What is the 99% confidence interval for the proportion of students who passed?
A certain newspaper reports the result of a survey, according to which 46% of the population intends to get vaccinated against the flu virus. It is stated that the margin of error is 3%, and the confidence level used is \((1 - \alpha) = 0.95\). How many people were interviewed?
Given \(\hat{p} = 0.46\), ME = 0.03, CI 95%: \[
n = \left(\frac{1.96^2 \cdot 0.46 \cdot 0.54}{0.03^2} \right) = 1060
\]
Hypothesis Testing
Definition
A statistical hypothesis is a statement concerning one or more parameters of the population distribution. It is an hypothesis rather than a fact because it cannot be established a priori whether it is true or not.
Testing Procedure
We aim to determine whether the sample values are compatible with the statistical hypothesis in question.
To accept an hypothesis based on the observed sample does not mean to affirm that it is true, but rather that the data collected do not reject the hypothesis.
Hypothesis Testing: parameter and sample Spaces
Parameter Space
The parameter space is the set of all values a population parameter can take.
By formulating an hypothesis (e.g., \(\mu = 1\) or \(\mu \geq 1\)), we create a bipartition of this space: values for which the hypothesis is true and those for which it is false.
Sample Space
The sample space is the set of all possible samples of size \(n\) that can be observed.
The decision rule divides this space: some samples lead to acceptance of the hypothesis, others to rejection.
Null and Alternative Hypotheses
Competing Hypotheses
Every hypothesis test includes two competing hypotheses:
\(H_1\): alternative hypothesis (e.g., \(\mu \neq 1\), \(\mu < 1\))
Parameter Space Bipartition
Let \(\omega_0\) be the set of values of the parameter \(\theta\) defined by \(H_0\):
If \(\theta \in \omega_0\), then \(H_0\) is true.
If \(\theta \notin \omega_0\), then \(H_0\) is false.
Simple vs Composite Hypotheses
If \(H_0: \mu = 1\) vs. \(H_1: \mu \neq 1\), then \(H_0\) is a simple hypothesis (only one value), and \(H_1\) is two-sided.
If \(H_0: \mu \geq 1\) vs. \(H_1: \mu < 1\), then \(H_0\) is a composite hypothesis (a range of values), and \(H_1\) is one-sided.
Decision rule
The observed sample will lead to a value of the test statistic \(T_n\). Now, there will be a set \(C_{0}\) of possible values of \(T_{n}\) that will lead to the acceptance of \(H_0\).
Type I Error (α): False positive → reject H₀ when it’s true
Type II Error (β): False negative → fail to reject H₀ when H₁ is true
why type I error matters more
example
\(H_0\): The defendant is innocent
\(H_1\): The defendant is guilty
Type I error → Convicting an innocent person
Type II error → Letting a guilty person go free
example
\(H_0\): The new drug is no better than the old
\(H_1\): The new drug is better
Type I error → Approving an ineffective drug
Type II error → Discarding an effective drug
probability of errors
One never knows whether \(H_{0}\) is true or not. The probability of making an error is given by the following:
\(P(reject \ H_{0}| \ H_{0} \ is \ true)= \alpha\)
\(P(accept \ H_{0}| \ H_{1} \ is \ true)= \beta\)
Code
# Parametersmu0 <-0# Mean under H0mu1 <-2# Mean under H1sd <-1# Standard deviation (same for both)alpha <-0.05# Significance levelz_crit <-qnorm(1- alpha) # Critical value for one-sided test# x rangex_vals <-seq(-4, 6, length.out =1000)# Data for the two distributionsdf <-data.frame(x = x_vals,H0 =dnorm(x_vals, mean = mu0, sd = sd),H1 =dnorm(x_vals, mean = mu1, sd = sd))# Data for alpha area (under H0, right of critical value)alpha_area <- df %>%filter(x > z_crit) %>%mutate(density = H0)# Data for beta area (under H1, left of critical value)beta_area <- df %>%filter(x < z_crit) %>%mutate(density = H1)# Plotggplot(df, aes(x = x)) +geom_line(aes(y = H0), color ="dodgerblue", linewidth =1.2, linetype ="solid") +geom_line(aes(y = H1), color ="indianred", linewidth =1.2, linetype ="dashed") +geom_area(data = alpha_area, aes(y = density), fill ="dodgerblue", alpha =0.3) +geom_area(data = beta_area, aes(y = density), fill ="indianred", alpha =0.3) +geom_vline(xintercept = z_crit, linetype ="dotted") +annotate("text", x = z_crit +0.3, y =0.05, label ="Critical value", angle =90, hjust =0) +annotate("text", x =4.2, y =0.15, label ="H1", color ="indianred", size =5) +annotate("text", x =-2, y =0.15, label ="H0", color ="dodgerblue", size =5) +annotate("text", x =1.5, y =0.02, label =expression(beta), color ="indianred", size =6) +annotate("text", x =3.5, y =0.02, label =expression(alpha), color ="dodgerblue", size =6) +theme_minimal() +labs(title ="Visualization of Alpha (Type I) and Beta (Type II) Errors",y ="Density", x ="Test Statistic")
probability of errors
Since the Type I error is the one to be minimized, one sets its probability of occurrence (a.k.a. the significance level\(\alpha\)) to a small value. The lower \(\alpha\), the higher is \(\beta\).
if \(\alpha\) is set to 0.1
Code
# Parametersmu0 <-0# Mean under H0mu1 <-2# Mean under H1sd <-1# Standard deviation (same for both)alpha <-0.1# Significance levelz_crit <-qnorm(1- alpha) # Critical value for one-sided test# x rangex_vals <-seq(-4, 6, length.out =1000)# Data for the two distributionsdf <-data.frame(x = x_vals,H0 =dnorm(x_vals, mean = mu0, sd = sd),H1 =dnorm(x_vals, mean = mu1, sd = sd))# Data for alpha area (under H0, right of critical value)alpha_area <- df %>%filter(x > z_crit) %>%mutate(density = H0)# Data for beta area (under H1, left of critical value)beta_area <- df %>%filter(x < z_crit) %>%mutate(density = H1)# Plotggplot(df, aes(x = x)) +geom_line(aes(y = H0), color ="dodgerblue", linewidth =1.2, linetype ="solid") +geom_line(aes(y = H1), color ="indianred", linewidth =1.2, linetype ="dashed") +geom_area(data = alpha_area, aes(y = density), fill ="dodgerblue", alpha =0.3) +geom_area(data = beta_area, aes(y = density), fill ="indianred", alpha =0.3) +geom_vline(xintercept = z_crit, linetype ="dotted") +annotate("text", x = z_crit +0.3, y =0.05, label ="Critical value", angle =90, hjust =0) +annotate("text", x =4.2, y =0.15, label ="H1", color ="indianred", size =5) +annotate("text", x =-2, y =0.15, label ="H0", color ="dodgerblue", size =5) +annotate("text", x =1.5, y =0.02, label =expression(beta), color ="indianred", size =6) +annotate("text", x =3.5, y =0.02, label =expression(alpha), color ="dodgerblue", size =6) +theme_minimal() +labs(title ="Visualization of Alpha (Type I) and Beta (Type II) Errors",y ="Density", x ="Test Statistic")
probability of errors
Since the Type I error is the one to be minimized, one sets its probability of occurrence (a.k.a. the significance level\(\alpha\)) to a small value. The lower \(\alpha\), the higher is \(\beta\).
if \(\alpha\) is set to 0.01
Code
# Parametersmu0 <-0# Mean under H0mu1 <-2# Mean under H1sd <-1# Standard deviation (same for both)alpha <-0.01# Significance levelz_crit <-qnorm(1- alpha) # Critical value for one-sided test# x rangex_vals <-seq(-4, 6, length.out =1000)# Data for the two distributionsdf <-data.frame(x = x_vals,H0 =dnorm(x_vals, mean = mu0, sd = sd),H1 =dnorm(x_vals, mean = mu1, sd = sd))# Data for alpha area (under H0, right of critical value)alpha_area <- df %>%filter(x > z_crit) %>%mutate(density = H0)# Data for beta area (under H1, left of critical value)beta_area <- df %>%filter(x < z_crit) %>%mutate(density = H1)# Plotggplot(df, aes(x = x)) +geom_line(aes(y = H0), color ="dodgerblue", linewidth =1.2, linetype ="solid") +geom_line(aes(y = H1), color ="indianred", linewidth =1.2, linetype ="dashed") +geom_area(data = alpha_area, aes(y = density), fill ="dodgerblue", alpha =0.3) +geom_area(data = beta_area, aes(y = density), fill ="indianred", alpha =0.3) +geom_vline(xintercept = z_crit, linetype ="dotted") +annotate("text", x = z_crit +0.3, y =0.05, label ="Critical value", angle =90, hjust =0) +annotate("text", x =4.2, y =0.15, label ="H1", color ="indianred", size =5) +annotate("text", x =-2, y =0.15, label ="H0", color ="dodgerblue", size =5) +annotate("text", x =1.5, y =0.02, label =expression(beta), color ="indianred", size =6) +annotate("text", x =3.5, y =0.02, label =expression(alpha), color ="dodgerblue", size =6) +theme_minimal() +labs(title ="Visualization of Alpha (Type I) and Beta (Type II) Errors",y ="Density", x ="Test Statistic")
the p-value
Setting the significance level\(\alpha\) defines the threshold (critical value): if the obseved value of the test statistic is greater than the critical value, reject the null hypothesis.
Say the observed value is \(z = 2\), if \(\alpha=0.01\)
Code
# Parametersmu0 <-0# Mean under H0mu1 <-2# Mean under H1sd <-1# Standard deviation (same for both)alpha <-0.01# Significance levelz_crit <-qnorm(1- alpha) # Critical value for one-sided test# x rangex_vals <-seq(-4, 6, length.out =1000)# Data for the two distributionsdf <-data.frame(x = x_vals,H0 =dnorm(x_vals, mean = mu0, sd = sd),H1 =dnorm(x_vals, mean = mu1, sd = sd))# Data for alpha area (under H0, right of critical value)alpha_area <- df %>%filter(x > z_crit) %>%mutate(density = H0)# Data for beta area (under H1, left of critical value)beta_area <- df %>%filter(x < z_crit) %>%mutate(density = H1)# Plotggplot(df, aes(x = x)) +geom_line(aes(y = H0), color ="dodgerblue", linewidth =1.2, linetype ="solid") +# geom_line(aes(y = H1), color = "indianred", linewidth = 1.2, linetype = "dashed") +geom_area(data = alpha_area, aes(y = density), fill ="dodgerblue", alpha =0.3) +# geom_area(data = beta_area, aes(y = density), fill = "indianred", alpha = 0.3) +geom_vline(xintercept = z_crit, linetype ="dotted") +geom_vline(xintercept =2, linetype ="solid",color="forestgreen") +annotate("text", x =2-0.1, y =0.05, label ="observed value", angle =90, hjust =0) +annotate("text", x = z_crit +0.3, y =0.05, label ="Critical value", angle =90, hjust =0) +annotate("text", x =3, y =0.15, label ="no reject H0", color ="indianred", size =5) +annotate("text", x =-2, y =0.15, label ="H0", color ="dodgerblue", size =5) +# annotate("text", x = 1.5, y = 0.02, label = expression(beta), color = "indianred", size = 6) +annotate("text", x =3.5, y =0.02, label =expression(alpha), color ="dodgerblue", size =6) +theme_minimal() +labs(title ="Visualization of Alpha (Type I) and Beta (Type II) Errors",y ="Density", x ="Test Statistic")
the p-value
Setting the significance level\(\alpha\) defines the threshold (critical value): if the obseved value of the test statistic is greater than the critical value, reject the null hypothesis.
Say the observed value is \(z = 2\), if \(\alpha=0.01\)
Code
# Parametersmu0 <-0# Mean under H0mu1 <-2# Mean under H1sd <-1# Standard deviation (same for both)alpha <-0.05# Significance levelz_crit <-qnorm(1- alpha) # Critical value for one-sided test# x rangex_vals <-seq(-4, 6, length.out =1000)# Data for the two distributionsdf <-data.frame(x = x_vals,H0 =dnorm(x_vals, mean = mu0, sd = sd),H1 =dnorm(x_vals, mean = mu1, sd = sd))# Data for alpha area (under H0, right of critical value)alpha_area <- df %>%filter(x > z_crit) %>%mutate(density = H0)# Data for beta area (under H1, left of critical value)beta_area <- df %>%filter(x < z_crit) %>%mutate(density = H1)# Plotggplot(df, aes(x = x)) +geom_line(aes(y = H0), color ="dodgerblue", linewidth =1.2, linetype ="solid") +# geom_line(aes(y = H1), color = "indianred", linewidth = 1.2, linetype = "dashed") +geom_area(data = alpha_area, aes(y = density), fill ="dodgerblue", alpha =0.3) +# geom_area(data = beta_area, aes(y = density), fill = "indianred", alpha = 0.3) +geom_vline(xintercept = z_crit, linetype ="dotted") +geom_vline(xintercept =2, linetype ="solid",color="forestgreen") +annotate("text", x =2+0.1, y =0.05, label ="observed value", angle =90, hjust =0) +annotate("text", x = z_crit +0.1, y =0.05, label ="Critical value", angle =90, hjust =0) +annotate("text", x =3, y =0.15, label ="reject H0", color ="indianred", size =5) +annotate("text", x =-2, y =0.15, label ="H0", color ="dodgerblue", size =5) +# annotate("text", x = 1.5, y = 0.02, label = expression(beta), color = "indianred", size = 6) +annotate("text", x =3.5, y =0.02, label =expression(alpha), color ="dodgerblue", size =6) +theme_minimal() +labs(title ="Visualization of Alpha (Type I) and Beta (Type II) Errors",y ="Density", x ="Test Statistic")
the p-value
Instead of setting \(\alpha\), we can set the observed value and calculate the p-value as the area under the curve to the right.
If the observed value is \(z = 2\), the p-value is 0.0227501
for \(\alpha=0.05\), reject the null hypothesis since 0.0227501 < 0.05
for \(\alpha=0.01\), do not reject the null hypothesis since 0.0227501 > 0.01
Code
# Parametersmu0 <-0# Mean under H0mu1 <-2# Mean under H1sd <-1# Standard deviation (same for both)alpha <-0.05# Significance levelz_crit <-qnorm(1- alpha) # Critical value for one-sided test# x rangex_vals <-seq(-4, 6, length.out =1000)# Data for the two distributionsdf <-data.frame(x = x_vals,H0 =dnorm(x_vals, mean = mu0, sd = sd),H1 =dnorm(x_vals, mean = mu1, sd = sd))# Data for alpha area (under H0, right of critical value)alpha_area <- df %>%filter(x > z_crit) %>%mutate(density = H0)p_area <- df %>%filter(x >2) %>%mutate(density = H0)# Data for beta area (under H1, left of critical value)beta_area <- df %>%filter(x < z_crit) %>%mutate(density = H1)# Plotggplot(df, aes(x = x)) +geom_line(aes(y = H0), color ="dodgerblue", linewidth =1.2, linetype ="solid") +# geom_line(aes(y = H1), color = "indianred", linewidth = 1.2, linetype = "dashed") +# geom_area(data = alpha_area, aes(y = density), fill = "dodgerblue", alpha = 0.3) +geom_area(data = p_area, aes(y = density), fill ="indianred", alpha =0.3) +# geom_vline(xintercept = z_crit, linetype = "dotted") +geom_vline(xintercept =2, linetype ="solid",color="forestgreen") +annotate("text", x =2+0.1, y =0.05, label ="observed value", angle =90, hjust =0) +# annotate("text", x = z_crit + 0.1, y = 0.05, label = "Critical value", angle = 90, hjust = 0) +# annotate("text", x = 3, y = 0.15, label = "reject H0", color = "indianred", size = 5) +annotate("text", x =-2, y =0.15, label ="H0", color ="dodgerblue", size =5) +# annotate("text", x = 1.5, y = 0.02, label = expression(beta), color = "indianred", size = 6) +annotate("text", x =2.8, y =0.05, label =expression(p-value), color ="indianred", size =6) +theme_minimal() +labs(title ="Visualization of Alpha (Type I) and Beta (Type II) Errors",y ="Density", x ="Test Statistic")
Hypothesis Testing on the Mean (Known Variance)
Example 1: One-Sided Test (Known Variance)
Hip prosthetics have a mean resistance \(\mu = 1800N\), standard deviation \(\sigma = 100N\). After a process improvement, a sample of \(n=50\) prosthetics has \(\bar{X} = 1850N\). Test, at \(\alpha = 0.01\), whether resistance improved.
A group of volunteers among hospitalized patients with high cholesterol levels (at least 240 mg/dL) was selected to test the effectiveness of a cholesterol-lowering drug. 40 volunteers were treated with the drug for 60 days, and their cholesterol levels were measured again. The sample showed an average decrease in cholesterol of 6.8 with a sample standard deviation of 12.1. Use a 5% significance level.
The critical value at 5% significance with 39 degrees of freedom is:
\[
t_{39, 0.025} = 2.02
\]
Since \(|T_{obs}| > t_{c}\), we reject \(H_0\). Thus, the reduction is statistically significant — though not necessarily due to the drug alone. A placebo effect or other causes could be responsible.
A subject A is tested for extrasensory abilities. They are shown 50 cards (red or blue) and asked to guess the color chosen by a subject B in another room. A guesses correctly 32 times. Can we say A has paranormal abilities at the 5% significance level?
Since \(z_{obs} > z_c\), we reject \(H_0\): A’s performance is significantly better than chance.
The corresponding \(p\)-value is: 0.024 that is lower than 0.05.
Hypothesis Testing: Comparing Two Populations
The Importance of Control Groups
When testing the effect of a treatment (e.g., a drug), it’s important that all other factors are held constant. This way, any difference in outcomes can be attributed to the treatment itself.
This is often not feasible, so we use:
A treatment group (receives the drug)
A control group (receives a placebo)
We then test whether the difference in outcomes is statistically significant.
\[
Z = \frac{\bar{X} - \bar{Y}}{\sqrt{\frac{\sigma_x^2}{n} + \frac{\sigma_y^2}{m}}}
\]
Example: testing the difference between two populations
The goal is to study the effectiveness of a new drug in reducing cholesterol levels. To test the drug, 100 volunteers were recruited and divided into two groups of 50 each. The first group was given the new drug, while the second group—the control group—was administered lovastatin, a commonly used substance for lowering cholesterol. Each volunteer was instructed to take one pill every 12 hours for three months. None of the patients knew whether they were taking the new drug or the lovastatin. The first group (which took the new drug) recorded an average cholesterol reduction of 8.8, with a sample variance of 4.5. The second group recorded an average reduction of 8.2, with a sample variance of 5.4. Do these results support the hypothesis that, at a 5% significance level, the new drug leads to a greater average reduction in cholesterol levels?