forked from dwf/glmnet-python
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathglmnet.f
7504 lines (7503 loc) · 548 KB
/
glmnet.f
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
c
c newGLMnet (5/12/14)
c
c
c Elastic net with squared-error loss
c
c dense predictor matrix:
c
c call elnet(ka,parm,no,ni,x,y,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,isd,
c intr,maxit,lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
c
c x(no,ni) = predictor data matrix flat file (overwritten)
c
c
c sparse predictor matrix:
c
c call spelnet(ka,parm,no,ni,x,ix,jx,y,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,
c isd,intr,maxit,lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
c
c x, ix, jx = predictor data matrix in compressed sparse row format
c
c
c other inputs:
c
c ka = algorithm flag
c ka=1 => covariance updating algorithm
c ka=2 => naive algorithm
c parm = penalty member index (0 <= parm <= 1)
c = 0.0 => ridge
c = 1.0 => lasso
c no = number of observations
c ni = number of predictor variables
c y(no) = response vector (overwritten)
c w(no)= observation weights (overwritten)
c jd(jd(1)+1) = predictor variable deletion flag
c jd(1) = 0 => use all variables
c jd(1) != 0 => do not use variables jd(2)...jd(jd(1)+1)
c vp(ni) = relative penalties for each predictor variable
c vp(j) = 0 => jth variable unpenalized
c cl(2,ni) = interval constraints on coefficient values (overwritten)
c cl(1,j) = lower bound for jth coefficient value (<= 0.0)
c cl(2,j) = upper bound for jth coefficient value (>= 0.0)
c ne = maximum number of variables allowed to enter largest model
c (stopping criterion)
c nx = maximum number of variables allowed to enter all models
c along path (memory allocation, nx > ne).
c nlam = (maximum) number of lamda values
c flmin = user control of lamda values (>=0)
c flmin < 1.0 => minimum lamda = flmin*(largest lamda value)
c flmin >= 1.0 => use supplied lamda values (see below)
c ulam(nlam) = user supplied lamda values (ignored if flmin < 1.0)
c thr = convergence threshold for each lamda solution.
c iterations stop when the maximum reduction in the criterion value
c as a result of each parameter update over a single pass
c is less than thr times the null criterion value.
c (suggested value, thr=1.0e-5)
c isd = predictor variable standarization flag:
c isd = 0 => regression on original predictor variables
c isd = 1 => regression on standardized predictor variables
c Note: output solutions always reference original
c variables locations and scales.
c intr = intercept flag
c intr = 0/1 => don't/do include intercept in model
c maxit = maximum allowed number of passes over the data for all lambda
c values (suggested values, maxit = 100000)
c
c output:
c
c lmu = actual number of lamda values (solutions)
c a0(lmu) = intercept values for each solution
c ca(nx,lmu) = compressed coefficient values for each solution
c ia(nx) = pointers to compressed coefficients
c nin(lmu) = number of compressed coefficients for each solution
c rsq(lmu) = R**2 values for each solution
c alm(lmu) = lamda values corresponding to each solution
c nlp = actual number of passes over the data for all lamda values
c jerr = error flag:
c jerr = 0 => no error
c jerr > 0 => fatal error - no output returned
c jerr < 7777 => memory allocation error
c jerr = 7777 => all used predictors have zero variance
c jerr = 10000 => maxval(vp) <= 0.0
C jerr < 0 => non fatal error - partial output:
c Solutions for larger lamdas (1:(k-1)) returned.
c jerr = -k => convergence for kth lamda value not reached
c after maxit (see above) iterations.
c jerr = -10000-k => number of non zero coefficients along path
c exceeds nx (see above) at kth lamda value.
c
c
c
c least-squares utility routines:
c
c
c uncompress coefficient vectors for all solutions:
c
c call solns(ni,nx,lmu,ca,ia,nin,b)
c
c input:
c
c ni,nx = input to elnet
c lmu,ca,ia,nin = output from elnet
c
c output:
c
c b(ni,lmu) = all elnet returned solutions in uncompressed format
c
c
c uncompress coefficient vector for particular solution:
c
c call uncomp(ni,ca,ia,nin,a)
c
c input:
c
c ni = total number of predictor variables
c ca(nx) = compressed coefficient values for the solution
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients for the solution
c
c output:
c
c a(ni) = uncompressed coefficient vector
c referencing original variables
c
c
c evaluate linear model from compressed coefficients and
c uncompressed predictor matrix:
c
c call modval(a0,ca,ia,nin,n,x,f);
c
c input:
c
c a0 = intercept
c ca(nx) = compressed coefficient values for a solution
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients for solution
c n = number of predictor vectors (observations)
c x(n,ni) = full (uncompressed) predictor matrix
c
c output:
c
c f(n) = model predictions
c
c
c evaluate linear model from compressed coefficients and
c compressed predictor matrix:
c
c call cmodval(a0,ca,ia,nin,x,ix,jx,n,f);
c
c input:
c
c a0 = intercept
c ca(nx) = compressed coefficient values for a solution
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients for solution
c x, ix, jx = predictor matrix in compressed sparse row format
c n = number of predictor vectors (observations)
c
c output:
c
c f(n) = model predictions
c
c
c
c
c Multiple response
c elastic net with squared-error loss
c
c dense predictor matrix:
c
c call multelnet(parm,no,ni,nr,x,y,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,isd,
c jsd,intr,maxit,lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
c
c x(no,ni) = predictor data matrix flat file (overwritten)
c
c
c sparse predictor matrix:
c
c call multspelnet(parm,no,ni,nr,x,ix,jx,y,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,
c isd,jsd,intr,maxit,lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
c
c x, ix, jx = predictor data matrix in compressed sparse row format
c
c other inputs:
c
c nr = number of response variables
c y(no,nr) = response data matrix (overwritten)
c jsd = response variable standardization flag
c jsd = 0 => regression using original response variables
c jsd = 1 => regression using standardized response variables
c Note: output solutions always reference original
c variables locations and scales.
c all other inputs same as elnet/spelnet above
c
c output:
c
c a0(nr,lmu) = intercept values for each solution
c ca(nx,nr,lmu) = compressed coefficient values for each solution
c all other outputs same as elnet/spelnet above
c (jerr = 90000 => bounds adjustment non convergence)
c
c
c
c multiple response least-squares utility routines:
c
c
c uncompress coefficient matrix for all solutions:
c
c call multsolns(ni,nx,nr,lmu,ca,ia,nin,b)
c
c input:
c
c ni,nx,nr = input to multelnet
c lmu,ca,ia,nin = output from multelnet
c
c output:
c
c b(ni,nr,lmu) = all multelnet returned solutions in uncompressed format
c
c
c uncompress coefficient matrix for particular solution:
c
c call multuncomp(ni,nr,nx,ca,ia,nin,a)
c
c input:
c
c ni,nr,nx = input to multelnet
c ca(nx,nr) = compressed coefficient values for the solution
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients for the solution
c
c output:
c
c a(ni,nr) = uncompressed coefficient matrix
c referencing original variables
c
c
c evaluate linear model from compressed coefficients and
c uncompressed predictor matrix:
c
c call multmodval(nx,nr,a0,ca,ia,nin,n,x,f);
c
c input:
c
c nx,nr = input to multelnet
c a0(nr) = intercepts
c ca(nx,nr) = compressed coefficient values for a solution
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients for solution
c n = number of predictor vectors (observations)
c x(n,ni) = full (uncompressed) predictor matrix
c
c output:
c
c f(nr,n) = model predictions
c
c
c evaluate linear model from compressed coefficients and
c compressed predictor matrix:
c
c call multcmodval(nx,nr,a0,ca,ia,nin,x,ix,jx,n,f);
c
c input:
c
c nx,nr = input to multelnet
c a0(nr) = intercepts
c ca(nx,nr) = compressed coefficient values for a solution
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients for solution
c x, ix, jx = predictor matrix in compressed sparse row format
c n = number of predictor vectors (observations)
c
c output:
c
c f(nr,n) = model predictions
c
c
c
c
c Symmetric binomial/multinomial logistic elastic net
c
c
c dense predictor matrix:
c
c call lognet (parm,no,ni,nc,x,y,o,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,isd,
c intr,maxit,kopt,lmu,a0,ca,ia,nin,dev0,fdev,alm,nlp,jerr)
c
c x(no,ni) = predictor data matrix flat file (overwritten)
c
c
c sparse predictor matrix:
c
c call splognet (parm,no,ni,nc,x,ix,jx,y,o,jd,vp,cl,ne,nx,nlam,flmin,
c ulam,thr,isd,intr,maxit,kopt,lmu,a0,ca,ia,nin,dev0,fdev,alm,nlp,jerr)
c
c x, ix, jx = predictor data matrix in compressed sparse row format
c
c
c other inputs:
c
c parm,no,ni,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,isd,intr,maxit
c = same as elnet above.
c
c nc = number of classes (distinct outcome values)
c nc=1 => binomial two-class logistic regression
c (all output references class 1)
c y(no,max(2,nc)) = number of each class at each design point
c entries may have fractional values or all be zero (overwritten)
c o(no,nc) = observation off-sets for each class
c kopt = optimization flag
c kopt = 0 => Newton-Raphson (recommended)
c kpot = 1 => modified Newton-Raphson (sometimes faster)
c kpot = 2 => nonzero coefficients same for each class (nc > 1)
c
c
c output:
c
c lmu,ia,nin,alm,nlp = same as elent above
c
c a0(nc,lmu) = intercept values for each class at each solution
c ca(nx,nc,lmu) = compressed coefficient values for each class at
c each solution
c dev0 = null deviance (intercept only model)
c fdev(lmu) = fraction of devience explained by each solution
c jerr = error flag
c jerr = 0 => no error
c jerr > 0 => fatal error - no output returned
c jerr < 7777 => memory allocation error
c jerr = 7777 => all used predictors have zero variance
c jerr = 8000 + k => null probability < 1.0e-5 for class k
c jerr = 9000 + k => null probability for class k
c > 1.0 - 1.0e-5
c jerr = 10000 => maxval(vp) <= 0.0
c jerr = 90000 => bounds adjustment non convergence
C jerr < 0 => non fatal error - partial output:
c Solutions for larger lamdas (1:(k-1)) returned.
c jerr = -k => convergence for kth lamda value not reached
c after maxit (see above) iterations.
c jerr = -10000-k => number of non zero coefficients along path
c exceeds nx (see above) at kth lamda value.
c jerr = -20000-k => max(p*(1-p)) < 1.0e-6 at kth lamda value.
c o(no,nc) = training data values for last (lmu_th) solution linear
c combination.
c
c
c
c logistic/multinomial utilitity routines:
c
c
c uncompress coefficient vectors for all solutions:
c
c call lsolns(ni,nx,nc,lmu,ca,ia,nin,b)
c
c input:
c
c ni,nx,nc = input to lognet
c lmu,ca,ia,nin = output from lognet
c
c output:
c
c b(ni,nc,lmu) = all lognet returned solutions in uncompressed format
c
c
c uncompress coefficient vector for particular solution:
c
c call luncomp(ni,nx,nc,ca,ia,nin,a)
c
c input:
c
c ni, nx, nc = same as above
c ca(nx,nc) = compressed coefficient values (for each class)
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients
c
c output:
c
c a(ni,nc) = uncompressed coefficient vectors
c referencing original variables
c
c
c evaluate linear model from compressed coefficients and
c uncompressed predictor vectors:
c
c call lmodval(nt,x,nc,nx,a0,ca,ia,nin,ans);
c
c input:
c
c nt = number of observations
c x(nt,ni) = full (uncompressed) predictor vectors
c nc, nx = same as above
c a0(nc) = intercepts
c ca(nx,nc) = compressed coefficient values (for each class)
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients
c
c output:
c
c ans(nc,nt) = model predictions
c
c
c evaluate linear model from compressed coefficients and
c compressed predictor matrix:
c
c call lcmodval(nc,nx,a0,ca,ia,nin,x,ix,jx,n,f);
c
c input:
c
c nc, nx = same as above
c a0(nc) = intercept
c ca(nx,nc) = compressed coefficient values for a solution
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients for solution
c x, ix, jx = predictor matrix in compressed sparse row format
c n = number of predictor vectors (observations)
c
c output:
c
c f(nc,n) = model predictions
c
c
c
c
c Poisson elastic net
c
c
c dense predictor matrix:
c
c call fishnet (parm,no,ni,x,y,o,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,
c isd,intr,maxit,lmu,a0,ca,ia,nin,dev0,fdev,alm,nlp,jerr)
c
c x(no,ni) = predictor data matrix flat file (overwritten)
c
c sparse predictor matrix:
c
c call spfishnet (parm,no,ni,x,ix,jx,y,o,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,
c isd,intr,maxit,lmu,a0,ca,ia,nin,dev0,fdev,alm,nlp,jerr)
c
c x, ix, jx = predictor data matrix in compressed sparse row format
c
c other inputs:
c
c y(no) = observation response counts
c o(no) = observation off-sets
c parm,no,ni,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,isd,intr,maxit
c = same as elnet above
c
c output:
c
c lmu,a0,ca,ia,nin,alm = same as elnet above
c dev0,fdev = same as lognet above
c nlp = total number of passes over predictor variables
c jerr = error flag
c jerr = 0 => no error
c jerr > 0 => fatal error - no output returned
c jerr < 7777 => memory allocation error
c jerr = 7777 => all used predictors have zero variance
c jerr = 8888 => negative response count y values
c jerr = 9999 => no positive observations weights
c jerr = 10000 => maxval(vp) <= 0.0
C jerr < 0 => non fatal error - partial output:
c Solutions for larger lamdas (1:(k-1)) returned.
c jerr = -k => convergence for kth lamda value not reached
c after maxit (see above) iterations.
c jerr = -10000-k => number of non zero coefficients along path
c exceeds nx (see above) at kth lamda value.
c o(no) = training data values for last (lmu_th) solution linear
c combination.
c
c
c Poisson utility routines:
c
c
c same as elnet above:
c
c call solns(ni,nx,lmu,ca,ia,nin,b)
c call uncomp(ni,ca,ia,nin,a)
c call modval(a0,ca,ia,nin,n,x,f);
c call cmodval(a0,ca,ia,nin,x,ix,jx,n,f);
c
c compute deviance for given uncompressed data and set of uncompressed
c solutions
c
c call deviance(no,ni,x,y,o,w,nsol,a0,a,flog,jerr)
c
c input:
c
c no = number of observations
c ni = number of predictor variables
c x(no,ni) = predictor data matrix flat file
c y(no) = observation response counts
c o(no) = observation off-sets
c w(no)= observation weights
c nsol = number of solutions
c a0(nsol) = intercept for each solution
c a(ni,nsol) = solution coefficient vectors (uncompressed)
c
c output:
c
c flog(nsol) = respective deviance values minus null deviance
c jerr = error flag - see above
c
c
c compute deviance for given compressed data and set of uncompressed solutions
c
c call spdeviance(no,ni,x,ix,jx,y,o,w,nsol,a0,a,flog,jerr)
c
c input:
c
c no = number of observations
c ni = number of predictor variables
c x, ix, jx = predictor data matrix in compressed sparse row format
c y(no) = observation response counts
c o(no) = observation off-sets
c w(no)= observation weights
c nsol = number of solutions
c a0(nsol) = intercept for each solution
c a(ni,nsol) = solution coefficient vectors (uncompressed)
c
c output
c
c flog(nsol) = respective deviance values minus null deviance
c jerr = error flag - see above
c
c
c compute deviance for given compressed data and compressed solutions
c
c call cspdeviance(no,x,ix,jx,y,o,w,nx,lmu,a0,ca,ia,nin,flog,jerr)
c
c input:
c
c no = number of observations
c x, ix, jx = predictor data matrix in compressed sparse row format
c y(no) = observation response counts
c o(no) = observation off-sets
c w(no)= observation weights
c nx = input to spfishnet
c lmu,a0(lmu),ca(nx,lmu),ia(nx),nin(lmu) = output from spfishnet
c
c output
c
c flog(lmu) = respective deviance values minus null deviance
c jerr = error flag - see above
c
c
c
c Elastic net with Cox proportional hazards model
c
c
c dense predictor matrix:
c
c call coxnet (parm,no,ni,x,y,d,o,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,
c maxit,isd,lmu,ca,ia,nin,dev0,fdev,alm,nlp,jerr)
c
c input:
c
c x(no,ni) = predictor data matrix flat file (overwritten)
c y(no) = observation times
c d(no) = died/censored indicator
c d(i)=0.0 => y(i) = censoring time
c d(i)=1.0 => y(i) = death time
c o(no) = observation off-sets
c parm,no,ni,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,maxit
c = same as fishnet above
c
c output:
c
c lmu,ca,ia,nin,dev0,fdev,alm,nlp = same as fishnet above
c jerr = error flag
c jerr = 0 => no error - output returned
c jerr > 0 => fatal error - no output returned
c jerr < 7777 => memory allocation error
c jerr = 7777 => all used predictors have zero variance
c jerr = 8888 => all observations censored (d(i)=0.0)
c jerr = 9999 => no positive observations weights
c jerr = 10000 => maxval(vp) <= 0.0
c jerr = 20000, 30000 => initialization numerical error
C jerr < 0 => non fatal error - partial output:
c Solutions for larger lamdas (1:(k-1)) returned.
c jerr = -k => convergence for kth lamda value not reached
c after maxit (see above) iterations.
c jerr = -10000-k => number of non zero coefficients along path
c exceeds nx (see above) at kth lamda value.
c jerr = -30000-k => numerical error at kth lambda value
c o(no) = training data values for last (lmu_th) solution linear
c combination.
c
c
c
c coxnet utility routines:
c
c
c same as elnet above:
c
c call solns(ni,nx,lmu,ca,ia,nin,b)
c call uncomp(ni,ca,ia,nin,a)
c
c
c evaluate linear model from compressed coefficients and
c uncompressed predictor matrix:
c
c call cxmodval(ca,ia,nin,n,x,f);
c
c input:
c
c ca(nx) = compressed coefficient values for a solution
c ia(nx) = pointers to compressed coefficients
c nin = number of compressed coefficients for solution
c n = number of predictor vectors (observations)
c x(n,ni) = full (uncompressed) predictor matrix
c
c output:
c
c f(n) = model predictions
c
c
c compute log-likelihood for given data set and vectors of coefficients
c
c call loglike(no,ni,x,y,d,o,w,nvec,a,flog,jerr)
c
c input:
c
c no = number of observations
c ni = number of predictor variables
c x(no,ni) = predictor data matrix flat file
c y(no) = observation times
c d(no) = died/censored indicator
c d(i)=0.0 => y(i) = censoring time
c d(i)=1.0 => y(i) = death time
c o(no) = observation off-sets
c w(no)= observation weights
c nvec = number of coefficient vectors
c a(ni,nvec) = coefficient vectors (uncompressed)
c
c output
c
c flog(nvec) = respective log-likelihood values
c jerr = error flag - see coxnet above
c
c
c
c
c Changing internal parameter values
c
c
c call chg_fract_dev(fdev)
c fdev = minimum fractional change in deviance for stopping path
c default = 1.0e-5
c
c call chg_dev_max(devmax)
c devmax = maximum fraction of explained deviance for stopping path
c default = 0.999
c
c call chg_min_flmin(eps)
c eps = minimum value of flmin (see above). default= 1.0e-6
c
c call chg_big(big)
c big = large floating point number. default = 9.9e35
c
c call chg_min_lambdas(mnlam)
c mnlam = minimum number of path points (lambda values) allowed
c default = 5
c
c call chg_min_null_prob(pmin)
c pmin = minimum null probability for any class. default = 1.0e-9
c
c call chg _max_exp(exmx)
c exmx = maximum allowed exponent. default = 250.0
c
c call chg_bnorm(prec,mxit)
c prec = convergence threshold for multi response bounds adjustment
c solution. default = 1.0e-10.
c mxit = maximum iterations for multiresponse bounds adjustment solution
c default = 100.
c
c
c Obtain current internal parameter values
c
c call get_int_parms(fdev,eps,big,mnlam,devmax,pmin,exmx)
c call get_bnorm(prec,mxit);
c
c
subroutine get_int_parms (sml,eps,big,mnlam,rsqmax,pmin,exmx) 772
data sml0,eps0,big0,mnlam0,rsqmax0,pmin0,exmx0 /1.0e-5,1.0e-6,9.9 774
*e35,5,0.999,1.0e-9,250.0/
sml=sml0 774
eps=eps0 774
big=big0 774
mnlam=mnlam0 774
rsqmax=rsqmax0 775
pmin=pmin0 775
exmx=exmx0 776
return 777
end 777
subroutine chg_fract_dev(arg) 777
sml0=arg 777
return 778
end 778
subroutine chg_dev_max(arg) 778
rsqmax0=arg 778
return 779
end 779
subroutine chg_min_flmin(arg) 779
eps0=arg 779
return 780
end 780
subroutine chg_big(arg) 780
big0=arg 780
return 781
end 781
subroutine chg_min_lambdas(irg) 781
mnlam0=irg 781
return 782
end 782
subroutine chg_min_null_prob(arg) 782
pmin0=arg 782
return 783
end 783
subroutine chg_max_exp(arg) 783
exmx0=arg 783
return 784
end 785
subroutine elnet (ka,parm,no,ni,x,y,w,jd,vp,cl,ne,nx,nlam,flmin,u 788
*lam,thr,isd,intr,maxit, lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
real x(no,ni),y(no),w(no),vp(ni),ca(nx,nlam),cl(2,ni) 789
real ulam(nlam),a0(nlam),rsq(nlam),alm(nlam) 790
integer jd(*),ia(nx),nin(nlam) 791
real, dimension (:), allocatable :: vq;
if(maxval(vp) .gt. 0.0)goto 10021 794
jerr=10000 794
return 794
10021 continue 795
allocate(vq(1:ni),stat=jerr) 795
if(jerr.ne.0) return 796
vq=max(0.0,vp) 796
vq=vq*ni/sum(vq) 797
if(ka .ne. 1)goto 10041 798
call elnetu (parm,no,ni,x,y,w,jd,vq,cl,ne,nx,nlam,flmin,ulam,thr, 801
*isd,intr,maxit, lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
goto 10051 802
10041 continue 803
call elnetn (parm,no,ni,x,y,w,jd,vq,cl,ne,nx,nlam,flmin,ulam,thr,i 806
*sd,intr,maxit, lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
10051 continue 807
10031 continue 807
deallocate(vq) 808
return 809
end 810
subroutine elnetu (parm,no,ni,x,y,w,jd,vp,cl,ne,nx,nlam,flmin,ula 813
*m,thr,isd,intr,maxit, lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
real x(no,ni),y(no),w(no),vp(ni),ulam(nlam),cl(2,ni) 814
real ca(nx,nlam),a0(nlam),rsq(nlam),alm(nlam) 815
integer jd(*),ia(nx),nin(nlam) 816
real, dimension (:), allocatable :: xm,xs,g,xv,vlam
integer, dimension (:), allocatable :: ju
allocate(g(1:ni),stat=jerr) 821
allocate(xm(1:ni),stat=ierr) 821
jerr=jerr+ierr 822
allocate(xs(1:ni),stat=ierr) 822
jerr=jerr+ierr 823
allocate(ju(1:ni),stat=ierr) 823
jerr=jerr+ierr 824
allocate(xv(1:ni),stat=ierr) 824
jerr=jerr+ierr 825
allocate(vlam(1:nlam),stat=ierr) 825
jerr=jerr+ierr 826
if(jerr.ne.0) return 827
call chkvars(no,ni,x,ju) 828
if(jd(1).gt.0) ju(jd(2:(jd(1)+1)))=0 829
if(maxval(ju) .gt. 0)goto 10071 829
jerr=7777 829
return 829
10071 continue 830
call standard(no,ni,x,y,w,isd,intr,ju,g,xm,xs,ym,ys,xv,jerr) 831
if(jerr.ne.0) return 832
cl=cl/ys 832
if(isd .le. 0)goto 10091 832
10100 do 10101 j=1,ni 832
cl(:,j)=cl(:,j)*xs(j) 832
10101 continue 832
10102 continue 832
10091 continue 833
if(flmin.ge.1.0) vlam=ulam/ys 834
call elnet1(parm,ni,ju,vp,cl,g,no,ne,nx,x,nlam,flmin,vlam,thr,maxi 836
*t,xv, lmu,ca,ia,nin,rsq,alm,nlp,jerr)
if(jerr.gt.0) return 837
10110 do 10111 k=1,lmu 837
alm(k)=ys*alm(k) 837
nk=nin(k) 838
10120 do 10121 l=1,nk 838
ca(l,k)=ys*ca(l,k)/xs(ia(l)) 838
10121 continue 838
10122 continue 838
a0(k)=0.0 839
if(intr.ne.0) a0(k)=ym-dot_product(ca(1:nk,k),xm(ia(1:nk))) 840
10111 continue 841
10112 continue 841
deallocate(xm,xs,g,ju,xv,vlam) 842
return 843
end 844
subroutine standard (no,ni,x,y,w,isd,intr,ju,g,xm,xs,ym,ys,xv,jerr 845
*)
real x(no,ni),y(no),w(no),g(ni),xm(ni),xs(ni),xv(ni) 845
integer ju(ni) 846
real, dimension (:), allocatable :: v
allocate(v(1:no),stat=jerr) 849
if(jerr.ne.0) return 850
w=w/sum(w) 850
v=sqrt(w) 851
if(intr .ne. 0)goto 10141 851
ym=0.0 851
y=v*y 852
ys=sqrt(dot_product(y,y)-dot_product(v,y)**2) 852
y=y/ys 853
10150 do 10151 j=1,ni 853
if(ju(j).eq.0)goto 10151 853
xm(j)=0.0 853
x(:,j)=v*x(:,j) 854
xv(j)=dot_product(x(:,j),x(:,j)) 855
if(isd .eq. 0)goto 10171 855
xbq=dot_product(v,x(:,j))**2 855
vc=xv(j)-xbq 856
xs(j)=sqrt(vc) 856
x(:,j)=x(:,j)/xs(j) 856
xv(j)=1.0+xbq/vc 857
goto 10181 858
10171 continue 858
xs(j)=1.0 858
10181 continue 859
10161 continue 859
10151 continue 860
10152 continue 860
goto 10191 861
10141 continue 862
10200 do 10201 j=1,ni 862
if(ju(j).eq.0)goto 10201 863
xm(j)=dot_product(w,x(:,j)) 863
x(:,j)=v*(x(:,j)-xm(j)) 864
xv(j)=dot_product(x(:,j),x(:,j)) 864
if(isd.gt.0) xs(j)=sqrt(xv(j)) 865
10201 continue 866
10202 continue 866
if(isd .ne. 0)goto 10221 866
xs=1.0 866
goto 10231 867
10221 continue 868
10240 do 10241 j=1,ni 868
if(ju(j).eq.0)goto 10241 868
x(:,j)=x(:,j)/xs(j) 868
10241 continue 869
10242 continue 869
xv=1.0 870
10231 continue 871
10211 continue 871
ym=dot_product(w,y) 871
y=v*(y-ym) 871
ys=sqrt(dot_product(y,y)) 871
y=y/ys 872
10191 continue 873
10131 continue 873
g=0.0 873
10250 do 10251 j=1,ni 873
if(ju(j).ne.0) g(j)=dot_product(y,x(:,j)) 873
10251 continue 874
10252 continue 874
deallocate(v) 875
return 876
end 877
subroutine elnet1 (beta,ni,ju,vp,cl,g,no,ne,nx,x,nlam,flmin,ulam,t 879
*hr,maxit,xv, lmu,ao,ia,kin,rsqo,almo,nlp,jerr)
real vp(ni),g(ni),x(no,ni),ulam(nlam),ao(nx,nlam),rsqo(nlam),almo( 880
*nlam),xv(ni)
real cl(2,ni) 881
integer ju(ni),ia(nx),kin(nlam) 882
real, dimension (:), allocatable :: a,da
integer, dimension (:), allocatable :: mm
real, dimension (:,:), allocatable :: c
allocate(c(1:ni,1:nx),stat=jerr)
call get_int_parms(sml,eps,big,mnlam,rsqmax,pmin,exmx) 889
allocate(a(1:ni),stat=ierr) 889
jerr=jerr+ierr 890
allocate(mm(1:ni),stat=ierr) 890
jerr=jerr+ierr 891
allocate(da(1:ni),stat=ierr) 891
jerr=jerr+ierr 892
if(jerr.ne.0) return 893
bta=beta 893
omb=1.0-bta 894
if(flmin .ge. 1.0)goto 10271 894
eqs=max(eps,flmin) 894
alf=eqs**(1.0/(nlam-1)) 894
10271 continue 895
rsq=0.0 895
a=0.0 895
mm=0 895
nlp=0 895
nin=nlp 895
iz=0 895
mnl=min(mnlam,nlam) 896
10280 do 10281 m=1,nlam 897
if(flmin .lt. 1.0)goto 10301 897
alm=ulam(m) 897
goto 10291 898
10301 if(m .le. 2)goto 10311 898
alm=alm*alf 898
goto 10291 899
10311 if(m .ne. 1)goto 10321 899
alm=big 899
goto 10331 900
10321 continue 900
alm=0.0 901
10340 do 10341 j=1,ni 901
if(ju(j).eq.0)goto 10341 901
if(vp(j).le.0.0)goto 10341 902
alm=max(alm,abs(g(j))/vp(j)) 903
10341 continue 904
10342 continue 904
alm=alf*alm/max(bta,1.0e-3) 905
10331 continue 906
10291 continue 906
dem=alm*omb 906
ab=alm*bta 906
rsq0=rsq 906
jz=1 907
10350 continue 907
10351 continue 907
if(iz*jz.ne.0) go to 10360 907
nlp=nlp+1 907
dlx=0.0 908
10370 do 10371 k=1,ni 908
if(ju(k).eq.0)goto 10371 909
ak=a(k) 909
u=g(k)+ak*xv(k) 909
v=abs(u)-vp(k)*ab 909
a(k)=0.0 911
if(v.gt.0.0) a(k)=max(cl(1,k),min(cl(2,k),sign(v,u)/(xv(k)+vp(k)*d 912
*em)))
if(a(k).eq.ak)goto 10371 913
if(mm(k) .ne. 0)goto 10391 913
nin=nin+1 913
if(nin.gt.nx)goto 10372 914
10400 do 10401 j=1,ni 914
if(ju(j).eq.0)goto 10401 915
if(mm(j) .eq. 0)goto 10421 915
c(j,nin)=c(k,mm(j)) 915
goto 10401 915
10421 continue 916
if(j .ne. k)goto 10441 916
c(j,nin)=xv(j) 916
goto 10401 916
10441 continue 917
c(j,nin)=dot_product(x(:,j),x(:,k)) 918
10401 continue 919
10402 continue 919
mm(k)=nin 919
ia(nin)=k 920
10391 continue 921
del=a(k)-ak 921
rsq=rsq+del*(2.0*g(k)-del*xv(k)) 922
dlx=max(xv(k)*del**2,dlx) 923
10450 do 10451 j=1,ni 923
if(ju(j).ne.0) g(j)=g(j)-c(j,mm(k))*del 923
10451 continue 924
10452 continue 924
10371 continue 925
10372 continue 925
if(dlx.lt.thr)goto 10352 925
if(nin.gt.nx)goto 10352 926
if(nlp .le. maxit)goto 10471 926
jerr=-m 926
return 926
10471 continue 927
10360 continue 927
iz=1 927
da(1:nin)=a(ia(1:nin)) 928
10480 continue 928
10481 continue 928
nlp=nlp+1 928
dlx=0.0 929
10490 do 10491 l=1,nin 929
k=ia(l) 929
ak=a(k) 929
u=g(k)+ak*xv(k) 929
v=abs(u)-vp(k)*ab 930
a(k)=0.0 932
if(v.gt.0.0) a(k)=max(cl(1,k),min(cl(2,k),sign(v,u)/(xv(k)+vp(k)*d 933
*em)))
if(a(k).eq.ak)goto 10491 934
del=a(k)-ak 934
rsq=rsq+del*(2.0*g(k)-del*xv(k)) 935
dlx=max(xv(k)*del**2,dlx) 936
10500 do 10501 j=1,nin 936
g(ia(j))=g(ia(j))-c(ia(j),mm(k))*del 936
10501 continue 937
10502 continue 937
10491 continue 938
10492 continue 938
if(dlx.lt.thr)goto 10482 938
if(nlp .le. maxit)goto 10521 938
jerr=-m 938