mid.importance: Calculate MID Importance

View source: R/mid_importance.R

mid.importanceR Documentation

Calculate MID Importance

Description

mid.importance() calculates the MID importance of a fitted MID model. This is a measure of feature importance that quantifies the average contribution of each component function across a dataset.

Usage

mid.importance(
  object,
  data = NULL,
  weights = NULL,
  sort = TRUE,
  measure = 1L,
  max.nsamples = 10000L
)

Arguments

object

a "mid" object.

data

a data frame containing the observations to calculate the importance. If not provided, data is automatically extracted based on the function call.

weights

an optional numeric vector of sample weights.

sort

logical. If TRUE, the output data frame is sorted by importance in descending order.

measure

an integer specifying the measure of importance. Possible alternatives are 1 for the mean absolute effect, 2 for the root mean square effect, and 3 for the median absolute effect.

max.nsamples

an integer specifying the maximum number of samples to retain in the predictions component of the returned object. If the number of observations exceeds this value, a weighted random sample is taken.

Details

The MID importance of a component function (e.g., a main effect or an interaction) is defined as the mean absolute effect on the predictions within the given data. Terms with higher importance have a larger average impact on the model's overall predictions.

Value

mid.importance() returns an object of class "mid.importance". This is a list containing the following components:

importance

a data frame with the calculated importance values, sorted by default.

predictions

the matrix of the fitted or predicted MID values. If the number of observations exceeds max.nsamples, this matrix contains a sampled subset.

measure

a character string describing the type of the importance measure used.

See Also

interpret, plot.mid.importance, ggmid.mid.importance

Examples

data(airquality, package = "datasets")
mid <- interpret(Ozone ~ .^2, data = airquality, lambda = 1)

# Calculate MID importance using median absolute contribution
imp <- mid.importance(mid, data = airquality)
print(imp)

# Calculate MID importance using root mean square contribution
imp <- mid.importance(mid, measure = 2)
print(imp)

midr documentation built on Jan. 16, 2026, 5:06 p.m.