rrtest_clust: Residual randomization test under cluster invariances

Description Usage Arguments Details Value Note See Also Examples

View source: R/functions.R

Description

This function tests the specified linear hypothesis in model assuming that the errors have some form of cluster invariance determined by type within the clusters determined by clustering.

Usage

1
2
3
4
5
6
7
8
rrtest_clust(
  model,
  type,
  clustering = NULL,
  num_R = 999,
  alpha = 0.05,
  val_type = "decision"
)

Arguments

model

Regression model and hypothesis. See example_model for details.

type

A character, either "perm", "sign" or "double".

clustering

A List that specifies a clustering of datapoint indexes 1, ..., n. See example_clustering. If NULL it takes default value according to type (see Note)

num_R

Number of test statistic values to calculate in the test.

alpha

Nominal test level (between 0 to 1).

val_type

The type of return value.

Details

For the regression y = X * beta + e, this function is testing the following linear null hypothesis:

H0: lam' beta = lam[1] * beta[1] + ... + lam[p] * beta[p] = lam0,

where y, X, lam, lam0 are specified in model. The assumption is that the errors, e, have some form of cluster invariance. Specifically:

Value

If val_type = "decision" (default) we get the test binary decision (1=REJECT H0).

If val_type = "pval" we get the test p-value.

If val_type = "full" we get the full test output, i.e., a List with elements tobs, tvals, the observed and randomization values of the test statistic, respectively.

Note

If clustering is NULL then it will be assigned a default value:

As in bootstrap num_R is usually between 1000-5000.

See Also

Life after bootstrap: residual randomization inference in regression models (Toulis, 2019)

https://www.ptoulis.com/residual-randomization

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
# 1. Validity example
set.seed(123)
n = 50
X = cbind(rep(1, n), 1:n/n)
beta = c(0, 0)
rej = replicate(200, {
  y = X %*% beta  + rt(n, df=5)
  model = list(y=y, X=X, lam=c(0, 1), lam0=0)  # H0: beta2 = 0
  rrtest_clust(model, "perm")
})
mean(rej)  # Should be ~ 5% since H0 is true.

# 2. Heteroskedastic example
set.seed(123)
n = 200
X = cbind(rep(1, n), 1:n/n)
beta = c(-1, 0.2)
ind = c(rep(0, 0.9*n), rep(1, .1*n))  # cluster indicator
y = X %*% beta + rnorm(n, sd= (1-ind) * 0.1 + ind * 5) # heteroskedastic
confint(lm(y ~ X + 0))  # normal OLS does not reject H0: beta2 = 0
cl = list(which(ind==0), which(ind==1))
model = list(y=y, X=X, lam=c(0, 1), lam0=0)

rrtest_clust(model, "sign")  # errors are sign symmetric regardless of cluster.
# Cluster sign test does not reject because of noise.

rrtest_clust(model, "perm", cl)  # errors are exchangeable within clusters
# Cluster permutation test rejects because inference is sharper.

RRI documentation built on Dec. 19, 2019, 9:06 a.m.

Related to rrtest_clust in RRI...