rdplot: Flexible RD Plot

Description Usage Arguments Examples

View source: R/discRD-rdplot.r

Description

Flexible RD Plot

Usage

 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
rdplot(object, ...)

## S3 method for class 'list_global_lm'
rdplot(
  object,
  usemod,
  treat_label = c("treated", "control"),
  ate_label_size = 5,
  ate_label_digits = 3,
  ate_label_format,
  outcome_label,
  ylim,
  vjust = 0,
  hjust = 0,
  xlab = "Running variable",
  ylab = "Average",
  patchwork = TRUE,
  ncol = NULL,
  nrow = NULL,
  ...
)

## S3 method for class 'list_local_lm'
rdplot(
  object,
  usemod,
  treat_label = c("treated", "control"),
  ate_label_size = 5,
  ate_label_digits = 3,
  ate_label_format,
  outcome_label,
  ylim,
  vjust = 0,
  hjust = 0,
  xlab = "Running variable",
  ylab = "Average",
  patchwork = TRUE,
  ncol = NULL,
  nrow = NULL,
  force = TRUE,
  ...
)

Arguments

object

object

...

arguments of simplegg()

usemod

numeric vector. which models do you want to plot?

treat_label

string vector of treatment and control label

ate_label_size

In-plot text size

ate_label_digits

decimal places of in-plot ATE result.

ate_label_format

string of label format of in-plot ATE result. The format produces labels according to a unique grammar. If you want to embed a numerical value related to the estimation result, you need to enclose it in .

  • {estimate}: embed coefficient value (Local ATE)

  • {std.error}: embed standard error of coefficient

  • {statistic}: embed z-score of coefficient

  • {p.value}: embed p-value of coefficient

  • {star}: show *** if p-value <= 0.01; ** if p-value <= 0.05; * if p-value <= 0.1

outcome_label

Outcome label in plot title

ylim

numeric vector of limits of y-axis

vjust

numeric. Adjust in-plot text vertically

hjust

numeric. Adjust in-plot text horizontally

xlab

label of x-axis

ylab

label of y-axis

patchwork

logical. add a list of plots into one composition by patchwork::wrap_plots

ncol

the dimensions of the grid to create. argument of patchwork::wrap_plots

nrow

the dimensions of the grid to create. argument of patchwork::wrap_plots

force

logical. Whether to ignore error about estimation

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
running <- sample(1:100, size = 1000, replace = TRUE)
cov1 <- rnorm(1000, sd = 2); cov2 <- rnorm(1000, mean = -1)
y0 <- running + cov1 + cov2 + rnorm(1000, sd = 10)
y1 <- 2 + 1.5 * running + cov1 + cov2 + rnorm(1000, sd = 10)
y <- ifelse(running <= 50, y1, y0)
bin <- ifelse(y > mean(y), 1, 0)
w <- sample(c(1, 0.5), size = 1000, replace = TRUE)
raw <- data.frame(y, bin, running, cov1, cov2, w)

set_optDiscRD(
  y + bin ~ running,
  discRD.cutoff = 50,
  discRD.assign = "smaller"
)

est <- global_lm(data = raw, weights = w)

rdplot(
  est,
  usemod = c(1, 2),
  treat_label = c("Treated", "Control"),
  outcome_label = switch(x,
    "1" = "Simulated outcome",
    "2" = "Simulated outcome > 0"
  ),
  ylab = "Weighted Average",
  ate_label_size = 4
)

nonpara <- local_lm(
  submod = 1,
  data = raw,
  kernel = "uniform",
  bw = 5,
  order = 1:3
)

rdplot(
  nonpara,
  usemod = 2,
  outcome_label = switch(x,
    "1" = "Order = 1",
    "2" = "Order = 2",
    "3" = "Order = 3"
  )
)

KatoPachi/discreteRD documentation built on Feb. 24, 2022, 12:32 a.m.