Main Content

Simulate regression coefficients and disturbance variance of Bayesian linear regression model

`[`

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, then`simulate`

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, then`simulate`

updates the posteriors with information about the parameters that it obtains from the additional data. The complete data likelihood is composed of the additional data`X`

and`y`

, and the data that created`Mdl`

.

`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 `BetaSim`

,`sigma2Sim`

]
= simulate(___,`Name,Value`

)*β* or
*σ*^{2} to simulate from the
*conditional* posterior distribution of one parameter,
given the specified value of the other parameter.

`[`

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.

`simulate`

cannot draw values from an*improper distribution*, that is, a distribution whose density does not integrate to 1.If

`Mdl`

is an`empiricalblm`

model object, then you cannot specify`Beta`

or`Sigma2`

. You cannot simulate from the conditional posterior distributions by using an empirical distribution.

Whenever

`simulate`

must estimate a posterior distribution (for example, when`Mdl`

represents a prior distribution and you supply`X`

and`y`

) 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, then`simulate`

simulates data from it differently compared to when`Mdl`

is a joint prior model and you supply`X`

and`y`

. 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 of`NumDraws`

,`Thin`

, and`BurnIn`

.Rectangles represent successive draws from the distribution.

`simulate`

removes the white rectangles from the sample. The remaining`NumDraws`

black rectangles compose the sample.If

`Mdl`

is a`semiconjugateblm`

model object, then`simulate`

samples from the posterior distribution by applying the Gibbs sampler.`simulate`

uses the default value of`Sigma2Start`

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`

, then`simulate`

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 an`empiricalblm`

model object and you do not supply`X`

and`y`

, then`simulate`

draws from`Mdl.BetaDraws`

and`Mdl.Sigma2Draws`

. If`NumDraws`

is less than or equal to`numel(Mdl.Sigma2Draws)`

, then`simulate`

returns the first`NumDraws`

elements of`Mdl.BetaDraws`

and`Mdl.Sigma2Draws`

as random draws for the corresponding parameter. Otherwise,`simulate`

randomly resamples`NumDraws`

elements from`Mdl.BetaDraws`

and`Mdl.Sigma2Draws`

.If

`Mdl`

is a`customblm`

model object, then`simulate`

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 to`Mdl.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, supply`NaN`

values instead.`simulate`

replaces`NaN`

values with numerical derivatives.If

`Mdl`

is a`lassoblm`

,`mixconjugateblm`

, or`mixsemiconjugateblm`

model object and you supply`X`

and`y`

, then`simulate`

samples from the posterior distribution by applying the Gibbs sampler. If you do not supply the data, then`simulate`

samples from the analytical, unconditional prior distributions.`simulate`

does not return default starting values that it generates.If

`Mdl`

is a`mixconjugateblm`

or`mixsemiconjugateblm`

, then`simulate`

draws from the regime distribution first, given the current state of the chain (the values of`RegimeStart`

,`BetaStart`

, and`Sigma2Start`

). If you draw one sample and do not specify values for`RegimeStart`

,`BetaStart`

, and`Sigma2Start`

, then`simulate`

uses the default values and issues a warning.

`conjugateblm`

|`customblm`

|`empiricalblm`

|`semiconjugateblm`

|`diffuseblm`

|`mixconjugateblm`

|`mixsemiconjugateblm`

|`lassoblm`