# Incorrect pred/ipred at dosing times

**URL:** <https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545>\
**Category:** Pumas issues\
**Created:** [November 5, 2021, 7:19am UTC](https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545 "2021-11-05T07:19:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![donaldlee3](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/donaldlee3/32/165_2.png) [@donaldlee3](https://discourse.pumas.ai/u/donaldlee3)\
**Post date:** [November 5, 2021, 7:19am UTC](https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545/1 "2021-11-05T07:19:38Z")

</div>

When using `predict` for multiple doses, I’m seeing the same pred and ipred values given across dosing times and onto the following id:

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/4353ee623e846c9ab54ff4eefa83ee860a0fc309.png)

Is this a known issue?

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/andreasnoack/32/22_2.png) [@andreasnoack](https://discourse.pumas.ai/u/andreasnoack)\
**Post date:** [November 5, 2021, 8:07am UTC](https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545/2 "2021-11-05T08:07:08Z")

</div>

Which version of Pumas are you using?

---

<div class="post-metadata">

**Author:** ![donaldlee3](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/donaldlee3/32/165_2.png) [@donaldlee3](https://discourse.pumas.ai/u/donaldlee3)\
**Post date:** [November 5, 2021, 8:39am UTC](https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545/3 "2021-11-05T08:39:48Z")

</div>

I’m using the version on JuliaHub. `status` doesn’t seem to show the version for Pumas.

---

<div class="post-metadata">

**Author:** ![pkofod](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/pkofod/32/59_2.png) [@pkofod](https://discourse.pumas.ai/u/pkofod)\
**Post date:** [November 5, 2021, 9:20am UTC](https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545/4 "2021-11-05T09:20:16Z")

</div>

I am observing that the dv\_ipreds are the same, but the dv’s are also the same. Is this how the raw data looks as well, or is this part of the issue?

---

<div class="post-metadata">

**Author:** ![donaldlee3](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/donaldlee3/32/165_2.png) [@donaldlee3](https://discourse.pumas.ai/u/donaldlee3)\
**Post date:** [November 5, 2021, 9:44am UTC](https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545/5 "2021-11-05T09:44:26Z")

</div>

The raw data was generated from simulations and don’t have dv’s at those dosing times.

---

<div class="post-metadata">

**Author:** ![donaldlee3](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/donaldlee3/32/165_2.png) [@donaldlee3](https://discourse.pumas.ai/u/donaldlee3)\
**Post date:** [November 5, 2021, 9:48am UTC](https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545/6 "2021-11-05T09:48:11Z")

</div>

I am running the following lines of code on the dataframe from `predict`:

```auto
    indices_001 = findall(ipred_df.time .== 0.001)
    indices_0 = findall(ipred_df.time .== 0)

    # reorders b/c predict puts dosing events out of order
    for j in 1:length(indices_0)
        foreach((vals, col_names) -> insert!(ipred_df[!, col_names], indices_001[j], vals), collect(ipred_df[indices_0[j],:]), names(ipred_df))
        delete!(ipred_df, indices_0[j]+1)
    end

    indices_92 = findall(ipred_df.time .== 92)
    indices_90 = findall(ipred_df.time .== 90)

    # reorders b/c predict puts dosing events out of order
    for j in 1:length(indices_90)
        foreach((vals, col_names) -> insert!(ipred_df[!, col_names], indices_92[j], vals), collect(ipred_df[indices_90[j],:]), names(ipred_df))
        delete!(ipred_df, indices_90[j]+1)
    end

    indices_182 = findall(ipred_df.time .== 182)
    indices_180 = findall(ipred_df.time .== 180)

    # reorders b/c predict puts dosing events out of order
    for j in 1:length(indices_180)
        foreach((vals, col_names) -> insert!(ipred_df[!, col_names], indices_182[j], vals), collect(ipred_df[indices_180[j],:]), names(ipred_df))
        delete!(ipred_df, indices_180[j]+1)
    end

    indices_272 = findall(ipred_df.time .== 272)
    indices_270 = findall(ipred_df.time .== 270)

    # reorders b/c predict puts dosing events out of order
    for j in 1:length(indices_270)
        foreach((vals, col_names) -> insert!(ipred_df[!, col_names], indices_272[j], vals), collect(ipred_df[indices_270[j],:]), names(ipred_df))
        delete!(ipred_df, indices_270[j]+1)
    end

```

Could that code cause this to happen?

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/andreasnoack/32/22_2.png) [@andreasnoack](https://discourse.pumas.ai/u/andreasnoack)\
**Post date:** [November 5, 2021, 10:09am UTC](https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545/7 "2021-11-05T10:09:00Z")

</div>

Yeah. I think it’s likely. I’d warn against mutating data frame columns like you do here. It’s very error prone. Try instead to call `sort!` on the data frame and select the appropriate columns to sort on. Please also try checking the individual predictions before you make any modifications to the data frame.

---

<div class="post-metadata">

**Author:** ![donaldlee3](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/donaldlee3/32/165_2.png) [@donaldlee3](https://discourse.pumas.ai/u/donaldlee3)\
**Post date:** [November 5, 2021, 6:22pm UTC](https://discourse.pumas.ai/t/incorrect-pred-ipred-at-dosing-times/545/8 "2021-11-05T18:22:07Z")

</div>

Using `sort!` instead fixed the issue. Thank you!

Would you be able to take a look at the other question I also posted?

> [@IPRED multiple doses for obstimes](https://discourse.pumas.ai/t/ipred-multiple-doses-for-obstimes/544):
>
> Hello, Is it currently possible to use the predict function to get ipreds with multiple doses if your dv’s were for just one dose? I tried to add a pumas population, but I’m getting a “no method matching…” error. I also tried the nsim method, which gave the following error: ERROR: using simulated subjects is not yet implemented.
