empiricalbvarm
Bayesian vector autoregression (VAR) model with samples from prior or posterior distribution
Since R2020a
Description
The Bayesian VAR model object empiricalbvarm
contains samples from the distributions of the coefficients Λ and innovations covariance matrix Σ of a VAR(p) model, which MATLAB® uses to characterize the corresponding prior or posterior distributions.
For Bayesian VAR model objects that have an intractable posterior, the estimate
function returns an empiricalbvarm
object representing the empirical posterior distribution. However, if you have random draws from the prior or posterior distributions of the coefficients and innovations covariance matrix, you can create a Bayesian VAR model with an empirical prior directly by using empiricalbvarm
.
Creation
Syntax
Description
creates a Mdl
= empiricalbvarm(numseries
,numlags
,'CoeffDraws',CoeffDraws
,'SigmaDraws',SigmaDraws
)numseries
-D Bayesian VAR(numlags
) model object Mdl
characterized by the random samples from the prior or posterior distributions of and Σ, CoeffDraws
and SigmaDraws
, respectively.
numseries
= m, a positive integer specifying the number of response time series variables.numlags
= p, a nonnegative integer specifying the AR polynomial order (that is, number ofnumseries
-by-numseries
AR coefficient matrices in the VAR model).
sets writable properties (except Mdl
= empiricalbvarm(numseries
,numlags
,'CoeffDraws
',CoeffDraws,'SigmaDraws
',SigmaDraws,Name,Value
)NumSeries
and P
) using name-value pair arguments. Enclose each property name in quotes. For example, empiricalbvarm(3,2,'CoeffDraws',CoeffDraws,'SigmaDraws',SigmaDraws,'SeriesNames',["UnemploymentRate" "CPI" "FEDFUNDS"])
specifies the random samples from the distributions of λ and Σ and the names of the three response variables.
Because the posterior distributions of a semiconjugate prior model (semiconjugatebvarm
) are analytically intractable, estimate
returns an empiricalbvarm
object that characterizes the posteriors and contains the Gibbs sampler draws from the full conditionals.
Input Arguments
numseries
— Number of time series m
1
(default) | positive integer
Number of time series m, specified as a positive integer. numseries
specifies the dimensionality of the multivariate response variable yt and innovation εt.
numseries
sets the NumSeries
property.
Data Types: double
numlags
— Number of lagged responses
nonnegative integer
Number of lagged responses in each equation of yt, specified as a nonnegative integer. The resulting model is a VAR(numlags
) model; each lag has a numseries
-by-numseries
coefficient matrix.
numlags
sets the P
property.
Data Types: double
Properties
You can set writable property values when you create the model
object by using name-value argument syntax, or after you create the model object by using dot
notation. For example, to create a 3-D Bayesian VAR(1) model from the coefficient and innovations covariance arrays of draws CoeffDraws
and SigmaDraws
, respectively, and then label the response variables, enter:
Mdl = empiricalbvarm(3,1,'CoeffDraws',CoeffDraws,'SigmaDraws',SigmaDraws); Mdl.SeriesNames = ["UnemploymentRate" "CPI" "FEDFUNDS"];
Required Draws from Distribution
CoeffDraws
— Random sample from prior or posterior distribution of λ
numeric matrix
Random sample from the prior or posterior distribution of λ, specified as a NumSeries*
-by-k
numdraws
numeric matrix, where
(the number of coefficients in a response equation). k
= NumSeries*P + IncludeIntercept + IncludeTrend + NumPredictorsCoeffDraws
represents the empirical distribution of λ based on a size numdraws
sample.
Columns correspond to successive draws from the distribution. CoeffDraws(1:
corresponds to all coefficients in the equation of response variable k
,:)SeriesNames(1)
, CoeffDraws((
corresponds to all coefficients in the equation of response variable k
+ 1):(2*k
),:)SeriesNames(2)
, and so on. For a set of row indices corresponding to an equation:
Elements
1
throughNumSeries
correspond to the lag 1 AR coefficients of the response variables ordered bySeriesNames
.Elements
NumSeries + 1
through2*NumSeries
correspond to the lag 2 AR coefficients of the response variables ordered bySeriesNames
.In general, elements
(
throughq
– 1)*NumSeries + 1
correspond to the lagq
*NumSeries
AR coefficients of the response variables ordered byq
SeriesNames
.If
IncludeConstant
istrue
, elementNumSeries*P + 1
is the model constant.If
IncludeTrend
istrue
, elementNumSeries*P + 2
is the linear time trend coefficient.If
NumPredictors
> 0, elementsNumSeries*P + 3
through
constitute the vector of regression coefficients of the exogenous variables.k
This figure shows the row structure of CoeffDraws
for a 2-D VAR(3) model that contains a constant vector and four exogenous predictors:
where
ϕq,jk is element (j,k) of the lag q AR coefficient matrix.
cj is the model constant in the equation of response variable j.
Bju is the regression coefficient of the exogenous variable u in the equation of response variable j.
CoeffDraws
and SigmaDraws
must be based on the same number of draws, and both must represent draws from either the prior or posterior distribution.
numdraws
should be reasonably large, for example, 1e6
.
Data Types: double
SigmaDraws
— Random sample from prior or posterior distribution of Σ
array of positive definite numeric matrices
Random sample from the prior or posterior distribution of Σ, specified as a NumSeries
-by-NumSeries
-by-numdraws
array of positive definite numeric matrices. SigmaDraws
represents the empirical distribution of Σ based on a size numdraws
sample.
Rows and columns correspond to innovations in the equations of the response variables ordered by SeriesNames
. Columns correspond to successive draws from the distribution.
CoeffDraws
and SigmaDraws
must be based on the same number of draws, and both must represent draws from either the prior or posterior distribution.
numdraws
should be reasonably large, for example, 1e6
.
Data Types: double
Model Characteristics and Dimensionality
Description
— Model description
string scalar | character vector
Model description, specified as a string scalar or character vector. The default value describes the model dimensionality, for example '2-Dimensional VAR(3) Model'
.
Example: "Model 1"
Data Types: string
| char
NumSeries
— Number of time series m
positive integer
This property is read-only.
Number of time series m, specified as a positive integer. NumSeries
specifies the dimensionality of the multivariate response variable yt and innovation εt.
Data Types: double
P
— Multivariate autoregressive polynomial order
nonnegative integer
This property is read-only.
Multivariate autoregressive polynomial order, specified as a nonnegative integer. P
is the maximum lag that has a nonzero coefficient matrix.
P
specifies the number of presample observations required to initialize the model.
Data Types: double
SeriesNames
— Response series names
string vector | cell array of character vectors
Response series names, specified as a NumSeries
length string vector. The default is ['Y1' 'Y2' ... 'Y
. NumSeries
']empiricalbvarm
stores SeriesNames
as a string vector.
Example: ["UnemploymentRate" "CPI" "FEDFUNDS"]
Data Types: string
IncludeConstant
— Flag for including model constant c
true
(default) | false
Flag for including a model constant c, specified as a value in this table.
Value | Description |
---|---|
false | Response equations do not include a model constant. |
true | All response equations contain a model constant. |
Data Types: logical
IncludeTrend
— Flag for including linear time trend term δt
false
(default) | true
Flag for including a linear time trend term δt, specified as a value in this table.
Value | Description |
---|---|
false | Response equations do not include a linear time trend term. |
true | All response equations contain a linear time trend term. |
Data Types: logical
NumPredictors
— Number of exogenous predictor variables in model regression component
0
(default) | nonnegative integer
Number of exogenous predictor variables in the model regression component, specified as a nonnegative integer. empiricalbvarm
includes all predictor variables symmetrically in each response equation.
VAR Model Parameters Derived from Distribution Draws
AR
— Distribution mean of autoregressive coefficient matrices Φ1,…,Φp
cell vector of numeric matrices
This property is read-only.
Distribution mean of the autoregressive coefficient matrices Φ1,…,Φp associated with the lagged responses, specified as a P
-D cell vector of NumSeries
-by-NumSeries
numeric matrices.
AR{
is
Φj
}j
, the coefficient matrix of
lag j
. Rows correspond to equations and columns correspond to
lagged response variables; SeriesNames
determines the order of
response variables and equations. Coefficient signs are those of the VAR model expressed
in difference-equation notation.
If P
= 0, AR
is an empty cell. Otherwise, AR
is the collection of AR coefficient means extracted from Mu
.
Data Types: cell
Constant
— Distribution mean of model constant c
numeric vector
This property is read-only.
Distribution mean of the model constant c (or intercept), specified as a NumSeries
-by-1 numeric vector. Constant(
is the constant in equation j
)j
; SeriesNames
determines the order of equations.
If IncludeConstant
= false
, Constant
is an empty array. Otherwise, Constant
is the model constant vector mean extracted from Mu
.
Data Types: double
Trend
— Distribution mean of linear time trend δ
numeric vector
This property is read-only.
Distribution mean of the linear time trend δ, specified as a NumSeries
-by-1 numeric vector. Trend(
is the linear time trend in equation j
)j
; SeriesNames
determines the order of equations.
If IncludeTrend
= false
(the default), Trend
is an empty array. Otherwise, Trend
is the linear time trend coefficient mean extracted from Mu
.
Data Types: double
Beta
— Distribution mean of regression coefficient matrix Β
numeric matrix
This property is read-only.
Distribution mean of the regression coefficient matrix B associated with the exogenous predictor variables, specified as a NumSeries
-by-NumPredictors
numeric matrix.
Beta(
contains the regression coefficients of each predictor in the equation of response variable j
yj
,:)j
,t. Beta(:,
contains the regression coefficient in each equation of predictor xk. By default, all predictor variables are in the regression component of all response equations. You can down-weight a predictor from an equation by specifying, for the corresponding coefficient, a prior mean of 0 in k
)Mu
and a small variance in V
.
When you create a model, the predictor variables are hypothetical. You specify predictor data when you operate on the model (for example, when you estimate the posterior by using estimate
). Columns of the predictor data determine the order of the columns of Beta
.
Data Types: double
Covariance
— Distribution mean of innovations covariance matrix Σ
positive definite numeric matrix
This property is read-only.
Distribution mean of the innovations covariance matrix Σ of the NumSeries
innovations at each time t = 1,...,T, specified as a NumSeries
-by-NumSeries
positive definite numeric matrix. Rows and columns correspond to innovations in the equations of the response variables ordered by SeriesNames
.
Data Types: double
Object Functions
summarize | Distribution summary statistics of Bayesian vector autoregression (VAR) model |
Examples
Create Empirical Model
Consider the 3-D VAR(4) model for the US inflation (INFL
), unemployment (UNRATE
), and federal funds (FEDFUNDS
) rates.
For all , is a series of independent 3-D normal innovations with a mean of 0 and covariance .
You can create an empirical Bayesian VAR model for the coefficients and innovations covariance matrix in two ways:
Indirectly create an
empiricalbvarm
model by estimating the posterior distribution of a semiconjugate prior model.Directly create an
empiricalbvarm
model by supplying draws from the prior or posterior distribution of the parameters.
Indirect Creation
Assume the following prior distributions:
, where is a 39-by-1 vector of means and is the 39-by-39 covariance matrix.
, where is the 3-by-3 scale matrix and is the degrees of freedom.
Create a semiconjugate prior model for the 3-D VAR(4) model parameters.
numseries = 3; numlags = 4; PriorMdl = semiconjugatebvarm(numseries,numlags)
PriorMdl = semiconjugatebvarm with properties: Description: "3-Dimensional VAR(4) Model" NumSeries: 3 P: 4 SeriesNames: ["Y1" "Y2" "Y3"] IncludeConstant: 1 IncludeTrend: 0 NumPredictors: 0 Mu: [39x1 double] V: [39x39 double] Omega: [3x3 double] DoF: 13 AR: {[3x3 double] [3x3 double] [3x3 double] [3x3 double]} Constant: [3x1 double] Trend: [3x0 double] Beta: [3x0 double] Covariance: [3x3 double]
PriorMdl
is a semiconjugatebvarm
Bayesian VAR model object representing the prior distribution of the coefficients and innovations covariance of the 3-D VAR(4) model.
Load the US macroeconomic data set. Compute the inflation rate. Plot all response series.
load Data_USEconModel seriesnames = ["INFL" "UNRATE" "FEDFUNDS"]; DataTimeTable.INFL = 100*[NaN; price2ret(DataTimeTable.CPIAUCSL)]; figure plot(DataTimeTable.Time,DataTimeTable{:,seriesnames}) legend(seriesnames)
Stabilize the unemployment and federal funds rates by applying the first difference to each series.
DataTimeTable.DUNRATE = [NaN; diff(DataTimeTable.UNRATE)];
DataTimeTable.DFEDFUNDS = [NaN; diff(DataTimeTable.FEDFUNDS)];
seriesnames(2:3) = "D" + seriesnames(2:3);
Remove all missing values from the data.
rmDataTimeTable = rmmissing(DataTimeTable);
Estimate the posterior distribution by passing the prior model and entire data series to estimate
.
rng(1); % For reproducibility PosteriorMdl = estimate(PriorMdl,rmDataTimeTable{:,seriesnames},'Display','off')
PosteriorMdl = empiricalbvarm with properties: Description: "3-Dimensional VAR(4) Model" NumSeries: 3 P: 4 SeriesNames: ["Y1" "Y2" "Y3"] IncludeConstant: 1 IncludeTrend: 0 NumPredictors: 0 CoeffDraws: [39x10000 double] SigmaDraws: [3x3x10000 double] AR: {[3x3 double] [3x3 double] [3x3 double] [3x3 double]} Constant: [3x1 double] Trend: [3x0 double] Beta: [3x0 double] Covariance: [3x3 double]
PosteriorMdl
is an empiricalbvarm
model representing the empirical posterior distribution of the coefficients and innovations covariance matrix. empiricalbvarm
stores the draws from the posteriors of and in the CoeffDraws
and SigmaDraws
properties, respectively.
Direct Creation
Draw a random sample of size 1000 from the prior distribution PriorMdl
.
numdraws = 1000;
[CoeffDraws,SigmaDraws] = simulate(PriorMdl,'NumDraws',numdraws);
size(CoeffDraws)
ans = 1×2
39 1000
size(SigmaDraws)
ans = 1×3
3 3 1000
Create a Bayesian VAR model characterizing the empirical prior distributions of the parameters.
PriorMdlEmp = empiricalbvarm(numseries,numlags,'CoeffDraws',CoeffDraws,... 'SigmaDraws',SigmaDraws)
PriorMdlEmp = empiricalbvarm with properties: Description: "3-Dimensional VAR(4) Model" NumSeries: 3 P: 4 SeriesNames: ["Y1" "Y2" "Y3"] IncludeConstant: 1 IncludeTrend: 0 NumPredictors: 0 CoeffDraws: [39x1000 double] SigmaDraws: [3x3x1000 double] AR: {[3x3 double] [3x3 double] [3x3 double] [3x3 double]} Constant: [3x1 double] Trend: [3x0 double] Beta: [3x0 double] Covariance: [3x3 double]
Display the prior covariance mean matrices of the four AR coefficients by setting each matrix in the cell to a variable.
AR1 = PriorMdlEmp.AR{1}
AR1 = 3×3
-0.0198 0.0181 -0.0273
-0.0207 -0.0301 -0.0070
-0.0009 0.0638 0.0113
AR2 = PriorMdlEmp.AR{2}
AR2 = 3×3
-0.0453 0.0371 0.0110
-0.0103 -0.0304 -0.0011
0.0277 -0.0253 0.0061
AR3 = PriorMdlEmp.AR{3}
AR3 = 3×3
0.0368 -0.0059 0.0018
-0.0306 -0.0106 0.0179
-0.0314 -0.0276 0.0116
AR4 = PriorMdlEmp.AR{4}
AR4 = 3×3
0.0159 0.0406 -0.0315
-0.0178 0.0415 -0.0024
0.0476 -0.0128 -0.0165
More About
Bayesian Vector Autoregression (VAR) Model
A Bayesian VAR model treats all coefficients and the innovations covariance matrix as random variables in the m-dimensional, stationary VARX(p) model. The model has one of the three forms described in this table.
Model | Equation |
---|---|
Reduced-form VAR(p) in difference-equation notation |
|
Multivariate regression |
|
Matrix regression |
|
For each time t = 1,...,T:
yt is the m-dimensional observed response vector, where m =
numseries
.Φ1,…,Φp are the m-by-m AR coefficient matrices of lags 1 through p, where p =
numlags
.c is the m-by-1 vector of model constants if
IncludeConstant
istrue
.δ is the m-by-1 vector of linear time trend coefficients if
IncludeTrend
istrue
.Β is the m-by-r matrix of regression coefficients of the r-by-1 vector of observed exogenous predictors xt, where r =
NumPredictors
. All predictor variables appear in each equation.which is a 1-by-(mp + r + 2) vector, and Zt is the m-by-m(mp + r + 2) block diagonal matrix
where 0z is a 1-by-(mp + r + 2) vector of zeros.
, which is an (mp + r + 2)-by-m random matrix of the coefficients, and the m(mp + r + 2)-by-1 vector λ = vec(Λ).
εt is an m-by-1 vector of random, serially uncorrelated, multivariate normal innovations with the zero vector for the mean and the m-by-m matrix Σ for the covariance. This assumption implies that the data likelihood is
where f is the m-dimensional multivariate normal density with mean ztΛ and covariance Σ, evaluated at yt.
Before considering the data, you impose a joint prior distribution assumption on (Λ,Σ), which is governed by the distribution π(Λ,Σ). In a Bayesian analysis, the distribution of the parameters is updated with information about the parameters obtained from the data likelihood. The result is the joint posterior distribution π(Λ,Σ|Y,X,Y0), where:
Y is a T-by-m matrix containing the entire response series {yt}, t = 1,…,T.
X is a T-by-m matrix containing the entire exogenous series {xt}, t = 1,…,T.
Y0 is a p-by-m matrix of presample data used to initialize the VAR model for estimation.
Version History
Introduced in R2020a
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)