FarmTest (version 1.0.3)

farm.scree: Diagnostic plots and quantities arising from estimating the number of underlying factors


Given the data, this function draws a scree plot and a plot of the eigenvalue ratios. The eignevalue ratio test is used to estimate the number of factors. See Ahn and Horenstein(2013).


farm.scree(X, K.scree = NULL, K.factors = NULL, robust = TRUE,
  cv = TRUE, tau = 2, show.plot = FALSE)



an n x p data matrix with each row being a sample.


an optional integer specifying the number of eigenvalues to be plotted in the scree plot. Default is min(n,p).


an optional integer specifying the number of eigenvalues to be used for the eigenvalue ratio test. Default is min(n,p)/2.


a TRUE/FALSE indicating whether to use a robust covariance estimator if TRUE, or the sample covariance estimator. Default is TRUE.


a boolean, specifying whether or not to run cross-validation for the tuning parameter. Default is TRUE. Only used if robust is TRUE.


>0, multiplier for the tuning parameter for Huber loss function. Default is 2. Only used if robust is TRUE and cv is FALSE. See details.


a TRUE/FALSE indicating whether to show the resulting plots. Default is FALSE.


An object with S3 class farm.scree containing:

  • eigenvalues Eigenvalues of the covariance matrix

  • proportions Proportion of variance explained by the principal components

  • eigenvalue.ratios Ratios calculated in the eigenvalue ratio test

  • nfactors Number of factors found using the eigenvalue ratio test

  • K.scree Number of eigenvalues plotted in the scree plot

  • K.factors Number of eigenvalues used in the eigenvalue ratio test

If show.plots=TRUE function returns two plots: First plot is the scree plot of the data. Second plot illustrates the eigenvalue ratio test.


The maximum eigenvalue ratio is marked differently on the plot. The index of this maximum ratio gives the number of estimated factors.

If show.plots=TRUE, plots are output and user has to hit <Return> to see the second plot. Alternatively, one may use the plot method for this class.

The tuning parameter = tau * sigma * optimal rate where optimal rate is the optimal rate for the tuning parameter. For details, see Fan et al.(2017). sigma is the standard deviation of the data.


Ahn, S. C. and Horenstein, A. R. (2013). "Eigenvalue Ratio Test for the Number of Factors," Econometrica, 81 (3), 1203<U+2013>1227.

Fan, J., Ke, Y., Sun, Q. and Zhou, W-X. (2017). "FARM-Test: Factor-Adjusted Robust Multiple Testing with False Discovery Control",

Zhou, W-X., Bose, K., Fan, J. and Liu, H. (2017). "A New Perspective on Robust M-Estimation: Finite Sample Theory and Applications to Dependence-Adjusted Multiple Testing," Annals of Statistics, to appear,

See Also and


Run this code
p = 100
n = 20
epsilon = matrix(rnorm( p*n, 0,1), nrow = n)
B = matrix(rnorm(p*3,0,1), nrow=p)
fx = matrix(rnorm(3*n, 0,1), nrow = n)
X = fx%*%t(B)+ epsilon
output = farm.scree(X,show.plot = TRUE, cv=FALSE)
output = farm.scree(X,show.plot = FALSE, cv=FALSE, K.scree=5, K.factors =10)
plot(output, scree.plot=FALSE, col="blue", main="Customized plot")

# }

Run the code above in your browser using DataCamp Workspace