SAS Proc Freq Examples for Matched Data

/***********************************************

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";

procfreq;

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";

procfreq;

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";

procfreq 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";

PROCFREQ DATA=GRADERS;

TABLES EXAMINRA * EXAMINRB / AGREE ;

EXACT AGREE;

RUN;

McNemar's Test for Low Urine at Time 1 vs. Time 2

The FREQ Procedure

Table of low_urine1 by low_urine2

low_urine1 low_urine2

Frequency‚

Percent ‚

Row Pct ‚

Col Pct ‚ 0‚ 1‚ Total

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

0 ‚ 33 ‚ 4 ‚ 37

‚ 29.20 ‚ 3.54 ‚ 32.74

‚ 89.19 ‚ 10.81 ‚

‚ 47.83 ‚ 9.09 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

1 ‚ 36 ‚ 40 ‚ 76

‚ 31.86 ‚ 35.40 ‚ 67.26

‚ 47.37 ‚ 52.63 ‚

‚ 52.17 ‚ 90.91 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

Total 69 44 113

61.06 38.94 100.00

Statistics for Table of low_urine1 by low_urine2

McNemar's Test

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Statistic (S) 25.6000

DF 1

Pr > S <.0001

Simple Kappa Coefficient

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Kappa 0.3423

ASE 0.0720

95% Lower Conf Limit 0.2012

95% Upper Conf Limit 0.4833

Sample Size = 113

Mastery of Algebra Problems After Two Teaching Methods

The FREQ Procedure

Table of symbolic by verbal

symbolic verbal

Frequency ‚

Percent ‚

Row Pct ‚

Col Pct ‚Mastery ‚Nonmaste‚ Total

‚ ‚ry ‚

ƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

Mastery ‚ 38 ‚ 17 ‚ 55

‚ 60.32 ‚ 26.98 ‚ 87.30

‚ 69.09 ‚ 30.91 ‚

‚ 88.37 ‚ 85.00 ‚

ƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

Nonmastery ‚ 5 ‚ 3 ‚ 8

‚ 7.94 ‚ 4.76 ‚ 12.70

‚ 62.50 ‚ 37.50 ‚

‚ 11.63 ‚ 15.00 ‚

ƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

Total 43 20 63

68.25 31.75 100.00

Statistics for Table of symbolic by verbal

McNemar's Test

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Statistic (S) 6.5455

DF 1

Pr > S 0.0105

Simple Kappa Coefficient

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Kappa 0.0402

ASE 0.1114

95% Lower Conf Limit -0.1781

95% Upper Conf Limit 0.2584

Sample Size = 63

Agreement of two raters on skin condition

Table of derm1 by derm2

derm1 derm2

Frequency‚

Percent ‚

Row Pct ‚

Col Pct ‚terrible‚poor ‚marginal‚clear ‚ Total

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

terrible ‚ 10 ‚ 4 ‚ 1 ‚ 0 ‚ 15

‚ 11.36 ‚ 4.55 ‚ 1.14 ‚ 0.00 ‚ 17.05

‚ 66.67 ‚ 26.67 ‚ 6.67 ‚ 0.00 ‚

‚ 58.82 ‚ 20.00 ‚ 3.23 ‚ 0.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

poor ‚ 5 ‚ 10 ‚ 12 ‚ 2 ‚ 29

‚ 5.68 ‚ 11.36 ‚ 13.64 ‚ 2.27 ‚ 32.95

‚ 17.24 ‚ 34.48 ‚ 41.38 ‚ 6.90 ‚

‚ 29.41 ‚ 50.00 ‚ 38.71 ‚ 10.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

marginal ‚ 2 ‚ 4 ‚ 12 ‚ 5 ‚ 23

‚ 2.27 ‚ 4.55 ‚ 13.64 ‚ 5.68 ‚ 26.14

‚ 8.70 ‚ 17.39 ‚ 52.17 ‚ 21.74 ‚

‚ 11.76 ‚ 20.00 ‚ 38.71 ‚ 25.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

clear ‚ 0 ‚ 2 ‚ 6 ‚ 13 ‚ 21

‚ 0.00 ‚ 2.27 ‚ 6.82 ‚ 14.77 ‚ 23.86

‚ 0.00 ‚ 9.52 ‚ 28.57 ‚ 61.90 ‚

‚ 0.00 ‚ 10.00 ‚ 19.35 ‚ 65.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

Total 17 20 31 20 88

19.32 22.73 35.23 22.73 100.00

Test of Symmetry

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Statistic (S) 4.5354

DF 6

Pr > S 0.6046

Simple Kappa Coefficient

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Kappa 0.3449

ASE 0.0724

95% Lower Conf Limit 0.2030

95% Upper Conf Limit 0.4868

Test of H0: Kappa = 0

ASE under H0 0.0612

Z 5.6366

One-sided Pr > Z <.0001

Two-sided Pr > |Z| <.0001

Weighted Kappa Coefficient

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Weighted Kappa 0.5082

ASE 0.0655

95% Lower Conf Limit 0.3798

95% Upper Conf Limit 0.6366

Sample Size = 88

KAPPA AND WEIGHTED KAPPA: AGREEMENT FOR 2 RATERS

SCALE IS ORDINAL: WEIGHTED KAPPA IS APPROPRIATE

DATA FROM HAND ET AL

The FREQ Procedure

Table of EXAMINRA by EXAMINRB

EXAMINRA EXAMINRB

Frequency‚

Percent ‚

Row Pct ‚

Col Pct ‚ 0‚ 1‚ 2‚ 3‚ 4‚ Total

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

0 ‚ 9 ‚ 1 ‚ 2 ‚ 0 ‚ 0 ‚ 12

‚ 31.03 ‚ 3.45 ‚ 6.90 ‚ 0.00 ‚ 0.00 ‚ 41.38

‚ 75.00 ‚ 8.33 ‚ 16.67 ‚ 0.00 ‚ 0.00 ‚

‚ 100.00 ‚ 100.00 ‚ 25.00 ‚ 0.00 ‚ 0.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

1 ‚ 0 ‚ 0 ‚ 5 ‚ 0 ‚ 0 ‚ 5

‚ 0.00 ‚ 0.00 ‚ 17.24 ‚ 0.00 ‚ 0.00 ‚ 17.24

‚ 0.00 ‚ 0.00 ‚ 100.00 ‚ 0.00 ‚ 0.00 ‚

‚ 0.00 ‚ 0.00 ‚ 62.50 ‚ 0.00 ‚ 0.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

2 ‚ 0 ‚ 0 ‚ 1 ‚ 5 ‚ 0 ‚ 6

‚ 0.00 ‚ 0.00 ‚ 3.45 ‚ 17.24 ‚ 0.00 ‚ 20.69

‚ 0.00 ‚ 0.00 ‚ 16.67 ‚ 83.33 ‚ 0.00 ‚

‚ 0.00 ‚ 0.00 ‚ 12.50 ‚ 55.56 ‚ 0.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

3 ‚ 0 ‚ 0 ‚ 0 ‚ 0 ‚ 1 ‚ 1

‚ 0.00 ‚ 0.00 ‚ 0.00 ‚ 0.00 ‚ 3.45 ‚ 3.45

‚ 0.00 ‚ 0.00 ‚ 0.00 ‚ 0.00 ‚ 100.00 ‚

‚ 0.00 ‚ 0.00 ‚ 0.00 ‚ 0.00 ‚ 50.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

4 ‚ 0 ‚ 0 ‚ 0 ‚ 4 ‚ 1 ‚ 5

‚ 0.00 ‚ 0.00 ‚ 0.00 ‚ 13.79 ‚ 3.45 ‚ 17.24

‚ 0.00 ‚ 0.00 ‚ 0.00 ‚ 80.00 ‚ 20.00 ‚

‚ 0.00 ‚ 0.00 ‚ 0.00 ‚ 44.44 ‚ 50.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

Total 9 1 8 9 2 29

31.03 3.45 27.59 31.03 6.90 100.00

KAPPA AND WEIGHTED KAPPA: AGREEMENT FOR 2 RATERS 6

SCALE IS ORDINAL: WEIGHTED KAPPA IS APPROPRIATE

DATA FROM HAND ET AL

The FREQ Procedure

Statistics for Table of EXAMINRA by EXAMINRB

Test of Symmetry

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Statistic (S) 14.8000

DF 10

Pr > S 0.1395

Simple Kappa Coefficient

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Kappa (K) 0.2103

ASE 0.0852

95% Lower Conf Limit 0.0433

95% Upper Conf Limit 0.3773

Test of H0: Kappa = 0

ASE under H0 0.0857

Z 2.4544

One-sided Pr > Z 0.0071

Two-sided Pr > |Z| 0.0141

Exact Test

One-sided Pr >= K 0.0186

Two-sided Pr >= |K| 0.0226

Weighted Kappa Coefficient

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

Weighted Kappa (K) 0.5797

ASE 0.0717

95% Lower Conf Limit 0.4391

95% Upper Conf Limit 0.7203

Test of H0: Weighted Kappa = 0

ASE under H0 0.1231

Z 4.7110

One-sided Pr > Z <.0001

Two-sided Pr > |Z| <.0001

Exact Test

One-sided Pr >= K 5.803E-07

Two-sided Pr >= |K| 5.803E-07

Sample Size = 29

1