%% Estimate ARIMAX Model Parameters Without Initial Values
% Fit an ARIMAX model to a simulated time series without specifying initial values for the response or the parameters.
% Define the ARIMAX(2,1,1) model
% (1 - 0.5L + 0.3{L^2}){(1 - L)^1}{y_t} = 1.5{x_{1,t}} + 2.6{x_{2,t}} - 0.3{x_{3,t}} + {\varepsilon _t} + 0.2{\varepsilon _{t - 1}}
% to eventually simulate a time series of length 500, where \varepsilon_{t} follows a Gaussian distribution with mean 0 and variance 0.1.

Mdl0 = arima('AR',{0.5,-0.3},'MA',0.2,'D',1,...
    'Constant',0,'Variance',0.1,'Beta',[1.5 2.6 -0.3]);
T = 500;

%
% Simulate three stationary AR(1) series and presample values:
% \begin{array}{*{20}{c}}
% {{x_{1,t}} = 0.1{x_{1,t - 1}} + {\eta _{1,t}}}\\
% {{x_{2,t}} = 0.2{x_{2,t - 1}} + {\eta _{2,t}}}\\
% {{x_{3,t}} = 0.3{x_{3,t - 1}} + {\eta _{3,t}},}
% \end{array}
% where \eta_{i,t} follows a Gaussian distribution with mean 0 and variance 0.01 for i = {1,2,3}.

numObs = Mdl0.P + T;
MdlX1 = arima('AR',0.1,'Constant',0,'Variance',0.01);
MdlX2 = arima('AR',0.2,'Constant',0,'Variance',0.01);
MdlX3 = arima('AR',0.3,'Constant',0,'Variance',0.01);
X1 = simulate(MdlX1,numObs);
X2 = simulate(MdlX2,numObs);
X3 = simulate(MdlX3,numObs);
Xmat = [X1 X2 X3];

% The simulated exogenous predictors are stored in the numObs-by-3 matrix Xmat.
%
% Simulate 500 data points from the ARIMA(2,1,1) model.

y = simulate(Mdl0,T,'X',Xmat);

% The simulated response is stored in the column vector y.
%
% Create an ARIMA(2,1,1) model with known 0-valued constant and unknown coefficients and variance.

Mdl = arima(2,1,1);
Mdl.Constant = 0

% Mdl is an ARIMA(2,1,1) model. estimate changes this designation to ARIMAX(2,1,1) when you specify the exogenous predictors data by using the 'X' name-value pair argument. estimate fits all estimable parameters, properties having value NaN in Mdl, to the data.
%
% Fit the ARIMAX(2,1,1) model to y including regression matrix Xmat.

EstMdl = estimate(Mdl,y,'X',Xmat);

% EstMdl is a new arima model designated as ARIMAX(2,1,1) since exogenous predictors enter the model. The estimates in EstMdl resemble the parameter values that generated the simulated data.
% Copyright 2015 The MathWorks, Inc.