add_fitted_sims.psem: Generate fitted simulations from a psem model

View source: R/piecewisesem_psem_predict_sims.R

add_fitted_sims.psemR Documentation

Generate fitted simulations from a psem model

Description

Generate simulations from a psem model incorporating either error in fitted 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()

Usage

## S3 method for class 'psem'
add_fitted_sims(newdata, mod, n_sims = 1000, seed = NULL, ...)

Arguments

newdata

a data.frame of new data to predict

mod

An piecewiseSEM::psem() object to simulate from.

n_sims

number of simulation samples to construct

seed

numeric, optional argument to set seed for simulations

...

Unused dots for compatibility with generic functions.

Value

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

See Also

Other psem: add_predicted_sims.psem()

Examples


## Not run: 

library(piecewiseSEM)
data(keeley)
mod <- psem(
 lm(abiotic ~ distance, data=keeley),
 lm(rich ~ abiotic + hetero, data=keeley),
 lm(hetero ~ distance, data=keeley),
 data = keeley)

newdat <- data.frame(distance=c(30, 50))

new_fitted_sims <- newdat %>%
 add_fitted_sims(mod)

head(new_fitted_sims)

## End(Not run)

jebyrnes/sinterval documentation built on March 18, 2023, 5:05 a.m.