/* -------------------------------------------------------------------------- This macro program is used to produce an ASCII file a0.dat, i.e., the A_0 matrix to be pasted in place of A_0 in sample program emma.sas. Please refer to the Biometrics paper "Weighted least squares approach for comparing correlated Kappa" by Huiman X. Barnhart and John M. Williamson. -------------------------------------------------------------------------*/ %macro a0(J=); /* J -- J is the number of categories of the response variable This program outputs data file a0.dat to be pasted in PROC CATMOD for estimating kappa statistics */ %let tcol=%eval(&J*&J*&J*&J); proc iml; A0=j(2*&J*&J,&J*&J*&J*&J,0); do i=1 to &J*&J; do k=1 to &J*&J; A0[i,(i-1)*&J*&J+k]=1; A0[i+&J*&J,i+(k-1)*&J*&J]=1; end; end; create A0 from A0; append from A0; run; data _null_; set a0; file a0; if _n_ < 2*&J*&J then put col1-col&tcol ','; if _n_ = 2*&J*&J then put col1-col&tcol ';'; run; %mend a0; *************************************************************** /* -------------------------------------------------------------------------- This program is used to produce the WLS analyses for the cervical ectopy study used in the Biometrics paper "Weighted least squares approach for comparing correlated Kappa" by Huiman X. Barnhart and John M. Williamson. 1. Run the macro a0.mac to output A_0 matrix file a0.dat to be pasted in place of A_0 in the PROC CATMOD. Please run the program after pasting. 2. Data set cerv contains the data with one subject per line. id - subject id y11 - visual assessment of rater 1 y12 - visual assessment of rater 2 y21 - Computerized planimetry reading of rater 1 y22 - Computerized planimetry reading of rater 2 -------------------------------------------------------------------------*/ %include 'a0.mac'; %a0(J=4); run; data cerv; input id y11 y12 y21 y22; cards; 1 4 4 3 4 2 1 1 1 1 3 2 1 1 1 4 3 3 2 3 5 1 2 1 3 6 1 1 1 1 7 2 2 2 2 8 3 2 2 2 9 4 3 3 2 10 2 2 1 1 11 2 1 1 1 12 4 4 3 2 13 4 2 1 1 14 1 2 1 1 15 4 4 4 4 16 4 4 4 4 17 4 2 2 2 18 2 2 1 1 19 2 2 1 1 20 4 2 2 2 21 4 4 4 3 22 4 3 3 3 23 1 1 1 1 24 4 1 1 1 25 2 1 2 1 26 4 2 2 2 27 4 4 4 4 28 2 2 1 1 29 2 2 3 1 30 4 3 4 4 31 4 4 4 4 32 2 3 2 2 33 3 1 2 2 34 4 3 2 2 35 1 1 1 1 36 1 1 1 1 37 4 3 2 2 38 1 1 1 1 39 1 1 2 2 40 4 4 4 4 41 3 2 2 2 42 4 3 2 2 43 1 1 1 1 44 1 1 1 1 45 4 4 4 4 46 2 2 1 1 47 3 1 2 3 48 2 2 1 1 49 3 2 2 2 50 3 2 3 2 51 4 3 4 3 52 1 1 1 1 53 2 2 2 1 54 2 2 2 1 55 2 1 1 1 56 4 3 2 2 57 4 4 4 4 58 4 3 3 2 59 3 3 2 2 60 4 3 1 1 61 2 2 2 1 62 3 2 2 1 63 2 1 1 1 64 2 1 1 1 65 2 2 1 1 66 4 3 2 1 67 1 1 2 2 68 1 1 2 1 69 2 2 1 1 70 2 1 1 1 71 2 3 2 2 72 2 1 2 2 73 1 1 1 1 74 2 2 2 2 75 4 4 4 2 76 3 2 2 2 77 4 3 2 2 78 2 3 2 2 79 3 1 2 3 80 2 1 1 1 81 3 3 2 2 82 2 1 1 2 83 2 2 1 1 84 3 2 2 2 85 2 2 2 2 ; run; /* compute Cohen's kappa */ proc catmod data=cerv; response exp 1 -1 0 0, /* A_4 */ 0 0 1 -1 log -1 -1 -1 -1 1 0 0 0 0 0 0 0, -1 -1 -1 -1 0 1 0 0 0 0 0 0, /* A_3 */ 0 0 0 0 0 0 -1 -1 -1 -1 1 0, 0 0 0 0 0 0 -1 -1 -1 -1 0 1 exp 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0, 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0, 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0, 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0, 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0, 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0, /* A_2 */ 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 * A_0 /* one should replace A_0 here with file A0.dat */ /* missing=1e-20 forces zero cell as sampling zero */ model y11*y12*y21*y22=(1 0, 0 1) (1='kappa for visual assessment', 2='kappa for computerized planimetry') /missing=1e-20 corrb; contrast "equal Cohen's kappas" all_parms 1 -1; run; /* Compute weighted kappa using Fleiss and Cohen's weights */ proc catmod data=cerv; response exp 1 -1 0 0, /* A_4 */ 0 0 1 -1 log -1 -0.8889 -0.5559 0 -0.8889 -1 -0.8889 -0.5559 /* A_3 */ -0.5559 -0.8889 -1 -0.8889 0 -0.5559 -0.8889 -1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0, -1 -0.8889 -0.5559 0 -0.8889 -1 -0.8889 -0.5559 -0.5559 -0.8889 -1 -0.8889 0 -0.5559 -0.8889 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0, 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -0.8889 -0.5559 0 -0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y22=(1 0, 0 1) (1='kappa for visual assessment', 2='kappa for computerized planimetry') /missing=1e-20 corrb; contrast "equal weighted kappas" all_parms 1 -1; run; *************************************************************** /* -------------------------------------------------------------------------- This program is used to produce the WLS analyses for the ophthalmology study used in the Biometrics paper "Weighted least squares approach for comparing correlated Kappa" by Huiman X. Barnhart and John M. Williamson. -------------------------------------------------------------------------*/ options ls=80; data eye; input y11 y12 y21 y22 count; if count=0 then count=1e-20; /* treat frequency 0 as sampling zero */ cards; /* y11=left eye and 1st rater, y12=left eye and 2nd rater */ 0 0 0 0 800 /* y21=right eye and 1st rater, y22=right eye and 2nd rater */ 0 0 0 1 9 0 0 1 0 3 0 0 1 1 5 0 1 0 0 10 0 1 0 1 2 0 1 1 0 0 0 1 1 1 0 1 0 0 0 4 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0 0 2 1 1 0 1 0 1 1 1 0 0 1 1 1 1 4 ; run; /* compute Cohen's kappa */ proc catmod data=eye; weight count; response exp 1 -1 0 0, /* A_4 */ 0 0 1 -1 log -1 -1 1 0 0 0 0 0, -1 -1 0 1 0 0 0 0, /* A_3 */ 0 0 0 0 -1 -1 1 0, 0 0 0 0 -1 -1 0 1 exp 1 0 1 0 0 0 0 0 0 0 0 0, 0 1 0 1 0 0 0 0 0 0 0 0, 0 0 0 0 1 0 0 0 0 0 0 0, 0 0 0 0 0 1 0 0 0 0 0 0, /* A_2 */ 0 0 0 0 0 0 1 0 1 0 0 0, 0 0 0 0 0 0 0 1 0 1 0 0, 0 0 0 0 0 0 0 0 0 0 1 0, 0 0 0 0 0 0 0 0 0 0 0 1 log 1 1 0 0 0 0 0 0, 0 0 1 1 0 0 0 0, 1 0 1 0 0 0 0 0, 0 1 0 1 0 0 0 0, 1 0 0 1 0 0 0 0, 1 1 1 1 0 0 0 0, /* A_1 */ 0 0 0 0 1 1 0 0, 0 0 0 0 0 0 1 1, 0 0 0 0 1 0 1 0, 0 0 0 0 0 1 0 1, 0 0 0 0 1 0 0 1, 0 0 0 0 1 1 1 1 * 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0, 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0, 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0, 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1, /* A_0 */ 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0, 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0, 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0, 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1; model y11*y12*y21*y22=(1 0, 0 1) (1='Kappa1 for left eye', 2='Kappa2 for right eye')/corrb; /* model left1*left2*right1*right2=(1, 1)(1='Common kappa')/corrb; */ /* the last model statement can replace the previous one */ /* to estimate common kappa */ contrast "equal cohen's kappas" all_parms 1 -1; run; *************************************************************** /* -------------------------------------------------------------------------- This program is used to produce the WLS analyses for the pathology data used in the Biometrics paper "Weighted least squares approach for comparing correlated Kappa" by Huiman X. Barnhart and John M. Williamson. -------------------------------------------------------------------------*/ options ls=80; data path; input y11 y12 y21 y22 count; cards; 0 0 0 0 9 0 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 4 1 0 0 1 0 1 0 1 0 1 1 0 1 1 1 1 1 0 0 6 1 1 0 1 0 1 1 1 0 0 1 1 1 1 4 ; run; /* compute intraclass kappa */ proc catmod data=path; weight count; response exp 1 -1 0 0, /* A_4 */ 0 0 1 -1 log -1 -1 1 0 0 0 0 0, -1 -1 0 1 0 0 0 0, /* A_3 */ 0 0 0 0 -1 -1 1 0, 0 0 0 0 -1 -1 0 1 exp 2 0 0 0 0 0 0 0, 0 2 0 0 0 0 0 0, 0 0 1 0 0 0 0 0, 0 0 0 1 0 0 0 0, /* A_2 */ 0 0 0 0 2 0 0 0, 0 0 0 0 0 2 0 0, 0 0 0 0 0 0 1 0, 0 0 0 0 0 0 0 1 log 1 .5 .5 0 0 0 0 0, 0 .5 .5 1 0 0 0 0, 1 0 0 1 0 0 0 0, 1 1 1 1 0 0 0 0, /* A_1 */ 0 0 0 0 1 .5 .5 0, 0 0 0 0 0 .5 .5 1, 0 0 0 0 1 0 0 1, 0 0 0 0 1 1 1 1 * 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0, 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0, 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0, 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1, /* A_0 */ 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0, 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0, 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0, 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1; /* zero=1e-20 forces zero cell as sampling zero */ model y11*y12*y21*y22=(1 0, 0 1) (1='Kappa for 1st pathologist', 2='Kappa for 2nd pathologist') /zero=1e-20; contrast 'equal intraclass kappas' all_parms 1 -1; run; ***************************************************************