Hello! I want to fit three component mixture model. Let W ~ π(ππ,ππ)
be a set of two-dimensional random vectors and we want to fit
(ππ,ππ) ~ π0ππ(.|π0ππ0π)+π1ππ(.|π1ππ1π)+ π2ππ(.|π2ππ2π)
Where π(.|ππ)
is the product of two Poisson distribution and the mean of the three components were defined as follows:
π0π > π0π , π1π = π1π and π2π < π2π respectively
and I write the following R code:
data {
int<lower=1> N;
int<lower=2> y1[N];
int<lower=2> y2[N];
matrix[N,4] x1;
matrix[N,4] x2;
real<lower=0> ci;
vector[N] mci1;
vector[N] mci2;
vector[N] mci;
real<lower=0> mc;
vector[N] a1;
vector[N] a2;
vector[N] a3;
real<lower=0> ma1;
real<lower=0> ma2;
real<lower=0> ma3;
}
transformed data{
int y_ast1[N];
int y_ast2[N];
for (i in 1:N){
y_ast1[i] = y1[i] - 2;
y_ast2[i] = y2[i] - 2;
}
}
parameters {
vector[4] beta1;
vector[4] beta2;
real alpha1;
real alpha2;
vector<lower=0, upper=1>[N] p1;
vector<lower=0, upper=1>[N] p2;
}
transformed parameters{
vector[N] mu1 = exp(alpha1 + x1*beta1);
vector[N] mu2 = exp(alpha2 + x2*beta2);
}
model {
beta1 ~ normal(0,3);
alpha1 ~ normal(0,3);
beta2 ~ normal(0,3);
alpha2 ~ normal(0,3);
p1 ~ beta(a1,ma1);
p2 ~ beta(a2,ma2);
p3 ~ beta(a3,ma3);
// Likelihood
for(i in 1:N)
target += log_sum_exp(
log(p1) + poisson_lpmf(y_ast1[i]|mu1[i]*exp(ci))*poisson_lpmf(y_ast2[i]|mu1[i]), // mu1 > mu2, then I substitute mu2 by mu1 and I multiply mu1 by positive number
log(p2) + poisson_lpmf(y_ast1[i]|mu1[i])*poisson_lpmf(y_ast1[i]|mu1[i]), // mu1=mu2, then I put mu1 in both
log(1-p1-p2) + poisson_lpmf(y_ast1[i]|mu1[i]*(1/exp(ci)))*poisson_lpmf(y_ast2[i]|mu1[i])); // mu1 < mu2 , then I did the reverse what I put in the first
}
}
When I run the above code, I got the following err
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for: log_sum_exp(vector, vector, vector)
Therefore, would you please guide me how I fix it
Thanks for you help!