Error when fitting a Bernoulli logit model with weights

Hi everyone,

I am trying to fit a weighted logistic regression model (using weights as the survey weights).

My code is as follows. Here w corresponds to the weights:

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

parameters {
   real alpha1;
   vector[K1] beta1;

model {
  beta1 ~ normal(0, 5);
    alpha1 ~ normal(0, 5);

   for (k in 1:N)
  target+=  w[k]*bernoulli_logit_glm_lpmf(y1[k]|x1,alpha1,beta1);

However, I am getting the following error:

No matches for:

bernoulli_logit_glm_lpmf(int, matrix, 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)

It seems there is a problem of how I define parameters inside the bernoulli_logit_glm_lpmf and I couldn’t figure it out by myself.
Can somebody help me to figure this out?

Thank you.

The issue is that this signature for bernoulli_logit_glm_lpmf is not available in rstan, since rstan is a couple of stan versions behind. I can compile your model without issue using the cmdstanR package:

1 Like