Title: | Simulate Data from R or 'JAGS' Code |
---|---|
Description: | Generates data from R or 'JAGS' code for use in simulation studies. The data are returned as an 'nlist::nlists' object and/or saved to file as individual '.rds' files. Parallelization is implemented using the 'future' package. Progress is reported using the 'progressr' package. |
Authors: | Audrey Beliveau [aut, cre], Joe Thorley [aut] |
Maintainer: | Audrey Beliveau <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.4 |
Built: | 2024-12-01 07:42:37 UTC |
Source: | https://github.com/poissonconsulting/sims |
Add Simulated Datasets
sims_add(path = ".", nsims = 1)
sims_add(path = ".", nsims = 1)
path |
A string specifying the path to the directory to add the data sets to. |
nsims |
A count of the number of additional datasets to generate. |
A character vector of the names of the files created.
Checks the simulated data argument values in the '.sims.rds' file.
sims_check(path = ".")
sims_check(path = ".")
path |
A string of the path to the directory with the simulated data. |
The checks include whether number and names of the data files in the directory are consistent with the number of simulations.
An informative error or invisible list of the argument values.
set.seed(10) sims_simulate("a <- runif(1)", save = TRUE, path = tempdir(), exists = NA, ask = FALSE ) (sims_check(tempdir()))
set.seed(10) sims_simulate("a <- runif(1)", save = TRUE, path = tempdir(), exists = NA, ask = FALSE ) (sims_check(tempdir()))
Copy Simulated Datasets
sims_copy( path_from = ".", path_to = paste0(path_from, "_copy"), exists = FALSE, ask = getOption("sims.ask", TRUE), silent = FALSE )
sims_copy( path_from = ".", path_to = paste0(path_from, "_copy"), exists = FALSE, ask = getOption("sims.ask", TRUE), silent = FALSE )
path_from |
A string of the path to the directory containing the simulated datasets. |
path_to |
A string of the path to the directory to copy the simulated dataset to. |
exists |
A flag specifying whether |
ask |
A flag specifying whether to ask before deleting files. |
silent |
A flag specifying whether to suppress warnings. |
A character vector of the names of the files copied.
Gets the simulated datasets as an nlist::nlists_object()
.
There is no guarantee that all the datasets will fit in memory.
sims_data(path = ".")
sims_data(path = ".")
path |
A string of the path to the directory with the simulated data. |
An nlist::nlists_object()
of the simulated datasets.
set.seed(10) sims_simulate("a <- runif(1)", nsims = 10L, path = tempdir(), exists = NA, ask = FALSE ) library(nlist) sims_data(tempdir())
set.seed(10) sims_simulate("a <- runif(1)", nsims = 10L, path = tempdir(), exists = NA, ask = FALSE ) library(nlist) sims_data(tempdir())
Gets the names of the simulated data files.
sims_data_files(path = ".")
sims_data_files(path = ".")
path |
A string of the path to the directory with the simulated data. |
A character vector of the names of the simulated data files.
set.seed(10) sims_simulate("a <- runif(1)", nsims = 10L, path = tempdir(), exists = NA, ask = FALSE ) sims_data_files(tempdir())
set.seed(10) sims_simulate("a <- runif(1)", nsims = 10L, path = tempdir(), exists = NA, ask = FALSE ) sims_data_files(tempdir())
Gets the simulated data argument values in the '.sims.rds' file.
sims_info(path = ".")
sims_info(path = ".")
path |
A string of the path to the directory with the simulated data. |
A named list of the values in file.path(path, '.sims.rds')
.
set.seed(10) sims_simulate("a <- runif(1)", path = tempdir(), exists = NA, ask = FALSE) sims_info(tempdir())
set.seed(10) sims_simulate("a <- runif(1)", path = tempdir(), exists = NA, ask = FALSE) sims_info(tempdir())
Gets the names of the R random variate generating functions
listed in Distributions()
.
sims_rdists()
sims_rdists()
A character vector.
sims_rdists()
sims_rdists()
Simulates datasets using JAGS or R code. By default
returns the datasets as an nlist::nlists_object()
.
If path
is provided then the datasets are written to the directory
as individual .rds
files.
sims_simulate( code, constants = nlist::nlist(), parameters = nlist::nlist(), monitor = ".*", stochastic = NA, latent = NA, nsims = 1, save = FALSE, path = ".", exists = FALSE, rdists = sims_rdists(), ask = getOption("sims.ask", TRUE), silent = FALSE )
sims_simulate( code, constants = nlist::nlist(), parameters = nlist::nlist(), monitor = ".*", stochastic = NA, latent = NA, nsims = 1, save = FALSE, path = ".", exists = FALSE, rdists = sims_rdists(), ask = getOption("sims.ask", TRUE), silent = FALSE )
code |
A string of the JAGS or R code to generate the data. The JAGS code must not be in a data or model block. |
constants |
An nlist object (or list that can be coerced to nlist) specifying the values of nodes in code. The values are included in the output dataset. |
parameters |
An nlist object (or list that can be coerced to nlist) specifying the values of nodes in code. The values are not included in the output dataset. |
monitor |
A character vector (or regular expression if a string) specifying the names of the nodes in code to include in the dataset. By default all nodes are included. |
stochastic |
A logical scalar specifying whether to monitor deterministic and stochastic (NA), only deterministic (FALSE) or only stochastic nodes (TRUE). |
latent |
A logical scalar specifying whether to monitor observed and latent (NA), only latent (TRUE) or only observed nodes (FALSE). |
nsims |
A whole number between 1 and 1,000,000 specifying the number of data sets to simulate. By default 1 data set is simulated. |
save |
A flag specifying whether to return the data sets as
an |
path |
A string specifying the path to the directory to save the data sets in. |
exists |
A flag specifying whether the |
rdists |
A character vector specifying the R functions to recognize as stochastic. |
ask |
A flag specifying whether to ask before deleting sims compatible files. |
silent |
A flag specifying whether to suppress warnings. |
JAGS code is identified by the presence of '~' indicating a
stochastic variable node.
Otherwise code is assumed to be R code and stochastic variable nodes
are those where assignment is immediately succeeded
by a call to one of the functions named in rdists
.
Both constants and parameters must be [nlist::nlist_object]s
(or lists that can be coerced to such) .
The only difference between constants and parameters is that the values in
constants are appended to the output data while the values in parameters
are not.
Neither constants or parameters can include missing values nor can they
have elements with the same name.
Elements which are not in code are dropped with a warning
(unless silent = TRUE
in which case the warning is suppressed).
Each set of simulated data set is written as a separate .rds file.
The files are labelled data0000001.rds
, data0000002.rds
,
data0000003.rds
etc.
The argument values are saved in the hidden file .sims.rds
.
sims compatible files are those matching the regular expression
^((data\\\\d\{7,7\})|([.]sims))[.]rds$
.
Parallelization is implemented using the future package.
By default an nlist::nlists_object()
of the simulated data.
Otherwise if path
is defined saves the datasets as individual .rds
files and returns TRUE.
set.seed(101) sims_simulate("a <- runif(1)", path = tempdir(), exists = NA, ask = FALSE)
set.seed(101) sims_simulate("a <- runif(1)", path = tempdir(), exists = NA, ask = FALSE)