Chapter Contents |
Previous |
Next |

The GLM Procedure |

- Set all
*L*_{i}corresponding to covariates (continuous variables) to their mean value. - Consider effects contained by the given effect.
Set the
*L*_{i}corresponding to levels associated with the given level equal to 1. Set all other*L*_{i}in these effects equal to 0. (See Chapter 12, "The Four Types of Estimable Functions," for a definition of*containing*.) - Consider the given effect.
Set the
*L*_{i}corresponding to the given level equal to 1. Set the*L*_{i}corresponding to other levels equal to 0. - Consider the effects that contain the given effect.
If these effects are not nested within the given effect,
then set the
*L*_{i}corresponding to the given level to 1/*k*, where*k*is the number of such columns. If these effects are nested within the given effect, then set the*L*_{i}corresponding to the given level to 1/(*k*_{1}*k*), where_{2}*k*is the number of nested levels within this combination of nested effects, and_{1}*k*is the number of such combinations. For_{2}*L*_{i}corresponding to other levels, use 0. - Consider the other effects not yet considered.
If there are no nested factors, then set all
*L*_{i}corresponding to this effect to 1/*j*, where*j*is the number of levels in the effect. If there are nested factors, then set all*L*_{i}corresponding to this effect to 1/(*j*_{1}*j*), where_{2}*j*is the number of nested levels within a given combination of nested effects and_{1}*j*is the number of such combinations._{2}

The consequence of these rules is that the sum of the Xs within any classification effect is 1. This set of Xs forms a linear combination of the parameters that is checked for estimability before it is evaluated.

For example, consider the following model:

proc glm; class A B C; model Y=A B A*B C Z; lsmeans A B A*B C; run;

Assume A has 3 levels, B has 2 levels, and C has 2 levels, and assume that every combination of levels of A and B exists in the data. Assume also that Z is a continuous variable with an average of 12.5. Then the least-squares means are computed by the following linear combinations of the parameter estimates:

A | B | A*B | C | |||||||||||||||||

1 | 2 | 3 | 1 | 2 | 11 | 12 | 21 | 22 | 31 | 32 | 1 | 2 | Z | |||||||

LSM( ) | 1 | 1/3 | 1/3 | 1/3 | 1/2 | 1/2 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/2 | 1/2 | 12.5 | |||||

LSM(A1) | 1 | 1 | 0 | 0 | 1/2 | 1/2 | 1/2 | 1/2 | 0 | 0 | 0 | 0 | 1/2 | 1/2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 |

If there is an effect containing two or more covariates, the AT option sets the effect equal to the product of the individual means rather than the mean of the product (as with standard LS-means calculations). The AT MEANS option leaves covariates equal to their mean values (as with standard LS-means) and incorporates this adjustment to cross products of covariates.

As an example, the following is a model with a classification variable A and two continuous variables, x1 and x2:

class A; model y = A x1 x2 x1*x2;

The coefficients for the continuous effects with various AT specifications are shown in the following table.

Syntax |
x1 |
x2 |
x1*x2 |

lsmeans A; | |||

lsmeans A / at means; | |||

lsmeans A / at x1=1.2; | 1.2 | ||

lsmeans A / at (x1 x2)=(1.2 0.3); | 1.2 | 0.3 | 1.2·0.3 |

For the first two LSMEANS statements, the A LS-mean coefficient for x1 is (the mean of x1) and for x2 is (the mean of x2). However, for the first LSMEANS statement, the coefficient for x1*x2 is , but for the second LSMEANS statement the coefficient is . The third LSMEANS statement sets the coefficient for x1 equal to 1.2 and leaves that for x2 at , and the final LSMEANS statement sets these values to 1.2 and 0.3, respectively.

If you specify a WEIGHT variable, then weighted means are used for the covariate values. Also, observations with missing dependent variables are included in computing the covariate means, unless these observations form a missing cell. You can use the E option in conjunction with the AT option to check that the modified LS-means coefficients are the ones you desire.

The AT option is disabled if you specify the BYLEVEL option, in which case the coefficients for the covariates are set equal to their means within each level of the LS-mean effect in question.

In computing the observed margins, PROC GLM uses all observations for which there are no missing independent variables, including those for which there are missing dependent variables. Also, if there is a WEIGHT variable, PROC GLM uses weighted margins to construct the LS-means coefficients. If the analysis data set is balanced or if you specify a simple one-way model, the LS-means will be unchanged by the OM option.

The BYLEVEL option modifies the observed-margins LS-means. Instead of computing the margins across the entire data set, PROC GLM computes separate margins for each level of the LS-mean effect in question. The resulting LS-means are actually equal to raw means in this case. The BYLEVEL option disables the AT option if it is specified.

Note that the MIXED procedure implements a more versatile form of the OM option, enabling you to specifying an alternative data set over which to compute observed margins. If you use the BYLEVEL option, too, then this data set is effectively the "population" over which the population marginal means are computed. See Chapter 41, "The MIXED Procedure," for more information.

You may want to use the E option in conjunction with either the OM or BYLEVEL option to check that the modified LS-means coefficients are the ones you desire. It is possible that the modified LS-means are not estimable when the standard ones are, or vice versa.

Chapter Contents |
Previous |
Next |
Top |

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.