View source: R/cv.panel.sglfit.R
cv.panel.sglfit | R Documentation |
Does k-fold cross-validation for panel data sg-LASSO regression model.
The function runs sglfit nfolds+1
times; the first to get the path solution in λ sequence, the rest to compute the fit with each of the folds omitted.
The average error and standard deviation over the folds is computed, and the optimal regression coefficients are returned for lam.min
and lam.1se
. Solutions are computed for a fixed γ
cv.panel.sglfit(x, y, lambda = NULL, gamma = 1.0, gindex = 1:p, nfolds = 10, foldid, method = c("pooled", "fe"), nf = NULL, parallel = FALSE, ...)
x |
NT by p data matrix, where NT and p respectively denote the sample size of pooled data and the number of regressors. |
y |
NT by 1 response variable. |
lambda |
a user-supplied lambda sequence. By leaving this option unspecified (recommended), users can have the program compute its own λ sequence based on |
gamma |
sg-LASSO mixing parameter. γ = 1 gives LASSO solution and γ = 0 gives group LASSO solution. |
gindex |
p by 1 vector indicating group membership of each covariate. |
nfolds |
number of folds of the cv loop. Default set to |
foldid |
the fold assignments used. |
method |
choose between 'pooled' and 'fe'; 'pooled' forces the intercept to be fitted in sglfit, 'fe' computes the fixed effects. User must input the number of fixed effects |
nf |
number of fixed effects. Used only if |
parallel |
if |
... |
Other arguments that can be passed to sglfit. |
method='pooled'
) method='fe'
) cv.panel.sglfit object.
Jonas Striaukas
set.seed(1) x = matrix(rnorm(100 * 20), 100, 20) beta = c(5,4,3,2,1,rep(0, times = 15)) y = x%*%beta + rnorm(100) gindex = sort(rep(1:4,times=5)) cv.panel.sglfit(x = x, y = y, gindex = gindex, gamma = 0.5, method = "fe", nf = 10, standardize = FALSE, intercept = FALSE) ## Not run: # Parallel require(doMC) registerDoMC(cores = 2) x = matrix(rnorm(1000 * 20), 1000, 20) beta = c(5,4,3,2,1,rep(0, times = 15)) y = x%*%beta + rnorm(1000) gindex = sort(rep(1:4,times=5)) system.time(cv.panel.sglfit(x = x, y = y, gindex = gindex, gamma = 0.5, method = "fe", nf = 10, standardize = FALSE, intercept = FALSE)) system.time(cv.panel.sglfit(x = x, y = y, gindex = gindex, gamma = 0.5, method = "fe", nf = 10, standardize = FALSE, intercept = FALSE, parallel = TRUE)) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.