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). For plotting, check the examples in visualisation_recipe.

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

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

Confidence Interval (CI) level. Default to 0.95 (95%).

keep_iterations

If TRUE, will keep all iterations (draws) of bootstrapped or Bayesian models. They will be added as additional columns named iter_1, iter_2, .... You can reshape them to a long format 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

library(modelbased)

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

# Get predicted and prediction interval (see insight::get_predicted)
estimate_response(model)
#> Model-based Prediction
#> 
#> wt   | Predicted |   SE |         95% CI | Residuals
#> ----------------------------------------------------
#> 2.62 |     23.28 | 3.11 | [16.93, 29.64] |      2.28
#> 2.88 |     21.92 | 3.10 | [15.59, 28.25] |      0.92
#> 2.32 |     24.89 | 3.13 | [18.49, 31.29] |      2.09
#> 3.21 |     20.10 | 3.09 | [13.79, 26.42] |     -1.30
#> 3.44 |     18.90 | 3.10 | [12.58, 25.22] |      0.20
#> 3.46 |     18.79 | 3.10 | [12.47, 25.12] |      0.69
#> 3.57 |     18.21 | 3.10 | [11.88, 24.54] |      3.91
#> 3.19 |     20.24 | 3.09 | [13.92, 26.55] |     -4.16
#> 3.15 |     20.45 | 3.09 | [14.13, 26.77] |     -2.35
#> 3.44 |     18.90 | 3.10 | [12.58, 25.22] |     -0.30
#> 3.44 |     18.90 | 3.10 | [12.58, 25.22] |      1.10
#> 4.07 |     15.53 | 3.13 | [ 9.14, 21.92] |     -0.87
#> 3.73 |     17.35 | 3.11 | [11.01, 23.69] |      0.05
#> 3.78 |     17.08 | 3.11 | [10.73, 23.43] |      1.88
#> 5.25 |      9.23 | 3.30 | [ 2.50, 15.96] |     -1.17
#> 5.42 |      8.30 | 3.33 | [ 1.50, 15.10] |     -2.10
#> 5.34 |      8.72 | 3.31 | [ 1.95, 15.49] |     -5.98
#> 2.20 |     25.53 | 3.14 | [19.10, 31.95] |     -6.87
#> 1.61 |     28.65 | 3.22 | [22.08, 35.23] |     -1.75
#> 1.83 |     27.48 | 3.19 | [20.97, 33.99] |     -6.42
#> 2.46 |     24.11 | 3.12 | [17.74, 30.49] |      2.61
#> 3.52 |     18.47 | 3.10 | [12.15, 24.80] |      2.97
#> 3.44 |     18.93 | 3.10 | [12.61, 25.25] |      3.73
#> 3.84 |     16.76 | 3.11 | [10.41, 23.12] |      3.46
#> 3.85 |     16.74 | 3.11 | [10.38, 23.09] |     -2.46
#> 1.94 |     26.94 | 3.18 | [20.46, 33.43] |     -0.36
#> 2.14 |     25.85 | 3.15 | [19.41, 32.28] |     -0.15
#> 1.51 |     29.20 | 3.24 | [22.59, 35.81] |     -1.20
#> 3.17 |     20.34 | 3.09 | [14.03, 26.66] |      4.54
#> 2.77 |     22.48 | 3.10 | [16.14, 28.82] |      2.78
#> 3.57 |     18.21 | 3.10 | [11.88, 24.54] |      3.21
#> 2.78 |     22.43 | 3.10 | [16.09, 28.76] |      1.03
#> 
#> Variable predicted: mpg

# Get expected values with confidence interval
pred <- estimate_relation(model)
pred
#> Model-based Expectation
#> 
#> wt   | Predicted |   SE |         95% CI
#> ----------------------------------------
#> 1.51 |     29.20 | 1.09 | [26.96, 31.43]
#> 1.95 |     26.88 | 0.89 | [25.06, 28.70]
#> 2.38 |     24.55 | 0.71 | [23.10, 26.01]
#> 2.82 |     22.23 | 0.58 | [21.04, 23.42]
#> 3.25 |     19.91 | 0.54 | [18.81, 21.01]
#> 3.69 |     17.59 | 0.60 | [16.36, 18.81]
#> 4.12 |     15.26 | 0.74 | [13.76, 16.77]
#> 4.55 |     12.94 | 0.92 | [11.06, 14.82]
#> 4.99 |     10.62 | 1.13 | [ 8.32, 12.92]
#> 5.42 |      8.30 | 1.35 | [ 5.55, 11.05]
#> 
#> Variable predicted: mpg
#> Predictors modulated: wt

# Visualisation (see visualisation_recipe())
plot(pred)


# Standardize predictions
pred <- estimate_relation(lm(mpg ~ wt + am, data = mtcars))
z <- effectsize::standardize(pred, include_response = FALSE)
z
#> Model-based Expectation (standardized)
#> 
#> wt    |    am | Predicted |   SE |         95% CI
#> -------------------------------------------------
#> -1.74 | -0.81 |     29.22 | 1.91 | [25.31, 33.14]
#> -1.30 | -0.81 |     26.90 | 1.60 | [23.62, 30.17]
#> -0.85 | -0.81 |     24.57 | 1.30 | [21.90, 27.24]
#> -0.41 | -0.81 |     22.24 | 1.03 | [20.13, 24.36]
#> 0.03  | -0.81 |     19.92 | 0.82 | [18.24, 21.59]
#> 0.48  | -0.81 |     17.59 | 0.71 | [16.13, 19.05]
#> 0.92  | -0.81 |     15.27 | 0.76 | [13.71, 16.83]
#> 1.37  | -0.81 |     12.94 | 0.94 | [11.01, 14.87]
#> 1.81  | -0.81 |     10.61 | 1.20 | [ 8.17, 13.06]
#> 2.26  | -0.81 |      8.29 | 1.49 | [ 5.25, 11.33]
#> -1.74 | -0.59 |     29.22 | 1.78 | [25.58, 32.86]
#> -1.30 | -0.59 |     26.89 | 1.46 | [23.90, 29.89]
#> -0.85 | -0.59 |     24.57 | 1.17 | [22.19, 26.95]
#> -0.41 | -0.59 |     22.24 | 0.90 | [20.40, 24.08]
#> 0.03  | -0.59 |     19.92 | 0.70 | [18.48, 21.35]
#> 0.48  | -0.59 |     17.59 | 0.64 | [16.28, 18.90]
#> 0.92  | -0.59 |     15.26 | 0.75 | [13.73, 16.80]
#> 1.37  | -0.59 |     12.94 | 0.98 | [10.94, 14.93]
#> 1.81  | -0.59 |     10.61 | 1.26 | [ 8.04, 13.18]
#> 2.26  | -0.59 |      8.29 | 1.56 | [ 5.09, 11.48]
#> -1.74 | -0.37 |     29.22 | 1.65 | [25.85, 32.59]
#> -1.30 | -0.37 |     26.89 | 1.33 | [24.17, 29.62]
#> -0.85 | -0.37 |     24.57 | 1.04 | [22.45, 26.68]
#> -0.41 | -0.37 |     22.24 | 0.78 | [20.65, 23.83]
#> 0.03  | -0.37 |     19.91 | 0.61 | [18.67, 21.16]
#> 0.48  | -0.37 |     17.59 | 0.61 | [16.34, 18.83]
#> 0.92  | -0.37 |     15.26 | 0.78 | [13.67, 16.85]
#> 1.37  | -0.37 |     12.93 | 1.04 | [10.81, 15.06]
#> 1.81  | -0.37 |     10.61 | 1.33 | [ 7.88, 13.34]
#> 2.26  | -0.37 |      8.28 | 1.65 | [ 4.91, 11.66]
#> -1.74 | -0.15 |     29.21 | 1.53 | [26.10, 32.33]
#> -1.30 | -0.15 |     26.89 | 1.21 | [24.41, 29.37]
#> -0.85 | -0.15 |     24.56 | 0.92 | [22.68, 26.45]
#> -0.41 | -0.15 |     22.24 | 0.68 | [20.85, 23.63]
#> 0.03  | -0.15 |     19.91 | 0.56 | [18.77, 21.05]
#> 0.48  | -0.15 |     17.58 | 0.63 | [16.30, 18.86]
#> 0.92  | -0.15 |     15.26 | 0.84 | [13.54, 16.98]
#> 1.37  | -0.15 |     12.93 | 1.12 | [10.64, 15.23]
#> 1.81  | -0.15 |     10.61 | 1.43 | [ 7.68, 13.53]
#> 2.26  | -0.15 |      8.28 | 1.75 | [ 4.70, 11.86]
#> -1.74 |  0.08 |     29.21 | 1.41 | [26.32, 32.10]
#> -1.30 |  0.08 |     26.89 | 1.11 | [24.62, 29.15]
#> -0.85 |  0.08 |     24.56 | 0.83 | [22.87, 26.25]
#> -0.41 |  0.08 |     22.23 | 0.61 | [20.98, 23.49]
#> 0.03  |  0.08 |     19.91 | 0.55 | [18.78, 21.04]
#> 0.48  |  0.08 |     17.58 | 0.69 | [16.18, 18.98]
#> 0.92  |  0.08 |     15.26 | 0.93 | [13.35, 17.16]
#> 1.37  |  0.08 |     12.93 | 1.23 | [10.42, 15.44]
#> 1.81  |  0.08 |     10.60 | 1.54 | [ 7.46, 13.75]
#> 2.26  |  0.08 |      8.28 | 1.86 | [ 4.47, 12.09]
#> -1.74 |  0.30 |     29.21 | 1.31 | [26.52, 31.90]
#> -1.30 |  0.30 |     26.88 | 1.02 | [24.80, 28.96]
#> -0.85 |  0.30 |     24.56 | 0.76 | [23.01, 26.11]
#> -0.41 |  0.30 |     22.23 | 0.59 | [21.02, 23.44]
#> 0.03  |  0.30 |     19.91 | 0.60 | [18.67, 21.14]
#> 0.48  |  0.30 |     17.58 | 0.78 | [15.98, 19.17]
#> 0.92  |  0.30 |     15.25 | 1.04 | [13.12, 17.39]
#> 1.37  |  0.30 |     12.93 | 1.34 | [10.18, 15.67]
#> 1.81  |  0.30 |     10.60 | 1.66 | [ 7.21, 13.99]
#> 2.26  |  0.30 |      8.27 | 1.98 | [ 4.22, 12.33]
#> -1.74 |  0.52 |     29.21 | 1.23 | [26.69, 31.73]
#> -1.30 |  0.52 |     26.88 | 0.95 | [24.93, 28.83]
#> -0.85 |  0.52 |     24.55 | 0.73 | [23.07, 26.04]
#> -0.41 |  0.52 |     22.23 | 0.62 | [20.96, 23.50]
#> 0.03  |  0.52 |     19.90 | 0.69 | [18.49, 21.32]
#> 0.48  |  0.52 |     17.58 | 0.90 | [15.74, 19.41]
#> 0.92  |  0.52 |     15.25 | 1.17 | [12.86, 17.64]
#> 1.37  |  0.52 |     12.92 | 1.47 | [ 9.92, 15.93]
#> 1.81  |  0.52 |     10.60 | 1.79 | [ 6.94, 14.25]
#> 2.26  |  0.52 |      8.27 | 2.11 | [ 3.95, 12.59]
#> -1.74 |  0.74 |     29.20 | 1.17 | [26.81, 31.59]
#> -1.30 |  0.74 |     26.88 | 0.91 | [25.01, 28.75]
#> -0.85 |  0.74 |     24.55 | 0.73 | [23.05, 26.05]
#> -0.41 |  0.74 |     22.23 | 0.69 | [20.81, 23.64]
#> 0.03  |  0.74 |     19.90 | 0.81 | [18.25, 21.55]
#> 0.48  |  0.74 |     17.57 | 1.03 | [15.47, 19.68]
#> 0.92  |  0.74 |     15.25 | 1.30 | [12.58, 17.92]
#> 1.37  |  0.74 |     12.92 | 1.61 | [ 9.64, 16.21]
#> 1.81  |  0.74 |     10.60 | 1.92 | [ 6.67, 14.53]
#> 2.26  |  0.74 |      8.27 | 2.24 | [ 3.68, 12.86]
#> -1.74 |  0.97 |     29.20 | 1.13 | [26.89, 31.51]
#> -1.30 |  0.97 |     26.88 | 0.91 | [25.02, 28.73]
#> -0.85 |  0.97 |     24.55 | 0.78 | [22.95, 26.15]
#> -0.41 |  0.97 |     22.22 | 0.79 | [20.60, 23.85]
#> 0.03  |  0.97 |     19.90 | 0.94 | [17.97, 21.82]
#> 0.48  |  0.97 |     17.57 | 1.17 | [15.17, 19.97]
#> 0.92  |  0.97 |     15.25 | 1.45 | [12.28, 18.21]
#> 1.37  |  0.97 |     12.92 | 1.75 | [ 9.34, 16.50]
#> 1.81  |  0.97 |     10.59 | 2.06 | [ 6.38, 14.81]
#> 2.26  |  0.97 |      8.27 | 2.38 | [ 3.39, 13.14]
#> -1.74 |  1.19 |     29.20 | 1.11 | [26.92, 31.48]
#> -1.30 |  1.19 |     26.87 | 0.93 | [24.96, 28.78]
#> -0.85 |  1.19 |     24.55 | 0.86 | [22.79, 26.30]
#> -0.41 |  1.19 |     22.22 | 0.92 | [20.35, 24.10]
#> 0.03  |  1.19 |     19.89 | 1.08 | [17.68, 22.11]
#> 0.48  |  1.19 |     17.57 | 1.32 | [14.86, 20.27]
#> 0.92  |  1.19 |     15.24 | 1.60 | [11.97, 18.51]
#> 1.37  |  1.19 |     12.92 | 1.90 | [ 9.04, 16.79]
#> 1.81  |  1.19 |     10.59 | 2.21 | [ 6.08, 15.10]
#> 2.26  |  1.19 |      8.26 | 2.53 | [ 3.10, 13.43]
#> 
#> Variable predicted: mpg
#> Predictors modulated: wt, am
effectsize::unstandardize(z, include_response = FALSE)
#> Model-based Expectation (standardized)
#> 
#> wt   |   am | Predicted |   SE |         95% CI
#> -----------------------------------------------
#> 1.51 | 0.00 |     29.22 | 1.91 | [25.31, 33.14]
#> 1.95 | 0.00 |     26.90 | 1.60 | [23.62, 30.17]
#> 2.38 | 0.00 |     24.57 | 1.30 | [21.90, 27.24]
#> 2.82 | 0.00 |     22.24 | 1.03 | [20.13, 24.36]
#> 3.25 | 0.00 |     19.92 | 0.82 | [18.24, 21.59]
#> 3.69 | 0.00 |     17.59 | 0.71 | [16.13, 19.05]
#> 4.12 | 0.00 |     15.27 | 0.76 | [13.71, 16.83]
#> 4.55 | 0.00 |     12.94 | 0.94 | [11.01, 14.87]
#> 4.99 | 0.00 |     10.61 | 1.20 | [ 8.17, 13.06]
#> 5.42 | 0.00 |      8.29 | 1.49 | [ 5.25, 11.33]
#> 1.51 | 0.11 |     29.22 | 1.78 | [25.58, 32.86]
#> 1.95 | 0.11 |     26.89 | 1.46 | [23.90, 29.89]
#> 2.38 | 0.11 |     24.57 | 1.17 | [22.19, 26.95]
#> 2.82 | 0.11 |     22.24 | 0.90 | [20.40, 24.08]
#> 3.25 | 0.11 |     19.92 | 0.70 | [18.48, 21.35]
#> 3.69 | 0.11 |     17.59 | 0.64 | [16.28, 18.90]
#> 4.12 | 0.11 |     15.26 | 0.75 | [13.73, 16.80]
#> 4.55 | 0.11 |     12.94 | 0.98 | [10.94, 14.93]
#> 4.99 | 0.11 |     10.61 | 1.26 | [ 8.04, 13.18]
#> 5.42 | 0.11 |      8.29 | 1.56 | [ 5.09, 11.48]
#> 1.51 | 0.22 |     29.22 | 1.65 | [25.85, 32.59]
#> 1.95 | 0.22 |     26.89 | 1.33 | [24.17, 29.62]
#> 2.38 | 0.22 |     24.57 | 1.04 | [22.45, 26.68]
#> 2.82 | 0.22 |     22.24 | 0.78 | [20.65, 23.83]
#> 3.25 | 0.22 |     19.91 | 0.61 | [18.67, 21.16]
#> 3.69 | 0.22 |     17.59 | 0.61 | [16.34, 18.83]
#> 4.12 | 0.22 |     15.26 | 0.78 | [13.67, 16.85]
#> 4.55 | 0.22 |     12.93 | 1.04 | [10.81, 15.06]
#> 4.99 | 0.22 |     10.61 | 1.33 | [ 7.88, 13.34]
#> 5.42 | 0.22 |      8.28 | 1.65 | [ 4.91, 11.66]
#> 1.51 | 0.33 |     29.21 | 1.53 | [26.10, 32.33]
#> 1.95 | 0.33 |     26.89 | 1.21 | [24.41, 29.37]
#> 2.38 | 0.33 |     24.56 | 0.92 | [22.68, 26.45]
#> 2.82 | 0.33 |     22.24 | 0.68 | [20.85, 23.63]
#> 3.25 | 0.33 |     19.91 | 0.56 | [18.77, 21.05]
#> 3.69 | 0.33 |     17.58 | 0.63 | [16.30, 18.86]
#> 4.12 | 0.33 |     15.26 | 0.84 | [13.54, 16.98]
#> 4.55 | 0.33 |     12.93 | 1.12 | [10.64, 15.23]
#> 4.99 | 0.33 |     10.61 | 1.43 | [ 7.68, 13.53]
#> 5.42 | 0.33 |      8.28 | 1.75 | [ 4.70, 11.86]
#> 1.51 | 0.44 |     29.21 | 1.41 | [26.32, 32.10]
#> 1.95 | 0.44 |     26.89 | 1.11 | [24.62, 29.15]
#> 2.38 | 0.44 |     24.56 | 0.83 | [22.87, 26.25]
#> 2.82 | 0.44 |     22.23 | 0.61 | [20.98, 23.49]
#> 3.25 | 0.44 |     19.91 | 0.55 | [18.78, 21.04]
#> 3.69 | 0.44 |     17.58 | 0.69 | [16.18, 18.98]
#> 4.12 | 0.44 |     15.26 | 0.93 | [13.35, 17.16]
#> 4.55 | 0.44 |     12.93 | 1.23 | [10.42, 15.44]
#> 4.99 | 0.44 |     10.60 | 1.54 | [ 7.46, 13.75]
#> 5.42 | 0.44 |      8.28 | 1.86 | [ 4.47, 12.09]
#> 1.51 | 0.56 |     29.21 | 1.31 | [26.52, 31.90]
#> 1.95 | 0.56 |     26.88 | 1.02 | [24.80, 28.96]
#> 2.38 | 0.56 |     24.56 | 0.76 | [23.01, 26.11]
#> 2.82 | 0.56 |     22.23 | 0.59 | [21.02, 23.44]
#> 3.25 | 0.56 |     19.91 | 0.60 | [18.67, 21.14]
#> 3.69 | 0.56 |     17.58 | 0.78 | [15.98, 19.17]
#> 4.12 | 0.56 |     15.25 | 1.04 | [13.12, 17.39]
#> 4.55 | 0.56 |     12.93 | 1.34 | [10.18, 15.67]
#> 4.99 | 0.56 |     10.60 | 1.66 | [ 7.21, 13.99]
#> 5.42 | 0.56 |      8.27 | 1.98 | [ 4.22, 12.33]
#> 1.51 | 0.67 |     29.21 | 1.23 | [26.69, 31.73]
#> 1.95 | 0.67 |     26.88 | 0.95 | [24.93, 28.83]
#> 2.38 | 0.67 |     24.55 | 0.73 | [23.07, 26.04]
#> 2.82 | 0.67 |     22.23 | 0.62 | [20.96, 23.50]
#> 3.25 | 0.67 |     19.90 | 0.69 | [18.49, 21.32]
#> 3.69 | 0.67 |     17.58 | 0.90 | [15.74, 19.41]
#> 4.12 | 0.67 |     15.25 | 1.17 | [12.86, 17.64]
#> 4.55 | 0.67 |     12.92 | 1.47 | [ 9.92, 15.93]
#> 4.99 | 0.67 |     10.60 | 1.79 | [ 6.94, 14.25]
#> 5.42 | 0.67 |      8.27 | 2.11 | [ 3.95, 12.59]
#> 1.51 | 0.78 |     29.20 | 1.17 | [26.81, 31.59]
#> 1.95 | 0.78 |     26.88 | 0.91 | [25.01, 28.75]
#> 2.38 | 0.78 |     24.55 | 0.73 | [23.05, 26.05]
#> 2.82 | 0.78 |     22.23 | 0.69 | [20.81, 23.64]
#> 3.25 | 0.78 |     19.90 | 0.81 | [18.25, 21.55]
#> 3.69 | 0.78 |     17.57 | 1.03 | [15.47, 19.68]
#> 4.12 | 0.78 |     15.25 | 1.30 | [12.58, 17.92]
#> 4.55 | 0.78 |     12.92 | 1.61 | [ 9.64, 16.21]
#> 4.99 | 0.78 |     10.60 | 1.92 | [ 6.67, 14.53]
#> 5.42 | 0.78 |      8.27 | 2.24 | [ 3.68, 12.86]
#> 1.51 | 0.89 |     29.20 | 1.13 | [26.89, 31.51]
#> 1.95 | 0.89 |     26.88 | 0.91 | [25.02, 28.73]
#> 2.38 | 0.89 |     24.55 | 0.78 | [22.95, 26.15]
#> 2.82 | 0.89 |     22.22 | 0.79 | [20.60, 23.85]
#> 3.25 | 0.89 |     19.90 | 0.94 | [17.97, 21.82]
#> 3.69 | 0.89 |     17.57 | 1.17 | [15.17, 19.97]
#> 4.12 | 0.89 |     15.25 | 1.45 | [12.28, 18.21]
#> 4.55 | 0.89 |     12.92 | 1.75 | [ 9.34, 16.50]
#> 4.99 | 0.89 |     10.59 | 2.06 | [ 6.38, 14.81]
#> 5.42 | 0.89 |      8.27 | 2.38 | [ 3.39, 13.14]
#> 1.51 | 1.00 |     29.20 | 1.11 | [26.92, 31.48]
#> 1.95 | 1.00 |     26.87 | 0.93 | [24.96, 28.78]
#> 2.38 | 1.00 |     24.55 | 0.86 | [22.79, 26.30]
#> 2.82 | 1.00 |     22.22 | 0.92 | [20.35, 24.10]
#> 3.25 | 1.00 |     19.89 | 1.08 | [17.68, 22.11]
#> 3.69 | 1.00 |     17.57 | 1.32 | [14.86, 20.27]
#> 4.12 | 1.00 |     15.24 | 1.60 | [11.97, 18.51]
#> 4.55 | 1.00 |     12.92 | 1.90 | [ 9.04, 16.79]
#> 4.99 | 1.00 |     10.59 | 2.21 | [ 6.08, 15.10]
#> 5.42 | 1.00 |      8.26 | 2.53 | [ 3.10, 13.43]
#> 
#> Variable predicted: mpg
#> Predictors modulated: wt, am

# Logistic Models
model <- glm(vs ~ wt, data = mtcars, family = "binomial")
estimate_response(model)
#> Model-based Prediction
#> 
#> wt   | Predicted |       95% CI | Residuals
#> -------------------------------------------
#> 2.62 |      0.67 | [0.00, 1.00] |      0.67
#> 2.88 |      0.56 | [0.00, 1.00] |      0.56
#> 2.32 |      0.78 | [0.00, 1.00] |     -0.22
#> 3.21 |      0.39 | [0.00, 1.00] |     -0.61
#> 3.44 |      0.30 | [0.00, 1.00] |      0.30
#> 3.46 |      0.29 | [0.00, 1.00] |     -0.71
#> 3.57 |      0.25 | [0.00, 1.00] |      0.25
#> 3.19 |      0.41 | [0.00, 1.00] |     -0.59
#> 3.15 |      0.42 | [0.00, 1.00] |     -0.58
#> 3.44 |      0.30 | [0.00, 1.00] |     -0.70
#> 3.44 |      0.30 | [0.00, 1.00] |     -0.70
#> 4.07 |      0.11 | [0.00, 1.00] |      0.11
#> 3.73 |      0.20 | [0.00, 1.00] |      0.20
#> 3.78 |      0.18 | [0.00, 1.00] |      0.18
#> 5.25 |      0.01 | [0.00, 0.00] |      0.01
#> 5.42 |  9.49e-03 | [0.00, 0.00] |  9.49e-03
#> 5.34 |      0.01 | [0.00, 0.00] |      0.01
#> 2.20 |      0.82 | [0.00, 1.00] |     -0.18
#> 1.61 |      0.93 | [0.00, 1.00] |     -0.07
#> 1.83 |      0.90 | [0.00, 1.00] |     -0.10
#> 2.46 |      0.73 | [0.00, 1.00] |     -0.27
#> 3.52 |      0.27 | [0.00, 1.00] |      0.27
#> 3.44 |      0.30 | [0.00, 1.00] |      0.30
#> 3.84 |      0.16 | [0.00, 1.00] |      0.16
#> 3.85 |      0.16 | [0.00, 1.00] |      0.16
#> 1.94 |      0.88 | [0.00, 1.00] |     -0.12
#> 2.14 |      0.84 | [0.00, 1.00] |      0.84
#> 1.51 |      0.94 | [0.00, 1.00] |     -0.06
#> 3.17 |      0.42 | [0.00, 1.00] |      0.42
#> 2.77 |      0.60 | [0.00, 1.00] |      0.60
#> 3.57 |      0.25 | [0.00, 1.00] |      0.25
#> 2.78 |      0.60 | [0.00, 1.00] |     -0.40
#> 
#> Variable predicted: vs
estimate_relation(model)
#> Model-based Expectation
#> 
#> wt   | Predicted |   SE |       95% CI
#> --------------------------------------
#> 1.51 |      0.94 | 0.07 | [0.60, 0.99]
#> 1.95 |      0.88 | 0.10 | [0.53, 0.98]
#> 2.38 |      0.76 | 0.12 | [0.46, 0.92]
#> 2.82 |      0.58 | 0.12 | [0.35, 0.78]
#> 3.25 |      0.38 | 0.11 | [0.20, 0.60]
#> 3.69 |      0.21 | 0.10 | [0.07, 0.47]
#> 4.12 |      0.10 | 0.08 | [0.02, 0.38]
#> 4.55 |      0.05 | 0.05 | [0.01, 0.32]
#> 4.99 |      0.02 | 0.03 | [0.00, 0.27]
#> 5.42 |  9.49e-03 | 0.02 | [0.00, 0.23]
#> 
#> Variable predicted: vs
#> Predictors modulated: wt

# Mixed models
if (require("lme4")) {
  model <- lmer(mpg ~ wt + (1 | gear), data = mtcars)
  estimate_response(model)
  estimate_relation(model)
}
#> Model-based Expectation
#> 
#> wt   | Predicted |   SE |         95% CI
#> ----------------------------------------
#> 1.51 |     28.56 | 1.37 | [25.75, 31.37]
#> 1.95 |     26.36 | 1.18 | [23.95, 28.78]
#> 2.38 |     24.17 | 1.03 | [22.07, 26.27]
#> 2.82 |     21.98 | 0.93 | [20.07, 23.89]
#> 3.25 |     19.79 | 0.92 | [17.91, 21.67]
#> 3.69 |     17.60 | 0.98 | [15.58, 19.61]
#> 4.12 |     15.40 | 1.12 | [13.11, 17.69]
#> 4.55 |     13.21 | 1.30 | [10.55, 15.87]
#> 4.99 |     11.02 | 1.51 | [ 7.93, 14.11]
#> 5.42 |      8.83 | 1.74 | [ 5.27, 12.39]
#> 
#> Variable predicted: mpg
#> Predictors modulated: wt

# Bayesian models
# \donttest{
if (require("rstanarm")) {
  model <- rstanarm::stan_glm(mpg ~ wt, data = mtcars, refresh = 0, iter = 200)
  estimate_response(model)
  estimate_relation(model)
}
#> Loading required package: rstanarm
#> Loading required package: Rcpp
#> This is rstanarm version 2.21.1
#> - See https://mc-stan.org/rstanarm/articles/priors for changes to default priors!
#> - Default priors may change, so it's safest to specify priors, even if equivalent to the defaults.
#> - For execution on a local, multicore CPU with excess RAM we recommend calling
#>   options(mc.cores = parallel::detectCores())
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> http://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> http://mc-stan.org/misc/warnings.html#tail-ess
#> Model-based Expectation
#> 
#> wt   | Predicted |   SE |         95% CI
#> ----------------------------------------
#> 1.51 |     29.21 | 1.19 | [26.86, 31.64]
#> 1.95 |     26.88 | 0.94 | [24.84, 28.69]
#> 2.38 |     24.54 | 0.74 | [23.00, 25.97]
#> 2.82 |     22.20 | 0.59 | [21.04, 23.51]
#> 3.25 |     19.86 | 0.50 | [18.75, 21.00]
#> 3.69 |     17.52 | 0.60 | [16.20, 18.67]
#> 4.12 |     15.18 | 0.76 | [13.71, 16.62]
#> 4.55 |     12.85 | 0.96 | [10.92, 14.57]
#> 4.99 |     10.51 | 1.23 | [ 8.09, 12.62]
#> 5.42 |      8.17 | 1.45 | [ 5.35, 10.81]
#> 
#> Variable predicted: mpg
#> Predictors modulated: wt
# }