Proportion of prediction variability unexplained by main effects of v
, see Details.
Use plot()
to get a barplot.
h2(object, ...)
# Default S3 method
h2(object, ...)
# S3 method for class 'hstats'
h2(object, normalize = TRUE, squared = TRUE, ...)
An object of class "hstats_matrix" containing these elements:
M
: Matrix of statistics (one column per prediction dimension), or NULL
.
SE
: Matrix with standard errors of M
, or NULL
.
Multiply with sqrt(m_rep)
to get standard deviations instead.
Currently, supported only for perm_importance()
.
m_rep
: The number of repetitions behind standard errors SE
, or NULL
.
Currently, supported only for perm_importance()
.
statistic
: Name of the function that generated the statistic.
description
: Description of the statistic.
If the model is additive in all features, then the (centered) prediction
function \(F\) equals the sum of the (centered) partial dependence
functions \(F_j(x_j)\), i.e.,
$$
F(\mathbf{x}) = \sum_{j}^{p} F_j(x_j)
$$
(check partial_dep()
for all definitions).
To measure the relative amount of variability unexplained by all main effects,
we can therefore study the test statistic of total interaction strength
$$
H^2 = \frac{\frac{1}{n} \sum_{i = 1}^n \big[F(\mathbf{x}_i) -
\sum_{j = 1}^p\hat F_j(x_{ij})\big]^2}{\frac{1}{n}
\sum_{i = 1}^n\big[F(\mathbf{x}_i)\big]^2}.
$$
A value of 0 means there are no interaction effects at all.
Due to (typically undesired) extrapolation effects, depending on the model,
values above 1 may occur.
In Żółkowski et al. (2023), \(1 - H^2\) is called additivity index. A similar measure using accumulated local effects is discussed in Molnar (2020).
h2(default)
: Default method of total interaction strength.
h2(hstats)
: Total interaction strength from "interact" object.
Żółkowski, Artur, Mateusz Krzyziński, and Paweł Fijałkowski. Methods for extraction of interactions from predictive models. Undergraduate thesis. Faculty of Mathematics and Information Science, Warsaw University of Technology (2023).
Molnar, Christoph, Giuseppe Casalicchio, and Bernd Bischl". Quantifying Model Complexity via Functional Decomposition for Better Post-hoc Interpretability, in Machine Learning and Knowledge Discovery in Databases, Springer International Publishing (2020): 193-204.
# MODEL 1: Linear regression
fit <- lm(Sepal.Length ~ . + Petal.Width:Species, data = iris)
s <- hstats(fit, X = iris[, -1])
#> 1-way calculations...
#>
|
| | 0%
|
|================== | 25%
|
|=================================== | 50%
|
|==================================================== | 75%
|
|======================================================================| 100%
#> 2-way calculations...
#>
|
| | 0%
|
|======================================================================| 100%
h2(s)
#> H^2 (normalized)
#> [1] 0.0502364
# MODEL 2: Multi-response linear regression
fit <- lm(as.matrix(iris[, 1:2]) ~ Petal.Length + Petal.Width * Species, data = iris)
s <- hstats(fit, X = iris[, 3:5])
#> 1-way calculations...
#>
|
| | 0%
|
|======================= | 33%
|
|=============================================== | 67%
|
|======================================================================| 100%
#> 2-way calculations...
#>
|
| | 0%
|
|======================================================================| 100%
h2(s)
#> H^2 (normalized)
#> Sepal.Length Sepal.Width
#> 0.04758952 0.03963575
# MODEL 3: No interactions
fit <- lm(Sepal.Length ~ ., data = iris)
s <- hstats(fit, X = iris[, -1], verbose = FALSE)
h2(s)
#> H^2 (normalized)
#> [1] 0