Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR IN STAN CODE #1458

Closed
abqozeem opened this issue Oct 27, 2024 · 1 comment
Closed

ERROR IN STAN CODE #1458

abqozeem opened this issue Oct 27, 2024 · 1 comment

Comments

@abqozeem
Copy link

abqozeem commented Oct 27, 2024

I have the below code:

functions {
  real[] RPubSIR(real t, real[] y, real[] theta, 
             real[] x_r, int[] x_i) {

      real S = y[1];
      real I = y[2];
      real R = y[3];
      real N = x_i[1];
      
      real beta = theta[1];
      real sigma = theta[2];
      
      #TODO: fill it in.
      real dS_dt = -beta * S * I / N;
      real dI_dt = beta * S * I / N - sigma * I;
      real dR_dt = sigma * I;

      
      return {dS_dt, dI_dt, dR_dt};
  }
}

data {
  int<lower=1> n_days;
  real y0[3];
  real t0;
  real ts[n_days];
  int N;
  int cases[n_days];
}

transformed data {
  real x_r[0];
  int x_i[1] = {N};
}

parameters {
  real<lower=0> sigma;
  real<lower=0> beta;
  real<lower=0> phi_inv;
}

transformed parameters{
  real y[n_days, 3];
  real phi = 1. / phi_inv;
  {
    real theta[2]; // model parameters
    theta[1] = beta;
    theta[2] = sigma;

    y = integrate_ode_rk45(RPubSIR, y0, t0, ts, theta, x_r, x_i);
  }
}

model {
  //priors
  beta ~ normal(2, 1); //truncated at 0
  sigma ~ normal(0.4, 0.25); //truncated at 0
  phi_inv ~ exponential(5);
  
  //likelihood
  //col(matrix x, int n) - The n-th column of matrix x. Here the number of infected people
  cases ~ neg_binomial_2(col(to_matrix(y), 2), phi);
}

generated quantities {
  real recovery_time = 1 / sigma;
  real pred_cases[n_days];
  pred_cases = neg_binomial_2_rng(col(to_matrix(y), 2) + 1e-5, phi);
}

and when I tried to save it and further to the Rscript to compile, an error popped up and is:

> rstan:::rstudio_stanc("RPubSIR.stan")
Error in stanc(filename, allow_undefined = TRUE) : 0
Internal compiler error:
TypeError: not a function

Kindly respond by helping to debug.

@WardBrian
Copy link
Member

@abqozeem this sounds like a duplicate of #1446

We've seen some reports suggesting this goes away if you can install the V8 package

@andrjohns -- another one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants