Skip to contents

Get the coefficients from a fitted ptLasso model.

Usage

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

Arguments

object

fitted "ptLasso" object.

model

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

...

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

Value

Model coefficients. If model = "overall", this function returns the output of coef. If model is "individual" or "pretrain", this function returns a list containing the results of coef for each group-specific model. If model = "all", this returns a list containing all (overall, individual and pretrain) coefficients.

See also

ptLasso.

Author

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

Examples

# Train data
out = gaussian.example.data()
x = out$x; y=out$y; groups = out$group;

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

coef(fit, model = "overall") # Overall model only
#> 125 x 1 sparse Matrix of class "dgCMatrix"
#>                      s1
#> (Intercept)  1.79300815
#> groups2     -4.77841749
#> groups3     -2.20745229
#> groups4     -1.29396505
#> groups5     -2.80081665
#>              7.03787622
#>              5.95742513
#>              6.93417474
#>              7.71212703
#>              5.83781201
#>              6.19147485
#>              6.35333791
#>              8.39876277
#>              6.86451762
#>              6.59835750
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              0.09713763
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              0.89219086
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
#>              .         
length(coef(fit, model = "individual")) # List of coefficients for each group model
#> [1] 5
length(coef(fit, model = "pretrain")) # List of coefficients for each group model
#> [1] 5