# rrtest: Generic residual randomization test In RRI: Residual Randomization Inference for Regression Models

## Description

This function tests the specified linear hypothesis in `model` assuming the errors are distributionally invariant with respect to stochastic function `g_invar`.

## Usage

 `1` ```rrtest(model, g_invar, num_R = 999, alpha = 0.05, val_type = "decision") ```

## Arguments

 `model` Regression model and hypothesis. See example_model for details. `g_invar` Stochastic function that transforms residuals. Accepts n-vector and returns n-vector. `num_R` Number of test statistic values to calculate in the randomization 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 * beta + ... + 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:

(e_1, e_2, ..., e_n) ~ g_invar(e_1, e_2, ..., e_n),

where ~ denotes equality in distribution, and `g_invar` is the supplied invariance function.

## 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

There is no guarantee that an arbitrary `g_invar` will produce valid tests. The rrtest_clust function has such guarantees under mild assumptions.

 ```1 2 3``` ```model = example_model(n = 100) # test H0: beta2 = 0 (here, H0 is true) g_invar = function(e) sample(e) # Assume errors are exchangeable. rrtest(model, g_invar) # same as rrtest_clust(model, "perm") ```