This brief vignette describes how to get started with the
After installing the package, open R and type.
library(simulator) dir <- "./sims" create(dir)
dir to be the path of a directory (that does not yet exist) where you want your simulation code and files to be stored. In practice,
"./sims" would be a standard choice, where
"." refers to a directory containing files relevant to your current project.
create command generates a skeleton of a simulation.^[This function was inspired by the
create function in
devtools, which creates the skeleton on an R package.] A look at the newly created directory shows that several files have been created.
This is the template of a basic simulation.
model_functions.R, write code that defines the models under which you wish to simulate.
method_functions.R, add code for methods that you wish to compare in your simulation (note that by using
library, you can keep
method_functions.Rshort and to the point, focusing on calling
new_methodrather than putting the actual heart of algorithms in that file).
new_metricto define the ways in which your methods will be evaluated.
main.Rcontains the main entry point to the simulation. Running the code in this file determines which models/methods/metrics are computed, etc.
writeup.Rmdshows how all results can be presented in as a report. This document pulls all code from the
.Rfiles mentioned above, so that as
main.Rand other files develop, the report will remain up to date. To create an
htmlfile report, run the following command in R (which requires installing the package
Or if one is using RStudio, one can simply press the
Knit HTML button.
On a typical project, one starts by defining a model in
model_functions.R, one or two methods in
method_functions.R, and a few metrics in
eval_functions.R, and then one runs the code in
main.R. After looking at some of the results, one might add an additional model or method or metric. One then returns to
main.R, adds some additional lines specifying that the additional components should be run as well and looks at some more results.
The simplest way to look at results is by using the plot functions
plot_evals_by. In situations where you wish to investigate results more deeply than just looking at aggregated plots, one can use the functions
evals to get at all objects generated through the course of the simulation.
The best way to get a sense of how to use the simulator is to look at examples. There are several vignettes that demonstrate how the simulator can be used to conduct simulations for some of the most famous statistical methods.
1) Lasso vignette: Explains basics, including the magrittr pipe and making plots and tables. Also demonstrates some more advanced features such as writing method extensions (such as refitting the result of the lasso or performing cross-validation). 2) James-Stein vignette: Shows how to step into specific parts of the simulation for troubleshooting your code. 3) Elastic net vignette: Shows how we can work with a sequence of methods that are identical except for a parameter that varies 4) Benjamini-Hochberg vignette: Shows how we can load a preexisting simulation and add more random draws without having to rerun anything. It also shows how one can have multiple simulation objects that point to overlapping sets of results. 5) Link to working with data vignette
# delete all files created in running this vignette unlink(dir, recursive = TRUE)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.