I am trying to model the given equation using pystan

For a given cluster, there are *n* states.

Values of *alpha* and * beta* are different for each state within a cluster.

I have had success in modelling this differently, In my case,

I am assuming *alpha* and * beta* are same for each state within a cluster.

Model code that i came up with goes as,

```
"""
data {
int<lower=1> N; // number of states
int<lower=1> M; // number of months
row_vector[N] X1[M];
row_vector[N] X2[M];
row_vector[N] X3[M];
row_vector[N] X4[M];
row_vector[N] X5[M];
row_vector[N] X6[M];
row_vector[N] D[M];
}
parameters {
real alpha;
vector[6] beta;
vector[6] mu_beta;
cov_matrix[6] sigma_beta;
cov_matrix[N] sigma_err;
}
transformed parameters {
row_vector[N] D_hat[M];
for(i in 1:M) {
D_hat[i] = alpha + X1[i] * beta[1] + X2[i] * beta[2] + X3[i] * beta[3] + X4[i] * beta[4] + X5[i] * beta[5] + X6[i] * beta[6];
}
}
model {
alpha ~ normal(0, 100);
mu_beta ~ multi_normal(rep_vector(0, 6), diag_matrix(rep_vector(100,6)));
sigma_beta ~ inv_wishart(7, diag_matrix(rep_vector(0.0001,6)));
beta ~ multi_normal(mu_beta, sigma_beta);
sigma_err ~ inv_wishart(N+1, diag_matrix(rep_vector(0.0001,N)));
D ~ multi_normal(D_hat, sigma_err);
}
"""
```

Now, I want to model it with states have different values for *alpha* and * beta* , but the representation for

*gets me all confused, for this case.*

**D_hat**Can anyone assist me or provide some pointers that I can look into?

I understand that parameters block will be changed as follows, but representation for *D_hat* leaves me clueless.

```
parameters {
vector[N] alpha;
vector[6] beta[N];
vector[6] mu_beta;
cov_matrix[6] sigma_beta;
cov_matrix[N] sigma_err;
}
```

And, Is there a way I can print values of * D_hat[i]* after each iteration???