# PKPD Example

## Specifying a PKPD Model using mrgsolve

Here we use a two-compartment PK model linked to an indirect response PD model with the drug inhibiting the rate constant of input (Kin). The model included several covariates effects on Clearance, Volume and Kin. The baseline PD response is controlled by the ratio of Kin/Kout.

codepkpdmodelcov <- '
$PARAM CL = 4, V=10 , KA=0.5, Vp =50, Qp= 10, CLALB = -0.8, CLSEX = 0.2, CLWT = 1, VSEX = 0.07, VWT = 1, KIN = 3, KOUT = 0.06, IC50 = 3, IMAX = 0.999 gamma = 0.548, KINWT=0.4 , KINAGE=-0.08, KINHEALTHY =1.5, WT=66, SEX=0, ALB =45, AGE=62, HEALTHY = 0$CMT GUT CENT PER RESP
$GLOBAL #define CP (CENT/Vi) #define CPER (PER/Vpi) #define INH (IMAX*pow(CP,gamma)/(pow(IC50,gamma)+pow(CP,gamma))) #define PDRESP RESP$MAIN
double KAi = KA;
double Vpi = Vp *pow((WT/70.0),    1);
double Qpi = Qp *pow((WT/70.0), 0.75);
double CLi = CL *
pow((ALB/45.0), CLALB)*
(SEX == 1.0 ? (1.0+CLSEX) : 1.0)*
pow((WT/66), CLWT)*exp(ETA(1));
double Vi = V *
(SEX == 1.0 ? (1.0+VSEX) : 1.0)*
pow((WT/66), VWT)*exp(ETA(2));
double KINi = KIN *
pow((AGE/62), KINAGE)*
(HEALTHY == 1.0 ? KINHEALTHY : 1.0)*
pow((WT/66), KINWT)*exp(ETA(3));
double RESP_0 = KINi/KOUT;

$OMEGA 0.3 0.01 0.3$OMEGA
0.25

$ODE dxdt_GUT = -KAi *GUT; dxdt_CENT = KAi *GUT - (CLi+Qpi)*CP + Qpi*CPER; dxdt_PER = Qpi*CP - Qpi*CPER; dxdt_RESP = KINi*(1-INH) - KOUT*RESP;$CAPTURE CP PDRESP
'
modpkpdsim <- mcode("codepkpdmodelcov", codepkpdmodelcov)
#> Building codepkpdmodelcov ... done.

### Simulate Reference Subjects with BSV

We simulate at reference covariate values with between subject variability (BSV) and then we show a plot of the PK and PD profiles of five random subjects.

idata <- tibble(
ID = 1:100, WT = 66,
ALB = 45, AGE = 62,SEX = 0, HEALTHY=0)
ev1 <- ev(time = 0, amt = 100,
cmt = 1, ii = 24, addl = 20)
data.dose <- ev(ev1)
data.dose <- as.data.frame(data.dose)
data.all <- merge(idata, data.dose)

set.seed(678549)
outputpkpdsim <- modpkpdsim %>%
data_set(data.all) %>%
carry.out(WT, ALB, AGE, SEX, HEALTHY,
CLi, KINi, KOUT) %>%
mrgsim(end = 24*28, delta = 0.25)
outputpkpdsim <- as.data.frame(outputpkpdsim)
outputpkpdsim$HEALTHY <- as.factor(outputpkpdsim$HEALTHY)

yvar_names <- c(
'CP'="Plasma Concentrations",
'RESP'="PD Response"
)
set.seed(678549)
outputpkpdsimlong <- outputpkpdsim[outputpkpdsim$ID %in% sample(unique(outputpkpdsim$ID), 5), ] %>%
gather(key,value,CP,RESP)

ggplot(data =outputpkpdsimlong ,
aes(time, value, group = ID)) +
geom_line(alpha = 0.8, size = 0.3) +
facet_grid(key ~ID,scales="free_y",switch="y",
labeller = labeller(key=yvar_names)) +
labs(y = "", color = "Sex", x = "Time (h)")+
theme(strip.placement = "outside",
axis.title.y=element_blank())

### Compute PD Parameters and Summarize BSV

Here we compute the PD baseline (where we start), nadir response (minimum response achieved) and the delta (difference) between the baseline and nadir. We then summarize and report the BSV around these parameters as ranges of 50 and 90% of patients. We then show a plot of the first 10 replicates as an example of the simulated PD profiles. Since the code is similar to the PK Example vignette it is not shown.

NCATYPICAL <- outputpkpdsim %>%
group_by(ID, HEALTHY, WT, SEX, AGE, ALB) %>%
summarise (
nadir = min(PDRESP, na.rm = TRUE),
baselinepd = PDRESP[1],
) %>%
NCATYPICAL <- NCATYPICAL %>%
group_by (paramname)
NCATYPICALREF <- NCATYPICAL%>%
group_by (paramname) %>%
mutate(medparam = median(paramvalue),
paramvalue = paramvalue / medparam)
BSVRANGESSTD<- NCATYPICALREF %>%
summarize(
P05 = quantile(paramvalue, 0.05),
P25 = quantile(paramvalue, 0.25),
P50 = quantile(paramvalue, 0.5),
P75 = quantile(paramvalue, 0.75),
P95 = quantile(paramvalue, 0.95)
)
BSVRANGESSTD
paramname P05 P25 P50 P75 P95
baselinepd 0.4215967 0.7372112 1 1.403291 2.751336
deltapd 0.4335001 0.8022619 1 1.673008 3.202107
nadir 0.3941671 0.7297790 1 1.393084 2.702835

## Construct ans Simulate at Combinations of Covariate of Interest

Similarly to the PK Example vignette we generate covariate combinations of interest and we simulate with uncertainty using an invented varcov matrix.

reference.values <- data.frame(WT = 66,ALB = 45, AGE = 62, SEX = 0, HEALTHY = 0)
covcomb <- expand.modelframe(
WT  = c(40,66,90),
AGE = c(42,62,82),
ALB = c(40,45,50),
SEX = c(0,1),#Refernce is for SEX =0
HEALTHY = c(0,1),#Refernce is for HEALTHY =0
rv = reference.values)
covcomb$ID <- 1:nrow(covcomb) covcomb <- covcomb[!duplicated( paste(covcomb$WT,covcomb$ALB,covcomb$AGE,covcomb$HEALTHY,covcomb$SEX)),]
covcomb
WT AGE ALB SEX HEALTHY covname ID
1 40 62 45 0 0 WT 1
2 66 62 45 0 0 WT 2
3 90 62 45 0 0 WT 3
4 66 62 40 0 0 ALB 4
6 66 62 50 0 0 ALB 6
7 66 42 45 0 0 AGE 7
9 66 82 45 0 0 AGE 9
11 66 62 45 1 0 SEX 11
13 66 62 45 0 1 HEALTHY 13
ggplot(iter_sims[iter_sims$rep<=10,], aes(time/24,PDRESP,col=factor(WT),linetype=factor(HEALTHY) ) )+ geom_line(aes(group=interaction(ID,rep)),alpha=0.3,size=0.3)+ facet_grid(ALB~ AGE,labeller = label_both)+ labs(linetype="Healthy", colour="Weight (kg)", caption ="Simulation\nwith Uncertainty without BSV\nreplicates 1 to 10" , x="Days", y = "PD Response") ### Compute PD Parameters and Distributions Plots Similar to the above we compute the PD parameters, standardize by the median and provide a plot. Since the code is similar to the PK Example vignette it is not shown. ggplot(out.df.univariatecov.nca, aes(x=paramvalue,y=covvalue,fill=factor(..quantile..),height=..ndensity..))+ facet_grid(covname~paramname,scales="free_y",space="free")+ annotate( "rect", xmin = 0.5, xmax = 2, ymin = -Inf, ymax = Inf, fill = "gray",alpha=0.4 )+ stat_density_ridges( geom = "density_ridges_gradient", calc_ecdf = TRUE, quantile_lines = TRUE, rel_min_height = 0.001,scale=0.9, quantiles = c(0.05,0.5, 0.95)) + scale_fill_manual( name = "Probability", values = c("#FF0000A0", "white","white", "#0000FFA0"), labels = c("(0, 0.05]", "(0.05, 0.5]","(0.5, 0.95]", "(0.95, 1]") )+ stat_summaryh(aes(x=paramvalue,y=covvalue),fun.data="median_hilow_h", color="steelblue", geom="pointrangeh",size=0.5,position=position_nudge(y=-0.1), fun.args = list(conf.int=0.9),inherit.aes = FALSE)+ geom_vline( aes(xintercept = 1),size = 1)+ theme_bw()+ labs(x="Effects Relative to parameter reference value",y="")+ scale_x_continuous(breaks=c(0.25,0.5,0.8,1/0.8,1/0.5,1/0.25))+ scale_x_log10() ### Summarize, add BSV and Use forest_plot We will show how a multiple parameters, multiple covariates plot and table can be done. coveffectsdatacovrep <- out.df.univariatecov.nca %>% dplyr::group_by(paramname,covname,covvalue) %>% dplyr::summarize( mid= median(paramvalue), lower= quantile(paramvalue,0.05), upper = quantile(paramvalue,0.95)) coveffectsdatacovreplabel<- coveffectsdatacovrep %>% mutate( label= covvalue, LABEL = paste0(format(round(mid,2), nsmall = 2), " [", format(round(lower,2), nsmall = 2), "-", format(round(upper,2), nsmall = 2), "]")) coveffectsdatacovrepbsv <- coveffectsdatacovrep[coveffectsdatacovrep$covname=="REF",]
coveffectsdatacovrepbsv$covname <- "BSV" coveffectsdatacovrepbsv$covvalue <- "50% of patients"
coveffectsdatacovrepbsv$label <- "50% of patients" coveffectsdatacovrepbsv$lower <- BSVRANGESSTD$P25 coveffectsdatacovrepbsv$upper <- BSVRANGESSTD$P75 coveffectsdatacovrepbsv2 <- coveffectsdatacovrep[coveffectsdatacovrep$covname=="REF",]
coveffectsdatacovrepbsv2$covname <- "BSV" coveffectsdatacovrepbsv2$covvalue <- "90% of patients"
coveffectsdatacovrepbsv2$label <- "90% of patients" coveffectsdatacovrepbsv2$lower <- BSVRANGESSTD$P05 coveffectsdatacovrepbsv2$upper <- BSVRANGESSTD$P95 coveffectsdatacovrepbsv<- rbind(coveffectsdatacovrep,coveffectsdatacovrepbsv,coveffectsdatacovrepbsv2) #> Warning in bind_rows_(x, .id): binding factor and character vector, coercing #> into character vector #> Warning in bind_rows_(x, .id): binding character and factor vector, coercing #> into character vector #> Warning in bind_rows_(x, .id): binding factor and character vector, coercing #> into character vector #> Warning in bind_rows_(x, .id): binding character and factor vector, coercing #> into character vector coveffectsdatacovrepbsv <- coveffectsdatacovrepbsv %>% mutate( label= covvalue, LABEL = paste0(format(round(mid,2), nsmall = 2), " [", format(round(lower,2), nsmall = 2), "-", format(round(upper,2), nsmall = 2), "]")) coveffectsdatacovrepbsv<- as.data.frame(coveffectsdatacovrepbsv) coveffectsdatacovrepbsv$label <- as.factor(coveffectsdatacovrepbsv$covvalue ) coveffectsdatacovrepbsv$label <- reorder(coveffectsdatacovrepbsv$label, coveffectsdatacovrepbsv$lower)

coveffectsdatacovrepbsv$covname <-factor(as.factor(coveffectsdatacovrepbsv$covname ),
levels =
c("Weight","Sex","Albumin","Age",
"Healthy", "REF", "BSV")
)

interval_legend_text = "Median (points)\n90% CI (horizontal lines)"
interval_bsv_text = "BSV (points)\nPrediction Intervals (horizontal lines)"

png("./coveffectsplotpd.png",width =9 ,height = 9,units = "in",res=72)
coveffectsplot::forest_plot(coveffectsdatacovrepbsv,
ref_area = c(0.5, 1/0.5),
x_range = c(0.25,4),
strip_placement = "outside",
base_size = 16,
y_label_text_size = 12,
xlabel = "Fold Change Relative to Reference",
ref_legend_text =
"Reference (vertical line)\nClinically relevant limits\n(gray area)",
area_legend_text =
"Reference (vertical line)\nClinically relevant limits\n(gray area)",
interval_legend_text = interval_legend_text,
interval_bsv_text = interval_bsv_text,
facet_formula = "covname~paramname",
facet_switch = "y",
facet_scales = "free_y",
facet_space = "free",
paramname_shape = FALSE,
table_position = "below",
table_text_size=4,
plot_table_ratio = 1,
table_facet_switch = "both",
show_table_facet_strip = "both",
show_table_yaxis_tick_label = TRUE,
logxscale = TRUE,
major_x_ticks = c(0.5,1,1/0.5),
return_list = FALSE)
dev.off()
#> png
#>   2