October 18, 2025

Introduction

  • I will present a short overview of hypothesis testing and p-values with some examples.
  • I used basic data sets, mtcars and iris.

P-value

Let \(T(X)\) be a test statistic under \(H_0\).

The p-value is \[ {\ p=\Pr(T\geq t\mid H_{0})} \]

for a one-sided right-tail test-statistic distribution.

One-sample t-test

Let \(\ {\hat {\beta }}\) be an estimator of parameter \(\beta\) in some statistical model.

Then a t-test for this parameter is \[ {\ t_{\hat {\beta }}={\frac {{\hat {\beta }}-\beta _{0}}{\operatorname {s.e.} ({\hat {\beta }})}},} \]

Example 1

Test if the average fuel efficiency equals 20 MPG

  • If \(H_0\) were true, the probability of observing a \(t\) as extreme as this (or more) is the reported p-value.
  • Reject \(H_0\) at \(\alpha=0.05\) if p-value \(< 0.05\).
Distribution of MPG with sample mean

Distribution of MPG with sample mean

Example 2

Two-sample t-test on iris. Compare mean Petal Width between setosa and versicolor.

##    cohens_d
## 1 -6.816068

3D Plot (Plotly)

Code — show steps for Example 1

data(mtcars)
test1 <- t.test(mtcars$mpg, mu = 20)

mpg_df <- data.frame(mpg = mtcars$mpg)
library(ggplot2)
p_hist <- ggplot(mpg_df, aes(x = mpg)) +
  geom_histogram(binwidth = 2) +
  geom_vline(aes(xintercept = mean(mpg)), linetype = "dashed")
print(test1)
## 
##  One Sample t-test
## 
## data:  mtcars$mpg
## t = 0.08506, df = 31, p-value = 0.9328
## alternative hypothesis: true mean is not equal to 20
## 95 percent confidence interval:
##  17.91768 22.26357
## sample estimates:
## mean of x 
##  20.09062