Generate simulations from a lm model incorporating either error in predicted error. Simulations explore the possible space of what a model might predict rather than an interval for use in comparison to Bayesian posteriors for non-Bayesian models. The output format and functions draw inspiration from the tidybayes::tidybayes() library and merTools::predictInterval()

# S3 method for lm
add_predicted_sims(
  newdata,
  mod,
  n_sims = 1000,
  seed = NULL,
  type = c("predict", "fit"),
  ...
)

Arguments

newdata

a data.frame of new data to predict

mod

An lm model to simulate from.

n_sims

number of simulation samples to construct

seed

numeric, optional argument to set seed for simulations

type

Character defining if we are looking at fit or predict intervals.

...

Unused dots for compatibility with generic functions.

Value

A tibble::tibble() with information about simulate values.

See also

Other lm: add_fitted_sims.lm()

Examples

clotting <- data.frame(
   u = c(5,10,15,20,30,40,60,NA,100),
   lot1 = c(118,58,42,35,27,25,21,19,18),
   lot2 = c(69,35,26,21,18,16,13,12,12))

mod <- lm(lot1 ~ log(u) + lot2, data = clotting)

sims_pred <- add_predicted_sims(clotting, mod)

head(sims_pred)
#> # A tibble: 6 × 5
#>       u  lot1  lot2 .sim  lot1_predict
#>   <dbl> <dbl> <dbl> <chr>        <dbl>
#> 1     5   118    69 1             122.
#> 2     5   118    69 2             117.
#> 3     5   118    69 3             118.
#> 4     5   118    69 4             117.
#> 5     5   118    69 5             117.
#> 6     5   118    69 6             118.