vary_across | R Documentation |
Experiment
.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.
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)
.experiment , experiment |
An |
.dgp , dgp |
Name of |
.method , method |
Name of |
... |
Any number of named arguments where names match an argument in the
user-specified |
param_names |
A character vector of parameter names to remove. If not
provided, the entire set of |
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.
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()
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.