| rblimp_sim | R Documentation |
Generate simulated datasets using Blimp's SIMULATE command. Supports both single-level and multilevel data generation.
rblimp_sim(
model,
n,
seed,
define = NULL,
variables = NULL,
tmpfolder,
nopowershell = FALSE
)
model |
Character string or vector specifying data generation equations.
Can be specified as a vector: |
n |
Sample size. For single-level: integer (e.g., |
seed |
Random seed for reproducibility. |
define |
Character vector or string of parameter definitions (optional).
Can be |
variables |
Formula or character string specifying which variables to save (optional). If not specified, all variables from the model are saved. |
tmpfolder |
Character string. Temporary folder path. If not specified, creates one with |
nopowershell |
Windows only. Uses cmd.exe instead of powershell. |
A data.frame with simulated data. The returned object has two attributes:
The Blimp syntax used for simulation (blimp_syntax object)
The raw Blimp output (blimp_out object)
Access these with attr(result, "syntax") and attr(result, "output").
SIMULATE() for creating a simulation specification to use with rblimp()
# Simple regression: y = 10 + 0.5*x + error
dat <- rblimp_sim(
model = c(
"x = normal(0, 1)",
"y = normal(10 + x*0.5, 1)"
),
n = 1000,
seed = 10972
)
# Same thing with full quoted syntax
dat <- rblimp_sim(
model = "x = normal(0, 1);
y = normal(10 + x*0.5, 1);",
n = 1000,
seed = 10972
)
# With parameter definitions
dat <- rblimp_sim(
model = c(
"x = normal(0, 1)",
"y = normal(b0 + b1*x, s2e)"
),
n = 1000,
define = c("b0 = 10", "b1 = 0.5", "s2e = 1"),
seed = 10972
)
# Multilevel model
dat <- rblimp_sim(
model = list(
schools = c(
"z = normal(0, 1)",
"u0 = normal(10 + z*-0.5, 1.0)"
),
students = c(
"x = normal(0, 1)",
"y = normal(u0 + x*0.5, 1)"
)
),
n = list(students = 1000, schools = 100),
seed = 198723
)
# Access syntax and output
syntax <- attr(dat, "syntax")
print(syntax)
output <- attr(dat, "output")
print(output)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.