In my Stan code, I want to add an ICAR-term (phi) to the following covariate model:
// covariate models with logit link
vector[total_surveys] logit_p = (X_p * beta_p) + phi[ii_sampled];
However the dim(X_p)
= (1900, 3)
and dim(beta_p)
= 3
Thus dim(X_p * beta_p
= 1900
While the dim(phi[ii_sampled])
is 95
Therefore, I would like to do:
phi_p <- rep(phi[ii_sampled], each = 20)
In essence, my problem comes down to doing (example with different dimensions):
phi <- c(1.2, -0.5, 2.1, -0.7)
phi_p <- rep(phi, each = 3)
phi_p
>(1.2, 1.2, 1.2, -0.5, -0.5, -0.5, 2.1, 2.1, 2.1, -0.7, -0.7, -0.7)
in Stan
Unfortunately, the rep()
function is not available in Stan.
You would have to do a loop instead.
What would such a loop look like?