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 crateOlsFit;
/// Total sum of squares used as the `R²` denominator.
///
/// With an intercept this is the **centered** TSS `Σ (yᵢ − ȳ)²`; without one it
/// is the **uncentered** TSS `Σ yᵢ²`. The distinction matters: reporting a
/// centered `R²` for a through-the-origin model would overstate fit, so the
/// choice follows whether the model actually estimated a constant.
/// Coefficient of determination `R² = 1 − RSS / TSS`.
///
/// Uses centered TSS when the model has an intercept, uncentered otherwise (see
/// [`total_sum_of_squares`]).
/// Adjusted `R²`, penalizing model complexity:
///
/// `R̄² = 1 − (RSS / dfₑ) / (TSS / df_total)`
///
/// where `dfₑ = n − p` and `df_total = n − 1` with an intercept (`n` without).
///
/// Adding an irrelevant predictor can only nudge plain `R²` upward, but it costs
/// a residual degree of freedom, so adjusted `R²` frequently *falls* — that
/// asymmetry is exactly what makes it the honest "did this predictor earn its
/// place" statistic.