View source: R/prediction_survival.R
| simulate_prediction | R Documentation |
Draws the continuous predictors independently from normal distributions and
each categorical predictor by sampling its levels with replacement, then
forms the outcome as the intercept plus the continuous linear predictor plus
the level effects plus normal residual noise. With no categorical predictor
the call is simply simulate_regression().
simulate_prediction(
n,
coefficients,
categorical_levels = NULL,
categorical_effects = NULL,
category_probabilities = NULL,
predictor_means = 0,
predictor_sds = 1,
error_sd = 1,
outcome = "outcome",
seed = NULL,
batch = NULL
)
n |
Sample size. A single whole number of at least 2. |
coefficients |
Named numeric vector of continuous-predictor
coefficients, with an optional |
categorical_levels |
Named list of levels for categorical predictors,
or a tidy data frame with columns |
categorical_effects |
Named list of level effects matching
|
category_probabilities |
Optional named list of sampling probabilities,
one non-negative value per level summing to one within each predictor.
Defaults to |
predictor_means, predictor_sds |
Mean and standard deviation of each
normally distributed continuous predictor, a scalar recycled across them
(the defaults, |
error_sd |
Residual standard deviation. A single positive number,
defaulting to |
outcome |
Outcome-column name. A single non-empty string, defaulting to
|
seed |
Optional random seed. A single number, or |
batch |
Optional single positive whole number. When given, the
simulator runs |
When categorical_levels is NULL, whatever simulate_regression()
returns. Otherwise a simulab_sim base data.frame with one row per unit
and columns id, one column per continuous coefficient name, one character
column per categorical predictor, and the outcome named by outcome.
Components: coefficients (one row per fixed term, columns term and
coefficient, always including (Intercept)), categorical_effects (one
row per predictor level, columns variable, level, effect and
probability), and effects (one row, columns signal_variance,
residual_variance and r_squared). signal_variance is the realized
variance of the simulated linear predictor, so r_squared is the realized
proportion of outcome variance it explains, not a population value.
result <- simulate_prediction(
n = 200,
coefficients = c("(Intercept)" = 0.5, x1 = 1, x2 = -1),
seed = 1
)
head(result)
as.data.frame(result, what = "coefficients")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.