Open-Systems-Pharmacology / OSPSuite-R

R package for the OSPSuite
https://www.open-systems-pharmacology.org/OSPSuite-R/
Other
28 stars 11 forks source link

Sensitivity Analysis: Return the simulated values #863

Open msevestre opened 2 years ago

msevestre commented 2 years ago

@IndrajeetPatil @PavelBal @Yuri05

This is definitely possible with the current implementation At the moment, we create a huge "Variation Table" that is being passed to the PopulationRunner Each Column is a parameter, each row is a simulation. (or Individual so to speak). Each Row represents the variation of only one parameter

https://github.com/Open-Systems-Pharmacology/OSPSuite.Core/blob/develop/src/OSPSuite.Core/Domain/Services/SensitivityAnalyses/SensitivityAnalysisEngine.cs#L68

The [runResults] https://github.com/Open-Systems-Pharmacology/OSPSuite.Core/blob/develop/src/OSPSuite.Core/Domain/Services/SensitivityAnalyses/SensitivityAnalysisEngine.cs#L69

are of type PopulationRunResults. which has a property internally that is well known in R Results of type SimulationResults

We are already using this object from ospsuite-R. There is for sure some mapping to be performed to understand what row corresponds to which variation but everything is already here somehow

We could also add this info directly to the SensitivityAnalysisRunResult which is also used directly in R

So all in all, I think this could be exposed easily to R

msevestre commented 2 years ago

I have a PR exposing this stuff https://github.com/Open-Systems-Pharmacology/OSPSuite.Core/pull/1583

I will need help for naming however

PavelBal commented 2 years ago

@msevestre I cannot get it running from R.

Running sensitivity analysis with ReturnOutputValues = TRUE:

sim <- loadTestSimulation("simple")
sensitivity <- SensitivityAnalysis$new(sim)
sensitivityAnalysisOptions <- SensitivityAnalysisRunOptions$new(showProgress = FALSE)
sensitivityAnalysisOptions$returnOutputValues <- TRUE
results <- runSensitivityAnalysis(sensitivity, sensitivityAnalysisOptions)

> results
SensitivityAnalysisResults: 
   Number of calculated sensitivities: 72 
   Available PK parameters: C_max t_max C_tEnd AUC_tEnd Thalf AUC_inf MRT FractionAucLastToInf 

Trying to get the outputs returns an empty list:

> tmp <- rClr::clrCall(results$ref, "OutputParameterSensitivitiesFor", "Organism|B", "R1-k1")
> tmp
list()

The sensitivity for the combination of output path and parameter does exist:

> results$pkParameterSensitivityValueFor("C_max", "Organism|B", "R1-k1")
[1] 0.125683
PavelBal commented 2 years ago

We also need the simulated time, which is currently not exposed.

msevestre commented 2 years ago

tmp <- rClr::clrCall(results$ref, "OutputParameterSensitivitiesFor", "Organism|B", "R1-k1")

This should be the parameter path as second argument

msevestre commented 2 years ago

but we can use the PI PArameter name instead if this makes more sense

msevestre commented 2 years ago

and it probably makes sense if we have results$pkParameterSensitivityValueFor("C_max", "Organism|B", "R1-k1")