View source: R/statistical_simulation.r
simulate_conditionally.simbase_list | R Documentation |
simbase_list
objectAdd simulated values to a dataset conditionally, based on a simbase_list
object
## S3 method for class 'simbase_list' simulate_conditionally( data, simbase, force_positive = TRUE, ..., error_when_groups_missing = TRUE )
data |
The dataset where simulated values are added to. |
simbase |
Basic data object for the simulation, as calculated by
|
force_positive |
If |
... |
further arguments passed to or from other methods. |
error_when_groups_missing |
Whether to raise an error if for a certain
value combination in the grouping variables no dedicated |
Simulating values based on a simbase_list
object
has some special aspects compared to that of other simbase_*
objects,
(see simulate_conditionally
).
In particular, a simbase_list
object stores simbase
s
for specific value combinations within the grouping variables.
These grouping variables must also be present in data
.
If there is a value combination in these grouping variables for which no
dedicated simbase
object exists, this will lead to NA
values
in the columns to be simulated and either to an error
(if error_when_groups_missing = TRUE
) or to a warning.
Due to the internal call to nest
and subsequent call to
unnest
, the returned dataset will be ordered according to
the grouping variables in the simbase, with any grouping variable
combinations missing in the simbase coming last.
The modified dataset data
with simulated values.
# create a simbase_list object for the values of subsets = c('AT', 'DE') dataset_0 <- simulate_dataset(subsets = c('AT', 'DE')); simbase <- simbase_covar(dplyr::group_by(dataset_0, country), c('f', 'E', 'E_dyn')); # simulate on another dataset dataset <- data.frame(E_dyn = rnorm(n = 100, mean = 12500, sd = 2200), country = 'AT'); dataset_1 <- simulate_conditionally(dataset, simbase); head(dataset_1); # warning if for some value of country we don't have an entry in the simbase dataset$country <- 'CH'; dataset_2 <- simulate_conditionally(dataset, simbase, error_when_groups_missing = FALSE); head(dataset_2);
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.