vignettes/making-bootstrap-parameter-tables.Rmd
making-bootstrap-parameter-tables.Rmd
This is a vignette to help you become familiar with using
define_boot_table()
and format_boot_table()
.
For more information how to effectively integrate pmparams
into your workflow, visit the
MeRGE Expo: Parameter Tables ..
We begin by creating a parameter key that tells R how to interpret you parameter values. Our code require four arguments for each parameter:
If you have a model that uses theta in the $ERROR block, make sure
that the theta section’s panel is “RV” so that pmparams
functions can properly identify it.
It is recommended to use a parameter key yaml, but
pmparams
works for parameter key tibbles.
A more detailed walk-through of generating the parameter key is available here: MeRGE Expo: Creating a Parameter Key .
paramKeyPath <- system.file("model/nonmem/pk-parameter-key-new.yaml", package = "pmparams")
paramKey <- yaml::yaml.load_file(paramKeyPath)
head(unlist(paramKey))
#> THETA1.abb THETA1.desc
#> "KA (1/h)" "First order absorption rate constant"
#> THETA1.panel THETA1.trans
#> "struct" "logTrans"
#> THETA2.abb THETA2.desc
#> "V2/F (L)" "Apparent central volume"
pmparams
allows for different non-boot parameter
estimate input types: * path to model directory * data.frame of bbr
model_summary
For this example, we will use the path to the model directory.
nonboot_paramEstPath <- system.file("model/nonmem/106", package = "pmparams")
pmparams
allows for different boot parameter estimate
input types: * path to file * data.frame
For this example, we will use the path to file.
boot_paramEstPath <- system.file("model/nonmem/boot/data/boot-106.csv", package = "pmparams")
We will now join parameter estimates and parameter key. Note: this is an inner_join, so only parameters included in the model output and parameter key will be kept in the table. This was done so that, if your base and final model used the same structural THETAs and random parameters, the same parameter key could be used for both. The additional covariate THETAs defined in the parameter key YAML would simply be ignored when creating the base model parameter table.
Additionally, define_param_table
performs checks and
calculates confidence intervals.
df1 <- define_boot_table(.boot_estimates = boot_paramEstPath,
.nonboot_estimates = nonboot_paramEstPath,
.key = paramKeyPath)
#> Rows: 1000 Columns: 16
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): run
#> dbl (15): THETA1, THETA2, THETA3, THETA4, THETA5, THETA6, THETA7, THETA8, OM...
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> [1] "Parameter table yaml path provided: /data/pmparams/renv/library/R-4.1/x86_64-pc-linux-gnu/pmparams/model/nonmem/pk-parameter-key-new.yaml"
#> [1] "Model path provided: /data/pmparams/renv/library/R-4.1/x86_64-pc-linux-gnu/pmparams/model/nonmem/106"
head(df1)
#> # A tibble: 6 × 25
#> parameter_names estimate lower upper name abb desc panel trans nrow
#> <chr> <dbl> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <int>
#> 1 THETA1 0.449 1.39 1.78 THETA1 KA (1/h) Firs… stru… logT… 1
#> 2 THETA2 4.12 58.3 65.1 THETA2 V2/F (L) Appa… stru… logT… 2
#> 3 THETA3 1.17 3.07 3.42 THETA3 CL/F (L… Appa… stru… logT… 3
#> 4 THETA4 4.21 65.0 69.8 THETA4 V3/F (L) Appa… stru… logT… 4
#> 5 THETA5 1.28 3.37 3.86 THETA5 Q/F (L/… Appa… stru… logT… 5
#> 6 THETA6 0.484 0.408 0.558 THETA6 CL/F ~ … eGFR… cov none 6
#> # ℹ 15 more variables: fixed <lgl>, value <dbl>, transTHETA <lgl>,
#> # THETAERR <lgl>, TH <lgl>, OM <lgl>, S <lgl>, LOG <lgl>, LOGIT <lgl>,
#> # lognormO <lgl>, Osd <lgl>, logitOsd <lgl>, propErr <lgl>, addErr <lgl>,
#> # addErrLogDV <lgl>
Now, we perform some house-keeping based on the new parameter key
information, calculate any summary statistics (the 95% confidence
intervals are calculated by default), and format the values for the
report using format_boot_table
.
df2 <- format_boot_table(df1)
Usually define_boot_table
and
format_boot_table
are run together in a single call like
this:
df2 <- define_boot_table(.boot_estimates = boot_paramEstPath,
.nonboot_estimates = nonboot_paramEstPath,
.key = paramKeyPath) %>%
format_boot_table()
#> Rows: 1000 Columns: 16
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): run
#> dbl (15): THETA1, THETA2, THETA3, THETA4, THETA5, THETA6, THETA7, THETA8, OM...
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> [1] "Parameter table yaml path provided: /data/pmparams/renv/library/R-4.1/x86_64-pc-linux-gnu/pmparams/model/nonmem/pk-parameter-key-new.yaml"
#> [1] "Model path provided: /data/pmparams/renv/library/R-4.1/x86_64-pc-linux-gnu/pmparams/model/nonmem/106"
head(df2)
#> abb desc boot_value boot_ci_95
#> 1 KA (1/h) First order absorption rate constant 1.57 1.39, 1.78
#> 2 V2/F (L) Apparent central volume 61.5 58.3, 65.1
#> 3 CL/F (L/h) Apparent clearance 3.23 3.07, 3.42
#> 4 V3/F (L) Apparent peripheral volume 67.3 65.0, 69.8
#> 5 Q/F (L/h) Apparent intercompartmental clearance 3.61 3.37, 3.86
#> 6 CL/F ~ eGFR eGFR effect on CL/F 0.484 0.408, 0.558
We use pmtables
to make formatted table.
tableList <- list()
#grab footnotes
footnote <- param_notes(.ci = 95)
tableList$bootstrap <- df2 %>%
mutate(boot_ci_95 = if_else(is.na(boot_ci_95), "FIXED", boot_ci_95)) %>%
st_new() %>%
st_panel("desc") %>%
st_rename(Value = boot_value,
"95% CI" = boot_ci_95,
" "= abb) %>%
#abbreviations
st_notes(footnote$ci) %>%
#equations
st_notes(footnote$ciEq)
tableList$bootstrap %>%
stable() %>%
st_asis()