How do i figure out what's wrong with an invalid type error?

I’m getting the following error with my model.

ValueError: Invalid type provided to write_stan_json for key 'cl_pure_premium' as part of collection <class 'dict'>

Here is my model

data {
int<lower=0> N; // number policy term years
int<lower=0> cl_pure_premium[N]; // collision pure premium
vector[N] old_auto_c_score;// Farmers Auto C Model

parameters {
real<lower=0> mu;
real beta;


model {
mu ~ normal(0,3);
beta ~ normal(0,1);
cl_pure_premium~ poisson_log(mu + old_auto_c_score*beta);

Technically, we usually fit the variable pure premium with a quasi-poisson (standard GLM) since they're not all real numbers.  Could that be the reason?  I tried changing pure premium to a real data type and 

```cl_pure_premium~ poisson_log(mu + old_auto_c_score*beta)


cl_pure_premium~ poisson_log_lmpf(mu + old_auto_c_score*beta)

but got an error that stated ’ statement should refer to a distribution without its “_lpdf/_lupdf” or “_lpmf/_lupmf” suffix’.

cl_pure_premium is a float in python so maybe it has to be real but a possion_log doesn’t seem to like real data types.

The error you’re getting is happening inside python, not inside Stan itself. Can you share the data you are using in Python?

The data is proprietary but both the target and predictor are integers, about 67K observations.


Based on the error, it seems like the structure of what you’re passing to data has a nested dictionary which can’t be handled. The dictionary you’re passing has to have all of the values be either numeric or arrays of numbers

1 Like

It was a nested dictionary. Thank you for the help. It’s sampling as I type!

1 Like