%% Create Partially Specified Univariate Model for Estimation
% Consider fitting to data a two-state exponential STAR model for a 1-D response process. Assume all parameters are unknown (includes transition mid-level t, rate r, and all dynamic model coefficients and variances \theta).
% Create an exponential threshold transition. Specify unknown elements using NaN.

tt = threshold(NaN,Type="exponential",Rates=NaN)

% tt is a partially specified threshold object. The mid-level tt.Levels and transition rate tt.Rates are unknown and estimable.
% Create AR(1) and AR(2) models by using the shorthand syntax of arima.

mdl1 = arima(1,0,0);
mdl2 = arima(2,0,0);

% mdl1 and mdl2 are partially specified arima objects. NaN-valued properties correspond to unknown, estimable parameters.
% Store the submodels in a vector.

mdl = [mdl1; mdl2];

% Create a STAR model template from the switching mechanism tt and the state-specific submodels mdl.

Mdl = tsVAR(tt,mdl)

% Mdl is a partially specified tsVAR object representing a univariate two-state STAR model.

Mdl.Submodels(1)
Mdl.Submodels(2)

% tsVAR converts the arima object submodels to 1-D varm object equivalents.
% Mdl is prepared for estimation. You can pass Mdl, along with data and a fully specified threshold transition (threshold object) containing initial values for optimization, to estimate.
% Copyright 2021 The MathWorks, Inc.