simulate
Simulate regression coefficients and disturbance variance of Bayesian linear regression model
Syntax
Description
[
returns a random vector of regression coefficients (BetaSim
,sigma2Sim
]
= simulate(Mdl
)BetaSim
)
and a random disturbance variance (sigma2Sim
) drawn from the
Bayesian linear regression
model
Mdl
of β and
σ2.
[
draws from the marginal posterior distributions produced or updated by
incorporating the predictor data BetaSim
,sigma2Sim
]
= simulate(Mdl
,X
,y
)X
and corresponding response
data y
.
If
Mdl
is a joint prior model, thensimulate
produces the marginal posterior distributions by updating the prior model with information about the parameters that it obtains from the data.If
Mdl
is a marginal posterior model, thensimulate
updates the posteriors with information about the parameters that it obtains from the additional data. The complete data likelihood is composed of the additional dataX
andy
, and the data that createdMdl
.
NaN
s in the data indicate missing values, which
simulate
removes by using list-wise deletion.
[
uses any of the input argument combinations in the previous syntaxes and
additional options specified by one or more name-value pair arguments. For
example, you can specify a value for β or
σ2 to simulate from the
conditional posterior distribution of one parameter,
given the specified value of the other parameter.BetaSim
,sigma2Sim
]
= simulate(___,Name,Value
)
[
also returns draws from the latent regime distribution if BetaSim
,sigma2Sim
,RegimeSim
]
= simulate(___)Mdl
is a Bayesian linear regression model for stochastic search variable selection
(SSVS), that is, if Mdl
is a mixconjugateblm
or mixsemiconjugateblm
model object.
Examples
Input Arguments
Output Arguments
Limitations
simulate
cannot draw values from an improper distribution, that is, a distribution whose density does not integrate to 1.If
Mdl
is anempiricalblm
model object, then you cannot specifyBeta
orSigma2
. You cannot simulate from the conditional posterior distributions by using an empirical distribution.
More About
Algorithms
Whenever
simulate
must estimate a posterior distribution (for example, whenMdl
represents a prior distribution and you supplyX
andy
) and the posterior is analytically tractable,simulate
simulates directly from the posterior. Otherwise,simulate
resorts to Monte Carlo simulation to estimate the posterior. For more details, see Posterior Estimation and Inference.If
Mdl
is a joint posterior model, thensimulate
simulates data from it differently compared to whenMdl
is a joint prior model and you supplyX
andy
. Therefore, if you set the same random seed and generate random values both ways, then you might not obtain the same values. However, corresponding empirical distributions based on a sufficient number of draws is effectively equivalent.This figure shows how
simulate
reduces the sample by using the values ofNumDraws
,Thin
, andBurnIn
.Rectangles represent successive draws from the distribution.
simulate
removes the white rectangles from the sample. The remainingNumDraws
black rectangles compose the sample.If
Mdl
is asemiconjugateblm
model object, thensimulate
samples from the posterior distribution by applying the Gibbs sampler.simulate
uses the default value ofSigma2Start
for σ2 and draws a value of β from π(β|σ2,X,y).simulate
draws a value of σ2 from π(σ2|β,X,y) by using the previously generated value of β.The function repeats steps 1 and 2 until convergence. To assess convergence, draw a trace plot of the sample.
If you specify
BetaStart
, thensimulate
draws a value of σ2 from π(σ2|β,X,y) to start the Gibbs sampler.simulate
does not return this generated value of σ2.If
Mdl
is anempiricalblm
model object and you do not supplyX
andy
, thensimulate
draws fromMdl.BetaDraws
andMdl.Sigma2Draws
. IfNumDraws
is less than or equal tonumel(Mdl.Sigma2Draws)
, thensimulate
returns the firstNumDraws
elements ofMdl.BetaDraws
andMdl.Sigma2Draws
as random draws for the corresponding parameter. Otherwise,simulate
randomly resamplesNumDraws
elements fromMdl.BetaDraws
andMdl.Sigma2Draws
.If
Mdl
is acustomblm
model object, thensimulate
uses an MCMC sampler to draw from the posterior distribution. At each iteration, the software concatenates the current values of the regression coefficients and disturbance variance into an (Mdl.Intercept
+Mdl.NumPredictors
+ 1)-by-1 vector, and passes it toMdl.LogPDF
. The value of the disturbance variance is the last element of this vector.The HMC sampler requires both the log density and its gradient. The gradient should be a
(NumPredictors+Intercept+1)
-by-1 vector. If the derivatives of certain parameters are difficult to compute, then, in the corresponding locations of the gradient, supplyNaN
values instead.simulate
replacesNaN
values with numerical derivatives.If
Mdl
is alassoblm
,mixconjugateblm
, ormixsemiconjugateblm
model object and you supplyX
andy
, thensimulate
samples from the posterior distribution by applying the Gibbs sampler. If you do not supply the data, thensimulate
samples from the analytical, unconditional prior distributions.simulate
does not return default starting values that it generates.If
Mdl
is amixconjugateblm
ormixsemiconjugateblm
, thensimulate
draws from the regime distribution first, given the current state of the chain (the values ofRegimeStart
,BetaStart
, andSigma2Start
). If you draw one sample and do not specify values forRegimeStart
,BetaStart
, andSigma2Start
, thensimulate
uses the default values and issues a warning.
Version History
Introduced in R2017a
See Also
Objects
conjugateblm
|customblm
|empiricalblm
|semiconjugateblm
|diffuseblm
|mixconjugateblm
|mixsemiconjugateblm
|lassoblm