-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #308 from esqLABS/documentation
Documenting plotting and sensitivity functions
- Loading branch information
Showing
9 changed files
with
68,187 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: "Visualization and reporting" | ||
output: rmarkdown::html_vignette | ||
#output: pdf_document | ||
vignette: > | ||
%\VignetteIndexEntry{Visualization and reporting} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
```{r, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
knitr::opts_knit$set( | ||
root.dir = "../tests/data/TestProject/Code/" | ||
) | ||
``` | ||
|
||
```{r, echo = FALSE, results = "hide", message = FALSE} | ||
library(esqlabsR) | ||
projectConfiguration <- createDefaultProjectConfiguration() | ||
dataSheets <- "Laskin 1982.Group A" | ||
observedData <- loadObservedData(projectConfiguration = projectConfiguration, sheets = dataSheets) | ||
scenarioConfiguration <- ScenarioConfiguration$new(projectConfiguration) | ||
OutputPaths <- enum(list( | ||
Aciclovir_PVB = "Organism|PeripheralVenousBlood|Aciclovir|Plasma (Peripheral Venous Blood)" | ||
)) | ||
simulatedScenarios <- runScenarios( | ||
scenarioNames = c("TestScenario"), | ||
scenarioConfiguration = scenarioConfiguration, | ||
customParams = NULL, saveSimulationsToPKML = FALSE | ||
) | ||
``` | ||
|
||
### Workflow | ||
|
||
Plotting the simulation results is an important part of model diagnostics and quality control. Simulated modeling scenarios can be passed to plotting functions from the `{ospsuite}` package to create uniformly-looking plots. | ||
|
||
`DataCombined` is a class used to store matching observed and simulated data. Initialize a new class instance and populate it with data with the following code: | ||
|
||
```{r datacombined} | ||
dataCombined <- DataCombined$new() | ||
dataCombined$addDataSets(observedData, names = "Observed", groups = "Aciclovir") | ||
dataCombined$addSimulationResults(simulatedScenarios$TestScenario$results, names = "Simulated", groups = "Aciclovir") | ||
dataCombined$toDataFrame() | ||
``` | ||
|
||
The simulation results are stored in a list returned by the `runScenarios()` function. Plotting and visualization is performed by storing these results along with matching observed data in a `DataCombined` object and passing it to plotting functions. | ||
|
||
Plotting functions in the `{ospsuite}` package are wrappers around `{tlf}` plotting functions that provide default plot configuration options. All of them accept instances of `DataCombined` class as the data source. | ||
|
||
Time profile plots visualize the pharmacokinetics of the drug in question and help assess if the observed data (represented by points and error bars) match the simulated data (represented by lines). | ||
|
||
|
||
```{r plot-time-profile, fig.width=7, fig.height=4} | ||
plotIndividualTimeProfile(dataCombined) | ||
``` | ||
|
||
Observed versus simulated plots show if simulated time points and observed time points follow a linear trend. | ||
|
||
```{r plot-obs-vs-pred, fig.width=7, fig.height=4} | ||
plotObservedVsSimulated(dataCombined) | ||
``` | ||
|
||
Residual plots show if there is a systematic bias in how the simulation represents values either in high-concentration or low-concentration regions, or, alternatively, in early or late time periods. | ||
|
||
```{r residuals-vs-simulated, fig.width=7, fig.height=4} | ||
plotResidualsVsSimulated(dataCombined) | ||
``` | ||
|
||
```{r residuals-vs-time, fig.width=7, fig.height=4} | ||
plotResidualsVsTime(dataCombined) | ||
``` | ||
|
||
The plots returned by plotting functions are `ggplot` objects. They can be modified further and saved to files with `{ggplot2}` functions: | ||
|
||
```{r save-plots} | ||
plotObject <- plotIndividualTimeProfile(dataCombined) | ||
ggplot2::ggsave(filename = "../Results/aciclovir_time_profile.png", plotObject, width = 8, height = 4) | ||
``` | ||
|
||
### Troubleshooting | ||
|
||
* At any time, you can check the groups assigned to the datasets in the `DataCombined` object by examining the output of `dataCombined$toDataFrame()`. | ||
|
||
More detailed information on function signatures can be found in: | ||
|
||
* `ospsuite` documentation on: | ||
* [Simulation class](https://www.open-systems-pharmacology.org/OSPSuite-R/reference/Simulation.html) | ||
* [SimulationResults class](https://www.open-systems-pharmacology.org/OSPSuite-R/reference/SimulationResults.html) | ||
* [DataCombined class](https://www.open-systems-pharmacology.org/OSPSuite-R/reference/DataCombined.html) | ||
* [plotIndividualTimeProfile()](https://www.open-systems-pharmacology.org/OSPSuite-R/reference/plotIndividualTimeProfile.html) | ||
* [plotObservedVsSimulated()](https://www.open-systems-pharmacology.org/OSPSuite-R/reference/plotObservedVsSimulated.html) | ||
* [plotResidualsVsSimulated()](https://www.open-systems-pharmacology.org/OSPSuite-R/reference/plotResidualsVsSimulated.html) | ||
* [plotResidualsVsTime()](https://www.open-systems-pharmacology.org/OSPSuite-R/reference/plotResidualsVsTime.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: "Sensitivity analysis" | ||
output: rmarkdown::html_vignette | ||
vignette: > | ||
%\VignetteIndexEntry{Sensitivity analysis} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
```{r, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
knitr::opts_knit$set( | ||
root.dir = "../tests/data/TestProject/Code/" | ||
) | ||
``` | ||
|
||
```{r, echo = FALSE, results = "hide", message = FALSE} | ||
library(esqlabsR) | ||
projectConfiguration <- createDefaultProjectConfiguration() | ||
dataSheets <- "Laskin 1982.Group A" | ||
observedData <- loadObservedData(projectConfiguration = projectConfiguration, sheets = dataSheets) | ||
scenarioConfiguration <- ScenarioConfiguration$new(projectConfiguration) | ||
OutputPaths <- enum(list( | ||
Aciclovir_PVB = "Organism|PeripheralVenousBlood|Aciclovir|Plasma (Peripheral Venous Blood)" | ||
)) | ||
simulatedScenarios <- runScenarios( | ||
scenarioNames = c("TestScenario"), | ||
scenarioConfiguration = scenarioConfiguration, | ||
customParams = NULL, saveSimulationsToPKML = FALSE | ||
) | ||
``` | ||
|
||
### Workflow | ||
|
||
Sensitivity analysis quantifies how the pharmacokinetics of the drug changes with a variation in simulation parameters. This is important to track if the values of simulation parameters are uncertain. | ||
|
||
In the aciclovir simulation example, the lipophilicity of aciclovir was assumed to be -0.100 in log units. In the sensitivity analysis, we want to quantify how much the pharmacokinetic parameters change if the lipophilicity of aciclovir varies in the (-0.01, -1.00) range. | ||
|
||
The `sensitivityCalculation()` function in the `{esqlabsR}` package does that by re-running the simulation with a set of updated parameter values. The function returns a list with output paths, parameter paths, a `SimulationResults` object, and a data frame with computed pharmacokinetic parameters for each of the input parameter values. | ||
|
||
```{r analysis} | ||
simulation <- simulatedScenarios$TestScenario$simulation | ||
OutputPaths <- enum(list( | ||
Aciclovir_PVB = "Organism|PeripheralVenousBlood|Aciclovir|Plasma (Peripheral Venous Blood)" | ||
)) | ||
analysis <- sensitivityCalculation(simulation, OutputPaths, parameterPaths = "Aciclovir|Lipophilicity") | ||
head(analysis$pkData) | ||
``` | ||
|
||
In the aciclovir example case, the default value of lipophilicity was -0.100 log units, corresponding to the area under curve (AUC) of 3915.87 µmol×min/L. Changing the lipophilicity to -0.01 log units leads to a decrease of AUC to 3895.43 µmol×min/L (a change of -0.52%), while changing the lipophilicity to -1.00 log units leads to an increase of AUC to 4015.73 µmol×min/L (a change of 2.55%). | ||
|
||
The results of the sensitivity analysis can be plotted with two functions: | ||
|
||
* the `sensitivitySpiderPlot()` function shows a separate plot for each of the pharmacokinetic parameters under investigation. By default, the `sensitivityCalculation()` function computes the changes in area under curve (`AUC_inf`), maximum concentration (`C_max`) and time when the maximum concentration is reached (`t_max`). | ||
|
||
```{r spider-plot, fig.width=7, fig.height=4} | ||
sensitivitySpiderPlot(analysis) | ||
``` | ||
|
||
* the `sensitivityTimeProfiles()` function plots the concentration profile for each of the input parameter values: | ||
|
||
```{r time-profile, fig.width=7, fig.height=4} | ||
sensitivityTimeProfiles(analysis) | ||
``` | ||
|
||
### Troubleshooting | ||
|
||
* The `SensitivityPKParameter` column in the output of `analysis$pkData` will be `NA` in the rows corresponding to the initial parameter values. | ||
|
||
More detailed information on function signatures can be found in: | ||
|
||
* `esqlabsR` documentation on: | ||
* [sensitivityCalculation()](https://esqlabs.github.io/esqlabsR/reference/sensitivityCalculation.html) | ||
* [sensitivitySpiderPlot()](https://esqlabs.github.io/esqlabsR/reference/sensitivitySpiderPlot.html) | ||
* [sensitivityTimeProfiles()](https://esqlabs.github.io/esqlabsR/reference/sensitivityTimeProfiles.html) | ||
|