# Ode\_rk45 does not recognise the function's name

**URL:** <https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770>\
**Category:** Modeling\
**Created:** [June 9, 2022, 1:43pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770 "2022-06-09T13:43:13Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![irenegfsr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/irenegfsr/32/15802_2.png) [@irenegfsr](https://discourse.mc-stan.org/u/irenegfsr)\
**Post date:** [June 9, 2022, 1:43pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/1 "2022-06-09T13:43:13Z")

</div>

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.

 ![ode_rk45](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/8/8681d97e47b202f755f0cbce1759efb2388e43df.png)

```nohighlight
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;}
    else{
      yhat = ode_rk45(model3, zinitials, t0, eval_time, pAB, uABt, uASC);
      yhatmu[j,2] = yhat[1,1] - pow(sigma, 2.0)/2;
    }  
  //likelihood
    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);
  }
}

```

---

<div class="post-metadata">

**Author:** ![jsocolar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsocolar/32/2486_2.png) [@jsocolar](https://discourse.mc-stan.org/u/jsocolar)\
**Post date:** [June 9, 2022, 2:27pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/2 "2022-06-09T14:27:08Z")

</div>

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`?)

---

<div class="post-metadata">

**Author:** ![irenegfsr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/irenegfsr/32/15802_2.png) [@irenegfsr](https://discourse.mc-stan.org/u/irenegfsr)\
**Post date:** [June 9, 2022, 2:31pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/3 "2022-06-09T14:31:22Z")

</div>

Hi,

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.

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [June 9, 2022, 11:44pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/4 "2022-06-09T23:44:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jsocolar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsocolar/32/2486_2.png) [@jsocolar](https://discourse.mc-stan.org/u/jsocolar)\
**Post date:** [June 10, 2022, 12:52am UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/5 "2022-06-10T00:52:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![irenegfsr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/irenegfsr/32/15802_2.png) [@irenegfsr](https://discourse.mc-stan.org/u/irenegfsr)\
**Post date:** [June 13, 2022, 3:41pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/6 "2022-06-13T15:41:45Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [June 13, 2022, 3:51pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/7 "2022-06-13T15:51:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![irenegfsr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/irenegfsr/32/15802_2.png) [@irenegfsr](https://discourse.mc-stan.org/u/irenegfsr)\
**Post date:** [June 13, 2022, 3:53pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/8 "2022-06-13T15:53:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [June 13, 2022, 5:04pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/9 "2022-06-13T17:04:14Z")

</div>

was the stan code run through rstan or cmdstanr?

---

<div class="post-metadata">

**Author:** ![irenegfsr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/irenegfsr/32/15802_2.png) [@irenegfsr](https://discourse.mc-stan.org/u/irenegfsr)\
**Post date:** [June 15, 2022, 5:20pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/10 "2022-06-15T17:20:27Z")

</div>

Hi,

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.

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [June 15, 2022, 5:27pm UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/11 "2022-06-15T17:27:37Z")

</div>

You can follow [cmdstanr vignette](https://mc-stan.org/cmdstanr/articles/cmdstanr.html) to run your code.

---

<div class="post-metadata">

**Author:** ![irenegfsr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/irenegfsr/32/15802_2.png) [@irenegfsr](https://discourse.mc-stan.org/u/irenegfsr)\
**Post date:** [June 16, 2022, 8:42am UTC](https://discourse.mc-stan.org/t/ode-rk45-does-not-recognise-the-functions-name/27770/12 "2022-06-16T08:42:26Z")

</div>

Hi,

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?

 ![ode_rk](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/3/3d795f0abb29c0d798dea10f48cd33278d8b3688.png)
