IAI CS2 cheat sheet
IAI CS2 · Keep the key ideas within reach.
Survival Models and Lifetime Distributions
Survival function S(t) = P(T > t) = 1 − F(t); hazard h(t) = f(t)/S(t) = −d/dt log S(t); cumulative hazard H(t) = −log S(t), so S(t) = exp(−H(t)).
Exponential: constant hazard λ, S(t) = e^(−λt), mean 1/λ; memoryless, so it is a poor fit when mortality rises with age.
Gompertz: h(t) = Bc^t (B > 0, c > 1); Makeham adds a constant: h(t) = A + Bc^t. Both are standard laws of mortality for adult ages.
Weibull: h(t) = λγt^(γ−1); γ > 1 gives increasing hazard, γ < 1 decreasing, γ = 1 reduces to exponential. S(t) = exp(−λt^γ).
Kaplan–Meier estimator: Ŝ(t) = Π over event times t_i ≤ t of (1 − d_i/n_i); Greenwood's formula gives Var(Ŝ(t)) = Ŝ(t)² Σ d_i/[n_i(n_i − d_i)].
Nelson–Aalen estimator of cumulative hazard: Ĥ(t) = Σ_{t_i ≤ t} d_i/n_i; the slope of H(t) against t indicates whether the hazard is rising or falling.
Censoring: right-censored observations contribute S(t) to the likelihood (they are known to survive to t); independent censoring is required for KM and partial-likelihood methods to be valid.
Log-likelihood with censoring indicator δ_i: ℓ = Σ [δ_i log f(t_i) + (1 − δ_i) log S(t_i)] = Σ [δ_i log h(t_i) − H(t_i)].
Estimation and Graduation of Survival Models
Crude (central) death rate: m_x = d_x/E_x^c, where E_x^c is the central exposed to risk; the force of mortality μ_{x+1/2} ≈ m_x under a uniform-distribution-of-deaths assumption.
Initial (actuarial) rate: q_x = d_x/E_x^0 with E_x^0 = E_x^c + ½d_x; the approximation q_x ≈ m_x/(1 + ½m_x) follows from assuming deaths occur evenly across the year.
Binomial (maximum-likelihood) estimate of q_x solves d_x = E_x^0 q_x − ½ E_x^0 q_x² ... use the exact MLE when deaths are concentrated early; variance ≈ q_x(1 − q_x)/E_x^0.
Poisson model: D_x ~ Poisson(E_x^c μ_x), giving μ̂_x = d_x/E_x^c and Var(μ̂_x) = μ_x/E_x^c; standard for large populations with small rates.
Standardised mortality ratio: SMR = observed deaths / expected deaths, where expected = Σ E_x^c μ_x^std; 95% CI from Poisson: SMR × exp(±1.96/√d).
Graduation: fit a smooth curve (Gompertz–Makeham, Heligman–Pollard, splines) to raw rates; assess by χ² goodness-of-fit, runs tests of signs of deviations, and comparison of crude vs graduated rates.
Standard errors of graduated values combine the variance of the fitted parameters (from the model) and, for the χ² test, the assumed binomial/Poisson variance of the crude data.
Exposure can be computed by the census (mid-year population) or the exact (individual) method; the census approximation requires the population to be approximately linear within each year.
Regression Models for Survival Data
Cox proportional hazards: h(t|x) = h_0(t) exp(βᵀx); baseline hazard h_0(t) is unspecified, so β is estimated by partial likelihood, which conditions out h_0(t).
Hazard ratio for a one-unit increase in x_j is exp(β_j); a 95% CI is exp(β̂_j ± 1.96 SE(β̂_j)) and does not depend on time under proportional hazards.
Proportional hazards check: plot log(−log Ŝ(t)) against log t for groups (parallel lines), or use scaled Schoenfeld residuals and a Grambsch–Therneau test.
Ties in event times: Breslow, Efron, and exact partial-likelihood approximations; Efron's is the default in R's coxph and is more accurate than Breslow when ties are heavy.
Parametric alternatives: exponential (constant hazard), Weibull (h(t) = λγt^(γ−1), PH or AFT form), Gompertz, log-logistic and lognormal (non-monotone hazards, AFT).
Accelerated failure time model: log T = μ + βᵀx + σε; the survival functions of two covariate patterns are related by S_1(t) = S_0(t/exp(βᵀΔx)), i.e. time is scaled.
Likelihood-ratio test compares nested parametric models; AIC = −2ℓ + 2k and BIC = −2ℓ + k log n are used to choose among non-nested distributions.
Martingale and deviance residuals identify influential observations and poor fit; Cox–Snell residuals should be approximately unit exponential if the model fits.
Generalised Linear Models
GLM components: random component (exponential family: Poisson, binomial, gamma, normal), systematic component η = Xβ, and link g(μ) = η.
Canonical links: identity for normal, log for Poisson, logit for binomial, log for gamma; using the canonical link makes Xᵀ(y − μ) = 0 and simplifies the Fisher information.
Poisson log-linear model: log μ_i = x_iᵀβ; variance function V(μ) = μ; deviance = 2Σ[y log(y/μ̂) − (y − μ̂)].
Binomial logistic model: logit(p) = x_iᵀβ; V(μ) = μ(1 − μ); coefficient exp(β_j) is an odds ratio; overdispersion inflates the variance beyond μ(1 − μ).
Overdispersion: Pearson χ²/df > 1 indicates it; remedies include quasi-Poisson (variance φμ) or negative binomial (variance μ + μ²/θ), and quasi-likelihood standard errors.
Deviance D = 2[ℓ(saturated) − ℓ(model)]; nested models compared by ΔD ~ χ² with df equal to the difference in parameters.
Offset: a known term with coefficient 1, e.g. log(exposure) in a Poisson rate model, so log μ = log E + xᵀβ models the rate μ/E.
Iteratively reweighted least squares: β^(k+1) = (XᵀWX)^(−1) XᵀWz with working weights W = diag[(∂μ/∂η)²/V(μ)] and working response z = η + (y − μ)(∂η/∂μ).
Bayesian Statistics and Computational Methods
Bayes' theorem: posterior ∝ likelihood × prior; the normalising constant is the marginal likelihood p(y) = ∫ p(y|θ)p(θ)dθ.
Conjugate pairs: beta–binomial, gamma–Poisson, normal–normal (known variance), Dirichlet–multinomial; conjugacy gives closed-form posteriors.
Credible interval: a 95% interval contains the parameter with posterior probability 0.95; an equal-tailed interval takes the 2.5% and 97.5% posterior quantiles.
Metropolis–Hastings: propose θ* from q(·|θ), accept with probability min(1, [p(y|θ*)p(θ*)q(θ|θ*)]/[p(y|θ)p(θ)q(θ*|θ)]); the chain has stationary distribution equal to the posterior.
Gibbs sampling: update each parameter from its full conditional; it is Metropolis–Hastings with acceptance probability 1.
Diagnostics: Gelman–Rubin potential scale reduction R̂ close to 1, trace plots, autocorrelation and effective sample size; burn-in discards early non-stationary draws.
Predictive distribution: p(ỹ|y) = ∫ p(ỹ|θ)p(θ|y)dθ; the posterior predictive check compares replicated data with observed data.
Bayes factor for M1 vs M0 = p(y|M1)/p(y|M0); it is sensitive to the prior and to the prior's diffuseness.
Statistical Modelling with R and Data Analysis
Survival objects: Surv(time, event) with event = 1 for death and 0 for censored; survfit() gives the Kaplan–Meier estimate and survdiff() the log-rank test.
coxph(Surv(time, event) ~ x, data = d) fits Cox PH; cox.zph() tests proportional hazards using scaled Schoenfeld residuals; strata() allows a stratum-specific baseline hazard.
Parametric survival: survreg() fits AFT models (dist = "weibull", "lognormal", "loglogistic", "exponential"); flexsurv::flexsurvreg() fits PH or AFT forms including Gompertz.
GLMs: glm(y ~ x, family = poisson(link = "log"), offset = log(exposure)); summary() reports coefficients, standard errors, deviance and AIC.
Model comparison: anova(m1, m2, test = "Chisq") for nested GLMs; AIC(m1, m2) for non-nested; drop1() and step() for variable selection.
Diagnostics: plot(model) gives residual vs fitted, QQ, scale–location and leverage plots; residuals(model, type = "deviance") for GLMs, type = "martingale" for coxph.
Data handling: subset() and dplyr::filter() for rows; na.omit() or na.action to handle missing data; factor() with levels to set reference categories.
Reproducibility: set.seed() before simulation; knitr/rmarkdown for reports; sessionInfo() records package versions.