**[ME] meglm postestimation** -- Postestimation tools for meglm

__Postestimation commands__

The following postestimation command is of special interest after **meglm**:

Command Description
-------------------------------------------------------------------------
**estat group** summarize the composition of the nested groups
**estat icc** estimate intraclass correlations
**estat sd** display variance components as standard deviations
and correlations
-------------------------------------------------------------------------

The following standard postestimation commands are also available:

Command Description
-------------------------------------------------------------------------
**contrast** contrasts and ANOVA-style joint tests of estimates
**estat ic** Akaike's and Schwarz's Bayesian information criteria
(AIC and BIC)
**estat summarize** summary statistics for the estimation sample
**estat vce** variance-covariance matrix of the estimators (VCE)
**estat** (svy) postestimation statistics for survey data
**estimates** cataloging estimation results
* **hausman** Hausman's specification test
**lincom** point estimates, standard errors, testing, and
inference for linear combinations of coefficients
* **lrtest** likelihood-ratio test
**margins** marginal means, predictive margins, marginal effects,
and average marginal effects
**marginsplot** graph the results from margins (profile plots,
interaction plots, etc.)
**nlcom** point estimates, standard errors, testing, and
inference for nonlinear combinations of
coefficients
**predict** predictions, residuals, influence statistics, and
other diagnostic measures
**predictnl** point estimates, standard errors, testing, and
inference for generalized predictions
**pwcompare** pairwise comparisons of estimates
**test** Wald tests of simple and composite linear hypotheses
**testnl** Wald tests of nonlinear hypotheses
-------------------------------------------------------------------------
* **hausman** and **lrtest** are not appropriate with **svy** estimation results.

__Syntax for predict__

Syntax for obtaining predictions of the outcome and other statistics

**predict** [*type*] *newvarsspec* [*if*] [*in*] [**,** *statistic* *options*]

Syntax for obtaining estimated random effects and their standard errors

**predict** [*type*] *newvarsspec* [*if*] [*in*]**,** **reffects** [*re_options*]

Syntax for obtaining ML scores

**predict** [*type*] *newvarsspec* [*if*] [*in*]**,** __sc__**ores**

*newvarsspec* is *stub****** or *newvarlist*.

*statistic* Description
-------------------------------------------------------------------------
Main
**mu** mean response; the default
**pr** synonym for **mu** for ordinal and binary response
models
**eta** fitted linear predictor
**xb** linear predictor for the fixed portion of the
model only
**stdp** standard error of the fixed-portion linear
prediction
__den__**sity** predicted density function
__dist__**ribution** predicted distribution function
__res__**iduals** raw residuals; available only with the
Gaussian family
__pea__**rson** Pearson residuals
__dev__**iance** deviance residuals
__ans__**combe** Anscombe residuals
-------------------------------------------------------------------------
These statistics are available both in and out of sample; type **predict**
*...* **if e(sample)** *...* if wanted only for the estimation sample.

*options* Description
-------------------------------------------------------------------------
Main
__cond__**itional(***ctype***)** compute *statistic* conditional on estimated
random effects; default is
**conditional(ebmeans)**
**marginal** compute *statistic* marginally with respect to
the random effects
__nooff__**set** make calculation ignoring offset or exposure
__out__**come(***outcome***)** outcome category for predicted probabilities
for ordinal models

Integration
*int_options* integration options
-------------------------------------------------------------------------
**pearson**, **deviance**, **anscombe** may not be combined with **marginal**.
For ordinal outcomes, you can specify one or *k* new variables in
*newvarlist* with **mu** and **pr**, where *k* is the number of outcomes. If you
do not specify **outcome()**, these options assume **outcome(#1)**.

*ctype* Description
-------------------------------------------------------------------------
__ebmean__**s** empirical Bayes means of random effects; the
default
__ebmode__**s** empirical Bayes modes of random effects
__fixed__**only** prediction for the fixed portion of the model
only
-------------------------------------------------------------------------

*re_options* Description
-------------------------------------------------------------------------
Main
__ebmean__**s** use empirical Bayes means of random effects;
the default
__ebmode__**s** use empirical Bayes modes of random effects
**reses(***stub******|*newvarlist***)** calculate standard errors of empirical Bayes
estimates

Integration
*int_options* integration options
-------------------------------------------------------------------------

*int_options* Description
-------------------------------------------------------------------------
__intp__**oints(***#***)** use *#* quadrature points to compute marginal
predictions and empirical Bayes means
__iter__**ate(***#***)** set maximum number of iterations in computing
statistics involving empirical Bayes
estimators
__tol__**erance(***#***)** set convergence tolerance for computing
statistics involving empirical Bayes
estimators
-------------------------------------------------------------------------

__Menu for predict__

**Statistics > Postestimation**

__Description for predict__

**predict** creates a new variable containing predictions such as mean
responses; linear predictions; density and distribution functions;
standard errors; and raw, Pearson, deviance, and Anscombe residuals.

__Options for predict__

+------+
----+ Main +-------------------------------------------------------------

**mu**, the default, calculates the expected value of the outcome.

**pr** calculates predicted probabilities and is a synonym for **mu**. This
option is available only for ordinal and binary response models.

**eta** calculates the fitted linear prediction.

**xb** calculates the linear prediction xb using the estimated fixed effects
(coefficients) in the model. This is equivalent to fixing all random
effects in the model to their theoretical (prior) mean value of 0.

**stdp** calculates the standard error of the fixed-effects linear predictor
xb.

**density** calculates the density function. This prediction is computed
using the current values of the observed variables, including the
dependent variable.

**distribution** calculates the distribution function. This prediction is
computed using the current values of the observed variables,
including the dependent variable.

**residuals** calculates raw residuals, that is, responses minus the fitted
values. This option is available only for the Gaussian family.

**pearson** calculates Pearson residuals. Pearson residuals that are large
in absolute value may indicate a lack of fit.

**deviance** calculates deviance residuals. Deviance residuals are
recommended by McCullagh and Nelder (1989) as having the best
properties for examining the goodness of fit of a GLM. They are
approximately normally distributed if the model is correctly
specified. They can be plotted against the fitted values or against
a covariate to inspect the model fit.

**anscombe** calculates Anscombe residuals, which are designed to closely
follow a normal distribution.

**conditional(***ctype***)** and **marginal** specify how random effects are handled in
computing *statistic*.

**conditional()** specifies that *statistic* will be computed conditional
on specified or estimated random effects.

**conditional(ebmeans)**, the default, specifies that empirical Bayes
means be used as the estimates of the random effects. These
estimates are also known as posterior mean estimates of the
random effects.

**conditional(ebmodes)** specifies that empirical Bayes modes be used
as the estimates of the random effects. These estimates are
also known as posterior mode estimates of the random effects.

**conditional(fixedonly)** specifies that all random effects be set
to zero, equivalent to using only the fixed portion of the
model.

**marginal** specifies that the predicted *statistic* be computed
marginally with respect to the random effects, which means that
*statistic* is calculated by integrating the prediction function
with respect to all the random effects over their entire support.

Although this is not the default, marginal predictions are often
very useful in applied analysis. They produce what are commonly
called population-averaged estimates. They are also required by
**margins**.

**nooffset** is relevant only if you specified **offset(***varname_o***)** or
**exposure(***varname_e***)** with **meglm**. It modifies the calculations made by
**predict** so that they ignore the offset or the exposure variable; the
linear prediction is treated as xb rather than xb + offset or xb +
exposure, whichever is relevant.

**outcome(***outcome***)** specifies the outcome for which the predicted
probabilities are to be calculated. **outcome()** should contain either
one value of the dependent variable or one of **#1**, **#2**, ..., with **#1**
meaning the first category of the dependent variable, **#2** meaning the
second category, etc.

**reffects** calculates estimates of the random effects using empirical Bayes
predictions. By default, or if the **ebmeans** option is specified,
empirical Bayes means are computed. With the **ebmodes** option,
empirical Bayes modes are computed. You must specify *q* new
variables, where *q* is the number of random-effects terms in the
model. However, it is much easier to just specify *stub****** and let
Stata name the variables *stub***1**, *stub***2**,...,*stubq* for you.

**ebmeans** specifies that empirical Bayes means be used as the estimates of
the random effects.

**ebmodes** specifies that empirical Bayes modes be used as the estimates of
the random effects.

**reses(***stub******|*newvarlist***)** calculates standard errors of the empirical Bayes
estimators and stores the result in *newvarlist*. This option requires
the **reffects** option. You must specify *q* new variables, where *q* is
the number of random-effects terms in the model. However, it is much
easier to just specify *stub****** and let Stata name the variables *stub***1**,
*stub***2**,...,*stubq* for you. The new variables will have the same
storage type as the corresponding random-effects variables.

The **reffects** and **reses()** options often generate multiple new
variables at once. When this occurs, the random effects (and
standard errors) contained in the generated variables correspond to
the order in which the variance components are listed in the output
of **meglm**. The generated variables are also labeled to identify their
associated random effect.

**scores** calculates the scores for each coefficient in **e(b)**. This option
requires a new variable list of length equal to the number of columns
in **e(b)**. Otherwise, use the *stub****** syntax to have **predict** generate
enumerated variables with prefix *stub*.

+-------------+
----+ Integration +------------------------------------------------------

**intpoints(***#***)** specifies the number of quadrature points used to compute
marginal predictions and the empirical Bayes means; the default is
the value from estimation.

**iterate(***#***)** specifies the maximum number of iterations when computing
statistics involving empirical Bayes estimators; the default is the
value from estimation.

**tolerance(***#***)** specifies convergence tolerance when computing statistics
involving empirical Bayes estimators; the default is the value from
estimation.

__Syntax for margins__

**margins** [*marginlist*] [**,** *options*]

**margins** [*marginlist*] **,** __pr__**edict(***statistic *...**)** [__pr__**edict(***statistic *...**)**
...] [*options*]

*statistic* Description
-------------------------------------------------------------------------
**mu** mean response; the default
**pr** synonym for **mu** for ordinal and binary response models
**eta** fitted linear predictor
**xb** linear predictor for the fixed portion of the model
only
**stdp** not allowed with **margins**
__den__**sity** not allowed with **margins**
__dist__**ribution** not allowed with **margins**
__res__**iduals** not allowed with **margins**
__pea__**rson** not allowed with **margins**
__dev__**iance** not allowed with **margins**
__ans__**combe** not allowed with **margins**
**reffects** not allowed with **margins**
**scores** not allowed with **margins**
-------------------------------------------------------------------------
Options **conditional(ebmeans)** and **conditional(ebmodes)** are not allowed
with **margins**.
Option **marginal** is assumed where applicable if **conditional(fixedonly)** is
not specified.

Statistics not allowed with **margins** are functions of stochastic
quantities other than **e(b)**.

For the full syntax, see **[R] margins**.

__Menu for margins__

**Statistics > Postestimation**

__Description for margins__

**margins** estimates margins of response for mean responses and linear
predictions.

__Examples__

---------------------------------------------------------------------------
Setup
**. webuse towerlondon**
**. meglm dtlm difficulty i.group || family: || subject:,**
**family(bernoulli)**

Obtain predicted probabilities based on the contribution of both fixed
effects and random effects
**. predict pr**

Obtain predicted probabilities based on the contribution of fixed effects
only
**. predict prfixed, conditional(fixedonly)**

Obtain predictions of the posterior means and their standard errors
**. predict re_means*, reses(se_means*) reffects**

Obtain predictions of the posterior modes and their standard errors
**. predict re_modes*, reses(se_modes*) reffects ebmodes**

---------------------------------------------------------------------------
Setup
**. use http://www.stata-press.com/data/mlmus3/schiz, clear**
**. generate impso = imps**
**. recode impso -9=. 1/2.4=1 2.5/4.4=2 4.5/5.4=3 5.5/7=4**
**. meglm impso week treatment || id:, family(ordinal)**

Obtain predicted probabilities for each outcome based on the contribution
of both fixed effects and random effects
**. predict pr***

---------------------------------------------------------------------------
Setup
**. use http://www.stata-press.com/data/mlmus3/drvisits, clear**
**. meglm numvisit reform age married loginc || id: reform,**
**family(poisson)**

Obtain the predicted counts based on the contribution of both fixed
effects and random effects
**. predict n**

---------------------------------------------------------------------------

__Reference__

McCullagh, P., and J. A. Nelder. 1989. *Generalized Linear Models*. 2nd
ed. London: Chapman & Hall/CRC.