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
use Array1;
use ;
/// Logistic 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
/// `wᵢ = pᵢ(1 − pᵢ)`.
///
/// The GLM analogue of OLS leverage: it measures how much observation `i`'s own
/// fitted value is determined by its predictors, but weighted by the binomial
/// variance, so points where the model is already near-certain (`pᵢ ≈ 0` or `1`)
/// carry little leverage. Computed from the stored covariance without forming the
/// `n × n` hat matrix, and the values sum to `p`.
/// Cook's-distance analogue for logistic regression (Pregibon):
///
/// `Cᵢ = r_pᵢ² · hᵢ / (p · (1 − hᵢ)²)`,
///
/// where `r_pᵢ` is the Pearson residual and `hᵢ` the logistic leverage. Like its
/// OLS counterpart it combines residual size and leverage into a single
/// per-observation influence measure — large when a point is both poorly fit and
/// has unusual, well-weighted predictor values — and flags observations whose
/// removal would most move the coefficients.