**[R] glm postestimation** -- Postestimation tools for glm

__Postestimation commands__

The following postestimation commands are available after **glm**:

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
+ **forecast** dynamic forecasts and simulations
+ **hausman** Hausman's specification test
**lincom** point estimates, standard errors, testing, and
inference for linear combinations of coefficients
**linktest** link test for model specification
*+ **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
**suest** seemingly unrelated estimation
**test** Wald tests of simple and composite linear hypotheses
**testnl** Wald tests of nonlinear hypotheses
-------------------------------------------------------------------------
* **estat ic** and **lrtest** are not appropriate after **glm, irls**.
+ **forecast**, **hausman**, and **lrtest** are not appropriate with **svy** estimation
results. **forecast** is also not appropriate with **mi** estimation results.

__Syntax for predict__

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

*statistic* Description
-------------------------------------------------------------------------
Main
__m__**u** expected value of y; the default
**xb** linear prediction
__e__**ta** synonym of **xb**
**stdp** standard error of the linear prediction
__a__**nscombe** Anscombe (1953) residuals
__c__**ooksd** Cook's distance
__d__**eviance** deviance residuals
__h__**at** diagonals of the "hat" matrix
__l__**ikelihood** a weighted average of standardized deviance and
standardized Pearson residuals
__p__**earson** Pearson residuals
__r__**esponse** differences between the observed and fitted outcomes
__s__**core** first derivative of the log likelihood with respect to
xb
__w__**orking** working residuals
-------------------------------------------------------------------------

*options* Description
-------------------------------------------------------------------------
Options
__nooff__**set** modify calculations to ignore offset variable
__adj__**usted** adjust deviance residual to speed up convergence
__sta__**ndardized** multiply residual by the factor (1-h)^[-1/2]
__stu__**dentized** multiply residual by one over the square root of the
estimated scale parameter
__mod__**ified** modify denominator of residual to be a reasonable
estimate of the variance of *depvar*
-------------------------------------------------------------------------
These statistics are available both in and out of sample; type **predict**
*...* **if e(sample)** *...* if wanted only for the estimation sample.
**mu**, **xb**, **stdp**, and **score** are the only statistics allowed with **svy**
estimation results.

__Menu for predict__

**Statistics > Postestimation**

__Description for predict__

**predict** creates a new variable containing predictions such as expected
values, linear predictions, standard errors, residuals, Cook's distance,
diagonals of the "hat" matrix, weighted averages, differences between the
observed and fitted outcomes, and equation-level scores.

__Options for predict__

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

**mu**, the default, specifies that **predict** calculate the expected value of
y, equal to the number of trials times the inverse link of the linear
prediction.

**xb** calculates the linear prediction.

**eta** is a synonym for **xb**.

**stdp** calculates the standard error of the linear predictor.

**anscombe** calculates the Anscombe (1953) residuals to produce residuals
that closely follow a normal distribution.

**cooksd** calculates Cook's distance, which measures the aggregate change in
the estimated coefficients when each observation is left out of the
estimation.

**deviance** calculates the deviance residuals. Deviance residuals are
recommended by McCullagh and Nelder (1989) and by others as having
the best properties for examining the goodness of fit of a GLM. They
are approximately normally distributed if the model is correct. They
may be plotted against the fitted values or against a covariate to
inspect the model's fit. Also see the **pearson** option below.

**hat** calculates the diagonals of the "hat" matrix, analogous to linear
regression.

**likelihood** calculates a weighted average of standardized deviance and
standardized Pearson residuals.

**pearson** calculates the Pearson residuals. Pearson residuals often have
markedly skewed distributions for nonnormal family distributions.
Also see the **deviance** option above.

**response** calculates the differences between the observed and fitted
outcomes.

**score** calculates the equation-level score, the derivative of the log
likelihood with respect to the linear prediction.

**working** calculates the working residuals, which are response residuals
weighted according to the derivative of the link function.

+---------+
----+ Options +----------------------------------------------------------

**nooffset** is relevant only if you specified **offset(***varname***)** for **glm**. It
modifies the calculations made by **predict** so that they ignore the
offset variable; the linear prediction is treated as xb rather than
xb + offset.

**adjusted** adjusts the deviance residual to speed up the convergence to the
limiting normal distribution. The adjustment deals with adding to
the deviance residual a higher-order term that depends on the
variance function family. This option is allowed only when **deviance**
is specified.

**standardized** requests that the residual be multiplied by the factor
(1-h)^[-1/2], where h is the diagonal of the hat matrix. This
operation is done to account for the correlation between *depvar* and
its predicted value.

**studentized** requests that the residual be multiplied by one over the
square root of the estimated scale parameter.

**modified** requests that the denominator of the residual be modified to be
a reasonable estimate of the variance of *depvar*. The base residual
is multiplied by the factor (k/w)^[-1/2], where k is either one or
the user-specified dispersion parameter and w is the specified weight
(or one if left unspecified).

__Syntax for margins__

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

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

*statistic* Description
-------------------------------------------------------------------------
__m__**u** expected value of y; the default
**xb** linear prediction
__e__**ta** synonym for **xb**
**stdp** not allowed with **margins**
__a__**nscombe** not allowed with **margins**
__c__**ooksd** not allowed with **margins**
__d__**eviance** not allowed with **margins**
__h__**at** not allowed with **margins**
__l__**ikelihood** not allowed with **margins**
__p__**earson** not allowed with **margins**
__r__**esponse** not allowed with **margins**
__s__**core** not allowed with **margins**
__w__**orking** not allowed with **margins**
-------------------------------------------------------------------------

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 expected values and linear
predictions.

__Examples__

Setup
**. webuse ldose**

Fit model to grouped binomial data
**. glm r ldose, family(binomial n) link(logit)**

Calculate expected number of failures
**. predict mu_logit**

Calculate deviance residuals
**. predict dr_logit, deviance**

Perform link test
**. linktest, family(binomial n) link(logit)**

__References__

Anscombe, F. J. 1953. Contribution of discussion paper by H. Hotelling
"New light on the correlation coefficient and its transforms".
*Journal of the Royal Statistical Society, Series B* 15: 229-230.

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