A virtual class for statistical models
FLModel(model, ...)
The FLModel
class provides a virtual class that developers of various
statistical models can use to implement classes that allow those models to
be tested, fitted and presented.
Slots in this class attempt to map all the usual outputs for a modelling
exercise, together with the standard inputs. Input data are stored in slots
created by a specified class based on FLModel
. See for example
FLSR
for a class used for stock-recruitment models.
The initial
slot contains a function used to obtain initial values for
the numerical solver. It can also contain two attributes, upper
and
lower
that limit the sarch area for each parameter.
Various fitting algorithms, similar to those present in the basic R packages,
are currently available for FLModel
, including fmle
,
nls-FLCore
and glm
.
character
.character
.numeric
.factor
.FLQuant
.FLQuant
.formula
.function
.function
.FLPar
, function
.FLPar
.logLik
.array
.array
.list
.# Normally, FLModel objects won't be created if "class" is not set summary(FLModel(length~width*alpha))#> An object of class "FLModel" #> #> Name: #> Description: #> Quant: quant #> Dims: quant year unit season area iter #> 1 1 1 1 1 1 #> #> Range: min max minyear maxyear #> NA NA 1 1 #> #> residuals : [ 1 1 1 1 1 1 ], units = NA #> fitted : [ 1 1 1 1 1 1 ], units = NA #> #> Model: length ~ width * alpha #> Parameters: #> params #> iter length width alpha #> 1 NA NA NA #> Log-likelihood: NA(NA) #> Variance-covariance: params #> params length width alpha #> length NA NA NA #> width NA NA NA #> alpha NA NA NA# Objects of FLModel-based classes use their own constructor, # which internally calls FLModel fsr <- FLModel(rec~ssb*a, class='FLSR') is(fsr)#> [1] "FLSR" "FLModel" "FLComp"summary(fsr)#> An object of class "FLSR" #> #> Name: #> Description: #> Quant: quant #> Dims: quant year unit season area iter #> 1 1 1 1 1 1 #> #> Range: min max minyear maxyear #> NA NA 1 1 #> #> rec : [ 1 1 1 1 1 1 ], units = NA #> ssb : [ 1 1 1 1 1 1 ], units = NA #> residuals : [ 1 1 1 1 1 1 ], units = NA #> fitted : [ 1 1 1 1 1 1 ], units = NA #> #> Model: rec ~ ssb * a #> Parameters: #> params #> iter a #> 1 NA #> Log-likelihood: NA(NA) #> Variance-covariance: params #> params a #> a NA# An example constructor method for an FLModel-based class # Create class FLGrowth with a single new slot, 'mass' setClass('FLGrowth', representation('FLModel', mass='FLArray')) # Define a creator method based on FLModel setGeneric("FLGrowth", function(object, ...) standardGeneric("FLGrowth"))#> [1] "FLGrowth"setMethod('FLGrowth', signature(object='ANY'), function(object, ...) return(FLModel(object, ..., class='FLGrowth')))#> [1] "FLGrowth"setMethod('FLGrowth', signature(object='missing'), function(...) return(FLModel(formula(NULL), ..., class='FLGrowth')))#> [1] "FLGrowth"# Define an accessor method setMethod('mass', signature(object='FLGrowth'), function(object) return(slot(object, 'mass')))#> [1] "mass"