Error in integrate_ode_bdf

I’m trying to build a very simple pharmacometric model. Shown below is some data.

I am trying to use the integrate_ode_bdf function to integrate the differential equation for my model. When I do so, I keep getting the following error: Exception: integrate_ode_bdf: times is not a valid ordered vector..

I’ve tried sorting the Time column before passing it into Stan, but the error persists.

Here is my model:

#Courtesy of Michael Betancourt
functions {
  real[] one_comp_lin_elim_abs(real t,
                               real[] y,
                               real[] theta,
                               real[] x_r,
                               int[] x_i) {
    real dydt[1];
    real k_a = theta[1]; // Dosing rate in 1/day
    real k = theta[2];   // Elimination rate in 1/day
    real D = x_r[1];
    real V = x_r[2];
    real dose = 0;
    real elim = k * y[1];

    if (t > 0)
      dose = exp(- k_a * t) * D * k_a / V;

    dydt[1] = dose - elim;

    return dydt;
  }
}

data {
  real t0;    // Initial time in days;
  real C0[1]; // Initial concentration at t0 in mg/L

  real D;   // Total dosage in mg
  //real V;   // Compartment volume in L

  int<lower=1> N_t;
  real times[N_t];   // Measurement times in days

  // Measured concentrations in effect compartment in mg/L
  real C_hat[N_t];
}

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

parameters {
  real<lower=0> k_a; // Dosing rate in 1/day
  real<lower=0> k;   // Elimination rate in 1/day
  real<lower=0> sigma;
  real<lower=0> V;
}

transformed parameters {
  real C[N_t, 1];
  {
    real theta[2] = {k_a, k};
    C = integrate_ode_bdf(one_comp_lin_elim_abs, C0, t0, times, theta, x_r, x_i);
  }
}

model {
  // Priors
  k_a ~ cauchy(0, 1);
  k ~ cauchy(0, 1);
  sigma ~ cauchy(0, 1);
  V ~ cauchy(0,1);

  // Likelihood
  for (n in 1:N_t)
    C_hat[n] ~ lognormal(log(C[n, 1]), sigma);
}

generated quantities {
  real C_ppc[N_t];
  for (n in 1:N_t)
    C_ppc[n] = lognormal_rng(log(C[n, 1]), sigma);
}

And here is how I set up my data to be passed to the model

t0 = c(0)
C0 = array(c(0), dim = 1)
D = 2.5
times = apixaban.data$Time
N_t = length(apixaban.data$Time)
C_hat = apixaban.data$Concentration

stan_rdump(c("t0", "C0", "D", "times", "N_t", "C_hat"), file="apixaban_model.data.R")
input_data <- read_rdump("apixaban_model.data.R")

#Model is in a Stan cell in an R Notebook
rstan::sampling(apixaban.model,data = input_data)

Data shown below

apixiban.data = tibble::tribble(
     ~Time, ~Subject, ~Concentration,    ~Group,     ~Sex, ~Sex_ID, ~Group_ID, ~Subejct_ID,
       0.5,       1L,            0.7,   "NAFLD",   "Male",       1,         0,          1L,
       0.5,       3L,            8.2,   "NAFLD", "Female",       0,         0,          2L,
       0.5,       4L,           13.3,   "NAFLD", "Female",       0,         0,          3L,
       0.5,       5L,           15.6,   "NAFLD", "Female",       0,         0,          4L,
       0.5,       6L,          102.1,   "NAFLD", "Female",       0,         0,          5L,
       0.5,       7L,           33.7, "Control", "Female",       0,         1,          6L,
       0.5,       8L,           37.4, "Control",   "Male",       1,         1,          7L,
       0.5,       9L,           26.3, "Control", "Female",       0,         1,          8L,
       0.5,      10L,           82.3, "Control", "Female",       0,         1,          9L,
       0.5,      11L,            6.6,   "NAFLD",   "Male",       1,         0,         10L,
       0.5,      12L,           75.2,   "NAFLD", "Female",       0,         0,         11L,
       0.5,      13L,            6.7, "Control", "Female",       0,         1,         12L,
       0.5,      14L,            4.3,   "NAFLD", "Female",       0,         0,         13L,
       0.5,      15L,           10.6,   "NAFLD",   "Male",       1,         0,         14L,
       0.5,      16L,            4.6,   "NAFLD",   "Male",       1,         0,         15L,
       0.5,      17L,           15.9,   "NAFLD", "Female",       0,         0,         16L,
       0.5,      18L,           17.9, "Control", "Female",       0,         1,         17L,
       0.5,      19L,            3.9,   "NAFLD", "Female",       0,         0,         18L,
       0.5,      20L,            7.1,   "NAFLD", "Female",       0,         0,         19L,
       0.5,      21L,           28.2,   "NAFLD",   "Male",       1,         0,         20L,
       0.5,      22L,           21.1, "Control",   "Male",       1,         1,         21L,
       0.5,      23L,             18, "Control", "Female",       0,         1,         22L,
       0.5,      24L,           13.8,   "NAFLD",   "Male",       1,         0,         23L,
       0.5,      25L,            5.2,   "NAFLD", "Female",       0,         0,         24L,
       0.5,      26L,           37.9,   "NAFLD", "Female",       0,         0,         25L,
       0.5,      27L,            7.4,   "NAFLD",   "Male",       1,         0,         26L,
       0.5,      28L,           15.6, "Control", "Female",       0,         1,         27L,
       0.5,      29L,           24.1, "Control", "Female",       0,         1,         28L,
       0.5,      30L,           19.4, "Control", "Female",       0,         1,         29L,
       0.5,      31L,           31.1, "Control", "Female",       0,         1,         30L,
       0.5,      32L,           14.3,   "NAFLD",   "Male",       1,         0,         31L,
       0.5,      33L,            4.9,   "NAFLD",   "Male",       1,         0,         32L,
       0.5,      34L,             10,   "NAFLD",   "Male",       1,         0,         33L,
       0.5,      35L,            2.1,   "NAFLD", "Female",       0,         0,         34L,
       0.5,      36L,           12.4,   "NAFLD", "Female",       0,         0,         35L,
       0.5,      37L,            1.7,   "NAFLD",   "Male",       1,         0,         36L,
         1,       1L,           32.7,   "NAFLD",   "Male",       1,         0,          1L,
         1,       3L,           45.4,   "NAFLD", "Female",       0,         0,          2L,
         1,       4L,          117.9,   "NAFLD", "Female",       0,         0,          3L,
         1,       5L,           97.8,   "NAFLD", "Female",       0,         0,          4L,
         1,       6L,          165.8,   "NAFLD", "Female",       0,         0,          5L,
         1,       7L,           84.5, "Control", "Female",       0,         1,          6L,
         1,       8L,           74.4, "Control",   "Male",       1,         1,          7L,
         1,       9L,           65.5, "Control", "Female",       0,         1,          8L,
         1,      10L,          103.4, "Control", "Female",       0,         1,          9L,
         1,      11L,            7.7,   "NAFLD",   "Male",       1,         0,         10L,
         1,      12L,           76.1,   "NAFLD", "Female",       0,         0,         11L,
         1,      13L,           38.4, "Control", "Female",       0,         1,         12L,
         1,      14L,           34.6,   "NAFLD", "Female",       0,         0,         13L,
         1,      15L,           61.1,   "NAFLD",   "Male",       1,         0,         14L,
         1,      16L,           35.4,   "NAFLD",   "Male",       1,         0,         15L,
         1,      17L,           59.1,   "NAFLD", "Female",       0,         0,         16L,
         1,      18L,           82.2, "Control", "Female",       0,         1,         17L,
         1,      19L,           21.1,   "NAFLD", "Female",       0,         0,         18L,
         1,      20L,           82.3,   "NAFLD", "Female",       0,         0,         19L,
         1,      21L,           66.1,   "NAFLD",   "Male",       1,         0,         20L,
         1,      22L,           49.9, "Control",   "Male",       1,         1,         21L,
         1,      23L,           65.2, "Control", "Female",       0,         1,         22L,
         1,      24L,             41,   "NAFLD",   "Male",       1,         0,         23L,
         1,      25L,           43.2,   "NAFLD", "Female",       0,         0,         24L,
         1,      26L,          119.9,   "NAFLD", "Female",       0,         0,         25L,
         1,      27L,           18.3,   "NAFLD",   "Male",       1,         0,         26L,
         1,      28L,           39.2, "Control", "Female",       0,         1,         27L,
         1,      29L,           50.5, "Control", "Female",       0,         1,         28L,
         1,      30L,             41, "Control", "Female",       0,         1,         29L,
         1,      31L,           65.9, "Control", "Female",       0,         1,         30L,
         1,      32L,           41.2,   "NAFLD",   "Male",       1,         0,         31L,
         1,      33L,           22.6,   "NAFLD",   "Male",       1,         0,         32L,
         1,      34L,           19.2,   "NAFLD",   "Male",       1,         0,         33L,
         1,      35L,           13.5,   "NAFLD", "Female",       0,         0,         34L,
         1,      36L,           36.3,   "NAFLD", "Female",       0,         0,         35L,
         1,      37L,            9.6,   "NAFLD",   "Male",       1,         0,         36L,
         2,       1L,           79.7,   "NAFLD",   "Male",       1,         0,          1L,
         2,       3L,           69.7,   "NAFLD", "Female",       0,         0,          2L,
         2,       4L,          102.7,   "NAFLD", "Female",       0,         0,          3L,
         2,       5L,            103,   "NAFLD", "Female",       0,         0,          4L,
         2,       6L,          151.5,   "NAFLD", "Female",       0,         0,          5L,
         2,       7L,          117.2, "Control", "Female",       0,         1,          6L,
         2,       8L,           79.9, "Control",   "Male",       1,         1,          7L,
         2,       9L,            162, "Control", "Female",       0,         1,          8L,
         2,      10L,          104.1, "Control", "Female",       0,         1,          9L,
         2,      11L,           12.9,   "NAFLD",   "Male",       1,         0,         10L,
         2,      12L,           77.1,   "NAFLD", "Female",       0,         0,         11L,
         2,      13L,           94.4, "Control", "Female",       0,         1,         12L,
         2,      14L,           83.8,   "NAFLD", "Female",       0,         0,         13L,
         2,      15L,           67.8,   "NAFLD",   "Male",       1,         0,         14L,
         2,      16L,           32.2,   "NAFLD",   "Male",       1,         0,         15L,
         2,      17L,           78.1,   "NAFLD", "Female",       0,         0,         16L,
         2,      18L,          126.5, "Control", "Female",       0,         1,         17L,
         2,      19L,           42.8,   "NAFLD", "Female",       0,         0,         18L,
         2,      20L,           78.7,   "NAFLD", "Female",       0,         0,         19L,
         2,      21L,           64.1,   "NAFLD",   "Male",       1,         0,         20L,
         2,      22L,           46.8, "Control",   "Male",       1,         1,         21L,
         2,      23L,            123, "Control", "Female",       0,         1,         22L,
         2,      24L,           39.8,   "NAFLD",   "Male",       1,         0,         23L,
         2,      25L,           82.2,   "NAFLD", "Female",       0,         0,         24L,
         2,      26L,          125.7,   "NAFLD", "Female",       0,         0,         25L,
         2,      27L,           23.3,   "NAFLD",   "Male",       1,         0,         26L,
         2,      28L,           57.4, "Control", "Female",       0,         1,         27L,
         2,      29L,           86.1, "Control", "Female",       0,         1,         28L,
         2,      30L,           59.7, "Control", "Female",       0,         1,         29L,
         2,      31L,           82.1, "Control", "Female",       0,         1,         30L,
         2,      32L,           60.9,   "NAFLD",   "Male",       1,         0,         31L,
         2,      33L,           55.8,   "NAFLD",   "Male",       1,         0,         32L,
         2,      34L,           22.7,   "NAFLD",   "Male",       1,         0,         33L,
         2,      35L,           37.8,   "NAFLD", "Female",       0,         0,         34L,
         2,      36L,           45.7,   "NAFLD", "Female",       0,         0,         35L,
         2,      37L,           27.1,   "NAFLD",   "Male",       1,         0,         36L,
         4,       1L,           59.2,   "NAFLD",   "Male",       1,         0,          1L,
         4,       3L,           75.6,   "NAFLD", "Female",       0,         0,          2L,
         4,       4L,          201.6,   "NAFLD", "Female",       0,         0,          3L,
         4,       5L,          106.2,   "NAFLD", "Female",       0,         0,          4L,
         4,       6L,            144,   "NAFLD", "Female",       0,         0,          5L,
         4,       7L,           98.6, "Control", "Female",       0,         1,          6L,
         4,       8L,           72.5, "Control",   "Male",       1,         1,          7L,
         4,       9L,          126.3, "Control", "Female",       0,         1,          8L,
         4,      10L,             81, "Control", "Female",       0,         1,          9L,
         4,      11L,           44.8,   "NAFLD",   "Male",       1,         0,         10L,
         4,      12L,           73.5,   "NAFLD", "Female",       0,         0,         11L,
         4,      13L,           83.8, "Control", "Female",       0,         1,         12L,
         4,      14L,           72.8,   "NAFLD", "Female",       0,         0,         13L,
         4,      15L,           67.1,   "NAFLD",   "Male",       1,         0,         14L,
         4,      16L,           27.1,   "NAFLD",   "Male",       1,         0,         15L,
         4,      17L,           75.8,   "NAFLD", "Female",       0,         0,         16L,
         4,      18L,          105.5, "Control", "Female",       0,         1,         17L,
         4,      19L,           66.1,   "NAFLD", "Female",       0,         0,         18L,
         4,      20L,           58.5,   "NAFLD", "Female",       0,         0,         19L,
         4,      21L,           61.6,   "NAFLD",   "Male",       1,         0,         20L,
         4,      22L,           42.5, "Control",   "Male",       1,         1,         21L,
         4,      23L,          105.3, "Control", "Female",       0,         1,         22L,
         4,      24L,           42.1,   "NAFLD",   "Male",       1,         0,         23L,
         4,      25L,           80.3,   "NAFLD", "Female",       0,         0,         24L,
         4,      26L,           98.4,   "NAFLD", "Female",       0,         0,         25L,
         4,      27L,           29.7,   "NAFLD",   "Male",       1,         0,         26L,
         4,      28L,           68.6, "Control", "Female",       0,         1,         27L,
         4,      29L,           91.4, "Control", "Female",       0,         1,         28L,
         4,      30L,           71.3, "Control", "Female",       0,         1,         29L,
         4,      31L,           90.3, "Control", "Female",       0,         1,         30L,
         4,      32L,           58.3,   "NAFLD",   "Male",       1,         0,         31L,
         4,      33L,           41.8,   "NAFLD",   "Male",       1,         0,         32L,
         4,      34L,           32.3,   "NAFLD",   "Male",       1,         0,         33L,
         4,      35L,           79.6,   "NAFLD", "Female",       0,         0,         34L,
         4,      36L,             57,   "NAFLD", "Female",       0,         0,         35L,
         4,      37L,           43.9,   "NAFLD",   "Male",       1,         0,         36L,
         6,       1L,           42.2,   "NAFLD",   "Male",       1,         0,          1L,
         6,       3L,             70,   "NAFLD", "Female",       0,         0,          2L,
         6,       4L,            119,   "NAFLD", "Female",       0,         0,          3L,
         6,       5L,           77.4,   "NAFLD", "Female",       0,         0,          4L,
         6,       6L,           94.2,   "NAFLD", "Female",       0,         0,          5L,
         6,       7L,           65.2, "Control", "Female",       0,         1,          6L,
         6,       8L,           53.6, "Control",   "Male",       1,         1,          7L,
         6,       9L,           93.6, "Control", "Female",       0,         1,          8L,
         6,      10L,           52.4, "Control", "Female",       0,         1,          9L,
         6,      11L,           37.8,   "NAFLD",   "Male",       1,         0,         10L,
         6,      12L,           64.6,   "NAFLD", "Female",       0,         0,         11L,
         6,      13L,           79.3, "Control", "Female",       0,         1,         12L,
         6,      14L,           44.7,   "NAFLD", "Female",       0,         0,         13L,
         6,      15L,           41.7,   "NAFLD",   "Male",       1,         0,         14L,
         6,      16L,           16.7,   "NAFLD",   "Male",       1,         0,         15L,
         6,      17L,           43.1,   "NAFLD", "Female",       0,         0,         16L,
         6,      18L,           65.2, "Control", "Female",       0,         1,         17L,
         6,      19L,           52.5,   "NAFLD", "Female",       0,         0,         18L,
         6,      20L,             39,   "NAFLD", "Female",       0,         0,         19L,
         6,      21L,           43.2,   "NAFLD",   "Male",       1,         0,         20L,
         6,      22L,           32.4, "Control",   "Male",       1,         1,         21L,
         6,      23L,           57.5, "Control", "Female",       0,         1,         22L,
         6,      24L,           31.3,   "NAFLD",   "Male",       1,         0,         23L,
         6,      25L,           56.2,   "NAFLD", "Female",       0,         0,         24L,
         6,      26L,           59.4,   "NAFLD", "Female",       0,         0,         25L,
         6,      27L,           22.4,   "NAFLD",   "Male",       1,         0,         26L,
         6,      28L,           45.5, "Control", "Female",       0,         1,         27L,
         6,      29L,           57.9, "Control", "Female",       0,         1,         28L,
         6,      30L,           55.9, "Control", "Female",       0,         1,         29L,
         6,      31L,           62.3, "Control", "Female",       0,         1,         30L,
         6,      32L,           38.8,   "NAFLD",   "Male",       1,         0,         31L,
         6,      33L,             33,   "NAFLD",   "Male",       1,         0,         32L,
         6,      34L,             30,   "NAFLD",   "Male",       1,         0,         33L,
         6,      35L,           74.1,   "NAFLD", "Female",       0,         0,         34L,
         6,      36L,           42.8,   "NAFLD", "Female",       0,         0,         35L,
         6,      37L,             37,   "NAFLD",   "Male",       1,         0,         36L,
         8,       1L,           23.4,   "NAFLD",   "Male",       1,         0,          1L,
         8,       3L,           40.1,   "NAFLD", "Female",       0,         0,          2L,
         8,       4L,           89.2,   "NAFLD", "Female",       0,         0,          3L,
         8,       5L,           50.1,   "NAFLD", "Female",       0,         0,          4L,
         8,       6L,           62.7,   "NAFLD", "Female",       0,         0,          5L,
         8,       7L,           49.4, "Control", "Female",       0,         1,          6L,
         8,       8L,           37.8, "Control",   "Male",       1,         1,          7L,
         8,       9L,           73.6, "Control", "Female",       0,         1,          8L,
         8,      10L,           35.4, "Control", "Female",       0,         1,          9L,
         8,      11L,           27.5,   "NAFLD",   "Male",       1,         0,         10L,
         8,      12L,           48.2,   "NAFLD", "Female",       0,         0,         11L,
         8,      13L,           57.3, "Control", "Female",       0,         1,         12L,
         8,      14L,           34.1,   "NAFLD", "Female",       0,         0,         13L,
         8,      15L,           31.4,   "NAFLD",   "Male",       1,         0,         14L,
         8,      16L,           12.6,   "NAFLD",   "Male",       1,         0,         15L,
         8,      17L,           34.6,   "NAFLD", "Female",       0,         0,         16L,
         8,      18L,           37.5, "Control", "Female",       0,         1,         17L,
         8,      19L,           47.7,   "NAFLD", "Female",       0,         0,         18L,
         8,      20L,           27.4,   "NAFLD", "Female",       0,         0,         19L,
         8,      21L,           31.1,   "NAFLD",   "Male",       1,         0,         20L,
         8,      22L,           21.6, "Control",   "Male",       1,         1,         21L,
         8,      23L,           35.9, "Control", "Female",       0,         1,         22L,
         8,      24L,           21.1,   "NAFLD",   "Male",       1,         0,         23L,
         8,      25L,           38.2,   "NAFLD", "Female",       0,         0,         24L,
         8,      26L,           42.3,   "NAFLD", "Female",       0,         0,         25L,
         8,      27L,           17.4,   "NAFLD",   "Male",       1,         0,         26L,
         8,      28L,           39.1, "Control", "Female",       0,         1,         27L,
         8,      29L,           43.1, "Control", "Female",       0,         1,         28L,
         8,      30L,           42.9, "Control", "Female",       0,         1,         29L,
         8,      31L,             43, "Control", "Female",       0,         1,         30L,
         8,      32L,           27.7,   "NAFLD",   "Male",       1,         0,         31L,
         8,      33L,           24.2,   "NAFLD",   "Male",       1,         0,         32L,
         8,      34L,           30.5,   "NAFLD",   "Male",       1,         0,         33L,
         8,      35L,             61,   "NAFLD", "Female",       0,         0,         34L,
         8,      36L,           39.4,   "NAFLD", "Female",       0,         0,         35L,
         8,      37L,           27.8,   "NAFLD",   "Male",       1,         0,         36L,
        10,       1L,           16.4,   "NAFLD",   "Male",       1,         0,          1L,
        10,       3L,           26.8,   "NAFLD", "Female",       0,         0,          2L,
        10,       4L,           65.9,   "NAFLD", "Female",       0,         0,          3L,
        10,       5L,             42,   "NAFLD", "Female",       0,         0,          4L,
        10,       6L,           35.6,   "NAFLD", "Female",       0,         0,          5L,
        10,       7L,           37.2, "Control", "Female",       0,         1,          6L,
        10,       8L,           31.1, "Control",   "Male",       1,         1,          7L,
        10,       9L,           62.3, "Control", "Female",       0,         1,          8L,
        10,      10L,           31.4, "Control", "Female",       0,         1,          9L,
        10,      11L,           23.1,   "NAFLD",   "Male",       1,         0,         10L,
        10,      12L,           33.6,   "NAFLD", "Female",       0,         0,         11L,
        10,      13L,           44.1, "Control", "Female",       0,         1,         12L,
        10,      14L,           26.2,   "NAFLD", "Female",       0,         0,         13L,
        10,      15L,           26.1,   "NAFLD",   "Male",       1,         0,         14L,
        10,      16L,            8.9,   "NAFLD",   "Male",       1,         0,         15L,
        10,      17L,             25,   "NAFLD", "Female",       0,         0,         16L,
        10,      18L,           27.8, "Control", "Female",       0,         1,         17L,
        10,      19L,           38.3,   "NAFLD", "Female",       0,         0,         18L,
        10,      20L,           23.1,   "NAFLD", "Female",       0,         0,         19L,
        10,      21L,             29,   "NAFLD",   "Male",       1,         0,         20L,
        10,      22L,           17.4, "Control",   "Male",       1,         1,         21L,
        10,      23L,           22.5, "Control", "Female",       0,         1,         22L,
        10,      24L,             17,   "NAFLD",   "Male",       1,         0,         23L,
        10,      25L,           27.8,   "NAFLD", "Female",       0,         0,         24L,
        10,      26L,             33,   "NAFLD", "Female",       0,         0,         25L,
        10,      27L,           15.8,   "NAFLD",   "Male",       1,         0,         26L,
        10,      28L,           18.3, "Control", "Female",       0,         1,         27L,
        10,      29L,             33, "Control", "Female",       0,         1,         28L,
        10,      30L,           35.5, "Control", "Female",       0,         1,         29L,
        10,      31L,           30.6, "Control", "Female",       0,         1,         30L,
        10,      32L,           19.9,   "NAFLD",   "Male",       1,         0,         31L,
        10,      33L,           20.8,   "NAFLD",   "Male",       1,         0,         32L,
        10,      34L,           25.4,   "NAFLD",   "Male",       1,         0,         33L,
        10,      35L,           50.7,   "NAFLD", "Female",       0,         0,         34L,
        10,      36L,           37.6,   "NAFLD", "Female",       0,         0,         35L,
        10,      37L,           21.8,   "NAFLD",   "Male",       1,         0,         36L,
        12,       1L,           32.9,   "NAFLD",   "Male",       1,         0,          1L,
        12,       3L,             21,   "NAFLD", "Female",       0,         0,          2L,
        12,       4L,           49.6,   "NAFLD", "Female",       0,         0,          3L,
        12,       5L,           33.4,   "NAFLD", "Female",       0,         0,          4L,
        12,       6L,           48.4,   "NAFLD", "Female",       0,         0,          5L,
        12,       7L,           25.4, "Control", "Female",       0,         1,          6L,
        12,       8L,           21.4, "Control",   "Male",       1,         1,          7L,
        12,       9L,           53.9, "Control", "Female",       0,         1,          8L,
        12,      10L,           20.9, "Control", "Female",       0,         1,          9L,
        12,      11L,             16,   "NAFLD",   "Male",       1,         0,         10L,
        12,      12L,           24.9,   "NAFLD", "Female",       0,         0,         11L,
        12,      13L,           32.1, "Control", "Female",       0,         1,         12L,
        12,      14L,           23.7,   "NAFLD", "Female",       0,         0,         13L,
        12,      15L,           16.9,   "NAFLD",   "Male",       1,         0,         14L,
        12,      16L,            4.7,   "NAFLD",   "Male",       1,         0,         15L,
        12,      17L,           19.6,   "NAFLD", "Female",       0,         0,         16L,
        12,      18L,           18.8, "Control", "Female",       0,         1,         17L,
        12,      19L,           24.3,   "NAFLD", "Female",       0,         0,         18L,
        12,      20L,           19.3,   "NAFLD", "Female",       0,         0,         19L,
        12,      21L,           19.6,   "NAFLD",   "Male",       1,         0,         20L,
        12,      22L,           11.2, "Control",   "Male",       1,         1,         21L,
        12,      23L,           13.8, "Control", "Female",       0,         1,         22L,
        12,      24L,            8.7,   "NAFLD",   "Male",       1,         0,         23L,
        12,      25L,             18,   "NAFLD", "Female",       0,         0,         24L,
        12,      26L,           22.5,   "NAFLD", "Female",       0,         0,         25L,
        12,      27L,           10.8,   "NAFLD",   "Male",       1,         0,         26L,
        12,      28L,           12.3, "Control", "Female",       0,         1,         27L,
        12,      29L,             20, "Control", "Female",       0,         1,         28L,
        12,      30L,           23.8, "Control", "Female",       0,         1,         29L,
        12,      31L,             21, "Control", "Female",       0,         1,         30L,
        12,      32L,           14.4,   "NAFLD",   "Male",       1,         0,         31L,
        12,      33L,           13.7,   "NAFLD",   "Male",       1,         0,         32L,
        12,      34L,           17.5,   "NAFLD",   "Male",       1,         0,         33L,
        12,      35L,           41.9,   "NAFLD", "Female",       0,         0,         34L,
        12,      36L,           26.9,   "NAFLD", "Female",       0,         0,         35L,
        12,      37L,           14.6,   "NAFLD",   "Male",       1,         0,         36L
     )

You have to break your data up by subject and then run the ODE solver over each subject’s individual time points. Right now you’re trying to evaluate the ODE system at the same time point multiple times (because you’re aggregating all the subjects together) which is not allowed in the ODE solver.