-
Notifications
You must be signed in to change notification settings - Fork 0
/
GLMnet.f
7493 lines (7493 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 (2/15/13)
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(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-5
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
c
subroutine get_int_parms(sml,eps,big,mnlam,rsqmax,pmin,exmx) 771
data sml0,eps0,big0,mnlam0,rsqmax0,pmin0,exmx0 /1.0e-5,1.0e-6,9.9 773
*e35,5,0.999,1.0e-5,250.0/
sml=sml0 773
eps=eps0 773
big=big0 773
mnlam=mnlam0 773
rsqmax=rsqmax0 774
pmin=pmin0 774
exmx=exmx0 775
return 776
entry chg_fract_dev(arg) 776
sml0=arg 776
return 777
entry chg_dev_max(arg) 777
rsqmax0=arg 777
return 778
entry chg_min_flmin(arg) 778
eps0=arg 778
return 779
entry chg_big(arg) 779
big0=arg 779
return 780
entry chg_min_lambdas(irg) 780
mnlam0=irg 780
return 781
entry chg_min_null_prob(arg) 781
pmin0=arg 781
return 782
entry chg_max_exp(arg) 782
exmx0=arg 782
return 783
end 784
subroutine elnet (ka,parm,no,ni,x,y,w,jd,vp,cl,ne,nx,nlam,flmin,u 787
*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) 788
real ulam(nlam),a0(nlam),rsq(nlam),alm(nlam) 789
integer jd(*),ia(nx),nin(nlam) 790
real, dimension (:), allocatable :: vq;
if(maxval(vp) .gt. 0.0)goto 10021 793
jerr=10000 793
return 793
10021 continue 794
allocate(vq(1:ni),stat=jerr) 794
if(jerr.ne.0) return 795
vq=max(0.0,vp) 795
vq=vq*ni/sum(vq) 796
if(ka .ne. 1)goto 10041 797
call elnetu (parm,no,ni,x,y,w,jd,vq,cl,ne,nx,nlam,flmin,ulam,thr, 800
*isd,intr,maxit, lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
goto 10051 801
10041 continue 802
call elnetn (parm,no,ni,x,y,w,jd,vq,cl,ne,nx,nlam,flmin,ulam,thr,i 805
*sd,intr,maxit, lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr)
10051 continue 806
10031 continue 806
deallocate(vq) 807
return 808
end 809
subroutine elnetu (parm,no,ni,x,y,w,jd,vp,cl,ne,nx,nlam,flmin,ula 812
*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) 813
real ca(nx,nlam),a0(nlam),rsq(nlam),alm(nlam) 814
integer jd(*),ia(nx),nin(nlam) 815
real, dimension (:), allocatable :: xm,xs,g,xv,vlam
integer, dimension (:), allocatable :: ju
allocate(g(1:ni),stat=jerr) 820
allocate(xm(1:ni),stat=ierr) 820
jerr=jerr+ierr 821
allocate(xs(1:ni),stat=ierr) 821
jerr=jerr+ierr 822
allocate(ju(1:ni),stat=ierr) 822
jerr=jerr+ierr 823
allocate(xv(1:ni),stat=ierr) 823
jerr=jerr+ierr 824
allocate(vlam(1:nlam),stat=ierr) 824
jerr=jerr+ierr 825
if(jerr.ne.0) return 826
call chkvars(no,ni,x,ju) 827
if(jd(1).gt.0) ju(jd(2:(jd(1)+1)))=0 828
if(maxval(ju) .gt. 0)goto 10071 828
jerr=7777 828
return 828
10071 continue 829
call standard(no,ni,x,y,w,isd,intr,ju,g,xm,xs,ym,ys,xv,jerr) 830
if(jerr.ne.0) return 831
cl=cl/ys 831
if(isd .le. 0)goto 10091 831
10100 do 10101 j=1,ni 831
cl(:,j)=cl(:,j)*xs(j) 831
10101 continue 831
10102 continue 831
10091 continue 832
if(flmin.ge.1.0) vlam=ulam/ys 833
call elnet1(parm,ni,ju,vp,cl,g,no,ne,nx,x,nlam,flmin,vlam,thr,maxi 835
*t,xv, lmu,ca,ia,nin,rsq,alm,nlp,jerr)
if(jerr.gt.0) return 836
10110 do 10111 k=1,lmu 836
alm(k)=ys*alm(k) 836
nk=nin(k) 837
10120 do 10121 l=1,nk 837
ca(l,k)=ys*ca(l,k)/xs(ia(l)) 837
10121 continue 837
10122 continue 837
a0(k)=0.0 838
if(intr.ne.0) a0(k)=ym-dot_product(ca(1:nk,k),xm(ia(1:nk))) 839
10111 continue 840
10112 continue 840
deallocate(xm,xs,g,ju,xv,vlam) 841
return 842
end 843
subroutine standard (no,ni,x,y,w,isd,intr,ju,g,xm,xs,ym,ys,xv,jerr 844
*)
real x(no,ni),y(no),w(no),g(ni),xm(ni),xs(ni),xv(ni) 844
integer ju(ni) 845
real, dimension (:), allocatable :: v
allocate(v(1:no),stat=jerr) 848
if(jerr.ne.0) return 849
w=w/sum(w) 849
v=sqrt(w) 850
if(intr .ne. 0)goto 10141 850
ym=0.0 850
y=v*y 851
ys=sqrt(dot_product(y,y)-dot_product(v,y)**2) 851
y=y/ys 852
10150 do 10151 j=1,ni 852
if(ju(j).eq.0)goto 10151 852
xm(j)=0.0 852
x(:,j)=v*x(:,j) 853
xv(j)=dot_product(x(:,j),x(:,j)) 854
if(isd .eq. 0)goto 10171 854
xbq=dot_product(v,x(:,j))**2 854
vc=xv(j)-xbq 855
xs(j)=sqrt(vc) 855
x(:,j)=x(:,j)/xs(j) 855
xv(j)=1.0+xbq/vc 856
goto 10181 857
10171 continue 857
xs(j)=1.0 857
10181 continue 858
10161 continue 858
10151 continue 859
10152 continue 859
goto 10191 860
10141 continue 861
10200 do 10201 j=1,ni 861
if(ju(j).eq.0)goto 10201 862
xm(j)=dot_product(w,x(:,j)) 862
x(:,j)=v*(x(:,j)-xm(j)) 863
xv(j)=dot_product(x(:,j),x(:,j)) 863
if(isd.gt.0) xs(j)=sqrt(xv(j)) 864
10201 continue 865
10202 continue 865
if(isd .ne. 0)goto 10221 865
xs=1.0 865
goto 10231 866
10221 continue 867
10240 do 10241 j=1,ni 867
if(ju(j).eq.0)goto 10241 867
x(:,j)=x(:,j)/xs(j) 867
10241 continue 868
10242 continue 868
xv=1.0 869
10231 continue 870
10211 continue 870
ym=dot_product(w,y) 870
y=v*(y-ym) 870
ys=sqrt(dot_product(y,y)) 870
y=y/ys 871
10191 continue 872
10131 continue 872
g=0.0 872
10250 do 10251 j=1,ni 872
if(ju(j).ne.0) g(j)=dot_product(y,x(:,j)) 872
10251 continue 873
10252 continue 873
deallocate(v) 874
return 875
end 876
subroutine elnet1 (beta,ni,ju,vp,cl,g,no,ne,nx,x,nlam,flmin,ulam,t 878
*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( 879
*nlam),xv(ni)
real cl(2,ni) 880
integer ju(ni),ia(nx),kin(nlam) 881
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) 888
allocate(a(1:ni),stat=ierr) 888
jerr=jerr+ierr 889
allocate(mm(1:ni),stat=ierr) 889
jerr=jerr+ierr 890
allocate(da(1:ni),stat=ierr) 890
jerr=jerr+ierr 891
if(jerr.ne.0) return 892
bta=beta 892
omb=1.0-bta 893
if(flmin .ge. 1.0)goto 10271 893
eqs=max(eps,flmin) 893
alf=eqs**(1.0/(nlam-1)) 893
10271 continue 894
rsq=0.0 894
a=0.0 894
mm=0 894
nlp=0 894
nin=nlp 894
iz=0 894
mnl=min(mnlam,nlam) 895
10280 do 10281 m=1,nlam 896
if(flmin .lt. 1.0)goto 10301 896
alm=ulam(m) 896
goto 10291 897
10301 if(m .le. 2)goto 10311 897
alm=alm*alf 897
goto 10291 898
10311 if(m .ne. 1)goto 10321 898
alm=big 898
goto 10331 899
10321 continue 899
alm=0.0 900
10340 do 10341 j=1,ni 900
if(ju(j).eq.0)goto 10341 900
if(vp(j).le.0.0)goto 10341 901
alm=max(alm,abs(g(j))/vp(j)) 902
10341 continue 903
10342 continue 903
alm=alf*alm/max(bta,1.0e-3) 904
10331 continue 905
10291 continue 905
dem=alm*omb 905
ab=alm*bta 905
rsq0=rsq 905
jz=1 906
10350 continue 906
10351 continue 906
if(iz*jz.ne.0) go to 10360 906
nlp=nlp+1 906
dlx=0.0 907
10370 do 10371 k=1,ni 907
if(ju(k).eq.0)goto 10371 908
ak=a(k) 908
u=g(k)+ak*xv(k) 908
v=abs(u)-vp(k)*ab 908
a(k)=0.0 910
if(v.gt.0.0) a(k)=max(cl(1,k),min(cl(2,k),sign(v,u)/(xv(k)+vp(k)*d 911
*em)))
if(a(k).eq.ak)goto 10371 912
if(mm(k) .ne. 0)goto 10391 912
nin=nin+1 912
if(nin.gt.nx)goto 10372 913
10400 do 10401 j=1,ni 913
if(ju(j).eq.0)goto 10401 914
if(mm(j) .eq. 0)goto 10421 914
c(j,nin)=c(k,mm(j)) 914
goto 10401 914
10421 continue 915
if(j .ne. k)goto 10441 915
c(j,nin)=xv(j) 915
goto 10401 915
10441 continue 916
c(j,nin)=dot_product(x(:,j),x(:,k)) 917
10401 continue 918
10402 continue 918
mm(k)=nin 918
ia(nin)=k 919
10391 continue 920
del=a(k)-ak 920
rsq=rsq+del*(2.0*g(k)-del*xv(k)) 921
dlx=max(xv(k)*del**2,dlx) 922
10450 do 10451 j=1,ni 922
if(ju(j).ne.0) g(j)=g(j)-c(j,mm(k))*del 922
10451 continue 923
10452 continue 923
10371 continue 924
10372 continue 924
if(dlx.lt.thr)goto 10352 924
if(nin.gt.nx)goto 10352 925
if(nlp .le. maxit)goto 10471 925
jerr=-m 925
return 925
10471 continue 926
10360 continue 926
iz=1 926
da(1:nin)=a(ia(1:nin)) 927
10480 continue 927
10481 continue 927
nlp=nlp+1 927
dlx=0.0 928
10490 do 10491 l=1,nin 928
k=ia(l) 928
ak=a(k) 928
u=g(k)+ak*xv(k) 928
v=abs(u)-vp(k)*ab 929
a(k)=0.0 931
if(v.gt.0.0) a(k)=max(cl(1,k),min(cl(2,k),sign(v,u)/(xv(k)+vp(k)*d 932
*em)))
if(a(k).eq.ak)goto 10491 933
del=a(k)-ak 933
rsq=rsq+del*(2.0*g(k)-del*xv(k)) 934
dlx=max(xv(k)*del**2,dlx) 935
10500 do 10501 j=1,nin 935
g(ia(j))=g(ia(j))-c(ia(j),mm(k))*del 935
10501 continue 936
10502 continue 936
10491 continue 937
10492 continue 937
if(dlx.lt.thr)goto 10482 937
if(nlp .le. maxit)goto 10521 937
jerr=-m 937
return 937
10521 continue 938
goto 10481 939
10482 continue 939
da(1:nin)=a(ia(1:nin))-da(1:nin) 940
10530 do 10531 j=1,ni 940
if(mm(j).ne.0)goto 10531 941
if(ju(j).ne.0) g(j)=g(j)-dot_product(da(1:nin),c(j,1:nin)) 942