LMIXED Procedure

MARGINS Statement

  • MARGINS fixed-effects </ options>;

The MARGINS statement computes predictive margins of fixed effects. You can compute predictive margins for any effect in the MODEL statement that involves only classification variables.

The predictive margin for a specific level (group) of a fixed effect represents the average predicted response if all the observations in the data set were in that group (Lane and Nelder 1982; Chang, Gelman, and Pagano 1982). You compute the predictive margin by fixing this effect at the specified level for all observations and averaging the predicted responses. The standard error of the predictive margin is computed by using the delta method. The weighted average predicted response is the weighted predictive margins.

For example, consider the simple regression , where is the effect of the ith level of the classification effect , , and is the covariate for the jth observation in the ith level of the effect , . Then the predictive margin for level r of effect is

where .

For a more complex example, consider the following linear model with an interaction effect:

data mylib.bal;
input sex$ group rep y yname$;
cards;
boy    2    1   12  y1
boy    2    2    8  y2
boy    3    1   14  y3
boy    3    2    9  y4
girl   1    1   10  y5
girl   1    2   23  y6
girl   2    1   14  y7
girl   2    2   13  y8
girl   3    1   13  y9
girl   3    2   12  y10
;

proc lmixed data=mylib.bal;
   class sex group;
   model y = sex group sex*group;
   margins sex;
run;

The model fits the data that have ten observations: four of them are for the variable boy, and six of them are for the variable girl. Notice that group 1 has no data for boy. The predictive margin for boy is the average of the predicted values of these ten response variables, assuming that all responses are observed from boys. However, you cannot compute the predicted values for y5 and y6 for boy because y5 and y6 are in group 1, which is a group level that is absent from the data for boys. Thus, the predictive margin for boy is not predictable. This nonpredictability is caused by the lack of estimated parameters for boy interacting with group 1, which is due to the missing information in the interaction effect.

You can specify multiple effects in one or multiple MARGINS statements. Predictive margin computations are not supported for constructed effects.

PROC LMIXED constructs an approximate t test to determine whether the null hypothesis that the associated population quantity equals zero is valid. By default, the denominator degrees of freedom for this test are the same as those displayed for the effect in the "Type III Tests of Fixed Effects" table.

Table 8 summarizes the options available in the MARGINS statement. All these options are discussed in alphabetical order after the table.

Table 8: MARGINS Statement Options

Option Description
Construction and Computation of Predictive Margins
AT Modifies the covariate value in computing predictive margins
DIFF Computes differences of predictive margins
SLICEBY= Partitions F tests
SLICEDIFF Computes differences of sliced predictive margins and determines the types of differences
WEIGHT Computes the weighted predictive margins
Degrees of Freedom and p-Values
ADJUST= Specifies the method of multiple comparison adjustment of predictive margin differences
ALPHA= Specifies the confidence level ()
DF= Assigns specific value to degrees of freedom for tests and confidence limits
Statistical Output
CL Constructs confidence limits for predictive margins and/or predictive margin differences


You can specify the following options in the MARGINS statement after a slash (/).

ADJUST=method

performs a multiple comparison adjustment of the p-values and confidence limits for the differences of predictive margins. The adjusted quantities are produced in addition to the unadjusted quantities. By default, PROC LMIXED performs all pairwise differences. If you specify ADJUST=DUNNETT, the procedure analyzes all differences with a control level. The ADJUST= option does not imply the DIFF option.

Adjusted confidence limits are produced if you specify the CL or ALPHA= option. For a description of the adjustments, see the ADJUST= option in the LSMEANS statement.

You can specify the following methods:

BON

performs Bonferroni t tests of differences between margins. This 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 determines whether any treatments are significantly different from a single control for the effects in the MARGINS statement.

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. This 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<(simoptions)>

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 quantile, where is the confidence coefficient. For a description of the simoptions (except for the CVADJUST option, which you cannot use in the MARGINS statement), see the ADJUST= option in the LSMEANS statement.

TUKEY

performs Tukey’s studentized range test on the predictive margins.

ALPHA=number

constructs a t-type confidence interval for each of the predictive margins with confidence level is . The value of number must be between 0 and 1, exclusive; by default, ALPHA=0.05.

AT at-specification

enables you to modify the values of the covariates that are used in computing predictive margins. By default, all covariate effects 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.

As an example, consider the following invocation of PROC LMIXED:

proc lmixed;
   class A;
   model Y = A x1 x2 x1*x2;
   margins A;
   margins A / at means;
   margins A / at x1=1.2;
   margins A / at (x1 x2)=(1.2 0.3);
run;

The first MARGINS statement sets x1 and x2 to their observed values for each observation. For the second MARGINS statement, x1 is set to (the mean of x1) and x2 is set to (the mean of x2). Their interaction is set to . The third MARGINS statement sets x1 to 1.2, and the final MARGINS statement sets these variables to 1.2 and 0.3, respectively.

Even if you specify a weight variable in the WEIGHT statement, the unweighted covariate means are used for the covariate coefficients if you omit the AT option. If you specify the AT option, the weight variable in the WEIGHT statement or the frequency variable in the FREQ statement is 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.

CL

constructs t-type confidence limits for each of the predictive margins. If DDFM=NONE, then PROC LMIXED uses infinite degrees of freedom for this test, essentially computing a z interval. The confidence level is 0.95 by default; you can change this by specifying the ALPHA= option. If you specify an ADJUST= option, then the confidence limits are adjusted for multiplicity.

DF=number

specifies the degrees of freedom for the t test and confidence limits. The default is the denominator degrees of freedom from the "Type III Tests of Fixed Effects" table corresponding to the margins effect.

DIFF<=difftype>
PDIFF<=difftype>

displays differences of the predictive margins. The optional difftype specifies which differences to produce; the difftype values are ALL, CONTROL, CONTROLL, and CONTROLU. The ALL difftype displays all pairwise differences; it is the default. The CONTROL difftype displays differences between each margin and a control, which, by default, is the first level of each effect that you specify in the MARGINS statement.

To specify which levels of the effects are the controls, list the quoted formatted values in parentheses after the CONTROL keyword. For example, for the classification variables A, B, and C, each having two levels, 1 and 2, the following MARGINS statement specifies the (1,2) level of A*B and the (2,1) level of B*C as controls:

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

For an effect that has multiple classification variables, the quoted formatted values are assigned to these variables in the order in which they appear in the CLASS statement.

Two-tailed tests and confidence limits are associated with the CONTROL difftype. For one-tailed results, use either the CONTROLL or CONTROLU difftype. The CONTROLL difftype tests whether the noncontrol levels are significantly smaller than the control level; the upper confidence limits for the control level minus the noncontrol levels are considered to be infinity and are displayed as missing. Conversely, the CONTROLU difftype tests whether the noncontrol levels are significantly larger than the control level; the upper confidence limits for the noncontrol levels minus the control level are considered to be infinity and are displayed as missing.

If you want to perform multiple comparison adjustments on the differences of predictive margins, you must specify the ADJUST= option.

SLICEBY=fixed-effect | (fixed-effects)
SLICE=fixed-effect | (fixed-effects)

specifies effects by which to partition interaction effects that you specify in the MARGINS statement. This option produces tests of margins for each level of the specified slice effect.

For example, suppose that the effect specified in the MARGINS statement is A*B. To test the margins of A*B for each level of A, you can specify the following statement:

margins A*B / sliceby=A;

The SLICEBY= option produces an F test that performs a test of the simultaneous equality of the margins at a fixed level of the slice effect A. You can compute differences of the margins while holding one or more factors at a fixed level by specifying the SLICEDIFF option.

SLICEDIFF<=difftype>

constructs the specified type of differences for the sliced margins and tests them against zero. The difftype values are ALL, CONTROL, CONTROLL, and CONTROLU. The ALL difftype computes all pairwise differences; it is the default. The CONTROL, CONTROLL, and CONTROLU difftypes compute the differences between each margin and a control. Whereas the SLICEBY= option tests the simultaneous equality of the margins at a fixed level of the slice effect, the SLICEDIFF option tests pairwise differences of these margins. This enables you to perform multiple comparisons among the levels of one factor at a fixed level of the other factor.

For example, assume that, in a certain design, factors A and B have a = 4 and b = 3 levels, respectively. Consider the following statements:

proc lmixed;
   class A B;
   model y = A B A*B;
   margins A*B / sliceby=A;
   margins A*B / sliceby=A slicediff=all;
run;

The first MARGINS statement produces four F tests, one per level of A. Denote the three margins that correspond to the first level of A as , , and . Then the first F test determines whether the two-degrees-of-freedom hypothesis is valid:

The SLICEDIFF option performs tests of the differences between all pairs of these three margins. In the example, this corresponds to tests of the following form:

In the example, where a = 4 and b = 3, the second MARGINS statement produces four sets of predictive margin differences. Within each set, factor A is held fixed at a particular level, and each set consists of three comparisons.

For differences between each margin and a control, the default control is the first level of each effect that you specify in the MARGINS statement. To specify which levels of the effects are the controls, list the quoted formatted values in parentheses after the keyword CONTROL.

For example, if the effects A, B, and C are classification variables, each having three levels (1, 2, and 3), the following MARGINS statement specifies the (1,3) level of A*B as the control:

margins A*B / sliceby=(A B)
              slicediff=control('1' '3');

This MARGINS statement first produces predictive margin differences while holding the levels of A fixed, and then it produces predictive margin differences while holding the levels of B fixed. In the former case, level '3' of B serves as the control level. In the latter case, level '1' of A serves as the control.

For an effect that has multiple classification variables, the quoted formatted values are assigned to these variables in the order in which they appear in the CLASS statement.

Two-tailed tests and confidence limits are associated with the CONTROL difftype. For one-tailed results, use either the CONTROLL or CONTROLU difftype. The CONTROLL difftype tests whether the noncontrol levels are significantly smaller than the control level; the upper confidence limits for the control level minus the noncontrol levels are considered to be infinity and are displayed as missing. Conversely, the CONTROLU difftype tests whether the noncontrol levels are significantly larger than the control level; the upper confidence limits for the noncontrol levels minus the control level are considered to be infinity and are displayed as missing.

When you specify the ADJUST= option, the LMIXED procedure also adjusts the tests for multiplicity. The adjustment is based on the number of comparisons within each level of the SLICEBY= effect.

WEIGHT

computes the weighted predictive margins. The weight values are provided by the WEIGHT statement. By default, the unweighted predictive margins are computed even if you specify the WEIGHT statement.

Last updated: May 14, 2026