Read a calibration settings table from a text file and coerce it to the
structure expected by calibration_data() and calibration_objFn(). The
setup table defines which model outputs are compared with observations, which
objective function is used for each output, whether a row contributes to the
calibration, and how each component is weighted in the final objective.
Usage
calibration_setup(file, control = list(), ...)Arguments
- file
Path to the calibration setup file, typically a
.csvfile.- control
Named list of defaults used when optional columns are missing from the setup table. Currently recognised entries are:
col_skipDefault number of leading columns to discard when a text file is read as a full table by
calibration_data(). Defaults to2.nrowsDefault number of rows to read from each data file. Defaults to
NA, which is interpreted downstream as “read all rows”.
- ...
Additional arguments passed to
utils::read.csv()when readingfile.
Value
A data.frame describing the calibration targets. The returned table
is suitable for direct use in calibration_data() and
calibration_objFn(). Standard columns are coerced to the expected types
and missing optional columns are added where needed.
Details
The function is a validated wrapper around utils::read.csv(). It checks
required column names, coerces standard column types, fills a few optional
columns from control, and derives weight from cv when needed.
The setup table may contain the following columns:
variableName of the calibration component. This name must match the corresponding element returned by the model function supplied to
calibration_objFn().typeName of the objective function used for that component. In current workflows this is usually the name of a function accepted by
objFn(), such as"norm2","lnorm2","pois","multinom","normp", or"penalty".calibrateLogical flag indicating whether the component is active in the calibration. Only rows with
calibrate = TRUEare included in the objective function returned bycalibration_objFn().weightPositive weight used when partial objective values are aggregated. If
weightis missing, or containsNA, it is derived fromcvas1 / (2 * cv^2)for the corresponding rows.cvCoefficient of variation used to derive
weightwhen an explicit weight is not supplied. At least one ofweightorcvmust be available in the table.use_dataLogical flag indicating whether an observed dataset must be read for that row. This is typically
FALSEfor pure penalties such as"normp", where the objective depends only on simulated values.filePath to the observed data file for that component. Paths are interpreted relative to the
pathargument ofcalibration_data(). This column is still required whenuse_data = FALSE, although the file will not be read in that case.varidOptional identifier used by
calibration_data()when extracting a single column from a text file. If omitted, a full numeric table is read instead.col_skipOptional number of leading columns to discard when a text file is read as a full table. Missing values are replaced by
control$col_skip.nrowsOptional number of rows to read from each observed-data file. Missing values are replaced by
control$nrows.
Required columns are variable, type, calibrate, use_data, and
file. In addition, at least one of weight or cv must be supplied.
Weight handling
Aggregation weights are stored in the returned table regardless of whether the objective is later used in vector or scalar form.
If the table does not contain a weight column, weights are computed from
cv as 1 / (2 * cv^2). If weight exists but contains missing values,
those entries are filled using the same formula. All final weights must be
strictly positive.
Relationship with the rest of the workflow
A typical file-based calibration workflow is:
read the setup table with
calibration_setup();load observed data with
calibration_data();build the objective function with
calibration_objFn();pass the resulting function to
calibrate()or another optimiser.
Examples
if (FALSE) { # \dontrun{
demo = calibrar_demo(model = "PredatorPrey")
setup = calibration_setup(file = demo$setup)
setup
} # }
