Contents: |
Purpose / History / Requirements / Usage / Details / Limitations / See Also |

*PURPOSE:*- Provide multiple comparisons (pairwise, sequential, or against a control) on the mean scale among the levels of an effect in a generalized linear model. More complex contrasts of means and ratios of pairs of means can also be estimated and tested.
*HISTORY:*- The version of the NLMeans macro that you are using is displayed in the log when you specify
**version**(or any string) as the first argument. For example:%NLMeans(version, )

The NLMeans macro always attempts to check for a later version of itself. If it is unable to do this (such as if there is no active internet connection available), the macro will issue the following message in the log:

NOTE: Unable to check for newer version

The computations performed by the macro are not affected by the appearance of this message.

*Version**Update Notes*1.04 Store sets of results in data sets EST1, EST2, ... . Append all sets into a single results file using **options=append**.1.03 Fix for LABEL variable in contrasts= data set. 1.02 Minor fix to version printing. 1.01 A LABEL variable can optionally be included in the **contrasts=**data set.1.0 Initial coding *REQUIREMENTS:*- Base SAS
^{®}, SAS/STAT^{®}and the NLEstimate macro (Version 1.5 or later) are required. *USAGE:*- Follow the instructions in the Downloads tab of this sample to save the NLMeans macro definition. Follow similar instructions to download and define the NLEstimate macro. Replace the text within quotation marks in the following statements with the locations of the NLMeans and NLEstimate macro definition files on your system. In your SAS program or in the SAS editor window, specify these statements to define both macros and make them available for use:
%inc "<location of your file containing the NLEstimate macro>"; %inc "<location of your file containing the NLMeans macro>";

After defining both macros, fit a generalized linear model and include one or more LSMEANS, SLICE, or ESTIMATE statements with the E option and save the model using the STORE statement. You can then call the NLMeans macro to compare means. See the Results tab for examples.

The following parameters are required when using the NLMeans macro. The necessary model information is provided to the macro by specifying either the

**instore=**parameter or both the**inest=**and**incovb=**parameters. If the modeling procedure provides a STORE statement for saving the fitted model,**instore=**is the better method for providing the model information.**instore=***item-store*- Specifies the fitted model that was saved using the STORE statement in the modeling procedure. The OUT= option in the STORE statement saves the model in a file known as an
*item store*. This is the preferred method for providing the required model information. However, if the modeling procedure does not offer the STORE statement, then you might be able to use the**inest=**and**incovb=**parameters. See Limitations below.

... or both of the following ...

**inest=***data-set-name*- Specifies the data set of parameter estimates saved using an ODS OUTPUT statement in the modeling procedure. The parameter estimates of the model should be stored in a variable named ESTIMATE in this data set. An error is issued if the ESTIMATE variable is not found.
**incovb=***data-set-name*- Specifies the data set containing the variance-covariance matrix of model parameters saved using an ODS OUTPUT statement in the modeling procedure. Typically, an option such as COVB is required in the modeling procedure to make this matrix available for saving. If the saved data set contains numeric variables other than those containing the covariance matrix, they should be removed before specifying the data set in this macro parameter in order to avoid a compatibility error. The
**incovb=**data set should have the same number of observations (rows) and variables (columns) as the number of rows in the**inest=**data set in order to be compatible. See Limitations below.

The following parameters are also required:

**coef=***data-set-name*- Specifies the data set of estimate coefficients saved using an ODS OUTPUT statement in the modeling procedure. The required table must first be produced by including the E option in the LSMEANS, SLICE, or ESTIMATE statement in the modeling procedure. The table name is typically Coef and can be saved in a data set by specifying

ods output Coef=*data-set-name*; **link=***link-function*- Specifies the link function used in the modeling procedure, typically in the LINK= option in the MODEL statement. Note that for models fit by PROC PROBIT which specifies the link with the DIST= option, specify
**link=probit**or**cumprobit**when DIST=NORMAL;**link=logit**or**cumlogit**when DIST=LOGISTIC; or**link=cll**or**cumcll**when DIST=EXTREME or GOMPERTZ.

The following parameters are optional:

**diff=***type <type>*...

where*type*is**all**,**seq**, or*number*- To estimate and test all pairwise differences of means, specify
**diff=all**. Sequential differences of means (μ1-μ2, μ2-μ3, ...) are provided when**diff=seq**. To obtain all differences with a control level, specify**diff=***number*, where*number*is the position of the control level in the ordered list of levels shown in the results from the modeling procedure. For example, if level A is the control in a variable whose levels are shown in the order A, B, C, then specify**diff=1**. When there are multiple sets of estimates from the modeling procedure (presented in multiple tables), such as when the SLICE / E SLICEBY= statement is used or when multiple LSMEANS /E, SLICE /E, or ESTIMATE /E statements are used, then you can either specify a single*type*to apply to all estimate sets, or a list of*types*to apply different*types*to the sets. If**diff=**is omitted, all pairwise differences are done for all sets (**diff=all**). **contrasts=***data-set-name*- Specifies an optional data of coefficients defining contrasts among the estimates in each set of estimates. The specified data set must contain a variable named SET and
*k*variables named K1, K2, ... , K*k*, where*k*is the number of Row variables in**coef=**data set. Optionally, a LABEL variable can be included to label each of the specified contrasts. For a given row in the data set, the value of SET indicates the set of estimates that the contrast in that row applies to. The SET value must match one of the values of the LMatrix variable in the**coef=**data set. The K variables correspond to the Row variables in the**coef=**data set which define each estimate. For multinomial models,*k*=*mf*where*m*is the number of estimates requested in each response function and*f*is the number of response functions. For**link=glogit**models,*k*=*mf*+*m*. The additional set of*m*variables correspond to the last response level. See the description of**options=ratio**for limitations on the contrast coefficients when mean ratios are desired. If**contrasts=**and**diff=**are both specified,**diff=**is ignored. **df=***value*- Specifies the degrees of freedom to be used in the tests and confidence intervals computed for the estimated functions. If omitted, large-sample Wald statistics are given. The degrees of freedom for testing a linear combination of parameters in a linear model would typically be the number of observations used in fitting the model minus the number of parameters estimated in the model – essentially, the error degrees of freedom.
**alpha=***value*- Specifies the alpha level to be used in computing confidence limits. If omitted,
**alpha=0.05**. **title=***title-text*- Specifies a title for the table(s) of results. The
*title-text*must not contain quotes (" or '), ampersands (&), commas, or parentheses. If omitted,**title=**Nonlinear Function Estimate. **options=<JOINT|NOJOINT> <NAMES|NONAMES> <REVERSE|NOREVERSE> <RATIO|NORATIO> <DIFINFNS|DIFALL> <APPEND|NOAPPEND>**- Use
**options=**to enable or disable any of several binary options. JOINT combines multiple sets of estimates into a single set before differencing or applying contrasts. NAMES displays the names of the model parameters used by the NLEstimate macro. REVERSE reverses the direction of differencing done by**diff=**. REVERSE is ignored when**contrasts=**is specified. RATIO requests estimation of ratios rather than differences of pairs of means. RATIO can be used with**diff=**or**contrasts=**, but with**contrasts=**each contrast must specify exactly one 1 coefficient to select the numerator, one -1 coefficient to select the denominator, and 0 coefficients otherwise. For multinomial models, DIFALL applies the differencing type specified in**diff=**across all estimates rather than within the response functions as done by DIFINFNS. This option is ignored for nonmultinomial models. APPEND merges results from all estimate sets into a single results data set named EST_ALL. NOAPPEND saves results sets in separate data sets (EST1, EST2, ...). The last results set is always saved in data set EST as well. If not specified,**options=nojoint nonames noreverse noratio difinfns noappend**.

*DETAILS:*- The NLMeans macro can be used after fitting a generalized linear model (GLM) and estimating multiple linear combinations of model parameters, L
_{i}β, which are response means when the inverse of the GLM link function,*g*, is applied. That is, μ_{i}=*g*^{-1}(L_{i}β). GLMs can be fit by several SAS/STAT procedures including GENMOD, GLIMMIX, LOGISTIC, PROBIT, SURVEYLOGISTIC, and GEE. L_{i}β estimates are available using the LSMEANS, SLICE, and ESTIMATE statements in the modeling procedure. The ILINK option in these statements provides estimates of the means, μ_{i}. If the STORE statement is used to save the fitted model, these statements are also available at any time using PROC PLM.While the DIFF option in the LSMEANS and SLICE statements provide pairwise differences on the link scale, L

_{i}β-L_{j}β, differences on the mean scale, μ_{i}-μ_{j}, are not available. Similarly, in an ESTIMATE statement that defines a difference, L_{i}β-L_{j}β, the ILINK option applies the inverse of the link function to the difference, g^{-1}(L_{1}β-L_{2}β) rather than computing the difference of the inverse linked estimates g^{-1}(L_{1}β)-g^{-1}(L_{2}β) = μ_{i}-μ_{j}. The quantity g^{-1}(L_{1}β-L_{2}β) is generally only of interest in the case where the link function,*g*, is the log. In this case, the ILINK (or EXP) option estimates the ratio of means.Note that the NLMeans macro is not needed for models that use the identity link. This includes models fit by the REG, GLM, MIXED, or ORTHOREG procedures and others. For these models, differences of L

_{i}β are differences of μ_{i}. Consequently, the results of the DIFF option in the LSMEANS or SLICE statement, or the results of an ESTIMATE statement that defines a difference of L_{i}β directly provide the differences of μ_{i}. You can also use the LSMESTIMATE statement to estimate or test differences or contrasts of means.The NLMeans macro can be used to provide estimates and tests of differences of means, μ

_{i}-μ_{j}, ratios of means, μ_{i}/μ_{j}, or more complex contrasts of means, L_{i}μ_{i}. Standard errors are obtained using the delta method. To do this, you supply the saved model and a data set containing the coefficients, L_{i}, used by the LSMEANS, SLICE, or ESTIMATE statements. You also indicate the link function used in the model. The model is best saved using the STORE statement in the modeling procedure. The coefficients can be saved by including the E option in any LSMEANS, SLICE, or ESTIMATE statement specified in the procedure, and by including an ODS OUTPUT statement to save the displayed table of coefficients in a data set. In most cases, the name of the coefficients table is Coef, so the following statement saves it in a data set.ods output coef=

*data-set-name*;See the list of macro parameters above for details about how to provide the saved model and coefficients to the macro, about how to request means, ratios, or contrasts, and other options.

The macro can process more than one set of estimates. Multiple sets of estimates occur when the modeling procedure includes: a SLICE statement, multiple LSMEANS or ESTIMATE statements, or a combination of these statements. The macro processes each set and a table of results is displayed for each set of estimates. By default, the results from each set are saved in separate data sets named EST1, EST2, EST3, ... . Specify

**options=append**to create a single data set named EST_ALL of all results from all sets. If EST_ALL already exists, new results are appended to it. The last results set is also stored in data set EST.For ordinal multinomial models, the macro by default produces comparisons within each of the response functions. To do comparisons across all response functions, specify

**options=difall**. For nominal multinomial models (**link=glogit**), the macro produces comparisons within each of the response level probabilities. When specifying a**contrasts=**data set, each contrast (row) of the data set must contain coefficients for all estimates in all response functions (ordinal) or in all response levels (nominal).Since the LSMEANS and SLICE statements require GLM parameterized CLASS variables (PARAM=GLM in the CLASS statement), the NLEstimate macro called by the NLMeans macro will typically display the following Warning message in this log. This Warning can be ignored.

WARNING: The final Hessian matrix is not positive definite, and therefore the estimated covariance matrix is not full rank and may be unreliable. The variance of some parameter estimates is zero or some parameters are linearly related to other parameters.

*LIMITATIONS:*- The NLMeans macro cannot process results from a modeling procedure that used BY processing. Use a WHERE statement to select a single BY group before running the NLMeans macro.
The NLMeans macro is not intended for use with survival models (LIFEREG, PHREG, SURVEYPHREG), models from PROC CATMOD, or from SAS/ETS

^{®}procedures. The macro cannot be used to compare means from zero-inflated models fit by PROC GENMOD.For models fit by the GENMOD or GLIMMIX procedures, use the LSMEANS, SLICE, or ESTIMATE statements in PROC PLM after saving the fitted model using the STORE statement. Do not use those statements in GENMOD or GLIMMIX.

Note that the NLMeans macro cannot use coefficients produced by the LSMESTIMATE statement. The macro requires the coefficients that define the individual means.

The use of

**inest=**and**incovb=**should rarely, if ever, be necessary. If used, it is likely that modifications will be needed to those input data sets particularly when GLM parameterization of CLASS variables is used. In such cases, it might prove more convenient to use a full-rank parameterization and the NLEstimate macro directly. *SEE ALSO:*- The NLMeans macro forms the expressions to be evaluated. It then calls the NLEstimate macro to do the computations. See the NLEstimate macro description for details.

These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.

These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.

In addition to the following example, several more examples of using the NLMeans macro can be found in these notes:

- Estimating differences in probabilities with confidence interval
- Estimating rate differences (with confidence interval) using a Poisson model
- Estimating relative risks in a multinomial response model
- Estimating a relative risk (also called risk ratio, prevalence ratio)
- Estimating the difference in differences of means
- Estimating the risk (proportion) difference for matched pairs data with binary response

**EXAMPLE: Estimate difference or ratio in group means in a log-linked gamma model**- The example titled "Gamma Distribution Applied to Life Data" in the GENMOD documentation presents failure times of 201 machine parts from two manufacturers, denoted A and B. The following GENMOD statements fit the log-linked gamma model. The STORE statement saves the model in an item store for later use by the NLMeans macro. The LSMEANS statement with the ILINK option is used in PROC PLM to estimate the manufacturer means.
proc genmod data = lifdat; class mfg / param=glm; model lifetime = mfg / dist=gamma link=log; store out=gammod; run; proc plm restore=gammod; lsmeans mfg / e ilink diff exp; ods output coef=coeffs; run;

In the partial results below, the intercept, MFG_{A}, and MFG_{B}estimated model parameters are shown in the "Analysis Of Maximum Likelihood Parameter Estimates" table. The values in the Estimate column in the "MFG Least Squares Means" table are the estimates of the linear combinations of model parameters, L_{i}β, defined in the "Coefficients for MFG Least Squares Means" table. This table of coefficients is produced by the E option and will be needed by the NLMeans macro. From this table it can be seen that the MFG="A" estimate, 6.1501, is the Row1 linear combination defined as 1*Intercept+1*MFG_{A}. Similarly for MFG="B". Note that since the linear predictor in this gamma model estimates the log gamma mean, linear combinations of the model parameters, such as those from the LSMEANS or ESTIMATE statement, also estimate the log gamma mean. Therefore, 6.1501 is the estimated log mean for manufacturer A. 6.1302 is the estimated log mean for manufacturer B. The ILINK option in the LSMEANS statement applies the inverse of the link function to the estimates. In this log-linked model, that means that the estimates are exponentiated. The resulting mean estimates are presented in the column labelled "Mean". The estimated mean lifetimes are 468.74 for manufacturer A and 459.51 for manufacturer B. The DIFF option computes the pairwise differences among the LS-mean estimates and presents them in the "Differences of MFG Least Squares Means" table. This produces a difference of the log means, or equivalently a log ratio of means, in the Estimate column (0.01989). The EXP option exponentiates this difference producing in an estimated ratio of means in the Exponentiated column (1.0201). Note that the EXP option also exponentiates the estimates in the "MFG Least Squares Means" table resulting in the Exponentiated column that reproduces the Mean column from the ILINK option in this case.Analysis Of Maximum Likelihood Parameter Estimates Parameter DF Estimate Standard

ErrorWald 95% Confidence Limits Wald Chi-Square Pr > ChiSq Intercept 1 6.1302 0.1043 5.9257 6.3347 3451.61 <.0001 MFG A 1 0.0199 0.1559 -0.2857 0.3255 0.02 0.8985 MFG B 0 0.0000 0.0000 0.0000 0.0000 . . Scale 1 0.8275 0.0714 0.6987 0.9800

Coefficients for MFG Least

Squares MeansParameter MFG Row1 Row2 Intercept 1 1 MFG A A 1 MFG B B 1

MFG Least Squares Means MFG Estimate Standard Error z Value Pr > |z| Mean Standard Error

of MeanExponentiated A 6.1501 0.1159 53.07 <.0001 468.74 54.3172 468.74 B 6.1302 0.1043 58.75 <.0001 459.51 47.9468 459.51

Differences of MFG Least Squares Means MFG _MFG Estimate Standard Error z Value Pr > |z| Exponentiated A B 0.01989 0.1559 0.13 0.8985 1.0201 The difference of the manufacturer means can be estimated by the NLMeans macro. Before using the macro, both the NLMeans macro and the NLEstimate macro that it calls must be defined in your current SAS session. Use the %INCLUDE statements described in the Usage section of the Details tab.

With the macros defined, you can now can now call the NLMeans macro. The fitted model, saved by the STORE statement as gammod, is provided by

**instore=**and the data set of coefficients defining the LS-means and saved by the ODS OUTPUT statement is provided by**coef=**. The link function used for this model is the log function. By default,**diff=all**meaning that all pairwise differences will be computed. Since there are two estimates, there is only one difference to estimate. A title for the table of results is supplied by**title=**. Note that quotes should not be used in the title.%NLMeans(instore=gammod, coef=coeffs, link=log, title=Difference of MFG means)

The estimated difference in lifetime means is 468.74 - 459.51 = 9.2309 with 95% large-sample confidence interval (-132.77, 151.23). The Label column displays the contrast applied to the mean estimates showing that the computed difference is MFG

_{A}-MFG_{B}. Note that if the MFG_{B}-MFG_{A}difference is desired, then add**options=reverse**in the macro call.Difference of MFG means

Label Estimate Standard Error Wald Chi-Square Pr > ChiSq Alpha Lower Upper 1 -1 9.2309 72.4517 0.016233 0.8986 0.05 -132.77 151.23 The ratio of means can also be provided by the NLMeans macro.

%NLMeans(instore=gammod, coef=coeffs, link=log, options=ratio, title=Ratio of MFG means)

Notice that the estimated ratio, 1.0201, is identical to the estimate provided by the EXP option in the LSMEANS statement. A large-sample 95% confidence interval for the ratio is (0.7083, 1.3319). The Label column indicates that the computed ratio is MFG

_{A}/MFG_{B}. The inverse of this ratio can be estimated by adding**options=reverse**in the macro call.Ratio of MFG means

Label Estimate Standard Error Wald Chi-Square Pr > ChiSq Alpha Lower Upper 1 /1 1.0201 0.1591 41.1266 <.0001 0.05 0.7083 1.3319 The difference in manufacturer means can also be produced by using the NLEstimate macro directly, though this requires writing the difference of means in terms of the model parameter estimates. This is illustrated in the Example in the Results tab of the NLEstimate macro description.

Right-click on the link below and select **Save** to save the NLMeans macro definition to a file. It is recommended that you name the file NLMeans.sas.

The LSMEANS, SLICE, and ESTIMATE statements in generalized linear modeling procedures such as GLIMMIX, GENMOD, LOGISTIC, and others provide mean estimates using the ILINK option, but estimates and tests of differences of means are not currently available. The NLMeans macro provides these and more.

#### Operating System and Release Information

Type: | Sample |

Topic: | Analytics ==> Regression SAS Reference ==> Macro |

Date Modified: | 2018-06-28 10:20:39 |

Date Created: | 2018-05-23 16:41:36 |

Product Family | Product | Host | SAS Release | |

Starting | Ending | |||

SAS System | SAS/STAT | Microsoft Windows 8 Enterprise 32-bit | ||

z/OS | ||||

z/OS 64-bit | ||||

OpenVMS VAX | ||||

Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||

Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||

Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||

Microsoft Windows XP 64-bit Edition | ||||

Microsoft® Windows® for x64 | ||||

OS/2 | ||||

Microsoft Windows 8 Enterprise x64 | ||||

Microsoft Windows 8 Pro 32-bit | ||||

Microsoft Windows 8 Pro x64 | ||||

Microsoft Windows 8.1 Enterprise 32-bit | ||||

Microsoft Windows 8.1 Enterprise x64 | ||||

Microsoft Windows 8.1 Pro 32-bit | ||||

Microsoft Windows 8.1 Pro x64 | ||||

Microsoft Windows 10 | ||||

Microsoft Windows 95/98 | ||||

Microsoft Windows 2000 Advanced Server | ||||

Microsoft Windows 2000 Datacenter Server | ||||

Microsoft Windows 2000 Server | ||||

Microsoft Windows 2000 Professional | ||||

Microsoft Windows NT Workstation | ||||

Microsoft Windows Server 2003 Datacenter Edition | ||||

Microsoft Windows Server 2003 Enterprise Edition | ||||

Microsoft Windows Server 2003 Standard Edition | ||||

Microsoft Windows Server 2003 for x64 | ||||

Microsoft Windows Server 2008 | ||||

Microsoft Windows Server 2008 R2 | ||||

Microsoft Windows Server 2008 for x64 | ||||

Microsoft Windows Server 2012 Datacenter | ||||

Microsoft Windows Server 2012 R2 Datacenter | ||||

Microsoft Windows Server 2012 R2 Std | ||||

Microsoft Windows Server 2012 Std | ||||

Microsoft Windows Server 2016 | ||||

Microsoft Windows XP Professional | ||||

Windows 7 Enterprise 32 bit | ||||

Windows 7 Enterprise x64 | ||||

Windows 7 Home Premium 32 bit | ||||

Windows 7 Home Premium x64 | ||||

Windows 7 Professional 32 bit | ||||

Windows 7 Professional x64 | ||||

Windows 7 Ultimate 32 bit | ||||

Windows 7 Ultimate x64 | ||||

Windows Millennium Edition (Me) | ||||

Windows Vista | ||||

Windows Vista for x64 | ||||

64-bit Enabled AIX | ||||

64-bit Enabled HP-UX | ||||

64-bit Enabled Solaris | ||||

ABI+ for Intel Architecture | ||||

AIX | ||||

HP-UX | ||||

HP-UX IPF | ||||

IRIX | ||||

Linux | ||||

Linux for x64 | ||||

Linux on Itanium | ||||

OpenVMS Alpha | ||||

OpenVMS on HP Integrity | ||||

Solaris | ||||

Solaris for x64 | ||||

Tru64 UNIX |