Individual Growth – Other Nonlinear Model Fitting Algorithms

Other Nonlinear Model Fitting Algorithms

The von Bertalanffy Growth Function (VBGF) was introduced and methods for fitting the function were illustrated in Chapter 12 of the Introductory Fisheries Analyses with R (IFAR) book. The nls() function demonstrated in the IFAR book uses the Gauss-Newton algorithm by default. However, there are many other algorithms for fitting nonlinear functions. Two of the several algorithms coded in R are demonstrated in this supplement. Other supplements demonstrate how to fit other parameterizations of the VBGF and other growth functions.

 

Required Packages for this Supplement

Functions used in this supplement require the packages shown below.

> library(FSA)
> library(dplyr)
> library(nlstools)
> library(minpack.lm)

Data Used in this Supplement

The male Black Drum data (viewdownloadmeta-data) used in the IFAR book will also be used in this supplement.

> bdmf <- read.csv("BlackDrum2001.csv") %>%
    select(-c(spname,day,weight)) %>%
    filterD(sex %in% c("male","female"),otoage<50)
> bdm <- filterD(bdmf,sex=="male")
> headtail(bdm)
   year agid month     tl  sex otoage
1  2001    1     4  787.5 male      6
2  2001    2     5  700.0 male      5
3  2001    8     5 1140.0 male     23
72 2001  122     5 1175.0 male     39
73 2001  125     6  590.0 male      4
74 2001  127     6  530.0 male      3

 

Levenberg-Marquardt Algorithm

The Levenberg-Marquardt (L-M) algorithm is a powerful and common method that switches between two other algorithms depending on when those algorithms perform most optimally (Motulsky and Ransnas 1987). Most practically, the L-M algorithm appears to be quite robust to “poor” starting values.

The L-M algorithm is implemented in nlsLM() from minpack.lm (Elzhov et al. 2013) and uses the same main arguments as nls(). For example, the “Typical” VBGF is fit (and parameter estimates, likelihood profile confidence intervals, and predictions are extracted) to the male Black Drum data below using the L-M algorithm.

> vbTyp <- vbFuns()
> svTyp <- list(Linf=1193,K=0.13,t0=-2.0)
> fitLM <- nlsLM(tl~vbTyp(otoage,Linf,K,t0),data=bdm,start=svTyp)
> bootLM <- nlsBoot(fitLM)
> cbind(Ests=coef(fitLM),confint(bootLM))
             Ests      95% LCI      95% UCI
Linf 1196.7193456 1179.8720413 1214.7444331
K       0.1418266    0.1241443    0.1622749
t0     -1.5943403   -2.5034835   -0.8176289
> predict(bootLM,vbTyp,t=3)
prediction    95% LCI    95% UCI 
  572.8113   535.0526   606.2789 

 

Algorithms that Allow Parameter Constraints

In some instances, the user may want to constrain the model fitting algorithms to only consider parameter values within a certain range. For example, the user may want to constrain the LL∞ and KK parameters of the “Typical” VBGF to be positive. Parameter constraints may substantively effect the results of the model fitting. Thus, they should be used rarely and, when used, set liberally.

Parameter constraints can be used with at least two algorithms in R. In either case, the lower and upper bounds for each parameter are entered into separate named vectors in the same order as the list used for starting values. Infinite bounds are the default ,but may be specifically defined for some parameters with Inf and -Inf (where Inf represents infinity). For example, vectors that define constraints for the parameters in the “Typical” VBGF are defined below, with LL∞ and KK constrained to be positive values and t0t0 left unconstrained.

> clwr <- c(Linf=1,  K=0.0001,t0=-Inf)
> cupr <- c(Linf=Inf,K=Inf,   t0=Inf)

These constraints may be provided to lower= and upper=, respectively, of nlsLM(). In this instance, these bounds had no noticeable effect until bootstapping, where there were fewer instances of lack of convergence.

> fitLM1 <- nlsLM(tl~vbTyp(otoage,Linf,K,t0),data=bdm,start=svTyp,lower=clwr,upper=cupr)
> bootLM1 <- nlsBoot(fitLM1)
> cbind(Ests=coef(fitLM1),confint(bootLM1))
             Ests      95% LCI      95% UCI
Linf 1196.7193456 1177.7663812 1214.8739079
K       0.1418266    0.1225476    0.1633342
t0     -1.5943403   -2.6332131   -0.7804033

Parameter constraints may be used similarly with nls(), but the optimization algorithm must be changed to “Port” with algorithm="port".

> fitP <- nls(tl~vbTyp(otoage,Linf,K,t0),data=bdm,start=svTyp,
              algorithm="port",lower=clwr,upper=cupr)
> bootP <- nlsBoot(fitP)
> cbind(Ests=coef(fitP),confint(bootP))
             Ests     95% LCI      95% UCI
Linf 1196.7188609 1177.616313 1215.1724867
K       0.1418273    0.123604    0.1633974
t0     -1.5943118   -2.578606   -0.8138321

 

Other Algorithms

Still other algorithms are found in nlxb() from nlmrt (Nash 2014) and nls2() from nls2 (Grothendieck 2013).

 


Reproducibility Information

  • Compiled Date: Fri Nov 06 2015
  • Compiled Time: 10:04:38 AM
  • R Version: R version 3.2.2 (2015-08-14)
  • System: Windows, i386-w64-mingw32/i386 (32-bit)
  • Base Packages: base, datasets, graphics, grDevices, methods, stats, utils
  • Required Packages: FSA, dplyr, nlstools, minpack.lm, captioner, knitr and their dependencies (assertthat, car, DBI, digest, evaluate, formatR, gdata, gplots, graphics, grDevices, highr, Hmisc, lazyeval, magrittr, markdown, methods, plotrix, plyr, R6, Rcpp, sciplot, stats, stringr, tools, utils, yaml)
  • Other Packages: captioner_2.2.3, dplyr_0.4.3, extrafont_0.17, FSA_0.8.4, knitr_1.11, minpack.lm_1.1-9, nlstools_1.0-2
  • Loaded-Only Packages: assertthat_0.1, DBI_0.3.1, digest_0.6.8, evaluate_0.8, extrafontdb_1.0, formatR_1.2.1, gdata_2.17.0, gtools_3.5.0, htmltools_0.2.6, lazyeval_0.1.10, magrittr_1.5, parallel_3.2.2, plyr_1.8.3, R6_2.1.1, Rcpp_0.12.1, rmarkdown_0.8.1, Rttf2pt1_1.3.3, stringi_1.0-1, stringr_1.0.0, tools_3.2.2, yaml_2.1.13
  • Links: Script / RMarkdown

 

References

Elzhov, T. V., K. M. Mullen, A.-N. Spiess, and B. M. Bolker. 2013. minpack.lm: R interface to the Levenberg-Marquardt nonlinear least-squares algorithm found in MINPACK, plus support for bounds.

Grothendieck, G. 2013. nls2: Non-linear regression with brute force.

Motulsky, H. J., and L. A. Ransnas. 1987. Fitting curves to data using nonlinear regression: A practical and nonmathematical review. The Federation of American Societies for Experimental Biology Journal 1:365–374.

Nash, J. C. 2014. nlmrt: Functions for nonlinear least squares solutions.