sim_model: Simulate databases based in models

Description Usage Arguments Value Author(s) Examples

Description

sim_model simulate a database based on common models. The structure used to create the data is similar as the bamlss.formula.

Usage

1
2
3
4
sim_model(formula = list(mean ~ I(0), sd ~ I(1)),
  link_inv = replicate(length(formula), identity), generator = rnorm,
  n = nrow(init_data), responses = 1, init_data = NULL,
  lm_syntax = TRUE, effects_save = TRUE, seed = NULL)

Arguments

formula

List of the parameters, indicating how they should be computed. similar to formula for lm, glm, bamlss, with the difference that it included the coefficients and link function explicitly.

link_inv

A list of function representing the inverse link function for the parameters.

generator

Function to generate the response variables given the parameters

n

Number of observations to be simulated

responses

a numeric value indicating the number of response or a character vector indicating the names of the response variables

init_data

Initial data including some variables to not been simulated.

lm_syntax

Optional logical argument to indicate if the usual syntax of formula.lm should be used.

effects_save

Optional logical argument to save or not generated random effects

seed

Seed to be defined with function set.seed to obtain reproducible results

Value

A tibble containing the simulated predictors, parameters and response variable

Author(s)

Erick A. Chacon-Montalvan

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
f <- list(
  mean ~ I(5 + 0.5 * x1 + 0.1 * x2 + 0.7 * id1),
  sd ~ exp(x1)
)
(model_frame(f, n = 10))
(data <- sim_model(f, n = 100))

# Structure of the model
formula <- list(
  mean ~ I(age ^ 2) + fa(sex, beta = c(-1, 1)),
  sd ~ fa(sex, beta = c(1, 2))
)
idata <- data.frame(s1 = 1:10)
(datasim <- model_frame(formula, idata = idata))
(datasim <- model_frame(formula, n = 10))
(data <- model_frame(formula, n = 10))
(model_response(data))
(datasim2 <- sim_model(formula, n = 10))
library(magrittr)
model_frame(formula, n = 10) %>% model_response()

f <- list(
  mean ~ gp(list(s1), "exp_cor", list(phi = 0.05)),
  sd ~ I(1.6)
)
(data <- sim_model(f, n = 400))
plot(mean ~ s1, data)
plot(response ~ s1, data)

formula <- list(
mean ~ I(0.5 * x1) : I(x2) + re(city, 1, 2),
sd ~ I(1)
)
data <- sim_model(formula, n = 10)

ErickChacon/datasim documentation built on March 25, 2020, 7:53 p.m.