Forecasting using distributions\timeseries in pymc 4.4.0

Is there yet a general way to forecast n steps ahead using timeseries models, like pm.AR ?

I thing that ideally there would be an ‘extra steps’ argument, or something similar to generate extra points beyond the end of the observed data for these models.

Or an accessible iterator function supplied by the ts class, which allowed stepping to be coded manually, given the necessary state.

I would like something that can be used in the main inference sampling as well as ppc. So far, I have tried a few approaches

(i) passing in a pandas series with padded nans at the end, as suggested here:

this looks like it should be a generic solution, but I get the error:

Automatic inputation is only supported for univariate RandomVariables. lk of type <class ‘pymc.distributions.timeseries.AutoRegressiveRV’> is not supported

(which I suspect should read imputation)

(ii) I tried also having two calls to pm.AR() in the model, the first including the observed data, and the second intended to carry on (forecasting n steps) where the first one left off. However, I could not figure out how to set up the latter correctly - because init_dist in the second call is not going to accept a tensor value passed out of the first call.

The only way that I have been able to get this to work so far, is to manually code an iterator function that steps the AR process forward separately from the pm.AR. this is obviously not ideal, as you end up having to recode the process which is inside the time-series distribution.

Thanks for any insights


Do you want to forecast, conditioning on the last observed value or also redrawing the observed timepoints?

If it’s the first, the easiest is to add a Deterministic:

with pm.Model() as m:
  obs = pm.AR("obs", ..., observed=data)
  pred = pm.Deterministic(

Passing the same parameters that you use for the observed timeseries, which I omitted with ...

If the second, just use the default sample_posterior_predictive. You can make the shape depend on a MutableData to increase the number of steps that are simulated.

This is also a pretty comprehensive set of examples: Forecasting with Structural AR Timeseries — PyMC example gallery

Thanks, that is what I was looking for