One-sample mean

One-sample mean

◎◉○

Live simulation

Average penguin body mass

For this example, we’ll use the body mass of all penguins near Palmer Station, Antarctica. We want to know if the average body mass is different from 4,000 grams.

At first glance, it looks like most penguins are already roughly around 4,000 grams. Some are lighter, a lot are heavier, but 4,000 seems fairly reasonable.

We can look at this more officially. First, we’ll load some packages and check the official average weight:

library(tidyverse)
library(infer)
library(parameters)

penguins <- penguins |> drop_na(sex)

penguins |>
  summarize(avg_weight = mean(body_mass))
  avg_weight
1   4207.057

The sample mean is 4,207 g, which is a bit higher than our comparison value of 4,000 g. But is that difference real, or could it just be due to random chance?

Null hypothesis inference with {infer}

Null hypothesis inference with t.test()

In practice, most people do not simulate null worlds. Instead, they use a one-sample t-test, which approximates the null world mathematically using a t-distribution. The intuition is the same: a p-value is still the probability of seeing a sample mean at least that extreme in a world where the true mean is μ₀.

To test whether the average body mass differs from 4,000 g, we can use t.test() with mu = 4000:

t.test(penguins$body_mass, mu = 4000)

    One Sample t-test

data:  penguins$body_mass
t = 4.6925, df = 332, p-value = 3.952e-06
alternative hypothesis: true mean is not equal to 4000
95 percent confidence interval:
 4120.256 4293.858
sample estimates:
mean of x 
 4207.057 

The p-value is in that wall of text—it’s 3.952e-06, or 3.952 × 10−6, or 0.000003952. That’s really tiny. In a world where the average weight for all penguins is around 4,000 grams, it would be virtually impossible to see a difference as extreme as 4,207. We have enough evidence to declare that difference is statistically significant.

If you don’t like all that text output, you can feed the results of t.test() to the model_parameters() function from the {parameters} package:

t.test(penguins$body_mass, mu = 4000) |>
  model_parameters() |>
  display(caption = "")
Parameter Mean mu Difference 95% CI t(332) p
Alternative hypothesis: true mean is not equal to 4000
body_mass 4207.06 4000 207.06 (4120.26, 4293.86) 4.69 < .001

Footnotes

  1. Kind of—in common law systems, defendants are presumed innocent until proven guilty, so if there’s not enough evidence to prove guilt, they are innocent by definition. ↩︎