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:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
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