Cheat sheet module 1
Cheat sheet module 1: diagnostic analytics
Formulas (formula sheet or know them)
- SE = s / sqrt(n). Halve: 4 x as many n
- CI = x-bar +/- t* x s / sqrt(n), or z* x sigma / sqrt(n) for known sigma or large n (formula sheet)
- z* : 90% = 1.64 | 95% = 1.96 | 99% = 2.58 (know them)
- Z = (x - mu) / sigma; 68% within 1 sd, 95% within 2 sd, 99.7% within 3 sd (know it)
- CoV = sd / mean; IQR = Q3 - Q1; range = max - min. R’s var() and sd() divide by n - 1
R functions
- summary(), mean(), median(), sd(), quantile(x, p), IQR(), table(), cor(x, y)
- pnorm(x, mu, sigma) = probability left; right = 1 - pnorm(). qnorm(p) = critical value, qt(p, df)
Reading R output (School, n = 80)
- Mean > Median: right-skewed (Sat 1174 > 1158). Mean < Median: left-skewed (Debts 13.14 < 13.46). IQR Debts = 15.72 - 10.46 = 5.26
- t.test(Debts): SE 0.476, t* 1.990, CI [12.20; 14.09]. The p < 2.2e-16 belongs to H0: mu = 0: meaningless, read only the interval
- cor(CostTot, Debts) = 0.424, r^2 = 0.18: association, not cause
- 1 - pnorm(8, 5, 1.5) = 0.0228 (Z = 2, rule of thumb 2.5%)
Decision rules
- SE describes the mean, the sd the data. SE falls with n, the sd does not
- Higher confidence level: wider CI. Example n = 100, mean 50, s = 20: SE = 2. The 95% confidence interval is 50 +/- 1.96 x 2, so [46.08; 53.92]
- 95% CI: “on repetition 95% of the intervals contain mu”. Never “95% chance mu is in it” or “95% of the data”
- central limit theorem: about the sample mean, not the data; from n above 20 to 30
Causal relationship scheme
- Mediator: X to M to Y (channel). Moderator: Z changes the strength of X to Y (“for whom or when”). Confounder: Z causes X and Y (spurious relationship). Reverse causality: Y also influences X
Hypotheses
- Testable, with direction, clear variables and H0 (no effect)
- Survey: associative (“is related to”). Experiment: causal
- In advance, otherwise data dredging: 20 tests give 1 - 0.95^20 = 0.64 chance of a fluke
Variables and validity
- Nominal, ordinal (qualitative); continuous, discrete (quantitative). Code 1, 2, 3 is nominal: make it a factor
- Internal validity: trustworthy for the source population. External validity: generalise to the target population