BookmarkSubscribeRSS Feed
Miracle
Barite | Level 11

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;

8 REPLIES 8
Ksharp
Super User

What does your data look like ?

And better post it at SAS Statistical Procedures

Let more statistical expert  to see it .

Miracle
Barite | Level 11

Hi Keshan.

Thanks for your reply.

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

idfreq_beforefreq_after
1101
252
368

.

.

.

.

.

.

.

.

.

10023

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 Smiley Happy

Ksharp
Super User

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

Miracle
Barite | Level 11

Hi Keshan.

Thanks for your reply.

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 Smiley Happy

Ksharp
Super User

"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

Miracle
Barite | Level 11

Hi Keshan.

Thanks for your reply.

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

Ksharp
Super User

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

SteveDenham
Jade | Level 19

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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