sim_comp_pop {saeSim} | R Documentation |
Calculation component
Description
One of the components which can be added to a sim_setup
. These functions can be used for adding new variables to the data.
Usage
sim_comp_pop(simSetup, fun = comp_var(), by = "")
sim_comp_sample(simSetup, fun = comp_var(), by = "")
sim_comp_agg(simSetup, fun = comp_var(), by = "")
Arguments
simSetup |
a |
fun |
a function, see details. |
by |
names of variables as character; identifying groups for which fun is applied. |
Details
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.
See Also
comp_var
, sim_gen
, sim_agg
, sim_sample
, sim_comp_N
, sim_comp_n
, sim_comp_popMean
, sim_comp_popVar
Examples
# 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)
[Package saeSim version 0.11.0 Index]