Learn R Programming

modelbased (version 0.6.0)

estimate_relation: Generates predictions from models

Description

estimate_link is a shortcut to estimate_response with data = "grid". estimate_response would be used in the context of generating actual predictions for the existing or new data, whereas estimate_link is more relevant in the context of visualisation and plotting. There are many control parameters that are not listed here but can be used, such as the arguments from visualisation_matrix (used when data = "grid") and from insight::get_predicted() (the function to compute predictions used internally).

Usage

estimate_relation(
  model,
  data = "grid",
  ci = 0.95,
  keep_iterations = FALSE,
  ...
)

estimate_link(model, data = "grid", ci = 0.95, keep_iterations = FALSE, ...)

estimate_prediction( model, data = NULL, ci = 0.95, keep_iterations = FALSE, ... )

estimate_response(model, data = NULL, ci = 0.95, keep_iterations = FALSE, ...)

Arguments

model

A statistical model.

data

A data frame with model's predictors to estimate the response. If NULL, the model's data is used. If "grid", the model matrix is obtained (through visualisation_matrix).

ci

The interval level (default 0.95, i.e., 95% CI).

keep_iterations

Only relevant for Bayesian models or simulated models. If TRUE, will keep all prediction iterations (draws). You can reshape them by running bayestestR::reshape_iterations().

...

You can add all the additional control arguments from visualisation_matrix (used when data = "grid") and insight::get_predicted().

Value

A dataframe of predicted values.

Examples

Run this code
# NOT RUN {
library(modelbased)

# Linear Models
model <- lm(mpg ~ wt, data = mtcars)
estimate_response(model)
estimate_relation(model)

# Logistic Models
model <- glm(vs ~ wt, data = mtcars, family = "binomial")
estimate_response(model)
estimate_relation(model)

# Mixed models
if (require("lme4")) {
  model <- lmer(mpg ~ wt + (1 | gear), data = mtcars)
  estimate_response(model)
  estimate_relation(model)
}

# Bayesian models
if (require("rstanarm")) {
  model <- rstanarm::stan_glm(mpg ~ wt, data = mtcars, refresh = 0, iter = 200)
  estimate_response(model)
  estimate_relation(model)
}
# }

Run the code above in your browser using DataLab