farm.select {FarmSelect} | R Documentation |
Factor-adjusted robust model selection
Description
Given a covariate matrix and output vector, this function first adjusts the covariates for underlying factors and then performs model selection.
Usage
farm.select(X, Y, loss = c("scad", "mcp", "lasso"), robust = TRUE,
cv = FALSE, tau = 2, lin.reg = TRUE, K.factors = NULL,
max.iter = 10000, nfolds = ceiling(length(Y)/3), eps = 1e-04,
verbose = TRUE)
Arguments
X |
an n x p covariate matrix with each row being a sample. Must have same number of rows as the size of |
Y |
a size n outcome vector. |
loss |
a character string specifying the loss function to be minimized. Must be one of "scad" (default) "mcp" or "lasso". You can just specify the initial letter. |
robust |
a boolean, specifying whether or not to use robust estimators for mean and variance. Default is TRUE. |
cv |
a boolean, specifying whether or not to run cross-validation for the tuning parameter. Default is FALSE. Only used if |
tau |
|
lin.reg |
a boolean, specifying whether or not to assume that we have a linear regression model (TRUE) or a logit model (FALSE) structure. Default is TRUE. |
K.factors |
number of factors to be estimated. Otherwise estimated internally. K>0. |
max.iter |
maximum number of iterations across the regularization path. Default is 10000. |
nfolds |
the number of cross-validation folds. Default is ceiling(samplesize/3). |
eps |
Convergence threshhold for model fitting using |
verbose |
a boolean specifying whether to print runtime updates to the console. Default is TRUE. |
Details
For formula of how the covariates are adjusted for latent factors, see Section 3.2 in Fan et al.(2017).
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.
ncvreg
is used to fit the model after decorrelation. This package may output its own warnings about failures to converge and model saturation.
Value
A list with the following items
model.size |
the size of the model |
beta.chosen |
the indices of the covariates chosen in the model |
coef.chosen |
the coefficients of the chosen covariates |
X.residual |
the residual covariate matrix after adjusting for factors |
nfactors |
number of (estimated) factors |
n |
number of observations |
p |
number of dimensions |
robust |
whether robust parameters were used |
loss |
loss function used |
#' @details Number of rows and columns of the covariate matrix must be at least 4 in order to be able to calculate latent factors.
References
Fan J., Ke Y., Wang K., "Decorrelation of Covariates for High Dimensional Sparse Regression." https://arxiv.org/abs/1612.08490
See Also
Examples
##linear regression
set.seed(100)
P = 200 #dimension
N = 50 #samples
K = 3 #nfactors
Q = 3 #model size
Lambda = matrix(rnorm(P*K, 0,1), P,K)
F = matrix(rnorm(N*K, 0,1), N,K)
U = matrix(rnorm(P*N, 0,1), P,N)
X = Lambda%*%t(F)+U
X = t(X)
beta_1 = rep(5,Q)
beta = c(beta_1, rep(0,P-Q))
eps = rt(N, 2.5)
Y = X%*%beta+eps
##with default options
output = farm.select(X,Y) #robust, no cross-validation
output$beta.chosen #variables selected
output$coef.chosen #coefficients of selected variables
#examples of other robustification options
output = farm.select(X,Y,robust = FALSE) #non-robust
output = farm.select(X,Y, tau = 3) #robust, no cross-validation, specified tau
#output = farm.select(X,Y, cv= TRUE) #robust, cross-validation: LONG RUNNING!
##changing the loss function and inputting factors
output = farm.select(X, Y,loss = "mcp", K.factors = 4)
##use a logistic regression model, a larger sample size is desired.
## Not run:
set.seed(100)
P = 400 #dimension
N = 300 #samples
K = 3 #nfactors
Q = 3 #model size
Lambda = matrix(rnorm(P*K, 0,1), P,K)
F = matrix(rnorm(N*K, 0,1), N,K)
U = matrix(rnorm(P*N, 0,1), P,N)
X = Lambda%*%t(F)+U
X = t(X)
beta_1 = rep(5, Q)
beta = c(beta_1, rep(0,P-Q))
eps = rnorm(N)
Prob = 1/(1+exp(-X%*%beta))
Y = rbinom(N, 1, Prob)
output = farm.select(X,Y, lin.reg=FALSE, eps=1e-3)
output$beta.chosen
output$coef.chosen
## End(Not run)