sim_er {BayesERtools} | R Documentation |
Simulate from ER model
Description
Simulate from ER model
Usage
sim_er(
ermod,
newdata = NULL,
n_draws_sim = NULL,
seed_sample_draws = NULL,
output_type = c("draws", "median_qi"),
qi_width = 0.95,
.nrow_cov_data = NULL
)
Arguments
ermod |
An object of class |
newdata |
New data to use for simulation. Default is NULL (use the data in the model object). |
n_draws_sim |
Number of draws for simulation. If NULL (default), all draws in the model object are used. |
seed_sample_draws |
Seed for sampling draws. Default is NULL. |
output_type |
Type of output. "draws" returns the raw draws from the simulation, and "median_qi" returns the median and quantile interval. |
qi_width |
Width of the quantile interval. Default is 0.95. Only
used when |
.nrow_cov_data |
Number of rows in the covariate data, used for internal purposes. Users should not set this argument. |
Value
ersim
object, which is a tibble with the simulated responses
with some additional information in object attributes.
It has three types of predictions - .linpred
, .epred
, .prediction
.
.linpred
and .epred
are similar in a way that they both represent
"expected response", i.e. without residual variability. They are the same
for models with continuous endpoits (Emax model). For models with binary
endpoints, .linpred
is the linear predictor (i.e. on the logit scale) and
.epred
is on the probability scale. .prediction
is the predicted
response with residual variability (or in case of binary endpoint,
the predicted yes (1) or no (0) for event occurrence).
See tidybayes::add_epred_draws()
for more details.
In case of output_type = "median_qi"
, it returns ersim_med_qi
object.
See Also
calc_ersim_med_qi()
for calculating median and quantile interval
from ersim
object (generated with output_type = "draws"
).
Examples
data(d_sim_binom_cov_hgly2)
ermod_bin <- dev_ermod_bin(
data = d_sim_binom_cov_hgly2,
var_resp = "AEFLAG",
var_exposure = "AUCss_1000",
var_cov = "BHBA1C_5",
)
ersim <- sim_er(
ermod_bin,
n_draws_sim = 500, # This is set to make the example run faster
output_type = "draws"
)
ersim_med_qi <- sim_er(
ermod_bin,
n_draws_sim = 500, # This is set to make the example run faster
output_type = "median_qi"
)
ersim
ersim_med_qi