I have the following model im pymc3.

import pandas as pd
import pymc3 as pm
import numpy as np
import arviz as az

with basic_model:
     lambda1 = pm.Gamma("lambda1", alpha=0.001, beta=0.001)
     p =  pm.Beta('p', 1, 1,)
     z = [0.0] * len(x['Length'].values)
     Y_obs = [0.0] * len(x['Length'].values)
     for i in range(len(x['Length'].values)):
        z[i] = pm.Bernoulli('z[i]',p)
        Y_obs[i] = pm.Poisson("Y_obs[i]", mu=lambda1*z[i]*x['Length'].values+0.001, observed=x['Count'].values[i])
     trace = pm.sample(7000, tune=2000, cores=1, return_inferencedata=True)

x is a data frame that is read form a csv file. It is producing the error for the names Y_obs[i] and z[i]. I understand that I cannot change use the same name for the variables, but I couldn’t figure out how to change the rate of Y_obs[i] at every iteration. At a later stage, I will be changing the rates with if-else conditions, as well. How do I define a different mean for every data point?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.