library(knitr)
options(knitr.kable.NA = "")
knitr::opts_chunk$set(comment = ">", dpi = 300)
options(digits = 2)

if (!requireNamespace("ggplot2", quietly = TRUE) ||
  !requireNamespace("mgcv", quietly = TRUE) ||
  !requireNamespace("see", quietly = TRUE)) {
  knitr::opts_chunk$set(eval = FALSE)
}

set.seed(333)

This vignette will present how to visualize the effects and interactions using estimate_relation().

Note that the statistically correct name of estimate_relation is estimate_expectation (which can be used as an alias), as it refers to expected predictions (read more).

Simple regression

Linear relationship

library(modelbased)

model <- lm(Sepal.Length ~ Sepal.Width, data = iris)

visualization_data <- estimate_relation(model)
head(visualization_data)
library(ggplot2)
plot(visualization_data, line = list(color = "red")) +
  theme_minimal()

More complex regressions

Polynomial

lm(Sepal.Length ~ poly(Sepal.Width, 2), data = iris) |>
  modelbased::estimate_relation(length = 50) |>
  plot()

Additive Models

library(mgcv)

mgcv::gam(Sepal.Length ~ s(Sepal.Width), data = iris) |>
  modelbased::estimate_relation(length = 50) |>
  plot()

References



easystats/estimate documentation built on April 5, 2025, 1:36 p.m.