knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
set.seed(123)
library(rART)

The rART package provides functions for Approximate Randomization Tests with a Small Number of Clusters introduced in "Randomization tests under an approximate symmetry assumption" (Canay et al. 2017) and further described in "A User's Guide to Approximate Randomization Tests with a Small Number of Clusters" (Cai et al. 2022).

The package is centered around a single function artlm which runs the main regression. Several companion functions are provided in order to use the method. In order to demonstrate this, we generate some data.

cn <- 100 # cluster size
nc <- 10   # number of clusters

x1 <- rnorm(cn * nc, sd = 2)
x2 <- rnorm(cn * nc, mean = x1)
x3 <- runif(cn * nc)

eps <- matrix(runif(cn * nc), cn, nc)

# make some correlation within groups
eps <- as.vector(eps + eps[sample(cn),] + eps[sample(cn),])
group = factor(rep(1:nc, each = cn))

# true model
y <- 1 + 10*x1 + x2/20 + eps

df <- data.frame(y, x1, x2, x3, group)

head(df)

Regression

The linear ART regression is artlm. It is exactly the same as lm. However, it requires a cluster variable or vector to be specified.

(artlm1 <- artlm(y ~ x1 + x2, cluster=group, data=df))

It supports all the features that lm supports. For example, you can add fixed effects.

(artlm2 <- artlm(y ~ x1 + x2 + group - 1, cluster=group, data=df))

You can also specify that you are only interested in a subset of the variables. For example, suppose I am only interested in x1.

(artlm3 <- artlm(y ~ x1 + x2 + group - 1, cluster=group, select = "x1", data=df))

Including the select option allows you to choose the parameters you are interested in. The result will not display in the regression object itself. However, chosen variables will not de displayed in summary etc.

Summarizing models

You can run the simplest form of ART by running summary on any regression object. For example, we can apply it to our weighted fixed effects regression.

summary(artlm2)

This gives us the OLS estimates, the t-statistic, the p-value, and the critical value of the t-test for 95\% confidence.

If we summarize the regression where we selected to view only x1, then we will only see this one variable in the summary. Note that no selection is required to ignore the group fixed effects because ART cannot be applied to these coefficients.

summary(artlm3)

Confidence intervals

Confidence intervals are computed using the confint command as usual.

confint(artlm2)

You can adjust the level of significance using the level parameter.

confint(artlm2, level = 0.98)

The command will only display selected variables. So, if we use artlm3 where we selected only x1, then we will only see the confidence interval for this one term. More importantly, the function will not compute intervals for unselected parameters.

confint(artlm3)

It is also possible to select variables in confint instead of in the regression.

confint(artlm2, parm = "x2")

Linear tests

You can conduct arbitrary linear tests using ARTHypothesis. For example, suppose I wanted to test to see if $\beta_1 = \beta_2$. Then, I can run.

ARTHypothesis(artlm2, "x1 = x2")

You can also supply the constraint vector and constant value manually like so.

ARTHypothesis(artlm2, c(1,-1), 0)

You cannot construct a linear test using a parameter that was not selected in the original regression.



mwt/rART documentation built on June 16, 2022, 1:39 a.m.