Skip to content

Instantly share code, notes, and snippets.

@kylebaron
Created November 12, 2019 18:21
Show Gist options
  • Save kylebaron/448e3c6cecef9719e7059e42c1ba4ef4 to your computer and use it in GitHub Desktop.
Save kylebaron/448e3c6cecef9719e7059e42c1ba4ef4 to your computer and use it in GitHub Desktop.
SS 1 and 2
library(mrgsolve)
#> 
#> Attaching package: 'mrgsolve'
#> The following object is masked from 'package:stats':
#> 
#>     filter
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(ggplot2)
theme_set(theme_bw())


mod <- modlib("pk1") 
#> Building pk1 ...
#> done.
single <- ev(amt = 10)
dose <- seq(single, wait=1, single) %>% mutate(ss = c(1,2),addl=10, ii = 24)

ss=1 and ss=2

dose
#> Events:
#>   time amt ii addl cmt evid ss
#> 1    0  10 24   10   1    1  1
#> 2    1  10 24   10   1    1  2

out <- mrgsim(mod,dose,end = 120,delta=0.05) %>% filter_sims(time >=24,time <=30)
sims1 <- as_tibble(out) %>% mutate(time = time-24)

no ss

dose2 <- seq(single, wait=1, single) %>% mutate(addl=100, ii = 24)
dose2
#> Events:
#>   time amt ii addl cmt evid
#> 1    0  10 24  100   1    1
#> 2    1  10 24  100   1    1

out2 <- mrgsim(mod,dose2,end = 490,delta=0.05)
sims2 <- filter(out2, time >=480,time <= 486) %>% mutate(time = time-480)

ggplot() + 
  geom_point(data = sims2, aes(time,CP),col="cornflowerblue", size = 3) +
  geom_line(data = sims1, aes(time,CP), lwd=1) 

Created on 2019-11-12 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment