# First model with interactions
fit_nonadd <- lm(
Sepal.Length ~ . + Sepal.Width:Species + Petal.Width:Species, data = iris
)
fl_nonadd <- flashlight(
model = fit_nonadd, label = "nonadditive", data = iris, y = "Sepal.Length"
)
# Friedman's H per feature
plot(light_interaction(fl_nonadd), fill = "chartreuse4")
# Unnormalized H^2 measures proportion of bivariate effect explained by interaction
plot(
light_interaction(fl_nonadd, normalize = TRUE, take_sqrt = TRUE),
fill = "chartreuse4"
)
# Pairwise H
plot(light_interaction(fl_nonadd, pairwise = TRUE), fill = "chartreuse4")
# Second model without interactions
fit_add <- lm(Sepal.Length ~ ., data = iris)
fl_add <- flashlight(
model = fit_add, label = "additive", data = iris, y = "Sepal.Length"
)
fls <- multiflashlight(list(fl_add, fl_nonadd))
plot(light_interaction(fls), fill = "chartreuse4")
Run the code above in your browser using DataLab