vivi_interaction: vivi_interaction

View source: R/vimp_vint.R

vivi_interactionR Documentation

vivi_interaction

Description

Compute pairwise interactions only (Friedman's H), without importance.

Usage

vivi_interaction(
  data,
  fit,
  response,
  nmax = 500,
  gridSize = 50,
  predictFun = NULL,
  normalized = FALSE,
  vars = NULL,
  reorder = TRUE
)

Arguments

data

Data frame used for fit.

fit

A supervised ML model understood by condvis2::CVpredict (or supply predictFun).

response

Name of the response column in data.

nmax

Maximum number of rows to consider for grids. Default 500. Use all rows if NULL.

gridSize

Grid size for evaluating partial dependence. Default 50.

predictFun

Optional prediction function ⁠(fit, data, prob = TRUE/FALSE)⁠. If NULL, an internal CVpredict-based function is used.

normalized

Should H be normalised. Default FALSE.

vars

Optional character vector of feature names to restrict the calculation.

reorder

If TRUE, reorder the resulting matrix with vividReorder(). Default TRUE.

Value

Square interaction matrix with zero diagonal.

Examples

# Example 1 — interactions with a linear model
aq <- na.omit(airquality)
fit_lm <- lm(Ozone ~ ., data = aq)
int_mat <- vivi_interaction(data = aq, fit = fit_lm, response = "Ozone")
dim(int_mat); int_mat[1:3, 1:3]
# viviHeatmap(int_mat)  # if you want to visualise interactions only

# Example 2 — classification with ranger

if (requireNamespace("ranger", quietly = TRUE)) {
  library(ranger)
  fit_rf <- ranger(Species ~ ., data = iris,
                   importance = "impurity", probability = TRUE)
  vivi_interaction(data = iris, fit = fit_rf, response = "Species")
}



vivid documentation built on Aug. 24, 2025, 1:09 a.m.