Given the increasing complexity of my model, I’m trying to condense the code using vectors and matrices. As a result though I’m running into some base type mismatch problems that I can’t solve.
Say you have the following code as part of your model, I’ve tried to strip out unnecessary info:
data {
int<lower=1> N; //data points
real Y[N]; //dependent variable
int Nx; //number of predictors
matrix[N,Nx] XVar; //matrix of explanatory variable values
}
parameters {
vector[Nx] beta_mu; //Mu parameters for Xvar, assume no intercept
}
model {
to_vector(beta_mu) ~ normal(0,1); //priors
//linear predictor
real mu[N];
for (i in 1:N) {
mu[i] = beta_mu * XVar[i,];
}
}
The problem occurs during the likelihood where I get a “Base type mismatch in assignment”, as it complains that ‘mu’ is not a matrix (which is understandable). Is there a way to succinctly sum out the beta_mu * XVar[i,]
expression without having to index out every coefficient and the corresponding matrix column?