msim_model: Simulate Databases Based in Multivariate Models

Description Usage Arguments Value Author(s) Examples

Description

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

Usage

1
2
msim_model(formula, generator = rnorm, n = 100, init_data = NULL,
  seed = NULL, extent = 1)

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.

generator

Function to generate the response variables given the parameters

n

Number of observations to be simulated

init_data

Initial data including some variables to not been simulated.

seed

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

extent

Spatial extent for the simulation of coordinates when a spatial effect is included.

Value

a tibble containing the simulated predictors, parameters and response variable

Author(s)

Erick Albacharro 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
# Covariance parameters
n <- 100
q <- 2
var <- sqrt(diag(c(4, 4)))
A <- matrix(c(1, - 0.8, 0, 0.6), nrow = 2)
variance <- var %*% tcrossprod(A) %*% var
nugget <- diag(0, q)
phi <- rep(1 / 0.08, q)

# Structure of the model
formula <- list(
  mean ~ psych::logistic(
    mgp(s1, s2, "exponential", get("variance"), get("nugget"), get("phi"))),
  sd ~ 1
)

# Simulate data based on formula
library(tidyr)
library(dplyr)
data <- msim_model(formula, generator = rnorm, n = n, extent = 2, seed = 1)
data_long <- gather(data, yname, yval, matches("^y[0-9]+"))

# Plot the observed realization
library(ggplot2)
spgg <- ggplot(data_long, aes(s1, s2, size = yval, col = yval)) +
  geom_point() +
  scale_colour_gradientn(colours = terrain.colors(10)) +
  facet_wrap(~ yname)
print(spgg)

ErickChacon/day2day documentation built on May 6, 2019, 4:03 p.m.