Obsidian | Level 7

## Specify Pairwise Comparisons Using PROC GLM

Hello,

Is there a way to specify which pairwise comparisons you want to look at, so that I can apply a Bonferroni adjustment using PROC GLM?

Example:

Factor A has 6 levels

Outcome variable is continuous

Thus we use an ANOVA model Y = mu + tau1 + tau2 + tau3 + tau4 + tau5 + tau6 + epsilon.

I am interested in whether there is a significant difference of mean in levels 1 and 2, levels 3 and 5, and level 1 and 6. Thus I am testing the null hypotheses mu1 = mu2, mu3 = mu5, and mu1 = mu6. Since this isn't all pairwise comparisons, I want to apply Bonferroni adjustment in place of Tukey adjustment. However, I don't want it to adjust for all comparisons since I don't care about that. Can SAS accommodate this? Or is splitting the alpha the way to go?

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: Specify Pairwise Comparisons Using PROC GLM

What you are asking for might not be done in PROC GLM --- In some other procedures that can also fit your ANOVA model, like PROC MIXED or PROC GENMOD, you might use the LSMESTIMATE statement with the ADJUST= option to get what you want; or use the ESTIMATE statement with the ADJUST=BON in procedures like PROC GLIMMIX or PROC GENMOD to get what you want. But PROC GLM does not have the LSMESTIMATE statement, and for the ESTIMATE statement in PROC GLM, ADJUST= option is not supported. Below is a sample syntax --

``````proc mixed data=yourdata;
class A;
model y=A;
lsmestimate A 'level 1 vs 2' 1 -1 0 0 0 0,
'level 3 vs 5' 0 0 1 0 -1 0,        ,
'level 1 vs 6' 1 0 0 0 0 -1/adjust=bon;     ,
run;``````

Another approach if you prefer fitting your model in PROC GLM, is to use the STORE statement in PROC GLM then use PROC PLM to do the multiple comparisons you want. For example,

``````proc glm data=yourdata;
class A;
model y=A;
store glmout;
run;

proc plm restore=glmout;
lsmestimate A 'level 1 vs 2' 1 -1 0 0 0 0,
'level 3 vs 5' 0 0 1 0 -1 0,        ,
'level 1 vs 6' 1 0 0 0 0 -1/adjust=bon;        ,
run;``````

6 REPLIES 6
SAS Employee

## Re: Specify Pairwise Comparisons Using PROC GLM

You can use write specific contrasts for desired comparison and adjust the P-values based on Bonferroni method by considering the number of pairwise comparisons:
This online resource might be useful:
https://people.stat.sc.edu/habing/courses/516cmsup3.pdf
SAS Super FREQ

## Re: Specify Pairwise Comparisons Using PROC GLM

What you are asking for might not be done in PROC GLM --- In some other procedures that can also fit your ANOVA model, like PROC MIXED or PROC GENMOD, you might use the LSMESTIMATE statement with the ADJUST= option to get what you want; or use the ESTIMATE statement with the ADJUST=BON in procedures like PROC GLIMMIX or PROC GENMOD to get what you want. But PROC GLM does not have the LSMESTIMATE statement, and for the ESTIMATE statement in PROC GLM, ADJUST= option is not supported. Below is a sample syntax --

``````proc mixed data=yourdata;
class A;
model y=A;
lsmestimate A 'level 1 vs 2' 1 -1 0 0 0 0,
'level 3 vs 5' 0 0 1 0 -1 0,        ,
'level 1 vs 6' 1 0 0 0 0 -1/adjust=bon;     ,
run;``````

Another approach if you prefer fitting your model in PROC GLM, is to use the STORE statement in PROC GLM then use PROC PLM to do the multiple comparisons you want. For example,

``````proc glm data=yourdata;
class A;
model y=A;
store glmout;
run;

proc plm restore=glmout;
lsmestimate A 'level 1 vs 2' 1 -1 0 0 0 0,
'level 3 vs 5' 0 0 1 0 -1 0,        ,
'level 1 vs 6' 1 0 0 0 0 -1/adjust=bon;        ,
run;``````

## Re: Specify Pairwise Comparisons Using PROC GLM

Thanks @jiltao for pointing out the error with my code, and even better, posting a solution that did use PROC GLM.  I wish I could mark your reply as correct.

SteveDenham

## Re: Specify Pairwise Comparisons Using PROC GLM

You should look into using the LSMESTIMATE statement.  You can do multiple comparisons and apply a Bonferroni correction (amongst many correction types).  Something like this may be what you are looking for:

(But keep in mind that PROC GLM does not support the LSMESTIMATE statement.  For a better set of code, see the response by @jiltao in this thread.)

``````proc glm data=yourdata;
class factor_A;
model y=factor_A;
lsmeans factor_A;
lsmestimate factor_A 'One vs two'   1 -1 0 0 0 0,
'Three vs five' 0 0 1 0 -1 0,        ,
'One vs six' 1 0 0 0 0 -1/adjust=bon;     ,
run;``````

Hope this helps.

SteveDenham

SAS Super FREQ

## Re: Specify Pairwise Comparisons Using PROC GLM

Just wanted to point out that the LSMESTIMATE statement is not available in PROC GLM. Please refer to my previous post for alternative approaches.

Obsidian | Level 7

## Re: Specify Pairwise Comparisons Using PROC GLM

Yes. Thank you! I'm not sure how to change accepted solution, though.

Discussion stats
• 6 replies
• 2292 views
• 7 likes
• 4 in conversation