Learn R Programming

The Simulator

The simulator is an R package that streamlines the process of performing simulations by creating a common infrastructure that can be easily used and reused across projects. The paper The Simulator: An Engine to Streamline Simulations discusses the simulator in greater depth.

Installation

The most up-to-date version of the simulator is on this github page and can be installed using the devtools R package (if not already installed, open R and type install.packages("devtools")). To install simulator, type

devtools::install_github("jacobbien/simulator")

in R. This installs simulator from github.

Vignettes

The Getting Started vignette walks you through setting up your first simulation with the simulator.

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.

Copy Link

Version

Install

install.packages('simulator')

Monthly Downloads

191

Version

0.2.5

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Jacob Bien

Last Published

February 4th, 2023

Functions in simulator (0.2.5)

ModelRef-class

An S4 class representing a reference to an object of class Model.
add_bold

Make a string bold in a certain format
Output-class

An S4 class representing the output of a method run by simulator.
add_oref_to_list

Internal function to add OutputRef to a list of OutputRef objects
catsim

Concatenate and print for the simulator
generate_model

Generate a model.
get_relative_path

Get relative path
create

Create template for a new set of simulations
get_model_indices

Returns indices of a specified subset of sim@model_refs
evaluate_single

Run one or more metrics on outputs.
describe

Describe the contents of a simulator directory
do_in_parallel

Do a function in parallel.
as.data.frame.listofModels

Convert a List of Models to a data.frame
$,Model-method

Get element of Model's params list
get_files_not_in_simulations

Find files in simulator directory not referred to by any simulations
get_contents

Get the contents of a simulator directory
%>%

This is not magrittr's pipe (actually it is)
load,DrawsRef-method

Load a DrawsRef
load,ModelRef-method

Load a ModelRef
load,EvalsRef-method

Load an EvalsRef
get_simulation_with_all_files

Returns a simulation object containing references to all files in directory
load_libraries_on_cluster

Load necessary libraries on a cluster
load_model

Load a model from file.
ggplot_eval

Make a boxplot of a metric for each method using ggplot2
as.data.frame.Model

Convert a Model to a data.frame
evals

Get one or more evals from a simulation
load_draws

Load one or more draws objects from file.
make_my_example_model

Make My Example Model
memory_as_string

Write memory in human readable way
as.data.frame.listofEvals

Convert a list of Evals to a data.frame
draws

Get one or more draws from a simulation
load_evals

Load one or more Evals objects from file.
aggregate_evals

Apply aggregator to a list of Evals objects
as.data.frame.Evals

Convert an Evals to a data.frame
new_metric

Create a Metric object
new_method_extension

Create an object that can be used to make an extended version of a method
evaluate_internal

Evaluate outputs of methods according to provided metrics.
model

Get one or more models from a simulation
evaluate

Evaluate outputs of methods according to provided metrics.
load,list-method

Load a list of reference objects
load,OutputRef-method

Load an OutputRef
model_names

Get model names in a Simulation
plot_evals

Plot one metric versus another for each method
+,ExtendedMethod,MethodExtension-method

Create an ExtendedMethod from an ExtendedMethod and MethodExtension
outputs_or_evals

Internal function used by both outputs and evals
output

Get one or more outputs from a simulation
new_extended_method

Create an ExtendedMethod object
new_method

Create a Method object
load_simulation

Load a simulation object
plot_eval_by

Plot a metric across multiple values of a model parameter
plot_eval

Plot a metric's value for each method
load_outputs

Load one or more output objects from file.
run_method_single

Run a single method on a single index of simulated data.
new_model

Create a Model object
new_simulation

Make a new simulation object
run_method_parallel

Run one or more methods on simulated data.
models_as_data.frame

Convert a list of Model objects into a data.frame
relabel

Give simulation a new label
new_aggregator

Create an Aggregator object
recycle

Recycles elements to create vector of desired length
my_example_method

My Example Method
my_example_loss

My Example Loss
simulate_from_model

Simulate from a model.
save_simulation

Save a simulation object
simulate_from_model_single

Simulate from a model.
simulate_parallel

Simulate from a model in parallel.
+,Method,MethodExtension-method

Create an ExtendedMethod from a Method and MethodExtension
+,list,MethodExtension-method

Create a list of ExtendedMethod from a list of Methods and a MethodExtension
run_extmethod_parallel

Run one or more extended methods on simulated data.
subset_simulation

Create a simulation that is a subset of a preexisting simulation object
run_method

Run one or more methods on simulated data.
tabulate_eval

Make a table of a metric for each pair of models and methods
rename

Give simulation a new name
run_extendedmethod_single

Run a single extended method on a single index of simulated data.
subset_models

Subset Models
subset_evals

Reduce an Evals object to a subset of methods and/or metrics
MethodExtension-class

An S4 class used to create an extended version of a method
Evals-class

An S4 class representing the evaluation of a metric run by simulator.
Aggregator-class

An S4 class for aggregating evaluated metrics
Component-class

An S4 class representing a component of the simulator.
ExtendedMethod-class

An S4 class representing the extension of a method
DrawsRef-class

An S4 class representing a reference to an object of class Draws.
Method-class

An S4 class representing a method to be run by simulator.
EvalsRef-class

An S4 class representing a reference to an object of class Evals
Metric-class

An S4 class representing an evaluation metric to be used by simulator.
Draws-class

An S4 class representing the random draws from a Model object.
Model-class

An S4 class representing the model component of the simulator.
add_eref_to_list

Internal function to add EvalsRef to a list of EvalsRef objects
OutputRef-class

An S4 class representing a reference to an object of class Output.
add_dref_to_list

Internal function to add DrawsRef to a list of DrawsRef objects
add

Add a reference to a simulation
Simulation-class

An S4 class representing a simulation.