BookmarkSubscribeRSS Feed
bmac1
Obsidian | Level 7

Hello SAS users,

I want to compare variances of observations from 12 groups to see whether there are significant differences and which groups have variances which differ from other groups.

I am using Proc GLM with the HOVTEST = Levene option to test for differences in variances.  The test gives a significant result, so some groups are more variable than others.  But how do I find out which groups differ from others?  Is there something like a Tukey or SNK multiple comparison test for variances (instead of for means)?

 

Here is the code I have been using:

 

proc glm data = stat;

   class area;

   model nos = area;

   means area / hovtest = levene (type = square);

run;

 

Suggestions welcome.  Thank you.

4 REPLIES 4
StatDave
SAS Super FREQ

See this note that discusses testing for inequality of variances and methods that adjust for inequality. If you want to test the variances in each pair of groups, then you could use the variance test that is provided by PROC TTEST. Use a WHERE statement in PROC TTEST each time to select one pair of groups. Since there will be a substantial number of tests, it would probably be good to adjust the p-values for multiple testing. This can be done by collecting the variance test p-values of all of the pairwise tests into a variable in a data set and then using a p-value adjustment method in PROC MULTTEST to adjust the raw p-values by using the INPVALUES= option. There is an example in the MULTTEST documentation. The HOLM method is generally a good adjustment method.. 

bmac1
Obsidian | Level 7

Hi,

Thank you for this solution.

However, it seems cumbersome.  i. e., having to run dozens of Proc ttest’s (recall that I have 12 groups, so each one against all others will be very many tests…), save the P values  and then import the values to another procedure for the adjustment, which I fully agree is needed.  Is there a way that Proc ttest (or maybe another Procedure?) can do the tests for all pairs (something like how ANOVA or GLM does the multiple comparison of group means) by each group, and can save the P values in a file with the pairs of groups?  

 

Regarding saving the P values, I can’t find an output statement in Proc ttest that allows to save those values.  How do I do that, for a situation like this, where there will be many comparisons and results?

 

I also tried using the WHERE statement but ran into problems.  Exactly where in the Proc ttest code should that statement be located?  The CLASS variable must only have two levels, so I tried with the WHERE statement before or after the CLASS statement and it did not work. e.g.,

proc ttest data = stat;

   class area;

   where area = "aaa" and "bbb";

   var res;

run;

 

Would you have any other suggestions for how to do this?

Best regards

ballardw
Super User

Let's start with the easy part: your where is incorrect. When you have a single variable you either list the explicit combinations of variable name and value:

   where area = "aaa" and area= "bbb";

Or use the IN operator to compare a single variable to a list of values:

   where area in ("aaa"  "bbb" );

Much of the output that is not available in an OUTPUT is available to capture using the ODS OUTPUT option. Long story; look up the ODS TRACE ON/OFF to get names of tables created that you can redirect with the ODS OUTPUT statement. Or read the DETAILS section of the on line help that often has the names of the tables created and the options needed.

In your case you probably want the TTESTS set:

proc ttest data = stat;
   ODS OUTPUT TTESTS=WORK.MYTESTRESULT;
   class area;
   where area IN ("aaa"  "bbb") ;
   var res;
run;

which would send the T-value and the probability of a larger t value to the output set Work.Testresult.

 

StatDave
SAS Super FREQ

Normally for problems where you want to run a procedure repeatedly, the best solution is to arrange the data so that you can run the procedure once with a BY statement to run the analysis for each BY group. Including an ODS OUTPUT statement would accumulate the specified table of results from all of the analyses. However, since you want to run the TTEST procedure for each pair of the GROUP variable's values, rather than for each individual GROUP value, the BY statement approach isn't quite so easy. But it can be done with a fairly straightforward macro that uses %DO statements to cycle through unique pairs of groups. The following code assumes that the GROUP values are 1, 2, ... , 12. You'll want to use the ODS EXCLUDE statement to suppress generating the full output from all of the TTEST runs. The PERSIST option in ODS OUTPUT allows you to accumulate all of the variance test tables into a single data set. The ODS OUTPUT CLOSE statement closes the accumulated data set (VARS). Finally, PROC MULTTEST does the p-value adjustment.

%macro ttrep;
ods output equality(persist)=vars;
%do grpi=1 %to 12;
%do grpj=&grpi+1 %to 12;
proc ttest data=test; 
where group=&grpi or group=&grpj;
class group; var res;
run;
%end; %end;
%mend;
ods exclude all;
%ttrep
ods output close;
ods select all;
proc multtest inpvalues(probf)=vars holm;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 656 views
  • 5 likes
  • 3 in conversation