Type: Package
Title: Randomization Tests
Description: A collection of randomization tests, data sets and examples. The current version focuses on five testing problems and their implementation in empirical work. First, it facilitates the empirical researcher to test for particular hypotheses, such as comparisons of means, medians, and variances from k populations using robust permutation tests, which asymptotic validity holds under very weak assumptions, while retaining the exact rejection probability in finite samples when the underlying distributions are identical. Second, the description and implementation of a permutation test for testing the continuity assumption of the baseline covariates in the sharp regression discontinuity design (RDD) as in Canay and Kamat (2018) https://goo.gl/UZFqt7. More specifically, it allows the user to select a set of covariates and test the aforementioned hypothesis using a permutation test based on the Cramer-von Misses test statistic. Graphical inspection of the empirical CDF and histograms for the variables of interest is also supported in the package. Third, it provides the practitioner with an effortless implementation of a permutation test based on the martingale decomposition of the empirical process for testing for heterogeneous treatment effects in the presence of an estimated nuisance parameter as in Chung and Olivares (2021) <doi:10.1016/j.jeconom.2020.09.015>. Fourth, this version considers the two-sample goodness-of-fit testing problem under covariate adaptive randomization and implements a permutation test based on a prepivoted Kolmogorov-Smirnov test statistic. Lastly, it implements an asymptotically valid permutation test based on the quantile process for the hypothesis of constant quantile treatment effects in the presence of an estimated nuisance parameter.
Version: 0.1.10
BugReports: https://github.com/ignaciomsarmiento/RATest/issues
Maintainer: Mauricio Olivares <mau.olivarego@gmail.com>
Depends: R (≥ 3.00), ggplot2(≥ 2.2.1), gridExtra
Imports: stats, quantreg, compiler
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
Author: Mauricio Olivares [aut, cre], Ignacio Sarmiento-Barbieri [aut]
Collate: 'CvM.stat.R' 'H.cdf.R' 'randomization.test.R' 'group.action.R' 'PT.Khmaladze.fit.R' 'PT.Khmaladze.MultTest.R' 'PTQTE.Khmaladze.fit.R' 'RDperm.R' 'RPT.R' 'lee2008.R' 'plot.RDperm.R' 'prepivot.ks.permtest.R' 'summary.PT.Khmaladze.MultTest.R' 'summary.PT.Khmaladze.fit.R' 'summary.PTQTE.Khmaladze.fit.R' 'summary.RDperm.R' 'summary.RPT.R' 'summary.prepivot.ks.permtest.R'
Suggests: knitr, rmarkdown
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2022-09-28 09:21:54 UTC; hoeffding
Repository: CRAN
Date/Publication: 2022-09-29 04:30:02 UTC

Cramer - von Mises statistics

Description

Calculates the Cramer-von Mises test statistic

T(S_n)=\frac{1}{2q}\sum_{i=1}^{2q}\left(H^-_n(S_{n,i})-H^+_n(S_{n,i})\right)^2

where H^-_n(\cdot) and H^+_n(\cdot) are the empirical CDFs of the the sample of baseline covariates close to the cutoff from the left and right, respectively. See equation (12) in Canay and Kamat (2017).

Usage

CvM.stat(Sn)

Arguments

Sn

Numeric. The pooled sample of induced order statistics. The first column of S can be viewed as an independent sample of W conditional on Z being close to zero from the left. Similarly, the second column of S can be viewed as an independent sample of W conditional on Z being close to the cutoff from the right. See section 3 in Canay and Kamat (2017).

Value

Returns the numeric value of the Cramer - von Mises test statistic.

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri

References

Canay, I and Kamat V, (2018) Approximate Permutation Tests and Induced Order Statistics in the Regression Discontinuity Design. The Review of Economic Studies, 85(3): 1577-1608


Regression Discontinuity Design Permutation test

Description

Calculates the empirical CDF of the sample of W conditional on Z being close to the cutoff from either the left or right. Given the induced order for the baseline covariates

W^{-}_{[q]}, W^{-}_{[q-1]},\dots\le W^{-}_{[1]}

or

W^{+}_{[1]}, W^{+}_{[2]},\dots, W^{+}_{[q]}

, this function will calculate either

H^-_n(t)=\frac{1}{q}\sum_{i=1}^q I\{W^{-}_{[i]}\le t\}

or

H^+_n(t)=\frac{1}{q}\sum_{i=1}^q I\{W^{+}_{[i]}\le t\}

depending on the argument of the function. See section 3 in Canay & Kamat (2017).

Usage

H.cdf(W, t)

Arguments

W

Numeric. The sample of induced order statistics. The input can be either \{W^{-}_{[q]}, W^{-}_{[q-1]},\dots, W^{-}_{[1]}\} or \{W^{+}_{[1]}, W^{+}_{[2]},\dots, W^{+}_{[q]}\}.

t

Numeric. The scalar needed for the calculation of the CDF.

Value

Numeric. For a sample W=(w_1,\dots,w_n), returns the fraction of observations less or equal to t.

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri

References

Canay, I and Kamat V, (2018) Approximate Permutation Tests and Induced Order Statistics in the Regression Discontinuity Design. The Review of Economic Studies, 85(3): 1577-1608


Martingale transformed Permutation Test: Multiple Testing procedures.

Description

This function applies the martingale transformed Permutation test (Chung and Olivares (2020)) to test whether there exists within-group treatment effect heterogeneity. The method jointly tests the null hypotheses that treatment effects are constant within mutually exclusive subgroups while allowing them to be different across subgroups. More formally, assume the mutually exclusive subgroups are formed from observed covariates, and are taken as given. Denote \mathcal{J} the total number of such subgroups. Let F_0^{j}(y) and F_1^{j}(y) be the CDFs of the control and treatment group for subgroup 1\le j\le \mathcal{J}. The null hypothesis of interest is given by the joint hypothesis

\mathbf{H}_{0}: F_1^{j}(y + \delta_{j}) = F_0^{j}(y)

for all mutually exclusive j\in\{1,\dots,\mathcal{J}\}, for some \delta_j. We are treating \mathbf{H}_0 as a multiple testing problem in which every individual hypothesis j\in\{1,\dots,\mathcal{J}\}, given by

H_{0,j}: F_1^{j}(y + \delta_{j}) = F_0^{j}(y)

for some \delta_j specifies whether the treatment effect is heterogeneous for a particular subgroup.

To achieve control of the family-wise error rate, the function considers several multiple testing procedures, such as Bonferroni, maxT and minP (Westfall and Young (1993)), and Holm (1979). For further details, see Chung and Olivares (2020).

Usage

PT.Khmaladze.MultTest(
  data,
  procedure = "maxT",
  alpha = 0.05,
  n.perm = 499,
  B = 499,
  na.action
)

Arguments

data

List. Data are presented in the form of a list, where each sublist contains the treatment and control group observations for a specific subgroup.

procedure

multiple testing procedure. Several options are available, including maxT and minP (Westfall and Young (1993)), Bonferroni adjustment, and Holm (1979) procedure. The default is Bonferroni.

alpha

Significance level.

n.perm

Numeric. Number of permutations needed for the stochastic approximation of the p-values. See Remark 4 in Chung and Olivares (2020). The default is n.perm=499.

B

Numeric. Number of permutations needed for the stochastic approximation in the Westfall-Young procedures. See Remark 11 in Chung and Olivares (2020). The default is B=499.

na.action

a function to filter missing data. This is applied to the model.frame . The default is na.omit, which deletes observations that contain one or more missing values.

Value

An object of class "PT.Khmaladze.MultTest" is a list containing at least the following components:

description

Type of multiple testing adjustment. It can be Westfall-Young's maxT, minP, Holm or Bonferroni.

n.subgroups

Number of subgrups for a specific covariate.

T.obs

Vector. Observed test statistic for each subgroup.

pvalues

Vector. P-value for each individual test.

adj.pvalue

Vector. Adjusted p-values according to the user-chosen multiple testing procedure.

n.perm

Number of permutations.

B

Number of permutations used in the Westfall-Young procedure.

sample.sizes

Subgroup sample sizes.

alpha

Significance level.

Author(s)

Maurcio Olivares

References

Chung, E. and Olivares, M. (2021). Permutation Test for Heterogeneous Treatment Effects with a Nuisance Parameter. Forthcoming in Journal of Econometrics. Holm, S. (1979). A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics, pages 65-70. Westfall, P.H. and Young, S.S. (1993). Resampling-based multiple testing: Examples and methods for p-value adjustment, Volume 279, John & Wiley Sons.

Examples

## Not run: 
subgroup1 <- list()
subgroup1$Y0 <- rnorm(11)
subgrpup1$Y1 <- rnorm(8,1,1) 
subgroup2 <- list()
subgroup2$Y0 <- rnorm(9)
subgroup2$Y1 <- rnorm(7,1,2)
data <- list(subgroup1,subgroup2)
res.minP <- PT.Khmaladze.MultTest(data,"minP",n.perm=100,B=100)
summary(res.minP)
adjusted.p.values <- res.minP$adj.pvalues
adjusted.p.values

## End(Not run)

Permutation Test for Heterogeneous Treatment Effects with a Nuisance Parameter

Description

A permutation test of the two-sample goodness-of-fit hypothesis in the presence of an estimated niusance parameter. The permutation test considered here is based on the Khmaladze transformation of the empirical process (Khmaladze (1981)), and adapted by Chung and Olivares (2020).

Usage

PT.Khmaladze.fit(y1, y0, alpha = 0.05, n.perm = 999)

Arguments

y1

Numeric. A vector containing the response variable of the treatment group.

y0

Numeric. A vector containing the response variable of the control group.

alpha

Numeric. Nominal level for the test. The default is 0.05.

n.perm

Numeric. Number of permutations needed for the stochastic approximation of the p-values. The default is n.perm=999.

Value

An object of class "PT.Khmaladze.fit" containing at least the following components:

n_populations

Number of grups.

N

Sample Size.

T.obs

Observed test statistic.

shift

The estimated nuisance parameter (average treatment effect).

cv

Critical Value. This value is used in the general construction of a randomization test.

pvalue

P-value.

T.perm

Vector. Test statistic recalculated for all permutations used in the stochastic approximation.

n_perm

Number of permutations.

sample_sizes

Groups size.

Author(s)

Maurcio Olivares

References

Khmaladze, E. (1981). Martingale Approach in the Theory of Goodness-of-fit Tests. Theory of Probability and its Application, 26: 240–257. Chung, E. and Olivares, M. (2021). Permutation Test for Heterogeneous Treatment Effects with a Nuisance Parameter. Forthcoming in Journal of Econometrics.

Examples

## Not run: 
Y0 <- rnorm(100, 1, 1)
# Treatment Group with constant shift equals to 1
Y1 <- Y0 + 1
Tx = sample(100) <= 0.5*(100)
# Observed Outcome 
Y = ifelse( Tx, Y1, Y0 )
dta <- data.frame(Y = Y, Z = as.numeric(Tx))
pt.GoF<-PT.Khmaladze.fit(dta$Y[dta$Z==1],dta$Y[dta$Z==0],n.perm = 49)
summary(pt.GoF)

## End(Not run)

Quantile-Based Permutation Test with an Estimated Nuisance Parameter

Description

A permutation test for testing whether the quantile treatment effects are constant across quantiles. The permutation test considered here is based on the Khmaladze transformation of the quantile process (Koenler and Xiao (2002)), and adapted by Chung and Olivares (2021).

Usage

PTQTE.Khmaladze.fit(
  Y,
  Z,
  taus = seq(0.1, 0.9, by = 0.05),
  alpha = 0.05,
  n.perm = 999
)

Arguments

Y

Numeric. Vector of responses.

Z

Numeric. Treatment indicator. Z=1 if the unit is in the treatment group, and Z=0 if the unit is in the control group.

taus

quantiles at which the process is to be evaluated, if any of the taus lie outside (0,1) then the full process is computed for all distinct solutions.

alpha

Significance level.

n.perm

Numeric. Number of permutations needed for the stochastic approximation of the p-values. The default is n.perm=999.

Value

An object of class "PTQTE.Khmaladze" containing at least the following components:

n_populations

Number of grups.

N

Sample Size.

KS.obs

Observed two-sample Kolmogorov-Smirnov test statistic based on the quantile process.

shift

The estimated nuisance parameter.

rej.rule

Binary decision for the permutation test, where 1 means rejection.

pvalue

P-value.

KS.perm

Vector. Test statistic recalculated for all permutations used in the stochastic approximation.

n_perm

Number of permutations.

sample_sizes

Groups size.

Author(s)

Maurcio Olivares

References

Khmaladze, E. (1981). Martingale Approach in the Theory of Goodness-of-fit Tests. Theory of Probability and its Application, 26: 240–257. Koenker, R. and Xiao, Z. (2002) Inference on the Quantile Regression Process. Econometrica, 70(4): 1583-1612. Chung, E. and Olivares, M. (2021). Comment on "Can Variation in Subgroups' Average Treatment Effects Explain Treatment Effect Heterogeneity? Evidence from a Social Experiment."

Examples

## Not run: 
dta <- data.frame(Y=rnorm(100),Z=sample(c(0,1), 100, replace = TRUE))
pt.QTE<-PTQTE.Khmaladze.fit(dta$Y,dta$Z,taus=seq(.1,.9,by=0.05),alpha=0.05,n.perm = 499)
summary(pt.QTE)

## End(Not run)

Regression Discontinuity Design Permutation Test

Description

A permutation test for continuity of covariates in Sharp Regression Discontinuity Design as described in Canay and Kamat (2018).

Usage

RDperm(
  W,
  z,
  data,
  n.perm = 499,
  q_type = 10,
  cutoff = 0,
  test.statistic = "CvM"
)

Arguments

W

Character. Vector of covariates names. The procedure will test the null hypothesis of continuity of the distribution of each element in W at the cutoff.

z

Character. Running variable name. This is the scalar random variable that defines, along with the cutoff, the treatment assignment rule in the sharp regression discontinuity design.

data

Data.frame.

n.perm

Numeric. Number of permutations needed for the stochastic approximation of the p-values. See remark 3.2 in Canay and Kamat (2018). The default is B=499.

q_type

A fixed and small (relative to the sample size) natural number that will define the q closest values of the order statistic of Z to the right and to the left of the cutoff. The default, 'rot', value is given by the feasible rule of thumb in footnote 4 of Canay and Kamat (2018), section 3.1. If 'arot', it calls for the Rule of Thumb described in equation (15) of Canay and Kamat (2018), section 3.1. The default option grows at a slower rate than the optional rule of thumb, but adds a larger constant.

cutoff

Numeric. The scalar defining the threshold of the running variable.

test.statistic

Character. A rank test statistic satisfying rank invariance. The default is a Cramer-von Mises test statistic.

Value

The functions summary and plot are used to obtain and print a summary and plot of the estimated regression discontinuity. The object of class RDperm is a list containing the following components:

results

Matrix. Test Statistic, P-values and Q

test.statistic

Test Statistic

q_type

Type of Q used in the calculations, can be either, "Defined by User", the "Rule of Thumb" or the "Alternative Rule of Thumb".

n_perm

number of permutations

rv

Character. Running variable name

Z

Vector. Running Variable

cutoff

cutoff

data

data set

S

Matrix. Pooled sample of induced order statistics

S_perm

List. Permutations of the induced order statistic.

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri

References

Canay, I and Kamat V, (2018) Approximate Permutation Tests and Induced Order Statistics in the Regression Discontinuity Design. The Review of Economic Studies, 85(3): 1577-1608

Examples

permtest<-RDperm(W=c("demshareprev"),z="difdemshare",data=lee2008)
summary(permtest)
## Not run: 
permtest<-RDperm(W=c("demshareprev","demwinprev"),z="difdemshare",data=lee2008)
summary(permtest)

## End(Not run)

Robust Permutation Test

Description

This function considers the k-sample problem of comparing general parameters, such as means, medians, or parameters that depend on the joint distribution using permutation tests. Under weak assumptions for comparing estimator, the permutation tests implemented here provide a general test procedure whereby the asymptotic validity of the permutation test holds while retaining the exact rejection probability \alpha in finite samples when the underlying distributions are identical. Here we will consider three test for the 2 sample case, but the function works for k-samples.

Difference of means: Here, the null hypothesis is of the form H_0: \mu(P)-\mu(Q)=0, and the corresponding test statistic is given by

T_{m,n}=\frac{N^{1/2}(\bar{X}_m-\bar{Y}_n)}{\sqrt{\frac{N}{m}\sigma^2_m(X_1,\dots,X_m)+ \frac{N}{n}\sigma^2_n(Y_1,\dots,Y_n)}}

where \bar{X}_m and \bar{Y}_n are the sample means from population P and population Q, respectively, and \sigma^2_m(X_1,\dots,X_m) is a consistent estimator of \sigma^2(P) when X_1,\dots,X_m are i.i.d. from P. Assume consistency also under Q.

Difference of medians: Let F and G be the CDFs corresponding to P and Q, and denote \theta(F) the median of F i.e. \theta(F)=\inf\{x:F(x)\ge1/2\}. Assume that F is continuously differentiable at \theta(P) with derivative F' (and the same with F replaced by G). Here, the null hypothesis is of the form H_0: \theta(P)-\theta(Q)=0, and the corresponding test statistic is given by

T_{m,n}=\frac{N^{1/2}\left(\theta(\hat{P}_m)-\theta(\hat{Q})\right)}{\hat{\upsilon}_{m,n}}

where \hat{\upsilon}_{m,n} is a consistent estimator of \upsilon(P,Q):

\upsilon(P,Q)=\frac{1}{\lambda}\frac{1}{4(F'(\theta))^2}+\frac{1}{1-\lambda}\frac{1}{4(G'(\theta))^2}

Choices of \hat{\upsilon}_{m,n} may include the kernel estimator of Devroye and Wagner (1980), the bootstrap estimator of Efron (1992), or the smoothed bootstrap Hall et al. (1989) to list a few. For further details, see Chung and Romano (2013). Current implementation uses the bootstrap estimator of Efron (1992)

Difference of variances: Here, the null hypothesis is of the form H_0: \sigma^2(P)-\sigma^2(Q)=0, and the corresponding test statistic is given by

T_{m,n}=\frac{N^{1/2}(\hat{\sigma}_m^2(X_1,\dots,X_,)-\hat{\sigma}_n^2(Y_1,\dots,Y_n))}{\sqrt{\frac{N}{m}(\hat{\mu}_{4,x}-\frac{(m-3)}{(m-1)}(\hat{\sigma}_m^2)^2)+\frac{N}{n}(\hat{\mu}_{4,y}-\frac{(n-3)}{(n-1)}(\hat{\sigma}_y^2)^2)}}

where \hat{\mu}_{4,m} the sample analog of E(X-\mu)^4 based on an i.i.d. sample X_1,\dots,X_m from P. Similarly for \hat{\mu}_{4,n}.

We could also have the case when the parameter of interest is a function of the joint distribution. The examples considered here are

Lehmann (1951) two-sample U statistics: Consider testing H_0: P=Q, or the more general hypothesis that P and Q only differ in location against the alternative that the Y's are more spread out than the X's. The null hypothesis is of the form

H_0: P(\vert Y-Y'\vert>\vert X-X'\vert)=1/2

.

Two-sample Wilcoxon statistic, where the null hypothesis is of the form

H_0: P(X\le Y)=1/2

.

Two-sample Wilcoxon statistic without continuity assumption. In this case, the null hypothesis is of the form

H_0: P(X\le Y)=P(Y\le X)

.

Hollander (1967) two-sample U statistics. The null hypothesis is of the form

H_0: P(X+X'<Y+Y')=1/2

.

Usage

RPT(
  formula,
  data,
  test = "means",
  n.perm = 499,
  na.action,
  wilcoxon.option = "continuity"
)

Arguments

formula

a formula object, with the response on the left of a ~ operator, and the groups on the right.

data

a data.frame in which to interpret the variables named in the formula. If this is missing, then the variables in the formula should be on the search list.

test

test to be perfomed. Multiple options are available, depending on the nature of the testing problem. In general, we have two types of problem. First, when the researcher is interested in comparing parameters. In this case, "means" will perform a Difference of Means, "medians" a Difference of Medians, "variances" a Difference of Variances. This case allows for 2 or more population comparisons. For the test of difference of medians the Efron (1992) bootstrap estimator is used to estimate the variances (for further details, see Chung and Romano (2013)). Second, when the parameter of interest is a function of the joint distribution. In this case, "lehmann.2S.test" will perform Lehmann (1951) two-sample U statistics, "wilcoxon.2s.test" the two-sample Wilcoxon test (with or without continuity assumption), and "hollander.2S.test" Hollander (1967) two sample U statistics. In this case, only 2 sample comparisons are permitted.

n.perm

Numeric. Number of permutations needed for the stochastic approximation of the p-values. See remark 3.2 in Canay and Kamat (2017). The default is n.perm=499.

na.action

a function to filter missing data. This is applied to the model.frame . The default is na.omit, which deletes observations that contain one or more missing values.

wilcoxon.option

Continuity assumption for Wilcoxon test" with continuity ("continuity") or without ("discontinuity"). The default is "continuity"

Value

An object of class "RPT" is a list containing at least the following components:

description

Type of test, can be Difference of Means, Medians, or Variances.

n_populations

Number of grups.

N

Sample Size.

T.obs

Observed test statistic.

pvalue

P-value.

T.perm

Vector. Test statistics from the permutations.

n_perm

Number of permutations.

parameters

Estimated parameters.

sample_sizes

Groups lengths.

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri

References

Chung, E. and Romano, J. P. (2013). Exact and asymptotically robust permutation tests. The Annals of Statistics, 41(2):484–507. Chung, E. and Romano, J. P. (2016). Asymptotically valid and exact permutation tests based on two-sample u-statistics. Journal of Statistical Planning and Inference, 168:97–105. Devroye, L. P. and Wagner, T. J. (1980). The strong uniform consistency of kernel density estimates. In Multivariate Analysis V: Proceedings of the fifth International Symposium on Multivariate Analysis, volume 5, pages 59–77. Efron, B. (1992). Bootstrap methods: another look at the jackknife. In Breakthroughs in statistics, pages 569–593. Springer. Hall, P., DiCiccio, T. J., and Romano, J. P. (1989). On smoothing and the bootstrap. The Annals of Statistics, pages 692–704. Hollander, M. (1967). Asymptotic efficiency of two nonparametric competitors of wilcoxon’s two sample test. Journal of the American Statistical Association, 62(319):939–949. Lehmann, E. L. (1951). Consistency and unbiasedness of certain nonparametric tests. The Annals of Mathematical Statistics, pages 165–179.

Examples

## Not run: 
male<-rnorm(50,1,1)
female<-rnorm(50,1,2)
dta<-data.frame(group=c(rep(1,50),rep(2,50)),outcome=c(male,female))
rpt.var<-RPT(dta$outcome~dta$group,test="variances")
summary(rpt.var)


## End(Not run)

General Construction of Permutation Tests: Group Actions

Description

Calculates the pre-specified actions on data. Consider data Z taking values in a sample space \Omega. Let \mathbf{G} be a finite group of transformations from \Omega onto itself, with M=\vert \mathbf{G}\vert. This function applies gZ as g varies in \bf{G}. If Z is a vector of sizeN and the actions g are permutations, M=N!. If the actions g are sign changes, then M=\{1,-1\}^{N}.

Usage

group.action(Z, M, type = "permutations")

Arguments

Z

Numeric. A vector of size N to which the group action will act on. In the two-sample testing problem, Z is the pooled sample.

M

Numeric. Number of actions to be performed. This is the number of transformations used in the stochastic approximation to the test. This is due to the fact that in some cases M=\vert \mathbf{G}\vert is too large, which makes the application of the actions computationally expensive.

type

Character. The action to be performed. It represents gx, the action the action of g\in\mathbf{G} on x\in\Omega. It can be either permutations or sign changes.

Value

Numeric. A matrix of size N\times M where N is the size of input Z and M is the number of actions to be performed on Z.

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri

References

Lehmann, Erich L. and Romano, Joseph P (2005) Testing statistical hypotheses.Springer Science & Business Media.


Data set used in Lee (2008)

Description

Randomized experiments from non-random selection in U.S. House elections

Format

A data frame with 6558 observations and two variables:

demsharenext

Democrat vote share election t+1

difdemshare

Running variable. Diff. democratic share

demshareprev

Democrat vote share t-1

demwinprev

Democrat win t-1

demofficeexp

Democrat political experience t

othofficeexp

Oppositions political experience t

demelectexp

Democrat electoral experience t

othelectexp

Oposition electoral experience t

Source

Mostly Harmless Econometrics Data Archive: https://economics.mit.edu/people/faculty/josh-angrist/mhe-data-archive

References

Lee, D. (2008) Randomized experiments from non-random selection in U.S. House elections, Journal of Econometrics, 142, 675-697


Plot RDperm

Description

Plots a histogram and empirical cdf

Usage

## S3 method for class 'RDperm'
plot(x, w, plot.class = "both", ...)

Arguments

x

Object of class "RDperm"

w

Character. Name of variable to be plotted

plot.class

Character. Can be: "both" for a histogram and cdf plot, "hist" for a histogram or "cdf" for only the cdf plot

...

Additional ggplot2 controls

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri

References

Canay, I and Kamat V, (2018) Approximate Permutation Tests and Induced Order Statistics in the Regression Discontinuity Design. The Review of Economic Studies, 85(3): 1577-1608

Examples

## Not run: 
permtest<-RDperm(W=c("demshareprev","demwinprev"),z="difdemshare",data=lee2008)
plot(permtest,w="demshareprev")

## End(Not run)

Permutation Test for the two-sample goodness-of-fit problem under covariate-adaptive randomization

Description

A permutation test of the two-sample goodness-of-fit hypothesis when the randomization scheme is covariate-adaptive. The permutation test considered here is based on prepivoting the Kolmogorov-Smirnov test statistic following Beran (1987,1988), and adapted by Olivares (2020). Current version includes the following randomization schemes: simple randomization, Efron's biased-coin design, Wei's biased-coin design, and stratified block randomization. This implementation uses a Bayesian bootstrap approximation for prepivoting.

Usage

prepivot.ks.permtest(Y1, Y0, alpha, B, n.perm)

Arguments

Y1

Numeric. A vector containing the response variable of the treatment group.

Y0

Numeric. A vector containing the response variable of the control group.

alpha

Numeric. Nominal level for the test. The default is 0.05.

B

Numeric. Number of weighted bootstrap samples.

n.perm

Numeric. Number of permutations needed for the stochastic approximation of the p-values. The default is n.perm=999.

Value

An object of class "prepivot.ks.permtest" containing at least the following components:

n_populations

Number of grups.

N

Sample Size.

T.obs

Observed test statistic.

cv

Critical Value. This value is used in the general construction of a randomization test.

pvalue

P-value.

rejectrule

Rule. Binary decision for randomization test, where 1 means "to reject"

T.perm

Vector. Test statistic recalculated for all permutations used in the stochastic approximation.

n.perm

Number of permutations.

B

Bayesian bootstrap samples.

sample_sizes

Groups size.

Author(s)

Maurcio Olivares

References

Beran, R. (1987). Prepivoting to reduce level error of confidence sets. Biometrika, 74(3): 457–468. Beran, R. (1988). Prepivoting test statistics: a bootstrap view of asymptotic refinements. Journal of the American Statistical Association, 83(403):687–697. Olivares, M. (2020). Asymptotically Robust Permutation Test under Covariate-Adaptive Randomization. Working Paper.

Examples

## Not run: 
Y0 <- rnorm(100, 1, 1)
Y1 <- rbeta(100,2,2)
Tx = sample(100) <= 0.5*(100)
# Observed Outcome 
Y = ifelse( Tx, Y1, Y0 )
dta <- data.frame(Y = Y, A = as.numeric(Tx))
pKS.GoF<-prepivot.ks.permtest(dta$Y[dta$A==1],dta$Y[dta$A==0],alpha=0.05,B=1000,n.perm = 999)
summary(pKS.GoF)

## End(Not run)

General Construction of Randomization Tests

Description

Calculates the randomization test. Further discussion can be found in chapter 15 of Lehmann and Romano (2005, p 633). Consider data X taking values in a sample space \Omega. Let \mathbf{G} be a finite group of transformations from \Omega onto itself, with M=\vert \mathbf{G}\vert. Let T(X) be a real-valued test statistic such that large values provide evidence against the null hypothesis. Denote by

T^{(1)}(X)\le T^{(2)}(X)\le\dots\le T^{(M)}(X)

the ordered values of \{T(gX)\,:\,g\in\mathbf{G}\}. Let k=M-\lfloor M\alpha\rfloor and define M^{+}(x) and M^{0}(x) be the number of values T^{(j)}(X), j=1,\dots,M, which are greater than T^{(k)}(X) and equal to T^{(k)}(X) respectively. Set

a(X)=\frac{\alpha M-M^{+}(X)}{M^{0}(X)}~.

The randomization test is given by

\phi(X)=1\{T(x)> T^{(k)}(X)\}+a(X)\times 1\{T(X)= T^{(k)}(X)\}~.

Usage

randomization.test(Tn, Tng, alpha = 0.05)

Arguments

Tn

Numeric. A scalar representing the observed test statistic T(X).

Tng

Numeric. A vector containing \{T(gX)\,:\,g\in\mathbf{G}\}.

alpha

Numeric. Nominal level for the test. The default is 0.05.

Value

Numeric. A vector containing \phi(X)\in\{0,1\} and T^{(k)}(X). The test rejects the null hypothesis if \phi(X)=1, and does not reject otherwise.

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri

References

Lehmann, Erich L. and Romano, Joseph P (2005) Testing statistical hypotheses.Springer Science & Business Media.


Summarizing Permutation Test for Within-grpup Treatment Effect Heterogeneity in the presence of an Estimated Nuisance Parameter

Description

summary method for class "PT.Khmaladze.fit"

Usage

## S3 method for class 'PT.Khmaladze.MultTest'
summary(object, ..., digits = max(3, getOption("digits") - 3))

Arguments

object

an object of class "PT.Khmaladze.MultTest", usually a result of a call to PT.Khmaladze.MultTest

...

unused

digits

number of digits to display

Value

summary.PT.Khmaladze.MultTest returns an object of class "summary.PT.Khmaladze.MultTest" which has the following components

results

Matrix with the Testing Problem, Number of Permutations for the test and the multiple testing procedure, number of subgroups, (raw) p-values, adjusted p-values, Test Statistic.

Author(s)

Maurcio Olivares


Summarizing Permutation Test for Heterogeneous Treatment Effects with Estimated Nuisance Parameter

Description

summary method for class "PT.Khmaladze.fit"

Usage

## S3 method for class 'PT.Khmaladze.fit'
summary(object, ..., digits = max(3, getOption("digits") - 3))

Arguments

object

an object of class "PT.Khmaladze.fit", usually a result of a call to PT.Khmaladze.fit

...

unused

digits

number of digits to display

Value

summary.PT.Khmaladze.fit returns an object of class "summary.PT.Khmaladze.fit" which has the following components

results

Matrix with the Testing Problem, Sample Sizes, Number of Permutations, ATE, Test Statistic, Critical value and P-value.

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri


Summarizing Quantile-Based Permutation Test with an Estimated Nuisance Parameter

Description

summary method for class "PTQTE.Khmaladze.fit"

Usage

## S3 method for class 'PTQTE.Khmaladze.fit'
summary(object, ..., digits = max(3, getOption("digits") - 3))

Arguments

object

an object of class "PTQTE.Khmaladze.fit", the result of calling PTQTE.Khmaladze.fit

...

unused

digits

number of digits to display

Value

PTQTE.Khmaladze.fit returns an object of class "PTQTE.Khmaladze.fit" which has the following components

results

Matrix with the Testing Problem, Sample Sizes, Number of Permutations, Observed test Statistic, Binary Rule and Significance Level.

Author(s)

Maurcio Olivares


Summarizing Regression Discontinuity Design Permutation Test

Description

summary method for class "RDPerm"

Usage

## S3 method for class 'RDperm'
summary(object, digits = max(3, getOption("digits") - 3), ...)

Arguments

object

an object of class "RDperm", usually a result of a call to RDperm

digits

number of digits to display

...

unused

Value

summary.RDperm returns an object of class "summary.RDperm" which has the following components

results

Matrix with the Test Statistic, P-values and Q used

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri


Summarizing Robust Permutation Test

Description

summary method for class "RPT"

Usage

## S3 method for class 'RPT'
summary(object, ..., digits = max(3, getOption("digits") - 3))

Arguments

object

an object of class "RPT", usually a result of a call to RPT

...

unused

digits

number of digits to display

Value

summary.RPT returns an object of class "summary.RPT" which has the following components

results

Matrix with the Testing Problem, Point Estimates, Sample Sizes, Test Statistic, P-values and Sample Sizes.

Author(s)

Maurcio Olivares

Ignacio Sarmiento Barbieri


Summarizing Two-sample Goodness-of-fit Permutation Test under Covariate-adaptive Randomization

Description

summary method for class "prepivot.ks.permtest"

Usage

## S3 method for class 'prepivot.ks.permtest'
summary(object, ..., digits = max(3, getOption("digits") - 3))

Arguments

object

an object of class "prepivot.ks.permtest", the result of calling prepivot.ks.permtest

...

unused

digits

number of digits to display

Value

summary.prepivot.ks.permtest returns an object of class "summary.prepivot.ks.permtest" which has the following components

results

Matrix with the Testing Problem, Sample Sizes, Number of Permutations, Number of Bootstrap samples, Observed test Statistic, Critical value and P-value.

Author(s)

Maurcio Olivares