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

__Postestimation commands__

The following postestimation commands are of special interest after
**logistic**:

Command Description
-------------------------------------------------------------------------
**estat classification** report various summary statistics, including the
classification table
**estat gof** Pearson or Hosmer-Lemeshow goodness-of-fit test
**lroc** compute area under ROC curve and graph the curve
**lsens** graph sensitivity and specificity versus
probability cutoff
-------------------------------------------------------------------------
These commands are not appropriate after the **svy** prefix.

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
* **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
-------------------------------------------------------------------------
* **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* __nooff__**set** __rule__**s** **asif**]

*statistic* Description
-------------------------------------------------------------------------
Main
__p__**r** probability of a positive outcome; the default
**xb** linear prediction
**stdp** standard error of the prediction
* __db__**eta** Pregibon (1981) Delta-Beta influence statistic
* __de__**viance** deviance residual
* __dx__**2** Hosmer, Lemeshow, and Sturdivant (2013) Delta
chi-squared influence statistic
* __dd__**eviance** Hosmer, Lemeshow, and Sturdivant (2013) Delta-D
influence statistic
* __h__**at** Pregibon (1981) leverage
* __n__**umber** sequential number of the covariate pattern
* __r__**esiduals** Pearson residuals; adjusted for number sharing
covariate pattern
* __rs__**tandard** standardized Pearson residuals; adjusted for number
sharing covariate pattern
__sc__**ore** first derivative of the log likelihood with respect
to xb
-------------------------------------------------------------------------
Unstarred statistics are available both in and out of sample; type
**predict** *...* **if e(sample)** *...* if wanted only for the estimation sample.
Starred statistics are calculated only for the estimation sample, even
when **if e(sample)** is not specified.
**pr**, **xb**, **stdp**, and **score** are the only options allowed with **svy** estimation
results.

__Menu for predict__

**Statistics > Postestimation**

__Description for predict__

**predict** creates a new variable containing predictions such as
probabilities, linear predictions, standard errors, influence statistics,
deviance residuals, leverages, sequential numbers, Pearson residuals, and
equation-level scores.

__Options for predict__

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

**pr**, the default, calculates the probability of a positive outcome.

**xb** calculates the linear prediction.

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

**dbeta** calculates the Pregibon (1981) Delta-Beta influence statistic, a
standardized measure of the difference in the coefficient vector that
is due to deletion of the observation along with all others that
share the same covariate pattern. In Hosmer, Lemeshow, and
Sturdivant (2013, 154-155) jargon, this statistic is M-asymptotic;
that is, it is adjusted for the number of observations that share the
same covariate pattern.

**deviance** calculates the deviance residual.

**dx2** calculates the Hosmer, Lemeshow, and Sturdivant (2013, 191) Delta
chi-squared influence statistic, reflecting the decrease in the
Pearson chi-squared that is due to deletion of the observation and
all others that share the same covariate pattern.

**ddeviance** calculates the Hosmer, Lemeshow, and Sturdivant (2013, 191)
Delta-D influence statistic, which is the change in the deviance
residual that is due to deletion of the observation and all others
that share the same covariate pattern.

**hat** calculates the Pregibon (1981) leverage or the diagonal elements of
the hat matrix adjusted for the number of observations that share the
same covariate pattern.

**number** numbers the covariate patterns -- observations with the same
covariate pattern have the same **number**. Observations not used in
estimation have **number** set to missing. The first covariate pattern
is numbered 1, the second 2, and so on.

**residuals** calculates the Pearson residual as given by Hosmer, Lemeshow,
and Sturdivant (2013, 155) and adjusted for the number of
observations that share the same covariate pattern.

**rstandard** calculates the standardized Pearson residual as given by
Hosmer, Lemeshow, and Sturdivant (2013, 191) and adjusted for the
number of observations that share the same covariate pattern.

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

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

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

**rules** requests that Stata use any rules that were used to identify the
model when making the prediction. By default, Stata calculates
missing for excluded observations. See example 1 in **[R] logit**
**postestimation**.

**asif** requests that Stata ignore the rules and the exclusion criteria and
calculate predictions for all observations possible by using the
estimated parameter from the model. See example 1 in **[R] logit**
**postestimation**.

__Syntax for margins__

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

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

*statistic* Description
-------------------------------------------------------------------------
__p__**r** probability of a positive outcome; the default
**xb** linear prediction
**stdp** not allowed with **margins**
__db__**eta** not allowed with **margins**
__de__**viance** not allowed with **margins**
__dx__**2** not allowed with **margins**
__dd__**eviance** not allowed with **margins**
__h__**at** not allowed with **margins**
__n__**umber** not allowed with **margins**
__r__**esiduals** not allowed with **margins**
__rs__**tandard** not allowed with **margins**
__sc__**ore** 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 probabilities and linear
predictions.

__Examples__

---------------------------------------------------------------------------
Setup
**. webuse lbw**

Fit logistic regression to predict low birth weight
**. logistic low age lwt i.race smoke ptl ht ui**

Graph ROC curve and calculate area under the curve
**. lroc**

Graph sensitivity and specificity against probability cutoff
**. lsens**

Report classification table and summary statistics
**. estat class**

Perform goodness-of-fit test
**. estat gof**

Calculate fitted probabilities for estimation sample only
**. predict phat if e(sample)**

Calculate Pearson residuals
**. predict r, resid**

---------------------------------------------------------------------------
Setup
**. webuse nhanes2, clear**

Fit logistic regression with three-way interaction
**. logistic highbp sex##agegrp##c.bmi**

Estimate for each **sex** the probability of high blood pressure at equally
spaced values of **bmi**
**. margins sex, at(bmi=(10(5)65))**

Plot estimates against **bmi**
**. marginsplot**

Estimate for each **sex** changes in the probability of high blood pressure
associated with five-unit increases in BMI
**. margins sex, at(bmi=(10(5)65)) contrast(atcontrast(ar._at)**
**marginswithin)**

Plot results
**. marginsplot**

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

__References__

Hosmer, D. W., Jr., S. A. Lemeshow, and R. X. Sturdivant. 2013. *Applied*
*Logistic Regression*. 3rd ed. Hoboken, NJ: Wiley.

Pregibon, D. 1981. Logistic regression diagnostics. *Annals of Statistics*
9: 705-724.