%% Change Switching Time for Diffuse Model Estimation
% For diffuse state-space models, the software implements the diffuse Kalman filter until it satisfies a regularity condition. To meet the condition, the software requires enough presample data. After the software satisfies the condition, it switches to using the standard Kalman filter. By default, the software determines how much presample data it requires and only uses as much as it needs. However, you can experiment by specifying other values for the SwitchTime name-value pair argument.
% For this example, use the same data and model as in Estimate Diffuse State-Space Model Containing Regression Component.
% Load the Nelson-Plosser data set.

load Data_NelsonPlosser

isNaN = any(ismissing(DataTable),2);
gnpn = DataTable.GNPN(~isNaN);
y = DataTable.UR(~isNaN);
T = size(gnpn,1);                          
Z = log(gnpn);

%
% Specify the coefficient matrices.

A = NaN;
B = NaN;
C = 1;

%
% Create the state-space model using dssm by supplying the coefficient matrices and specifying that the state values come from a diffuse distribution. The diffuse specification indicates complete ignorance about the moments of the initial distribution.

StateType = 2;
Mdl = dssm(A,B,C,'StateType',StateType);

%
% Estimate the parameters several times. For each time, change the period to switch to the standard Kalman filter.

params0 = [0.3 0.2]; % Initial values chosen arbitrarily
Beta0 = 0.1;

[~,estParams1] = estimate(Mdl,y,params0,'Predictors',Z,'Display','off',...
    'Beta0',Beta0,'lb',[-Inf 0 -Inf],'SwitchTime',1);
[~,estParams5] = estimate(Mdl,y,params0,'Predictors',Z,'Display','off',...
    'Beta0',Beta0,'lb',[-Inf 0 -Inf],'SwitchTime',5);
[~,estParams10] = estimate(Mdl,y,params0,'Predictors',Z,'Display','off',...
    'Beta0',Beta0,'lb',[-Inf 0 -Inf],'SwitchTime',10);

%
% Compare the parameter estimates.

estParams1
estParams5
estParams10

% Because estimate uses fewer data points for subsequent estimations, the estimates are slightly different.
% Copyright 2012 The MathWorks, Inc.