Description Usage Arguments Details See Also Examples
One of the components which can be added to a sim_setup
. These functions can be used for adding new variables to the data.
1 2 3 4 5 | sim_comp_pop(simSetup, fun = comp_var(), by = "")
sim_comp_sample(simSetup, fun = comp_var(), by = "")
sim_comp_agg(simSetup, fun = comp_var(), by = "")
|
simSetup |
a |
fun |
a function, see details. |
by |
names of variables as character; identifying groups for which fun is applied. |
Potentially you can define a function for computation yourself. Take care that it only has one argument, named dat
, and returns a data.frame
. Use comp_var
for simple data manipulation. Functions added with sim_comp_pop
are applied before sampling; sim_comp_sample
after sampling. Functions added with sim_comp_agg
after aggregation.
comp_var
, sim_gen
, sim_agg
, sim_sample
, sim_comp_N
, sim_comp_n
, sim_comp_popMean
, sim_comp_popVar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Standard behavior
sim_base() %>% sim_gen_x() %>% sim_comp_N()
# Custom data modifications
## Add predicted values of a linear model
library(saeSim)
comp_lm <- function(dat) {
dat$linearPredictor <- predict(lm(y ~ x, data = dat))
dat
}
sim_base_lm() %>% sim_comp_pop(comp_lm)
# or if applied after sampling
sim_base_lm() %>% sim_sample() %>% sim_comp_pop(comp_lm)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.