Provides a formatted summary of a shapr object and returns an object of class
summary.shapr containing the same information as returned by get_results().
Usage
# S3 method for class 'shapr'
summary(object, digits = 2L, ...)Value
An object of class summary.shapr, which is a named list
with the same accessible components as returned by get_results().
See get_results() for details about each component.
Examples
# \donttest{
# Load example data
data("airquality")
airquality <- airquality[complete.cases(airquality), ]
x_var <- c("Solar.R", "Wind", "Temp", "Month")
y_var <- "Ozone"
# Split data into test and training data
data_train <- head(airquality, -3)
data_explain <- tail(airquality, 3)
x_train <- data_train[, x_var]
x_explain <- data_explain[, x_var]
# Fit a linear model
lm_formula <- as.formula(paste0(y_var, " ~ ", paste0(x_var, collapse = " + ")))
model <- lm(lm_formula, data = data_train)
# Explain predictions
p <- mean(data_train[, y_var])
explanation <- explain(
model = model,
x_explain = x_explain,
x_train = x_train,
approach = "gaussian",
phi0 = p,
n_MC_samples = 1e2
)
#>
#> ── Starting `shapr::explain()` at 2026-05-18 15:36:33 ──────────────────────────
#> ℹ `max_n_coalitions` is `NULL` or larger than `2^n_features = 16`, and is
#> therefore set to `2^n_features = 16`.
#>
#> ── Explanation overview ──
#>
#> • Model class: <lm>
#> • v(S) estimation class: Monte Carlo integration
#> • Approach: gaussian
#> • Procedure: Non-iterative
#> • Number of Monte Carlo integration samples: 100
#> • Number of feature-wise Shapley values: 4
#> • Number of observations to explain: 3
#> • Computations (temporary) saved at: /tmp/RtmpU1rVKw/shapr_obj_19923bc7a54.rds
#>
#> ── Main computation started ──
#>
#> ℹ Using 16 of 16 coalitions.
# Call summary without assignment - prints formatted output to console
summary(explanation)
#>
#> ── Summary of Shapley value explanation ────────────────────────────────────────
#> • Computed with `shapr::explain()` in 0.4 seconds, started 2026-05-18 15:36:33
#> • Model class: <lm>
#> • v(S) estimation class: Monte Carlo integration
#> • Approach: gaussian
#> • Procedure: Non-iterative
#> • Number of Monte Carlo integration samples: 100
#> • Number of feature-wise Shapley values: 4
#> • Number of observations to explain: 3
#> • Number of coalitions used: 16 (of total 16)
#> • Computations (temporary) saved at: /tmp/RtmpU1rVKw/shapr_obj_19923bc7a54.rds
#>
#> ── Estimated Shapley values
#> explain_id none Solar.R Wind Temp Month
#> <int> <char> <char> <char> <char> <char>
#> 1: 1 42.79 2.42 -20.22 -7.24 0.01
#> 2: 2 42.79 -3.14 7.86 -9.89 0.13
#> 3: 3 42.79 5.65 -5.66 -26.17 -0.93
#>
#> ── Estimated MSEv
#> Estimated MSE of v(S) = 275 (with sd = 102)
# Assign to variable - returns shapr.summary with summary information for later use
expl_summary <- summary(explanation) # print(expl_summary) provides the formatted output
# Access components from the summary object
expl_summary$shapley_est # Estimated Shapley values
#> explain_id none Solar.R Wind Temp Month
#> <int> <num> <num> <num> <num> <num>
#> 1: 1 42.78704 2.422441 -20.220654 -7.241425 0.005011148
#> 2: 2 42.78704 -3.135589 7.859349 -9.889042 0.134730248
#> 3: 3 42.78704 5.649030 -5.659119 -26.174630 -0.929656487
expl_summary$timing_summary$total_time_secs # Total computation time
#> [1] 0.4486473
expl_summary$approach # Approach used
#> [1] "gaussian"
# }