Skip to contents

This function calculates various cost metrics to evaluate the fit of a model by comparing simulated data against observed data. It supports different methods for weighting residuals.

Usage

calculateCostMetrics(
  df,
  objectiveFunctionType = "lsq",
  residualWeightingMethod = "none",
  robustMethod = "none",
  scaleVar = FALSE,
  ...
)

Arguments

df

A dataframe containing the combined data for simulation and observation. Supports dataframes created from a DataCombined object via DataCombined$toDataFrame(). The dataframe must include columns for "dataType", "xValues", "yValues", and optionally "yErrorValues" if the residualWeightingMethod is set to "error".

objectiveFunctionType

A string indicating the objective function type for calculating model cost. Options include "lsq" (least squares, default) and "m3" for handling censored data.

residualWeightingMethod

A string indicating the method to weight the residuals. Options include "none" (default), "std", "mean", and "error".

robustMethod

A string indicating the robust method to apply to the residuals. Options include "none" (default), "huber", and "bisquare".

scaleVar

A boolean indicating whether to scale residuals by the number of observations. Defaults to FALSE.

...

Additional arguments passed to .calculateCensoredContribution, including 'scaling', 'linScaleCV', and 'logScaleSD'.

Value

A cost metrics summary list containing the following fields:

  • modelCost: The total cost calculated from the scaled sum of squared residuals.

  • minLogProbability: The minimum log probability indicating the model fit.

  • costDetails: A dataframe with details on the cost calculations.

  • residualDetails: A dataframe with the calculated residuals and their weights. The summary has the class modelCost.

Details

The function calculates the residuals between the simulated and observed values, applies the specified weighting method, and computes the cost metrics.

Examples

if (FALSE) {

# Assuming DataCombined is a valid ospsuite DataCombined object
df <- DataCombined$toDataFrame()

# Calculate cost metrics
costMetrics <- calculateCostMetrics(df, residualWeightingMethod = "std", scaleVar = TRUE)

# View model cost
print(costMetrics$modelCost)
}