0% found this document useful (0 votes)
7 views6 pages

Bmabmacoefsample

The bmacoefsample command simulates regression coefficients and model parameters from their posterior distributions following the bmaregress command. It allows users to specify options such as MCMC sample size and random-number seed, and can save simulation results to a file. This command is essential for obtaining posterior samples needed for further Bayesian analysis and inference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Bmabmacoefsample

The bmacoefsample command simulates regression coefficients and model parameters from their posterior distributions following the bmaregress command. It allows users to specify options such as MCMC sample size and random-number seed, and can save simulation results to a file. This command is essential for obtaining posterior samples needed for further Bayesian analysis and inference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

bmacoefsample — Posterior samples of regression coefficients

Description Quick start Menu Syntax


Options Remarks and examples Stored results Methods and formulas
Also see

Description
bmacoefsample simulates regression coefficients and other model parameters from their posterior
distributions after bmaregress.

Quick start
Simulate regression coefficients and other model parameters from their posterior distributions after
bmaregress, and use bayesstats summary to display posterior summaries for {y:}, all 12 regres-
sion coefficients, and the intercept, including their 90% highest posterior density (HPD) credible in-
tervals (CrIs)
bmaregress y x1-x12, saving(bmamodelmcmc)
bmacoefsample
bayesstats summary {y:}, clevel(90) hpd
Same as above, but specify a random-number seed and the size of the simulated dataset, and save the
simulated dataset in file bmacoefmcmc.dta
bmacoefsample, rseed(1234) mcmcsize(5000) saving(bmacoefmcmc)
Simulate results without saving first, but then later specify option saving() to save the previously sim-
ulated results in file bmacoefmcmc1.dta, and save a new set of results in bmacoefmcmc2.dta
bmacoefsample, rseed(1234)
bmacoefsample, saving(bmacoefmcmc1)
bmacoefsample, saving(bmacoefmcmc2)
Same as above, but save only one set of results, use option simulate to resimulate the results, and save
the new ones in bmacoefmcmc1, replacing already existing file
bmacoefsample, rseed(1234)
bmacoefsample, saving(bmacoefmcmc1, replace) simulate

Menu
Statistics > Bayesian model averaging > Posterior samples of coefficients

1
2 bmacoefsample — Posterior samples of regression coefficients

Syntax
bmacoefsample [ , coefsimopts ]
coefsimopts Description
Simulation
mcmcsize(#) Markov chain Monte Carlo (MCMC) sample size; default is
mcmcsize(10000) or as specified with bmaregress
rseed(#) random-number seed
Reporting
saving(filename[ , replace ]) save simulation results to filename.dta
[ no ]dots suppress or display dots every 1,000 iterations and iteration
numbers every 5,000 iterations; default is dots
dots(#[ , every(#) ]) display dots as simulation is performed
simulate simulate new results instead of saving existing ones
simulate does not appear in the dialog box.

Options

 Simulation

mcmcsize(#) specifies the target MCMC sample size. The default is mcmcsize(10000) or as specified
in bmaregress’s mcmcsize() option.
rseed(#) sets the random-number seed. This option can be used to reproduce results. Option rseed(#)
is equivalent to typing set seed # prior to calling the bmacoefsample command; see [R] set seed.

 Reporting

saving(filename[ , replace ]) saves simulation results in filename.dta. The replace option speci-
fies to overwrite filename.dta if it exists. If the saving() option is not specified, bmacoefsample
saves simulation results in a temporary file for later access. This temporary file will be overwritten
every time bmacoefsample or bmaregress is run and will be erased if the current estimation re-
sults are cleared. The simulation dataset has the same structure as described in option saving() of
[BAYES] bayesmh. The simulation results include posterior samples of regression coefficients, the
intercept, and the error variance.
If you first run bmacoefsample without option saving(), you can rerun it with this option later
to save the current simulation results in a file without having to redo a potentially time-consuming
simulation. If, for some reason, you need to simulate a new sample in this case, you should specify
option simulate in addition to saving().
dots, nodots, dots(#), and dots(#, every(#)) specify to display or suppress dots during simula-
tion. dots, the default, displays dots every 1,000 iterations and iteration numbers every 5,000 itera-
tions; it is a synonym for dots(1000, every(5000)). dots(#) displays a dot every # iterations. If
dots(. . ., every(#)) is specified, then an iteration number is displayed every #th iteration instead
of a dot. dots(, every(#)) is equivalent to dots(1, every(#)).
bmacoefsample — Posterior samples of regression coefficients 3

The following option is available with bmacoefsample but is not shown in the dialog box:
simulate is used with option saving() to simulate a new set of results and save them in a file instead
of saving the previously simulated results. This option is implied with bmacoefsample in all but one
case—when option saving() is used and simulation results from a previous run of bmacoefsample
have not been saved in a file already.
stata.com

Remarks and examples


Bayesian model averaging (BMA) simulation consists of two steps: 1) simulation of a model space
and, optionally, 2) simulation of model parameters, which include regression coefficients, the intercept,
and the error variance. The first, main step is performed by bmaregress, during which a posterior
sample of models is obtained. In addition, a posterior sample of parameter 𝑔 of a Zellner’s 𝑔-prior, which
affects the simulation of the model space, is obtained. Because bmaregress reports only posterior means
and standard deviations of model parameters, which are available analytically, it does not automatically
simulate posterior samples of model parameters to save time. But these samples may be needed if we
want to obtain CrIs, functions of regression coefficients, or certain predictions.
The bmacoefsample command simulates model parameters of a BMA linear regression fit by
bmaregress from their posterior distributions. The simulated data include posterior samples of regres-
sion coefficients, the intercept, and the error variance. For convenience, the data also include the posterior
sample of the 𝑔 parameter simulated by bmaregress. To use bmacoefsample after bmaregress, you
must first save the BMA model simulation results by using the saving() option with bmaregress either
during estimation or on replay.
bmacoefsample differs from a standard Stata postestimation command—it is a hybrid between an es-
timation and a postestimation command. Unlike other Stata postestimation commands, bmacoefsample
actually modifies or, rather, augments the estimation results stored by bmaregress. But it is still a postes-
timation command because it can run only after bmaregress is run. You can think of it as a “replay
option” of the bmaregress command, which continues the simulation process started by bmaregress.
But it is more convenient as a stand-alone command.
In addition to storing results in e(), bmacoefsample has its own concept of “replay”. Because it
performs a potentially time-consuming simulation, it allows you to save your simulation results later, if
you did not do so the first time you ran the command. That is,

. bmaregress ..., saving(bmamodelmcmc)


. bmacoefsample
produces a simulation sample of model parameters but saves them temporarily. If you run
bmacoefsample or bmaregress again, these results will be lost. You can use bmacoefsample’s
saving() option to save the current model parameter simulation results permanently in a file:

. bmacoefsample, saving(mycoef)
Once the current results are permanently saved, the next run of bmacoefsample will automatically
produce a new sample. In fact, if you use any option with bmacoefsample other than saving(), it will
automatically trigger the generation of a new sample. You can also force the bmacoefsample command
to resample and save a new set of simulation results by specifying the simulate option together with
saving():

. bmacoefsample
4 bmacoefsample — Posterior samples of regression coefficients

. bmacoefsample, saving(mycoef) simulate


For a fixed 𝑔, the samples generated by bmaregress and bmacoefsample are independent. For a
random 𝑔, these MCMC samples are dependent.
Inference based on MCMC simulations depends on the variation of the MCMC sample. Specifically, the
size of the MCMC sample, that is the number of draws from parameters’ posterior distributions, affects the
precision of the parameter estimates. The larger the MCMC sample size, the more precise the estimates.
The MCMC sample size is specified in the mcmcsize() option. The default is 10,000 or the value specified
in bmaregress’s mcmcsize() option.
bmacoefsample is a stochastic command, so you need to specify the rseed() option to reproduce
results.
After bmacoefsample, you can use the following standard Bayesian postestimation commands to
explore posterior summaries of model parameters: [BAYES] bayesstats summary, [BAYES] bayesstats
ess, [BAYES] bayesstats ppvalues, [BAYES] bayesgraph, and [BAYES] bayespredict. You can also use
the estimates command, except estimates table, estimates stats, and estimates selected;
see [BMA] BMA postestimation.
For examples of how to use this command, see, for instance, example 5, example 16, and example 19
of [BMA] bmaregress.

Stored results
In addition to the estimation results stored by bmaregress, bmacoefsample stores the following in
e():
Scalars
e(mcmcsize2) MCMC sample size
Macros
e(cmd2) bmacoefsample
e(filename) name of the file with simulation results
e(parnames) names of model parameters
e(postvars) variable names corresponding to model parameters in e(parnames)
e(scparams) scalar model parameters
e(pareqmap) model parameters in display order
e(rngstate2) random-number state at the time of simulation

Methods and formulas


Methods and formulas are presented under the following headings:
Enumerated model space
Simulated model space
Conditional on a model 𝑀 and parameter 𝑔, the posterior distribution of the error variance 𝜎2 is an
inverse-gamma distribution, and the posterior distribution of regression coefficients and the intercept is
a multivariate location-scale 𝑡-distribution; see Conditional posterior distribution of model parameters in
Methods and formulas of [BMA] bmaregress.
bmacoefsample simulates model parameters from their posterior distributions in two ways, which
depend on whether bmaregress enumerated or sampled the model space.
bmacoefsample — Posterior samples of regression coefficients 5

Enumerated model space


When all models in the model space are visited by bmaregress, the posterior model distribution is
known, and PMPs can be computed exactly. Also, Zellner’s 𝑔 parameter is fixed with model enumeration.
In this case, bmacoefsample generates an independent sample of size 𝑇 for model parameters as follows.
For 𝑡 = 1, 2, . . . , 𝑇:
1. Draw a model 𝑀𝑡 from the model space according to the PMP distribution, which is described in
Posterior model probability in Methods and formulas of [BMA] bmaregress.
2. Draw model parameters according to
2
𝑛 − 1 𝑠𝑡,𝛿
𝜎𝑡2 |𝑔, 𝑀𝑡 ∼ InverseGamma ( , )
2 2
θ𝑡,𝑝𝑡 |𝜎𝑡2 , 𝑔, 𝑀𝑡 ∼ 𝑁𝑝𝑡 +1 (µ𝑡 , 𝜎𝑡2 𝚺𝑡 )

where 𝑛 is the sample size and 𝑠2𝑡,𝛿 , µ𝑡 , and 𝚺𝑡 are computed according to (1), (3), and (4) in Conditional
posterior distribution of model parameters in Methods and formulas of [BMA] bmaregress (with index
𝑗 substituted for 𝑡, that is, conditional on model 𝑀𝑡 instead of 𝑀𝑗 ). θ𝑡,𝑝𝑡 = (β′𝑡,𝑝 , 𝛼)′ is a (𝑝𝑡 + 1) × 1
𝑡
vector of the 𝑝𝑡 regression coefficients included in model 𝑀𝑡 and the intercept. Regression coefficients
that are not included in 𝑀𝑡 are assigned 0s. Then a (𝑝 + 1) × 1 vector θ𝑡 includes all 𝑝 regression
coefficients and the intercept from iteration 𝑡.
The result is a sample {θ𝑡 , 𝜎𝑡2 }𝑇𝑡=1 from the BMA posterior distribution of model parameters.

Simulated model space


For a random 𝑔, the exact posterior model distribution is not available, and bmaregress provides an
MCMC sample (𝑚𝑡 , 𝑔𝑡 ), for 𝑡= 1, 2, . . . , 𝑇, from the BMA posterior distribution of models and parameter
𝑔. bmacoefsample command reuses this sample to simulate model parameters.
For each 𝑡, regression coefficients that are not included in 𝑚𝑡 are assigned 0s. The remaining 𝑝𝑡
regression coefficients and the intercept, θ𝑡,𝑝𝑡 , and variance 𝜎𝑡2 are drawn according to

2
𝑛 − 1 𝑠𝑡,𝛿
𝜎𝑡2 |𝑔𝑡 , 𝑚𝑡 ∼ InverseGamma ( , )
2 2
θ𝑡,𝑝𝑡 |𝜎𝑡2 , 𝑔𝑡 , 𝑚𝑡 ∼ 𝑁𝑝𝑡 +1 (µ𝑡 , 𝜎𝑡2 𝚺𝑡 )

where 𝑛 is the sample size and 𝑠2𝑡,𝛿 , µ𝑡 , and 𝚺𝑡 are computed according to (1), (3), and (4) in Conditional
posterior distribution of model parameters in Methods and formulas of [BMA] bmaregress (with index
𝑗 substituted for 𝑡, that is, conditional on model 𝑚𝑡 instead of 𝑀𝑗 ).
Let θ𝑡 be a (𝑝 +1)×1 vector that includes all 𝑝 regression coefficients and the intercept from iteration
𝑡. Then the result is a sample {θ𝑡 , 𝜎𝑡2 }𝑇𝑡=1 from the BMA posterior distribution of model parameters.
6 bmacoefsample — Posterior samples of regression coefficients

Also see
[BMA] bmaregress — Bayesian model averaging for linear regression
[BMA] BMA postestimation — Postestimation tools for Bayesian model averaging
[BMA] Glossary
[BAYES] Bayesian postestimation — Postestimation tools after Bayesian estimation

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 com-
panies. Copyright © 1985–2023 StataCorp LLC, College Station, TX, USA. All rights
reserved.
For suggested citations, see the FAQ on citing Stata documentation.

You might also like