Error in Simulation using specific obstimes

Hi All,
Please can you help me with this issue.

I am trying to simulate specific obstimes for a 3 subjects with different values of the covariate. But I see that the when I try to simulate specific obstimes it gives out a weird dataframe. When I simulate with obstimes=0:1:72 it works fine.

using Pumas, Plots, StatsPlots, CSV

pk28 = @model begin
  @param begin
    tvcl ∈ RealDomain(lower=0)
    tvv ∈ RealDomain(lower=0)
    Ω ∈ PDiagDomain(2)
    σ_prop ∈ RealDomain(lower=0)
  end

  @random begin
    η ~ MvNormal(Ω)
  end

  @pre begin
    Cl = tvcl * BW^0.636 * exp(η[1])
    V = tvv * BW^1.030 * exp(η[2])
  end

  @covariates BW

  @dynamics begin
    Central'= -(Cl/V)*Central
  end

  @derived begin
    cp = @. Central/V
    dv ~ @. Normal(cp, sqrt(cp^2*σ_prop))
  end
end

par28 = (tvcl = 0.319,
          tvv = 3.076,
          Ω = Diagonal([0.0001,0.0001]),
          σ_prop = 0.0)

ev28_1 = DosageRegimen(25, cmt=1, time=0)
sub28_1 = Subject(id=1, evs=ev28_1, cvs=(BW=0.023,))
ev28_2 = DosageRegimen(500, cmt=1, time=0)
sub28_2 = Subject(id=2, evs=ev28_2, cvs=(BW=0.250,))
ev28_3 = DosageRegimen(100000, cmt=1, time=0)
sub28_3 = Subject(id=3, evs=ev28_3, cvs=(BW=70,))
pop28 = Population([sub28_1,sub28_2,sub28_3])
obs28 = simobs(pk28, pop28, par28, obstimes=[0.167,0.5,2,4,0.167,0.33,0.5,1,2,4,8,12,1,2,4,8,12,24,36,48,72])
df = DataFrame(obs28)
plot(obs28)
obs28_1 = simobs(pk28, pop28, par28, obstimes=0:1:72)
plot(obs28_1)

Output of df:
    66×9 DataFrame
    │ Row │ id     │ time    │ cp         │ dv         │ amt      │ evid │ cmt     │ rate    │ BW      │
    │     │ String │ Float64 │ Float64⍰   │ Float64⍰   │ Float64  │ Int8 │ Int64⍰  │ Float64 │ Float64 │
    ├─────┼────────┼─────────┼────────────┼────────────┼──────────┼──────┼─────────┼─────────┼─────────┤
    │ 1   │ 1      │ 0.0     │ missing    │ missing    │ 25.0     │ 1    │ 1       │ 0.0     │ 0.023   │
    │ 2   │ 1      │ 0.167   │ 359.678    │ 359.678    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 3   │ 1      │ 0.167   │ 308.91     │ 308.91     │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 4   │ 1      │ 0.33    │ 245.816    │ 245.816    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 5   │ 1      │ 0.5     │ 359.678    │ 359.678    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 6   │ 1      │ 0.5     │ 245.816    │ 245.816    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 7   │ 1      │ 1.0     │ 155.656    │ 155.656    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 8   │ 1      │ 1.0     │ 62.4136    │ 62.4136    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 9   │ 1      │ 2.0     │ 333.862    │ 333.862    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 10  │ 1      │ 2.0     │ 155.656    │ 155.656    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 11  │ 1      │ 2.0     │ 10.0347    │ 10.0347    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 12  │ 1      │ 4.0     │ 308.91     │ 308.91     │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 13  │ 1      │ 4.0     │ 155.656    │ 155.656    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 14  │ 1      │ 4.0     │ 10.0347    │ 10.0347    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 15  │ 1      │ 8.0     │ 62.4136    │ 62.4136    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 16  │ 1      │ 8.0     │ 1.61354    │ 1.61354    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 17  │ 1      │ 12.0    │ 62.4136    │ 62.4136    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 18  │ 1      │ 12.0    │ 1.61354    │ 1.61354    │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 19  │ 1      │ 24.0    │ 0.00670855 │ 0.00670855 │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 20  │ 1      │ 36.0    │ 2.77805e-5 │ 2.77805e-5 │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 21  │ 1      │ 48.0    │ 9.24372e-8 │ 9.24372e-8 │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 22  │ 1      │ 72.0    │ 1.55959e-7 │ 1.55959e-7 │ 0.0      │ 0    │ missing │ 0.0     │ 0.023   │
    │ 23  │ 2      │ 0.0     │ missing    │ missing    │ 500.0    │ 1    │ 1       │ 0.0     │ 0.25    │
    │ 24  │ 2      │ 0.167   │ 670.507    │ 670.507    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 25  │ 2      │ 0.167   │ 631.301    │ 631.301    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 26  │ 2      │ 0.33    │ 576.697    │ 576.697    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 27  │ 2      │ 0.5     │ 670.507    │ 670.507    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 28  │ 2      │ 0.5     │ 576.697    │ 576.697    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 29  │ 2      │ 1.0     │ 481.248    │ 481.248    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 30  │ 2      │ 1.0     │ 335.129    │ 335.129    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 31  │ 2      │ 2.0     │ 651.021    │ 651.021    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 32  │ 2      │ 2.0     │ 481.248    │ 481.248    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 33  │ 2      │ 2.0     │ 162.516    │ 162.516    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 34  │ 2      │ 4.0     │ 631.301    │ 631.301    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 35  │ 2      │ 4.0     │ 481.248    │ 481.248    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 36  │ 2      │ 4.0     │ 162.516    │ 162.516    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 37  │ 2      │ 8.0     │ 335.129    │ 335.129    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 38  │ 2      │ 8.0     │ 78.8114    │ 78.8114    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 39  │ 2      │ 12.0    │ 335.129    │ 335.129    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 40  │ 2      │ 12.0    │ 78.8114    │ 78.8114    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 41  │ 2      │ 24.0    │ 8.98757    │ 8.98757    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 42  │ 2      │ 36.0    │ 1.02505    │ 1.02505    │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 43  │ 2      │ 48.0    │ 0.116912   │ 0.116912   │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 44  │ 2      │ 72.0    │ 0.00152144 │ 0.00152144 │ 0.0      │ 0    │ missing │ 0.0     │ 0.25    │
    │ 45  │ 3      │ 0.0     │ missing    │ missing    │ 100000.0 │ 1    │ 1       │ 0.0     │ 70.0    │
    │ 46  │ 3      │ 0.167   │ 400.983    │ 400.983    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 47  │ 3      │ 0.167   │ 398.412    │ 398.412    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 48  │ 3      │ 0.33    │ 394.583    │ 394.583    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 49  │ 3      │ 0.5     │ 400.983    │ 400.983    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 50  │ 3      │ 0.5     │ 394.583    │ 394.583    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 51  │ 3      │ 1.0     │ 387.036    │ 387.036    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 52  │ 3      │ 1.0     │ 372.37     │ 372.37     │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 53  │ 3      │ 2.0     │ 399.723    │ 399.723    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 54  │ 3      │ 2.0     │ 387.036    │ 387.036    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 55  │ 3      │ 2.0     │ 344.685    │ 344.685    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 56  │ 3      │ 4.0     │ 398.412    │ 398.412    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 57  │ 3      │ 4.0     │ 387.036    │ 387.036    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 58  │ 3      │ 4.0     │ 344.685    │ 344.685    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 59  │ 3      │ 8.0     │ 372.37     │ 372.37     │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 60  │ 3      │ 8.0     │ 319.058    │ 319.058    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 61  │ 3      │ 12.0    │ 372.37     │ 372.37     │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 62  │ 3      │ 12.0    │ 319.058    │ 319.058    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 63  │ 3      │ 24.0    │ 253.054    │ 253.054    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 64  │ 3      │ 36.0    │ 200.704    │ 200.704    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 65  │ 3      │ 48.0    │ 159.183    │ 159.183    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │
    │ 66  │ 3      │ 72.0    │ 100.135    │ 100.135    │ 0.0      │ 0    │ missing │ 0.0     │ 70.0    │

@parssh.mehta did you intend your obstimes to be like this?

obstimes=[0.167,0.5,2,4,0.167,0.33,0.5,1,2,4,8,12,1,2,4,8,12,24,36,48,72]

From what I see, the obstimes represent times for each of the 3 subjects you are simulating above, in which case, you have to change the way you pass in times. See below

ev28_1 = DosageRegimen(25, cmt=1, time=0)
sub28_1 = Subject(id=1, evs=ev28_1, cvs=(BW=0.023,), time=[0.167,0.5,2,4])
ev28_2 = DosageRegimen(500, cmt=1, time=0)
sub28_2 = Subject(id=2, evs=ev28_2, cvs=(BW=0.250,), time=[0.167,0.33,0.5,1,2,4,8,12])
ev28_3 = DosageRegimen(100000, cmt=1, time=0)
sub28_3 = Subject(id=3, evs=ev28_3, cvs=(BW=70,),time=[1,2,4,8,12,24,36,48,72])
pop28 = [sub28_1,sub28_2,sub28_3]
obs28 = simobs(pk28, pop28, par28)
df = DataFrame(obs28)
plot(obs28)
obs28_1 = simobs(pk28, pop28, par28, obstimes=0:1:72)
plot(obs28_1)

Essentially, you can pass in a time argument to the Subject which will be that subjects observation time.
Also notice the change in how a Population is made. You no longer need Population([subjects]). You can collect all subjects in an array [ ] and they become a Population. Hope that helps?

Thanks a lot @vijay. My bad I didn’t check that the obstimes were specific for each of the 3 subjects. But passing time argument in each subject is better to get observations of each subjects. Will make note of Population as well.