# Mixture Bayesian Poisson Regression Model

#21

I don’t undertand what you want to correspond to what.

You have a two-dimensional parameter `mu` and a one-dimensional parmaeter `pi`. You’re looking at draws from the posterior. There’s not a different `mu` or `pi` for each `Y` in the model.

#22

Did you realize that Stan uses the standard deviation to parameterize normal? Also, you can collapse all those statements into

``````beta ~ normal(0, 1e-3);
``````

#23

it is the probability of the first group and the the second will have 1- `pi`.
I need the corresponding `pi` for each observation, therefore how can we get such value?

#24

I don’t think I can really follow this. Could you post your current Stan code and describe where the data come from and what inferences you are trying to make, which questions are you trying to answer?

#25

thank you for your concern. My model is the mixture of truncated Poisson. Each observation will have probability `pi[1]` to be in the first group and `pi[2]` in the second group. Therefore, I need here two `pi's` with `[N]` dimensions at observation level. Similarly, we need `mu[1] and mu[2]` at observation level. After having pi, we will do categorization of each observation according to some literatures (example below 0.6, we will categorize in group 1 and so on).

my current code is the following:

``````data {

int<lower=0> N;           // number of data points
int <lower=1> y[N];         // observations
matrix[N,4] x;               // Covariates
real<lower=0> mi[N];
}

transformed data {
real<lower=0> Ami;
Ami=mean(mi);
}

parameters {
real<lower=0> ci; // any Positive number added on the mu[1] to get mu[2]
vector[4] beta;
real alpha;
vector<lower=0, upper=1>[N] pi;  // mixing proportions; need to have pi's at observation level

}

transformed parameters{
vector<lower=0>[N] mu[2];    // locations of mixture components; need to have mu's for each observation
mu[1] = exp(alpha + x*beta);
mu[2] = exp((alpha + x*beta)+ci);

}

model {

// Priors
beta ~ normal(0, 1e1);
alpha ~ normal(0,1e1);
ci ~ normal(0, 1e1);
pi ~ beta(mi,Ami);     // how can we change to Dirichlet distribution using mi and mci?
// Likelihood

for (i in 1:N)
target += log_mix(pi,
poisson_lpmf(y[i] | mu[1]) - log1m_exp(poisson_lpmf(0 | mu[1])),
poisson_lpmf(y[i] | mu[2]) - log1m_exp(poisson_lpmf(0 | mu[2])));

}
``````

When I run the above code, I got this error

``````SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:
log_mix(vector, real, real)
Available argument signatures for log_mix:
log_mix(real, real, real)
log_mix(real[], real[])
log_mix(real[], vector)
log_mix(real[], row vector)
log_mix(real[], vector[])
log_mix(real[], row vector[])
log_mix(vector, real[])
log_mix(vector, vector)
log_mix(vector, row vector)
log_mix(vector, vector[])
log_mix(vector, row vector[])
log_mix(row vector, real[])
log_mix(row vector, vector)
log_mix(row vector, row vector)
log_mix(row vector, vector[])
log_mix(row vector, row vector[])

error in 'modeld8755c72_ff542624806624524b7b715fc8665283' at line 56, column 82
-------------------------------------------------
54:       target += log_mix(pi,
55:                   poisson_lpmf(y[i] | mu[1]) - log1m_exp(poisson_lpmf(0 | mu[1])),
56:                   poisson_lpmf(y[i] | mu[2]) - log1m_exp(poisson_lpmf(0 | mu[2])));
^
57:
-------------------------------------------------
Error in stanc(file = file, model_code = model_code, model_name = model_name,  :
failed to parse Stan model 'ff542624806624524b7b715fc8665283' due to the above error.
In file.remove(tf) :
cannot remove file 'C:\Users\521-04\AppData\Local\Temp\Rtmpc35uis\filed82a886c34', reason 'Permission denied'
``````

I understand the problem here that the log_mix is real and it will not consider vector mixing proportion. But I need the mixing proportion at observation level and how can i handle this.

FYI: When I change the mixing proportion to `real<lower=0, upper=1> pi` it was working properly and can get the `N` amount of `mu[1] and mu[2]` , but could not get the mixing proportion at observation level.

Generated quantities for mixture models
#26

You probably want

``````target += log_mix(pi[i], ...
``````