local_random_test: Perform Local Randomization Approach

Description Usage Arguments Examples

View source: R/discRD-local-random.r

Description

An analysis of the difference between the means of the two groups is performed under the assumption that the treatment assignments are random near the cutoff (local random). Statistical inference has a permutation test for small sample sizes in addition to the standard t-test.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
local_random_test(
  basemod,
  data,
  weights,
  submod,
  subset,
  bw,
  global = FALSE,
  bootse,
  bootp,
  cutoff,
  assign
)

Arguments

basemod

baseline formula. outcome ~ running variable.

data

data.frame which you want to use.

weights

weight variable.

submod

numeric vector. Which baseline model you want to use.

subset

subset condition.

bw

numeric vector of bandwidth. If specified, use data whose running variables are within this range will be used. If missing, use data from treatment and control groups where the running variable is closest to the cutoff

global

logical (default is FALSE). Whether to use all observations.

bootse

numeric. Generate N averages of bootstrap samples and use the standard deviation as the standard error of the average. If missing, standard error of mean is calculated by sqrt(v / e) where v is unbiased variance of outcome, and e is effective sample size: e = sum(w) ^ 2 / sum(w ^ 2). If w is missing, we set w = 1, and obtain e = 1 / n. standard error of mean difference is obtained by sqrt((v1 / e1) + (v0 / e0))

bootp

numeric. Perform a permutation test with N re-randomization. The p-value is obtained at a rate where the absolute value of the mean difference due to re-randomization is greater than the absolute value of the observed mean difference. If missing, standard t-test is performed.

cutoff

numeric of cutoff points If missing, try to find getOption("discRD.cutoff").

assign

assignment rule of treatment. If "greater", treated whose running variable is greater than or equal to cutoff. If "smaller", treated whose running variable is less than or equal to cutoff. If missing, try to find getOption("discRD.assign").

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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"
)

est1 <- local_random_test(data = raw, weights = w, global = TRUE)
str(est1)
est2 <- local_random_test(data = raw, bootp = 1000, submod = 1)
str(est2)

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