PyMC Help Needed - TVP-PVAR with Stochastic Volatility

Hi everyone,

I’m following up on a previous inquiry where @jessegrabowski (thanks again!) offered valuable help regarding a time-varying parameter panel vector autoregression (TVP-PVAR) model with autoregressive order 1 (AR(1)) and stochastic volatility for my research (not yet published). I’m hoping to get some additional guidance from the community on the PyMC implementation aspects.

Model Structure Description:

My model leverages a state-space framework, a common approach for TVP-PVAR models. This framework involves two key equations:

Observation Equation: This equation relates the observed data (denoted as y_t for time t) to a time-varying state vector (alpha_t) and an error term (varepsilon_t). It captures how the observed data is generated by the underlying dynamics in the model.

State Evolution Equation: This equation describes how the state vector (alpha_t) evolves over time. It often involves the previous state vector (alpha_(t-1)) and potentially a random component (eta_t) to account for the time-varying nature of the parameters.

Time-Varying Parameters and Stochastic Volatility:

A key feature of my model is that some parameters within the state vector (alpha_t) can vary over time. This allows the model to capture the dynamic relationships between economic variables.

Additionally, the model incorporates stochastic volatility, meaning the variance of the error term (varepsilon_t) is not constant but can fluctuate over time.

Specific Areas for Assistance (PyMC Implementation):

I have tried as @jessegrabowski suggested here, but I have not been successful
I’m particularly interested in the following aspects of the PyMC implementation:

State-Space Model Setup: Recommendations for building the state-space model structure within PyMC, including defining placeholders for the state vector, observation equation, and state evolution equation.

Time-Varying Parameter Priors: Suggestions on appropriate prior distributions for these time-varying parameters within the state vector in a PyMC context (e.g., conjugate priors).

Stochastic Volatility Implementation: Insights on incorporating stochastic volatility into the model using PyMC, considering different approaches for modeling time-varying variances (e.g., concepts like random walk ).

Additional Information :

My model is related to Bayesian analysis, panel data, and time series econometrics.

I’m particularly interested in using PyMC for the implementation due to its capabilities in state-space modeling.

Minimal Code Snippet (for Context):

import pymc as pm

class BayesianModel:

    def __init__(self, data, vars):
        # data processing and initialization


    def process_country(self, country, filtered_data, vars):
        # Data filtering for a country



    with pm.Model() as model:
        #  PyMC model building using state-space framework

    # Placeholder for state vector (alpha_t)

    # Placeholder for observation equation (relating y_t to alpha_t and error)

    # Placeholder for state evolution equation (how alpha_t evolves)

    #   Sampling using MCMC methods (e.g., pm.sample)

    return country, trace

# Rest of the code for processing countries and analysis)

Error Encountered (Context for process_country function):

Furthermore, I have tried some code ,but I’m encountering an error message within the process_country function of my code. The error states: “Error processing n must be an integer. It is a tensor.” I’m using PyTensor throughout my code, and I suspect this error might be related to the usage of tensors where an integer value is expected.

I would greatly appreciate any guidance or suggestions you can offer to help me resolve these.

Thank you in advance for your time and assistance!

Sincerely,

Dimitri