Hi all,

I am completely new to Stan, and I am trying to fit a logistic regression model with time-varying parameters (and fixed regressors).

The idea is to model the dependent variable as a logistic regression and the model parameters as a random walk.

I have a matrix (N x T, where N is the number of datapoints I have, and T is the number of timesteps) for the response variable containing 0’s and 1’s.

What I noticed is that when the number of N increases (for example N \geq 300) the time to calibrate the model is very large (more than 20hours).

Is there anything I could do to make the model running faster? Is there anything incorrect in the model specification? Any help would be greatly appreciated!

Here’s the code of the model:

```
data {
int<lower=0> N; // number of datapoints
int<lower=0> T; // number of timesteps
int<lower=0,upper=1> y[N,T]; // outcome matrix with 0's and 1's
// Variables
vector[N] x1; // regressor 1
vector[N] x2; // regressor 2
vector[N] x3; // regressor 3
vector[N] x4; // regressor 4
vector[N] x5; // regressor 5
vector[N] x6; // regressor 6
vector[N] x7; // regressor 7
}
parameters {
vector[T] alpha;
vector[T] b1;
vector[T] b2;
vector[T] b3;
vector[T] b4;
vector[T] b5;
vector[T] b6;
vector[T] b7;
real<lower=0> Walpha;
real<lower=0> W1;
real<lower=0> W2;
real<lower=0> W3;
real<lower=0> W4;
real<lower=0> W5;
real<lower=0> W6;
real<lower=0> W7;
}
model {
alpha[1] ~ normal(0.0,25);
b1[1] ~ normal(0.0, 25);
b2[1] ~ normal(0.0, 25);
b3[1] ~ normal(0.0, 25);
b4[1] ~ normal(0.0, 25);
b5[1] ~ normal(0.0, 25);
b6[1] ~ normal(0.0, 25);
b7[1] ~ normal(0.0, 25);
Walpha ~ inv_gamma(0.01,0.01);
W1 ~ inv_gamma(0.01,0.01);
W2 ~ inv_gamma(0.01,0.01);
W3 ~ inv_gamma(0.01,0.01);
W4 ~ inv_gamma(0.01,0.01);
W5 ~ inv_gamma(0.01,0.01);
W6 ~ inv_gamma(0.01,0.01);
W7 ~ inv_gamma(0.01,0.01);
alpha[2:T] ~ normal(alpha[1:(T-1)], Walpha);
b1[2:T] ~ normal(b1[1:(T-1)], W1);
b2[2:T] ~ normal(b2[1:(T-1)], W2);
b3[2:T] ~ normal(b3[1:(T-1)], W3);
b4[2:T] ~ normal(b4[1:(T-1)], W4);
b5[2:T] ~ normal(b5[1:(T-1)], W5);
b6[2:T] ~ normal(b6[1:(T-1)], W6);
b7[2:T] ~ normal(b7[1:(T-1)], W7);
for (t in 1:T){
for (n in 1:N){
y[n,t] ~ bernoulli_logit(alpha[t] + b1[t]*x1[n] + b2[t]*x2[n]+ b3[t]*x3[n]+ b4[t]*x4[n]+ b5[t]*x5[n]+ b6[t]*x6[n]+ b7[t]*x7[n]);
}
}
}
```