Programming the statistical procedures from SAS

Comparing means between several groups

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

Comparing means between several groups

Hello,

 

I asking for your help.

 

I have 3 variables that divided to 4 groups (Quantitative variables).

I intend to check if there is any difference between the groups for each variable.

 

My difficulty in using ANOVA - it indicates that one of the group is different but it does not indicate which one of the group is different.

 

Can you please advise what king of test to use in order to get indication which group is different in relate to the other. Should I use TTEST in the following way: checking one group in relate to the other 3 groups together (=as another one group)?

 

I hope my question is clear...

 

Thanks a lot!


Accepted Solutions
Solution
‎03-30-2017 03:55 AM
Super User
Posts: 10,827

Re: Comparing means between several groups

One way to group values for analysis is to use a custom format. This has an advantage that you do not need to add variables.

Then use the CLASS statement to indicate the variable used to define the classification groups for the test.

 

proc format library=work;
   value firstgroup
       1 = '1'
       2,3,4 = '2-4';
    value secgroup
       2='2'
       1,3,4 = '1,3,4';
run;

proc ttest data=sasuser.sasfile010916;
   class stage;
   format state firstgroup.;
   var ROA1 ROA2 ROA3 ROA4 ROE1 ROE2 ROIC Q LNQ ;
run;

proc ttest data=sasuser.sasfile010916;
   class stage;
   format state secgroup.;
   var ROA1 ROA2 ROA3 ROA4 ROE1 ROE2 ROIC Q LNQ ;
run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,659

Re: Comparing means between several groups

Contributor
Posts: 69

Re: Comparing means between several groups

@PaigeMiller - thanks for your answer!

 

But if I want to test it with proc ttest, I want to compare between 1 group in relate to ALL 3 OTHER GROUPS TOGETHER. So, what is wrong with my following code:

 

proc ttest data=sasuser.sasfile010916;
where stage=1;
var ROA1 ROA2 ROA3 ROA4 ROE1 ROE2 ROIC Q LNQ ;
run;

 

Remarks - the groups are in variable STAGE that has the values - 1,2,3,4. How can I relate to groups 2-4 together (as 1 group)?

 

Thanks 

Trusted Advisor
Posts: 1,659

Re: Comparing means between several groups

You want to use the CONTRAST statement in PROC GLM (not PROC ANOVA).

http://documentation.sas.com/?cdcId=statcdc&cdcVersion=14.2&docsetId=statug&docsetTarget=statug_glm_...

 

If you scroll down to the last example in the CONTRAST statement documentation, it shows how you would compare a control group to the average of the others, which if I am understanding you properly is what you are trying to do.

Solution
‎03-30-2017 03:55 AM
Super User
Posts: 10,827

Re: Comparing means between several groups

One way to group values for analysis is to use a custom format. This has an advantage that you do not need to add variables.

Then use the CLASS statement to indicate the variable used to define the classification groups for the test.

 

proc format library=work;
   value firstgroup
       1 = '1'
       2,3,4 = '2-4';
    value secgroup
       2='2'
       1,3,4 = '1,3,4';
run;

proc ttest data=sasuser.sasfile010916;
   class stage;
   format state firstgroup.;
   var ROA1 ROA2 ROA3 ROA4 ROE1 ROE2 ROIC Q LNQ ;
run;

proc ttest data=sasuser.sasfile010916;
   class stage;
   format state secgroup.;
   var ROA1 ROA2 ROA3 ROA4 ROE1 ROE2 ROIC Q LNQ ;
run;

Contributor
Posts: 69

Re: Comparing means between several groups

@ballardw Thanks for your answer. You meant to format stage firstgroup and not format state firstgroup, right?

Super User
Posts: 10,827

Re: Comparing means between several groups


yael wrote:

@ballardw Thanks for your answer. You meant to format stage firstgroup and not format state firstgroup, right?


Correct

Trusted Advisor
Posts: 1,659

Re: Comparing means between several groups


ballardw wrote:

One way to group values for analysis is to use a custom format. This has an advantage that you do not need to add variables.

Then use the CLASS statement to indicate the variable used to define the classification groups for the test.

 

proc format library=work;
   value firstgroup
       1 = '1'
       2,3,4 = '2-4';
    value secgroup
       2='2'
       1,3,4 = '1,3,4';
run;

proc ttest data=sasuser.sasfile010916;
   class stage;
   format state firstgroup.;
   var ROA1 ROA2 ROA3 ROA4 ROE1 ROE2 ROIC Q LNQ ;
run;

proc ttest data=sasuser.sasfile010916;
   class stage;
   format state secgroup.;
   var ROA1 ROA2 ROA3 ROA4 ROE1 ROE2 ROIC Q LNQ ;
run;


Hello, @ballardw, it seems to me that this doesn't give the same answer as a CONTRAST statement in a PROC GLM analysis, because this PROC TTEST would use a different error term. In my understanding of the matter, I think the proper error term would indeed be the analysis-of-variance (PROC GLM) error term, and not the error derived via this PROC TTEST, specifically because the PROC GLM analysis-of-variance method would account for the group-to-group differences and not put this into the error term; however the PROC TTEST method just considers group-to-group diffferences to be part of the overall error term.

 

What do you think?

Super User
Posts: 10,827

Re: Comparing means between several groups

@PaigeMiller agreed.

 

The example was mostly to show the use of the format to create groups. And since the OP mention ttest use that as an example.

 

Sort of the "know thy data" before picking the analysis technique.

Contributor
Posts: 69

Re: Comparing means between several groups

Dear @PaigeMiller

I wonder if you can help me with the contrast statement,

I want to compare between stage 2 to stage 1,3,4,5 together,

The code is:

proc glm data=sasuser.sasfile010916;
class stage;
model ROA1=stage;
means stage/deponly;
contrast 'Compare 2 vs 1,3,4,5 together' stage 1 1 -4 1 1;
run;

 

Am I right?

Trusted Advisor
Posts: 1,659

Re: Comparing means between several groups


yael wrote:

Dear @PaigeMiller

I wonder if you can help me with the contrast statement,

I want to compare between stage 2 to stage 1,3,4,5 together,

The code is:

proc glm data=sasuser.sasfile010916;
class stage;
model ROA1=stage;
means stage/deponly;
contrast 'Compare 2 vs 1,3,4,5 together' stage 1 1 -4 1 1;
run;

 

Am I right?


Following the example in the CONTRAST statement documentation, you'd want

 

contrast 'Compare 2 vs 1,3,4,5' stage -0.25 1 -0.25 -0.25 -0.25;
Contributor
Posts: 69

Re: Comparing means between several groups

@PaigeMiller Thanks for your fast reply and shabat shalom

Contributor
Posts: 69

Re: Comparing means between several groups

Dear @PaigeMiller, I understand that I should use PROC GLM instead of TTEST because of the error terms (if I compare more than 2 groups). I really want to understand it deeply. Can you recommand what is the specific subject that I have to look for in order to get more understanding about it? Thanks

SAS Super FREQ
Posts: 3,540

Re: Comparing means between several groups

The area of study is called "multiple comparisons." I would start with the PROC GLM doc. If you want a book, I highly recommend Multiple Comparisons and Multiple Tests by Westfall, Tobias, and Wolfinger.

Trusted Advisor
Posts: 1,659

Re: Comparing means between several groups

With all due respect to @Rick_SAS, I don't think that book is the place to look for the answer, I don't consider the question posed in this thread to be a multiple comparison question. I'm not sure what reading I would recommend.

 

The bottom line is that the PROC TTEST treats the analysis as if there are only two groups, the group of interest and all the other groups combined. So the actual group to group variability between "all the other groups combined" is considered by PROC TTEST to be random variation, used in the error term of the analysis. In PROC GLM, the difference betwee all 5 groups is specifically accounted for as the group-to-group variability, and thus it is not lumped into the error term. The comparison of group 2 to the average of all other groups combined is tested against this PROC GLM error term, which is smaller than the error term used by PROC TTEST, because the PROC GLM error term does not have the group-to-group variability included (as the PROC TTEST error term does).

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 15 replies
  • 371 views
  • 11 likes
  • 5 in conversation