Hi Bob,
I am using cmdstanR 0.5.3 (CmdStan 2.30.1).
The full model is
functions {
vector sho(real t,
vector y,
real theta) {
vector[2] dydt;
dydt[1] = y[2];
dydt[2] = -y[1] - theta * y[2];
return dydt;
}
}
data {
int<lower=1> T;
array[T] vector[2] y;
real t0;
array[T] real ts;
}
parameters {
vector[2] y0;
vector<lower=0>[2] sigma;
real theta;
}
model {
vector[2] mu[T] = ode_rk45(sho, y0, t0, ts, theta);
sigma ~ normal(0, 2.5);
theta ~ std_normal();
y0 ~ std_normal();
for (t in 1:T) {
y[t] ~ normal(mu[t], sigma);
}
}
When I compile the example there is a warning:
Compiling Stan program…
Warning in ‘/var/folders/9x/86f88pr155s4lsxpdt623gx57n0ss1/T/Rtmpim4LXT/model-61687d701e5d.stan’, line 23, column 2: Declaration
of arrays by placing brackets after a variable name is deprecated and
will be removed in Stan 2.32.0. Instead use the array keyword before the
type. This can be changed automatically using the auto-format flag to
stanc
This is caused by the vector[2] mu[T] = ode_rk45(sho, y0, t0, ts, theta);
When I replace this with
array[T] vector [2] mu = ode_rk45(sho, y0, t0, ts, theta);
The warning is gone. This is good.
Now, if I have a number of replicates (n_rep), and I want to fit the ODE model to each of them. I attempted to do the model below:
functions {
vector sho(real t,
vector y,
real theta) {
vector[2] dydt;
dydt[1] = y[2];
dydt[2] = -y[1] - theta * y[2];
return dydt;
}
}
data {
int<lower=1> T;
array[T] vector[2] y;
real t0;
array[T] real ts;
int<lower=0> n_rep;
}
parameters {
vector[2] y0;
vector<lower=0>[2] sigma;
real theta;
}
model {
array[T,n_rep] vector[2] mu = ode_rk45(sho, y0, t0, ts, theta);
sigma ~ normal(0, 2.5);
theta ~ std_normal();
y0 ~ std_normal();
for (t in 1:T) {
y[t] ~ normal(mu[t], sigma);
}
}
But I got an error message
Semantic error in ‘/var/folders/9x/86f88pr155s4lsxpdt623gx57n0ss1/T/Rtmpim4LXT/model-61682954e7c1.stan’, line 24, column 2 to column 65:
22: }
23: model {
24: array[T,n_rep] vector[2] mu = ode_rk45(sho, y0, t0, ts, theta);
^
25: sigma ~ normal(0, 2.5);
26: theta ~ std_normal();
Ill-typed arguments supplied to assignment operator =: lhs has type array[,] vector and rhs has type array vector
I couldn’t figure out myself and I hope you could provide me some hint.