wwrechard / pydlm

A python library for Bayesian time series modeling
BSD 3-Clause "New" or "Revised" License
475 stars 98 forks source link

Data used in plotCoef #36

Open kreamas opened 5 years ago

kreamas commented 5 years ago

Hi, I'm trying to retrieve the raw data used in plotCoef.

I'm in the idea that the red line is taken via

.getLatentState(filterType='backwardSmoother', name='x')

but my issue is that I haven't found what are the values taken to plot the probability bands for such latent state

I thought that using

.getLatentCov(filterType='backwardSmoother', name='x')

would give me such numbers (by adding and substracting them from the Latent State) but such numbers are not the same as those that were plotted.

Am I doing and / or interpreting something wrong?

Thanks in advance

wwrechard commented 5 years ago

Hi Kreamas

The latent state plot function is done here: https://github.com/wwrechard/pydlm/blob/47d9437aca5c7894eb15986057ff15eb93faafa6/pydlm/plot/dlmPlot.py#L206

The marginal variance is obtained from the diagonal entry of the latent covariance matrix: https://github.com/wwrechard/pydlm/blob/47d9437aca5c7894eb15986057ff15eb93faafa6/pydlm/plot/dlmPlot.py#L290, which is the same as you described.

It then calls to a specific function for getting the confidence interval: https://github.com/wwrechard/pydlm/blob/47d9437aca5c7894eb15986057ff15eb93faafa6/pydlm/plot/dlmPlot.py#L300 using the mean and variance from the previous steps. For p = 95%, the result is around [mean - 2 sqrt(var), mean + 2 sqrt(var)]