View source: R/correlated_regressors.R
correlated_regressors | R Documentation |
This function simulates regressor values from various marginal distributions with custom correlations.
correlated_regressors(
labels,
n = 100,
marginals = list(),
correlation = diag(length(labels)),
verbose = FALSE
)
labels |
[ |
n |
[ |
marginals |
[ Each list entry must be named according to a regressor label, and the following distributions are currently supported:
|
correlation |
[ |
verbose |
[ |
A data.frame
with n
rows and length(labels)
columns.
This function heavily depends on the {SimMultiCorrData}
package.
Other simulation helpers:
ddirichlet_cpp()
,
dmvnorm_cpp()
,
dtnorm_cpp()
,
dwishart_cpp()
,
simulate_markov_chain()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.