Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

888 residuals #939

Merged
merged 14 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Suggests:
tracelib,
styler,
rClr,
crayon
crayon,
webshot
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.1
Expand Down
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(SensitivityPlotSettings)
export(SimulationSet)
export(StandardPlotTasks)
export(StandardSimulationTasks)
export(StatisticsTypes)
export(Task)
export(activateWorkflowTasks)
export(addFigureChunk)
Expand Down Expand Up @@ -57,6 +58,9 @@ export(defaultSimulationNumberOfCores)
export(defaultVariationRange)
export(evalDataFilter)
export(generateResultFileNames)
export(geomean)
export(geomeanDividedBySD)
export(geomeanMultipliedBySD)
export(getAnchorName)
export(getDefaultDemographyXParameters)
export(getDefaultPKParametersXParameters)
Expand All @@ -74,6 +78,7 @@ export(getResiduals)
export(getSimulationDescriptor)
export(getSimulationParameterDisplayPaths)
export(getSimulationResultFileNames)
export(getStatisticsFromType)
export(getTaskInputs)
export(getWorkflowParameterDisplayPaths)
export(getXParametersForDemogrpahyPlot)
Expand Down Expand Up @@ -117,7 +122,9 @@ export(plotMassBalanceCumulativeTimeProfile)
export(plotMassBalancePieChart)
export(plotMassBalanceTimeProfile)
export(plotMeanTimeProfile)
export(plotMeanTimeProfileLog)
export(plotPopulationTimeProfile)
export(plotPopulationTimeProfileLog)
export(prettyCaption)
export(ratioBoxplot)
export(readObservedDataFile)
Expand All @@ -135,6 +142,7 @@ export(setDefaultPlotFormat)
export(setDefaultStairstep)
export(setDefaultTheme)
export(setDefaultThemeFromJson)
export(setDefaultTimeProfileStatistics)
export(setPlotFormat)
export(setSimulationDescriptor)
export(setWatermarkConfiguration)
Expand Down
112 changes: 85 additions & 27 deletions R/captions.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,73 @@ captions <- list(
referenceSetText <- ifNotNull(referenceSetName, paste0(" in comparison to ", referenceSetName), "")
return(paste0(
xParameterName, "-dependence of ", yParameterName, " for ", reportSimulationSet(simulationSetName, descriptor),
referenceSetText, ". Profiles are plotted in a ", plotScale, " scale."
referenceSetText, getPlotScaleCaption("Profiles", plotScale)
))
}
),
plotGoF = list(
timeProfile = function(simulationSetName, descriptor, dataSource, plotScale = "linear") {
dataSourceText <- ifNotNull(dataSource, paste0(". Data source: ", dataSource), "")
return(paste0(
"Time profiles for ", reportSimulationSet(simulationSetName, descriptor),
dataSourceText, ". Time profiles are plotted in a ", plotScale, " scale."
getDataSourceCaption(dataSource), getPlotScaleCaption("Time profiles", plotScale)
))
},
obsVsPred = function(simulationSetName, descriptor, dataSource, plotScale = "linear") {
dataSourceText <- ifNotNull(dataSource, paste0(". Data source: ", dataSource), "")
obsVsPred = function(simulationSetName, descriptor, dataSource = NULL, plotScale = "linear", yCaption = NULL, pathName = NULL) {
return(paste0(
"Predicted vs observed for ", reportSimulationSet(simulationSetName, descriptor),
dataSourceText, ". Predictions and observations are plotted in a ", plotScale, " scale."
"Predicted ", getStatisticsCaption(yCaption), "vs observed for ",
getResidualsAcrossCaption(pathName), reportSimulationSet(simulationSetName, descriptor),
getDataSourceCaption(dataSource), getPlotScaleCaption("Predictions and observations", plotScale)
))
},
resVsPred = function(simulationSetName, descriptor, dataSource, plotScale = ResidualScales$Linear) {
dataSourceText <- ifNotNull(dataSource, paste0(". Data source: ", dataSource), "")
return(paste0(plotScale, " residuals vs predicted values for ", reportSimulationSet(simulationSetName, descriptor), dataSourceText, "."))
resVsPred = function(simulationSetName, descriptor, dataSource = NULL, plotScale = ResidualScales$Linear, yCaption = NULL, pathName = NULL) {
return(paste0(
plotScale, " residuals vs predicted ", getStatisticsCaption(yCaption), "values for ",
getResidualsAcrossCaption(pathName), reportSimulationSet(simulationSetName, descriptor),
getDataSourceCaption(dataSource)
))
},
resVsTime = function(simulationSetName, descriptor, dataSource = NULL, plotScale = ResidualScales$Linear, pathName = NULL) {
return(paste0(
plotScale, " residuals vs time values for ",
getResidualsAcrossCaption(pathName), reportSimulationSet(simulationSetName, descriptor),
getDataSourceCaption(dataSource)
))
},
resHisto = function(simulationSetName, descriptor, dataSource = NULL, plotScale = ResidualScales$Linear, pathName = NULL) {
return(paste0(
plotScale, " residuals distribution (stacked) for ",
getResidualsAcrossCaption(pathName), reportSimulationSet(simulationSetName, descriptor),
getDataSourceCaption(dataSource)
))
},
resQQPlot = function(simulationSetName, descriptor, dataSource = NULL, plotScale = ResidualScales$Linear, pathName = NULL) {
return(paste0(
plotScale, " residuals for ",
getResidualsAcrossCaption(pathName), reportSimulationSet(simulationSetName, descriptor),
" as quantile-quantile plot", getDataSourceCaption(dataSource)
))
},
resVsTime = function(simulationSetName, descriptor, dataSource, plotScale = ResidualScales$Linear) {
dataSourceText <- ifNotNull(dataSource, paste0(". Data source: ", dataSource), "")
return(paste0(plotScale, " residuals vs time values for ", reportSimulationSet(simulationSetName, descriptor), dataSourceText, "."))
meanLegend = function(simulationSetName, descriptor, pathName){
return(paste0("Simulated ", pathName, " (", reportSimulationSet(simulationSetName, descriptor), ")"))
},
resHisto = function(simulationSetName, descriptor, dataSource, plotScale = ResidualScales$Linear) {
dataSourceText <- ifNotNull(dataSource, paste0(". Data source: ", dataSource), "")
return(paste0(plotScale, " residuals distribution (stacked) for ", reportSimulationSet(simulationSetName, descriptor), dataSourceText, "."))
populationLegend = function(simulationSetName, descriptor, statistics, pathName){
paste0(
"Simulated ", statistics$yCaption, " and ", statistics$rangeCaption,
" for ", pathName, " (", reportSimulationSet(simulationSetName, descriptor), ")"
)
},
resQQPlot = function(simulationSetName, descriptor, dataSource, plotScale = ResidualScales$Linear) {
dataSourceText <- ifNotNull(dataSource, paste0(". Data source: ", dataSource), "")
return(paste0(plotScale, " residuals ", reportSimulationSet(simulationSetName, descriptor), " as quantile-quantile plot", dataSourceText, "."))
resLegend = function(simulationSetName, descriptor, pathName){
return(paste0(pathName, " (", reportSimulationSet(simulationSetName, descriptor), ")"))
},
histogram = function(simulationSetName, descriptor) {
paste0("Distribution (stacked) of residuals for ", reportSimulationSet(simulationSetName, descriptor), ".")
observedLegend = function(simulationSetName, descriptor, pathName){
paste0(
"Observed data for ", pathName, " (", reportSimulationSet(simulationSetName, descriptor), ")"
)
},
qqPlot = function(simulationSetName, descriptor) {
paste0("Residuals for ", reportSimulationSet(simulationSetName, descriptor), " as quantile-quantile plot.")
lloqLegend = function(simulationSetName, descriptor, pathName){
paste0(
"BLQ data for ", pathName, " (", reportSimulationSet(simulationSetName, descriptor), ")"
)
}
),
plotPKParameters = list(
Expand Down Expand Up @@ -156,13 +183,19 @@ getDataSource <- function(structureSet) {
return(dataSource)
}

getGoodnessOfFitCaptions <- function(structureSet, plotType, plotScale = "linear") {
getGoodnessOfFitCaptions <- function(structureSet, plotType, plotScale = "linear", settings = NULL) {
dataSource <- getDataSource(structureSet)
simulationSetName <- structureSet$simulationSet$simulationSetName
setDescriptor <- structureSet$simulationSetDescriptor

captionExpression <- parse(text = paste0("plotCaption <- captions$plotGoF$", plotType, "(simulationSetName, setDescriptor, dataSource, plotScale)"))
eval(captionExpression)
yCaption <- NULL
if(isOfType(structureSet$simulationSet, "PopulationSimulationSet") &
isIncluded(plotType, c("obsVsPred", "resVsPred"))){
gofStatistics <- settings$getStatistics()
yCaption <- gofStatistics$yCaption
plotCaption <- captions$plotGoF[[plotType]](simulationSetName, setDescriptor, dataSource, plotScale, yCaption)
return(plotCaption)
}
plotCaption <- captions$plotGoF[[plotType]](simulationSetName, setDescriptor, dataSource, plotScale)
return(plotCaption)
}

Expand Down Expand Up @@ -226,3 +259,28 @@ getTimeRangeCaption <- function(timeRangeName, reference, simulationSetName) {
))
}
}

getDataSourceCaption <- function(dataSource){
if(isEmpty(dataSource)){
return("")
}
return(paste0(". Data source: ", dataSource))
}

getStatisticsCaption <- function(statistics){
if(isEmpty(statistics)){
return("")
}
return(paste0("(", statistics,") "))
}

getPlotScaleCaption <- function(plotName, plotScale){
return(paste0(". ", plotName, " are plotted in a ", plotScale, " scale."))
}

getResidualsAcrossCaption <- function(pathName){
if(isEmpty(pathName)){
return("")
}
return(paste0(pathName, " across "))
}
Loading