Skip to contents

Get the coefficients from a fitted cv.ptLasso model.

Usage

# S3 method for class 'cv.ptLasso'
coef(
  object,
  model = c("all", "individual", "overall", "pretrain"),
  alpha = NULL,
  ...
)

Arguments

object

fitted "cv.ptLasso" object.

model

string indicating which coefficients to retrieve. Must be one of "all", "individual", "overall" or "pretrain".

alpha

value between 0 and 1, indicating which alpha to use. If NULL, return coefficients from all models. Only impacts the results for model = "all" or model = "pretrain".

...

other arguments to be passed to the "coef" function. May be e.g. s = "lambda.min".

See also

cv.ptLasso, ptLasso.

Author

Erin Craig and Rob Tibshirani
Maintainer: Erin Craig <erincr@stanford.edu>

Examples

set.seed(1234)
out = gaussian.example.data()
x = out$x; y=out$y; groups = out$group;

cvfit = cv.ptLasso(x, y, groups = groups, family = "gaussian", type.measure = "mse")
# Get all model coefficients.
names(coef(cvfit))
#> [1] "individual" "pretrain"   "overall"   

coef(cvfit, model = "overall") # Overall model only
#> 125 x 1 sparse Matrix of class "dgCMatrix"
#>                       s1
#> (Intercept) -1.293077574
#> groups2     -0.802576770
#> groups3      4.688453083
#> groups4     -1.067174861
#> groups5     -0.173873523
#>              6.534854270
#>              6.813808490
#>              5.141281910
#>              7.160160979
#>              6.284458960
#>              6.739156736
#>              7.910505452
#>              6.294609076
#>              5.231380388
#>              7.437161907
#>              0.316816148
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              0.119524657
#>              .          
#>              0.002353154
#>              0.257401597
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              0.522864277
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>             -0.040566927
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
#>              .          
length(coef(cvfit, model = "individual")) # List of coefficients for each group model
#> [1] 5
length(coef(cvfit, model = "pretrain", alpha = .5)) # List of coefficients for each group model
#> [1] 5