1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use Array1;
use Family;
use ;
/// GLM leverage — the diagonal of the weighted hat matrix
/// `H = W^{1/2}X(XᵀWX)⁻¹XᵀW^{1/2}`, i.e. `hᵢ = wᵢ · xᵢᵀ(XᵀWX)⁻¹xᵢ` with the IRLS
/// working weight `wᵢ = (dμ/dη)² / V(μᵢ)`.
///
/// The GLM analogue of OLS leverage: how much observation `i`'s own fitted value
/// is determined by its predictors, weighted by the family variance. The
/// dispersion cancels (it scales `W` and `(XᵀWX)⁻¹` inversely), so leverage is a
/// pure geometric quantity; the values sum to `p`. Computed from the stored
/// inverse information without forming the `n × n` hat matrix.
/// Cook's-distance analogue for a GLM (Pregibon):
///
/// `Cᵢ = r_pᵢ² · hᵢ / (p · (1 − hᵢ)²)`,
///
/// where `r_pᵢ` is the Pearson residual and `hᵢ` the GLM leverage. As in OLS it
/// combines residual size and leverage into one per-observation influence
/// measure — large when a point is both poorly fit and has unusual,
/// well-weighted predictor values — flagging observations whose removal would
/// most move the coefficients.