coef.pense_fit {pense} | R Documentation |
Extract Coefficient Estimates
Description
Extract coefficients from an adaptive PENSE (or LS-EN) regularization path fitted by pense()
or elnet()
.
Usage
## S3 method for class 'pense_fit'
coef(
object,
lambda,
alpha = NULL,
sparse = NULL,
standardized = FALSE,
exact = deprecated(),
correction = deprecated(),
...
)
Arguments
object |
PENSE regularization path to extract coefficients from. |
lambda |
a single number for the penalty level. |
alpha |
Either a single number or |
sparse |
should coefficients be returned as sparse or dense vectors? Defaults to the
sparsity setting in |
standardized |
return the standardized coefficients. |
exact , correction |
defunct. |
... |
currently not used. |
Value
either a numeric vector or a sparse vector of type
dsparseVector
of size p + 1
, depending on the sparse
argument.
Note: prior to version 2.0.0 sparse coefficients were returned as sparse matrix
of type dgCMatrix.
To get a sparse matrix as in previous versions, use sparse = 'matrix'
.
See Also
coef.pense_cvfit()
for extracting coefficients from a PENSE fit with
hyper-parameters chosen by cross-validation
Other functions for extracting components:
coef.pense_cvfit()
,
predict.pense_cvfit()
,
predict.pense_fit()
,
residuals.pense_cvfit()
,
residuals.pense_fit()
Examples
# Compute the PENSE regularization path for Freeny's revenue data
# (see ?freeny)
data(freeny)
x <- as.matrix(freeny[ , 2:5])
regpath <- pense(x, freeny$y, alpha = 0.5)
plot(regpath)
# Extract the coefficients at a certain penalization level
coef(regpath, lambda = regpath$lambda[[1]][[40]])
# What penalization level leads to good prediction performance?
set.seed(123)
cv_results <- pense_cv(x, freeny$y, alpha = 0.5,
cv_repl = 2, cv_k = 4)
plot(cv_results, se_mult = 1)
# Extract the coefficients at the penalization level with
# smallest prediction error ...
coef(cv_results)
# ... or at the penalization level with prediction error
# statistically indistinguishable from the minimum.
coef(cv_results, lambda = '1-se')