Unit 03.02: Look at the shape before testing the means
Plot the distribution before you test the means. A mean and a standard deviation cannot describe a distribution with two peaks.
Look at the shape first
Summary statistics compress a distribution to two numbers, and two numbers cannot express bimodality, a floor effect, a spike at zero or a truncation. Groups with nearly identical means and standard deviations can have completely different shapes, and the shape often *is* the finding.
The charts do different jobs. A histogram shows one distribution's shape. Overlaid densities compare two. A box plot puts medians and spreads side by side. A scatter plot shows whether two variables move together.
This also matters for test choice, since a t-test on a strongly bimodal variable is testing a mean that describes nobody.
This block summarises two groups and then draws them.
suppressPackageStartupMessages({library(ggplot2); library(dplyr)})
set.seed(31)
d <- data.frame(
group = rep(c("A", "B"), each = 80),
value = c(rnorm(80, 50, 5), c(rnorm(40, 44, 4), rnorm(40, 57, 4)))
)
by_group <- d |> group_by(group) |>
summarise(n = n(), mean = round(mean(value), 1), sd = round(sd(value), 1),
.groups = "drop")
print(by_group)
cat("\nThe two means are close, and the distributions are not the same shape:\n")
cat("group B is bimodal -- two clusters around 44 and 57 -- which a mean\n")
cat("and a standard deviation cannot express.\n\n")
charts <- c(histogram = "the shape of one distribution",
density = "two shapes overlaid for comparison",
boxplot = "medians and spread side by side",
scatter = "whether two variables move together")
for (nm in names(charts)) cat(sprintf("%-10s %s\n", nm, charts[[nm]]))
p <- ggplot(d, aes(value, fill = group)) +
geom_histogram(bins = 24, alpha = 0.6, position = "identity") +
labs(x = "Value", y = "Count")
f <- file.path(tempdir(), "dists.png")
ggsave(f, p, width = 6, height = 3, dpi = 100)
cat("\nPlot the distribution before you test the means:", file.size(f), "bytes\n")
The group means are 49.6 and 50.9 — close enough to look like the same distribution — with standard deviations of 4.8 and 6.9. Group B is actually bimodal, two clusters near 44 and 57, and no combination of mean and standard deviation can say so. A test comparing the means would answer a question about B that has no sensible answer.
The mistake this prevents
The mistake is going straight from group_by() to t.test(). The summary table looks reasonable, the test runs, and nobody ever sees that one group is two populations.
Takeaway
Plot the distributions before testing. Use histograms or densities to check shape, and reconsider the method if a distribution is bimodal, truncated or heavily skewed.
