sample_x | R Documentation |
Sampling is split into two steps, for predictors and for response variables,
to allow users to choose which to simulate. sample_x()
will only sample
predictor variables, and sample_y()
will augment a data frame of predictors
with columns for response variables, overwriting any already present. Hence
one can use sample_y()
as part of a simulation with fixed predictors, for
instance.
sample_x(population, n)
sample_y(xs)
population |
Population, as defined by |
n |
Number of observations to draw from the population. |
xs |
Data frame of predictor values drawn from the population, as
obtained from |
Data frame (tibble) of n
rows, with columns matching the variables
specified in the population.
# A population with a simple linear relationship
pop <- population(
x1 = predictor(rnorm, mean = 4, sd = 10),
x2 = predictor(runif, min = 0, max = 10),
y = response(0.7 + 2.2 * x1 - 0.2 * x2, error_scale = 1.0)
)
xs <- pop |>
sample_x(5)
xs
xs |>
sample_y()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.