Select Your Region
Americas
Europe
Middle East & Africa
Asia Pacific
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Contents: | Purpose / History / Requirements / Usage / Details / Limitations / See Also |
NOTE: Beginning in SAS® 9.4M6 (TS1M6), a version of this macro is available in the SAS/STAT® Autocall library and does not need to be downloaded and defined before use. To access features in more recent versions of the macro (see History), download and run as described in Usage below.
%nlmeans(v)
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 of the NLMEANS macro.
The computations performed by the macro are not affected by the appearance of this message. However, this check can be avoided by specifying nochk as the first macro argument. This can be useful if your machine has no connection to the internet.
Version
|
Update Notes
|
3.0 | Added f=, fset=, flabel=, and fdata=. Fixed behavior of options=joint with multinomial models. Enhanced flexibility with contrasts= and multinomial models. Requires version 2.1 or later of the NLEST macro. |
2.0 | nochk can be specified as the first (version) parameter. Requires version 2.1 or later of the NLEST macro. |
1.4 | Added where= and covdrop=. Requires version 1.9 or later of the NLEST macro. Version 1.4 of NLMEANS and version 1.9 of NLEST are available in the SAS/STAT Autocall Library beginning in SAS 9.4M8 (TS1M8). |
1.3 | Added print | noprint to options=. Added null=. Requires version 1.8 or later of the NLEST macro. |
1.04, 1.1 | Store sets of results in data sets EST1, EST2, ... . Append all sets into a single results file using options=append. Version 1.1 of NLMEANS and version 1.6 of NLEST are available in the SAS/STAT Autocall Library beginning in SAS 9.4M6 (TS1M6). |
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 |
%inc "<location of your file containing the NLEST macro>"; %inc "<location of your file containing the NLMEANS macro>";
After defining both macros in your SAS session, fit your model and include one or more LSMEANS, SLICE, ESTIMATE, or LSMESTIMATE statements with the E option and save the model using the STORE statement. You can then call the NLMEANS macro to estimate and test functions of response 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 generally the better method for providing the model information.
Estimation and testing of functions of response means, such as pairwise differences or ratios, or other linear or nonlinear functions of means can be requested using any of the following. By default, diff=all. When contrasts= is specified, diff= is ignored. contrasts= is not available with multinomial models.
The following parameters are optional:
While the DIFF option in the LSMEANS and SLICE statements provide pairwise differences on the link scale, Liβ-Ljβ, differences on the mean scale, μi-μj, are not available. Similarly, in an ESTIMATE or LSMESTIMATE statement that defines a difference, Liβ-Ljβ, the ILINK option applies the inverse of the link function to the difference, g-1(L1β-L2β) rather than computing the difference of the inverse linked estimates g-1(L1β)-g-1(L2β) = μi-μj. The same situation applies to estimating functions that are more complex than a simple difference. The NLMEANS macro is provided to make estimation of these functions available on the mean scale rather than the link scale. Note that the quantity g-1(L1β-L2β) 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, μi=Liβ, so differences or other functions of the Liβ are equivalent functions of the μi. Consequently, the results of the DIFF option in the LSMEANS or SLICE statement, or the results of an ESTIMATE or LSMESTIMATE statement that defines a function of the Liβ directly provide the same function of the μi.
The NLMEANS macro can be used to provide estimates and tests of differences of means, μi-μj, ratios of means, μi/μj, or linear contrasts of means. Using f= or fdata=, even nonlinear functions of means can be estimated. Standard errors are obtained using the delta method. To use the macro, you supply the saved model and a data set containing the coefficients, Li, used by one or more LSMEANS, SLICE, ESTIMATE, or LSMESTIMATE 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, ESTIMATE or LSMESTIMATE statement(s) specified in the procedure, and by including an ODS OUTPUT statement to save the displayed table of coefficients in a data set. In most procedures, 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 differences, ratios, contrasts, or other functions of means as well as other options.
The macro can process one or more sets of estimates. Multiple sets of estimates occur when the modeling procedure includes an LSMEANS statement with multiple variables, a SLICE statement with the SLICEBY= option, or multiple LSMEANS, SLICE, ESTIMATE, or LSMESTIMATE statements. The macro estimates the requested function(s) in each set and a table of results is displayed for each set of estimates. If you want to estimate function(s) of means defined across multiple sets, you can use options=joint to combine all of the separate sets into a single set.
For ordinal multinomial models (link=cumlogit, cumprobit, cumloglog, cumcloglog), the estimated means in any population are cumulative probabilities, Pr(Y=1), Pr(Y≤2), ... , Pr(Y≤ l), where l is the number of cumulative response functions, which is one less than the number of levels in the response variable, Y. For nominal multinomial models (link=glogit), the estimated means in any population are individual level probabilities, Pr(Y=1), Pr(Y=2), ... , Pr(Y= l ), where l is the number of response levels.
When diff= is specified in a multinomial model to provide pairwise comparisons in an estimate set (such as among levels of a variable in the LSMEANS statement), the macro by default estimates the requested comparisons within each of the l response functions or levels. This is the action with the default options=difinfns. For example, an ordinal cumulative logit model (link=cumlogit) on a three-level response has l = 2 cumulative logit response functions and predicts each of two cumulative probabilities (means). The requested comparisons are estimated separately for each cumulative mean. For a nominal multinomial model on a three-level response, by default the requested differences are estimated separately for each of the l = 3 individual response level probabilities (means). If you specify options=difall with diff=, the differencing method is applied across all k=ml probabilities, where m is the number of estimates in the estimate set. If you want to estimate differences or other functions defined across all the k means in an estimate set, you can use contrasts=, f=, or fdata=. See Example 2 in the Results tab.
When specifying a contrasts= data set, each contrast (row) of the data set can contain coefficients for all k=ml means. However, if you want the same contrasts to be applied separately to the m means within each response function or level, then you can specify just k=m coefficients and the macro will duplicate the provided coefficients in each of the l response functions or levels. Again, see Example 2 in the Results tab.
When the NLMEANS macro processes a single set of estimates (such as from a single LSMEANS statement), results are automatically saved in data set EST. When multiple sets of estimates are processed, the results from each set are saved by default 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. Be aware that if EST_ALL already exists, new results are appended to it. The last results set is also stored in data set EST.
The NLMEANS macro does not directly support BY group processing (such as for the analysis of multiply imputed data) or processing of domains from a survey analysis. That is, it cannot process results from a modeling procedure that was run using a BY or DOMAIN statement. However, this capability can be provided by the RunBY macro, which can run the NLMEANS macro repeatedly for each of the BY groups or domains. Version 1.4 or later of the NLMEANS macro, version 1.9 or later of the NLEST macro, and version 1.1 or later of the RunBY macro are required. See the RunBY macro documentation (SAS Note 66249) for details about its use. Additionally, you can use where= to allow NLMEANS to process the results of one BY group or domain by specifying an appropriate condition to select that BY group or domain. See the Example 4 in the Results tab above.
Since the LSMEANS and SLICE statements require GLM parameterized CLASS variables (PARAM=GLM in the CLASS statement), the NLEST macro (which is called by the NLMEANS macro) will typically display the following Warning message in this log. This Warning can be ignored when it is caused by the use of GLM parameterization.
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.
Specifying inest= and incovb= instead of instore= is generally not necessary. If used, modifications of those data sets or use of where= and/or covdrop= might be needed to correct incompatibility of the parameter vector and covariance matrix. In some cases, it might be necessary to use the NLEST macro directly rather than NLMEANS.
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. Otherwise, an error message is issued that indicates the relevant numbers of rows and columns. If the incovb= data set contains numeric variables other than those containing the covariance matrix, they should be removed in order to avoid a compatibility error. This can be done either by preprocessing the data set to remove the extraneous variables or by specifying them in covdrop= (requires version 1.4 or later of the NLMEANS macro and version 1.9 or later of the NLEST macro).
If a requested function of means results in a computational error, such as division by zero or taking the log of a negative value, the macro will issue Warning messages in the log indicating that 'AdditionalEstimates' was not created and that variables df and Probt were never referenced. No results are presented for the estimate set where this occurs even if other functions in the set are estimable.
Some modeling procedures cannot provide the necessary covariance matrix for some models. Some procedures either do not have a STORE statement (such as PROC FMM) or do not save the necessary model information (such as PROC COUNTREG). In such cases, use inest= and incovb= instead of instore=. When using inest= and incovb=, incompatibility of the parameter vector and covariance matrix can occur. See Compatibility error when using inest= and incovb= above.
For some models, such as those fit by the GENMOD or GLIMMIX procedures, use of the LSMEANS, SLICE, ESTIMATE, or LSMESTIMATE statements in the PLM procedure is recommended rather than using those statements in the modeling procedure. Using those statements in PLM requires saving the fitted model using the STORE statement in the modeling procedure.
Each coefficient column vector in an estimate set (identified by the LMatrix variable) appearing in the coef= data set should estimate an individual, link-transformed mean, g(μi). The NLMEANS macro applies the inverse of the link function specified in link= to obtain the means, μi, to be used in estimating the functions requested using the various macro parameters described above.
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.