View source: R/formulas_splines.R
| simulate_spline | R Documentation |
Add a spline-generated variable
simulate_spline(
data,
predictor,
variable,
coefficients,
knots = c(0.25, 0.5, 0.75),
degree = 3L,
output_range = NULL,
noise_variance = 0,
seed = NULL,
batch = NULL
)
data |
Base |
predictor |
Predictor variable. |
variable |
Name of the generated variable. |
coefficients |
Spline coefficients. |
knots |
Quantile probabilities for interior knots. |
degree |
Polynomial degree. |
output_range |
Optional numeric pair. The spline value |
noise_variance |
Non-negative Gaussian noise variance; the noise added
to each value has standard deviation |
seed |
Optional random seed. |
batch |
Optional single positive whole number. When given, the
simulator runs |
A simulab_sim base data.frame holding data with the spline
variable added. as.data.frame(x, what = "basis") gives the tidy basis
table, one row per observation/basis combination, and
as.data.frame(x, what = "parameters") gives one row per basis
coefficient.
data <- data.frame(id = 1:100, x = stats::runif(100))
result <- simulate_spline(
data, predictor = "x", variable = "y",
coefficients = c(0.1, 0.2, 0.5, 0.4, 0.7, 0.6, 0.9),
knots = c(0.25, 0.5, 0.75), seed = 1
)
head(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.