Likelihood function in the scan function (AR2 model)

Your model is incomplete. You should wrap the transition and scan into a single helper function and pass it to a pm.CustomDist. Here’s an example.

You could also give the SARIMAX model in pymc-experimental a try. It’s under active development, so if you do and you hit any problems, don’t hesitate to open an issue/ask here.