# [HELP] can I rep the parameter vector to matrix

I want to do this time-varying ordered logit model or state space model

model like this :
Y^* = \beta_t X_{it} + \epsilon_{it}
\beta_t = \beta_{t-1} + w_t
\epsilon_{it} is a logistic fuction and Y^* is a latent variable. X_{it} and \beta_{t} also the vector
and I want to add a constant coefficient like this :
Y^* = \beta_t X_{it} + \lambda Z_{it}+\epsilon_{it}

Is there exist the identification problem ?
And how can I wirte this Z_{it} in the matrix to do multivariate regression to speed up the running which I means the w_t can be multivariate prior? because I use non-centered parameter in my code.

this is my original stan code

functions {
real partial_sum(
int[] slice_y,
int start, int end,
matrix x1,matrix x2, vector[] thresh,
vector beta1, vector[] beta2, int[] g
)
{
real lp = 0;
for(i in start:end)
lp += ordered_logistic_lpmf(slice_y[i-start+1] |x1[i]*beta1+x2[i]*beta2[g[i]]  , thresh[g[i]]);
return lp;
}
real induced_dirichlet_lpdf(vector c, vector alpha, real phi) {
int K = num_elements(c) + 1;
vector[K - 1] sigma = inv_logit(phi - c);
vector[K] p;
matrix[K, K] J = rep_matrix(0, K, K);
// Induced ordinal probabilities
p[1] = 1 - sigma[1];
for (k in 2:(K - 1))
p[k] = sigma[k - 1] - sigma[k];
p[K] = sigma[K - 1];
// Baseline column of Jacobian
for (k in 1:K) J[k, 1] = 1;
// Diagonal entries of Jacobian
for (k in 2:K) {
real rho = sigma[k - 1] * (1 - sigma[k - 1]);
J[k, k] = - rho;
J[k - 1, k] = rho;
}
return   dirichlet_lpdf(p | alpha)
+ log_determinant(J);
}
}

data {
int<lower=1> N;             // Number of observations
int<lower=1> K;             // Number of ordinal categories
int<lower=1> D;
int<lower=1> DN;
array[N] int<lower=1, upper=K> y; // Observed ordinals
matrix[N,D-DN] x1;
matrix[N,DN] x2;
int g[N];
int<lower=1> P;        //P different threshold
}
parameters {
vector[D-DN] beta1;
vector[DN] beta21;
real<lower=0> sigma;

vector<lower=0>[DN] Omega;
ordered[K - 1] thresh[P];
vector[DN] yita[P-1];

}

transformed parameters{
vector[DN] beta2[P];

beta2[1] = beta21;
for (i in 2: P){
beta2[i] = beta2[i-1] + Omega.*yita[i-1];
}
}
model {

beta1~ normal(0,10);
beta21 ~normal(0,10);
thresh[1] ~ induced_dirichlet(rep_vector(1, K), 0);
sigma ~ normal(0,1);
Omega ~ normal(0,1);

for (i in 1: (P-1)){
(thresh[i+1]-thresh[i])~ normal(0,sigma);

yita[i] ~ normal(0,1);
}
target += reduce_sum(partial_sum, y, 1, x1,x2, thresh, beta1,beta2, g);
}



Are you asking if the model is identified as written? There seems to be a lot more going on in the code than in the math you wrote out, and I can’t tell what the model’s trying to do.

My general advice is to get it working with small data and without the parallelization and then try to parallelize.

Have you tried simulating data from known parameters then trying to recover those parameters?

Did you mean to make beta[t] a deterministic function of beta[t-1] that just drifts? If so, just define that as transformed data.

I couldn’t tell what you were asking here. Did you want to do something like give the rows or columns of this matrix a multivariate normal distribution? If so, you need to convert to an array of matrices, and then it can be vectorized. The reshaping is super fast in Stan even if it’s a loop.

I’m not sure what’s going on in this model with the Dirichlet and log determinant. It looks like the Jacobian matrix is triangular, so a direct computation of the log determinant as the log sum of diagonal elements is probably in order.