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-07-07 08:29:32 ──────────────────────────
#> ℹ `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/RtmpOD5nUp/shapr_obj_219238c6c398.rds
#>
#> ── Main computation started ──
#>
#> ℹ Using 16 of 16 coalitions.
#> ℹ Coalitions split into 10 batches (mean 1.6 per batch).
# 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-07-07 08:29:32
#> • 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/RtmpOD5nUp/shapr_obj_219238c6c398.rds
#>
#> ── Estimated Shapley values
#> explain_id none Solar.R Wind Temp Month
#> <int> <char> <char> <char> <char> <char>
#> 1: 1 42.79 1.69 -19.59 -6.74 -0.40
#> 2: 2 42.79 -3.86 8.49 -9.39 -0.27
#> 3: 3 42.79 4.92 -5.03 -25.67 -1.33
#>
#> ── Estimated MSEv
#> Estimated MSE of v(S) = 258 (with sd = 96)
# 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 1.694669 -19.594714 -6.739134 -0.3954469
#> 2: 2 42.78704 -3.863361 8.485288 -9.386751 -0.2657278
#> 3: 3 42.78704 4.921258 -5.033180 -25.672340 -1.3301146
expl_summary$timing_summary$total_time_secs # Total computation time
#> [1] 0.4441898
expl_summary$approach # Approach used
#> [1] "gaussian"
# }