0
$\begingroup$

I am having problems using EstimatedProcess to estimate a multivariate HiddenMarkovProcess. I'm following the work of a paper, so I know this method is feasible. In brief, given 2 economic variables: inflation and growth, it examines the different states of an economy.

I can use the Mathematica functions to build a reasonable model for each variable individually. However, I'm having problems when trying to build a joint model. Either, EstimatedProcess fails with a an error ("One or more data points are not in the support of the process"), or the HiddenMarkovProcess it returns has only univariate distributions.

Has anyone else had this problem? Are there working examples of this technique?

Here's a link to a notebook I'm using: https://www.wolframcloud.com/obj/56901a8a-ed94-48c9-ab02-985ef11c0016

$\endgroup$
2

1 Answer 1

2
$\begingroup$

It looks like you are trying to fit a 2-state HiddenMarkovProcess where the emission distributions from each state are both 2-variable MultinormalDistributions.

Using my answer from here, we can do that by changing the input data to be TemporalData. You can directly use the dates as the time specifiers with TemporalData, but I prefer to work with raw numbers so I changed the dates to reflect how many months they are away from the start (e.g. dates = data[All, "Date"] // Normal; and then times = (dates - dates[[1]])/Quantity[1, "month"];)

dates = data[All, "Date"] // Normal;
times = (dates - dates[[1]])/Quantity[1, "month"];
econ = data[All, {"INFL", "GRO"}] // Normal // Values;
withDates = TemporalData[econ, {times}]

dist = MultinormalDistribution[{m1, m2}, {{s11, s12}, {s21, s22}}];
class = HiddenMarkovProcess[2, dist];
eproc = EstimatedProcess[withDates, class]


(*HiddenMarkovProcess[{1., 
  0.}, {{0.971484, 0.0285164}, {0.0149025, 
   0.985098}}, {MultinormalDistribution[{4.52507, 
    1.17451}, {{12.1679, 4.53059}, {4.53059, 9.59945}}], 
  MultinormalDistribution[{2.59115, 
    3.40876}, {{1.12483, 0.156499}, {0.156499, 0.413983}}]}]*)

Then grab the emission PDF at each month and plot with observed data:

pdf[time_, x_, y_] = PDF[SliceDistribution[eproc, time], {x, y}];

plotPoints = 
  ListLinePlot3D[Flatten /@ withDates["Path"], PlotStyle -> Red];
dp3 = DensityPlot3D[
   pdf[time, x, y], {time, 1, Length@econ}, {x, -5, 15}, {y, -10, 10},
    PlotRange -> All, AxesLabel -> {"time", "inflation", "growth"}, 
   LabelStyle -> Directive[Bold, Medium], 
   PlotLegends -> BarLegend[Automatic, LegendLabel -> p], 
   ColorFunction -> "TemperatureMap"];
Show[dp3, plotPoints]

Mathematica graphics

Note that the transition matrix is nearly an Identity matrix, so the model doesn't change state very much.

$\endgroup$
2
  • $\begingroup$ @Elliot note that I had to make an update because I was wrong in assuming the dates are evenly spaced. It has been corrected now. $\endgroup$
    – ydd
    Commented Nov 1, 2023 at 15:44
  • $\begingroup$ Thanks again for the great answer! The key was using TemporalData rather than a simple numerical matrix. I also prefer to work with raw numbers. So using a structure like TemporalData in place of a matrix didn't occur to me. Unfortunately, this is not well documented and I'd argue shouldn't matter. As for the model itself, I'm positive that the 2-states is not enough. I was trying to start simple to fix EstimatedProcess. I'd guess that there are 4 states (i.e. 2x2), but that paper I linked found 7 states (with 3 being transitionary states). Thanks also for that awesome visualization! $\endgroup$
    – XXX
    Commented Nov 2, 2023 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.