-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlassologit.ihlp
1314 lines (1110 loc) · 42.9 KB
/
lassologit.ihlp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{smcl}
{* *! version 4oct2019}{...}
{hline}
{cmd:help lassologit}{right: lassopack v1.4.3}
{cmd:help rlassologit}
{cmd:help cvlassologit}
{hline}
{title:Title}
{p2colset 5 19 21 2}{...}
{p2col:{hi: lassologit} {hline 2}}Main program for regularized logistic regression{p_end}
{p2colreset}{...}
{p2colset 5 21 23 2}{...}
{p2col:{hi: cvlassologit} {hline 2}}Program for {it:K}-fold cross-validation with logistic regression{p_end}
{p2colreset}{...}
{p2colset 5 20 22 2}{...}
{p2col:{hi: rlassologit} {hline 2}}Program for regularized logistic regression with rigorous penalization{p_end}
{p2colreset}{...}
{marker syntax}{...}
{title:Syntax}
{p 4} {ul:Full syntax}
{p 8 14 2}
{cmd:lassologit}
{it:depvar} {it:regressors}
[{cmd:if} {it:exp}] [{cmd:in} {it:range}]
{bind:[{cmd:,}} {cmdab:postl:ogit}
{cmdab:nocon:stant}
{cmdab:l:ambda}{cmd:(}{it:numlist}{cmd:)}
{cmdab:lc:ount}{cmd:(}{it:integer}{cmd:)}
{cmdab:lminr:atio}{cmd:(}{it:real}{cmd:)}
{cmdab:lmax:}{cmd:(}{it:real}{cmd:)}
{opt lambdan}
{cmd:lic}{cmd:(}{it:string}{cmd:)}
{cmdab:ebicx:i}{cmd:(}{it:real}{cmd:)}
{cmdab:postres:ults}
{cmdab:notp:en(}{it:varlist}{cmd:)}
{opt spsi(matrix)}
{cmd:nostd}
{cmd:stdcoef}
{opt holdout(varname)}
{cmdab:lossm:easure}{cmd:(}{it:string}{cmd:)}
{cmdab:tolo:pt}{cmd:(}{it:real}{cmd:)}
{cmdab:tolz:ero}{cmd:(}{it:real}{cmd:)}
{cmdab:maxi:ter}{cmd:(}{it:int}{cmd:)}
{cmdab:quadp:rec}
{cmdab:noseqr:ule}
{cmdab:plot:path}{cmd:(}{it:method}{cmd:)}
{cmdab:plotv:ar}{cmd:(}{it:varlist}{cmd:)}
{cmdab:ploto:pt}{cmd:(}{it:string}{cmd:)}
{cmdab:plotl:abel}
{opt long}
{cmdab:verb:ose}
{cmd:ic}{cmd:(}{it:string}{cmd:)}
{bind:{cmdab:nopro:gressbar}]}
{p 8 14 2}
{cmd:cvlassologit}
{it:depvar} {it:regressors}
[{cmd:if} {it:exp}] [{cmd:in} {it:range}]
{bind:[{cmd:,}}
{cmdab:postl:ogit}
{cmdab:nocon:stant}
{cmdab:l:ambda}{cmd:(}{it:numlist}{cmd:)}
{cmdab:lc:ount}{cmd:(}{it:integer}{cmd:)}
{cmdab:lminr:atio}{cmd:(}{it:real}{cmd:)}
{cmdab:lmax:}{cmd:(}{it:real}{cmd:)}
{opt lambdan}
{cmd:lopt}
{cmd:lse}
{cmdab:postres:ults}
{cmdab:notp:en(}{it:varlist}{cmd:)}
{opt spsi(matrix)}
{cmd:nostd}
{cmdab:tolo:pt}{cmd:(}{it:real}{cmd:)}
{cmdab:tolz:ero}{cmd:(}{it:real}{cmd:)}
{cmdab:maxi:ter}{cmd:(}{it:int}{cmd:)}
{cmdab:quadp:rec}
{cmdab:noseqr:ule}
{cmdab:nf:olds}{cmd:(}{it:integer}{cmd:)}
{cmdab:foldv:ar}{cmd:(}{it:varname}{cmd:)}
{cmdab:savefoldv:ar}{cmd:(}{it:new varname}{cmd:)}
{cmd:seed}{cmd:(}{it:integer}{cmd:)}
{cmdab:strat:ified}
{opt storeest(string)}
{cmdab:lossm:easure}{cmd:(}{it:string}{cmd:)}
{cmd:plotcv}
{cmdab:ploto:pt}{cmd:(}{it:string}{cmd:)}
{opt long}
{cmdab:verb:ose}
{bind:{cmd:tabfold}]}
{p 8 14 2}
{cmd:rlassologit}
{it:depvar} {it:regressors}
[{cmd:if} {it:exp}] [{cmd:in} {it:range}]
{bind:[{cmd:,}}
{cmdab:postl:ogit}
{cmdab:nocon:stant}
{opt gamma(real)}
{opt c(real)}
{opt holdout(varname)}
{cmdab:lossm:easure}{cmd:(}{it:string}{cmd:)}
{cmdab:tolo:pt}{cmd:(}{it:real}{cmd:)}
{cmdab:tolz:ero}{cmd:(}{it:real}{cmd:)}
{cmdab:maxi:ter}{cmd:(}{it:int}{cmd:)}
{cmdab:quadp:rec}
{cmdab:noseqr:ule}
{bind:{cmdab:verb:ose}]}
{p 4} {ul:Options}
{synoptset 20}{...}
{synopthdr:Estimators}
{synoptline}
{synopt:{cmdab:postl:ogit}}
use post-estimation logit.
{cmd:lassologit}: If lambda is a list,
post-estimation OLS results are displayed and returned in {cmd:e(betas)}.
If lambda is a scalar (or {cmd:rlassologit} is used),
post-estimation OLS is always displayed,
and this option controls whether standard or post-estimation
OLS results are stored in {cmd:e(b)}.
{cmd:cvlassologit}: post-estimation logit
is used for cross-validation.
{p_end}
{synopt:{cmdab:nocon:stant}}
suppress constant from estimation (not recommended).
{p_end}
{synoptline}
{p2colreset}{...}
{pstd}
{synoptset 20}{...}
{synopthdr:Lambda(s)}
{synoptline}
{synopt:{cmdab:l:ambda}{cmd:(}{it:numlist}{cmd:)}}
a scalar lambda value or list of descending lambda values. Each lambda value must be greater than 0.
If not specified, the default list is used which is given by {cmd:exp(rangen(log(lmax),log(lminratio*lmax),lcount))} (see {helpb mf_range}).
{p_end}
{synopt:{cmdab:lc:ount}{cmd:(}{it:integer}{cmd:)}†}
number of lambda values for which the solution is obtained. Default is 50.
{p_end}
{synopt:{cmdab:lminr:atio}{cmd:(}{it:real}{cmd:)}†}
ratio of minimum to maximum lambda. {cmd:lminratio} must be between 0 and 1. Default is 1/1000.
{p_end}
{synopt:{cmdab:lmax:}{cmd:(}{it:real}{cmd:)}†}
maximum lambda value.
{p_end}
{synopt:{cmd:lambdan}}
uses {it:lambda}:={it:lambda}/{it:N} in the objective function.
This makes {it:lambda} comparable with {it:glmnet}
(Friedman, Hastie & Tibshirani, {helpb lassologit##Friedman2010:2010}).
{p_end}
{synopt:{cmd:lic}{cmd:(}{it:string}{cmd:)}}
{cmd:lassologit}: after first {cmd:lassologit} estimation using list of lambdas, estimate model corresponding to minimum information criterion.
'aic', 'bic', 'aicc', and 'ebic' (the default) are allowed.
Note the lower case spelling.
See {help lassologit##informationcriteria:Information criteria} for the definition of each information criterion.
{p_end}
{synopt:{cmdab:ebicx:i}{cmd:(}{it:real}{cmd:)}}
{cmd:lassologit}: controls the {it:xi} parameter of the EBIC.
{it:xi} needs to lie in the [0,1] interval.
{it:xi}=0 is equivalent to the BIC.
The default choice is {it:xi}=1-log(n)/(2*log(p)).
{p_end}
{synopt:{cmd:lopt}}
{cmd:cvlassologit}: after cross-validation, estimate model with lambda that minimized the mean-squared prediction error
{p_end}
{synopt:{cmd:lse}}
{cmd:cvlassologit}: after cross-validation, estimate model with largest lambda that is within one standard deviation from lopt
{p_end}
{synopt:{cmdab:postres:ults}} Used in combination with {cmd:lic()},
{cmd:lse} or {cmd:lopt}.
Stores estimation results of the model selected by information criterion in {cmd:e()}.
{p_end}
{synoptline}
{p2colreset}{...}
{pstd}
The above options are only applicable for {cmd:lassologit} and {cmd:cvlassologit}.
† Not applicable if {cmdab:l:ambda}{cmd:(}{it:numlist}{cmd:)} is specified.
{synoptset 20}{...}
{synopthdr:Rigorous lambda}
{synoptline}
{synopt:{opt gamma(real)}}
specifies the significance level {it:gamma}
for the rigorous lambda. The default is 0.05/max((p*log(n),n)).
{p_end}
{synopt:{opt c(real)}}
specified slack parameter {it:c} for
the rigorous lambda (default = 1.1)
{p_end}
{synoptline}
{p2colreset}{...}
{pstd}
The above options are only applicable for {cmd:rlassologit}.
{synoptset 20}{...}
{synopthdr:Loadings & standardization}
{synoptline}
{synopt:{cmdab:notp:en(}{it:varlist}{cmd:)}}
sets penalty loadings to zero for predictors in {it:varlist}. Unpenalized predictors are always included in the model.
{p_end}
{synopt:{opt spsi(matrix)}}
a row-vector of penalty loadings
(in standard units);
overrides the default which is a vector of ones.
The size of the vector should equal the number of predictors
(excluding partialled
out variables and excluding the constant).
{p_end}
{synopt:{cmd:nostd}}
do not standardize the predictors. Default is to
standardize predictors to have unit variance.
{p_end}
{synopt:{cmd:stdcoef}}
return coefficient estimates in standardized units.
Default is to return coefficients in original units.
{p_end}
{synoptline}
{p2colreset}{...}
{pstd}
{synoptset 20}{...}
{synopthdr:Optimization}
{synoptline}
{synopt:{cmdab:tolo:pt}{cmd:(}{it:real}{cmd:)}}
tolerance for lasso shooting algorithm (default=1e-10)
{p_end}
{synopt:{cmdab:tolz:ero}{cmd:(}{it:real}{cmd:)}}
minimum below which coeffs are rounded down to zero (default=1e-4)
{p_end}
{synopt:{cmdab:maxi:ter}{cmd:(}{it:int}{cmd:)}}
maximum number of iterations for the lasso shooting algorithm (default=10,000)
{p_end}
{synopt:{cmdab:quadp:rec}}
use {helpb mf_quadcross} instead of {helpb mf_cross}
in the shooting algorithm. This will slow down
the program (considerably)
but lead to
(in our experience minor)
gains in precision.
This will also disable the sequential strong rule,
see next.
{p_end}
{synopt:{cmdab:noseqr:ule}}
disables use of sequential strong rule, which discards
some predictors before running the shooting algorithm
(see Section 5 in
Tibshirani et al., {helpb lassologit##Tib2012:2012}).
The sequential rule leads to speed gains.
NB: sequential rule is automatically disabled if intercept is
omitted.
{p_end}
{synoptline}
{p2colreset}{...}
{synoptset 20}{...}
{synopthdr:Cross-validation}
{synoptline}
{synopt:{cmd:nfolds(}{it:integer}{cmd:)}}
the number of folds used for {it:K}-fold cross-validation. Default is 5.
{p_end}
{synopt:{cmd:foldvar(}{it:varname}{cmd:)}}
user-specified variable with fold IDs, ranging from 1 to #folds.
If not specified, fold IDs are randomly generated such that each fold is of approximately equal size.
{p_end}
{synopt:{cmd:savefoldvar(}{it:varname}{cmd:)}}
saves the fold ID variable.
{p_end}
{synopt:{cmd:seed(}{it:real}{cmd:)}}
set seed for the generation of a random fold variable. Only relevant if fold variable is randomly generated.
{p_end}
{synopt:{cmdab:strat:ified}}
observations are divided into folds
such that number of successes / failures is
approximately the same across folds.
Recommended especially if share of
successes is close to 0 or 1.
{p_end}
{synopt:{cmd:storeest(}{it:string}{cmd:)}}
saves {cmd:lassologit} results from each step of the cross-validation in {it:string1},
..., {it:stringK} where {it:K} is the number of folds. Intermediate results can
be restored using {helpb estimates restore}.
{p_end}
{synopt:{cmd:holdout(}{it:varname}{cmd:)}}
defines a holdout sample. {cmd:lassologit} and
{cmd:rlassologit} only.
{it:varname} should be a binary variable where 1 indicates
that observations are excluded from the estimation.
Estimated loss is returned in {cmd:e(loss)}.
{p_end}
{synopt:{cmdab:lossm:easure(}{it:string}{cmd:)}}
loss measure used for cross-validation
or for the holdout sample.
"deviance" and "class" (miss-classification error)
are supported. Deviance is the default.
{p_end}
{synoptline}
{p2colreset}{...}
{pstd}
Only applicable for {cmd:cvlassologit}.
{marker plottingopts}{...}
{synoptset 20}{...}
{synopthdr:Plotting {cmd:lassologit}}
{synoptline}
{synopt:{cmdab:plot:path(}{it:method}{cmd:)}}
plots the coefficients path as a function of the L1-norm ({it:norm}), lambda ({it:lambda})
or the log of lambda ({it:lnlambda})
{p_end}
{synopt:{cmdab:plotv:ar(}{it:varlist}{cmd:)}}
list of variables to be included in the plot
{p_end}
{synopt:{cmdab:ploto:pt(}{it:string}{cmd:)}}
additional plotting options passed on to {helpb line}.
For example, use {cmd:plotopt(legend(off))} to turn off the legend.
{p_end}
{synopt:{cmdab:plotl:abel}}
displays variable labels in graph.
{p_end}
{synoptline}
{p2colreset}{...}
{pstd}
{it:Note:} Plotting with {cmd:lassologit} is not
available if lambda is a scalar value.
{marker plottingopts}{...}
{synoptset 20}{...}
{synopthdr:Plotting {cmd:cvlassologit}}
{synoptline}
{synopt:{cmd:plotcv}}
plots the coefficients path as a function of the L1-norm ({it:norm}), lambda ({it:lambda})
or the log of lambda ({it:lnlambda})
{p_end}
{synopt:{cmdab:ploto:pt(}{it:string}{cmd:)}}
additional plotting options passed on to {helpb line}.
For example, use {cmd:plotopt(legend(off))} to turn off the legend.
{p_end}
{synoptline}
{p2colreset}{...}
{pstd}
{synoptset 20}{...}
{synopthdr:Display options}
{synoptline}
{synopt:{opt long}†}
show long output,
applicable for {cmd:lassologit}
and {cmd:cvlassologit}.
{p_end}
{synopt:{opt ver:bose}}
show additional output
{p_end}
{synopt:{cmd:tabfold}}
{cmd:cvlassologit}: show frequency
table of fold variable
{p_end}
{synopt:{cmd:ic}{cmd:(}{it:string}{cmd:)}†}
controls which information criterion is shown in the output.
'aic', 'bic', 'aicc', and 'ebic' (the default' are allowed).
Note the lower case spelling.
See {help lassologit##informationcriteria:Information criteria}
for the definition of each information criterion.
{p_end}
{synopt:{cmdab:nopro:gressbar}}
{cmd:lassologit}: do not show progressbar
{p_end}
{synoptline}
{p2colreset}{...}
{pstd}
{p 4} {ul:Replay syntax}
{pstd}
{cmd:lassologit} and {cmd:cvlassologit} support replay syntay.
The replay syntax can be used to
retrieve estimation results for the models selected by information
criteria (using the {opt lic()}) option or
the model selected by cross-validation (using
{opt lse} or {opt lopt}).
{p 8 14 2}
{cmd:lassologit}
{bind:[{cmd:,}}
{cmdab:plot:path}{cmd:(}{it:method}{cmd:)}
{cmdab:plotv:ar}{cmd:(}{it:varlist}{cmd:)}
{cmdab:ploto:pt}{cmd:(}{it:string}{cmd:)}
{cmdab:plotl:abel}
{opt long}
{cmdab:postres:ults}
{cmd:lic}{cmd:(}{it:string}{cmd:)}
{bind:{cmd:ic}{cmd:(}{it:string}{cmd:)}]}
{p 8 14 2}
{cmd:cvlassologit}
{bind:[{cmd:,}}
{cmdab:plot:path}{cmd:(}{it:method}{cmd:)}
{cmdab:plotv:ar}{cmd:(}{it:varlist}{cmd:)}
{cmdab:ploto:pt}{cmd:(}{it:string}{cmd:)}
{cmdab:plotl:abel}
{opt long}
{cmdab:postres:ults}
{cmd:lic}{cmd:(}{it:string}{cmd:)}
{bind:{cmd:ic}{cmd:(}{it:string}{cmd:)}]}
{p 4} {ul:Prediction}
{p 8 14 2}
{cmd:predict} {dtype} {newvar} {ifin} [{cmd:,}
{cmd:xb}
{cmdab:p:r}
{cmdab:c:lass}
{cmd:est}
{cmdab:postl:ogit}
{cmd:lse}
{cmd:lopt}
{opt lic(string)}
{bind:{cmdab:noi:sily}}
{synoptset 20}{...}
{synopthdr:Predict options}
{synoptline}
{synopt:{cmd:xb}}
compute predicted values (the default)
{p_end}
{synopt:{cmdab:p:r}}
predicted probabilities
{p_end}
{synopt:{cmdab:c:lass}}
predicted class (either 1 or 0)
{p_end}
{synopt:{cmd:est}}
re-estimate model with chosen lambda; used in combination with {cmdab:postl:ogit}
from {cmd:e(betas)} or {cmd:e(b)}
{p_end}
{synopt:{cmdab:postl:ogit}}
use post-logit (default is to use coefficients stored in {cmd:e(betas)} or {cmd:e(b)})
{p_end}
{synopt:{cmd:lic}{cmd:(}{it:string}{cmd:)}}
after {cmd:lassologit}: selects which information criterion to use for prediction.
{p_end}
{synopt:{cmd:lopt}}
after {cmd:cvlassologit}: use lambda that minimizes
the mean-squared prediction error
{p_end}
{synopt:{cmd:lse}}
after {cmd:cvlassologit}: use
largest lambda that is within one standard deviation
from lopt
{p_end}
{synopt:{cmdab:noi:sily}}
show estimation output if re-estimation required
{p_end}
{synoptline}
{p2colreset}{...}
{pstd}
{p 4} {ul:Notes}
{pstd}
All varlists may contain time-series operators or factor variables; see {stata "help varlist"}.
{title:Contents}
{phang}{help lassologit##description:Description}{p_end}
{phang}{help lassologit##coordinate:Coordinate descent algorithm}{p_end}
{phang}{help lassologit##penalization:Penalization level}{p_end}
{phang}{help lassologit##crossvalidation:Cross-validation}{p_end}
{phang}{help lassologit##informationcriteria:Information criteria}{p_end}
{phang}{help lassologit##rigorous:Rigorous penalization}{p_end}
{phang}{help lassologit##technical:Technical notes}{p_end}
{phang}{help lassologit##example:Example using Spam data}{p_end}
{phang}{help lassologit##example_data:--Data set}{p_end}
{phang}{help lassologit##example_intro:--Introduction}{p_end}
{phang}{help lassologit##example_information:--Information criteria}{p_end}
{phang}{help lassologit##example_cv:--Cross-validation}{p_end}
{phang}{help lassologit##example_rigorous:--Rigorous penalization}{p_end}
{phang}{help lassologit##example_prediction:--Prediction}{p_end}
{phang}{help lassologit##example_holdout:--Holdout option}{p_end}
{phang}{help lassologit##example_plot_lassologit:--Plotting with lassologit}{p_end}
{phang}{help lassologit##example_plot_cvlassologit:--Plotting with cvlassologit}{p_end}
{phang}{help lassologit##saved_results:Saved results}{p_end}
{phang}{help lassologit##references:References}{p_end}
{phang}{help lassologit##website:Website}{p_end}
{phang}{help lassologit##installation:Installation}{p_end}
{phang}{help lassologit##acknowledgements:Acknowledgements}{p_end}
{phang}{help lassologit##citation:Citation of lassologit}{p_end}
{marker description}{...}
{title:Description}
{pstd}
{opt lassologit} implements logistic lasso regression.
The logistic lasso maximizes the penalized log likelihood:
max 1/N sum_i { y(i) * log p(x(i)) + (1-y(i)) * log(1-p(x(i))) }
- lambda * ||Psi*beta||[1],
{pstd}
where
{synoptset 8}{...}
{synopt:y(i)}
is a binary response that is either 1 or 0,
{p_end}
{synopt:beta}
is a {it:p}-dimensional parameter vector,
{p_end}
{synopt:x(i)}
is a {it:p}-dimensional vector of predictors for observation i,
{p_end}
{synopt:p(x(i))}
is the probability that y(i) takes the value 1 given x(i); p(x(i)) = exp(x(i)'beta) / (1 + exp(x(i)'beta)),
{p_end}
{synopt:lambda}
is the overall penalty level,
{p_end}
{synopt:||.||[1]}
denotes the L(1) vector norm,
{p_end}
{synopt:Psi}
is a {it:p} by {it:p} diagonal matrix of predictor-specific penalty loadings. Note that {cmd:lassologit}
treats Psi as a row vector.
{p_end}
{synopt:N}
number of observations
{p_end}
{p2colreset}{...}
{pstd}
{cmd:lassologit} uses coordinate descent algorithms
for logistic lasso as described in
{helpb lassologit##Friedman2010:Friedman 2010}, Section 3.
{marker penalization}{...}
{title:Penalization level: choice of lambda}
{pstd}
Penalized regression methods
rely on tuning parameters that control the degree and type of penalization.
Logistic lasso relies on the tuning parameter {it:lambda}
which determines the level penalization.
We offer three approaches for selecting the "optimal" lambda value
implemented in {cmd:lassologit}, {cmd:cvlassologit}
and {cmd:rlassologit}:
{pstd}
(1) The penalty level may be chosen by cross-validation in order to optimize
out-of-sample prediction performance.
{it:K}-fold cross-validation is implemented in {cmd:cvlassologit}.
{pstd}
(2) Theoretically justified and feasible penalty levels and loadings are available for the
logistic lasso via {cmd:rlassologit}.
{pstd}
(3) Lambda can also be selected using information criteria.
{cmd:lassologit} calculates four information criteria:
Akaike Information Criterion (AIC; Akaike, {helpb lassologit##Akaike1974:1974}),
Bayesian Information Criterion (BIC; Schwarz, {helpb lassologit##Schwarz1978:1978}),
Extended Bayesian information criterion (EBIC; Chen & Chen, {helpb lassologit##Chen2008:2008})
and the corrected AIC (AICc; Sugiura, {helpb lassologit##Sugiura1978:1978},
and Hurvich, {helpb lassologit##Hurvich1989:1989}).
{marker crossvalidation}{...}
{title:K-fold cross-validation}
{pstd}
{cmd:cvlassologit} implements {it:K}-fold cross-validation.
The purpose of cross-validation is to assess the out-of-sample
prediction (classification) performance.
{pstd}
{ul:Cross-validation procedure}
{pstd}
{it:K}-fold cross-validation divides the data randomly
(or based on the user-specified {opt foldvar(varname)}
into {it:K} folds, i.e., data partitions of approximately
equal size. In each step, one fold is left out of the estimation
(training) sample and used for validation.
The prediction (classification) performance
is assessed based on loss measures.
{cmd:cvlassologit} offers two loss measures:
deviance and miss-classification error (defined below).
For more information, see {helpb cvlasso} (for the linear case).
{pstd}
{ul:Stratified cross-validation}
{pstd}
Simple {it:K}-fold cross-validation might fail
with randomly generated folds,
or produce misleading results,
if the share of successes (y=1) or
failures (y=0) is low. The {cmdab:strat:ified}
option ensures that the number of success/failures
is approximately the same across folds.
The {opt tabfold} option can be useful in this context;
it asks {cmd:cvlassologit} to show the
frequency distribution of successes/failures
across folds.
{pstd}
{ul:Loss measures}
{pstd}
The prediction performance is assessed
based on two loss measures:
deviance and miss-classification.
Deviance is the default and is defined as:
Deviance = -2 * {y0 :* log(p0) :+ (1:-y0):*log(1:-p0)}
{pstd}
where y0 is the response in the validation data
and p0 are the predicted probabilities.
{pstd}
The missclassification error is the average number
of wrongly classified cases, and can
be specified using {opt lossmeasure(class)}.
{marker informationcriteria}{...}
{title:Information criteria}
{pstd}
The information criteria supported by {cmd:lassologit} are
the Akaike information criterion (AIC, Akaike, {helpb lassologit##Akaike1974:1974}),
the Bayesian information criterion (BIC, Schwarz, {helpb lassologit##Schwarz1978:1978}),
the corrected AIC (Sugiura, {helpb lassologit##Sugiura1978:1978}; Hurvich, {helpb lassologit##Hurvich1989:1989}),
and the Extended BIC (Chen & Chen, {helpb lassologit##Chen2008:2008}).
These are given by (omitting dependence on lambda and alpha):
AIC = -2*LL + 2*{it:df}
BIC = -2*LL + {it:df}*log(N)
AICc = AIC + (2*{it:df}({it:df}+1))/(N-{it:df}-1)
EBIC = BIC + 2*{it:xi}*{it:df}*log(p)
{pstd}
where LL is the log-likelihood
and {it:df}(lambda,alpha) is the effective degrees of freedom,
which is a measure of model complexity.
{it:df} is approximated by the number of predictors selected.
{pstd}
By default, {cmd:lassologit} displays EBIC in the output,
but all four information criteria are stored in {cmd:e(aic)}, {cmd:e(bic)}, {cmd:e(ebic)} and {cmd:e(aicc)}.
See help file of {helpb lasso2} for more information.
{marker rigorous}{...}
{title:Rigorous penalization}
{pstd}
The theory-driven ("rigorous") penalty level
used by {cmd:rlassologit} is:
lambda = {it:c}/2 sqrt({it:N}) Phi^(-1)(1-{it:gamma})
{pstd}
where {it:c} is a slack parameter (default = 1.1),
Phi(.) is the standard normal CDF and
{it:gamma} is the significance level.
The default for {it:gamma} is 0.05/max((p*log(n),n)).
The approach requires the predictors to be standardized such that mean(x(i)^2)=1.
The penalty level is motivated by self-normalized moderate deviation theory,
and is aimed at overruling the noise associated with the data-generating process.
See Belloni, Chernozhukov & Wei ({helpb lassologit##Belloni2016:2016}).
{marker technical}{...}
{title:Technical notes}
{pstd}
{ul:Standardization}
{pstd}
{opt lassologit} centers and standardizes the predictors before estimation.
The coefficient estimates are returned in original scale. If the
{cmd:stdcoef} option is used, coefficients are returned in standardized units.
{opt nostd} can be used to estimate with predictors in original scale.
{pstd}
{ul:Constant}
{pstd}
The constant is not penalized by default.
Thus, the constant is always included
in the model.
To omit the constant,
use {cmdab:nocons:tant} (not recommended).
{marker example}{...}
{title:Example using Spam data}
{marker example_data}{...}
{pstd}
{ul:Data set}
{pstd}
For demonstration we consider the Spambase Data Set
from the Machine Learning Repository.
The data includes 4,601 observations and 57 variables.
The aim is to predict whether an email is spam
(i.e., unsolicited commercial e-mail) or not.
Each observation corresponds to one email.
{synoptset 10 tabbed}{...}
{p2col 5 19 23 2: Predictors}{p_end}
{synopt:v1-v48}percentage of words in the e-mail that match a specific {it:word},
i.e. 100 * (number of times the word appears in the e-mail) divided by
total number of words in e-mail.
To see which word each predictor corresponds to, see link below. {p_end}
{synopt:v49-v54}percentage of characters in the e-mail that match a specific {it:character},
i.e. 100 * (number of times the character appears in the e-mail) divided by
total number of characters in e-mail.
To see which character each predictor corresponds to, see link below.{p_end}
{synopt:v55}average length of uninterrupted sequences of capital letters{p_end}
{synopt:v56}length of longest uninterrupted sequence of capital letters{p_end}
{synopt:v57}total number of capital letters in the e-mail{p_end}
{synoptset 10 tabbed}{...}
{p2col 5 19 23 2: Outcome}{p_end}
{synopt:v58}denotes whether the e-mail was considered spam (1)
or not (0). {p_end}
{pstd}
For more information
about the data
see {browse "https://archive.ics.uci.edu/ml/datasets/spambase"}.
{pstd}Load spam data.{p_end}
{phang2}. {stata "insheet using https://archive.ics.uci.edu/ml/machine-learning-databases/spambase/spambase.data, clear comma"}{p_end}
{marker example_intro}{...}
{pstd}
{ul:Introduction to {cmd:lassologit}}
{pstd}
The basic syntax for {cmd:lassologit} is to specify the dependent variable
followed by a list of predictors:
{phang2}. {stata "lassologit v58 v1-v57"}{p_end}
{pstd}
The output of {cmd:lassologit} shows the penalty levels (lambda),
the number of predictors included (s), the L1-Norm, one information criterion
(EBIC by default), McFadden's Pseudo-R-squared and which predictors
are included/removed from the model.
{pstd}
By default, one line per knot is shown. Knots are points at which
predictors enter or leave the model. By specifying {opt long}, an
extended output with one row for each lambda is shown.
{phang2}. {stata "lassologit, long"}{p_end}
{pstd}
To obtain the logistic lasso estimate for a scalar lambda or a list
of lambdas, the {opt lambda(numlist)} option can be used.
For example:
{phang2}. {stata "lassologit v58 v1-v57, lambda(40 20)"}{p_end}
{phang2}. {stata "ereturn list"}{p_end}
{pstd}
And for one lambda:
{phang2}. {stata "lassologit v58 v1-v57, lambda(40)"}{p_end}
{phang2}. {stata "ereturn list"}{p_end}
{pstd}
Note that output and the objects stored in {opt e()}
depend on whether lambda is only one value or a list of more than one value.
{marker example_information}{...}
{pstd}
{ul:Information criteria}
{pstd}
To estimate the model selected by one of the information criteria,
use the {cmd:lic()} option:
{phang2}. {stata "lassologit v58 v1-v57"}{p_end}
{phang2}. {stata "lassologit, lic(ebic)"}{p_end}
{phang2}. {stata "lassologit, lic(aicc)"}{p_end}
{pstd}
In the above example, we use the replay syntax that works
similar to a post-estimation command.
The same can also be achieved in one line:
{phang2}. {stata "lassologit v58 v1-v57, lic(ebic)"}{p_end}
{pstd}
When {cmd:lic()} is used,
{cmd:lassologit} reports the logistic lasso estimates
and the post-logit estimates (from applying logit estimation to
the model selected by the logitistic lasso)
for the value of lambda selected by the specified
information criterion.
{pstd}
Note that {cmd:lic()} does not change the estimation
results in memory. The advantage is that this way
{cmd:lic()} can be used multiple times to compare
results without that we need to re-estimate the model.
{pstd}
To store the model selected by one of the information
criteria, use {cmdab:postres:ults}:
{phang2}. {stata "lassologit, lic(ebic) postresults"}{p_end}
{marker example_cv}{...}
{pstd}
{ul:Cross-validation with {cmd:cvlassologit}}
{pstd}
{cmd:cvlassologit} implements {it:K}-fold
cross-validation where the data is by default
randomly partitioned.
{pstd}
Here, we use {it:K}=3 and {opt seed(123)}
to set the seed for reproducibility.
(Be patient, this takes a minute.)
{phang2}. {stata "cvlassologit v58 v1-v57, nfolds(3) seed(123)"}{p_end}
{pstd}
The output shows the prediction performance
measured by deviance for each lambda value.
To estimate the model selected by cross-validation
we can specify {cmd:lopt} or {cmd:lse} using the
replay syntax.
{phang2}. {stata "cvlassologit, lopt"}{p_end}
{phang2}. {stata "cvlassologit, lse"}{p_end}
{pstd}
The data is by default randomly partitioned
into {it:K} folds. The {opt tabfold} option asks
{cmd:lassologit} to show the frequency distribution
of successes (1) and failures (0) across folds.
{phang2}. {stata "cvlassologit v58 v1-v57, nfolds(3) seed(123) tabfold"}{p_end}
{pstd}
In small samples, we might end up with a low number
of success or failures in some folds.
The {cmdab:strat:ified} option can help with this:
it ensures that
the number of successes (1) and failures (0)
is approximately the same across folds:
{phang2}. {stata "cvlassologit v58 v1-v57, nfolds(3) seed(123) tabfold stratified"}{p_end}
{pstd}
As with {cmd:lassologit}, we can use the {opt long}
option for an extended outout.
{phang2}. {stata "cvlassologit, long"}{p_end}
{marker example_rigorous}{...}
{pstd}
{ul:Rigorous penalization with {cmd:rlassologit}}
{pstd}
Lastly, we consider the logistic lasso with
rigorous penalization:
{phang2}. {stata "rlassologit v58 v1-v57"}{p_end}
{pstd}
{cmd:rlassologit} displays
the logistic lasso solution and
the post-logit solution.
{pstd}
The rigorous lambda is returned in
{cmd:e(lambda)} and is equal to
79.207801.
{phang2}. {stata "di e(lambda)"}{p_end}
{pstd}
We get the same result when specifying the
rigorous lambda manually using the
{cmd:lambda()} option of {cmd:lassologit}:
{phang2}. {stata "lassologit v58 v1-v57, lambda(79.207801)"}{p_end}
{marker example_prediction}{...}
{pstd}
{ul:Prediction}
{pstd}
After selecting a model, we can use {cmd:predict} to obtain
predicted probabilities or linear predictions.
{pstd}
First, we select a model using {cmd:lic()} in combination
with {cmd:postresults} as above:
{phang2}. {stata "lassologit v58 v1-v57"}{p_end}
{phang2}. {stata "lassologit, lic(ebic) postresults"}{p_end}
{pstd}
Then, we use {cmd:predict}:
{phang2}. {stata "predict double phat, pr"}{p_end}
{phang2}. {stata "predict double xbhat, xb"}{p_end}
{pstd}
{cmdab:p:r} saves the predicted probability of
success and {cmd:xb} saves the linear predicted
values.
{pstd}
Note that the use of {cmdab:postres:ults} is required.
Without {cmdab:postres:ults} the results of the estimation
with the selected penalty level are not stored.
{pstd}
The approach for {cmd:cvlassologit} is very similar:
{phang2}. {stata "cvlassologit v58 v1-v57"}{p_end}
{phang2}. {stata "cvlassologit, lopt postresults"}{p_end}
{phang2}. {stata "predict double phat, pr"}{p_end}
{pstd}
In the case of {cmd:rlassologit}, we don't need to
select a specific penalty level
and we also don't need to specify {cmdab:postres:ults}.
{phang2}. {stata "rlassologit v58 v1-v57"}{p_end}
{phang2}. {stata "predict double phat, pr"}{p_end}
{marker example_holdout}{...}
{pstd}
{ul:Assessing prediction accuracy with {opt holdout()}}
{pstd}
We can leave one partition of the data out of the estimation
sample and check the accuracy of prediction
using the {opt holdout(varname)} option.
{pstd}
We first define
a binary holdout variable:
{phang2}. {stata "gen myholdout = (_n>4500)"}{p_end}
{pstd}
There are 4,601 observations in the sample, and
we exclude observations 4,501 to 4,601 from the estimation.
The holdout variable should be set to 1 for all observations
that we want to use for assessing classification accuracy.
{phang2}. {stata "lassologit v58 v1-v57, holdout(myholdout)"}{p_end}
{phang2}. {stata "mat list e(loss)"}{p_end}
{phang2}. {stata "rlassologit v58 v1-v57, holdout(myholdout)"}{p_end}
{phang2}. {stata "mat list e(loss)"}{p_end}
{pstd}
The loss measure is returned in {cmd:e(loss)}.
As with cross-validation, deviance is used by default.
{opt lossmeasure(class)} will return the
average number of miss-classifications.
{marker example_plot_lassologit}{...}
{pstd}
{ul:Plotting with {cmd:lassologit}}
{pstd}
{cmd:lassologit} supports plotting of the
coefficient path over lambda.
Here, we create the plot using the replay syntax,
but the same can be achieved in one line: