mid.breakdown() calculates the contribution of each component function of a fitted MID model to a single prediction.
It breaks down the total prediction into the effects of the intercept, main effects, and interactions.
Arguments
- object
a "mid" object.
- data
a data frame containing one or more observations for which to calculate the MID breakdown. If not provided, data is automatically extracted based on the function call.
- row
an optional numeric value or character string specifying the row of
datato be used for the breakdown. IfNULL, and thedatacontains two or more observations, only the first observation is used.- sort
logical. If
TRUE, the output data frame is sorted by the absolute contribution of each effect.
Value
mid.breakdown() returns an object of class "midbrk". This is a list with the following components:
- breakdown
a data frame containing the breakdown of the prediction.
- data
the data frame containing the predictor variable values used for the prediction.
- intercept
the intercept of the MID model.
- prediction
the predicted value from the MID model.
For a "mids" collection object, mid.breakdown() returns a collection object of class "midbrks"-"midlist".
Details
This function provides local interpretability for a specific observation by decomposing its prediction into the individual contributions of the MID components. For a target observation \(\mathbf{x}\), the total prediction is represented as the sum of all estimated terms:
$$g(\mathbf{x}) = g_\emptyset + \sum_{j} g_j(x_j) + \sum_{j<k} g_{jk}(x_j, x_k)$$
The output data frame itemizes the numerical value of each main effect \(g_j(x_j)\) and interaction effect \(g_{jk}(x_j, x_k)\), along with the intercept \(g_\emptyset\). This decomposition makes the model's decision for a single instance fully transparent and easy to attribute to specific features or their combinations.
Examples
data(airquality, package = "datasets")
mid <- interpret(Ozone ~ .^2, data = airquality, lambda = 1)
#> 'model' not passed: response variable in 'data' is used
# Calculate the breakdown for the first observation in the data
brk <- mid.breakdown(mid, data = airquality, row = 1)
print(brk)
#>
#> MID Breakdown of a Prediction
#>
#> Intercept: 42.099
#>
#> Prediction: 39.738
#>
#> Breakdown of Effects:
#> term mid order
#> 1 Temp -1.5043e+01 1
#> 2 Day 4.9774e+00 1
#> 3 Month 3.7573e+00 1
#> 4 Wind:Month 2.0405e+00 2
#> 5 Temp:Day 1.3882e+00 2
#> 6 Solar.R:Month 1.3125e+00 2
#> 7 Wind 1.0226e+00 1
#> 8 Solar.R -9.4334e-01 1
#> 9 Wind:Temp -6.2883e-01 2
#> 10 Solar.R:Temp -5.6554e-01 2
#> 11 Month:Day 5.0512e-01 2
#> 12 Solar.R:Day -2.4745e-01 2
#> 13 Wind:Day 4.2728e-02 2
#> 14 Temp:Month 2.0633e-02 2
#> 15 Solar.R:Wind -1.0171e-04 2
# Calculate the breakdown for the third observation in the data
brk <- mid.breakdown(mid, data = airquality, row = 3)
print(brk)
#>
#> MID Breakdown of a Prediction
#>
#> Intercept: 42.099
#>
#> Prediction: 9.9678
#>
#> Breakdown of Effects:
#> term mid order
#> 1 Temp -16.686976 1
#> 2 Day -11.078440 1
#> 3 Wind -9.264052 1
#> 4 Month 3.757259 1
#> 5 Solar.R:Month 0.703515 2
#> 6 Wind:Day 0.502104 2
#> 7 Wind:Month -0.461564 2
#> 8 Solar.R:Wind 0.321344 2
#> 9 Month:Day 0.180978 2
#> 10 Temp:Day 0.120516 2
#> 11 Solar.R:Day -0.069253 2
#> 12 Temp:Month -0.068488 2
#> 13 Solar.R -0.035010 1
#> 14 Wind:Temp -0.030329 2
#> 15 Solar.R:Temp -0.022898 2
