/*********************************************** SAS EXAMPLE -- FREQUENCY TABULATIONS FOR MATCHED OR RELATED CATEGORICAL VARIABLES. MCNEMAR'S TEST OF SYMMETRY COHEN'S KAPPA. FILENAME: MATCHFREQ.SAS ***********************************************/ OPTIONS NODATE PAGENO=1 FORMDLIM=" "; TITLE; /*********************McNemar's Test of Symmetry for Matched Samples*/ DATA AFIFI; INFILE "c:\temp\labdata\AFIFI.DAT"; INPUT #1 IDNUM 1-4 AGE 5-8 HEIGHT 9-12 SEX 13-15 SURVIVE 16 SBP1 21-24 URINE1 57-60 #2 SBP2 21-24 URINE2 57-60; if urine1 not =. then do; if urine1 <=15 then low_urine1=1; else low_urine1 = 0; end; if urine2 not =. then do; if urine2 <=15 then low_urine2=1; else low_urine2 = 0; end; RUN; title "McNemar's Test for Low Urine at Time 1 vs. Time 2"; proc freq; tables low_urine1*low_urine2 / agree; run; /*Algebra mastery for students taught using two methods*/ data algebra; length symbolic verbal $ 10; input symbolic $ verbal $ count; cards; Mastery Mastery 38 Mastery Nonmastery 17 Nonmastery Mastery 5 Nonmastery Nonmastery 3 ; title "Mastery of Algebra Problems After Two Teaching Methods"; proc freq; tables symbolic*verbal/agree; weight count; run; /******************Agreement, Using Cohen's Kappa*********************/ /* Getting Started Example Agreement Study Example */ data SkinCondition; input derm1 $ derm2 $ count; datalines; terrible terrible 10 terrible poor 4 terrible marginal 1 terrible clear 0 poor terrible 5 poor poor 10 poor marginal 12 poor clear 2 marginal terrible 2 marginal poor 4 marginal marginal 12 marginal clear 5 clear terrible 0 clear poor 2 clear marginal 6 clear clear 13 ; title "Agreement of two raters on skin condition"; proc freq data=SkinCondition order=data; weight count; tables derm1*derm2 / agree ; test kappa; run; *------------------------------COHEN'S KAPPA FOR INTER-RATER RELIABILITY; DATA GRADERS; INPUT CANDIDATE EXAMINRA EXAMINRB; CARDS; 1 1 2 2 0 0 3 0 0 4 2 2 5 0 0 6 4 3 7 0 0 8 0 0 9 0 0 10 2 3 11 1 2 12 2 3 13 0 1 14 4 3 15 4 3 16 1 2 17 0 2 18 1 2 19 2 3 20 0 0 21 2 3 22 4 4 23 0 0 24 0 0 25 4 3 26 0 2 27 1 2 28 3 4 29 2 3 ; TITLE "KAPPA AND WEIGHTED KAPPA: AGREEMENT FOR 2 RATERS"; TITLE2 "SCALE IS ORDINAL: WEIGHTED KAPPA IS APPROPRIATE"; TITLE3 "DATA FROM HAND ET AL"; PROC FREQ DATA=GRADERS; TABLES EXAMINRA * EXAMINRB / AGREE ; EXACT AGREE; RUN;