turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- repeated chi-square tests

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-02-2011 10:27 PM

Hi

neeed some help in this.

I am currently using this program to run the chi sq/fishers exact test:

DATA;

INPUT FLOWERS $ COLOURS $ COUNT @@;

DATALINES;

A I 18 II 15 III 12

B I 44 II 43 III 34

C I 34 II 31 III 37

;

RUN;

PROC FREQ;

WEIGHT COUNT;

TABLES flowers*colours;

EXACT FISHER;

RUN;

However, this is just for an individual observation and I have many rows of data, with each observation tabulated as a 3x3 table. Is there a macro that can run a chisq/fishers exact test for every 3 rows of data?

thanks

neeed some help in this.

I am currently using this program to run the chi sq/fishers exact test:

DATA;

INPUT FLOWERS $ COLOURS $ COUNT @@;

DATALINES;

A I 18 II 15 III 12

B I 44 II 43 III 34

C I 34 II 31 III 37

;

RUN;

PROC FREQ;

WEIGHT COUNT;

TABLES flowers*colours;

EXACT FISHER;

RUN;

However, this is just for an individual observation and I have many rows of data, with each observation tabulated as a 3x3 table. Is there a macro that can run a chisq/fishers exact test for every 3 rows of data?

thanks

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-03-2011 09:11 AM

You should be able to use a BY statement in PROC FREQ

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-03-2011 09:53 AM

I tried inserting the BY statement but then the chi square test gets messed up.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-03-2011 10:04 AM

Before dealing with multiple tests, your input data file is not what you think. You are specifying that the first flower type is A and the first colour type is "18", with a count of 12. Because of the @@, the next flower type is "12", the next colour is "B", with a count of "44". And so on. If your really have three flower types (and how many colours?), you should best have three values per record:

Flower, Colour, Count

If you have 3 flower types and 3 colour types (as an example), you would have 9 records.

Then, the rest of your code would work fine.

If you want to analyze several groups, you need a fourth variable per record, indicating the group.

Group, Flower, Colour, Count

There would be nine records for each of the groups. You would need to sort by Group, before the FREQ analysis.

LVM

Flower, Colour, Count

If you have 3 flower types and 3 colour types (as an example), you would have 9 records.

Then, the rest of your code would work fine.

If you want to analyze several groups, you need a fourth variable per record, indicating the group.

Group, Flower, Colour, Count

There would be nine records for each of the groups. You would need to sort by Group, before the FREQ analysis.

LVM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-03-2011 10:36 AM

I slightly mis-interpreted the I (etc.) as a space. But your input file is still not correct, as I indicated in my original message. You need three values for each combination.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-03-2011 11:42 AM

Will this input data file work instead?

DATA;

DO flower = 1 TO 3;

DO colour = I TO III;

INPUT WT @@;

OUTPUT;

END;

DATALINES;

18 15 12

44 43 34

34 31 37

;

PROC FREQ;

WEIGHT WT;

TABLES flower*colour;

EXACT FISHER

RUN;

The end result is such that flower type 1 has three colours, with 18 having colour I, 15 having colour II and 12 having colour III, and a total of 45.

The same goes for flower type 2.

If I have to sort by Group, do I just have to put in the data for Group under the datalines as well?

DATA;

DO flower = 1 TO 3;

DO colour = I TO III;

INPUT WT @@;

OUTPUT;

END;

DATALINES;

18 15 12

44 43 34

34 31 37

;

PROC FREQ;

WEIGHT WT;

TABLES flower*colour;

EXACT FISHER

RUN;

The end result is such that flower type 1 has three colours, with 18 having colour I, 15 having colour II and 12 having colour III, and a total of 45.

The same goes for flower type 2.

If I have to sort by Group, do I just have to put in the data for Group under the datalines as well?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-03-2011 12:22 PM

Your do loops won't work right, separate from the analysis. It is always a good idea to print the data file before the analysis to make sure you have what you think you have. I can't get into the do loop rules, but here is a direct way of getting what you want. I repeated your data a second time to show two groups. Make sure the groups are in order. There can be any number of groups.

DATA a;

INPUT group FLOWERS $ COLOURS $ COUNT ;

DATALINES;

1 A I 18

1 A II 15

1 A III 12

1 B I 44

1 B II 43

1 B III 34

1 C I 34

1 C II 31

1 C III 37

2 A I 18

2 A II 15

2 A III 12

2 B I 44

2 B II 43

2 B III 34

2 C I 34

2 C II 31

2 C III 37

;

proc print data=a;

RUN;

PROC FREQ data=a;

by group;

WEIGHT COUNT;

TABLES flowers*colours;

EXACT FISHER;

RUN;

DATA a;

INPUT group FLOWERS $ COLOURS $ COUNT ;

DATALINES;

1 A I 18

1 A II 15

1 A III 12

1 B I 44

1 B II 43

1 B III 34

1 C I 34

1 C II 31

1 C III 37

2 A I 18

2 A II 15

2 A III 12

2 B I 44

2 B II 43

2 B III 34

2 C I 34

2 C II 31

2 C III 37

;

proc print data=a;

RUN;

PROC FREQ data=a;

by group;

WEIGHT COUNT;

TABLES flowers*colours;

EXACT FISHER;

RUN;