Contingency table

Reply
New Contributor
Posts: 3

Contingency table

Hello

I am trying to create 5x5 table where I want to assess the men/women differences in responding to a question that has 5 choices, rated 1 to 5 with 5 indicating no problem and 1 indicating worst problem. I understand it should look similar to the one below. The purpose is to assess if women answer differently to this question, where women rate themselves as having more problems compared to male. I have 1 column where I have coded men/women as "1" or "0" and the other column reflecting the responses on the question rated 1 to 5 corresponding to men/women.

I am not able to figure out how I can a) create a table such as the one below using SAS; 2) Do a chi square or Fisher's test on this. 

I am fairly new to SAS to any help would be appreciated. Thanks

Female

     1                       2                   3                    4                   5

1

2

Male

3

4

5

Occasional Contributor P_2
Occasional Contributor
Posts: 10

Re: Contingency table

Hi Pt_Prof,

I'm not sure laying your table out like that makes sense.  try this code:

data temp;

input sex rate;

cards;

1 5

1 2

0 3

1 3

0 1

1 3

1 2

0 2

0 3

0 3

;

proc freq data =temp;

tables sex*rate /chisq nocum nocol norow nopercent ;

run;

New Contributor
Posts: 3

Re: Contingency table

Thank you P˄2 for your reply.

I was thinking to lay out table like that (5 x 5 for men x women) to see the proportion of women who may rate their problem to be higher (rate the response as 1 or 2) whereas men rate them as lower problem (rate the response as 4 or 5).

For example, this question has five (R1, R2 etc) responses, and we have have m/f. I need a chi-square statistic but I also want the row x column outcome to see if there is a difference in terms of whether women or men systematically rate as having more problem. Consider there are 50 men and 50 women providing us 100 responses.

                                                               

Women

          R1                           R2                     R3                    R4                        R5

R1

R2

Men             R3

R4

R5

20

20

20

20

20

The example above has a perfect diagonal indicating there is absolute agreement in how men and women respond to this question.

In other scenario below -

Women

           R1                       R2                       R3                         R4                   R5

R1

R2

Men           R3

R4

R5

4

4

0

3

0

10

7

0

1

0

12

8

6

2

0

11

7

3

6

2

8

2

1

0

3

There are about 62 responses below the diagonal, indicating that the women rated themselves to have more problem (they had more R1, R2 responses compared to men).

I hope you can help how can I get this table and calculate is there is a systematic pattern here where men/women differ how they respond to this question.

Thank you again

Super User
Posts: 11,114

Re: Contingency table

The displayed grid only makes sense if you are comparing two responses such as "perceived difficulty" and "reported problem". Is that the case?

If not then a meaningful layout and the code recommended by P^2 would analyze is

<this shows "perfect" agreement>


 

Response


 

 

Male


 

 

Female


 

 

1


 

 

10


 

 

10


 

 

2


 

 

10


 

 

10


 

 

3


 

 

10


 

 

10


 

 

4


 

 

10


 

 

10


 

 

5


 

 

10


 

 

10


 

 

Total


 

 

50


 

 

50


 

And if the sample sizes differ between men and women, this also shows perfect agreement as far as distribution of responses within gender.


 

Response


 

 

Male


 

 

Female


 

 

1


 

 

20


 

 

10


 

 

2


 

 

20


 

 

10


 

 

3


 

 

20


 

 

10


 

 

4


 

 

20


 

 

10


 

 

5


 

 

20


 

 

10


 

 

Total


 

 

100


 

 

50


 

And that is what the chi-square looks at.

Occasional Contributor P_2
Occasional Contributor
Posts: 10

Re: Contingency table

You can add the exact fisher option if your table is a reasonable size:

proc freq data =temp;

tables sex*rate /chisq nocum nocol norow nopercent;

exact fisher;

run;

Occasional Contributor P_2
Occasional Contributor
Posts: 10

Re: Contingency table

Happy to help out!

I don't understand the layout of those tables.  For example what does cell one mean (R1, R1) mean?   It is unclear which of the 4 were men and which were women.  If you have a data set with a sex column and a response column, this code will give you the appropriate outcomes:

proc freq data =temp;

tables sex*response /chisq nocum nocol norow nopercent expected;

exact fisher;

run;

A low p-value will indicate there is a discrepancy between the way sexes respond.   If you add the expected option, you will get expected values for the cells.  If you have a low p-value and then see the expected number of R4 and R5 responses is lower than actual number of R4 and R5 responses for men, that shows a trend that men tend to have less of the problem than women.

Super User
Posts: 9,865

Re: Contingency table

You should post it at Statistical Forum since it is a Statistical problem.

Due to your order variable and Square Table, You should use Association test .Like

tables sex*response / agree cl 

tables sex*response / measure cl 


Check Example of Square Table in Freq documentation.

Ask a Question
Discussion stats
  • 6 replies
  • 290 views
  • 0 likes
  • 4 in conversation