Documentation 
Estimate VARX model parameters
EstSpec = vgxvarx(Spec,Y)
[EstSpec,EstStdErrors,LLF,W] = vgxvarx(Spec,Y,X,Y0,'Name1',Value1,'Name2',Value2,...);
Spec  A multivariate time series specification structure for an ndimensional time series process, as created by vgxset. Spec must contain model dimensions, a lag structure (if any), and parameter estimation mappings (if any). It is not necessary to have initial values for any parameters to be estimated. 
Y  A single path of an ndimensional time series process with T observations for each path, collected in a Tbyn matrix. If Y contains multiple paths, vgxvarx uses only the first path to estimate parameters in Spec. 
X  Exogenous inputs. nPX paths of regression design matrices associated with T observations of an ndimensional time series process, where each design matrix linearly relates nX exogenous inputs to each time series at each observation time. X is a TbynPX matrix of cell arrays with nbynX design matrices in each cell. If Y has multiple paths, X must contain either a single path or no fewer than the same number of paths as in Y. Extra paths are ignored. 
Y0  Presample time series process. nPY0 presample paths of an ndimensional time series process with TY0 samples for each path, collected in a TY0bynbynPY0 array. If Y0 is empty or if TY0 is less than the maximum AR lag in Spec, presample values are padded with zeros. If TY0 is greater than the maximum AR lag, the most recent samples from the last rows of each path of Y0 are used. If Y0 has multiple paths, Y0 must contain either a single path or no fewer than the same number of paths as in Y. Extra paths are ignored. 
Specify the following optional input arguments as variablelength lists of matching parameter name/value pairs: 'Name1', Value1, 'Name2', Value2, ... and so on. The following rules apply when specifying parametername pairs:
Specify the parameter name as a character string, followed by its corresponding parameter value.
You can specify parameter name/value pairs in any order.
Parameter names are case insensitive.
You can specify unambiguous partial string matches.
The following table lists valid parameter name/value pairs.
Name  Value 

'CovarType'  Form of the estimated covariance matrix.
This value overrides the value of Qsolve in Spec. 
'StdErrType'  Form of the estimated standard errors.

'IgnoreMA'  Use of moving average terms in the specification structure.
For example, if a VARMA (1,1) model is specified with IgnoreMA set to 'yes', vgxvarx treats the model as a VAR(1) model with no moving average terms. If IgnoreMA is set to 'no', vgxvarx will not calibrate the model and will produce an error. 
'MaxIter'  Maximum number of iterations for parameter estimation. The default is 1000. For ordinary leastsquares (OLS) estimates of the parameters, set 'MaxIter' to 1. For feasible generalized leastsquares (FGLS) estimates, set 'MaxIter' to 2. This parameter is used only for regression with exogenous inputs. 
'TolParam'  Convergence tolerance for parameter estimation. The default is sqrt(eps). 
'TolObj'  Convergence tolerance for parameter estimates. The default is eps^(3/4). 
EstSpec  A multivariate time series specification structure for an ndimensional time series process that contains parameter estimates for a VAR or VARX model, as created by vgxset. 
EstStdErrors  A multivariate time series specification structure containing standard errors of estimated parameters for the ndimensional time series process EstSpec. EstStdErrors is not a specification of a VAR or VARX model; it contains standard errors that are mapped to the equivalent model parameters in EstSpec. If StdErrType is set to 'none', EstStdErrors is vgxset.empty. The standard errors are maximum likelihood estimates, so a degreeoffreedom adjustment is necessary to form ordinary least squares estimates. To adjust standard errors for degreesoffreedom, multiply them by $$\sqrt{\frac{T}{(TNumActive1)}},$$ where T is the number of observations of the time series process and NumActive is the number of unrestricted parameters that vgxvarx estimates. 
LLF  The loglikelihood function with the maximum likelihood estimates of the model parameters from EstSpec. 
W  Estimated innovations process. Since the estimation is based on a single path of Y, W contains the inferred path of an ndimensional innovations process with T observations given the estimated model is EstSpec. 
Start with a 2dimensional VARMA(2, 2) specification structure in Spec with presample data for the time series and innovations process:
load Data_VARMA22
The process in Y was generated with the known specification structure in Spec and is a VARMA(2, 2) process. Since vgxvarx calibrates VARX models, ignore the moving average component of the model and fit a pure VAR(2) model as an approximation. The function vgxvarx generates parameter estimates in EstSpec and standard errors in EstStdErrors:
[EstSpec, EstStdErrors] = vgxvarx(vgxar(Spec), Y, [], Y0);
Use vgxdisp to display the estimated parameters along with standard errors and tstatistics:
vgxdisp(EstSpec, EstStdErrors)
Model : 2D VAR(2) with No Additive Constant Conditional mean is ARstable and is MAinvertible Standard errors without DoF adjustment (maximum likelihood) Parameter Value Std. Error tStatistic     AR(1)(1,1) 0.850166 0.12583 6.75649 (1,2) 0.0498191 0.163542 0.304625 (2,1) 0.219381 0.0934711 2.34705 (2,2) 0.0227752 0.121486 0.187472 AR(2)(1,1) 0.294609 0.145514 2.02461 (1,2) 0.221336 0.148174 1.49376 (2,1) 0.264504 0.108094 2.44699 (2,2) 0.0819125 0.110069 0.74419 Q(1,1) 0.051844 Q(2,1) 0.00711775 Q(2,2) 0.0286081
To see qualitatively how well the VARX approximation worked, infer the innovations process from the calibrated model and compare with the known innovations process from the VARMA(2, 2) process in W:
EstW = vgxinfer(EstSpec, Y, [], Y0, W0); subplot(2,1,1); plot([ W(:,1), EstW(:,1) ]); subplot(2,1,2); plot([ W(:,2), EstW(:,2) ]); legend('VARMA(2, 2)', 'VAR(2)');
Try to calibrate a VAR(2) model with a restricted model such that the crossterms in the AR lag matrices are fixed at 0 (this model treats each time series in Y as a separate VAR model but with a joint distribution for the innovations process):
SpecX = vgxset(vgxar(Spec),'AR',repmat({eye(2)},2,1), ... 'ARsolve', repmat({ logical(eye(2)) }, 2, 1)); [EstSpecX, EstStdErrorsX] = vgxvarx(SpecX, Y, [], Y0);
Compare the calibrated restricted VAR(2) model with the previous unrestricted VAR(2) model to see that the crossterms in the AR lag matrices have been fixed at 0 in the restricted model:
vgxdisp(EstSpecX, EstSpec);
Model 1: 2D VAR(2) with No Additive Constant Conditional mean is ARstable and is MAinvertible Model 2: 2D VAR(2) with No Additive Constant Conditional mean is ARstable and is MAinvertible Parameter Model 1 Model 2    AR(1)(1,1) 0.789031 0.850166 (1,2) 0 0.0498191 (2,1) 0 0.219381 (2,2) 0.284343 0.0227752 AR(2)(1,1) 0.251377 0.294609 (1,2) 0 0.221336 (2,1) 0 0.264504 (2,2) 0.178158 0.0819125 Q(1,1) 0.0541056 0.051844 Q(2,1) 0.00806393 0.00711775 Q(2,2) 0.0410274 0.0286081