~/ learn/ afm-113/ cards/ Paired differences
1 of 5

From the eight stores’ before and after sales, form the differences (after − before), compute d̄, s_d (statistics.stdev), the SE, t and df; then build the 95 % interval with the given t(0.025; 7) = 2.365.

From the eight stores’ before and after sales, form the differences (after − before), compute d̄, s_d (statistics.stdev), the SE, t and df; then build the 95 % interval with the given t(0.025; 7) = 2.365.

Answer

import math import statistics before = [42, 51, 38, 47, 55, 60, 44, 49] after = [45, 53, 41, 46, 58, 66, 47, 50] d = [a - b for a, b in zip(after, before)] dbar = statistics.mean(d) sd = statistics.stdev(d) n = len(d) se = sd / math.sqrt(n) t = dbar / se print(f"dbar={dbar:.2f} sd={sd:.4f} SE={se:.4f} t={t:.3f} df={n - 1}") lo, hi = dbar - 2.365 * se, dbar + 2.365 * se print(f"95% CI: {lo:.2f} to {hi:.2f}")

IBS1 §10.6 (matched pairs), IS1 §10.4, CC BY 4.0; BCc ch 5; H-W9 (promotion on/off, bracketed p) — shape only; original dataset

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/4dd32182-8a9d-49d3-b78a-46f2a3dde0a8/flashcard utf-8 LF