Declare diagnosands
Usage
diagnosand_handler(data, ..., subset = NULL, alpha = 0.05, label)
declare_diagnosands(..., handler = diagnosand_handler, label = NULL)
Arguments
- data
A data.frame.
- ...
A set of new diagnosands.
- subset
A subset of the simulations data frame within which to calculate diagnosands e.g.
subset = p.value < .05
.- alpha
Alpha significance level. Defaults to
.05
.- label
Label for the set of diagnosands.
- handler
a tidy-in, tidy-out function
Details
If term is TRUE, the names of ... will be returned in a term
column, and inquiry
will contain the step label. This can be used as an additional dimension for use in diagnosis.
Diagnosands summarize the simulations generated by diagnose_design
or simulate_design
. Typically, the columns of the resulting simulations data.frame include the following variables: estimate, std.error, p.value, conf.low, conf.high, and inquiry. Many diagnosands will be a function of these variables.
Examples
# Two-arm randomized experiment
design <-
declare_model(
N = 500,
gender = rbinom(N, 1, 0.5),
X = rep(c(0, 1), each = N / 2),
U = rnorm(N, sd = 0.25),
potential_outcomes(Y ~ 0.2 * Z + X + U)
) +
declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
declare_sampling(S = complete_rs(N = N, n = 200)) +
declare_assignment(Z = complete_ra(N = N, m = 100)) +
declare_measurement(Y = reveal_outcomes(Y ~ Z)) +
declare_estimator(Y ~ Z, inquiry = "ATE")
if (FALSE) {
# using built-in defaults:
diagnosis <- diagnose_design(design)
diagnosis
# You can choose your own diagnosands instead of the defaults:
my_diagnosands <-
declare_diagnosands(median_bias = median(estimate - estimand))
## You can set diagnosands within the diagnose_design function
## using the 'diagnosands =' argument
diagnosis <- diagnose_design(design, diagnosands = my_diagnosands)
diagnosis
## You can also set diagnosands with set_diagnosands
design <- set_diagnosands(design, diagnosands = my_diagnosands)
diagnosis <- diagnose_design(design)
diagnosis
# If you do not specify diagnosands in diagnose_design,
# the function default_diagnosands() is used,
# which is reproduced below.
alpha <- 0.05
default_diagnosands <-
declare_diagnosands(
mean_estimand = mean(estimand),
mean_estimate = mean(estimate),
bias = mean(estimate - estimand),
sd_estimate = sqrt(pop.var(estimate)),
rmse = sqrt(mean((estimate - estimand) ^ 2)),
power = mean(p.value <= alpha),
coverage = mean(estimand <= conf.high & estimand >= conf.low)
)
diagnose_design(
design,
diagnosands = default_diagnosands
)
# A longer list of potentially useful diagnosands might include:
extended_diagnosands <-
declare_diagnosands(
mean_estimand = mean(estimand),
mean_estimate = mean(estimate),
bias = mean(estimate - estimand),
sd_estimate = sd(estimate),
rmse = sqrt(mean((estimate - estimand) ^ 2)),
power = mean(p.value <= alpha),
coverage = mean(estimand <= conf.high & estimand >= conf.low),
mean_se = mean(std.error),
type_s_rate = mean((sign(estimate) != sign(estimand))[p.value <= alpha]),
exaggeration_ratio = mean((estimate/estimand)[p.value <= alpha]),
var_estimate = pop.var(estimate),
mean_var_hat = mean(std.error^2),
prop_pos_sig = mean(estimate > 0 & p.value <= alpha),
mean_ci_length = mean(conf.high - conf.low)
)
diagnose_design(
design,
diagnosands = extended_diagnosands
)
}