| simulate_regression | R Documentation |
Simulate a linear regression design
simulate_regression(
n = 100L,
coefficients = NULL,
predictor_means = 0,
predictor_sds = 1,
correlation = NULL,
error_sd = 1,
outcome = "outcome",
seed = NULL,
batch = NULL,
n_predictors = 2L
)
n |
Sample size, defaulting to |
coefficients |
Named coefficients including optional |
predictor_means, predictor_sds |
Predictor means and standard deviations. |
correlation |
Optional predictor correlation matrix or tidy table. |
error_sd |
Positive residual standard deviation. |
outcome |
Name of the outcome variable. |
seed |
Optional random seed. |
batch |
Optional single positive whole number. When given, the
simulator runs |
n_predictors |
Number of predictors when |
A simulab_sim base data.frame with one row per observation and
columns id, one column per predictor, and outcome (renamed by
outcome). Three tidy tables come from as.data.frame():
what = "coefficients" has one row per term with columns term and
coefficient, the intercept first; what = "effects" has a single row
with columns signal_variance (the quadratic form of the slopes in the
predictor covariance matrix), residual_variance (error_sd^2) and the
population r_squared
signal_variance / (signal_variance + residual_variance);
what = "predictor_correlation" has one row per correlation-matrix cell
with columns row, column and correlation.
# `coefficients` must be named; "(Intercept)" is optional.
result <- simulate_regression(
n = 200,
coefficients = c("(Intercept)" = 1, x1 = 0.5, x2 = -0.3),
seed = 1
)
head(result)
as.data.frame(result, what = "coefficients")
as.data.frame(result, what = "effects")
# With no coefficients, they are drawn and reported as the truth.
drawn <- simulate_regression(seed = 1)
as.data.frame(drawn, what = "coefficients")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.