Ode_rk45 does not recognise the function's name

Hi all,

After running this piece of code, I get the following error message (which says that it does not recognize the name of the function). However, this was running perfectly fine some months ago. Any idea why? I am working with R version 4.1.3.

functions {
  vector model3(real t, vector y, real pAB, real uAB, real uASC) {
    vector[2] dydt;  
    dydt[1] = pAB*y[2]-uAB*y[1];
    dydt[2] = -uASC*y[2];
   return dydt;
data {
  int <lower=1> nobs;
  real t0;
  vector[2] y0[nobs];
  real ts[nobs];
  int <lower=1> indivs;
  real <lower=0> antib[nobs];
  int <lower=1> subj[nobs];
parameters {
  real pAB0;
  real <lower=0, upper=1> uAB;
  real uASC0;
  real AB0;
  real ASC0;
  real logsigma;
  real logsigmapAB;
  real logsigmauASC;
  real logsigmaAB0;
  real logsigmaASC0;
  real rpAB[nobs];
  real ruASC[nobs];
  real rAB0[nobs];
  real rASC0[nobs];
model {
  vector[2] yhat[nobs];
  vector[2] yhatmu[nobs];
  real eval_time[1];
  real sigma = exp(logsigma);
  real sigmapAB = exp(logsigmapAB);
  real sigmauASC = exp(logsigmauASC);
  real sigmaAB0 = exp(logsigmaAB0);
  real sigmaASC0 = exp(logsigmaASC0);
  //prior distributions
  pAB0 ~ normal(0, 2.5);
  uASC0 ~ normal(0, 2.5);
  uAB ~ normal(0, 2.5);
  AB0 ~ uniform(5, 10);
  ASC0 ~ uniform(2,4);
  logsigmapAB ~ normal(0, 2.5);
  logsigmauASC ~ normal(0, 2.5);
  logsigmaAB0 ~ normal(0, 2.5);
  logsigmaASC0 ~ normal(0, 2.5);
  logsigma ~ normal(0, 2.5);
  for (j in 1:nobs) {
    real pAB = exp(pAB0)*exp(rpAB[subj[j]]);
    real uABt = uAB;
    real uASC = exp(uASC0)*exp(ruASC[subj[j]]);
    vector[2] zinitials;
    zinitials[1] = exp(AB0)*exp(rAB0[subj[j]]);
    //are we sure this is not yielding to negative values? is it hierarchical?
    zinitials[2] = exp(ASC0)*exp(rASC0[subj[j]]);
    // where mu of the r.e. is 0 or -sigmapAB/2
    rpAB[subj[j]] ~ normal(-sigmapAB/2, sigmapAB);
    ruASC[subj[j]] ~ normal(-sigmauASC/2, sigmauASC);
    rAB0[subj[j]] ~ normal(-sigmaAB0/2, sigmaAB0);
    rASC0[subj[j]] ~ normal(-sigmaASC0/2, sigmaASC0);
    eval_time[1] = ts[j];
    if (eval_time[1] == 0){
      yhatmu[j,1] = zinitials[1] - pow(sigma, 2.0)/2;
      yhatmu[j,2] = zinitials[2] - pow(sigma, 2.0)/2;}
      yhat = ode_rk45(model3, zinitials, t0, eval_time, pAB, uABt, uASC);
      yhatmu[j,2] = yhat[1,1] - pow(sigma, 2.0)/2;
    antib[j] ~ lognormal(yhatmu[j,2], sigma); 
generated quantities {
  real z_pred[nobs];
  real sigma2 = exp(logsigma);
  for (t in 1:nobs){
    z_pred[t] = lognormal_rng(antib[t], sigma2);

This compiles fine for me using both cmdstan 2.28.1 and cmdstan 2.29.2 via cmdstanr::cmdstan_model. Thus, I suspect there might be a problem with your stan version or some other aspect of your setup. Can you provide information about:

  1. What interface you are using (rstan or cmdstanr)
  2. What version of stan you are using (output of rstan::stan_version() or cmdstanr::cmdstan_version())
  3. What code you are actually running to produce this error (e.g. is error seen when you try to run cmdstanr::cmdstan_model?)
1 Like


This happens when I just compile the stan file. I have realized that I’ve only installed the package ‘rstan’ but not ‘cmstan’. Thus, I will be using stan_model; but the error did not come from there. I am currently running something that worked because I defined a function with a real model and then called integrate_ode_rk45 and this seems to compile.

Your rstan doesn’t know the “new” syntax. You’ll have to switch to cmdstanr so you can use later versions of Stan.

1 Like

Or the experimental branch of rstan, I think, would give access to this syntax without requiring you to modify your R code.


I have just installed cmdstanr but this link:
install.packages(“cmdstanr”, repos = c(“Repository for distributing (some) stan-dev R packages | r-packages”, getOption(“repos”)))
However, this issue with the ode_rk45 is still happening. Any other suggestions why this could be?

Could you post the script used to run the model? thx

I did not do any changes to the last script in Stan that I posted, except to install the package cmdstanr in R. The Stan code still does not recognise the function inside the ode_rk45

was the stan code run through rstan or cmdstanr?

1 Like


The code was run through rstan I believe. Although, I have tried to restart the session and install both rstan and cmdstanr, and then run my stan file again. However, I’ve gotten the same problem.

You can follow cmdstanr vignette to run your code.


I get the following error message as attached here.
I was able to run this Stan file with the run bottom on the top earlier without a problem. I do not see the issue now in the code, and it is not being able to recognize the name of the function. Why could this be?