Per the Stan reference manual, (6.10, indexing), a single subscript on a vector should result in a real.
But I get an error from the following function:
functions {
real ncspline(real x, vector[] beta, vector[] knots);
real ncspline(real x, vector[] beta, vector[] knots) {
// Inputs: x = a point at which to evaluate the spline
// beta = coefficients of each spline basis
// knots = the evenly spaced knots of the spline basis
// (only the first 2 knots are used: the code assumes the caller
// is telling the truth)
real yhat; // the predicted value
int k; // number of knots
real delta; // knot spacing
real x2; // temporary variables
real z ;
real b ;
k = size(beta); // beta is the same length as knots
x2 = (x- knots[1])/(knots[2] - knots[1]);
....
The compiler complains about the x2= line above, with “no matches for vector/ vector”. The phrase “delta = knots[2] - knots[1];” fails as well, with a message that the rhs is a vector.
How do I get a simple scalar out of a vector?
Second note: I found, by chance, that I I have matrix[N,K] x, then x[, 3], used as an argument to a function, is treated as a vector. This makes perfect sense, but is not mentioned as a legal use in the reference manual (that I could see).
Terry T.