diagnosand_handler {DeclareDesign} | R Documentation |
Declare diagnosands
diagnosand_handler(data, ..., subset = NULL, alpha = 0.05, label)
declare_diagnosands(..., handler = diagnosand_handler, label = NULL)
data |
A data.frame. |
... |
A set of new diagnosands. |
subset |
A subset of the simulations data frame within which to calculate diagnosands e.g. |
alpha |
Alpha significance level. Defaults to |
label |
Label for the set of diagnosands. |
handler |
a tidy-in, tidy-out function |
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.
a function that returns a data.frame
design <-
declare_model(
N = 500,
U = rnorm(N),
Y_Z_0 = U,
Y_Z_1 = U + rnorm(N, mean = 2, sd = 2)
) +
declare_assignment(Z = complete_ra(N)) +
declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
declare_estimator(Y ~ Z, inquiry = my_inquiry) +
declare_measurement(Y = reveal_outcomes(Y ~ Z))
## Not run:
# using built-in defaults:
diagnosis <- diagnose_design(design)
diagnosis
## End(Not run)
# You can choose your own diagnosands instead of the defaults e.g.,
my_diagnosands <-
declare_diagnosands(median_bias = median(estimate - inquiry))
## Not run:
diagnosis <- diagnose_design(design, diagnosands = my_diagnosands)
diagnosis
## End(Not run)
## Not run:
design <- set_diagnosands(design, diagnosands = my_diagnosands)
diagnosis <- diagnose_design(design)
diagnosis
## End(Not run)
# 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)
)
# 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 = estimate > 0 & p.value <= alpha,
mean_ci_length = mean(conf.high - conf.low)
)