Shared Concepts

LSMEANS Statement

  • LSMEANS model-effects </ options>;

  • LSMEANS EFFECT=model-effects </ options>;

This section applies to the following procedures: GENSELECT, LMIXED, and LOGSELECT.

The lsmeans statement computes least squares means (LS-means) of classification fixed effects. As in the GLM procedure, LS-means are predicted population margins—that is, they estimate the marginal means over a balanced population. In a sense, LS-means are to unbalanced designs as classification and subclassification arithmetic means are to balanced designs. You can view LS-means as linear combinations of the parameter estimates that are constructed in such a way that they correspond to average predicted values in a population where the levels of classification variables are balanced.

Each LS-mean is computed as bold upper L ModifyingAbove bold italic beta With caret, where bold upper L is the coefficient matrix that is associated with the least squares mean and ModifyingAbove bold italic beta With caret is the estimate of the fixed-effects parameter vector. This bold upper L matrix is the same as the bold upper L matrix that is constructed in PROC GLM; however, the standard errors are adjusted for the covariance parameters in the model. The approximate standard errors for the LS-mean are computed as the square root of bold upper L left parenthesis bold upper X prime ModifyingAbove bold upper V With caret Superscript negative 1 Baseline bold upper X right parenthesis Superscript minus Baseline bold upper L prime. The approximate variance matrix of the fixed-effects estimates depends on the estimation method.

LS-means can be computed for any effect in the procedure’s MODEL statement that involves only classification variables. You can specify multiple model-effects in one lsmeans statement or in multiple lsmeans statements, and all lsmeans statements must appear after the model statement. When you restore a model from an item store by using PROC GENSELECT or PROC LOGSELECT, then you must specify the desired model-effects in the EFFECT= option before the slash (/).

The bold upper L matrix is tested for estimability, and if this test fails, the procedure displays "Non-est" for the LS-means entries. Note that linear functions of LS-means, such as differences, can be estimable even when the means themselves are not estimable. Estimability checks for differences are thus applied separately from checks for the means. Assuming that the LS-mean is estimable, the procedure constructs an approximate normal test or t test (depending on the procedure) to test the null hypothesis that the associated population quantity equals zero. By default, the denominator degrees of freedom for the t test are the residual degrees of freedom.

Table 8 summarizes the options that are available in the lsmeans statement. All options are subsequently discussed in alphabetical order. Note that the df= and slice= options are available only with the LMIXED procedure.

Table 8: LSMEANS Statement Options

Option Description
Construction and Computation of LS-Means
AT Modifies covariate values used to compute LS-means
ATVAR Modifies covariate values for restored models
DIFF Computes differences of LS-means
SINGULAR= Tunes estimability checking
SLICE= Partitions interaction LS-means effects
Degrees of Freedom and p-Values
ADJUST= Specifies the multiple comparison adjustment method for LS-means differences
ALPHA=alpha Specifies the confidence level (1 minus alpha)
DF= Assigns a specific value to the degrees of freedom for tests and confidence limits
Statistical Output
CL Constructs confidence limits for means and mean differences
CORR Displays the correlation matrix of LS-means
COV Displays the covariance matrix of LS-means
E Displays the bold upper L matrix


You can specify the following options in the LSMEANS statement after a slash (/):

ADJUST=method

computes a multiple comparison adjustment for the p-values and confidence limits for the differences of LS-means. The adjusted quantities are produced along with the unadjusted quantities. The adjust= option works together with the diff option. If you omit the diff option and specify a method other than NONE, then the adjust= option invokes the diff option.

You must specify one of the following methods for the adjust= option:

BON

performs Bonferroni t tests of differences between LS-means. The method involves correction factors described in Chapter 53, The GLM Procedure (SAS/STAT User's Guide), and Chapter 86, The MULTTEST Procedure (SAS/STAT User's Guide); also see Westfall and Young (1993) and Westfall et al. (1999).

DUNNETT

performs Dunnett’s t test, which tests whether any treatments are significantly different from a single control for the effects in the lsmeans statement. When the LS-means are correlated, the procedure uses the factor-analytic covariance approximation described in Hsu (1992) and identifies the adjustment as "Dunnett-Hsu" in the results. The approximation derives approximate "effective sample sizes" for which exact critical values are computed.

NELSON

performs Nelson’s t test of each LS-mean against an average of the LS-means (Ott 1967; Nelson 1982, 1991, 1993). When the LS-means are correlated, the procedure uses the factor-analytic covariance approximation described in Hsu (1992) and identifies the adjustment as "Nelson-Hsu" in the results. The approximation derives approximate "effective sample sizes" for which exact critical values are computed.

NONE | T

performs no adjustment for multiple comparisons.

SCHEFFE

performs Scheffé’s multiple comparison procedure.

SIDAK

performs pairwise t tests on differences between LS-means with levels adjusted according to Šidák’s inequality. The method involves correction factors described in Chapter 53, The GLM Procedure (SAS/STAT User's Guide), and Chapter 86, The MULTTEST Procedure (SAS/STAT User's Guide); also see Westfall and Young (1993) and Westfall et al. (1999).

SIMULATE <( simopts )>

performs the simulation-based multiple comparison procedure. This method computes adjusted p-values and confidence limits from the simulated distribution of the maximum or maximum absolute value of a multivariate t random vector. All covariance parameters, except the residual scale parameter, are fixed at their estimated values throughout the simulation, potentially resulting in some underdispersion. The simulation estimates q, the true left parenthesis 1 minus alpha right parenthesis quantile, where 1 minus alpha is the confidence coefficient. The default value of alpha is 0.05; you can change this value by specifying the alpha= option in the lsmeans statement.

The number of samples is set so that the tail area for the simulated q is within gamma of 1 minus alpha with 100 left parenthesis 1 minus epsilon right parenthesis% confidence. In equation form,

normal upper P normal r left parenthesis StartAbsoluteValue upper F left parenthesis ModifyingAbove q With caret right parenthesis minus left parenthesis 1 minus alpha right parenthesis EndAbsoluteValue less than or equals gamma right parenthesis equals 1 minus epsilon

where ModifyingAbove q With caret is the simulated q and F is the true distribution function of the maximum; see Edwards and Berry (1987) for details. By default, gamma = 0.005 and epsilon = 0.01, placing the tail area of ModifyingAbove q With caret within 0.005 of 0.95 with 99% confidence.

You can specify the following simopts options in parentheses after the ADJUST=SIMULATE option:

ACC=value

specifies the target accuracy radius gamma of a 100 left parenthesis 1 minus epsilon right parenthesis% confidence interval for the true probability content of the estimated left parenthesis 1 minus alpha right parenthesis quantile. By default, ACC=0.005. Note that if you also specify the CVADJUST simoption, then the actual accuracy radius will probably be substantially less than this target.

CVADJUST

estimates the quantile by the control variate adjustment method of Hsu and Nelson (1998) instead of simply as the quantile of the simulated sample. Specifying this option usually has the effect of significantly reducing the accuracy radius gamma of a 100 times left parenthesis 1 minus epsilon right parenthesis% confidence interval for the true probability content of the estimated left parenthesis 1 minus alpha right parenthesis quantile. The control-variate-adjusted quantile estimate takes approximately twice as long to compute, but it is typically much more accurate than the sample quantile.

EPS=value

specifies the value epsilon for a 100 times left parenthesis 1 minus epsilon right parenthesis% confidence interval for the true probability content of the estimated left parenthesis 1 minus alpha right parenthesis quantile. The default value of the accuracy confidence is 99%, corresponding to EPS=0.01.

NSAMP=n

specifies the sample size for the simulation. By default, n is set by a formula that is based on the values of the target accuracy radius gamma and accuracy confidence 100 times left parenthesis 1 minus epsilon right parenthesis% for an interval for the true probability content of the estimated left parenthesis 1 minus alpha right parenthesis quantile. When the default values are used for gamma, epsilon, and alpha (0.005, 0.01, and 0.05, respectively), NSAMP=12605. If you omit the NSAMP= option or specify NSAMP=0, the default sample size is used.

REPORT

displays a report on the simulation, including a listing of the parameters, such as gamma, epsilon, and alpha, as well as an analysis of various methods of estimating or approximating the quantile.

SEED=number

specifies an integer to be used to start the pseudorandom number generator for the simulation. If you do not specify a seed, or if you specify a number less than or equal to 0, the seed is generated by reading the time of day from the computer’s clock.

SMM | GT2

performs pairwise comparisons based on the studentized maximum modulus and Šidák’s uncorrelated-t inequality, yielding Hochberg’s GT2 method when sample sizes are unequal.

T | NONE

performs no adjustment for multiple comparisons.

TUKEY

performs Tukey’s studentized range test on LS-means. When your data are unbalanced, the procedure uses the approximation described in Kramer (1956) and identifies the adjustment as "Tukey-Kramer" in the results.

By default, ADJUST=NONE.

If you specify ADJUST=DUNNETT, the procedure analyzes all differences with the first control level unless you have specified a different control level. If you specify ADJUST=NELSON, then diff=ANOM is assumed.

If you specify ADJUST=TUKEY, then diff=ALL is assumed. If you specify other methods, then the procedure performs all pairwise differences unless you specify the diff option.

Note that computing the exact adjusted p-values and critical values for unbalanced designs can be computationally intensive, especially for ADJUST=NELSON.

ALPHA=number

specifies that a confidence interval be constructed for each of the LS-means with confidence level 1 minus sans serif italic number. The value of number is between 0 and 1; the default is 0.05.

AT at-specification

enables you to modify the values of the covariates that are used in computing LS-means. By default, all covariates are set equal to their mean values for computing standard LS-means. The at option enables you to assign arbitrary values to the covariates. Additional columns in the output table indicate the values of the covariates.

You can specify the following at-specifications:

MEANS

sets covariates equal to their mean values (as with standard LS-means) and applies this adjustment to crossproducts of covariates.

variable=value

sets the covariate variable equal to value.

(variable-list)=(value-list)

sets covariates in the variable-list equal to values in the value-list.

Consider the following example:

class A B;
model Y = A*B x1 x2 x1*x2;
LSMEANS A*B;
LSMEANS A*B / at means;
LSMEANS A*B / at x1=1.2;
LSMEANS A*B / at (x1 x2)=(1.2 0.3);

For the first two LSMEANS statements, the LS-means coefficient of x1 is x overbar Subscript 1 (the mean of x1) and of x2 is x overbar Subscript 2 (the mean of x2). For the first LSMEANS statement, the coefficient of x1*x2 is ModifyingAbove x 1 x 2 With bar. However, for the second LSMEANS statement, the coefficient is x overbar Subscript 1 Baseline times x overbar Subscript 2. The third LSMEANS statement sets the coefficient of x1 equal to 1.2 and leaves it at x overbar Subscript 2 for x2, and the final LSMEANS statement sets these values to 1.2 and 0.3, respectively.

Even if you specify a weight variable, the unweighted covariate means are used for the covariate coefficients if you omit the at option. If you specify the at option, then weight and frequency variables are taken into account as follows. The weighted covariate means are used for the covariate coefficients for which no explicit at option values are given, or if you specify the AT MEANS option. Observations that do not contribute to the analysis because of a missing dependent variable are used in computing the covariate means. You should use the e option in conjunction with the at option to verify that the modified LS-means coefficients are the ones that you want.

ATVAR at-specification

is the same as the AT option, except that it is required when you restore a model from an item store but do not provide a data table. This option is available with the GENSELECT and LOGSELECT procedures.

CL

constructs confidence limits for each of the LS-means. The LMIXED procedure computes t-type limits, whereas other procedures compute normal (z) intervals. If you specify the DDFM=NONE option in the MODEL statement in PROC LMIXED, then infinite degrees of freedom are used for this test, which essentially computes a z interval. The confidence level is 0.95 by default; you can change the level by specifying the alpha= option.

CORR

displays the estimated correlation matrix of the least squares means as part of the "Least Squares Means" table.

COV

displays the estimated covariance matrix of the least squares means as part of the "Least Squares Means" table.

DF=number

specifies the degrees of freedom for the t test and confidence limits. The default is the residual degrees of freedom that you define by specifying the DDFM=RESIDUAL option in the MODEL statement in the LMIXED procedure. This option is available only for PROC LMIXED.

DIFF<=difftype>

displays differences of the LS-means in the "Differences of Least Squares Means" table. You can specify the following values for the optional difftype:

ALL

displays all pairwise differences.

ANOM

displays differences between each LS-mean and the average LS-mean, as in the analysis of means (Ott 1967). The average is computed as a weighted mean of the LS-means, with the weights being inversely proportional to the diagonal entries of the bold upper L left parenthesis bold upper X prime bold upper X right parenthesis Superscript minus Baseline bold upper L prime matrix. When you specify a weight statement, the preceding matrix is replaced with bold upper L left parenthesis bold upper X prime bold upper W bold upper X right parenthesis Superscript minus Baseline bold upper L prime, where bold upper W is the diagonal matrix that contains the weights. If LS-means are nonestimable, this design-based weighted mean is replaced with an equally weighted mean. Note that the ANOM procedure in SAS/QC software implements both tables and graphics for the analysis of means with a variety of response types. For one-way designs and normally distributed data, the ANOM computations are equivalent to the results of PROC ANOM.

CONTROL<('level1'<,'level2',…>)>

produces two-tailed tests and confidence limits for differences with a control; by default, the control is the first level of each specified LS-mean effect. To specify which levels of the effects are the controls, list the quoted formatted values in parentheses after the CONTROL keyword. For example, if the effects A, B, and C are classification variables, each having two levels, 1 and 2, the following lsmeans statement specifies the (1,2) level of A*B and the (2,1) level of B*C as controls:

lsmeans A*B B*C / diff=control('1' '2', '2' '1');

For multiple effects, the results depend on the order of the list, so you should check the output to make sure that the controls are correct.

CONTROLL

produces one-tailed results and tests whether the noncontrol levels are significantly smaller than the control. The upper confidence limits for the control minus the noncontrol levels are considered to be infinity and are displayed as missing.

CONTROLU

produces one-tailed results and tests whether the noncontrol levels are significantly larger than the control. The upper confidence limits for the noncontrol levels minus the control are considered to be infinity and are displayed as missing.

E

displays the matrix coefficients for all LS-mean effects in the "Matrix Coefficients" table.

PDIFF<=difftype>

is the same as the DIFF option.

SINGULAR=number

tunes the estimability checking. If bold v is a vector, define ABS(bold v) to be the largest absolute value of the elements of bold v. If ABS(bold upper L minus bold upper L bold upper T) is greater than c*number for any row of bold upper L in the contrast, then bold upper L bold italic beta is declared nonestimable. Here, bold upper T is the Hermite form matrix left parenthesis bold upper X prime bold upper X right parenthesis Superscript minus Baseline bold upper X prime bold upper X, and c is ABS(bold upper L), except when it equals 0, and then c is 1. The value of number is between 0 and 1; the default is 1E–4.

SLICE=effect1 <,effect2, …>}

specifies effects by which to partition interaction LS-mean effects. This option is available only for the LMIXED procedure. This partition can produce what are known as tests of simple effects (Winer 1971). For example, suppose that A*B is significant, and you want to test the effect of A for each level of B. The appropriate lsmeans statement is

lsmeans A*B / slice=B;

This statement tests for the simple main effects of A for B, which are calculated by extracting the appropriate rows from the coefficient matrix for the A*B LS-means and by using them to form an F test.

The slice= option produces F tests that test the simultaneous equality of cell means at a fixed level of the slice effect (Schabenberger, Gregoire, and Kong 2000). It produces a table titled "Tests of Effect Slices."

Last updated: June 22, 2026