optim_apsim: Optimize parameters in an APSIM simulation

View source: R/optim_apsim.R

optim_apsimR Documentation

Optimize parameters in an APSIM simulation

Description

It is a wrapper for running APSIM and optimizing parameters using optim

Friendly printing of optim_apsim

Variance-Covariance for an ‘optim_apsim’ object

Parameter estimates for an ‘optim_apsim’ object

Confidence intervals for parameter estimates for an ‘optim_apsim’ object

Usage

optim_apsim(
  file,
  src.dir = ".",
  crop.file,
  parm.paths,
  data,
  type = c("optim", "nloptr", "mcmc", "ucminf"),
  weights,
  index = "Date",
  parm.vector.index,
  xml.parm,
  ...
)

## S3 method for class 'optim_apsim'
print(x, ..., digits = 3, level = 0.95)

## S3 method for class 'optim_apsim'
vcov(object, ..., scaled = TRUE)

## S3 method for class 'optim_apsim'
coef(object, ..., scaled = FALSE)

## S3 method for class 'optim_apsim'
confint(object, parm, level = 0.95, ...)

Arguments

file

file name to be run (the extension .apsim is optional)

src.dir

directory containing the .apsim file to be run (defaults to the current directory)

crop.file

name of auxiliary xml file where parameters are stored. If this is missing, it is assumed that the parameters to be edited are in the main simulation file.

parm.paths

absolute paths of the coefficients to be optimized. It is recommended that you use inspect_apsim or inspect_apsim_xml for this.

data

data frame with the observed data. By default is assumes there is a 'Date' column for the index.

type

Type of optimization. For now, optim and, if available, nloptr or ‘mcmc’ through runMCMC. Option ‘ucminf’ uses the ucminf function.

weights

Weighting method or values for computing the residual sum of squares (see Note).

index

Index for filtering APSIM output. ‘Date’ is currently used. (I have not tested how well it works using anything other than Date).

parm.vector.index

Index to optimize a specific element of a parameter vector. At the moment it is possible to only edit one element at a time. This is because there is a conflict when generating multiple elements in the candidate vector for the same parameter.

xml.parm

optional logical vector used when optimizing parameters which are both in the .apsim file and in the ‘crop.file’. If ‘crop.file’ is missing it is assumed that the paramters to be optimized are in the .apsim file. If ‘crop.file’ is not missing it is assumed that they are in the ‘crop.file’. If the parameters are in both, this needs to be specified in this argument.

...

additional arguments (none used at the moment)

x

object of class ‘optim_apsim’

digits

number of digits to round up the output

level

confidence level (default is 0.95)

object

object of class ‘optim_apsim’

scaled

whether to return the scaled or unscaled estimates (TRUE in the optimized scale, FALSE in the original scale)

parm

parameter to select (it can be a regular expression)

Details

Simple optimization for APSIM Classic

* This function assumes that you want to optimize parameters which are stored in an auxiliary XML file. These are typically crop or cultivar specific parameters. However, it is possible to optimize parameters present in the main simulation file.

* Only one observation per day is allowed in the data.

* Given how APSIM Classic works, this can only be run when the main simulation file is in the current directory and the crop file (or XML) should be in the same directory as the main simulation.

* The initial values for the optimization should be the ones in the stored crop parameter file.

* It is suggested that you keep a backup of the original file. This function will edit and overwrite the file during the optimization.

* When you use the parm.vector.index you cannot edit two separate elements of a vector at the same time. This should be used to target a single element of a vector only.

* Internally, the optimization is done around the scaled value of the initial parameter values. A value of 1 would correspond to the inital value of the parameter. The ‘lower’ and ‘upper’ (or ‘ub’ and ‘lb’) are also scaled to the initial values of the parameters. So, for example, if your initial value is 20 and you provide an upper bound of 5, it means that the actual upper value that you are allowing for is 100.

Value

object of class ‘optim_apsim’, but really just a list with results from optim and additional information.

prints to console

it returns the variance-covariance matrix for an object of class ‘optim_apsim’.

a numeric vector with the value of the parameter estimates.

a matrix with lower and upper limits and the point estimate (coef)

Note

When computing the objective function (residual sum-of-squares) different variables are combined. It is common to weight them since they are in different units. If the argument weights is not supplied no weighting is applied. It can be ‘mean’, ‘var’ or a numeric vector of appropriate length.

This in the scale of the optimized parameters which are scaled to be around 1.


femiguez/apsimx documentation built on March 27, 2024, 12:36 a.m.