**F**actor-**A**djusted
**R**obust **M**ultiple
**Test**ing

The **FarmTest** library implements the
**F**actor-**A**djusted
**R**obust **M**ultiple
**Test**ing method proposed by Fan
et al., 2019. Let *X* be a *p*-dimensional random
vector with mean *μ =
(μ _{1},…,μ_{p})^{T}*. This library carries
out simultaneous inference on the

FarmTest implements a series of adaptive Huber methods combined with fast data-driven tuning schemes to estimate model parameters and construct test statistics that are robust against heavy-tailed and/or asymetric error distributions. Extensions to two-sample simultaneous mean comparison are also included. As by-products, this library also contains functions that compute adaptive Huber mean and covariance matrix estimators that are of independent interest.

The FarmTest method involves multiple tuning parameters for fitting the factor models. In the case of latent factors, the algorithm first computes a robust covariance matrix estimator, and then use the eigenvalue ratio method (Ahn and Horenstein, 2013) along with SVD to estimate the number of factors and loading vectors. It is therefore computationally expenstive to select all the tuning parameters via cross-validation. Instead, the current version makes use of the fast data-driven tuning scheme proposed by Ke et al., 2019, which significantly reduces the computational cost.

`FarmTest`

is available on CRAN, and it can
be installed into `R`

environment using the command:

`install.packages("FarmTest")`

There are 7 functions in this library:

`farm.test`

: Factor-adjusted robust multiple testing.`print.farm.test`

: Print function for`farm.test`

.`summary.farm.test`

: Summary function for`farm.test`

.`plot.farm.test`

: Plot function for`farm.test`

.`huber.mean`

: Tuning-free Huber mean estimation.`huber.cov`

: Tuning-free Huber-type covariance estimation.`huber.reg`

: Tuning-free Huber regression.

Help on the functions can be accessed by typing `?`

,
followed by function name at the `R`

command prompt.

For example, `?farm.test`

will present a detailed
documentation with inputs, outputs and examples of the function
`farm.test`

.

First generate data from a three-factor model *X = μ + Bf +
ε*. The sample size and dimension (the number of hypotheses) are
taken to be 50 and 100, respectively. The number of nonnulls is 5.

```
library(FarmTest)
= 50
n = 100
p = 3
K = rep(0, p)
muX 1:5] = 2
muX[set.seed(2019)
= matrix(rnorm(p * n, 0, 1), nrow = n)
epsilonX = matrix(runif(p * K, -2, 2), nrow = p)
BX = matrix(rnorm(K * n, 0, 1), nrow = n)
fX = rep(1, n) %*% t(muX) + fX %*% t(BX) + epsilonX X
```

In this case, the factors are unobservable and thus need to be
recovered from data. Assume one is interested in simultaneous inference
on the means with two-sided alternatives. For a desired FDR level
*α=0.05*, run FarmTest as follows:

`= farm.test(X) output `

The library includes `summary.farm.test`

,
`print.farm.test`

and `plot.farm.test`

functions,
which summarize, print and visualize the results of
`farm.test`

:

```
summary(output)
print(output)
plot(output)
```

Based on 100 simulations, we report below the average values of the true positive rate (TPR), false positive rate (FPR) and false discover rate (FDR).

TPR | FPR | FDR |
---|---|---|

1.000 | 0.002 | 0.026 |

In addition, we illustrate the use of FarmTest under different
circumstances. For one-sided alternatives, modify the
`alternative`

argument to be `less`

or
`greater`

:

`= farm.test(X, alternative = "less") output `

The number of factors can be user-specified. It should be a non-negative integer that is less than the minumum between sample size and number of hypotheses. However, without any subjective ground of the data, this is not recommended.

`= farm.test(X, KX = 10) output `

As a special case, when we set number of factors to be zero, a robust test without factor adjustment will be conducted.

`= farm.test(X, KX = 0) output `

In the situation with observable factors, put the *n* by
*K* factor matrix into argument `fX`

:

`= farm.test(X, fX = fX) output `

Finally, as an extension to two-sample problems, we generate another
sample *Y* with the same dimension 100, and conduct a two-sided
test with latent factors.

```
= rep(0, p)
muY 1:5] = 4
muY[= matrix(rnorm(p * n, 0, 1), nrow = n)
epsilonY = matrix(runif(p * K, -2, 2), nrow = p)
BY = matrix(rnorm(K * n, 0, 1), nrow = n)
fY = rep(1, n) %*% t(muY) + fY %*% t(BY) + epsilonY
Y = farm.test(X, Y = Y) output
```

As by-products, robust mean and covariance matrix estimation is not
only an important step in the FarmTest, but also of independent interest
in many other problems. We write separate functions
`huber.mean`

and `huber.cov`

for this purpose.

```
library(FarmTest)
set.seed(1)
= 1000
n = rlnorm(n, 0, 1.5)
X = huber.mean(X)
huberMean
= 100
n = 50
d = matrix(rt(n * d, df = 3), n, d)
X = huber.cov(X) huberCov
```

This library is built upon an earlier version written by Bose, K.,
Ke, Y. and Zhou, W.-X. (GitHub). Another library
named `tfHuber`

that implements data-driven robust mean and
covariance matrix estimation as well as standard and
*l _{1}*-regularized Huber regression can be found here.

GPL-3.0

C++11

Xiaoou Pan xip024@ucsd.edu, Yuan Ke yuan.ke@uga.edu, Wen-Xin Zhou wez243@ucsd.edu

Xiaoou Pan xip024@ucsd.edu

Ahn, S. C. and Horenstein, A. R. (2013). Eigenvalue ratio test for
the number of factors. *Econometrica* **81**
1203–1227. Paper

Benjamini, Y. and Hochberg, Y. (1995). Controlling the false
discovery rate: A practical and powerful approach to multiple testing.
*J. R. Stat. Soc. Ser. B. Stat. Methodol.* **57**
289–300. Paper

Bose, K., Fan, J., Ke, Y., Pan, X. and Zhou, W.-X. (2019). FarmTest: An R package for factor-adjusted robust multiple testing. Preprint

Eddelbuettel, D. and Francois, R. (2011). Rcpp: Seamless R and C++
integration. *J. Stat. Softw.* **40** 1-18. Paper

Eddelbuettel, D. and Sanderson, C. (2014). RcppArmadillo:
Accelerating R with high-performance C++ linear algebra. *Comput.
Statist. Data Anal.* **71** 1054-1063. Paper

Fan, J., Ke, Y., Sun, Q. and Zhou, W.-X. (2019). FarmTest:
Factor-adjusted robust multiple testing with approximate false discovery
control. *J. Amer. Statist. Assoc.* **114**
1880-1893. Paper

Huber, P. J. (1964). Robust estimation of a location parameter.
*Ann. Math. Statist.* **35** 73-101. Paper

Ke, Y., Minsker, S., Ren, Z., Sun, Q. and Zhou, W.-X. (2019).
User-friendly covariance estimation for heavy-tailed distributions.
*Statis. Sci.* **34** 454-471. Paper

Sanderson, C. and Curtin, R. (2016). Armadillo: A template-based C++
library for linear algebra. *J. Open Source Softw.*
**1** 26. Paper

Storey, J. D. (2002). A direct approach to false discovery rates.
*J. R. Stat. Soc. Ser. B. Stat. Methodol.* **64**
479–498. Paper

Sun, Q., Zhou, W.-X. and Fan, J. (2020). Adaptive Huber regression.
*J. Amer. Statist. Assoc.* **115** 254-265. Paper

Zhou, W.-X., Bose, K., Fan, J. and Liu, H. (2018). A new perspective
on robust M-estimation: Finite sample theory and applications to
dependence-adjusted multiple testing. *Ann. Statist.*
**46** 1904-1931. Paper