This function simulates regressor values from various marginal distributions with custom correlations.
Arguments
- labels
[
character()
]
Unique labels for the regressors.- n
[
integer(1)
]
The number of values per regressor.- marginals
[
list()
]
Optionally marginal distributions for regressors. If not specified, standard normal marginal distributions are used.Each list entry must be named according to a regressor label, and the following distributions are currently supported:
- discrete distributions
-
Poisson:
list(type = "poisson", lambda = ...)
categorical:
list(type = "categorical", p = c(...))
- continuous distributions
-
normal:
list(type = "normal", mean = ..., sd = ...)
uniform:
list(type = "uniform", min = ..., max = ...)
- correlation
[
matrix()
]
A correlation matrix of dimensionlength(labels)
, where the(p, q)
-th entry defines the correlation between regressorlabels[p]
andlabels[q]
.- verbose
[
logical(1)
]
Print information about the simulated regressors?
See also
Other simulation helpers:
Simulator
,
ddirichlet_cpp()
,
dmvnorm_cpp()
,
dtnorm_cpp()
,
dwishart_cpp()
,
simulate_markov_chain()
Examples
labels <- c("P", "C", "N1", "N2", "U")
n <- 100
marginals <- list(
"P" = list(type = "poisson", lambda = 2),
"C" = list(type = "categorical", p = c(0.3, 0.2, 0.5)),
"N1" = list(type = "normal", mean = -1, sd = 2),
"U" = list(type = "uniform", min = -2, max = -1)
)
correlation <- matrix(
c(1, -0.3, -0.1, 0, 0.5,
-0.3, 1, 0.3, -0.5, -0.7,
-0.1, 0.3, 1, -0.3, -0.3,
0, -0.5, -0.3, 1, 0.1,
0.5, -0.7, -0.3, 0.1, 1),
nrow = 5, ncol = 5
)
data <- correlated_regressors(
labels = labels, n = n, marginals = marginals, correlation = correlation
)
head(data)
#> P C N1 N2 U
#> 1 2 2 2.9490390 -0.8362976 -1.327995
#> 2 3 3 -0.4603099 0.2794340 -1.747991
#> 3 3 1 -1.3821734 -1.0694163 -1.041011
#> 4 3 1 -3.6357204 0.4382326 -1.076402
#> 5 2 3 -4.1142195 1.1053560 -1.847078
#> 6 1 2 -2.0557934 -0.5100406 -1.431888