I am struggling with this rather simple statement in my STAN code. Is there a way to vectorize a real-valued parameter? Normal(mu,sd) returns a real-valued array. However, as you can see I have defined x to be a vector[n_obs]. What is puzzling me is the fact that in the statement

X=append_col(ones,x);

it does treat x to be a vector and hence allows me to use append_col. However, in the statement,

P=(x’)*x

it throws me an error of type mismatch, where the base type is a matrix and the right-hand side is a real. Can you guys help me try to understand how the same value is treated differently in two subsequent statements and any suggestions on how to avoid this?

The STAN code is attached here and I realize many of the statements in the transformed data block are redundant and be clubbed together, but I have broken down the block as such since many several people are working on this one project and have varying knowledge of STAN. Thank you in advance.

```
> transformed data{
vector[n_obs] x;
int r=0;
matrix [n_obs,r] phi;
vector[r] zeros;
vector[n_obs] ones;
matrix [n_obs,n_cov] X;
matrix [n_obs,n_obs] G;
matrix [n_obs,n_obs] P;
matrix [n_obs,n_obs] M;
matrix [n_obs,n_obs] Qt;
matrix [r,r] C;
matrix [r,r] D;
matrix [r,r] Z;
matrix [r,r] A;
matrix [n_obs,1] x1;
matrix[r, r] L = cholesky_decompose(A);
vector[n_obs] values;
vector [r] V1;
vector[r] delta;
zeros = rep_vector(0, r);
delta = rep_vector(0, r);
ones = rep_vector(0, n_obs);
X=append_col(ones,x);
P=(x')*x;
G=(I-x*inverse(P)*(x'))*W*(I-x*inverse(P)*(x'));
values = eigenvalues_sym(G);
M=eigenvectors_sym(G);
for(i in 1:n_obs)
{
if(values[i]>0)
{r=r+1;}
}
phi=block(M,1,1,n_obs,r);
Qt=I-0.1571172*W;
C=quad_form(Qt,phi);
V1=eigenvalues_sym(C);
for(i in 1:r)
{
if(V1[i]>0) delta[i]=V1[i];
else delta[i]=0;
}
D=diag_matrix(delta);
Z=eigenvectors_sym(C);
A=quad_form(D,Z);
}
parameters {
vector[n_cov] beta;
vector[r] v;
}
transformed parameters{
vector[n_obs] eta;
vector[n_obs] F;
F=X*beta;
eta = phi*v;
}
model
{
x ~ normal(mu_X,Sd_X);
y ~ poisson_log(F+eta);
beta~ normal(0,10);
v ~ multi_normal_cholesky(zeros, L);
}
```