bayesbayesianpostestimation.pdf#bayesBayesianpostestimation
bayesbayesianpostestimation.pdf#bayesBayesianpostestimation
com
Bayesian postestimation — Postestimation tools after Bayesian estimation
Postestimation commands
The following Bayesian postestimation commands are available after the bayesmh com-
mand ([BAYES] bayesmh), the bayes prefix ([BAYES] bayes), and the bayesselect command
([BAYES] bayesselect):
Command Description
bayesgraph graphical summaries and convergence diagnostics
bayesstats grubin Gelman–Rubin convergence diagnostics
bayesstats ess effective sample sizes and related statistics
† bayesstats ppvalues Bayesian predictive p-values
bayesstats summary Bayesian summary statistics for model parameters and their functions
bayesstats ic Bayesian information criteria and Bayes factors
bayestest model hypothesis testing using model posterior probabilities
bayestest interval interval hypothesis testing
† bayespredict Bayesian predictions
∗
estimates cataloging estimation results
† bayesstats ppvalues and bayespredict are available only after bayesmh, bayesselect, bayes: var, and
panel-data bayes: xtcmd estimation commands.
∗
estimates table, estimates stats, and estimates selected are not appropriate with Bayesian estimation
results.
The following postestimation command is available after bayes: dsge and bayes: dsgenl:
Command Description
bayesirf Bayesian impulse–response functions
See [BAYES] bayes: dsge postestimation.
1
2 Bayesian postestimation — Postestimation tools after Bayesian estimation
After estimation, you can use bayesgraph to check convergence of MCMC visually. If you
simulated multiple chains, you can use bayesstats grubin to compute Gelman–Rubin convergence
diagnostics. Once convergence is established, you can use bayespredict and bayesstats ppvalues
to perform model checking; the table in the previous section indicates which estimation commands
support these postestimation features. Once you are satisfied with the model, you can use bayesstats
summary to obtain Bayesian summaries such as posterior means and standard deviations of model
parameters and functions of model parameters; bayesstats ess to compute effective sample sizes
and related statistics for model parameters and functions of model parameters; and bayesstats ic
to compute Bayesian information criteria and Bayes factors for model parameters and their functions.
You can use bayestest model to test hypotheses by comparing posterior probabilities of models.
You can also use bayestest interval to test interval hypotheses about parameters and functions of
parameters. Additionally, after select commands, you can also use bayespredict to predict future
outcome values.
For an overview example of postestimation commands, see Overview example in [BAYES] Bayesian
commands.
Many Bayesian postestimation commands such as bayesstats summary and bayesgraph allow
you to specify model parameters for which you want to see the results. To see results for all parameters,
simply type a postestimation command without arguments after estimation, for example,
. bayesstats summary
In the presence of more than one model parameter, you have several ways for referring to multiple
parameters at once. If parameters have the same equation name, you can refer to all the parameters
with that equation name as follows.
Suppose that you have three parameters with the same equation name eqname. Then the specification
. bayesstats summary {eqname:param1} {eqname:param2} {eqname:param3}
or the specification
. bayesstats summary {eqname:param1 param2 param3}
The above specification is useful if we want to refer to a subset of parameters with the same equation
name. For example, in the above, if we wanted to use only param1 and param2, we could type
. bayesstats summary {eqname:param1 param2}
There is also a convenient way to refer to the parameters with the same name but different equation
names. For example, typing
. bayesstats summary {eqname1:param} {eqname2:param}
You can mix and match all the specifications above in one call to a postestimation command. You
can also specify expressions of model parameters; see Specifying functions of model parameters for
details.
Note that if param refers to a matrix model parameter, then the results will be provided for all
elements of the matrix. For example, if param is the name of a 2 × 2 matrix, then typing
. bayesstats summary {param}
For multilevel models, there are various ways, reref, in which you can refer to individual random-
effects parameters. Suppose that your model has random intercepts at the id level, which are labeled
as {U0[id]} or {U0} for short. To refer to all random intercepts, you can use {U0}, {U0[.]}, and
{U0[id]}. To refer to specific random intercepts, you can use {U0[#]}, where # refers to the #th
element of the random-effects vector, or use {U0[#.id]}, where # refers to the #th level of the
id variable. You can also refer to a subset numlist of random intercepts by using {U0[numlist]} or
{U0[(numlist).id]}. For nested random effects, for example, {UU0[id1>id2]}, you can refer to all
random effects as {UU0} or {UU0[.,.]} and to subsets of random effects as {UU0[numlist,numlist]}
or {UU0[(numlist).id1,(numlist).id2]}.
If param is a matrix, we can specify expressions, including its elements, but not the matrix itself
in the following:
. bayesstats summary (exp({param_1_1})) (exp({param_1_2})) ...
or
. bayesselect, saving()
or
. bayes, saving()
As you can with other estimation commands, you can use estimates store to store Bayesian
estimation results in memory and estimates save to save them to disk, but you must first use the
saving() option with an estimation command to save simulation data in a permanent dataset. For
example, type
. bayesmh . . . , likelihood() prior() . . . saving(bmh_simdata)
. estimates store model1
Bayesian postestimation — Postestimation tools after Bayesian estimation 5
Once you create a permanent dataset, it is your responsibility to erase it after it is no longer
needed. estimates drop and estimates clear will drop estimation results only from memory;
they will not erase the simulation files you saved.
. estimates drop model1
. erase bmh_simdata.dta
See [R] estimates for more information about commands managing estimation results. estimates
table, estimates stats, and estimates selected are not appropriate after Bayesian estimation
commands.
To access prediction results, all postestimation commands must specify the prediction dataset in
the using specification. In fact, this is all postestimation commands need to produce results for
the prediction quantities. (Technically, the auxiliary estimation file generated by bayespredict, for
example, predfile.ster, must also exist.) That is, they do not rely on the estimation results or the
simulation data from Bayesian estimation commands.
When the prediction dataset contains simulated outcomes, in addition to accessing these outcomes
(for instance, { ysim1} and { ysim2} in our example), postestimation commands may also access
the residuals ({ resid1} and { resid2}), expected values ({ mu1} and { mu2}), and Stata
expressions of simulated outcomes, residuals, and expected values. You can also call Mata functions
within command specifications to compute functions of simulated outcomes, residuals, and expected
values.
Let’s calculate posterior summaries for all observations of the first outcome and for all residuals
of the second outcome.
. bayesstats summary {_ysim1} {_resid2} using predfile
6 Bayesian postestimation — Postestimation tools after Bayesian estimation
You can refer to a subset of predicted observations, say, from 1 to 10 for the observations and
from 1 to 5 for the residuals.
. bayesstats summary {_ysim1[1/10]} {_resid2[1/5]} using predfile
You can compute expressions of individual simulated outcome observations and their residuals.
. bayesstats summary (exp({_ysim1[1]})) ({_resid2[1]}^2) using predfile
You can test whether the residual for the first observation of the second outcome variable is greater
than zero by using bayestest interval to calculate the corresponding posterior probability.
. bayestest interval {_resid2[1]} using predfile, lower(0)
As we mentioned earlier, you can use Mata functions of predicted outcomes and residuals. These
functions operate across observations. For example, to summarize the mean of the first simulated
outcome and the variance of the second simulated outcome, type
. bayesstats summary (@mean({_ysim1})) (@variance({_ysim2})) using predfile
Instead of using the default labels for the computed quantities, you can specify your own. Below,
we use mean and var to label the corresponding predictions.
. bayesstats summary (mean:@mean({_ysim1})) (var:@variance({_ysim2})) using predfile
You cannot specify Mata functions with bayestest interval, and, unlike bayespredict, you
cannot specify Stata programs within the postestimation commands.
If you need to access individual values of the predicted quantity computed using a Mata function or
specify an expression of this quantity, you need to compute and save this quantity with bayespredict.
Suppose that you wish to compute the sum of the two outcome variances. You simulate these
variances by using bayespredict first.
. bayespredict (prvar1:@variance({_ysim1})) (prvar2:@variance({_ysim2})), ///
saving(predfile)
You can combine various specifications in one call to the postestimation command. For example,
let’s save the following prediction quantities with bayespredict.
. bayespredict {_ysim1} {_ysim2} (mean1:@mean({_ysim1})) ///
(var2:@variance({_ysim2})), saving(predfile)
You can specify multiple prediction quantities in one call to bayesstats summary or other
postestimation commands.
. bayesstats summary ({_ysim1}) ({_resid[1/5]}) ({mean1}) ///
({var2}) (mean2:@mean({_ysim2})) using predfile
Bayesian postestimation — Postestimation tools after Bayesian estimation 7
Also see
[BAYES] bayes — Bayesian regression models using the bayes prefix+
[BAYES] bayesmh — Bayesian models using Metropolis–Hastings algorithm+
[BAYES] bayesmh evaluators — User-defined evaluators with bayesmh
[BAYES] bayesselect — Bayesian variable selection for linear regression+
[BAYES] Bayesian commands — Introduction to commands for Bayesian analysis
[BAYES] Intro — Introduction to Bayesian analysis
[BAYES] Glossary
[U] 20 Estimation and postestimation commands
Stata, Stata Press, and Mata are registered trademarks of StataCorp LLC. Stata and
®
Stata Press are registered trademarks with the World Intellectual Property Organization
of the United Nations. StataNow and NetCourseNow are trademarks of StataCorp
LLC. Other brand and product names are registered trademarks or trademarks of their
respective companies. Copyright c 1985–2023 StataCorp LLC, College Station, TX,
USA. All rights reserved.
For suggested citations, see the FAQ on citing Stata documentation.