fit_mods: Fit a model to simulated datasets

Description Usage Arguments Details Value Examples

View source: R/customizable_functions.R


Fits a specified model to each of the simulated datasets and returns a dataframe summarizing results from fitting the model to each dataset, including the estimated effect and the estimated standard error for that estimated effect. The model is specified through a user-created R function, which must take specific input and return output in a specific format. For more details, see the parameter definitions, the Details section, and the vignette for the eesim package.


fit_mods(data, custom_model = NULL, custom_model_args = list())



A list of simulated data sets. Each simulated dataset must include a column called x with daily exposure values and a column called outcome with daily outcome values. Typically, this will be the outcome from create_sims.


The object name of an R function that defines the code that will be used to fit the model. This object name should not be in quotations. See Details for more.


A list of arguments and their values for a custom model. These arguments are passed through to the function specified with custom_model.


The function specified by the custom_model argument should be a user-created function that inputs a data frame with columns named "x" for exposure values and "outcome" for outcome values. The function must output a data frame with columns called Estimate, Std. Error, t value, Pr(>|t|), 2.5%, and 97.5%. Note that these columns are the output from summary and confint for models fit using a glm call. You may use the function format_out from eesim within your function to produce output with these columns if this model is fit using glm or something similar. For more details and examples, see the vignette for eesim.


A data frame in which each row gives the results from the model-fitting function run on one of the simulated datasets input to the function as the data object. The returned data frame has one row per simulated dataset and the following columns:


# Create a set of simulated datasets and then fit the model defined in `spline_mod` to
# all datasets, using the argument `df_year = 7` in the call to `spline_mod`. The `spline_mod`
# function is included in the `eesim` package and can be investigating by calling the function
# name without parentheses (i.e., `spline_mod`).
sims <- create_sims(n_reps = 10, n = 5 * 365, central = 100, sd = 10,
            exposure_type = "continuous", exposure_trend = "cos1",
            exposure_amp = .6, average_outcome = 22,
            outcome_trend = "no trend", outcome_amp = .6, rr = 1.01)
fit_mods(data = sims, custom_model = spline_mod, custom_model_args = list(df_year = 7))

eesim documentation built on June 4, 2017, 1:03 a.m.