After getting my first pystan model to infer just the mean (see: Help with first model in Pystan), I am now going through and adding one variable at a time.
However, after adding my first variable, I’m getting the following error:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-69-8a82764b37a4> in <module>
----> 1 sm_fit = sm.sampling(data=data1)
2 print(sm_fit)
~\AppData\Local\Continuum\anaconda3\envs\stan_env\lib\site-packages\pystan\model.py in sampling(self, data, pars, chains, iter, warmup, thin, seed, init, sample_file, diagnostic_file, verbose, algorithm, control, n_jobs, **kwargs)
756 raise ValueError("Warmup samples must be greater than 0 when adaptation is enabled (`adapt_engaged=True`)")
757 seed = pystan.misc._check_seed(seed)
--> 758 fit = self.fit_class(data, seed)
759
760 m_pars = fit._get_param_names()
stanfit4anon_model_6a60194cf24baf0e81dd4e0d08e2c3ea_5929338110356435324.pyx in stanfit4anon_model_6a60194cf24baf0e81dd4e0d08e2c3ea_5929338110356435324.StanFit4Model.__cinit__()
RuntimeError: Exception: int variable contained non-int values; processing stage=data initialization; variable name=y1; base type=int (in 'unknown file name' at line 5)
Below is the code for my model (note: my x variable has been normalized for easier sampling):
liability_code = """
data {
int<lower=0> N;
vector[N] driver_age;
int<lower=0> y1;
}
transformed data {}
parameters {
real a; //parameters is what we want to infer....'a' in this case is the coefficient for driver_age
real b;
}
transformed parameters{
real mu[N];
for (i in 1:N) {
mu[i] <- a*driver_age[i] + b;
}
}
model {
a ~ normal(0, 1);
b ~ normal(0,5);
y1 ~ poisson(mu);
}
sm = StanModel(model_code=liability_code)
Here is the data and fit
line:
data1 = {'N':len(y), 'driver_age':x1.values.tolist(), 'y1':y.iloc[:, 0].values.tolist()}
sm_fit = sm.sampling(data=data1)
y1 is a float.
Thank you.