difference in proportions

Regular Contributor
Posts: 233

difference in proportions

Dear all,

I wish you all well.

I have two(freq_b4 and freq_after) 10-level category variables which I would like to test if the proportions of each level from the 2 variables differ.

Am I doing it right? Your insight is greatly appreciated.

My SAS code is as below:

proc freq data=tmp compress;

exact binomial;

tables freq_b4 / binomial(level=1 p=0.05 );

.

.

.

tables freq_b4 / binomial(level=10 p=0.1 );

run;

Super User
Posts: 10,194

Re: difference in proportions

What does your data look like ?

And better post it at SAS Statistical Procedures

Let more statistical expert  to see it .

Regular Contributor
Posts: 233

Re: difference in proportions

Hi Keshan.

My data looks like this. The sample size is small with only about 100 individuals.

 id freq_before freq_after 1 10 1 2 5 2 3 6 8 ... ... ... 100 2 3

where 10=everyday, 9=once every few days, ...., 1=never for both freq_before and freq_after variable.

I was wondering if I should create dummy variables for the two 10-level categorical variables and do a Chi-square test/Fisher's exact test like this? :smileyconfused:

proc freq data=tmp; tables before_level1*after_level1 / chisq; run;

.

.

.

proc freq data=tmp; tables before_level10*after_level10 / chisq; run;

Any comments and insight is greatly appreciated

Super User
Posts: 10,194

Re: difference in proportions

"I was wondering if I should create dummy variables for the two 10-level categorical variables and do a Chi-square test/Fisher's exact test like this?"

Why do you need to create a dummy variable ? Yes. I think you can do a Chi-square test/Fisher's exact test ,better Fisher's exact test, since you have so many levels and so few obs , there are might lots of cells have < 5 obs .

Regular Contributor
Posts: 233

Re: difference in proportions

Hi Keshan.

Actually, maybe I need to do a McNemar's due to the correlated proportions of before and after from individuals.

I thought I need to create dummy variables for the two 10-level categorical variables in order to test for the before and after proportion for each level.

If I just did a Fisher's exact test between the two 10-level freq_before and 10-level freq_after variable, it will not tell me which level of before and after proportions are different.

Am I making any sense here? :smileyconfused:

Any comment and insight is greatly appreciated

Super User
Posts: 10,194

Re: difference in proportions

"maybe I need to do a McNemar's due to the correlated proportions of before and after from individuals."

If I was right, McNemar test is only for 2*2 contingency table .

Not sure ,Maybe you should try  Proc logistic .

And don't forget to

post it at SAS Statistical Procedures

Doc Steve might have a good vision.

Xia Keshan

Regular Contributor
Posts: 233

Re: difference in proportions

Hi Keshan.

By the way, I thought I've already moved this post to SAS Statistical Procedures. Have I not? :smileyconfused:

Super User
Posts: 10,194

Re: difference in proportions

Hi,

Maybe you could try one-way probability test by proc freq. But since there are 10 levels for each two variables, that could be 10*10 levels totally for your data .that is to say your data is too sparse for each levels.

E.X.

take sashelp.class as an example. we want to test if Female and Male have the same proportion . in other words  , Test  H0: F=0.5 and M=0.5 , now we can code like :

```
proc freq data=sashelp.class;
tables sex/nocum chisq testp=(50 50);
exact fisher  ;
run;

Chi-Square Test
for Specified Proportions
-------------------------
Chi-Square         0.0526
DF                      1
Pr > ChiSq         0.8185

Sample Size = 19

```

Now see the P-value is 0.8  . We have no reason to reject H0 . (i.e. Female and Male have the same proportion) .

Xia Keshan

Message was edited by: xia keshan

Posts: 2,655

Re: difference in proportions

Hello K C,

If you have SAS/STAT13.2, you can get Bowker's test output (generalization of McNemar's test to 2xK tables) with:

proc freq data=tmp;

tables before_level10*after_level10 / agree; run;

I can't guarantee this is what you are looking for, but it is now available.

Steve Denham

Discussion stats
• 8 replies
• 459 views
• 5 likes
• 3 in conversation