cv.extlasso: k-fold cross validation for penalized generalized linear...

Description Usage Arguments Value Note Author(s) References Examples

View source: R/extlasso.R

Description

The function does k-fold cross validation for selecting best value of regularization parameter.

Usage

1
2
cv.extlasso(x,y,family=c("binomial","normal","poisson"),k=5, 
nlambda=50,tau=1,plot=TRUE, errorbars=TRUE)

Arguments

x

x is matrix of order n x p where n is number of observations and p is number of predictor variables. Rows should represent observations and columns should represent predictor variables.

y

y is a vector of response variable of order n x 1.

family

family is either "normal" or "binomial" or "poisson".

k

Number of folds for cross validation. Default is k=5.

nlambda

Number of lambda values to be used for cross validation. Default is nlambda=50.

tau

Elastic net parameter, 0 ≤ τ ≤ 1 in elastic net penalty λ\{τ\|β\|_1+(1-τ)\|beta\|_2^2\}. Default tau=1 corresponds to LASSO penalty.

plot

if TRUE, produces a plot of cross validated prediction mean squared errors/ deviances against lambda. Default is TRUE.

errorbars

If TRUE, error bars are drawn in the plot. Default is TRUE.

Value

Produces a plot and returns a list with following components:

lambda

Value of lambda for which average cross validation error is minimum

pmse

A vector of average cross validation errors for various lambda values

lambdas

A vector of lambda values used in cross validation

se

A vector containing standard errors of cross validation errors

Note

This function uses prediction means squared errors for normal family and deviance for binomial and poisson family.

Author(s)

B N Mandal and Jun Ma

References

Mandal, B.N. and Jun Ma, (2014). A Jacobi-Armijo Algorithm for LASSO and its Extensions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#normal family
x=matrix(rnorm(100*30),100,30)
y=rnorm(100)
cv.extlasso(x,y,family="normal",k=5)

#binomial family
x=matrix(rnorm(100*30),100,30)
y=sample(c(0,1),100,replace=TRUE)
cv.extlasso(x,y,family="binomial",k=5)

#poisson family
x=matrix(rnorm(100*30),100,30)
y=sample(c(1:5),100,replace=TRUE)
cv.extlasso(x,y,family="poisson",k=5)

Example output

$lambda
[1] 2.192353

$pmse
 [1] 1.075076 1.089407 1.094850 1.100255 1.100217 1.117072 1.156816 1.210805
 [9] 1.271434 1.331750 1.390445 1.447636 1.505660 1.560907 1.612057 1.661128
[17] 1.704262 1.742694 1.773844 1.801282 1.822828 1.841138 1.856222 1.868825
[25] 1.879394 1.888167 1.895018 1.900879 1.905577 1.909551 1.912798 1.915352
[33] 1.917580 1.919288 1.920735 1.921869 1.922774 1.923520 1.924219 1.924764
[41] 1.925217 1.925626 1.925962 1.926230 1.926456 1.926639 1.926809 1.926959
[49] 1.927074 1.927181

$lambdas
 [1] 2.1923525305 1.7951146127 1.4698532413 1.2035268030 0.9854567278
 [6] 0.8068993229 0.6606951872 0.5409821498 0.4429602214 0.3626991350
[11] 0.2969807584 0.2431700613 0.1991094609 0.1630323124 0.1334920741
[16] 0.1093043065 0.0894991818 0.0732825980 0.0600043381 0.0491319998
[21] 0.0402296481 0.0329403361 0.0269717930 0.0220847054 0.0180831216
[26] 0.0148065949 0.0121237504 0.0099270173 0.0081283159 0.0066555257
[31] 0.0054495941 0.0044621683 0.0036536567 0.0029916414 0.0024495783
[36] 0.0020057330 0.0016423091 0.0013447350 0.0011010790 0.0009015717
[41] 0.0007382137 0.0006044549 0.0004949321 0.0004052541 0.0003318251
[46] 0.0002717009 0.0002224707 0.0001821607 0.0001491545 0.0001221288

$se
 [1] 0.2534020 0.2546217 0.2552609 0.2527674 0.2493407 0.2485255 0.2533415
 [8] 0.2592216 0.2657587 0.2710802 0.2754079 0.2794381 0.2832225 0.2891710
[15] 0.3008906 0.3157030 0.3282771 0.3382210 0.3461105 0.3536624 0.3594032
[22] 0.3645159 0.3684256 0.3718075 0.3744955 0.3769439 0.3788603 0.3806230
[29] 0.3819927 0.3830964 0.3840675 0.3848045 0.3854252 0.3859202 0.3863603
[36] 0.3867040 0.3868784 0.3871136 0.3874058 0.3875789 0.3876387 0.3877619
[43] 0.3878391 0.3879475 0.3880146 0.3880534 0.3881202 0.3881644 0.3881996
[50] 0.3882380

$lambda
[1] 0.939153

$pmse
 [1] 27.95325 27.23583 27.33851 27.43345 27.79091 28.31634 28.95539 29.69649
 [9] 30.52246 31.48475 32.51133 33.63584 34.90076 36.23166 37.66346 39.06784
[17] 40.48169 41.85373 43.10911 44.31754 45.41492 46.42632 47.30936 48.14448
[25] 48.87217 49.51777 50.04537 50.49562 50.89522 51.24245 51.52449 51.76952
[33] 51.99626 52.21390 52.35885 52.48824 52.60424 52.68703 52.75740 52.81957
[41] 52.86716 52.91092 52.95966 52.98498 53.00743 53.02963 53.05268 53.06886
[49] 53.08012 53.09021

$lambdas
 [1] 1.1291102171 0.9391529722 0.7811534178 0.6497351126 0.5404261275
 [6] 0.4495068738 0.3738835325 0.3109827769 0.2586642073 0.2151475165
[11] 0.1789519097 0.1488457152 0.1238044734 0.1029760757 0.0856517690
[16] 0.0712420384 0.0592565465 0.0492874486 0.0409955141 0.0340985834
[21] 0.0283619663 0.0235904561 0.0196216867 0.0163206081 0.0135748906
[26] 0.0112911022 0.0093915297 0.0078115342 0.0064973511 0.0054042613
[31] 0.0044950687 0.0037388353 0.0031098278 0.0025866421 0.0021514752
[36] 0.0017895191 0.0014884572 0.0012380447 0.0010297608 0.0008565177
[41] 0.0007124204 0.0005925655 0.0004928745 0.0004099551 0.0003409858
[46] 0.0002836197 0.0002359046 0.0001962169 0.0001632061 0.0001357489

$se
 [1] 0.3874844 0.7285742 0.9870201 1.0233997 1.0998729 1.2871376 1.5082443
 [8] 1.7658164 2.0365665 2.2032926 2.3204457 2.4618909 2.7325123 3.0612217
[15] 3.4442459 3.8454200 4.2864411 4.7145502 5.0765594 5.4429116 5.7642633
[22] 6.0494911 6.2967352 6.5352134 6.7429724 6.9225388 7.0708417 7.2186420
[29] 7.3474869 7.4573475 7.5422687 7.6184452 7.6792746 7.7409119 7.7888564
[36] 7.8290997 7.8673821 7.8895185 7.9115412 7.9282094 7.9469021 7.9589307
[43] 7.9764051 7.9846005 7.9917411 7.9975945 8.0051649 8.0113552 8.0146331
[50] 8.0173885

There were 23 warnings (use warnings() to see them)
$lambda
[1] 2.091832

$pmse
 [1] 36.77728 14.88419 14.50630 14.83673 15.15241 15.62520 16.31173 17.08256
 [9] 17.92446 18.83174 19.78206 20.68625 21.59402 22.51651 23.41476 24.29831
[17] 25.04178 25.71733 26.29098 26.78725 27.20785 27.57071 27.87459 28.13735
[25] 28.35924 28.55021 28.72213 28.85682 28.96431 29.06441 29.14735 29.20986
[33] 29.27111 29.32152 29.36022 29.40202 29.42940 29.45316 29.47060 29.48751
[41] 29.50427 29.51506 29.52466 29.53360 29.54025 29.54706 29.55299 29.55761
[49] 29.56091 29.56431

$lambdas
 [1] 3.0236165278 2.5149346855 2.0918315581 1.7399097053 1.4471938579
 [6] 1.2037234207 1.0012135318 0.8327731429 0.6926705298 0.5761382520
[11] 0.4792109252 0.3985902863 0.3315329596 0.2757571047 0.2293647693
[16] 0.1907773055 0.1586816511 0.1319856485 0.1097808807 0.0913117594
[21] 0.0759498133 0.0631723031 0.0525444331 0.0437045558 0.0363518662
[26] 0.0302361653 0.0251493469 0.0209183156 0.0173990971 0.0144719386
[31] 0.0120372342 0.0100121353 0.0083277314 0.0069267053 0.0057613825
[36] 0.0047921093 0.0039859029 0.0033153296 0.0027575710 0.0022936477
[41] 0.0019077731 0.0015868165 0.0013198565 0.0010978088 0.0009131176
[46] 0.0007594981 0.0006317230 0.0005254443 0.0004370456 0.0003635187

$se
 [1] 10.8181168  1.0845065  0.8460079  0.7836823  0.7565716  0.7695408
 [7]  0.7924959  0.8582993  0.9902366  1.1418970  1.2965332  1.4448945
[13]  1.5875970  1.7218778  1.8432112  2.0081959  2.1417881  2.2714402
[19]  2.3836386  2.4856436  2.5742858  2.6505187  2.7161164  2.7703064
[25]  2.8176375  2.8612029  2.8978712  2.9239015  2.9460454  2.9670033
[31]  2.9871563  2.9992885  3.0159096  3.0275479  3.0379667  3.0494664
[37]  3.0561946  3.0616439  3.0653935  3.0700100  3.0743182  3.0773644
[43]  3.0793727  3.0812266  3.0829802  3.0846834  3.0862297  3.0873398
[49]  3.0881897  3.0890851

There were 33 warnings (use warnings() to see them)

extlasso documentation built on May 2, 2019, 11:39 a.m.