DeclareDesign (version 0.16.0)

diagnosand_handler: Declare diagnosands

Description

Declare diagnosands

Usage

diagnosand_handler(data, ..., select, subtract, keep_defaults = TRUE,
  subset = NULL, alpha = 0.05, label)

declare_diagnosands(..., handler = diagnosand_handler, label = NULL)

Arguments

data

A data.frame.

...

A set of new diagnosands.

select

A set of the default diagnosands to report e.g., select = c(bias, rmse).

subtract

A set of the default diagnosands to exclude e.g., subtract = c(bias, rmse). Do not provide values for both select and subtract.

keep_defaults

A flag for whether to report the default diagnosands. Defaults to TRUE.

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

Value

a function that returns a data.frame

Details

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)

Examples

Run this code
# NOT RUN {
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
# }
# 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))

# 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)

# 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))

# or to report only \code{median_bias}

my_diagnosands <-
   declare_diagnosands(median_bias = median(estimate - estimand),
                       keep_defaults = FALSE)

# 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)
)

# }

Run the code above in your browser using DataCamp Workspace