Rstan: logistic regression

I am not sure how to use bernoulli_logit, I would like to fit a logistic regression model, but I am not sure is this model right?

infection ~ bernoulli_logit(b_0 + b_x* x[n]); // model

infection is the infection number, and my original formula is log(p/1-p) = b_0 + b_x* x, where p mean infection rate. So is this model right? because I cannot get the final result from this model, but there is no error comes out.

1 Like

That is the right idea, but it should probably be

infection ~ bernoulli_logit(b_0 + b_x * x);

without the [n] index on the vector x. In any event, b_0 + b_x * x is assumed to be the log-odds of being infected for each observation.

1 Like

I think I should add [n], because I also have ‘for (n in 1:N)’

Well, in that case it should be

for (n in 1:N) 
  infection[n] ~ bernoulli_logit(b_0 + b_x * x[n]);

but that is just a slow version of

infection ~ bernoulli_logit(b_0 + b_x * x);

so you should do it the fast way.

1 Like

but it took 2 days, there is still no results, I am thinking, there should be sth wrong, it’s weird.

What is the whole Stan program?

ohh, the results came out, thanks :)