BookmarkSubscribeRSS Feed
keckk
Fluorite | Level 6
Hello everybody!
Working with glimmix, I am looking for the way to tell SAS to generate the lsmeans for all possible combinations of the two main effects and their levels respectively. My aim is to plot graphics in which I can show the levels of main effect A over the levels of the main effect B. So I would need the lsmeans of the level 1 of factor A at each of the levels of factor B, the same for level 2 of factor A etc.
Using lsmeans varA varB / diff cl ilink; will produce the lsmeans of both factors A(genotype) and B(period) and their levels and the difference, but not a combination of both variables.
Does anyone know, if this is possible to have in my output ?

Here's my model (the interaction term is not significant and is supposed to be omitted):
proc glimmix data=Iastress.Iab3datenew;
class genotype farm animal period datenum;
model tf3(event='1' ref=first)=genotype period origin*period mean_bg3 / dist=negbin solution;
random farm;
random datenum(period) / subject=animal(farm) type=cs residual;
lsmeans genotype period / diff cl ilink;
run;

Thanks very much for a helpful hint,
Karin
5 REPLIES 5
SteveDenham
Jade | Level 19
Well, I mangled the first answer and hopefully it was swallowed up whole.

This all comes down to the question you are trying to answer. If you really are interested in comparing levels of factor A at each level of factor B, you have to include the interaction A*B in the model, whether or not it is "significant."

If you drop the interaction, the solution that leads to the LSMeans is the same at each level of factor B for factor A, and similarly for each level of factor A for factor B. That's what your model says is happening--there is no difference by level for the second factor. One size fits all.

Clear as mud, huh?

Steve Denham
Dale
Pyrite | Level 9
My understanding is that you want something which operates for categorical covariates like the AT= option operates for continuous covariates. Is that correct?

I believe that you will have to employ ESTIMATE statements in order to generate the results which you seek. You don't say how many levels there are for factors A and B, but I will assume that there are three for A (genotype) and two for B (period). With these assumptions, we could write the following code:

proc glimmix data=Iastress.Iab3datenew;
  class genotype farm animal period datenum;
  model tf3(event='1' ref=first)=genotype period mean_bg3 / dist=negbin solution;
  random farm;
  random datenum(period) / subject=animal(farm) type=cs residual;
  lsmeans genotype period / diff cl ilink;
  estimate "LSM at genotype=1, period=1"
  intercept 1     genotype 1 0 0     period 1 0    mean_bg3 / ilink;
  estimate "LSM at genotype=2, period=1"
  intercept 1     genotype 0 1 0     period 1 0    mean_bg3 / ilink;
  estimate "LSM at genotype=3, period=1"
  intercept 1     genotype 0 0 1     period 1 0     mean_bg3 / ilink;
  estimate "LSM at genotype=1, period=2"
  intercept 1     genotype 1 0 0     period 0 1    mean_bg3 / ilink;
  estimate "LSM at genotype=2, period=2"
  intercept 1     genotype 0 1 0     period 0 1    mean_bg3 / ilink;
  estimate "LSM at genotype=3, period=2"
  intercept 1     genotype 0 0 1     period 0 1    mean_bg3 / ilink;
run;

Differences between LSMeans across levels of A at B=1 are identical to differences between LSMeans across levels of A at B=2, so your LSMEANS statement reproduced above can be employed to produce those differences. You will have to determine the appropriate value for the covariate mean_bg3. You can determine this value by running the code:

proc means data=Iastress.Iab3datenew;
  where missing(genotype)=0 &
           missing(farm)=0 &
           missing(animal)=0 &
           missing(period)=0 &
           missing(datenum)=0 &
           missing(tf3);
  var mean_bg3;
run;

HTH,

Dale
keckk
Fluorite | Level 6
hm, what SteveDenham said was my assumption,
but I was hoping that it should be possible to generate e.g. a line chart which shows immediately that the differences between lsmeans across levels of A at B=1 is not different from differences between lsmeans across levels of A at B=2 ...from my model without A*B in the model.

mean_bg3 is a continuous covariate, I don't want to assign any values for the covariate mean_bg3 to be used for computing the lsmeans of A and B. Is this necessary?
Does the proc means code you proposed for specifying the mean_bg3 value not produce the same as the option at means?

Cheers,
Ka
Dale
Pyrite | Level 9
In order to have some difference between lsmeans across levels of A at B=1 which are different from the difference between lsmeans across levels of A at B=2, the A*B interaction must be present in the model. Moreover, in order to get the lsmeans which capture these differences, you must then specify the LSMEANS statement:

lsmeans A*B / diff ...;

Why don't you want to assign a value for the covariate mean_bg3? Note that the LSMEANS statement does assign all continuous covariates their mean value by default. The ESTIMATE statement has no such default behavior. If you do not specify a value for the covariate in the ESTIMATE statement, then the ESTIMATE statement will zero fill for the covariate. Thus, you would be estimating mean values for factors A and B given mean_bg3=0. Is that what you want? I doubt it.

Dale
keckk
Fluorite | Level 6
My continuous covariate is a measure of ambient environmental conditions while I repeatedly (days) observed my experimental units (animals). To get estimates for the means of factor A (genotype) at the levels of B (periods) there's nothing else for it but fill the mean (across the repeated measurements) of mean_bg3, isn't it?

Cheers,
Karin

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 3272 views
  • 0 likes
  • 3 in conversation