Getting an error when writing a Stan program for use with the loo package

I am trying to fit a logistic regression model using Stan so that I can feed it into the loo package. I am following the example here:

The example is based on bernoulli_logit_lpmf. I am trying to fit the model based on bernoulli_logit_glm_lpmf as it may be the most efficient way to do.

However, I am getting an error with the use of bernoulli_logit_glm_lpmf. My code is as follows:

data {
  int<lower=1> N;
  int<lower=1> K1; 
  int<lower=0,upper=1> y1[N];
  matrix[N,K1] x1;

parameters {
   real alpha1;
   vector[K1] beta1;

model {
    beta1 ~ normal(0, 5);
    alpha1 ~ normal(0, 5);
  y1 ~ bernoulli_logit_glm(x1, alpha1, beta1);
generated quantities {
  vector[N] log_lik;
  for (n in 1:N) {
    log_lik[n] = bernoulli_logit_glm_lpmf(y1[n] | x1[n], alpha1, beta1);

The error that I am getting is:

No matches for: 

  bernoulli_logit_glm_lpmf(int, row_vector, real, vector)

Available argument signatures for bernoulli_logit_glm_lpmf:

  bernoulli_logit_glm_lpmf(int[ ], matrix, real, vector)
  bernoulli_logit_glm_lpmf(int[ ], matrix, vector, vector)

 error in 'model2c5c309c5b00_logistic_model_regloo' at line 27, column 71
    25:   vector[N] log_lik;
    26:   for (n in 1:N) {
    27:     log_lik[n] = bernoulli_logit_glm_lpmf(y1[n] | x1[n], alpha1, beta1);
    28:   }

Can anyone guide me to fix this error?

Thank you

It tells you that there is no version of the log-likelihood function whose signature is bernoulli_logit_glm_lpmf(int, row_vector, real, vector). You probably meant

for (n in 1:N)
  log_lik[n] = bernoulli_logit_lpmf(y1[n] | alpha1 + x1[n, ] * beta1);
1 Like

@bgoodri Thank you very for the reply. Yeah this is working.
I am wondering how can I fix this with the use of bernoulli_logit_lpmf. May be with the different representation of the data component in the model. Will it be possible to give any advice regarding that?

bernoulli_logit_lpmf(y1[n] | alpha1 + x1[n, ] * beta1) is the same log-likelihood contribution from the n-th observation that is accumulated over all N observations by bernoulli_logit_glm(x1, alpha1, beta1).