Skip to contents

Return the model coefficients of a ppLasso or gr_ppLasso object

Usage

# S3 method for class 'ppLasso'
coef(fit, lambda, which = 1:length(fit$lambda), drop = TRUE, ...)

# S3 method for class 'gr_ppLasso'
coef(fit, lambda, which = 1:length(fit$lambda), drop = TRUE, ...)

Arguments

fit

a ppLasso or gr_ppLasso object.

lambda

values of the regularization parameter lambda at which coefficients are requested. For values of lambda not in the sequence of fitted models, linear interpolation is used.

which

indices of the penalty parameter lambda at which predictions are required. By default, all indices are returned. If lambda is specified, this will override which.

drop

whether to keep coefficient names

...

Examples

#fit glm without grouped covariates
data(BinaryData)
data <- BinaryData$data
Y.char <- BinaryData$Y.char
prov.char <- BinaryData$prov.char
Z.char <- BinaryData$Z.char
fit <- pp.lasso(data, Y.char, Z.char, prov.char)
coef(fit, lambda = fit$lambda)$beta[, 1:10]
#>    0.132    0.1202    0.1096    0.0998     0.091    0.0829    0.0755    0.0688
#> Z1     0 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
#> Z2     0 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
#> Z3     0 0.1120347 0.2148847 0.3098777 0.3980465 0.4801436 0.5568409 0.6285796
#> Z4     0 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
#> Z5     0 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
#>       0.0627    0.0571
#> Z1 0.0000000 0.0000000
#> Z2 0.0000000 0.0000000
#> Z3 0.6957436 0.7586491
#> Z4 0.0000000 0.0000000
#> Z5 0.0000000 0.0000000
coef(fit, lambda = fit$lambda)$gamma[1:10, 1:5]
#>         0.132     0.1202     0.1096     0.0998      0.091
#> 1  -0.2411977 -0.2939898 -0.3431091 -0.3889330 -0.4318211
#> 2  -1.9635362 -1.8742433 -1.7984115 -1.7336457 -1.6779754
#> 3  -1.2089403 -1.1883078 -1.1712888 -1.1572109 -1.1455229
#> 4  -1.9600386 -1.8922127 -1.8332183 -1.7815619 -1.7360041
#> 5  -0.5500569 -0.5698456 -0.5894538 -0.6087582 -0.6276779
#> 6  -1.3694159 -1.2813234 -1.2034985 -1.1342974 -1.0723356
#> 7  -0.4661063 -0.4936788 -0.5199327 -0.5449261 -0.5687380
#> 8  -0.4274344 -0.4203383 -0.4151684 -0.4115749 -0.4092523
#> 9   1.0329137  0.8945008  0.7694552  0.6557870  0.5517900
#> 10 -0.9075577 -0.9146380 -0.9232143 -0.9328743 -0.9433025
#fit glm with grouped covariates
data(BinaryData)
data <- BinaryData$data
Y.char <- BinaryData$Y.char
prov.char <- BinaryData$prov.char
Z.char <- BinaryData$Z.char
group <- BinaryData$group
fit <- grp.lasso(data, Y.char, Z.char, prov.char, group = group)
coef(fit, lambda = fit$lambda)$beta[, 1:5]
#>    0.0939      0.0856       0.078        0.071      0.0647
#> Z1      0  0.00000000  0.00000000 -0.003334178 -0.05627111
#> Z2      0  0.00000000  0.00000000  0.003875496  0.06351446
#> Z3      0  0.11268128  0.21468084  0.307301593  0.38977908
#> Z4      0 -0.01162498 -0.01401619 -0.009610844 -0.00190843
#> Z5      0  0.00000000  0.00000000  0.000000000  0.00000000
coef(fit, lambda = fit$lambda)$gamma[1:10, 1:5]
#>        0.0939     0.0856      0.078      0.071     0.0647
#> 1  -0.2411731 -0.2890605 -0.3366646 -0.3843345 -0.4426426
#> 2  -1.9635866 -1.8817822 -1.8080178 -1.7414115 -1.6832827
#> 3  -1.2089543 -1.1907172 -1.1742371 -1.1589555 -1.1394428
#> 4  -1.9600775 -1.8990257 -1.8418545 -1.7882081 -1.7355165
#> 5  -0.5500497 -0.5681728 -0.5871905 -0.6066594 -0.6253165
#> 6  -1.3694650 -1.2892476 -1.2136979 -1.1425348 -1.0753747
#> 7  -0.4660951 -0.4915285 -0.5170385 -0.5424109 -0.5680985
#> 8  -0.4274407 -0.4200726 -0.4148432 -0.4114738 -0.4111511
#> 9   1.0329839  0.9085190  0.7875110  0.6698040  0.5477673
#> 10 -0.9075578 -0.9153895 -0.9239389 -0.9332905 -0.9470281