Require real return type for probability functions error

I’m trying to convert a model into a map_rect function. I receive the following the error when I try to compile the model:
Require real return type for probability functions ending in _log, _lpdf, _lpmf, _lcdf, or _lccdf.

I think the function below I wrote should be returning a real, but it does not appear to be.

functions{

  vector bin_log(real beta, real alpha, vector theta, int[]Vs, int[]Is){
         real lp = binomial_logit_lpmf(Vs | Is, beta + alpha * theta);
    return [lp]';
  }
}

orignal model block

model{
  theta ~ normal(0, 1);     
  alpha ~ lognormal(1, 1);  
  beta ~ normal(0, 3);      
  for(k in 1:p){
    V[,k] ~ binomial_logit(I, beta[k] + alpha[k] * theta); //model
  }
}

Your function returns a vector[1], not a real. Functions whose name ends in _log (or _lpdf, or _lpmf, …) have special semantics. since you’re using it for map_rect just name the function something else, e.g. logbinom.

1 Like

Thanks for help. That fixed the problem. I was misreading the error as it be thrown for the binomial_logit_lpmf() function instead of my created function.

1 Like