Programming the statistical procedures from SAS

glm contrast statement with interaction

Reply
Occasional Contributor
Posts: 16

glm contrast statement with interaction

Hello,
I am running proc glm. I have 2 effects:
trt with 3 levels (t1,t2 and t3;1 is the control) and
cat with 2 levels (c1, c2).
I am checking whether there is a trt effect and whether there is a cat effect. I am also checking the interaction.
To find which trt has an effect I'm using contrast statements.
How can I find whether there is a trt effect within one of the cat levels?

Thanks in advance,
natanya
Trusted Advisor
Posts: 2,114

Re: glm contrast statement with interaction

This would be easier to respond to if you shared your code.

I am concerned that you are missing a fundamental principle of the general linear model. If there is an interaction, testing of main effects is not warranted, and may be misleading. ("To find which trt has an effect I'm using contrast statements." ). You need to test for one variable at specified values of the other.

If you have an interaction, the question that you posed is the one that makes sense. See the documentation for an example
http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_glm_sect050....
Occasional Contributor
Posts: 16

Re: glm contrast statement with interaction

Thank you for your response.
I do not have a significant interaction effect (p=0.08). I do have a significant trt effect (p=0.02). I do not have a significant cat effect. If I want to examine the effect within cat=1 and cat=2 should I just do the glm by cat or is there a way of checking this by using contrasts?
The code is strait forward (meanwhile):
proc glm data=a order=data;
class trt cat;
model param=trt cat trt*cat;
means trt cat trt*cat;
contrast "control vs t2" trt 1 -1 0;
contrast "control vs t3" trt 1 0 -1;
run;quit;

Thanks.
New Contributor
Posts: 4

Re: glm contrast statement with interaction

Hi Natanya

I've had the same problem before, and basically what you have to do is include the interaction in your contrast, and the factor you're comparing i.e. trt.

It sounds like you have 3 treatment levels and 2 categories levels is this correct?

If it is I would use something like this.

proc glm data=a order = data;
class cat trt ;
model results=trt cat trt*cat;
means trt cat trt*cat;
estimate "Cat1 - control vs t2" trt 1 -1 0 trt*cat 1 -1 0 0 0 0 / e;
estimate "Cat1 - control vs t3" trt 1 0 -1 trt*cat 1 0 -1 0 0 0 / e;
estimate "Cat2 - control vs t2" trt 1 -1 0 trt*cat 0 0 0 1 -1 0 / e;
estimate "Cat2 - control vs t3" trt 1 0 -1 trt*cat 0 0 0 1 0 -1 / e;
run;quit;

I have changed the variables in the clas statement to make the contrasts easier to understand, and I have used estimate instead of contrast just because I prefer it. The e option makes you understand if the coefficients you are using are correct.

Basically to go through first contrast we are saying that we want to compare treatment 1 against 2, and we are also saying that we want this comparison to be at Category 1.

An alternative way to get out the differences quickly and associated p-values is just to use the lsmeans statement Proc Mixed with the diffs option, but the default option does give you every possible interaction comparison.

proc mixed data=a order = data;
class cat trt ;
model results=trt cat trt*cat;
lsmeans trt*cat / diffs;
run;quit;


If you have any questions, please ask.

Thanks!
Contributor
Posts: 46

Re: glm contrast statement with interaction

Hi Risk.
I have the sas code below. The goal is to find those treatment combinations
are responsible for the interaction in the data, and write a report that summarizes all of the information in the data.
My attempts;
There is interaction between polymers and additives,also days significant.
My problem is to find those treatment combinations responsible for interaction.
Can I use polynomial contrasts or assume c1 to be the control and use equal spacing to calculate t-statistic and use fisher's or Bon LSD? But the problem is that the additives are on the same level. I looked confused um!

B A DAY TS B A DAY TS B A DAY TS
Mylar c1 1 9.2 Nylon c1 1 8.2 Peth c1 1 9.2
Mylar c2 1 8.7 Nylon c2 1 7.7 Peth c2 1 13.4
Mylar c3 1 9.1 Nylon c3 1 11.4 Peth c3 1 9.7
Mylar c4 1 12.4 Nylon c4 1 8.1 Peth c4 1 9.1
Mylar c5 1 10.5 Nylon c5 1 9.5 Peth c5 1 8.5
Mylar c1 2 8.2 Nylon c1 2 7.2 Peth c1 2 8.4
Mylar c2 2 8.7 Nylon c2 2 7.7 Peth c2 2 12.5
Mylar c3 2 8.8 Nylon c3 2 10.5 Peth c3 2 9.1
Mylar c4 2 11.5 Nylon c4 2 7.8 Peth c4 2 9.1
Mylar c5 2 10.6 Nylon c5 2 9.6 Peth c5 2 8.9
Mylar c1 3 8.4 Nylon c1 3 7.4 Peth c1 3 8.2
Mylar c2 3 8.3 Nylon c2 3 7.8 Peth c2 3 8.5
Mylar c3 3 8.7 Nylon c3 3 7.3 Peth c3 3 8.8
Mylar c4 3 8.5 Nylon c4 3 7.7 Peth c4 3 8.1
Mylar c5 3 8.8 Nylon c5 3 7.1 Peth c5 3 8.3


Obtain a complete analysis of the data that includes finding those treatment combinations are responsible for the interaction in the data, and write a report that summarizes what you believe to be all of the information in the data.



data ribbon;
input days polymers $ additives $ TS;
cards;
1 mylar c1 9.2
1 mylar c2 8.7
1 mylar c3 9.1
1 mylar c4 12.4
1 mylar c5 10.5
1 peth c1 9.2
1 peth c2 13.4
1 peth c3 9.7
1 peth c4 9.1
1 peth c5 8.5
1 nylon c1 8.2
1 nylon c2 7.7
1 nylon c3 11.4
1 nylon c4 8.1
1 nylon c5 9.5
2 mylar c1 8.2
2 mylar c2 8.7
2 mylar c3 8.8
2 mylar c4 11.5
2 mylar c5 10.6
2 peth c1 8.4
2 peth c2 12.5
2 peth c3 9.1
2 peth c4 9.1
2 peth c5 8.9
2 nylon c1 7.2
2 nylon c2 7.7
2 nylon c3 10.5
2 nylon c4 7.8
2 nylon c5 9.6
3 mylar c1 8.4
3 mylar c2 8.3
3 mylar c3 8.7
3 mylar c4 8.5
3 mylar c5 8.8
3 peth c1 8.2
3 peth c2 8.5
3 peth c3 8.8
3 peth c4 8.1
3 peth c5 8.3
3 nylon c1 7.4
3 nylon c2 7.8
3 nylon c3 7.3
3 nylon c4 7.7
3 nylon c5 7.1
;

proc GLM data =ribbon;
Class days polymers additives;
model TS= days polymers| additives;
Lsmeans days polymers | additives/pdiff stderr;
run;
quit;
Regular Contributor
Posts: 169

Re: glm contrast statement with interaction

It is not immediately clear whether you want to have an overall test of any treatment effect within each level of cat or whether you want to test pairwise differences between any two treatments within each level of cat. My initial assumption when I read your first post was that you wanted to construct an overall test of any treatment effect within each level of cat.

Assuming that is the model of interest, then you can use the code:

proc glm data=a order=data;
  class trt cat;
  model param=trt cat trt*cat;
  means trt cat trt*cat;
  lsmeans trt*cat / slice=cat;
run;quit;

Now, if you want to test pairwise differences between treatment levels within each level of cat, you have to make some decisions about whether and how you want to adjust for multiple comparisons. See the documentation of the ADJUST= option of the LSMEANS statement.
Ask a Question
Discussion stats
  • 5 replies
  • 1065 views
  • 0 likes
  • 5 in conversation