vary_across: Varying across parameters in an 'Experiment'.

vary_acrossR Documentation

Varying across parameters in an Experiment.

Description

Helper functions for adding, updating, removing, or getting a vary_across component in an Experiment. When a vary_across component is added and the Experiment is run, the Experiment is systematically varied across values of the specified parameter in the DGP or Method while all other parameters are held constant.

Usage

add_vary_across(.experiment, .dgp, .method, ...)

update_vary_across(.experiment, .dgp, .method, ...)

remove_vary_across(experiment, dgp, method, param_names = NULL)

get_vary_across(experiment)

Arguments

.experiment, experiment

An Experiment object.

.dgp, dgp

Name of DGP to vary in the Experiment. Can also be a DGP object that matches one in the Experiment or even a vector/list of DGP names/objects, assuming they can all take in the specified param_names.

.method, method

Name of Method to vary in the Experiment. Can also be a Method object that matches one in the Experiment or even a vector/list of Method names/objects, assuming they all support the target arguments provided via ....

...

Any number of named arguments where names match an argument in the user-specified DGP or Method function and values are vectors (for scalar parameters) or lists (for arbitrary parameters).

param_names

A character vector of parameter names to remove. If not provided, the entire set of vary_across parameters will be removed for the specified DGP/Method.

Details

One of the .dgp or .method arguments (but not both) must be provided when using add_vary_across() and update_vary_across. For remove_vary_across(), if both the dgp and method arguments are not provided, then all vary_across parameters from the experiment are removed.

Value

In the case of get_vary_across, a nested list with entries "dgp" and "method" that contains the parameters to vary across for each DGP and Method in the Experiment. Otherwise, the original Experiment object passed to ⁠*_vary_across()⁠.

Examples

# generate data from normal distribution with n samples
normal_dgp <- create_dgp(
  .dgp_fun = function(n) rnorm(n), .name = "Normal DGP", n = 100
)
# generate data from binomial distribution with n samples
bernoulli_dgp <- create_dgp(
  .dgp_fun = function(n) rbinom(n, 1, 0.5), .name = "Bernoulli DGP", n = 100
)

# compute weighted mean of data
mean_method <- create_method(
  .method_fun = function(x, ...) list(mean = mean(x, ...)),
  .name = "Mean"
)

# initialize experiment with toy DGPs and Methods
experiment <- create_experiment(name = "Experiment Name") %>%
  add_dgp(normal_dgp) %>%
  add_dgp(bernoulli_dgp) %>%
  add_method(mean_method)

# vary across n for normal DGP
experiment <- experiment %>%
  add_vary_across(.dgp = "Normal DGP", n = c(100, 200, 300))
get_vary_across(experiment)
print(experiment)

# remove vary across for normal DGP
experiment <- experiment %>%
  remove_vary_across(dgp = "Normal DGP")
get_vary_across(experiment)
print(experiment)

# can add vary across for multiple DGPs at once
experiment <- experiment %>%
  add_vary_across(.dgp = c("Normal DGP", "Bernoulli DGP"), n = c(100, 200, 300))
get_vary_across(experiment)
print(experiment)

# can update vary across for DGPs
experiment <- experiment %>%
  update_vary_across(.dgp = "Normal DGP", n = c(100, 300)) %>%
  update_vary_across(.dgp = "Bernoulli DGP", n = c(100, 200))
get_vary_across(experiment)
print(experiment)

# can also add/update/remove vary across for methods
experiment <- experiment %>%
  add_vary_across(.method = "Mean", trim = list(0, 0.1, 0.2))
print(experiment)
experiment <- experiment %>%
  update_vary_across(
    .method = "Mean", trim = list(0, 0.1, 0.2, 0.3)
  )
print(experiment)
experiment <- experiment %>%
  remove_vary_across(method = "Mean")
print(experiment)

# can remove all vary across parameters
experiment <- experiment %>%
  remove_vary_across()
get_vary_across(experiment)
print(experiment)


Yu-Group/simChef documentation built on March 25, 2024, 3:22 a.m.