Hi,
I have a (hopefully) simple coding question. According to the manual, it is more efficient to declare a matrix as a vector or row_vector.
In my data{} block, I have the following:
data {
…
int N; //number of observations
int D; //number of attributes, excluding the intercept
row_vector[D] A[N]; // A is a NxD matrix of attributes, excluding the intercept. I declare it as a row_vector here.
}
Now I want to add a column of ones to A for the intercept.
transformed data {
int DD;
vector[N] ones;
row_vector[DD] X[N]; // dim(X[i]) = 1xDD
DD=D+1;
ones = rep_vector(1,N);
X = append_col(ones, A);
}
But the last line, X = append_col(ones, A), gives me an error. I cannot append a vector to a row_vector. Instead, the following for-loop seems to work:
for (n in 1:N)
X[n] = append_col(1, A[n]);
But is it possible to avoid the for-loop?