declare_diagnosands: Declare diagnosands

Description Usage Arguments Details Value Examples

Description

Declare diagnosands

Usage

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)

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

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)

Value

a function that returns a data.frame

Examples

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

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

graemeblair/DeclareDesign documentation built on Aug. 26, 2018, 7:59 a.m.