FLSAM | R Documentation |
Performs a stock assessment using the State-Space assessment model (SAM)
FLSAM(stck, tun, ctrl, run.dir=tempdir(), batch.mode=FALSE,pin.sam=NULL)
update(object, stck, tun, run.dir=tempdir(),batch.mode=FALSE)
FLR2SAM(stck, tun, ctrl, run.dir = tempdir(),pin.sam=NULL)
runSAM(ctrl, run.dir=tempdir(),use.pin=FALSE)
SAM2FLR(ctrl="missing", admb.stem="sam", run.dir = tempdir())
stck |
|
tun |
|
ctrl |
|
run.dir |
Path to which the temporary files are to be written to or read from. Default is the R temporary directory provided by tempdir() |
batch.mode |
Logical variable indicating whether the code should be run in batch mode. |
object |
An object of the |
pin.sam |
Provide an FLSAM object, to be used as pin file, to the FLSAM function call to speed up the estimation process |
use.pin |
A logical variable indicating whether the SAM executable should look for a file containing initial parameter estimates (i.e. a pin file) |
admb.stem |
The name of the admb executable (ie without the .dat, .exe etc) |
FLSAM is an FLR wrapper to SAM, the state-space assessment model. SAM is written in the compiled ADMB language - compiled executables for each platform are included within the FLSAM package. The FLSAM function provides the interface between the data (FLStock
, FLIndices
objects) and configuration objects (FLSAM.control
) stored in R, and the compiled exectable.
Three helper functions provide the core of the FLSAM method. FLR2SAM accepts the necessary data objects and writes a series of text files to the path specified by run.dir. runSAM takes care of running the SAM executable and checking that the model has run to completion correctly. SAM2FLR reads the outputs generated by the SAM model and reads them back into the FLR environment. The FLSAM function provides a wrapper around these three functions, writing the data to the temporary directory, running the executable, and reading the results back. Generally, the user should not need to use FLR2SAM, runSAM or SAM2FLR, but they can be useful in helping to debug the code.
SAM2FLR is particularly useful when trying to read results of a SAM run into FLR for plotting, further analysis etc. Ideally it should be able to figure everything out from the contents of the directory containing the files. However, if this fails, it may be necessary to give it a helping hand by creating a (FLSAM.control
) object and supplying it via the "ctrl" argument.
The user can also specify the directory (via the 'run.dir' argument) in which the temporary files used to communication with SAM are stored. The default is to use the temporary directory of R.
FLSAM can also be run in "batch-mode" through the 'batch.mode' argument. This is a particularly useful feature when running a large number of assessments in an unattended situation. If the SAM model fails to converge in when running in batch-mode, it will suppress the error and return a "NULL" value (instead of an FLSAM object). If the model fails to converge when not running in batch-mode (the default), an error is returned.
It is also possible, via the 'update' function, to "reuse" the results of a previous stock assessment to provide initial guesses for the new assessment. Such a feature may be desirablie in situations where the user is running a large number of assessments that are very similar and have the same parameter configuration e.g. in a management-strategy evaluation. The supplied FLSAM object is used to generate a parameter-initialisation ("pin") file - the 'use.pin' argument in runSAM is then activated in this case, to tell the ADMB SAM executable to use these values. At the moment, it is not possible to change the assessment configuration in this manner - future releases will hopefully incorporate this feature.
The typical return value is an object of the FLSAM class with the following slots.
control |
The |
nohess |
Logical variable indicating whether the model was fit including the calculation of the hessian |
nopar |
The number of parameters fitted by the model |
n.states |
The number of states fitted internally in the model |
states |
The state coupling matrix - see |
nlogl |
The negative log-likelihood of the fitted parameters |
maxgrad |
The gradient of the negative log-likelihood at optimum |
vcov |
The variance-covariance matrix of the fitted parameters |
params |
The parameters fitted by the model, stored as a data.frame. The columns of the data frame are
|
stock.n |
An |
harvest |
An |
residuals |
A data.frame summarising the observed and fitted values, and the residuals linking them. The columns of the data frame are
|
name |
A text field giving the name of the object |
desc |
A text field describing the object |
range |
A named vector containg key information about range covered by the object
|
info |
Contains key information about the software versions and operating system used in running the assessment |
The FLSAM function will return an FLSAM object in all cases when the model converges. If the model does not converge, FLSAM will return an error unless it is running in batch mode, in which case it will return "NULL".
runSAM() returns an integer error code corresponding to the return value of the SAM model - 0 for a successful run, non-zero otherwise. SAM2FLR will return an FLSAM object. FLR2SAM does not return any values.
SAM2FLR based on code by Anders Nielsen and adapted by Mark Payne. FLR2SAM and FLSAM by Mark Payne
Nielsen et al (2012) In prep.
FLSAM.control
#Load library
library(FLSAM)
#Prepare data objects
data(NSH)
data(NSH.sam)
#Perform assessment
#Takes about two minutes on a 2.4GHz workstation
sam <- FLSAM(NSH,NSH.tun,NSH.ctrl)
sam <- FLSAM(NSH,NSH.tun,NSH.ctrl, return.fit=TRUE)
#If you want to re-use the sam object to create a pin file, use this:
sam <- FLSAM(NSH,NSH.tun,NSH.ctrl,pin.sam=sam)
#View results
plot(sam)
#Repeat the assessment using the previous result as an initial guess
uninit.time <- system.time(sam.uninit <- FLSAM(NSH,NSH.tun,NSH.ctrl))
#init.time <- system.time(sam.init <- update(sam.uninit,NSH,NSH.tun,NSH.ctrl))
#Big speed increase! (your results may vary: ours are about 2x)
#uninit.time[3]/init.time[3]
#But assessments are the sam (phew!)
#plot(FLSAMs(uninitialised=sam.uninit,initialised=sam.init))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.