Description Usage Arguments Value Author(s) Examples
msim_model
simulate a database based on common multivariate models. The
structure used to create the data is similar as the bamlss.formula
.
1 2 | msim_model(formula, generator = rnorm, n = 100, init_data = NULL,
seed = NULL, extent = 1)
|
formula |
List of the parameters, indicating how they should be computed.
similar to formula for |
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 |
extent |
Spatial extent for the simulation of coordinates when a spatial effect is included. |
a tibble
containing the simulated predictors, parameters and response
variable
Erick Albacharro Chacon-Montalvan
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.