%% Return Loglikelihood for Data
% Consider the model and data in docid:econ_ug.mw_c399d11f-569a-41a9-88d8-1c6f69d9045f.
% Create the fully specified Markov-switching model.

P = [0.92 0.08; 0.26 0.74];
mc = dtmc(P,'StateNames',["Expansion" "Recession"]);

sigma = 3.34;
mdl1 = arima('Constant',4.62,'Variance',sigma^2);
mdl2 = arima('Constant',-0.48,'Variance',sigma^2);
mdl = [mdl1; mdl2];

Mdl = msVAR(mc,mdl);

% Load and preprocess the data.

load Data_GDP

qrate = diff(Data(2:230))./Data(2:229); 
arate = 100*((1 + qrate).^4 - 1);       

%
% Compute filtered state probabilities and the loglikelihood for the data and model.

[FS,logL] = filter(Mdl,arate);
logL

% Copyright 2019 The MathWorks, Inc.
%
%