I’m getting two errors when trying to use arviz to plot_ppc
. I want to see the simulations/mean/observed for this model. The mode compiles and samples with no issue. The model is a basic logistic regression…which I have not done in STAN…or any Bayesian framework for that matter.
This is the code I’m running for plotting the ppc.
fit = my_model.sample(data=gh_dict, iter_warmup=200, iter_sampling =1000,
show_progress=True,
output_dir = "D:\\Stan")
inf_data = az.convert_to_inference_data(fit)
ppc = az.plot_ppc(inf_data, data_pairs={"y_rep":"issued_flag"})
fig2 = ppc.figure
fig2.savefig(r"C:\Users\JORDAN.HOWELL.GITDIR\PycharmProjects\pythonProject\gooseheadquotes\output\ppc.jpg",
dpi=200, bbox_inches="tight")
Error/Warning 1
UserWarning: rcParams['plot.max_subplots'] (40) is smaller than the number of variables to plot (18179) in plot_posterior, generating only 40 plots
warnings.warn(
Error/Warning 2
UserWarning: Your data appears to have a single value or no finite values
warnings.warn("Your data appears to have a single value or no finite values")
Here is the model I’m running.
data {
int<lower=0> N; // number policy
int<lower=0, upper=1> issued_flag[N]; // conversion numbers
vector[N] n_lmt1;// normalized limit 1
vector[N] n_pp_lmt; //normalized personal property limit
vector[N] n_age;//normalized age of insured
vector[N] n_aoh;//normalized age of home
}
parameters {
real<lower=0> mu;
real limit1_beta;
real pplimit_beta;
real age_beta;
real aoh_beta;
}
model {
mu ~ normal(0,3);
limit1_beta ~ normal(0,5);
pplimit_beta ~ normal(0,5);
age_beta ~ normal(0,5);
aoh_beta ~ normal(0,5);
issued_flag~ bernoulli_logit(mu + n_lmt1*limit1_beta + n_pp_lmt*pplimit_beta + n_age*age_beta + n_aoh*aoh_beta);
}
generated quantities {
vector[N] eta = mu + n_lmt1*limit1_beta + n_pp_lmt*pplimit_beta + n_age*age_beta + n_aoh*aoh_beta;
int y_rep[N];
if (max(eta) > 20) {
// avoid overflow in poisson_log_rng
print("max eta too big: ", max(eta));
for (n in 1:N)
y_rep[n] = -1;
} else {
for (n in 1:N)
y_rep[n] = bernoulli_rng(eta[n]);
}
}
If you need to use math formula, use Latex syntax:
Don’t forget to attach tags (top right of this form) for application area/class of models or other general subject areas your topic touches on.