BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
toxicatom5
Fluorite | Level 6

Hello,

 

I am making multiple comparisons using McNemar's Test in PROC FREQ. My goal is to take the pairwise p-values from this output, and replicate the "LINES" style of output that is produced when comparing means through various procedures (e.g. PROC ANOVA). Is anyone aware of a macro that can transform pairwise p-values into the LINES style of output?

 

Thank you in advance for any references you may have!

1 ACCEPTED SOLUTION

Accepted Solutions
toxicatom5
Fluorite | Level 6

I have found that the "LINES" statement is producing something called a Compact Letter Display, and that is what I would like to create for pairwise comparisons I make using procedures that do not have an option to produce Compact Letter Displays natively.

 

SAS clearly has this built-in to some procedures, so it is possible, but it appears to be a more complex problem than I had imagined.

 

Update: I may have found part of my answer, though I don't have SAS/IML so that poses a problem.  https://github.com/friendly/SAS-macros/blob/master/mult.sas

View solution in original post

8 REPLIES 8
data_null__
Jade | Level 19

This sounds interesting but you need to show some data and PROC FREQ to produce the pair-wise p-values.

toxicatom5
Fluorite | Level 6

Below is some example code that produces a table called "MeanLines" which shows Tukey groupings for mean data with alpha = 0.05, and a table called Pairwise which shows pairwise p-values for each of the 3 comparisons being made using McNemar. Since I quickly mocked this up, let's assume alpha = 0.10 for the pairwise comparisons using McNemar. In that case, I would like the output to be:

variable3 67% A

variable2 44% AB

variable1 11% B

 

data example;
input variable 1 meandata 2 percdata 3;
datalines;
170
180
190
191
170
190
190
180
190
271
291
290
290
260
280
261
271
260
360
351
371
371
340
341
361
370
381
;

ods output mclines = meanlines;
proc anova data = example;
class variable;
model meandata = variable;
means variable / alpha = 0.05 tukey linestable;
title 'lines output for means';
run;
quit;
ods output close;


data variable1data;
set example;
if variable = 1;
rename percdata = variable1;
drop variable meandata;
run;

data variable2data;
set example;
if variable = 2;
rename percdata = variable2;
drop variable meandata;
run;

data variable3data;
set example;
if variable = 3;
rename percdata = variable3;
drop variable meandata;
run;

data percdata;
merge variable1data variable2data variable3data;
run;

proc freq data = percdata;
tables variable1*variable2 variable1*variable3 variable2*variable3;
exact mcnemar;
output out = mcnemartest agree;
ods output mcnemarstest = pairwise;
title 'pairwise p-values for percentages';
run;

 

ballardw
Super User

Also suggest what exact table is created by Proc Anova as there are 3 different MC lines related output tables possible

toxicatom5
Fluorite | Level 6

Sure thing! For Anova it is the MCLINES table, and for Proc Freq it is McNemarTest. I've added those tables in the example code above to provide a starting point.

Ksharp
Super User

You can't "making multiple comparisons using McNemar's Test in PROC FREQ" .

McNemar Test is used for COUNT/FREQ data in 2x2 contingency table, unlike continuous data for PROC ANOVA.

If you want to make comparison with Risk Diff for matched pairs data(McNemar Test) ,check this:

https://support.sas.com/kb/46/997.html

 

And better post it at Statistical Forum . and @StatDave  @Rick_SAS  @lvm @SteveDenham  might give you a hand .

toxicatom5
Fluorite | Level 6

Thanks for your response Ksharp. I left out the detail that I use a Bonferroni correction when making multiple comparisons using McNemar, only because it does not matter with regard to the problem I am trying to solve, but I do recognize that McNemar applies to 2x2 data only.

 

Ultimately, I am looking for a way of transforming the standard output of SAS into a format that is usable for me, and I think that will require a creative macro. SAS already transforms pairwise multiple comparisons into "statistical groupings" using the LINES option. I just don't know the process behind how it makes that transformation.

toxicatom5
Fluorite | Level 6

I think it is possible to create a matrix of the pairwise comparisons where a 1 indicates the difference is not significant, and a 0 indicates it is significant. The diagonal is all 1's, of course. Using this thinking, and the example data I created above for the percentages, the matrix would look like this (v1-v3 sorted in descending numerical order):

    v3 v2 v1
v3 1   1   0
v2 1   1   1
v1 0   1   1

There is a visual pattern of "blocks" of 1's. If we assign each "block" a letter code, we get:

     v3 v2 v1 B1 B2
v3 1    1   0  A
v2 1    1   1  A   B
v1 0    1   1       B

I think my programming ability will allow me to create the matrix, but how the matrix is assessed in order to apply the letter codes is stumping me. Any ideas are appreciated!

toxicatom5
Fluorite | Level 6

I have found that the "LINES" statement is producing something called a Compact Letter Display, and that is what I would like to create for pairwise comparisons I make using procedures that do not have an option to produce Compact Letter Displays natively.

 

SAS clearly has this built-in to some procedures, so it is possible, but it appears to be a more complex problem than I had imagined.

 

Update: I may have found part of my answer, though I don't have SAS/IML so that poses a problem.  https://github.com/friendly/SAS-macros/blob/master/mult.sas

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1386 views
  • 0 likes
  • 4 in conversation