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

IOV on imported dataset #1256

Open
farmacyst99 opened this issue Dec 24, 2024 · 1 comment
Open

IOV on imported dataset #1256

farmacyst99 opened this issue Dec 24, 2024 · 1 comment

Comments

@farmacyst99
Copy link

I am trying to simulate a model which has IOV modeling, and I have a data of patients covariates which I want to simulate, but I am not able to implement IOV correctly, as the ID and dosing amount code I have written messes up the sequence of ID. Can you help me here is the model file:

mod <- mcode("iov", code)

patients <- read_csv("~/Desktop/pmx/replicated_patients.csv") %>% slice(1:10) %>% as.data.frame()

newdata <- mutate(patients,ID = 1:n())

data <- realize_addl(ev(amt = 40 * data$BSA, tinf = 0.5, ii = 24, addl = 4, ID = 1:10)) %>% as.data.frame

data <- mutate(data, OCC = cumsum(evid)-1)
data

and this is how my dataframe looks:

Screenshot 2024-12-24 at 3 23 28 PM
@kylebaron
Copy link
Collaborator

Hi @farmacyst99 -

Can you try the updated approach below? This lets the event expand function (ev_expand() ... also known as expand.ev()) handle the ID assignment. Please let me know if this is what you were aiming at.

Kyle

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(mrgsolve)
#> 
#> Attaching package: 'mrgsolve'
#> The following object is masked from 'package:stats':
#> 
#>     filter

#patients <- read_csv("~/Desktop/pmx/replicated_patients.csv") %>% slice(1:10) %>% as.data.frame()

patients <- data.frame(BSA = runif(10, 0.8, 1.2))

e <- ev_expand(amt = 40*patients$BSA, tinf = 0.5, ii = 24, addl = 4)

data <- realize_addl(e)

data <- mutate(data, OCC = cumsum(evid)-1, .by = ID)

head(data, n = 11)
#>    ID time      amt     rate ii addl cmt evid tinf OCC
#> 1   1    0 43.75310 87.50621  0    0   1    1  0.5   0
#> 2   1   24 43.75310 87.50621  0    0   1    1  0.5   1
#> 3   1   48 43.75310 87.50621  0    0   1    1  0.5   2
#> 4   1   72 43.75310 87.50621  0    0   1    1  0.5   3
#> 5   1   96 43.75310 87.50621  0    0   1    1  0.5   4
#> 6   2    0 32.44486 64.88972  0    0   1    1  0.5   0
#> 7   2   24 32.44486 64.88972  0    0   1    1  0.5   1
#> 8   2   48 32.44486 64.88972  0    0   1    1  0.5   2
#> 9   2   72 32.44486 64.88972  0    0   1    1  0.5   3
#> 10  2   96 32.44486 64.88972  0    0   1    1  0.5   4
#> 11  3    0 39.22790 78.45581  0    0   1    1  0.5   0

Created on 2024-12-26 with reprex v2.1.1

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