Greetings,
new-ish stan user here and looking to get a hand with my code.
I am attempting to model a multi-variate bernoulli distribution parameterised
the same way as Dai et al. (2013).
P(Y_1=y_1,Y_2=y_2) = p_{00}^{(1-y_1)(1-y_2)}p_{01}^{(1-y_1)y_2}p_{10}^{y_1(1-y_2)}p_11^{y_1y_2}
and looking to infer the parameters p based on observations of Y. Essentially, my approach is to map an observed combination of bernoulli outcomes to an integer. This integer will be the conversion of binary to decimal+1 since indexing is 1 based.
functions {
int f_getIndex(int[] vY){
real index = 1;
int useIndex = 1;
int K = num_elements(vY);
for (i in 1:K){
index = index + vY[i]*pow(2,K-i);
}
while(useIndex < index-0.1){
useIndex = useIndex + 1;
}
return useIndex;
}
real indexMVbern_lpmf(int index, real[] prob_vec){
real out;
out = log(prob_vec[index]);
return out;
}
}
data {
int N; //rows or observations
int K; //cols or number of classifiers
int y[N, K];
}
transformed data {
vector[N] indices;
for (i in 1:N){
indices[i] = f_getIndex(y[i,]);
print(indices[i]);
}
}
parameters {
simplex[K] theta;
vector[K] alpha;
}
model {
for (i in 1:N){
indices[i] ~ indexMVbern_lpmf(theta);
}
theta ~ dirichlet(alpha);
}
My issue is that I am getting the error “No matches for: Available argument signatures for indexMVbern_lpmf: Real return type required for probability function”. I am not sure why I am getting this as I think the variable out
being returned by indexMVbern_lpmf
is indeed real.
Any help would be much appreciated.