-
Notifications
You must be signed in to change notification settings - Fork 0
/
asurv.f
10015 lines (9334 loc) · 362 KB
/
asurv.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 **********************************************************************
C *********************** SUBROUTINE AARRAY ****************************
C **********************************************************************
C
SUBROUTINE AARRAY(Z,IND,ISTA,IS,NTOT,NDAT,MVAR,NG1,NG2,XY,
+ ID1,ID2,ISAVE)
C
C******* ISIGN,IFULL IS ADDED ON "COMMON' STATEMENT *
C * *
C * INPUT Z(I,J) : DATA TO BE TESTED *
C * IND(I,J): INDICATOR OF CENSORING *
C * ISTA(I) : INDICATOR OF GROUP *
C * IS : IS-TH SUB-DATA SET *
C * NG1 : INDICATOR OF THE FIRST GROUP *
C * NG2 : INDICATOR OF THE SECOND GROUP *
C * NTOT : TOTAL NUMBER OF DATA POINTS *
C * LL : INDICATOR OF OUTPUT FILE *
C * IPR : INDICATOR FOR PRINTING *
C * *
C * OUTPUT N : NTOT *
C * N1 : NUMBER OF DATA POINTS IN GROUP 1 *
C * N2 : NUMBER OF DATA POINTS IN GROUP 2 *
C * NCEN : NUMBER OF CENSORED DATA POINTS *
C * ISIGN : INDICATOR OF LOWER/UPPER LIMITS *
C * *
C * PUT ALL OBS. IN ARRAY XY AND FORM ARRAYS ID1 AND ID2 *
C * ID1(I)=0 : ITH OBS. IS UNCENSORED *
C * 1 : ITH OBS. IS CENSORED *
C * ID2(I)=J : ITH OBS. IS FROM ITH SAMPLE, J=1,2 *
C * *
C * SUBROUTINES *
C * SORT2 *
C
C******* ALTHOUGH THIS SUBROUTINE HAS THE SAME NAME AS A PROGRAM FROM *
C******* "STATISTICAL METHODS FOR SURVIVAL DATA ANALYSIS" BY ELISA T. *
C******* LEE, 1980, LIFETIME LEARNING PUBLICATIONS (BELMONT:CA), *
C******* IT IS DIFFERENT EXCEPT IN THE GENERAL PURPOSE. *
C******* ID1(I) IS ASSIGNED IN THE OPPOSITE WAY SO THAT THE PPROGRAM *
C******* CAN USE THE DATA SETS WHICH ARE MADE FOR OTHER PROGRAMS. *
C
IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N)
DIMENSION Z(MVAR,NDAT),IND(MVAR,NDAT),ISTA(NTOT)
DIMENSION XY(NTOT),ID1(NTOT),ID2(NTOT),ISAVE(NTOT)
COMMON /G/ NCOMP,N1,N2,NCEN,ISIGN,IFULL,LO
C
IU=0
NCEN=0
NCOMP=0
N1=0
N2=0
ISIGN=1
C
C * FIND THE CENSORSHIP OF THE DATA SET. -1 FOR UPPER LIMITS *
C * AND 1 FOR LOWER LIMITS *
C
DO 100 I=1,NTOT
ISAVE(I) = 0
IF(IND(IS,I) .EQ. 0) GOTO 100
ISIGN=IND(IS,I)/IABS(IND(IS,I))
ISAVE(I) = ISIGN
100 CONTINUE
C * CHECK WHETHER THE UPPER AND LOWER LIMITS ARE MIXED IN THE SAME *
C * VARIABLE. IF SO, THE PROGRAM IS TERMINATED. *
C * THIS TEST WAS ADDED. *
C
DO 110 I = 1, NTOT
IF(ISAVE(I) .EQ. 0) GOTO 110
IF(ISAVE(I) .NE. ISIGN) THEN
PRINT *
PRINT *,'YOU CANNOT HAVE BOTH UPPER AND LOWER LIMITS'
PRINT *,'IN ONE VARIABLE AT THE SAME TIME.'
PRINT *,'PLEASE CHECK YOUR DATA.'
PRINT *,'THE PROGRAM HAS BEEN TERMINATED.'
PRINT *
STOP
ENDIF
110 CONTINUE
C
C * COUNT NUMBER OF DATA POINTS IN THE TWO SUBSAMPLES *
C
DO 400 I = 1, NTOT
IF((ISTA(I) .EQ. NG1) .OR. (ISTA(I) .EQ. NG2)) THEN
NCOMP = NCOMP + 1
XY(NCOMP) = ISIGN*Z(IS,I)
IF(ISTA(I) .EQ. NG1) ID2(NCOMP) = 1
IF(ISTA(I) .EQ. NG2) ID2(NCOMP) = 2
IF(IABS(IND(IS,I)) .NE. 1) THEN
ID1(NCOMP) = 0
IU = IU + 1
IF(ID2(NCOMP) .EQ. 1) N1 = N1 + 1
IF(ID2(NCOMP) .EQ. 2) N2 = N2 + 1
ELSE
ID1(NCOMP) = 1
NCEN = NCEN + 1
IF(ID2(NCOMP) .EQ. 1) N1 = N1 + 1
IF(ID2(NCOMP) .EQ. 2) N2 = N2 + 1
ENDIF
ENDIF
400 CONTINUE
CALL SORT2(XY, ID1, ID2, NTOT)
RETURN
END
C
C **********************************************************************
C ********************* FUNCTION AGAUSS *******************************
C **********************************************************************
C
FUNCTION AGAUSS(Z)
C
C * EVALUATES THE INTEGRAL OF THE GAUSSIAN PROBABILITY FUNCTION *
C * OBTAINED FROM PROGRAM 3-5 ON P. 35 OF "DATA REDUCTION AND *
C * ERROR ANALYSIS FOR THE PHYSICAL SCIENCES", P. R. BEVINGTON, *
C * 1969, McGRAW HILL, (NY:NY). *
C * *
C
C
IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N)
C
C
Z=DABS(Z)
AGAUSS=1.0
C
C * IF Z>5.0, USE APPROXIMATION FOR PROB TO AVOID ERROR *
C
IF(Z.LE.5.0) THEN
DENOM=1.0
IF(Z .GT. 0.0) THEN
TERM=0.7071067812D00*Z
SUM=TERM
Y2=(Z**2)/2.0
31 DENOM=DENOM+2.0
TERM=TERM*(Y2*2.0/DENOM)
SUM=SUM+TERM
IF(TERM/SUM-1.0E-10 .GT. 0.0) THEN
GOTO 31
ELSE
AGAUSS=1.128379167D00*SUM*DEXP(-Y2)
ENDIF
ELSE
AGAUSS = 0.0
ENDIF
ENDIF
RETURN
END
C
C*************************************************************************
C********************* SUBROUTINE AKRANK *********************************
C*************************************************************************
C
C
SUBROUTINE AKRANK(IND, X, NTOT, IP, R, MVAR,ZU, ZC,
+ PL, F, V, FMASS, ITEMP, PTEMP,Z1,
+ WRK1,WRK2,WRK3,DWRK1,IWRK1,SWRK1)
C
C * THIS SUBROUTINE COMPUTES AKRITAS' RANK *
C * *
C * REFERENCE *
C * PENN STATE UNIVERSITY, DEPARTMENT OF STATISTICS, *
C * TECHNICAL REPORTS AND PREPRINTS SERIES, NUMBER 87, *
C * "ALIGNED RANK TESTS FOR REGRESSION WITH CENSORED DATA", *
C * MICHAEL G. AKRITAS, SEPTEMBER 1989 *
C * INPUT *
C * IND : INDICATOR OF CENSORSHIP *
C * X : VARIABLE *
C * NTOT : TOTAL NUMBER OF DATA POINTS *
C * *
C * OUTPUT *
C * R : RANK *
C * PL : PL ESTIMATOR *
C * F : 1.0 - PL (DISTRIBUTION FUNCTION) *
C * *
C * OTHER VARIABLES *
C * IP : INDEX OF VARIABLE BEING RANKED *
C * MVAR : NUMBER OF VARIABLES *
C * ZU : DETECTED DATA *
C * ZC : CENSORED DATA *
C * FMASS : JUMPS IN PL ESTIMATOR *
C * IU : NUMBER OF DETECTIONS *
C * IC : NUMBER OF CENSORED DATA POINTS *
C * PTEMP : TEMPORARY STORAGE OF PL ESTIMATOR *
C * *
C * SUBROUTINES *
C * XVAR, PLESTM, SORT1 *
C
C
IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N)
DIMENSION IND(MVAR, NTOT), X(MVAR, NTOT), ZU(NTOT), ZC(NTOT)
DIMENSION PL(NTOT), R(MVAR, NTOT), F(NTOT), V(NTOT), FMASS(NTOT)
DIMENSION Z1(MVAR, NTOT), ITEMP(NTOT), PTEMP(NTOT)
DIMENSION IWRK1(NTOT),DWRK1(MVAR,NTOT),SWRK1(MVAR)
DIMENSION WRK1(NTOT),WRK2(NTOT),WRK3(NTOT)
C
C * CALL SUBROUTINE XVAR : DISTINGUISH DETECTIONS AND CENSORED *
C * DATA POINTS. *
C
CALL XVAR(IND,X,IP,NTOT,ISIGN,ZU,ZC,IU,IC,IWRK1,WRK1,WRK2,WRK3,
+ DWRK1,SWRK1,LTOT,MVAR,ITEMP)
C
C * CALL PLESTM : PL ESTIMATOR COMPUTATION *
C
C
DO 5 I = 1, NTOT
ITEMP(I) = 0
Z1(1, I) = 0.0
IWRK1(I) = IND(IP,I)
5 CONTINUE
IF(IU .EQ. 0) THEN
WRITE(6,3)
3 FORMAT('NO DETECTIONS: PROGRAM IS TERMINATED')
STOP
ENDIF
CALL SORT1(IWRK1,Z1,ZU,IU,1,ITEMP,SWRK1,MVAR)
C
IF(IC .NE. 0) CALL SORT1(IWRK1,Z1,ZC,IC,1,ITEMP,SWRK1,MVAR)
C
C >>>> Bug fixed Sept. 1996. NCH was missing from following line <<<<
CALL PLESTM(ZU, ZC, IU, IC, PL, V, NTOT,SMEAN,SIGM,ICH,NCH,IWRK1)
C
C * IF THE DATA CONTAINS CENSORED DATA POINTS, THE PRODUCT LIMIT *
C * ESTIMATOR MUST BE ADJUSTED TO INCLUDE CENSORED DATA POINTS. *
C
IF(IC .NE. 0) THEN
C * IF THE DATA HAS UPPER LIMITS, FIRST THE PRODUCT LIMIT ESTIMATOR*
C * MUST BE ADJUSTED. *
IF(ISIGN .LT. 0) THEN
FMASS(1) = 1.0 - PL(1)
DO 10 I = 2, IU
FMASS(I) = PL(I-1)-PL(I)
10 CONTINUE
J = IU/2
DO 20 I = 1, J
FTEMP=FMASS(I)
FMASS(I)=FMASS(IU-I+1)
FMASS(IU-I+1)=FTEMP
20 CONTINUE
DO 40 I = 1, IU
PTEMP(I) = 1.0
DO 30 J = 1, I
PTEMP(I)=PTEMP(I)-FMASS(J)
30 CONTINUE
40 CONTINUE
ELSE
DO 50 I = 1, IU
PTEMP(I)=PL(I)
50 CONTINUE
ENDIF
C * NOW, PRODUCT LIMIT ESTIMATOR VALUES ARE ASSIGNED TO CENSORED *
C * DATA POINTS. *
IF(IND(IP,1) .EQ. 0) THEN
PL(1) = PTEMP(1)
J = 1
ELSE
PL(1) = 1.0
J = 0
ENDIF
DO 60 I = 2, NTOT
IF(IND(IP, I) .EQ. 0) THEN
J = J + 1
PL(I) = PTEMP(J)
ELSE
PL(I) = PL(I-1)
ENDIF
60 CONTINUE
ENDIF
C * THE PRODUCT LIMIT ESTIMATE IS NOW USED TO ESTIMATE THE *
C * DISTRIBUTION FUNCTION (F) AT ALL POINTS. *
DO 65 I = 1, NTOT
F(I) = 1.0 - PL(I)
65 CONTINUE
C
C * COMPUTE HERE AKRITAS' RANK USING F-VALUES *
C
DO 90 I = 1, NTOT
IF(IND(IP, I) .EQ. 0) THEN
R(IP, I) = REAL(NTOT)*F(I)
ELSEIF(IND(IP, I) .GT. 0) THEN
R(IP, I) = REAL(NTOT)*(0.5 + 0.5*F(I))
ELSE
R(IP, I) = NTOT*(0.5*F(I))
ENDIF
90 CONTINUE
RETURN
END
C
C **********************************************************************
C ******************** SUBROUTINE ARISK *******************************
C **********************************************************************
C
SUBROUTINE ARISK(R,XM,X,E1,NG,H,XY,ID1,NTOT)
C
C
C * THIS SUBROUTINE COMPUTES THE FOLLOWING FOUR *
C * ARRAYS FOR SUBROUTINE COX, LRANK, AND PWLCXN. *
C * R(I) : NO. OF OBSERVATIONS IN RISK SET AT THE *
C * I-TH DISTINCT FAILURE TIME. *
C * XM(I) : MULTIPLICITY OF THE I-TH DISTINCT *
C * FAILURE TIME. *
C * E1(I) : XM(I)/R(I) *
C * H(I) : KAPLAN AND MEIER'S ESTIMATES OF THE *
C * SURVIVOR FUNCTION *
C * *
C * X(I) : THE ARRAY OF DISTINCT FAILURE TIMES *
C * NG : NO OF X *
C * THIS SUBROUTINE IS OBTAINED FROM ELISA T. LEE, "STATISTICAL *
C * METHODS FOR SURVIVAL DATA ANALYSIS", 1980, LIFETIME LEARNING *
C * PUBLICATIONS (BELMONT:CA); BUT HAS BEEN SIGNIFICANTLY MODIFIED. *
C * *
C
IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N)
DIMENSION R(NTOT),XM(NTOT),X(NTOT),H(NTOT),E1(NTOT)
DIMENSION XY(NTOT),ID1(NTOT)
COMMON /G/ NCOMP,N1,N2,NCEN,ISIGN,IFULL,LO
C
L=1
I=1
R(L)=REAL(NCOMP)
C
C * COMPUTE RISK SETS, AND OTHER QUANTITIES *
C
24 IF(ID1(I).NE.0) THEN
R(L)=R(L)-1.0
I=I+1
GOTO 24
ENDIF
25 XM(L)=1.0
XNC=0.0
TEMP=XY(I)
X(L)=TEMP
21 IF(I.NE.NCOMP) THEN
I=I+1
C
IF(ID1(I).NE.1) THEN
IF(TEMP.NE.XY(I)) GOTO 20
XM(L)=XM(L)+1.0
GOTO 21
ENDIF
26 XNC=XNC+1.0
X(L)=TEMP
GOTO 21
20 L=L+1
R(L)=R(L-1)-XM(L-1)-XNC
GOTO 25
ENDIF
23 X(L)=TEMP
NG=L
C
C * COMPUTE KM ESTIMATOR *
DO 30 I=1,NG
E1(I)=XM(I)/R(I)
30 CONTINUE
H(1)=1.0
NG1=NG+1
DO 31 I=2,NG1
H(I)=H(I-1)*(1.0-E1(I-1))
31 CONTINUE
RETURN
END
C
C
C * ASURV: SURVIVAL ANALYSIS PACKAGE FOR ASTRONOMERS *
C * *
C * DEVELOPED BY: TAKASHI ISOBE *
C * CENTER FOR SPACE RESEARCH *
C * THE MASSACHUSETTS INSTITUTE OF TECHNOLOGY *
C * *
C * MICHAEL LAVALLEY *
C * DEPARTMENT OF STATISTICS *
C * THE PENSYLVANIA STATE UNIVERSITY *
C * 330A CLASSROOM BUILDING, UNIVERSITY PARK PA 16802 *
C * INTERNET: MLV@STAT.PSU.EDU *
C * *
C * ERIC FEIGELSON *
C * DEPARTMENT OF ASTRONOMY AND ASTROPHYSICS *
C * THE PENSYLVANIA STATE UNIVERSITY *
C * 525 DAVEY LAB. UNIVERSITY PARK PA 16802 *
C * *
C * REV. 1.2 SECOND UPDATE SUMMER 1992 *
C * *
C * THIS PACKAGE IS WRITTEN TO PROVIDE SEVERAL *
C * SURVIVAL ANALYSIS METHODS WHICH ARE USEFUL IN ANALYZING *
C * ASTRONOMICAL DATA. SURVIVAL ANALYSIS IS A GROUP OF STATISTICAL *
C * METHODS WHICH TREAT PROBLEMS WITH CENSORED DATA (UPPER OR LOWER *
C * LIMITS). THIS PACKAGE INCLUDES SOME TECHNIQUES DEVELOPED IN *
C * IN OTHER FIELDS (E.G. ECONOMICS, ACTUARIAL SCIENCE, RELIABILITY *
C * MATHEMATICS), AND A FEW METHODS DEVELOPED BY ASTRONOMERS. *
C * *
C * THE METHODS PROVIDED IN THIS PACKAGE ARE : *
C * *
C * UNIVARIATE DISTRIBUTION : KAPLAN-MEIER ESTIMATOR *
C * TWO-SAMPLE TESTS : GEHAN TEST *
C * LOGRANK TEST *
C * PETO AND PETO TEST *
C * PETO AND PRENTICE TEST *
C * CORRELATION TESTS : COX PROPORTIONAL HAZARDS MODEL *
C * GENERALIZED KENDALL'S TAU (BHK METHOD)*
C * GENERALIZED SPEARMAN'S RHO *
C * (AKRITAS' METHOD) *
C * LINEAR REGRESSIONS : EM ALGORITHM WITH NORMAL DISTRIBUTION *
C * BUCKLEY-JAMES METHOD *
C * TWO-DIMENSIONAL KAPLAN-MEIER *
C * REGRESSION FOR DUAL-CENSORED DATA *
C * *
C * *
C * INPUTS *
C * *
C * IS0 : IF 1 : UNIVARIATE PROBLEM *
C * 2 : CORRELATION/REGRESSION PROBLEM *
C * 3 : EXIT *
C * *
C * SUBROUTINES DATA1, UNIVAR, BIVAR *
C
IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N)
CHARACTER*1 BLANK
C OPEN(6,CARRIAGECONTROL='LIST',STATUS='OLD')
C
C
C
PRINT *
PRINT *,' ***************************************************'
PRINT *,' * *'
PRINT *,' * WELCOME TO ASURV *'
PRINT *,' * SURVIVAL ANALYSIS PACKAGE *'
PRINT *,' * FOR ASTRONOMERS *'
PRINT *,' * *'
PRINT *,' * DEVELOPED BY: *'
PRINT *,' * TAKASHI ISOBE *'
PRINT *,' * (CENTER FOR SPACE RESEARCH, MIT) *'
PRINT *,' * MICHAEL LAVALLEY *'
PRINT *,' * (DEPT. OF STATISTICS, PENN STATE) *'
PRINT *,' * ERIC FEIGELSON *'
PRINT *,' * (DEPT. OF ASTRONOMY & ASTROPHYSICS, PENN STATE) *'
PRINT *,' * *'
PRINT *,' * *'
PRINT *,' * REV 1.2 SUMMER 1992 *'
PRINT *,' ***************************************************'
PRINT *
PRINT *
PRINT *
PRINT *
PRINT *,' (CARRIAGE RETURN TO CONTINUE) '
READ(5,50) BLANK
50 FORMAT(A1)
PRINT *
C
C * START CONVERSATION WITH THE USER *
C
PRINT *
PRINT *
PRINT *
100 PRINT *,' MENU '
PRINT *
PRINT *
PRINT *,' UNIVARIATE DATA BIVARIATE DATA '
PRINT *
PRINT *
PRINT *,' DISTRIBUTION FUNCTION CORRELATION '
PRINT *,' 1 KAPLAN-MEIER ESTIMATOR 1 COX REGRESSION '
PRINT *,' 2 GEN. KENDALL TAU'
PRINT *,' 3 GEN. SPEARMAN RHO'
PRINT *
PRINT *
PRINT *,' TWO-SAMPLE TESTS LINEAR REGRESSION '
PRINT *,' 1 GEHAN TESTS 1 EM ALGORITHM WITH '
PRINT *,' 2 LOGRANK TEST GAUSSIAN RESIDUALS '
PRINT *,' 3 PETO AND PETO TEST 2 BUCKLEY-JAMES METHOD '
PRINT *,' 4 PETO AND PRENTICE TEST WITH KM RESIDUALS '
PRINT *,' 3 SCHMITT METHOD FOR '
PRINT *,' DUAL CENSORED DATA '
PRINT *
PRINT *
PRINT *
PRINT *,' (CARRIAGE RETURN TO CONTINUE) '
READ(5,50) BLANK
C
PRINT *
C
C * CHOICE : UNIVARIATE PROBLEM OR CORRELATION/REGRESSION PROBLEM *
C
PRINT *
PRINT *,' SELECT DATA TYPE: '
PRINT *,' 1 UNIVARIATE DATA '
PRINT *,' 2 BIVARIATE DATA '
PRINT *,' 3 EXIT '
200 WRITE(6,210)
210 FORMAT(' CHOICE ? ')
C 210 FORMAT(' CHOICE ? ',$)
C
CALL DATA1(IS0)
C
IF((IS0.EQ.1).OR.(IS0.EQ.2).OR.(IS0.EQ.3)) GOTO 300
PRINT *,'PLEASE TYPE ONCE MORE'
GOTO 200
C
300 IBACK=0
IF(IS0.EQ.1) CALL UNIVAR(IBACK)
IF(IS0.EQ.2) CALL BIVAR(IBACK)
IF(IS0.EQ.3) STOP
C
IF(IBACK.EQ.1) GOTO 100
STOP
END
C
C **********************************************************************
C ********************** SUBROUTINE BHK *******************************
C **********************************************************************
C
SUBROUTINE BHK(IND,XX,YY,NTOT,OUTPUT,X,Y,IAA,IBB,IP,MVAR)
C
C * GENERALIZED KENDALL'S TAU CORRELATION COEFFICIENT *
C * FOR CENSORED DATA *
C
C * THIS PROGRAM COMPUTES KENDALL'S TAU FOR BIVARIATE DATA *
C * SETS. THE DATA SETS CAN CONTAIN CENSORED POINTS IN THE *
C * INDEPENDENT VARIABLE AND/OR THE DEPENDENT VARIABLE. *
C * ALTHOUGH THIS PROGRAM GIVES ANSWERS FOR DATA SETS WHICH *
C * CONTAIN TIES, IT MAY NOT BE ACCURATE. *
C * PARAMETERS : *
C * INPUT *
C * NTOT : NUMBER OF OBSERVATIONS *
C * XX(1,I) : INDEPENDENT PARAMETER OF I-TH OBSERVATION *
C * YY(I) : DEPENDENT PARAMETER OF I-TH OBSERVATION *
C * IND(I) : INDICATOR OF CENSORED STATUS *
C * EACH POINT MUST BE SPECIFIED ITS CENSORED STATUS : *
C * FOR THE LOWER LIMITS *
C * 0 : DETECTED POINT *
C * 1 : ONLY DEPENDENT VARIABLE IS LOWER LIMIT *
C * 2 : ONLY INDEPENDENT VARIABLE IS LOWER LIMIT *
C * 3 : BOTH VARIABLES ARE LOWER LIMIT *
C * 4 : INDEPENDENT VARIABLE IS LOWER LIMIT AND *
C * DEPENDENT VARIABLE IS UPPER LIMIT *
C * FOR THE UPPER LIMITS, CHANGE THE SIGN OF ABOVE INDICATORS. *
C * *
C * WORK *
C * X(I) : =XX(1,I) *
C * Y(I) : =YY(I) *
C * IP(I) : =IND(I) *
C * IAA(I) : CONCORDANCE INFORMATION FOR X *
C * IBB(I) : CONCORDANCE INFORMATION FOR Y *
C * OUTPUT *
C * PROB : SIGNIFICANCE LEVEL FOR THE HYPOTHESIS THAT *
C * X AND Y ARE NOT CORRELATED UNDER THE *
C * GAUSSIAN DISTRIBUTION *
C * *
C * SUBROUTINES *
C * CENS, COEFF *
C * *
C * REF. BROWN, HOLLANDER, AND KORWAR 1974, IN RELIABILITY *
C * AND BIOMETRY P.327, EQNS 1 TO 8, PROSCHAN AND *
C * SERFLING EDS (SIAM) *
C
C * NOTE: THIS PROGRAM IS QUITE CPU INTENSIVE FOR LARGE DATA *
C * SETS (MORE THAN A FEW HUNDRED POINTS). *
C * *
IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N)
DIMENSION XX(MVAR,NTOT),YY(NTOT),IND(NTOT),X(NTOT),Y(NTOT)
DIMENSION IP(NTOT),IAA(NTOT),IBB(NTOT)
CHARACTER*9 OUTPUT
C
SIS =0.0
ASUM =0.0
BSUM =0.0
AASUM=0.0
BBSUM=0.0
C
C * SUBSTITUE XX AND YY TO X AND Y SO THAT THE ORIGINAL VALUES *
C * WON'T BE CHANGED. *
C
DO 90 I=1,NTOT
X(I) = XX(1,I)
Y(I) = YY(I)
IP(I) = IND(I)
90 CONTINUE
C
C
C * THE SUBROUTINE CENS ADDS OR SUBTRACTS A SMALL NUMBER *
C * FROM EACH CENSORED POINT SO THAT NO TIES WITH DETECTED *
C * POINTS OCCUR. *
C
C
CALL CENS(X,Y,IP,NTOT)
C
C
C * START MAKING INFORMATION FOR CONCORDANCE *
C
C
DO 1900 I=1,NTOT
C
C * INFORMATION OF CONCORDANCE FOR THE INDEPENDENT VAR. *
C
IA=2
IB=3
IC=4
ID=-2
IE=-3
IG=-4
IH=1
IJ=-1
C
C * SUBROUTINE WHICH FINDS CONCORDANCE INFORMATION *
C
CALL COEFF(I,X,IP,NTOT,IAA,IA,IB,IC,ID,IE,IG,IH,IJ)
C
C * INFORMATION OF CONCORDANCE FOR THE DEPENDENT VAR. *
C
IA=1
IB=3
IC=-4
ID=-1
IE=-3
IG=4
IH=2
IJ=-2
CALL COEFF(I,Y,IP,NTOT,IBB,IA,IB,IC,ID,IE,IG,IH,IJ)
C
C * START COMPUTING QUANTITIES IS, IASUM, IBSUM, *
C * IAASUM, AND IBBSUM. *
C
DO 1800 J=1,NTOT
IF((IAA(J).EQ.0).AND.(IBB(J).EQ.0)) GOTO 1800
SIS=SIS+IAA(J)*IBB(J)
ASUM=ASUM+IAA(J)**2
BSUM=BSUM+IBB(J)**2
1650 DO 1700 K=1,NTOT
IF(IAA(J).NE.0) THEN
IF(IAA(K).NE.0) THEN
AASUM=AASUM+IAA(J)*IAA(K)
ENDIF
ENDIF
1670 IF(IBB(J).NE.0) THEN
IF(IBB(K).NE.0) THEN
BBSUM=BBSUM+IBB(J)*IBB(K)
ENDIF
ENDIF
1700 CONTINUE
1800 CONTINUE
1900 CONTINUE
C
C * NOW COMPUTE THE STATISTIC AND THE PROBABILITY *
C
D1=REAL(NTOT*(NTOT-1))
D2=REAL(D1*(NTOT-2))
ALP=2.0*(ASUM*BSUM)/D1
GAM=4.0*((AASUM-ASUM)*(BBSUM-BSUM))/D2
VAR=ALP+GAM
SIGMA=DSQRT(VAR)
Z=SIS/SIGMA
PROB=1.0-AGAUSS(Z)
C
IF(OUTPUT.EQ.' ') THEN
WRITE(6,2030)
WRITE(6,2003)
WRITE(6,2030)
WRITE(6,2005) Z
WRITE(6,2007) PROB
WRITE(6,2030)
ELSE
WRITE(60,2030)
WRITE(60,2003)
WRITE(60,2030)
WRITE(60,2005) Z
WRITE(60,2007) PROB
WRITE(60,2030)
ENDIF
2003 FORMAT(5X,'CORRELATION TEST BY GENERALIZED KENDALL`S TAU')
2005 FORMAT(7X,'Z-VALUE =',F12.3)
2007 FORMAT(7X,'PROBABILITY =',F13.4,/,
+ ' (PROBABILITY THAT A CORRELATION IS NOT PRESENT)')
2030 FORMAT(' ')
RETURN
END
C
C **********************************************************************
C ********************** SUBROUTINE BIN *******************************
C **********************************************************************
C
SUBROUTINE BIN(NTOT,MX,MY,ISKIP,ICENS,DELX,DELY,XORG,YORG,MM,
+ M1,M2,M3,M4,M5,M6,M7,M8,INDEX,LP,XT,YT,Z,SWRK1,
+ X,Y,NP,XB,YB,F,N,N1,N2,N3,N4,N5,N6,N7,N8,IB,MVAR)
C
C
C * *
C * THIS SUBROUTINE DOES BINNING AND CHANGES CENSORED POINTS *
C * WHICH DO NOT HAVE DETECTED POINTS ABOVE (OR BELOW) *
C * TO DETECTED POINTS. *
C * *
C * WARNING WARNING WARNING WARNING *
C * *
C * THE USER SHOULD BE WARNED THAT THIS SUBROUTINE ACTUALLY *
C * CHANGES THE DATA!! FIRST, IT REDEFINES SOME LIMITS TO *
C * DETECTIONS. IF THE BINS ARE CHOSEN TO BE TOO NARROW, THEN *
C * VIRTUALLY ALL LIMITS COULD BE CHANGED. SECOND, IT PUSHES *
C * EACH LIMIT INTO THE ADJACENT BIN. IF THE BINS ARE CHOSEN TO *
C * TO BE TOO WIDE, THIS SUBSTANTIALLY ALTERS THE MEASURED VALUES. *
C * THUS, THE USER MUST TREAD A FINE LINE IN CHOSING BIN SIZES. *
C * *
C * *
C * INPUT *
C * X(I) : INDEPENDENT VARIABLE *
C * Y(I) : DEPENDENT VARIABLE *
C * NP(I) : INDICATOR OF CENSORING *
C * NTOT : TOTAL NUMBER OF DATA *
C * MX : NUMBER OF BINS IN X *
C * MY : NUMBER OF BINS IN Y *
C * ISKIP : INDICATOR OF BINNING PROCESS *
C * ICENS : CENSORING STATUS OF THE DATA SET *
C * IF ISKIP>0, THE NEXT VALUES MUST BE PROVIDED : *
C * DELX : BIN SIZE OF X AXIS *
C * DELY : BIN SIZE OF Y AXIS *
C * XORIG : ORIGIN OF X *
C * YORIG : ORIGIN OF Y *
C * *
C * WORK *
C * YT(I) : COPY OF Y(I) FOR SORTING PROGRAM. *
C * M1 : # OF Y LOWER LIMITS CHANGED TO DETECTIONS *
C * M2 : # OF X LOWER LIMITS CHANGED TO DETECTIONS *
C * M3 : # OF DOUBLE LOWER LIMITS CHANGED TO *
C * DETECTIONS *
C * M4 : # OF Y LOWER , X UPPER LIMITS CHANGED TO *
C * DETECTIONS *
C * M5 : # OF Y UPPER LIMITS CHANGED TO DETECTIONS *
C * M6 : # OF X LOWER LIMITS CHANGED TO DETECTIONS *
C * M7 : # OF DOUBLE UPPER LIMITS CHANGED TO *
C * DETECTIONS *
C * M8 : # OF Y UPPER , X LOWER LIMITS CHANGED TO *
C * DETECTIONS *
C * NC1, NC2,...,NC8 : # OF CENSORED POINTS. SEE THE *
C * MAIN PROGRAM FOR THE DEFINITIONS *
C * IB : DIMENSION SIZE OF BINS *
C * *
C * OUTPUT *
C * F(I,J): INITIAL GUESS OF THE PROBABILITY OF THE *
C * BIN(I,J) *
C * N(I,J): NUMBER OF DETECTED POINTS IN THE BIN(I,J) *
C * N1(I,J): NUMBER OF Y LOWER LIMITS IN THE BIN(I,J) *
C * N2(I,J): NUMBER OF X LOWER LIMITS IN THE BIN(I,J) *
C * N3(I,J): NUMBER OF DOUBLE LOWER LIMITS IN THE BIN(I,J) *
C * N4(I,J): NUMBER OF Y LOWER, X UPPER LIMITS IN THE *
C * BIN(I,J) *
C * N5(I,J): NUMBER OF Y UPPER LIMITS IN THE BIN(I,J) *
C * N6(I,J): NUMBER OF X UPPER LIMITS IN THE BIN(I,J) *
C * N7(I,J): NUMBER OF DOUBLE UPPER LIMITS IN THE BIN(I,J) *
C * N8(I,J): NUMBER OF Y UPPER, X LOWER LIMITS IN THE *
C * BIN(I,J) *
C * XB(I) : COORDINATE OF CENTER OF THE BIN IN X *
C * YB(I) : COORDINATE OF CENTER OF THE BINS IN Y *
C * IF ISKIP=0, THE NEXT VALUES ARE OUTPUTS : *
C * DELX : BIN SIZE OF X AXIS *
C * DELY : BIN SIZE OF Y AXIS *
C * XORIG : ORIGIN OF X *
C * YORIG : ORIGIN OF Y *
C * *
C * SUBROUTINES *
C * SORT1 *
C * *
C
IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N)
DIMENSION INDEX(NTOT),LP(NTOT),XT(NTOT),YT(NTOT),Z(MVAR,NTOT)
DIMENSION X(NTOT),Y(NTOT),NP(NTOT),XB(IB),YB(IB),SWRK1(MVAR)
DIMENSION F(IB,IB),N(IB,IB),N1(IB,IB),N2(IB,IB),N3(IB,IB)
DIMENSION N4(IB,IB),N5(IB,IB),N6(IB,IB),N7(IB,IB),N8(IB,IB)
COMMON /C1/NC1,NC2,NC3,NC4,NC5,NC6,NC7,NC8
C
C
C * SUBSTITUE NP, X, AND Y TO LP, XT, AND YT SO THAT THE ORIGINAL DATA*
C * WON'T BE CHANGED. *
C
DO 100 J=1,NTOT
LP(J)=NP(J)
XT(J)=X(J)
YT(J)=Y(J)
Z(1,J)=1.0
100 CONTINUE
C
C * CALL THE SUBROUTINE SORT1, AND FIND MIN. AND MAX. OF X AND Y. *
C * IF ISKIP=0, THE ORIGIN AND BIN SIZES ARE ALREADY GIVEN *
C
IF(ISKIP.EQ.0) THEN
C
C * SORTING X *
C
CALL SORT1(LP,Z,XT,NTOT,1,INDEX,SWRK1,MVAR)
C
C * SORTING Y *
C
CALL SORT1(LP,Z,YT,NTOT,1,INDEX,SWRK1,MVAR)
C
C * FIND THE SIZES OF BINS *
C
DELX=XT(NTOT)-XT(1)
DELY=YT(NTOT)-YT(1)
DELX=DELX/FLOAT(MX-2)
DELY=DELY/FLOAT(MY-2)
C
C * FIND THE ORIGIN OF THE GRID *
C
XORG=XT(1)-1.5*DELX
YORG=YT(1)-1.5*DELY
ENDIF
C
C
C * INITIALIZE N, N1,....,N8, AND F *
C
DO 300 I=1,MX
DO 200 J=1,MY
N(I,J) =0
N1(I,J)=0
N2(I,J)=0
N3(I,J)=0
N4(I,J)=0
N5(I,J)=0
N6(I,J)=0
N7(I,J)=0
N8(I,J)=0
F(I,J)=0.0
200 CONTINUE
300 CONTINUE
C
DO 390 I=1,NTOT
C
C * FIND POSITION OF I-TH DATA POINT IN THE GRID AND COUNT *
C * NUMBERS OF N,N1,N2,.....,N8. *
C
IP=INT((X(I)-XORG)/DELX)+1
JP=INT((Y(I)-YORG)/DELY)+1
C
C * FOR CONVENIENCE CENSORED POINTS ARE ASSIGNED TO THE NEXT BIN *
C
C
C * DETECTIONS *
C
IF(NP(I).EQ.0) THEN
N(IP,JP)=N(IP,JP)+1
C
C * Y LOWER LIMITS *
C
ELSEIF(NP(I).EQ.1) THEN
N1(IP,JP+1)=N1(IP,JP+1)+1
C
C * X LOWER LIMITS *
C
ELSEIF(NP(I).EQ.2) THEN
N2(IP+1,JP)=N2(IP+1,JP)+1
C
C * DOUBLE LOWER LIMITS *
C
ELSEIF(NP(I).EQ.3) THEN
N3(IP+1,JP+1)=N3(IP+1,JP+1)+1
C
C * Y LOWER LIMITS, X UPPER LIMITS *
C
ELSEIF(NP(I).EQ.4) THEN
N4(IP+1,JP-1)=N4(IP+1,JP-1)+1
C
C * Y UPPER LIMITS *
C
ELSEIF(NP(I).EQ.-1) THEN
N5(IP,JP-1)=N5(IP,JP-1)+1
C
C * X UPPER LIMITS *
C
ELSEIF(NP(I).EQ.-2) THEN
N6(IP-1,JP)=N6(IP-1,JP)+1
C
C * DOUBLE UPPER LIMITS *
C
ELSEIF(NP(I).EQ.-3) THEN
N7(IP-1,JP-1)=N7(IP-1,JP-1)+1
C
C * Y UPPER LIMITS, X LOWER LIMITS *
C
ELSEIF(NP(I).EQ.-4) THEN
N8(IP-1,JP+1)=N8(IP-1,JP+1)+1
ELSE
PRINT *,' THE CENSORSHIP INDICATOR IS NOT RECOGNIZED'
RETURN
ENDIF
390 CONTINUE
C
C * SET THE COORDINATES OF THE EACH BIN *
C
DO 410 I=1,MX
XB(I)=XORG+DELX/2.0+DELX*(I-1)
410 CONTINUE
DO 420 I=1,MY
YB(I)=YORG+DELY/2.0+DELY*(I-1)
420 CONTINUE
C
C * START CHECKING THE RELATION BETWEEN CENSORED POINTS AND *
C * DETECTED POINTS. IF THE CENSORED POINTS ARE LOCATED SO *
C * THAT THEY CANNOT GIVE WEIGHT TO DETECTED POINTS, THE *
C * CENSORED POINTS ARE CHANGED TO DETECTIONS. *
C
M1=0
M2=0
M3=0
M4=0
M5=0
M6=0
M7=0
M8=0
C
C
C * Y LOWER LIMITS *
C
IF(NC1.NE.0) THEN
DO 600 I=1,MX
DO 500 J=1,MY
JJ=MY-J+1
IF(N1(I,JJ).NE.0) THEN
K=JJ
450 IF(N(I,K).EQ.0) THEN
K=K+1
IF(K.LE.MY) GOTO 450
M1=M1+N1(I,JJ)
N(I,JJ)=N(I,JJ)+N1(I,JJ)
N1(I,JJ)=0
ENDIF
ENDIF
500 CONTINUE
600 CONTINUE
ENDIF
C
C
C * X LOWER LIMITS *
C
IF(NC2.NE.0) THEN
DO 800 J=1,MY
DO 700 I=1,MX
II=MX-I+1
IF(N2(II,J).NE.0) THEN
L=II
650 IF(N(L,J).EQ.0) THEN
L=L+1
IF(L.LE.MX) GOTO 650