| simulate_copula | R Documentation |
Simulate correlated general-distribution variables with a Gaussian copula
simulate_copula(
n,
specification,
rho = 0,
tau = NULL,
structure = c("independent", "exchangeable", "ar1", "custom"),
correlation = NULL,
id = "id",
seed = NULL,
envir = parent.frame(),
batch = NULL
)
n |
Number of observations. |
specification |
Variable definitions from |
rho |
Optional latent Pearson correlation, zero by default. |
tau |
Optional Kendall correlation, overriding |
structure |
Correlation structure: one of |
correlation |
Custom latent correlation matrix or tidy table. |
id |
Identifier name. |
seed |
Optional random seed. |
envir |
Formula evaluation environment. |
batch |
Optional single positive whole number. When given, the
simulator runs |
A simulab_sim base data.frame with one row per observation and
columns id (renamed by id) and one column per variable. Two tidy
tables come from as.data.frame(): what = "definitions" restates the
specification, and what = "latent_correlation" has one row per
correlation-matrix cell with columns row, column and correlation.
That matrix is the correlation of the latent Gaussian variables, not of
the generated margins, which are pulled apart by their own quantile
transforms.
simulab_no_quantile when a distribution call names a marginal with no
quantile function, such as rice() or mixture().
# Distribution calls. Each marginal keeps its own distribution while the
# variables are correlated through a Gaussian copula.
result <- simulate_copula(
n = 200,
specification = define_variables(
score = normal(mean = 10, sd = 2),
visits = poisson(lambda = 4),
rate = beta(shape1 = 2, shape2 = 5)
),
rho = 0.5, seed = 1
)
head(result)
specification <- define_variables(
define_variable("normal_var", formula = "0", variance = "1", distribution = "normal"),
define_variable("count_var", formula = "3", variance = "0", distribution = "poisson")
)
result <- simulate_copula(n = 200, specification = specification, rho = 0.5, seed = 1)
head(result)
components(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.