svgbrushablepoint-range
Point-range (mean ± CI)
How do group means compare, with their uncertainty?
How to read it
- Compare the group means: the dark dots.
- Read the bars as the uncertainty of each mean.
- Check the raw points behind them for how varied individuals are.
- Callout 1: The dot: the group mean. The bar: its interval.
- Callout 2: Raw points: individuals vary far more than the mean does.
Watch out
- Two overlapping intervals do not prove that two means are equal. Test the difference directly.
Defaults
- Interval
- Confidence interval (t)
- What the interval shows: a confidence interval, a standard error or a standard deviation.
- Also: ± 1 standard error · ± 1 standard deviation
- Confidence level
- 0.95
- How often intervals built this way contain the true value, over repeated samples.
- Range 0.8 to 0.99, step 0.01
- Raw points
- On
- Show each observation behind the summary.
- Order
- As in data
- How rows or groups are ordered.
- Also: By mean
Pinned in the code
- CI: x̄ ± t(1 − α/2, n − 1)·s/√n per group (R `t.test(x)$conf.int`; independent groups, no pooling); SD uses n − 1.
- ± SE and ± SD intervals are descriptive, not inferential — the axis label says which interval is drawn.
- Overlapping 95 % CIs do not imply a non-significant difference (Cumming & Finch 2005); use the Analyze module for tests.
- Raw points are jittered deterministically (seeded) so the picture is stable.
# Point-range (mean ± CI) — Codesplash Chart Lab (recipe "point-range")
# controls: interval=ci, level=0.95, points=true, sort=data
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
df = pd.read_csv("point-range-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["condition"] = pd.Categorical(df["condition"].astype("string"), categories=["Baseline", "Caffeine", "Sleep-deprived", "Music", "Dual task"])
d = df[["reaction_ms", "condition"]].dropna()
d["_g"] = d["condition"].astype(str)
order = [str(l) for l in df["condition"].cat.categories] if isinstance(df["condition"].dtype, pd.CategoricalDtype) else list(pd.unique(d["_g"]))
s = d.groupby("_g")["reaction_ms"].agg(["count", "mean", "std"]).reindex([l for l in order if l in set(d["_g"])]) # std uses n − 1
s["se"] = s["std"] / np.sqrt(s["count"])
s["half"] = stats.t.ppf(1 - (1 - 0.95) / 2, s["count"] - 1) * s["se"] # t interval per group, as R t.test(x)$conf.int
s["half"] = s["half"].fillna(0) # n < 2: the interval collapses to the mean
s = s.head(15)
LABEL = "reaction_ms (mean ± 95 % CI)"
fig, ax = plt.subplots(figsize=(7, 4.5))
xs = np.arange(len(s))
for i, level in enumerate(s.index): # raw points, deterministic jitter
v = d.loc[d["_g"] == level, "reaction_ms"].to_numpy()
jitter = ((np.arange(1, v.size + 1) * 0.618034) % 1 - 0.5) * 0.36
ax.scatter(i + jitter, v, s=8, color="#9aa0a6", alpha=0.5, zorder=1)
ax.errorbar(xs, s["mean"], yerr=s["half"], fmt="o", color=PALETTE[0], ecolor=PALETTE[0], elinewidth=2, capsize=4, markersize=7, zorder=3)
ax.set_xticks(xs, s.index)
ax.set_xlabel("condition")
ax.set_ylabel(LABEL)
plt.show()Needs pandas, numpy, matplotlib, scipy · reads point-range-demo.csv · app theme from the optional codesplash helper
# Point-range (mean ± CI) — Codesplash Chart Lab (recipe "point-range")
# controls: interval=ci, level=0.95, points=true, sort=data
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from scipy import stats
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else px.colors.qualitative.Plotly
df = pd.read_csv("point-range-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["condition"] = pd.Categorical(df["condition"].astype("string"), categories=["Baseline", "Caffeine", "Sleep-deprived", "Music", "Dual task"])
d = df[["reaction_ms", "condition"]].dropna()
d["_g"] = d["condition"].astype(str)
order = [str(l) for l in df["condition"].cat.categories] if isinstance(df["condition"].dtype, pd.CategoricalDtype) else list(pd.unique(d["_g"]))
s = d.groupby("_g")["reaction_ms"].agg(["count", "mean", "std"]).reindex([l for l in order if l in set(d["_g"])]) # std uses n − 1
s["se"] = s["std"] / np.sqrt(s["count"])
s["half"] = stats.t.ppf(1 - (1 - 0.95) / 2, s["count"] - 1) * s["se"] # t interval per group, as R t.test(x)$conf.int
s["half"] = s["half"].fillna(0) # n < 2: the interval collapses to the mean
s = s.head(15)
LABEL = "reaction_ms (mean ± 95 % CI)"
fig = go.Figure()
for i, level in enumerate(s.index): # raw points, deterministic jitter
v = d.loc[d["_g"] == level, "reaction_ms"].to_numpy()
jitter = ((np.arange(1, v.size + 1) * 0.618034) % 1 - 0.5) * 0.36
fig.add_scatter(x=i + jitter, y=v, mode="markers", marker=dict(color="#9aa0a6", size=4, opacity=0.5), showlegend=False)
fig.add_scatter(x=np.arange(len(s)), y=s["mean"], mode="markers", marker=dict(color=PALETTE[0], size=11),
error_y=dict(type="data", array=s["half"], thickness=2, width=6), name="mean", showlegend=False)
fig.update_layout(xaxis=dict(tickvals=list(range(len(s))), ticktext=list(s.index), title="condition"), yaxis_title=LABEL)
fig.show()Needs pandas, numpy, plotly, scipy · reads point-range-demo.csv · app theme from the optional codesplash helper
# Point-range (mean ± CI) — Codesplash Chart Lab (recipe "point-range")
# controls: interval=ci, level=0.95, points=true, sort=data
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("point-range-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["condition"]] <- factor(df[["condition"]], levels = c("Baseline", "Caffeine", "Sleep-deprived", "Music", "Dual task"))
update_geom_defaults("text", list(colour = "#131922")) # labels in the theme's text colour
d <- data.frame(y = df[["reaction_ms"]], g = as.character(df[["condition"]]))
d <- d[!is.na(d$y) & !is.na(d$g), ]
ord <- intersect(levels(df[["condition"]]), d$g) # dictionary order
s <- data.frame(g = ord,
n = as.numeric(tapply(d$y, d$g, length)[ord]),
mean = as.numeric(tapply(d$y, d$g, mean)[ord]),
sd = as.numeric(tapply(d$y, d$g, sd)[ord])) # sd uses n − 1
s$se <- s$sd / sqrt(s$n)
s$half <- qt(1 - (1 - 0.95) / 2, s$n - 1) * s$se # t interval per group, as t.test(x)$conf.int
s$half[is.na(s$half)] <- 0 # n < 2: the interval collapses to the mean
s <- head(s, 15)
s$g <- factor(s$g, levels = s$g)
d <- d[d$g %in% levels(s$g), ]
d$g <- factor(d$g, levels = levels(s$g))
d$jitter <- ave(seq_along(d$y), d$g, FUN = function(i) ((seq_along(i) * 0.618034) %% 1 - 0.5) * 0.36) # deterministic jitter
p <- ggplot(s, aes(as.numeric(g), mean)) + # numeric x so the jittered points share the axis
geom_point(data = d, aes(as.numeric(g) + jitter, y), colour = "#9aa0a6", alpha = 0.5, size = 0.8) +
geom_errorbar(aes(ymin = mean - half, ymax = mean + half), colour = cs_cat[1], width = 0.12, linewidth = 0.8) +
geom_point(colour = cs_cat[1], size = 3) +
scale_x_continuous(breaks = seq_len(nrow(s)), labels = levels(s$g)) +
labs(x = "condition", y = "reaction_ms (mean ± 95 % CI)") +
theme_cs
print(p)Needs ggplot2 · reads point-range-demo.csv · app theme from the optional codesplashr helper
-- Point-range (mean ± CI) — Codesplash Chart Lab (recipe "point-range")
-- controls: interval=ci, level=0.95, points=true, sort=data
-- per-group n, mean, SD (n − 1) and SE; CI half-width = t(1 − α/2, n − 1) · se (DuckDB has no t quantile —
-- multiply in Python/R, e.g. scipy.stats.t.ppf or qt)
SELECT "condition"::VARCHAR AS grp, count(*) AS n, avg("reaction_ms") AS mean, stddev_samp("reaction_ms") AS sd,
stddev_samp("reaction_ms") / sqrt(count(*)) AS se
FROM read_csv('point-range-demo.csv')
WHERE "condition" IS NOT NULL AND "reaction_ms" IS NOT NULL
GROUP BY 1
ORDER BY grp;Needs duckdb · reads point-range-demo.csv