do_simulation: Simulate from a fitted model

Description Usage Arguments Details Value Examples

Description

Simulate datasets from the model previously fit. This function has the additional capability of simulating new data.

Usage

1
do_simulation(model_array, new_values = NA, nsim = 1, seed = NULL)

Arguments

model_array

a tibble retreived from the fit_model() function

new_values

a data frame or tibble containing the values of each predictor to simulate at. Defaults to the given dataset.

nsim

the number of datasets to simulate

seed

an integer specifying how to initialize the random number generator

Details

This simulation function first uses the model to determine the average value at a given set of predictors. Then it generates a random number from the specified type of distribution using the parameters retreived from the prediction.

If a grouping variable was indicated then the simulation is carried out separately for each group.

This function is only supported for the frequentist methods.

Value

A tibble with each row representing one simulated value. Additional model information is returned including the type of model, the equation corresponding to the model, and teh value of the predictors at which a given value was simulated from.

Examples

1
2
3
4
5
6
7
trial_data <- tibble(w = runif(20, 0, 2), x = sample(c(1,2), 20, TRUE), y = rbinom(20, 15, .75))
new_data <- tibble(w = runif(5, 1, 2.5))

pois_model <- make_pois(w) %>% fit_model(frequentist, trial_data, y)
pois_model %>% do_simulation()
pois_model %>% do_simulation(new_data)
pois_model %>% do_simulation(new_data, 3)

bprucka/uttr documentation built on May 27, 2019, 11:54 a.m.