Description Usage Arguments Details Value Examples
Declare diagnosands
1 2 3 4 | diagnosand_handler(data, ..., select, subtract, keep_defaults = TRUE,
subset = NULL, alpha = 0.05, label)
declare_diagnosands(..., handler = diagnosand_handler, label = NULL)
|
data |
A data.frame. |
... |
A set of new diagnosands. |
select |
A set of the default diagnosands to report e.g., |
subtract |
A set of the default diagnosands to exclude e.g., |
keep_defaults |
A flag for whether to report the default diagnosands. Defaults to |
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 estimand_label
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 estimand. Many diagnosands will be a function of these variables.
By default (keep_defaults = TRUE
), a set of common diagnosands are reported:
bias = mean(estimate - estimand)
rmse = sqrt(mean((estimate - estimand)^2))
power = mean(p.value < .05)
coverage = mean(estimand <= conf.high & estimand >= conf.low)
mean_estimate = mean(estimate)
sd_estimate = sd(estimate)
type_s_rate = mean((sign(estimate) != sign(estimand))[p.value < alpha])
mean_estimand = mean(estimand)
a function that returns a data.frame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | my_population <- declare_population(N = 500, noise = rnorm(N))
my_potential_outcomes <- declare_potential_outcomes(
Y_Z_0 = noise, Y_Z_1 = noise +
rnorm(N, mean = 2, sd = 2))
my_assignment <- declare_assignment()
my_estimand <- declare_estimand(ATE = mean(Y_Z_1 - Y_Z_0))
my_estimator <- declare_estimator(Y ~ Z, estimand = my_estimand)
my_reveal <- declare_reveal()
design <- my_population + my_potential_outcomes + my_estimand +
my_assignment + my_reveal + my_estimator
## Not run:
# using built-in defaults:
diagnosis <- diagnose_design(design)
diagnosis
## End(Not run)
# You can select a set of those diagnosands via the \code{select} argument e.g.,
my_diagnosands <- declare_diagnosands(select = c(bias, rmse))
## 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)
# Alternatively, you can report all of the default diagnosands and subtract a subset of them e.g.,
my_diagnosands <- declare_diagnosands(subtract = type_s_rate)
## 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)
# You can add your own diagnosands in addition to or instead of the defaults e.g.,
my_diagnosands <-
declare_diagnosands(median_bias = median(estimate - estimand))
## 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)
# or to report only \code{median_bias}
my_diagnosands <-
declare_diagnosands(median_bias = median(estimate - estimand),
keep_defaults = FALSE)
## 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)
# Below is the code that makes the default diagnosands.
# You can use these as a model when writing your own diagnosands.
default_diagnosands <- declare_diagnosands(
bias = mean(estimate - estimand),
rmse = sqrt(mean((estimate - estimand) ^ 2)),
power = mean(p.value < alpha),
coverage = mean(estimand <= conf.high & estimand >= conf.low),
mean_estimate = mean(estimate),
sd_estimate = sd(estimate),
mean_se = mean(std.error),
type_s_rate = mean((sign(estimate) != sign(estimand))[p.value < alpha]),
mean_estimand = mean(estimand)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.