├── .gitignore ├── .Rbuildignore ├── growthmodels.Rproj ├── DESCRIPTION ├── tests ├── testthat.R └── testthat │ ├── testJanoschek.R │ ├── testBrody.R │ ├── testMitcherlich.R │ ├── testGompertz.R │ ├── testWeibull.R │ ├── testMmf.R │ ├── testNegativeExponential.R │ ├── testSchnute.R │ ├── testMonomolecular.R │ ├── testStannard.R │ ├── testChapmanRichards.R │ ├── testVonBertalanffy.R │ ├── testLoglogistic.R │ ├── testBlumberg.R │ ├── testLogistic.R │ └── testRichard.R ├── man ├── janoschek.Rd ├── logistic.Rd ├── gompertz.Rd ├── weibull.Rd ├── negativeExponential.Rd ├── richard.Rd ├── schnute.Rd ├── loglogistic.Rd ├── monomolecular.Rd ├── blumberg.Rd ├── mitcherlich.Rd ├── stannard.Rd ├── brody.Rd ├── mmf.Rd ├── generalisedLogistic.Rd ├── vonBertalanffy.Rd ├── chapmanRichards.Rd ├── generalisedRichard.Rd └── growthmodels-package.Rd ├── NAMESPACE ├── NEWS ├── R ├── growthmodels.R ├── janoschek.R ├── blumberg.R ├── gompertz.R ├── schnute.R ├── weibull.R ├── negativeExponential.R ├── monomolecular.R ├── brody.R ├── loglogistic.R ├── mmf.R ├── stannard.R ├── mitcherlich.R ├── chapmanRichards.R ├── vonBertalanffy.R ├── logistic.R └── richard.R └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | growthmodels.Rproj 2 | README.md 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | -------------------------------------------------------------------------------- /growthmodels.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageInstallArgs: --no-multiarch 17 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: growthmodels 2 | Type: Package 3 | Title: Nonlinear Growth Models 4 | Version: 1.2.0 5 | Date: 2013-11-23 6 | Author: Daniel Rodriguez 7 | Maintainer: Daniel Rodriguez 8 | Description: A compilation of nonlinear growth models. 9 | License: GPL-3 10 | URL: https://github.com/drodriguezperez/growthmodels 11 | BugReports: https://github.com/drodriguezperez/growthmodels/issues 12 | Suggests: 13 | testthat 14 | Roxygen: list(wrap = FALSE) 15 | RoxygenNote: 6.0.1 16 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Unit testing file 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 7/12/2014. 5 | ## 6 | ## Copyright (c) 2014 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | library(testthat) 23 | library(growthmodels) 24 | 25 | test_check("growthmodels") 26 | -------------------------------------------------------------------------------- /man/janoschek.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/janoschek.R 3 | \name{janoschek} 4 | \alias{janoschek} 5 | \alias{janoschek.inverse} 6 | \title{Janoschek growth model} 7 | \usage{ 8 | janoschek(t, alpha, beta, b, c) 9 | 10 | janoschek.inverse(x, alpha, beta, b, c) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{lower asymptote} 18 | 19 | \item{b}{growth parameter} 20 | 21 | \item{c}{shape parameter} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the Janoschek growth model and its inverse 27 | \deqn{ y(t) = \alpha *(\alpha - \beta) \exp(-b * t^c)) } 28 | } 29 | \examples{ 30 | growth <- janoschek(0:10, 10, 2, 0.5, 2) 31 | 32 | # Calculate inverse function 33 | time <- janoschek.inverse(growth, 12, 2, 0.5, 2) 34 | 35 | } 36 | \references{ 37 | Michael J. Panik, "Growth Curve Modeling: Theory and Applications", 38 | John Wiley & Sons, December 2013. 39 | } 40 | \author{ 41 | Daniel Rodriguez 42 | } 43 | -------------------------------------------------------------------------------- /man/logistic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/logistic.R 3 | \name{logistic} 4 | \alias{logistic} 5 | \alias{logistic.inverse} 6 | \title{Logistic growth model} 7 | \usage{ 8 | logistic(t, alpha, beta, k) 9 | 10 | logistic.inverse(x, alpha, beta, k) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{growth range} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{x}{size} 22 | } 23 | \description{ 24 | Computes the Logistic growth model 25 | \deqn{ y(t) = \frac{\alpha}{1 + \beta exp(-k t)}}{ y(t) = \alpha/(1 + \beta * exp(-k * t))} 26 | } 27 | \examples{ 28 | growth <- logistic(0:10, 10, 0.5, 0.3) 29 | 30 | # Calculate inverse function 31 | time <- logistic.inverse(growth, 10, 0.5, 0.3) 32 | 33 | } 34 | \references{ 35 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 36 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 37 | 327-336, 1999. 38 | } 39 | \author{ 40 | Daniel Rodriguez 41 | } 42 | -------------------------------------------------------------------------------- /man/gompertz.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gompertz.R 3 | \name{gompertz} 4 | \alias{gompertz} 5 | \alias{gompertz.inverse} 6 | \title{Gompertz growth model} 7 | \usage{ 8 | gompertz(t, alpha, beta, k) 9 | 10 | gompertz.inverse(x, alpha, beta, k) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{growth displacement} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{x}{size} 22 | } 23 | \description{ 24 | Computes the Gompertz growth model and its inverse 25 | \deqn{ y(t) = \alpha exp(-\beta exp(-k^t))}{ y(t) = \alpha * exp(-\beta * exp(-k^t))} 26 | } 27 | \examples{ 28 | growth <- gompertz(0:10, 10, 0.5, 0.3) 29 | 30 | # Calculate inverse function 31 | time <- gompertz.inverse(growth, 10, 0.5, 0.3) 32 | 33 | } 34 | \references{ 35 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 36 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 37 | 327-336, 1999. 38 | } 39 | \author{ 40 | Daniel Rodriguez 41 | } 42 | -------------------------------------------------------------------------------- /man/weibull.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/weibull.R 3 | \name{weibull} 4 | \alias{weibull} 5 | \alias{weibull.inverse} 6 | \title{Weibull growth model} 7 | \usage{ 8 | weibull(t, alpha, beta, k, m) 9 | 10 | weibull.inverse(x, alpha, beta, k, m) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{growth range} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{m}{slope of growth} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the Weibull growth model 27 | \deqn{ y(t) = \alpha - \beta exp(-k * t^m) }{ y(t) = \alpha - \beta * exp(-k * t^m) } 28 | } 29 | \examples{ 30 | growth <- weibull(0:10, 10, 0.5, 0.3, 0.5) 31 | 32 | # Calculate inverse function 33 | time <- weibull.inverse(growth, 10, 0.5, 0.3, 0.5) 34 | 35 | } 36 | \references{ 37 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 38 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 39 | 327-336, 1999. 40 | } 41 | \author{ 42 | Daniel Rodriguez 43 | } 44 | -------------------------------------------------------------------------------- /man/negativeExponential.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/negativeExponential.R 3 | \name{negativeExponential} 4 | \alias{negativeExponential} 5 | \alias{negativeExponential.inverse} 6 | \title{Negative exponential growth model} 7 | \usage{ 8 | negativeExponential(t, alpha, k) 9 | 10 | negativeExponential.inverse(x, alpha, k) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{k}{growth rate} 18 | 19 | \item{x}{size} 20 | } 21 | \description{ 22 | Computes the negative exponential growth model 23 | \deqn{ y(t) = \alpha ( 1 - exp(-k t))}{ y(t) = \alpha * ( 1 - exp(-k * t))} 24 | } 25 | \examples{ 26 | growth <- negativeExponential(0:10, 1, 0.3) 27 | 28 | # Calculate inverse function 29 | time <- negativeExponential.inverse(growth, 10, 0.3) 30 | 31 | } 32 | \references{ 33 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 34 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 35 | 327-336, 1999. 36 | } 37 | \author{ 38 | Daniel Rodriguez 39 | } 40 | -------------------------------------------------------------------------------- /man/richard.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/richard.R 3 | \name{richard} 4 | \alias{richard} 5 | \alias{richard.inverse} 6 | \title{Richard growth model} 7 | \usage{ 8 | richard(t, alpha, beta, k, m) 9 | 10 | richard.inverse(x, alpha, beta, k, m) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{growth range} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{m}{slope of growth} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the Richard growth model and its inverse 27 | \deqn{ y(t) = \frac{\alpha}{(1 + \beta exp(-k t))^{(1/m)}}}{ y(t) = \alpha/((1 + \beta * exp(-k * t))^(1 / m))} 28 | } 29 | \examples{ 30 | growth <- richard(0:10, 10, 0.5, 0.3, 0.5) 31 | 32 | time <- richard.inverse(growth, 10, 0.5, 0.3, 0.5) 33 | 34 | } 35 | \references{ 36 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 37 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 38 | 327-336, 1999. 39 | } 40 | \author{ 41 | Daniel Rodriguez 42 | } 43 | -------------------------------------------------------------------------------- /man/schnute.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/schnute.R 3 | \name{schnute} 4 | \alias{schnute} 5 | \alias{schnute.inverse} 6 | \title{Schnute growth model} 7 | \usage{ 8 | schnute(t, r0, beta, k, m) 9 | 10 | schnute.inverse(x, r0, beta, k, m) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{r0}{reference value} 16 | 17 | \item{beta}{growth displacement} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{m}{slope of growth} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the Schnute growth model 27 | \deqn{ y(t) = \left[ r_0 + \beta exp(k t) \right]^m }{ y(t) = (r_0 + \beta * exp(k * t))^m } 28 | } 29 | \examples{ 30 | growth <- schnute(0:10, 10, 5, .5, .5) 31 | 32 | # Calculate inverse function 33 | time <- schnute.inverse(growth, 10, 5, .5, .5) 34 | 35 | } 36 | \references{ 37 | A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 38 | modeling oil palm yield growth," Journal of Mathematics and Statistics, 39 | vol. 1, no. 3, p. 225, 2005. 40 | } 41 | \author{ 42 | Daniel Rodriguez 43 | } 44 | -------------------------------------------------------------------------------- /man/loglogistic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loglogistic.R 3 | \name{loglogistic} 4 | \alias{loglogistic} 5 | \alias{loglogistic.inverse} 6 | \title{Log-logistic growth model} 7 | \usage{ 8 | loglogistic(t, alpha, beta, k) 9 | 10 | loglogistic.inverse(x, alpha, beta, k) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{growth range} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{x}{size} 22 | } 23 | \description{ 24 | Computes the Log-logistic growth model 25 | \deqn{ y(t) = \frac{\alpha}{1 + \beta exp(-k log(t)}}{ y(t) = \alpha/(1 + \beta * exp(-k * log(t))} 26 | } 27 | \examples{ 28 | growth <- loglogistic(0:10, 10, 0.5, 0.3) 29 | 30 | # Calculate inverse function 31 | time <- loglogistic.inverse(growth, 10, 0.5, 0.3) 32 | 33 | } 34 | \references{ 35 | A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 36 | modeling oil palm yield growth," Journal of Mathematics and Statistics, 37 | vol. 1, no. 3, p. 225, 2005. 38 | } 39 | \author{ 40 | Daniel Rodriguez 41 | } 42 | -------------------------------------------------------------------------------- /man/monomolecular.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/monomolecular.R 3 | \name{monomolecular} 4 | \alias{monomolecular} 5 | \alias{monomolecular.inverse} 6 | \title{Monomolecular growth model} 7 | \usage{ 8 | monomolecular(t, alpha, beta, k) 9 | 10 | monomolecular.inverse(x, alpha, beta, k) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{growth range} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{x}{size} 22 | } 23 | \description{ 24 | Computes the monomolecular growth model 25 | \deqn{ y(t) = \alpha ( 1 - \beta exp(-k t))}{ y(t) = \alpha * ( 1 - \beta * exp(-k * t))} 26 | } 27 | \examples{ 28 | growth <- monomolecular(0:10, 10, 0.5, 0.3) 29 | 30 | # Calculate inverse function 31 | time <- monomolecular.inverse(growth, 10, 0.5, 0.3) 32 | 33 | } 34 | \references{ 35 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 36 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 37 | 327-336, 1999. 38 | } 39 | \author{ 40 | Daniel Rodriguez 41 | } 42 | -------------------------------------------------------------------------------- /man/blumberg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/blumberg.R 3 | \name{blumberg} 4 | \alias{blumberg} 5 | \alias{blumberg.inverse} 6 | \title{Blumberg growth model} 7 | \usage{ 8 | blumberg(t, alpha, w0, m, t0 = 0) 9 | 10 | blumberg.inverse(x, alpha, w0, m, t0 = 0) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{w0}{a reference value at t = t0} 18 | 19 | \item{m}{slope of growth} 20 | 21 | \item{t0}{time shift (default 0)} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the Blumberg growth model and its inverse 27 | \deqn{ y(t) = \frac{\alpha * (t + t_0)^m}{w_0 + (t + t_0)^m}}{y(t) = (\alpha * (t - t_0)^m)/(w_0 + (t - t_0)^m)} 28 | } 29 | \examples{ 30 | growth <- blumberg(0:10, 10, 2, 0.5) 31 | 32 | # Calculate inverse function 33 | time <- blumberg.inverse(growth, 12, 2, 0.5) 34 | 35 | } 36 | \references{ 37 | A. Tsoularis and J. Wallace, "Analysis of logistic growth models.," 38 | Math Biosci, vol. 179, no. 1, pp. 21-55, Jul. 2002. 39 | } 40 | \author{ 41 | Daniel Rodriguez 42 | } 43 | -------------------------------------------------------------------------------- /man/mitcherlich.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mitcherlich.R 3 | \name{mitcherlich} 4 | \alias{mitcherlich} 5 | \alias{mitscherlich} 6 | \alias{mitcherlich.inverse} 7 | \alias{mitscherlich.inverse} 8 | \title{Mitcherlich growth model} 9 | \usage{ 10 | mitcherlich(t, alpha, beta, k) 11 | 12 | mitcherlich.inverse(x, alpha, beta, k) 13 | } 14 | \arguments{ 15 | \item{t}{time} 16 | 17 | \item{alpha}{upper asymptote} 18 | 19 | \item{beta}{growth range} 20 | 21 | \item{k}{growth rate} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the Mitcherlich growth model 27 | \deqn{ y(t) = (\alpha - \beta k^t)}{ y(t) = \alpha - \beta * k^t} 28 | } 29 | \examples{ 30 | growth <- mitcherlich(0:10, 10, 0.5, 0.3) 31 | 32 | # Calculate inverse function 33 | time <- mitcherlich.inverse(growth, 10, 0.5, 0.3) 34 | 35 | } 36 | \references{ 37 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 38 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 39 | 327-336, 1999. 40 | } 41 | \author{ 42 | Daniel Rodriguez 43 | } 44 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(blumberg) 4 | export(blumberg.inverse) 5 | export(brody) 6 | export(brody.inverse) 7 | export(chapmanRichards) 8 | export(chapmanRichards.inverse) 9 | export(generalisedLogistic) 10 | export(generalisedLogistic.inverse) 11 | export(generalisedRichard) 12 | export(generalisedRichard.inverse) 13 | export(gompertz) 14 | export(gompertz.inverse) 15 | export(janoschek) 16 | export(janoschek.inverse) 17 | export(logistic) 18 | export(logistic.inverse) 19 | export(loglogistic) 20 | export(loglogistic.inverse) 21 | export(mitcherlich) 22 | export(mitcherlich.inverse) 23 | export(mitscherlich) 24 | export(mitscherlich.inverse) 25 | export(mmf) 26 | export(mmf.inverse) 27 | export(monomolecular) 28 | export(monomolecular.inverse) 29 | export(negativeExponential) 30 | export(negativeExponential.inverse) 31 | export(richard) 32 | export(richard.inverse) 33 | export(schnute) 34 | export(schnute.inverse) 35 | export(stannard) 36 | export(stannard.inverse) 37 | export(vonBertalanffy) 38 | export(vonBertalanffy.inverse) 39 | export(weibull) 40 | export(weibull.inverse) 41 | -------------------------------------------------------------------------------- /man/stannard.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/stannard.R 3 | \name{stannard} 4 | \alias{stannard} 5 | \alias{stannard.inverse} 6 | \title{Stannard growth model} 7 | \usage{ 8 | stannard(t, alpha, beta, k, m) 9 | 10 | stannard.inverse(x, alpha, beta, k, m) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{growth displacement} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{m}{slope of growth} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the Stannard growth model 27 | \deqn{ y(t) = \alpha \left[ 1 + exp(-(\beta + k t)/m) \right]^{-m}}{ y(t) = \alpha *( 1 + exp(-(beta + k * t)/m))^(-m) } 28 | } 29 | \examples{ 30 | growth <- stannard(0:10, 1, .2, .1, .5) 31 | 32 | # Calculate inverse function 33 | time <- stannard.inverse(growth, 1, .2, .1, .5) 34 | 35 | } 36 | \references{ 37 | A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 38 | modeling oil palm yield growth," Journal of Mathematics and Statistics, 39 | vol. 1, no. 3, p. 225, 2005. 40 | } 41 | \author{ 42 | Daniel Rodriguez 43 | } 44 | -------------------------------------------------------------------------------- /man/brody.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/brody.R 3 | \name{brody} 4 | \alias{brody} 5 | \alias{brody.inverse} 6 | \title{Brody growth model} 7 | \usage{ 8 | brody(t, alpha, w0, k) 9 | 10 | brody.inverse(x, alpha, w0, k) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{w0}{the value at t = 0} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{x}{size} 22 | } 23 | \description{ 24 | Computes the Brody growth model and its inverse 25 | \deqn{ y(t) = \alpha - (\alpha - w_0) exp(- k t) }{ y(t) = \alpha - (\alpha - w_0) * exp(- k * t) } 26 | } 27 | \examples{ 28 | growth <- brody(0:10, 10, 5, 0.3) 29 | 30 | # Calculate inverse function 31 | time <- brody.inverse(growth, 10, 5, 0.3) 32 | 33 | } 34 | \references{ 35 | M. M. Kaps, W. O. W. Herring, and W. R. W. Lamberson, "Genetic and 36 | environmental parameters for traits derived from the Brody growth curve and 37 | their relationships with weaning weight in Angus cattle.," Journal of 38 | Animal Science, vol. 78, no. 6, pp. 1436-1442, May 2000. 39 | } 40 | \author{ 41 | Daniel Rodriguez 42 | } 43 | -------------------------------------------------------------------------------- /man/mmf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmf.R 3 | \name{mmf} 4 | \alias{mmf} 5 | \alias{mmf.inverse} 6 | \title{Morgan-Mercer-Flodin growth model} 7 | \usage{ 8 | mmf(t, alpha, w0, gamma, m) 9 | 10 | mmf.inverse(x, alpha, w0, gamma, m) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{w0}{the value at t = 0} 18 | 19 | \item{gamma}{parameter that controls the point of inflection} 20 | 21 | \item{m}{growth rate} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the Morgan-Mercer-Flodin growth model 27 | \deqn{ y(t) = \frac{(w_0 \gamma + \alpha t^m)}{\gamma} +t^m}{ y(t) = (w_0 * \gamma + \alpha * t^m) / (\gamma + t^m)} 28 | } 29 | \examples{ 30 | growth <- mmf(0:10, 10, 0.5, 4, 1) 31 | 32 | # Calculate inverse function 33 | time <- mmf.inverse(growth, 10, 0.5, 4, 1) 34 | 35 | } 36 | \references{ 37 | A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 38 | modeling oil palm yield growth," Journal of Mathematics and Statistics, 39 | vol. 1, no. 3, p. 225, 2005. 40 | } 41 | \author{ 42 | Daniel Rodriguez 43 | } 44 | -------------------------------------------------------------------------------- /man/generalisedLogistic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/logistic.R 3 | \name{generalisedLogistic} 4 | \alias{generalisedLogistic} 5 | \alias{generalisedLogistic.inverse} 6 | \title{Generalised Logistic growth model} 7 | \usage{ 8 | generalisedLogistic(t, A, U, k, beta, t0) 9 | 10 | generalisedLogistic.inverse(x, A, U, k, beta, t0 = 0) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{A}{the lower asymptote} 16 | 17 | \item{U}{the upper asymptote} 18 | 19 | \item{k}{growth range} 20 | 21 | \item{beta}{growth range} 22 | 23 | \item{t0}{time shift (default 0)} 24 | 25 | \item{x}{size} 26 | } 27 | \description{ 28 | Computes the Generalised Logistic growth model 29 | \deqn{ y(t) = A + \frac{U - A}{1 + \beta exp(-k (t- t_0))}}{ y(t) = A + (U - A)/(1 + \beta * exp(-k * (t- t_0)))} 30 | } 31 | \examples{ 32 | growth <- generalisedLogistic(0:10, 5, 10, 0.3, 0.5, 3) 33 | 34 | # Calculate inverse function 35 | time <- generalisedLogistic.inverse(growth, 5, 10, 0.3, 0.5, 3) 36 | 37 | } 38 | \references{ 39 | http://en.wikipedia.org/wiki/Generalised_logistic_function 40 | } 41 | \author{ 42 | Daniel Rodriguez 43 | } 44 | -------------------------------------------------------------------------------- /man/vonBertalanffy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vonBertalanffy.R 3 | \name{vonBertalanffy} 4 | \alias{vonBertalanffy} 5 | \alias{vonBertalanffy.inverse} 6 | \title{von Bertalanffy growth model} 7 | \usage{ 8 | vonBertalanffy(t, alpha, beta, k, m) 9 | 10 | vonBertalanffy.inverse(x, alpha, beta, k, m) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{growth range} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{m}{slope of growth} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the von Bertalanffy growth model 27 | \deqn{ y(t) = (\alpha^(1-m) - \beta * exp(-k t))^(1/(1-m)) }{ y(t) = (\alpha^(1-m) - \beta * exp(-k * t))^(1/(1-m)) } 28 | } 29 | \examples{ 30 | growth <- vonBertalanffy(0:10, 10, 0.5, 0.3, 0.5) 31 | 32 | # Calculate inverse function 33 | time <- vonBertalanffy.inverse(growth, 10, 0.5, 0.3, 0.5) 34 | 35 | } 36 | \references{ 37 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 38 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 39 | 327-336, 1999. 40 | } 41 | \author{ 42 | Daniel Rodriguez 43 | } 44 | -------------------------------------------------------------------------------- /man/chapmanRichards.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chapmanRichards.R 3 | \name{chapmanRichards} 4 | \alias{chapmanRichards} 5 | \alias{chapmanRichards.inverse} 6 | \title{Chapman-Richards growth model} 7 | \usage{ 8 | chapmanRichards(t, alpha, beta, k, m) 9 | 10 | chapmanRichards.inverse(x, alpha, beta, k, m) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{alpha}{upper asymptote} 16 | 17 | \item{beta}{growth range} 18 | 19 | \item{k}{growth rate} 20 | 21 | \item{m}{slope of growth} 22 | 23 | \item{x}{size} 24 | } 25 | \description{ 26 | Computes the Chapman-Richards growth model and its inverse 27 | \deqn{ y(t) = \alpha (1 - \beta exp(-k t)^{1/(1-m)}) }{ y(t) = \alpha * (1 - \beta * exp(-k * t)^{1/(1-m)}) } 28 | } 29 | \examples{ 30 | growth <- chapmanRichards(0:10, 10, 0.5, 0.3, 0.5) 31 | 32 | # Calculate inverse function 33 | time <- chapmanRichards.inverse(growth, 10, 0.5, 0.3, 0.5) 34 | 35 | } 36 | \references{ 37 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 38 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 39 | 327-336, 1999. 40 | } 41 | \author{ 42 | Daniel Rodriguez 43 | } 44 | -------------------------------------------------------------------------------- /man/generalisedRichard.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/richard.R 3 | \name{generalisedRichard} 4 | \alias{generalisedRichard} 5 | \alias{generalisedRichard.inverse} 6 | \title{Generalised Richard growth model} 7 | \usage{ 8 | generalisedRichard(t, A, U, k, m, beta, t0) 9 | 10 | generalisedRichard.inverse(x, A, U, k, m, beta, t0 = 0) 11 | } 12 | \arguments{ 13 | \item{t}{time} 14 | 15 | \item{A}{the lower asymptote} 16 | 17 | \item{U}{the upper asymptote} 18 | 19 | \item{k}{growth range} 20 | 21 | \item{m}{slope of growth} 22 | 23 | \item{beta}{growth range} 24 | 25 | \item{t0}{time shift (default 0)} 26 | 27 | \item{x}{size} 28 | } 29 | \description{ 30 | Computes the Generalised Richard growth model and its inverse 31 | \deqn{ y(t) = A + \frac{U - A}{(1 + \beta exp(-k (t - t_0)))^{(1/m)} }}{ y(t) = A + (U - A)/(1 + \beta * exp(-k * (t - t_0)))^{(1/m)} } 32 | } 33 | \examples{ 34 | growth <- generalisedRichard(0:10, 5, 10, 0.3, 0.5, 1, 3) 35 | 36 | time <- generalisedRichard.inverse(growth, 5, 10, 0.3, 0.5, 1, 3) 37 | 38 | } 39 | \references{ 40 | http://en.wikipedia.org/wiki/Generalised_logistic_function 41 | } 42 | \author{ 43 | Daniel Rodriguez 44 | } 45 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | growthmodels 1.3.0 2 | -------------------------------------------------------------------------------- 3 | * This version includes new nonlinear growth models: 4 | Janoschek 5 | * `mitscherlich` alias to the `mitcherlich` function 6 | 7 | growthmodels 1.2.0 8 | -------------------------------------------------------------------------------- 9 | 10 | * This version includes new nonlinear growth models: 11 | Blumberg 12 | * Mitcherlich growth model can be called using mitcherlich or mitscherlich 13 | * Include the inverse functions for the models 14 | 15 | growthmodels 1.1.0 16 | -------------------------------------------------------------------------------- 17 | 18 | * This version includes new nonlinear growth models: 19 | Brody 20 | Log-logistic, 21 | Morgan-Mercer-Flodin, 22 | Schnute, 23 | Stannard. 24 | 25 | growthmodels 1.0.0 26 | -------------------------------------------------------------------------------- 27 | 28 | * `growthmodels` includes the following nonlinear growth models: 29 | Chapman-Richards, 30 | Generalised Logistic, 31 | Generalised Richard, 32 | Gompertz, 33 | Logistic, 34 | Mitcherlich, 35 | Monomolecular, 36 | Negative exponential, 37 | Richard’s, 38 | von Bertalanffy, 39 | Weibull. 40 | -------------------------------------------------------------------------------- /R/growthmodels.R: -------------------------------------------------------------------------------- 1 | #' growthmodels: Nonlinear Growth Models 2 | #' 3 | #' A compilation of nonlinear growth models. 4 | #' 5 | #' \tabular{ll}{ 6 | #' Package: \tab growthmodels \cr 7 | #' Version: \tab 1.2.0 \cr 8 | #' License: \tab GPL-3 \cr 9 | #' } 10 | #' 11 | #' @author Daniel Rodriguez \email{daniel.rodriguez.perez@@gmail.com} 12 | #' 13 | #' @references 14 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 15 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 16 | #' 327-336, 1999. 17 | #' 18 | #' M. M. Kaps, W. O. W. Herring, and W. R. W. Lamberson, "Genetic and 19 | #' environmental parameters for traits derived from the Brody growth curve and 20 | #' their relationships with weaning weight in Angus cattle.," Journal of 21 | #' Animal Science, vol. 78, no. 6, pp. 1436-1442, May 2000. 22 | #' 23 | #' A. Tsoularis and J. Wallace, "Analysis of logistic growth models.," 24 | #' Math Biosci, vol. 179, no. 1, pp. 21-55, Jul. 2002. 25 | #' 26 | #' A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 27 | #' modeling oil palm yield growth," Journal of Mathematics and Statistics, 28 | #' vol. 1, no. 3, p. 225, 2005. 29 | #' 30 | #' Michael J. Panik, "Growth Curve Modeling: Theory and Applications", 31 | #' John Wiley & Sons, December 2013. 32 | #' 33 | #' http://en.wikipedia.org/wiki/Generalised_logistic_function 34 | #' 35 | #' @name growthmodels-package 36 | #' @aliases growthmodels 37 | #' @docType package 38 | #' 39 | NULL 40 | -------------------------------------------------------------------------------- /man/growthmodels-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/growthmodels.R 3 | \docType{package} 4 | \name{growthmodels-package} 5 | \alias{growthmodels-package} 6 | \alias{growthmodels} 7 | \title{growthmodels: Nonlinear Growth Models} 8 | \description{ 9 | A compilation of nonlinear growth models. 10 | } 11 | \details{ 12 | \tabular{ll}{ 13 | Package: \tab growthmodels \cr 14 | Version: \tab 1.2.0 \cr 15 | License: \tab GPL-3 \cr 16 | } 17 | } 18 | \references{ 19 | D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 20 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 21 | 327-336, 1999. 22 | 23 | M. M. Kaps, W. O. W. Herring, and W. R. W. Lamberson, "Genetic and 24 | environmental parameters for traits derived from the Brody growth curve and 25 | their relationships with weaning weight in Angus cattle.," Journal of 26 | Animal Science, vol. 78, no. 6, pp. 1436-1442, May 2000. 27 | 28 | A. Tsoularis and J. Wallace, "Analysis of logistic growth models.," 29 | Math Biosci, vol. 179, no. 1, pp. 21-55, Jul. 2002. 30 | 31 | A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 32 | modeling oil palm yield growth," Journal of Mathematics and Statistics, 33 | vol. 1, no. 3, p. 225, 2005. 34 | 35 | Michael J. Panik, "Growth Curve Modeling: Theory and Applications", 36 | John Wiley & Sons, December 2013. 37 | 38 | http://en.wikipedia.org/wiki/Generalised_logistic_function 39 | } 40 | \author{ 41 | Daniel Rodriguez \email{daniel.rodriguez.perez@gmail.com} 42 | } 43 | -------------------------------------------------------------------------------- /tests/testthat/testJanoschek.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Janoschek growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 25/3/2018. 5 | ## 6 | ## Copyright (c) 2018 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Janoschek growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Janoschek model values", { 27 | expected <- c(2.000000, 3.769594, 7.056964, 9.156806, 9.853475, 28 | 9.984556, 9.999013, 9.999962, 9.999999, 10.000000) 29 | parameters <- c(10, 2, 0.25, 2) 30 | time <- 0:9 31 | 32 | expect_that(janoschek(time, parameters[1], parameters[2], parameters[3], parameters[4]), 33 | equals(expected, tolerance = MAXERROR)) 34 | }) 35 | 36 | test_that("Janoschek growth model values", { 37 | parameters <- c(10, 2, 0.5, 2) 38 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0) 39 | size <- janoschek(time, parameters[1], parameters[2], parameters[3], parameters[4]) 40 | 41 | expect_that(janoschek.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 42 | equals(time, tolerance = MAXERROR)) 43 | }) 44 | -------------------------------------------------------------------------------- /R/janoschek.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Janoschek growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 25/3/2018. 5 | ## 6 | ## Copyright (c) 2018 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Janoschek growth model 23 | #' 24 | #' Computes the Janoschek growth model and its inverse 25 | #' \deqn{ y(t) = \alpha *(\alpha - \beta) \exp(-b * t^c)) } 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta lower asymptote 31 | #' @param b growth parameter 32 | #' @param c shape parameter 33 | #' 34 | #' @examples 35 | #' growth <- janoschek(0:10, 10, 2, 0.5, 2) 36 | #' 37 | #' @references 38 | #' Michael J. Panik, "Growth Curve Modeling: Theory and Applications", 39 | #' John Wiley & Sons, December 2013. 40 | #' 41 | #' @author Daniel Rodriguez 42 | #' 43 | #' @rdname janoschek 44 | #' @export janoschek 45 | #' @aliases janoschek 46 | janoschek <- function(t, alpha, beta, b, c) { 47 | result <- alpha - (alpha - beta) * exp(-b * t^c) 48 | return(result) 49 | } 50 | 51 | #' @examples 52 | #' # Calculate inverse function 53 | #' time <- janoschek.inverse(growth, 12, 2, 0.5, 2) 54 | #' 55 | #' @rdname janoschek 56 | #' @export janoschek.inverse 57 | #' @aliases janoschek.inverse 58 | janoschek.inverse <- function(x, alpha, beta, b, c) { 59 | result <- (log((alpha - beta)/(alpha - x)) / b) ** (1 / c) 60 | return(result) 61 | } 62 | -------------------------------------------------------------------------------- /R/blumberg.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Blumberg growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 14/9/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Blumberg growth model 23 | #' 24 | #' Computes the Blumberg growth model and its inverse 25 | #' \deqn{ y(t) = \frac{\alpha * (t + t_0)^m}{w_0 + (t + t_0)^m}}{y(t) = (\alpha * (t - t_0)^m)/(w_0 + (t - t_0)^m)} 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param w0 a reference value at t = t0 31 | #' @param m slope of growth 32 | #' @param t0 time shift (default 0) 33 | #' 34 | #' @examples 35 | #' growth <- blumberg(0:10, 10, 2, 0.5) 36 | #' 37 | #' @references 38 | #' A. Tsoularis and J. Wallace, "Analysis of logistic growth models.," 39 | #' Math Biosci, vol. 179, no. 1, pp. 21-55, Jul. 2002. 40 | #' 41 | #' @author Daniel Rodriguez 42 | #' 43 | #' @rdname blumberg 44 | #' @export blumberg 45 | #' @aliases blumberg 46 | blumberg <- function(t, alpha, w0, m, t0 = 0) { 47 | result <- (alpha * (t + t0)^m) / (w0 + (t + t0)^m) 48 | return(result) 49 | } 50 | 51 | #' @examples 52 | #' # Calculate inverse function 53 | #' time <- blumberg.inverse(growth, 12, 2, 0.5) 54 | #' 55 | #' @rdname blumberg 56 | #' @export blumberg.inverse 57 | #' @aliases blumberg.inverse 58 | blumberg.inverse <- function(x, alpha, w0, m, t0 = 0) { 59 | result <- (x * w0 / (alpha - x))^(1/m) - t0 60 | return(result) 61 | } 62 | -------------------------------------------------------------------------------- /R/gompertz.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Gompertz exponential growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Gompertz growth model 23 | #' 24 | #' Computes the Gompertz growth model and its inverse 25 | #' \deqn{ y(t) = \alpha exp(-\beta exp(-k^t))}{ y(t) = \alpha * exp(-\beta * exp(-k^t))} 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth displacement 31 | #' @param k growth rate 32 | #' 33 | #' @usage gompertz(t, alpha, beta, k) 34 | #' 35 | #' @examples 36 | #' growth <- gompertz(0:10, 10, 0.5, 0.3) 37 | #' 38 | #' @references 39 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 40 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 41 | #' 327-336, 1999. 42 | #' 43 | #' @author Daniel Rodriguez 44 | #' 45 | #' @rdname gompertz 46 | #' @export gompertz 47 | #' @aliases gompertz 48 | gompertz <- function(t, alpha, beta, k) { 49 | result <- alpha * exp(-beta * exp(-k * t)); 50 | return(result) 51 | } 52 | 53 | #' @examples 54 | #' # Calculate inverse function 55 | #' time <- gompertz.inverse(growth, 10, 0.5, 0.3) 56 | #' 57 | #' @rdname gompertz 58 | #' @export gompertz.inverse 59 | #' @aliases gompertz.inverse 60 | gompertz.inverse <- function(x, alpha, beta, k) { 61 | result <- - log(-log(x / alpha) / beta) / k 62 | return(result) 63 | } 64 | -------------------------------------------------------------------------------- /R/schnute.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Schnute growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Schnute growth model 23 | #' 24 | #' Computes the Schnute growth model 25 | #' \deqn{ y(t) = \left[ r_0 + \beta exp(k t) \right]^m }{ y(t) = (r_0 + \beta * exp(k * t))^m } 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param r0 reference value 30 | #' @param beta growth displacement 31 | #' @param k growth rate 32 | #' @param m slope of growth 33 | #' 34 | #' @usage schnute(t, r0, beta, k, m) 35 | #' 36 | #' @examples 37 | #' growth <- schnute(0:10, 10, 5, .5, .5) 38 | #' 39 | #' @references 40 | #' A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 41 | #' modeling oil palm yield growth," Journal of Mathematics and Statistics, 42 | #' vol. 1, no. 3, p. 225, 2005. 43 | #' 44 | #' @author Daniel Rodriguez 45 | #' 46 | #' @rdname schnute 47 | #' @export schnute 48 | #' @aliases schnute 49 | schnute <- function(t, r0, beta, k, m) { 50 | result <- (r0 + beta * exp(k * t))^m 51 | return(result) 52 | } 53 | 54 | #' @examples 55 | #' # Calculate inverse function 56 | #' time <- schnute.inverse(growth, 10, 5, .5, .5) 57 | #' 58 | #' @rdname schnute 59 | #' @export schnute.inverse 60 | #' @aliases schnute.inverse 61 | schnute.inverse <- function(x, r0, beta, k, m) { 62 | result <- log((x^(1 / m) - r0) / beta) / k 63 | return(result) 64 | } 65 | -------------------------------------------------------------------------------- /R/weibull.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Weibull growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Weibull growth model 23 | #' 24 | #' Computes the Weibull growth model 25 | #' \deqn{ y(t) = \alpha - \beta exp(-k * t^m) }{ y(t) = \alpha - \beta * exp(-k * t^m) } 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth range 31 | #' @param k growth rate 32 | #' @param m slope of growth 33 | #' 34 | #' @usage weibull(t, alpha, beta, k, m) 35 | #' 36 | #' @examples 37 | #' growth <- weibull(0:10, 10, 0.5, 0.3, 0.5) 38 | #' 39 | #' @references 40 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 41 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 42 | #' 327-336, 1999. 43 | #' 44 | #' @author Daniel Rodriguez 45 | #' 46 | #' @rdname weibull 47 | #' @export weibull 48 | #' @aliases weibull 49 | weibull <- function(t, alpha, beta, k, m) { 50 | result <- alpha - beta * exp(-k * t^m); 51 | return(result) 52 | } 53 | 54 | #' @examples 55 | #' # Calculate inverse function 56 | #' time <- weibull.inverse(growth, 10, 0.5, 0.3, 0.5) 57 | #' 58 | #' @rdname weibull 59 | #' @export weibull.inverse 60 | #' @aliases weibull.inverse 61 | weibull.inverse <- function(x, alpha, beta, k, m) { 62 | result <- ((-1/k) * log((alpha - x)/beta))^(1/m) 63 | return(result) 64 | } 65 | -------------------------------------------------------------------------------- /R/negativeExponential.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Negative exponential growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Negative exponential growth model 23 | #' 24 | #' Computes the negative exponential growth model 25 | #' \deqn{ y(t) = \alpha ( 1 - exp(-k t))}{ y(t) = \alpha * ( 1 - exp(-k * t))} 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param k growth rate 31 | #' 32 | #' @usage negativeExponential(t, alpha, k) 33 | #' 34 | #' @examples 35 | #' growth <- negativeExponential(0:10, 1, 0.3) 36 | #' 37 | #' @references 38 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 39 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 40 | #' 327-336, 1999. 41 | #' 42 | #' @author Daniel Rodriguez 43 | #' 44 | #' @rdname negativeExponential 45 | #' @export negativeExponential 46 | #' @aliases negativeExponential 47 | negativeExponential <- function(t, alpha, k) { 48 | result <- alpha * (1.0 - exp(-k * t)) 49 | return(result) 50 | } 51 | 52 | #' @examples 53 | #' # Calculate inverse function 54 | #' time <- negativeExponential.inverse(growth, 10, 0.3) 55 | #' 56 | #' @rdname negativeExponential 57 | #' @export negativeExponential.inverse 58 | #' @aliases negativeExponential.inverse 59 | negativeExponential.inverse <- function(x, alpha, k) { 60 | result <- -log(1 - x/alpha) / k 61 | return(result) 62 | } 63 | -------------------------------------------------------------------------------- /R/monomolecular.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Monomolecular exponential growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Monomolecular growth model 23 | #' 24 | #' Computes the monomolecular growth model 25 | #' \deqn{ y(t) = \alpha ( 1 - \beta exp(-k t))}{ y(t) = \alpha * ( 1 - \beta * exp(-k * t))} 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth range 31 | #' @param k growth rate 32 | #' 33 | #' @usage monomolecular(t, alpha, beta, k) 34 | #' 35 | #' @examples 36 | #' growth <- monomolecular(0:10, 10, 0.5, 0.3) 37 | #' 38 | #' @references 39 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 40 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 41 | #' 327-336, 1999. 42 | #' 43 | #' @author Daniel Rodriguez 44 | #' 45 | #' @rdname monomolecular 46 | #' @export monomolecular 47 | #' @aliases monomolecular 48 | monomolecular <- function(t, alpha, beta, k) { 49 | result <- alpha * (1.0 - beta * exp(-k * t)) 50 | return(result) 51 | } 52 | 53 | #' @examples 54 | #' # Calculate inverse function 55 | #' time <- monomolecular.inverse(growth, 10, 0.5, 0.3) 56 | #' 57 | #' @rdname monomolecular 58 | #' @export monomolecular.inverse 59 | #' @aliases monomolecular.inverse 60 | monomolecular.inverse <- function(x, alpha, beta, k) { 61 | result <- - log((alpha - x)/(alpha * beta)) / k 62 | return(result) 63 | } 64 | -------------------------------------------------------------------------------- /R/brody.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Brody growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Brody growth model 23 | #' 24 | #' Computes the Brody growth model and its inverse 25 | #' \deqn{ y(t) = \alpha - (\alpha - w_0) exp(- k t) }{ y(t) = \alpha - (\alpha - w_0) * exp(- k * t) } 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param w0 the value at t = 0 31 | #' @param k growth rate 32 | #' 33 | #' @usage brody(t, alpha, w0, k) 34 | #' 35 | #' @examples 36 | #' growth <- brody(0:10, 10, 5, 0.3) 37 | #' 38 | #' @references 39 | #' M. M. Kaps, W. O. W. Herring, and W. R. W. Lamberson, "Genetic and 40 | #' environmental parameters for traits derived from the Brody growth curve and 41 | #' their relationships with weaning weight in Angus cattle.," Journal of 42 | #' Animal Science, vol. 78, no. 6, pp. 1436-1442, May 2000. 43 | #' 44 | #' @author Daniel Rodriguez 45 | #' 46 | #' @rdname brody 47 | #' @export brody 48 | #' @aliases brody 49 | brody <- function(t, alpha, w0, k) { 50 | result <- alpha - (alpha - w0) * exp(- k * t) 51 | return(result) 52 | } 53 | 54 | #' @examples 55 | #' # Calculate inverse function 56 | #' time <- brody.inverse(growth, 10, 5, 0.3) 57 | #' 58 | #' @rdname brody 59 | #' @export brody.inverse 60 | #' @aliases brody.inverse 61 | brody.inverse <- function(x, alpha, w0, k) { 62 | result <- - log((alpha - x) / (alpha - w0)) / k 63 | return(result) 64 | } 65 | -------------------------------------------------------------------------------- /R/loglogistic.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Log-logistic growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Log-logistic growth model 23 | #' 24 | #' Computes the Log-logistic growth model 25 | #' \deqn{ y(t) = \frac{\alpha}{1 + \beta exp(-k log(t)}}{ y(t) = \alpha/(1 + \beta * exp(-k * log(t))} 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth range 31 | #' @param k growth rate 32 | #' 33 | #' @usage loglogistic(t, alpha, beta, k) 34 | #' 35 | #' @examples 36 | #' growth <- loglogistic(0:10, 10, 0.5, 0.3) 37 | #' 38 | #' @references 39 | #' A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 40 | #' modeling oil palm yield growth," Journal of Mathematics and Statistics, 41 | #' vol. 1, no. 3, p. 225, 2005. 42 | #' 43 | #' @author Daniel Rodriguez 44 | #' 45 | #' @rdname loglogistic 46 | #' @export loglogistic 47 | #' @aliases loglogistic 48 | loglogistic <- function(t, alpha, beta, k) { 49 | t[t < 0] <- NaN 50 | result <- logistic(log(t), alpha, beta, k) 51 | return(result) 52 | } 53 | 54 | #' @examples 55 | #' # Calculate inverse function 56 | #' time <- loglogistic.inverse(growth, 10, 0.5, 0.3) 57 | #' 58 | #' @rdname loglogistic 59 | #' @export loglogistic.inverse 60 | #' @aliases loglogistic.inverse 61 | loglogistic.inverse <- function(x, alpha, beta, k) { 62 | result <- exp(logistic.inverse(x, alpha, beta, k)) 63 | return(result) 64 | } 65 | 66 | -------------------------------------------------------------------------------- /R/mmf.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Morgan-Mercer-Flodin growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Morgan-Mercer-Flodin growth model 23 | #' 24 | #' Computes the Morgan-Mercer-Flodin growth model 25 | #' \deqn{ y(t) = \frac{(w_0 \gamma + \alpha t^m)}{\gamma} +t^m}{ y(t) = (w_0 * \gamma + \alpha * t^m) / (\gamma + t^m)} 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param w0 the value at t = 0 31 | #' @param gamma parameter that controls the point of inflection 32 | #' @param m growth rate 33 | #' 34 | #' @usage mmf(t, alpha, w0, gamma, m) 35 | #' 36 | #' @examples 37 | #' growth <- mmf(0:10, 10, 0.5, 4, 1) 38 | #' 39 | #' @references 40 | #' A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 41 | #' modeling oil palm yield growth," Journal of Mathematics and Statistics, 42 | #' vol. 1, no. 3, p. 225, 2005. 43 | #' 44 | #' @author Daniel Rodriguez 45 | #' 46 | #' @rdname mmf 47 | #' @export mmf 48 | #' @aliases mmf 49 | mmf <- function(t, alpha, w0, gamma, m) { 50 | result <- (w0 * gamma + alpha * t^m) / (gamma + t^m) 51 | return(result) 52 | } 53 | 54 | #' @examples 55 | #' # Calculate inverse function 56 | #' time <- mmf.inverse(growth, 10, 0.5, 4, 1) 57 | #' 58 | #' @rdname mmf 59 | #' @export mmf.inverse 60 | #' @aliases mmf.inverse 61 | mmf.inverse <- function(x, alpha, w0, gamma, m) { 62 | result <- (gamma * (w0 - x) / (x - alpha))^(1/m) 63 | return(result) 64 | } 65 | -------------------------------------------------------------------------------- /R/stannard.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Stannard growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Stannard growth model 23 | #' 24 | #' Computes the Stannard growth model 25 | #' \deqn{ y(t) = \alpha \left[ 1 + exp(-(\beta + k t)/m) \right]^{-m}}{ y(t) = \alpha *( 1 + exp(-(beta + k * t)/m))^(-m) } 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth displacement 31 | #' @param k growth rate 32 | #' @param m slope of growth 33 | #' 34 | #' @usage stannard(t, alpha, beta, k, m) 35 | #' 36 | #' @examples 37 | #' growth <- stannard(0:10, 1, .2, .1, .5) 38 | #' 39 | #' @references 40 | #' A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 41 | #' modeling oil palm yield growth," Journal of Mathematics and Statistics, 42 | #' vol. 1, no. 3, p. 225, 2005. 43 | #' 44 | #' @author Daniel Rodriguez 45 | #' 46 | #' @rdname stannard 47 | #' @export stannard 48 | #' @aliases stannard 49 | stannard <- function(t, alpha, beta, k, m) { 50 | result <- alpha * ( 1 + exp(-(beta + k * t)/m) )^(-m) 51 | return(result) 52 | } 53 | 54 | #' @examples 55 | #' # Calculate inverse function 56 | #' time <- stannard.inverse(growth, 1, .2, .1, .5) 57 | #' 58 | #' @rdname stannard 59 | #' @export stannard.inverse 60 | #' @aliases stannard.inverse 61 | stannard.inverse <- function(x, alpha, beta, k, m) { 62 | result <- - (beta + m * log((alpha / x)^(1 / m) - 1)) / k 63 | return(result) 64 | } 65 | -------------------------------------------------------------------------------- /R/mitcherlich.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Mitcherlich exponential growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Mitcherlich growth model 23 | #' 24 | #' Computes the Mitcherlich growth model 25 | #' \deqn{ y(t) = (\alpha - \beta k^t)}{ y(t) = \alpha - \beta * k^t} 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth range 31 | #' @param k growth rate 32 | #' 33 | #' @usage mitcherlich(t, alpha, beta, k) 34 | #' 35 | #' @examples 36 | #' growth <- mitcherlich(0:10, 10, 0.5, 0.3) 37 | #' 38 | #' @references 39 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 40 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 41 | #' 327-336, 1999. 42 | #' 43 | #' @author Daniel Rodriguez 44 | #' 45 | #' @rdname mitcherlich 46 | #' @export mitcherlich mitscherlich 47 | #' @aliases mitcherlich mitscherlich 48 | mitcherlich <- function(t, alpha, beta, k) { 49 | result <- alpha - beta * k^t 50 | return(result) 51 | } 52 | 53 | mitscherlich <- mitcherlich 54 | 55 | #' @examples 56 | #' # Calculate inverse function 57 | #' time <- mitcherlich.inverse(growth, 10, 0.5, 0.3) 58 | #' 59 | #' @rdname mitcherlich 60 | #' @export mitcherlich.inverse mitscherlich.inverse 61 | #' @aliases mitcherlich.inverse mitscherlich.inverse 62 | mitcherlich.inverse <- function(x, alpha, beta, k) { 63 | result <- log((alpha - x) / beta) / log(k) 64 | return(result) 65 | } 66 | 67 | mitscherlich.inverse <- mitcherlich.inverse 68 | -------------------------------------------------------------------------------- /R/chapmanRichards.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Chapman-Richards growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Chapman-Richards growth model 23 | #' 24 | #' Computes the Chapman-Richards growth model and its inverse 25 | #' \deqn{ y(t) = \alpha (1 - \beta exp(-k t)^{1/(1-m)}) }{ y(t) = \alpha * (1 - \beta * exp(-k * t)^{1/(1-m)}) } 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth range 31 | #' @param k growth rate 32 | #' @param m slope of growth 33 | #' 34 | #' @usage chapmanRichards(t, alpha, beta, k, m) 35 | #' 36 | #' @examples 37 | #' growth <- chapmanRichards(0:10, 10, 0.5, 0.3, 0.5) 38 | #' 39 | #' @references 40 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 41 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 42 | #' 327-336, 1999. 43 | #' 44 | #' @author Daniel Rodriguez 45 | #' 46 | #' @rdname chapmanRichards 47 | #' @export chapmanRichards 48 | #' @aliases chapmanRichards 49 | chapmanRichards <- function(t, alpha, beta, k, m) { 50 | result <- alpha * (1 - beta * exp(-k * t))^(1 / (1 - m)) 51 | return(result) 52 | } 53 | 54 | #' @examples 55 | #' # Calculate inverse function 56 | #' time <- chapmanRichards.inverse(growth, 10, 0.5, 0.3, 0.5) 57 | #' 58 | #' @rdname chapmanRichards 59 | #' @export chapmanRichards.inverse 60 | #' @aliases chapmanRichards.inverse 61 | chapmanRichards.inverse <- function(x, alpha, beta, k, m) { 62 | result <- - log((1 - (x / alpha)^(1-m)) / beta) / k 63 | return(result) 64 | } 65 | -------------------------------------------------------------------------------- /R/vonBertalanffy.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## von Bertalanffy growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' von Bertalanffy growth model 23 | #' 24 | #' Computes the von Bertalanffy growth model 25 | #' \deqn{ y(t) = (\alpha^(1-m) - \beta * exp(-k t))^(1/(1-m)) }{ y(t) = (\alpha^(1-m) - \beta * exp(-k * t))^(1/(1-m)) } 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth range 31 | #' @param k growth rate 32 | #' @param m slope of growth 33 | #' 34 | #' @usage vonBertalanffy(t, alpha, beta, k, m) 35 | #' 36 | #' @examples 37 | #' growth <- vonBertalanffy(0:10, 10, 0.5, 0.3, 0.5) 38 | #' 39 | #' @references 40 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 41 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 42 | #' 327-336, 1999. 43 | #' 44 | #' @author Daniel Rodriguez 45 | #' 46 | #' @rdname vonBertalanffy 47 | #' @export vonBertalanffy 48 | #' @aliases vonBertalanffy 49 | vonBertalanffy <- function(t, alpha, beta, k, m) { 50 | result <- alpha^(1 - m) - beta * exp(-k * t) 51 | result <- result^(1 / (1 - m)) 52 | return(result) 53 | } 54 | 55 | #' @examples 56 | #' # Calculate inverse function 57 | #' time <- vonBertalanffy.inverse(growth, 10, 0.5, 0.3, 0.5) 58 | #' 59 | #' @rdname vonBertalanffy 60 | #' @export vonBertalanffy.inverse 61 | #' @aliases vonBertalanffy.inverse 62 | vonBertalanffy.inverse <- function(x, alpha, beta, k, m) { 63 | result <- -log((alpha^(1 - m) - x^(1 - m))/beta) / k 64 | return(result) 65 | } 66 | -------------------------------------------------------------------------------- /tests/testthat/testBrody.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Brody growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 30/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Brody growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Brody growth model values", { 27 | expected <- c(2.000000, 1.223130, 1.049787, 1.011109, 1.002479, 28 | 1.000553, 1.000123, 1.000028, 1.000006, 1.000001) 29 | parameters <- c(1, 2, 3) 30 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 31 | 32 | expect_that(brody(time, parameters[1], parameters[2], parameters[3]), 33 | equals(expected, tolerance = MAXERROR)) 34 | 35 | expected <- c(5.000000, 5.967293, 6.747455, 7.376687, 7.884190, 36 | 8.293511, 8.623646, 8.889914, 9.104669, 9.277879) 37 | parameters <- c(10, 5, .43) 38 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 39 | 40 | expect_that(brody(time, parameters[1], parameters[2], parameters[3]), 41 | equals(expected, tolerance = MAXERROR)) 42 | }) 43 | 44 | test_that("Inverse Brody growth model values", { 45 | parameters <- c(1, 2, 3) 46 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 47 | size <- brody(time, parameters[1], parameters[2], parameters[3]) 48 | 49 | expect_that(brody.inverse(size, parameters[1], parameters[2], parameters[3]), 50 | equals(time, tolerance = MAXERROR)) 51 | 52 | parameters <- c(10, 5, .43) 53 | size <- brody(time, parameters[1], parameters[2], parameters[3]) 54 | 55 | expect_that(brody.inverse(size, parameters[1], parameters[2], parameters[3]), 56 | equals(time, tolerance = MAXERROR)) 57 | }) -------------------------------------------------------------------------------- /tests/testthat/testMitcherlich.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Mitcherlich growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Mitcherlich growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Mitcherlich growth model values", { 27 | expected <- c(7.777778e-001, 6.150998e-001, 3.333333e-001, -1.547005e-001, 28 | -1, -2.464102e+000, -5, -9.392305e+000, -17) 29 | parameters <- c(1, 2, 3) 30 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 31 | 32 | expect_that(mitcherlich(time, parameters[1], parameters[2], parameters[3]), 33 | equals(expected, tolerance = MAXERROR)) 34 | 35 | expected <- c(1.175000e+001, 1.164645e+001, 1.150000e+001, 36 | 1.129289e+001, 11, 1.058579e+001, 10, 9.171573e+000, 8) 37 | parameters <- c(12, 1, 2) 38 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 39 | 40 | expect_that(mitcherlich(time, parameters[1], parameters[2], parameters[3]), 41 | equals(expected, tolerance = MAXERROR)) 42 | }) 43 | 44 | test_that("Inverse Mitcherlich growth model values", { 45 | parameters <- c(1, 2, 3) 46 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 47 | size <- mitcherlich(time, parameters[1], parameters[2], parameters[3]) 48 | 49 | expect_that(mitcherlich.inverse(size, parameters[1], parameters[2], parameters[3]), 50 | equals(time, tolerance = MAXERROR)) 51 | 52 | parameters <- c(12, 1, 2) 53 | size <- mitcherlich(time, parameters[1], parameters[2], parameters[3]) 54 | 55 | expect_that(mitcherlich.inverse(size, parameters[1], parameters[2], parameters[3]), 56 | equals(time, tolerance = MAXERROR)) 57 | }) 58 | -------------------------------------------------------------------------------- /tests/testthat/testGompertz.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Gompertz growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Gompertz growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Gompertz growth model values", { 27 | expected <- c(0, 6.488035e-079, 3.580340e-018, 1.280131e-004, 1.353353e-001, 28 | 6.400171e-001, 9.052228e-001, 9.780270e-001, 9.950548e-001) 29 | parameters <- c(1, 2, 3) 30 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 31 | 32 | expect_that(gompertz(time, parameters[1], parameters[2], parameters[3]), 33 | equals(expected, tolerance = MAXERROR)) 34 | 35 | expected <- c(2.330805e-023, 2.270614e-008, 7.415748e-003, 7.918564e-001, 36 | 4.414553e+000, 8.306408e+000, 1.048108e+001, 1.141718e+001, 37 | 1.178221e+001) 38 | parameters <- c(12, 1, 2) 39 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 40 | 41 | expect_that(gompertz(time, parameters[1], parameters[2], parameters[3]), 42 | equals(expected, tolerance = MAXERROR)) 43 | }) 44 | 45 | test_that("Inverse Gompertz growth model values", { 46 | parameters <- c(1, 2, 3) 47 | time <- c(-1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 48 | size <- gompertz(time, parameters[1], parameters[2], parameters[3]) 49 | 50 | expect_that(gompertz.inverse(size, parameters[1], parameters[2], parameters[3]), 51 | equals(time, tolerance = MAXERROR)) 52 | 53 | parameters <- c(12, 1, 2) 54 | size <- gompertz(time, parameters[1], parameters[2], parameters[3]) 55 | 56 | expect_that(gompertz.inverse(size, parameters[1], parameters[2], parameters[3]), 57 | equals(time, tolerance = MAXERROR)) 58 | }) 59 | -------------------------------------------------------------------------------- /tests/testthat/testWeibull.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Weibull growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Weibull growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Weibull growth model values", { 27 | expected <- c(1, 9.999995e-001, 9.004259e-001, -6.580582e-001, -1, 28 | -6.580582e-001, 9.004259e-001, 9.999995e-001, 1) 29 | parameters <- c(1, 2, 3, 4) 30 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 31 | 32 | expect_that(weibull(time, parameters[1], parameters[2], parameters[3], parameters[4]), 33 | equals(expected, tolerance = MAXERROR)) 34 | 35 | expected <- c(-7.948576e+002, -1.680343e+002, -2.817107e+001, 36 | 3.036622e+000, 10, 1.155374e+001, 1.190043e+001, 37 | 1.197778e+001, 1.199504e+001) 38 | parameters <- c(12, 2, 3, 1) 39 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 40 | 41 | expect_that(weibull(time, parameters[1], parameters[2], parameters[3], parameters[4]), 42 | equals(expected, tolerance = MAXERROR)) 43 | }) 44 | 45 | test_that("Inverse Weibull growth model values", { 46 | parameters <- c(1, 2, 3, 4) 47 | time <- c(0.0, 0.5, 1.0, 1.5) 48 | size <- weibull(time, parameters[1], parameters[2], parameters[3], parameters[4]) 49 | 50 | expect_that(weibull.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 51 | equals(time, tolerance = MAXERROR)) 52 | 53 | parameters <- c(12, 2, 3, 1) 54 | size <- weibull(time, parameters[1], parameters[2], parameters[3], parameters[4]) 55 | 56 | expect_that(weibull.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 57 | equals(time, tolerance = MAXERROR)) 58 | }) 59 | 60 | -------------------------------------------------------------------------------- /tests/testthat/testMmf.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Morgan-Mercer-Flodin growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 30/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Morgan-Mercer-Flodin growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Morgan-Mercer-Flodin growth model values", { 27 | expected <- c(1.157895, 1.372093, 1.750000, 1.979592, 2.000000, 28 | 1.979592, 1.750000, 1.372093, 1.157895, 1.035714) 29 | parameters <- c(1, 2, 3, 4) 30 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 3.0) 31 | 32 | expect_that(mmf(time, parameters[1], parameters[2], parameters[3], parameters[4]), 33 | equals(expected, tolerance = MAXERROR)) 34 | 35 | expected <- c(-18.000000, -8.000000, -3.000000, 0.000000, 2.000000, 36 | 3.428571, 4.500000, 5.333333, 6.000000, 7.000000) 37 | parameters <- c(12, 2, 3, 1) 38 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 3.0) 39 | 40 | expect_that(mmf(time, parameters[1], parameters[2], parameters[3], parameters[4]), 41 | equals(expected, tolerance = MAXERROR)) 42 | }) 43 | 44 | test_that("Inverse Morgan-Mercer-Flodin growth model values", { 45 | parameters <- c(1, 2, 3, 4) 46 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0) 47 | size <- mmf(time, parameters[1], parameters[2], parameters[3], parameters[4]) 48 | 49 | expect_that(mmf.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 50 | equals(time, tolerance = MAXERROR)) 51 | 52 | parameters <- c(12, 2, 3, 1) 53 | size <- mmf(time, parameters[1], parameters[2], parameters[3], parameters[4]) 54 | 55 | expect_that(mmf.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 56 | equals(time, tolerance = MAXERROR)) 57 | }) 58 | -------------------------------------------------------------------------------- /tests/testthat/testNegativeExponential.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the negative exponential growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Negative exponential growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Negative exponential growth model values", { 27 | expected <- c(-5.359815e+001, -1.908554e+001, -6.389056e+000, 28 | -1.718282e+000, 0, 6.321206e-001, 8.646647e-001, 29 | 9.502129e-001, 9.816844e-001) 30 | parameters <- c(1, 2) 31 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 32 | 33 | expect_that(negativeExponential(time, parameters[1], parameters[2]), 34 | equals(expected, tolerance = MAXERROR)) 35 | 36 | expected <- c(-7.666867e+001, -4.178027e+001, -2.061938e+001, 37 | -7.784655e+000, 0, 4.721632e+000, 7.585447e+000, 38 | 9.322438e+000, 1.037598e+001) 39 | parameters <- c(12, 1) 40 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 41 | 42 | expect_that(negativeExponential(time, parameters[1], parameters[2]), 43 | equals(expected, tolerance = MAXERROR)) 44 | }) 45 | 46 | test_that("Inverse negative exponentia growth model values", { 47 | parameters <- c(1, 2) 48 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 49 | size <- negativeExponential(time, parameters[1], parameters[2]) 50 | 51 | expect_that(negativeExponential.inverse(size, parameters[1], parameters[2]), 52 | equals(time, tolerance = MAXERROR)) 53 | 54 | parameters <- c(12, 1) 55 | size <- negativeExponential(time, parameters[1], parameters[2]) 56 | 57 | expect_that(negativeExponential.inverse(size, parameters[1], parameters[2]), 58 | equals(time, tolerance = MAXERROR)) 59 | }) 60 | -------------------------------------------------------------------------------- /tests/testthat/testSchnute.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Schnute growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 30/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Schnute growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Schnute growth model values", { 27 | expected <- c(1.002476, 1.011048, 1.048606, 1.202606, 1.732051, 28 | 3.156482, 6.416469, 13.454897, 28.422836, 570.535348) 29 | parameters <- c(1, 2, 3, 0.5) 30 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 4.0) 31 | 32 | expect_that(schnute(time, parameters[1], parameters[2], parameters[3], parameters[4]), 33 | equals(expected, tolerance = MAXERROR)) 34 | 35 | expected <- c(1.643888, 1.644360, 1.646471, 1.655800, 1.695218, 36 | 1.837775, 2.205393, 2.862040, 3.825090, 12.662398) 37 | parameters <- c(12, 2, 3, .20) 38 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 4.0) 39 | 40 | expect_that(schnute(time, parameters[1], parameters[2], parameters[3], parameters[4]), 41 | equals(expected, tolerance = MAXERROR)) 42 | }) 43 | 44 | test_that("Inverse Schnute growth model values", { 45 | parameters <- c(1, 2, 3, 0.5) 46 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 4.0) 47 | size <- schnute(time, parameters[1], parameters[2], parameters[3], parameters[4]) 48 | 49 | expect_that(schnute.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 50 | equals(time, tolerance = MAXERROR)) 51 | 52 | parameters <- c(12, 2, 3, .20) 53 | size <- schnute(time, parameters[1], parameters[2], parameters[3], parameters[4]) 54 | 55 | expect_that(schnute.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 56 | equals(time, tolerance = MAXERROR)) 57 | }) 58 | -------------------------------------------------------------------------------- /tests/testthat/testMonomolecular.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the monomolecular growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Monomolecular growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Monomolecular growth model values", { 27 | expected <- c(-8.058576e+002, -1.790343e+002, -3.917107e+001, 28 | -7.963378e+000, -1, 5.537397e-001, 9.004259e-001, 29 | 9.777820e-001, 9.950425e-001) 30 | parameters <- c(1, 2, 3) 31 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 32 | 33 | expect_that(monomolecular(time, parameters[1], parameters[2], parameters[3]), 34 | equals(expected, tolerance = MAXERROR)) 35 | 36 | expected <- c(-6.431778e+002, -2.290264e+002, -7.666867e+001, 37 | -2.061938e+001, 0, 7.585447e+000, 1.037598e+001, 38 | 1.140256e+001, 1.178021e+001) 39 | parameters <- c(12, 1, 2) 40 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 41 | 42 | expect_that(monomolecular(time, parameters[1], parameters[2], parameters[3]), 43 | equals(expected, tolerance = MAXERROR)) 44 | }) 45 | 46 | test_that("Inverse Monomolecular growth model values", { 47 | parameters <- c(1, 2, 3) 48 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 49 | size <- monomolecular(time, parameters[1], parameters[2], parameters[3]) 50 | 51 | expect_that(monomolecular.inverse(size, parameters[1], parameters[2], parameters[3]), 52 | equals(time, tolerance = MAXERROR)) 53 | 54 | parameters <- c(12, 1, 2) 55 | size <- monomolecular(time, parameters[1], parameters[2], parameters[3]) 56 | 57 | expect_that(monomolecular.inverse(size, parameters[1], parameters[2], parameters[3]), 58 | equals(time, tolerance = MAXERROR)) 59 | }) 60 | -------------------------------------------------------------------------------- /tests/testthat/testStannard.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Stannard growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 30/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Stannard growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Stannard growth model values", { 27 | expected <- c(0.01831257, 0.08180985, 0.34525776, 0.85501964, 0.99096609, 28 | 0.99954437, 0.99997730, 0.99999887, 0.99999994, 1.00000000) 29 | parameters <- c(1, 2, 3, 0.5) 30 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 4.0) 31 | 32 | expect_that(stannard(time, parameters[1], parameters[2], parameters[3], parameters[4]), 33 | equals(expected, tolerance = MAXERROR)) 34 | 35 | expected <- c(0.2192816, 0.9660857, 3.7981941, 9.0791332, 11.5399613, 36 | 11.9437234, 11.9933643, 11.9992210, 11.9999086, 12.0000000) 37 | parameters <- c(12, 2, 3, .70) 38 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 4.0) 39 | 40 | expect_that(stannard(time, parameters[1], parameters[2], parameters[3], parameters[4]), 41 | equals(expected, tolerance = MAXERROR)) 42 | }) 43 | 44 | test_that("Inverse Stannard growth model values", { 45 | parameters <- c(1, 2, 3, 0.5) 46 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 4.0) 47 | size <- stannard(time, parameters[1], parameters[2], parameters[3], parameters[4]) 48 | 49 | expect_that(stannard.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 50 | equals(time, tolerance = MAXERROR)) 51 | 52 | parameters <- c(12, 2, 3, .70) 53 | size <- stannard(time, parameters[1], parameters[2], parameters[3], parameters[4]) 54 | 55 | expect_that(stannard.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 56 | equals(time, tolerance = MAXERROR)) 57 | }) 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # growthmodels: Nonlinear Growth Models 2 | `growthmodels` is a `R` package that contains a compilation of nonlinear growth models used in many areas. 3 | 4 | ## Installation 5 | To install the stable version of `growthmodels` from CRAN, simply run the following from an R console: 6 | 7 | ``` 8 | install.packages('growthmodels') 9 | ``` 10 | 11 | To install the latest development builds of `growthmodels` directly from GitHub, run this instead: 12 | 13 | ``` 14 | require(devtools) 15 | install_github('growthmodels', 'drodriguezperez') 16 | ``` 17 | 18 | ## Features 19 | `growthmodels` includes functions for the calculation of the following nonlinear growth models and its inverse functions: 20 | 21 | * Blumberg 22 | * Brody 23 | * Chapman-Richards 24 | * Generalised Logistic 25 | * Generalised Richard 26 | * Gompertz 27 | * Janoschek 28 | * Log-logistic 29 | * Logistic 30 | * Mitcherlich 31 | * Monomolecular 32 | * Morgan -Mercer-Flodin 33 | * Negative exponential 34 | * Richard’s 35 | * Schnute 36 | * Stannard 37 | * von Bertalanffy 38 | * Weibull 39 | 40 | ## License 41 | [GNU General Public License, version 3](http://www.gnu.org/licenses/gpl-3.0.txt) 42 | 43 | ## References 44 | 1. D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 45 | nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 46 | 327-336, 1999. [Full text](http://www.metla.fi/silvafennica/full/sf33/sf334327.pdf) 47 | 2. M. M. Kaps, W. O. W. Herring, and W. R. W. Lamberson, "Genetic and 48 | environmental parameters for traits derived from the Brody growth curve and 49 | their relationships with weaning weight in Angus cattle.," Journal of 50 | Animal Science, vol. 78, no. 6, pp. 1436-1442, May 2000. 51 | [Full text](http://www.ncbi.nlm.nih.gov/pubmed/10875624) 52 | 3. A. Tsoularis and J. Wallace, "Analysis of logistic growth models.," 53 | Math Biosci, vol. 179, no. 1, pp. 21–55, Jul. 2002. DOI identifier: 54 | [10.1016/j.bbr.2011.03.031](http://dx.doi.org/10.1016/j.bbr.2011.03.031) 55 | 4. A. Khamiz, Z. Ismail, and A. T. Muhammad, "Nonlinear growth models for 56 | modeling oil palm yield growth," Journal of Mathematics and Statistics, 57 | vol. 1, no. 3, p. 225, 2005. DOI identifier: 58 | [10.3844/jmssp.2005.225.233](http://dx.doi.org/10.3844/jmssp.2005.225.233) 59 | 5. Michael J. Panik, "Growth Curve Modeling: Theory and Applications", 60 | John Wiley & Sons, December 2013. 61 | 6. [Generalised logistic function](http://en.wikipedia.org/wiki/Generalised_logistic_functi5on) 62 | 63 | # Acknowledgments 64 | I would like to thank J.A. Martinez for all of their helpful discussions during the develop of the package. 65 | -------------------------------------------------------------------------------- /tests/testthat/testChapmanRichards.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Chapman-Richards growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Chapman-Richards growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Chapman-Richards growth model invalid values", { 27 | parameters <- c(1, 2, 3, 4) 28 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0) 29 | 30 | result <- chapmanRichards(time, parameters[1], parameters[2], parameters[3], parameters[4]) 31 | 32 | for (i in 1:length(time)) { 33 | expect_that(is.na(result[i]), is_true()) 34 | } 35 | }) 36 | 37 | test_that("Chapman-Richards growth model values", { 38 | expected <- c(1.217769e+000, 1.035581e+000, 1.007518e+000, 1.001658e+000, 39 | 1.000369e+000, 1.000082e+000, 1.000018e+000, 1.000004e+000, 40 | 1.000001e+000) 41 | parameters <- c(1, 2, 3, 4) 42 | time <- c(0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 43 | 44 | expect_that(chapmanRichards(time, parameters[1], parameters[2], parameters[3], parameters[4]), 45 | equals(expected, tolerance = MAXERROR)) 46 | }) 47 | 48 | test_that("Inverse Chapman-Richards growth model values", { 49 | parameters <- c(1, 2, 3, 4) 50 | time <- c(0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 51 | size <- chapmanRichards(time, parameters[1], parameters[2], 52 | parameters[3], parameters[4]) 53 | 54 | expect_that(chapmanRichards.inverse(size, parameters[1], parameters[2], 55 | parameters[3], parameters[4]), 56 | equals(time, tolerance = MAXERROR)) 57 | 58 | parameters <- c(1, 1, 2, 2) 59 | size <- chapmanRichards(time, parameters[1], parameters[2], 60 | parameters[3], parameters[4]) 61 | 62 | expect_that(chapmanRichards.inverse(size, parameters[1], parameters[2], 63 | parameters[3], parameters[4]), 64 | equals(time, tolerance = MAXERROR)) 65 | }) 66 | -------------------------------------------------------------------------------- /tests/testthat/testVonBertalanffy.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the von Bertalanffy growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | 23 | context("von Bertalanffy growth model") 24 | 25 | MAXERROR <- 1e-6 26 | 27 | test_that("von Bertalanffy growth model invalid values", { 28 | parameters <- c(1, 2, 3, 4) 29 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0) 30 | 31 | result <- vonBertalanffy(time, parameters[1], parameters[2], parameters[3], parameters[4]) 32 | 33 | for (i in 1:length(time)) { 34 | expect_that(is.na(result[i]), is_true()) 35 | } 36 | }) 37 | 38 | test_that("von Bertalanffy growth model values", { 39 | expected <- c(1.217769e+000, 1.035581e+000, 1.007518e+000, 1.001658e+000, 40 | 1.000369e+000, 1.000082e+000, 1.000018e+000, 1.000004e+000, 41 | 1.000001e+000) 42 | parameters <- c(1, 2, 3, 4) 43 | time <- c(0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 44 | 45 | expect_that(vonBertalanffy(time, parameters[1], parameters[2], parameters[3], parameters[4]), 46 | equals(expected, tolerance = MAXERROR)) 47 | 48 | expected <- c(1.199897e+001, 1.199977e+001, 1.199995e+001, 1.199999e+001, 49 | 1.200000e+001, 1.200000e+001, 1.200000e+001, 1.200000e+001, 50 | 1.200000e+001) 51 | parameters <- c(12, 2, 3, -2) 52 | time <- c(0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 53 | 54 | expect_that(vonBertalanffy(time, parameters[1], parameters[2], parameters[3], parameters[4]), 55 | equals(expected, tolerance = MAXERROR)) 56 | }) 57 | 58 | test_that("Inverse Bertalanffy growth model values", { 59 | parameters <- c(1, 2, 3, 4) 60 | time <- c(0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 61 | size <- vonBertalanffy(time, parameters[1], parameters[2], parameters[3], parameters[4]) 62 | 63 | expect_that(vonBertalanffy.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 64 | equals(time, tolerance = MAXERROR)) 65 | 66 | parameters <- c(12, 2, 3, -2) 67 | size <- vonBertalanffy(time, parameters[1], parameters[2], parameters[3], parameters[4]) 68 | 69 | expect_that(vonBertalanffy.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 70 | equals(time, tolerance = MAXERROR)) 71 | }) 72 | -------------------------------------------------------------------------------- /tests/testthat/testLoglogistic.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Log-logistic growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 30/8/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Log-logistic growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Log-logistic growth model invalid values", { 27 | parameters <- c(1, 2, 3) 28 | time <- c(-2.0, -1.5, -1.0, -0.5) 29 | 30 | result <- loglogistic(time, parameters[1], parameters[2], parameters[3]) 31 | 32 | for (i in 1:length(time)) { 33 | expect_that(is.na(result[i]), is_true()) 34 | } 35 | }) 36 | 37 | test_that("Log-logistic growth model in t = 0", { 38 | expect_that(loglogistic(0, 1, 2, 3), equals(0, tolerance = MAXERROR)) 39 | expect_that(loglogistic(0, 10, 1, 0.3), equals(0, tolerance = MAXERROR)) 40 | expect_that(loglogistic(0, 12, 2, 0.5), equals(0, tolerance = MAXERROR)) 41 | }) 42 | 43 | test_that("Log-logistic growth model values", { 44 | expected <- c(0.00000000, 0.05882353, 0.33333333, 0.62790698, 0.80000000, 45 | 0.93103448, 0.96969697, 0.98425197, 0.99082569, 0.99420290) 46 | parameters <- c(1, 2, 3) 47 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0) 48 | 49 | expect_that(loglogistic(time, parameters[1], parameters[2], parameters[3]), 50 | equals(expected, tolerance = MAXERROR)) 51 | 52 | expected <- c( 0.000000, 2.400000, 6.000000, 8.307692, 9.600000, 53 | 10.800000, 11.294118, 11.538462, 11.675676, 11.760000) 54 | parameters <- c(12, 1, 2) 55 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0) 56 | 57 | expect_that(loglogistic(time, parameters[1], parameters[2], parameters[3]), 58 | equals(expected, tolerance = MAXERROR)) 59 | }) 60 | 61 | test_that("Inverse Log-logistic growth model values", { 62 | parameters <- c(1, 2, 3) 63 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0) 64 | size <- loglogistic(time, parameters[1], parameters[2], parameters[3]) 65 | 66 | expect_that(loglogistic.inverse(size, parameters[1], parameters[2], parameters[3]), 67 | equals(time, tolerance = MAXERROR)) 68 | 69 | parameters <- c(12, 1, 2) 70 | size <- loglogistic(time, parameters[1], parameters[2], parameters[3]) 71 | 72 | expect_that(loglogistic.inverse(size, parameters[1], parameters[2], parameters[3]), 73 | equals(time, tolerance = MAXERROR)) 74 | }) -------------------------------------------------------------------------------- /R/logistic.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Logistic exponential growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Logistic growth model 23 | #' 24 | #' Computes the Logistic growth model 25 | #' \deqn{ y(t) = \frac{\alpha}{1 + \beta exp(-k t)}}{ y(t) = \alpha/(1 + \beta * exp(-k * t))} 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth range 31 | #' @param k growth rate 32 | #' 33 | #' @usage logistic(t, alpha, beta, k) 34 | #' 35 | #' @examples 36 | #' growth <- logistic(0:10, 10, 0.5, 0.3) 37 | #' 38 | #' @references 39 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 40 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 41 | #' 327-336, 1999. 42 | #' 43 | #' @author Daniel Rodriguez 44 | #' 45 | #' @rdname logistic 46 | #' @export logistic 47 | #' @aliases logistic 48 | logistic <- function(t, alpha, beta, k) { 49 | result <- alpha / (1 + beta * exp(-k * t)) 50 | return(result) 51 | } 52 | 53 | #' @examples 54 | #' # Calculate inverse function 55 | #' time <- logistic.inverse(growth, 10, 0.5, 0.3) 56 | #' 57 | #' @rdname logistic 58 | #' @export logistic.inverse 59 | #' @aliases logistic.inverse 60 | logistic.inverse <- function(x, alpha, beta, k) { 61 | result <- - log((alpha - x) / (beta * x)) / k 62 | return(result) 63 | } 64 | 65 | #' Generalised Logistic growth model 66 | #' 67 | #' Computes the Generalised Logistic growth model 68 | #' \deqn{ y(t) = A + \frac{U - A}{1 + \beta exp(-k (t- t_0))}}{ y(t) = A + (U - A)/(1 + \beta * exp(-k * (t- t_0)))} 69 | #' 70 | #' @param t time 71 | #' @param x size 72 | #' @param A the lower asymptote 73 | #' @param U the upper asymptote 74 | #' @param k growth range 75 | #' @param beta growth range 76 | #' @param t0 time shift (default 0) 77 | #' 78 | #' @usage generalisedLogistic(t, A, U, k, beta, t0) 79 | #' 80 | #' @references 81 | #' http://en.wikipedia.org/wiki/Generalised_logistic_function 82 | #' 83 | #' @examples 84 | #' growth <- generalisedLogistic(0:10, 5, 10, 0.3, 0.5, 3) 85 | #' 86 | #' @author Daniel Rodriguez 87 | #' 88 | #' @rdname generalisedLogistic 89 | #' @export generalisedLogistic 90 | #' @aliases generalisedLogistic 91 | generalisedLogistic <- function(t, A, U, k, beta, t0 = 0) { 92 | result <- A + logistic(t - t0, U - A, beta, k); 93 | } 94 | 95 | #' @examples 96 | #' # Calculate inverse function 97 | #' time <- generalisedLogistic.inverse(growth, 5, 10, 0.3, 0.5, 3) 98 | #' 99 | #' @rdname generalisedLogistic 100 | #' @export generalisedLogistic.inverse 101 | #' @aliases generalisedLogistic.inverse 102 | generalisedLogistic.inverse <- function(x, A, U, k, beta, t0 = 0) { 103 | result <- logistic.inverse(x - A, U - A, beta, k) + t0 104 | return(result) 105 | } 106 | -------------------------------------------------------------------------------- /R/richard.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Richard growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | #' Richard growth model 23 | #' 24 | #' Computes the Richard growth model and its inverse 25 | #' \deqn{ y(t) = \frac{\alpha}{(1 + \beta exp(-k t))^{(1/m)}}}{ y(t) = \alpha/((1 + \beta * exp(-k * t))^(1 / m))} 26 | #' 27 | #' @param t time 28 | #' @param x size 29 | #' @param alpha upper asymptote 30 | #' @param beta growth range 31 | #' @param k growth rate 32 | #' @param m slope of growth 33 | #' 34 | #' @usage richard(t, alpha, beta, k, m) 35 | #' 36 | #' @examples 37 | #' growth <- richard(0:10, 10, 0.5, 0.3, 0.5) 38 | #' 39 | #' @references 40 | #' D. Fekedulegn, M. Mac Siurtain, and J. Colbert, "Parameter estimation of 41 | #' nonlinear growth models in forestry," Silva Fennica, vol. 33, no. 4, pp. 42 | #' 327-336, 1999. 43 | #' 44 | #' @author Daniel Rodriguez 45 | #' 46 | #' @rdname richard 47 | #' @export richard 48 | #' @aliases richard 49 | richard <- function(t, alpha, beta, k, m) { 50 | result <- (1 + beta * exp(-k * t))^(1 / m) 51 | result <- alpha / result; 52 | return(result) 53 | } 54 | 55 | #' @examples 56 | #' time <- richard.inverse(growth, 10, 0.5, 0.3, 0.5) 57 | #' 58 | #' @rdname richard 59 | #' @export richard.inverse 60 | #' @aliases richard.inverse 61 | richard.inverse <- function(x, alpha, beta, k, m){ 62 | result <- -log(((alpha/x)^m - 1)/beta)/k 63 | return(result) 64 | } 65 | 66 | #' Generalised Richard growth model 67 | #' 68 | #' Computes the Generalised Richard growth model and its inverse 69 | #' \deqn{ y(t) = A + \frac{U - A}{(1 + \beta exp(-k (t - t_0)))^{(1/m)} }}{ y(t) = A + (U - A)/(1 + \beta * exp(-k * (t - t_0)))^{(1/m)} } 70 | #' 71 | #' @param t time 72 | #' @param x size 73 | #' @param A the lower asymptote 74 | #' @param U the upper asymptote 75 | #' @param k growth range 76 | #' @param m slope of growth 77 | #' @param beta growth range 78 | #' @param t0 time shift (default 0) 79 | #' 80 | #' @usage generalisedRichard(t, A, U, k, m, beta, t0) 81 | #' 82 | #' @examples 83 | #' growth <- generalisedRichard(0:10, 5, 10, 0.3, 0.5, 1, 3) 84 | #' 85 | #' @references 86 | #' http://en.wikipedia.org/wiki/Generalised_logistic_function 87 | #' 88 | #' @author Daniel Rodriguez 89 | #' 90 | #' @rdname generalisedRichard 91 | #' @export generalisedRichard 92 | #' @aliases generalisedRichard 93 | generalisedRichard <- function(t, A, U, k, m, beta, t0 = 0) { 94 | result <- A + richard(t - t0, U - A, beta, k, m) 95 | return(result) 96 | } 97 | 98 | #' @examples 99 | #' time <- generalisedRichard.inverse(growth, 5, 10, 0.3, 0.5, 1, 3) 100 | #' 101 | #' @rdname generalisedRichard 102 | #' @export generalisedRichard.inverse 103 | #' @aliases generalisedRichard.inverse 104 | generalisedRichard.inverse <- function(x, A, U, k, m, beta, t0 = 0) { 105 | result <- richard.inverse(x - A, U - A, beta, k, m) + t0 106 | return(result) 107 | } 108 | -------------------------------------------------------------------------------- /tests/testthat/testBlumberg.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Blumberg growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 14/9/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Blumberg growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Blumberg growth model values", { 27 | expected <- c(0.00000000, 0.05882353, 0.33333333, 0.62790698, 0.80000000, 28 | 0.88652482, 0.93103448, 0.95543175, 0.96969697, 0.97852349) 29 | parameters <- c(1, 2, 3) 30 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 31 | 32 | expect_that(blumberg(time, parameters[1], parameters[2], parameters[3]), 33 | equals(expected, tolerance = MAXERROR)) 34 | 35 | expected <- c(0.000000, 1.292630, 1.666667, 1.923072, 2.122552, 36 | 2.287412, 2.428652, 2.552605, 2.663284, 2.763410) 37 | parameters <- c(10, 5, .43) 38 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 39 | 40 | expect_that(blumberg(time, parameters[1], parameters[2], parameters[3]), 41 | equals(expected, tolerance = MAXERROR)) 42 | 43 | expected <- c(0.8000000, 0.8865248, 0.9310345, 0.9554318, 0.9696970, 44 | 0.9785235, 0.9842520, 0.9881218, 0.9908257, 0.9927700) 45 | parameters <- c(1, 2, 3, 2) 46 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 47 | 48 | expect_that(blumberg(time, parameters[1], parameters[2], parameters[3], parameters[4]), 49 | equals(expected, tolerance = MAXERROR)) 50 | 51 | expected <- c(2.122552, 2.287412, 2.428652, 2.552605, 2.663284, 52 | 2.763410, 2.854921, 2.939251, 3.017494, 3.090503) 53 | parameters <- c(10, 5, .43, 2) 54 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 55 | 56 | expect_that(blumberg(time, parameters[1], parameters[2], parameters[3], parameters[4]), 57 | equals(expected, tolerance = MAXERROR)) 58 | }) 59 | 60 | test_that("Inverse Blumberg growth model values", { 61 | parameters <- c(1, 2, 3) 62 | time <- c(0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 63 | size <- blumberg(time, parameters[1], parameters[2], parameters[3]) 64 | 65 | expect_that(blumberg.inverse(size, parameters[1], parameters[2], parameters[3]), 66 | equals(time, tolerance = MAXERROR)) 67 | 68 | parameters <- c(10, 5, .43) 69 | size <- blumberg(time, parameters[1], parameters[2], parameters[3]) 70 | 71 | expect_that(blumberg.inverse(size, parameters[1], parameters[2], parameters[3]), 72 | equals(time, tolerance = MAXERROR)) 73 | 74 | parameters <- c(1, 2, 3, 2) 75 | size <- blumberg(time, parameters[1], parameters[2], parameters[3], parameters[4]) 76 | 77 | expect_that(blumberg.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 78 | equals(time, tolerance = MAXERROR)) 79 | 80 | parameters <- c(10, 5, .43, 2) 81 | size <- blumberg(time, parameters[1], parameters[2], parameters[3], parameters[4]) 82 | 83 | expect_that(blumberg.inverse(size, parameters[1], parameters[2], parameters[3], parameters[4]), 84 | equals(time, tolerance = MAXERROR)) 85 | }) 86 | -------------------------------------------------------------------------------- /tests/testthat/testLogistic.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Logistic growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 27/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Logistic growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Logistic growth model values", { 27 | expected <- c(1.237842e-003, 5.523816e-003, 2.428890e-002, 1.003676e-001, 28 | 3.333333e-001, 6.914385e-001, 9.094430e-001, 9.782649e-001, 29 | 9.950670e-001 ) 30 | parameters <- c(1, 2, 3) 31 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 32 | 33 | expect_that(logistic(time, parameters[1], parameters[2], parameters[3]), 34 | equals(expected, tolerance = MAXERROR)) 35 | 36 | expected <- c(2.158345e-001, 5.691105e-001, 1.430435e+000, 3.227297e+000, 37 | 6, 8.772703e+000, 1.056956e+001, 1.143089e+001, 1.178417e+001) 38 | parameters <- c(12, 1, 2) 39 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 40 | 41 | expect_that(logistic(time, parameters[1], parameters[2], parameters[3]), 42 | equals(expected, tolerance = MAXERROR)) 43 | }) 44 | 45 | test_that("Inverse Logistic growth model values", { 46 | parameters <- c(1, 2, 3) 47 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 48 | size <- logistic(time, parameters[1], parameters[2], parameters[3]) 49 | 50 | expect_that(logistic.inverse(size, parameters[1], parameters[2], parameters[3]), 51 | equals(time, tolerance = MAXERROR)) 52 | 53 | parameters <- c(12, 1, 2) 54 | size <- logistic(time, parameters[1], parameters[2], parameters[3]) 55 | 56 | expect_that(logistic.inverse(size, parameters[1], parameters[2], parameters[3]), 57 | equals(time, tolerance = MAXERROR)) 58 | }) 59 | 60 | test_that("Generalised Logistic growth model values", { 61 | expected <- c(1.000045e+000, 1.000553e+000, 1.006715e+000, 1.078849e+000, 62 | 1.666667e+000, 2.717962e+000, 2.973407e+000, 2.997790e+000, 63 | 2.999818e+000) 64 | parameters <- c(1, 3, 5, 2, 0) 65 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 66 | 67 | expect_that(generalisedLogistic(time, parameters[1], parameters[2], parameters[3], parameters[4], parameters[5]), 68 | equals(expected, tolerance = MAXERROR)) 69 | 70 | expected <- c(1.200000e+001, 1.199998e+001, 1.199980e+001, 1.199751e+001, 71 | 1.196978e+001, 1.164518e+001, 9, 4.269170e+000, 3.119670e+000) 72 | parameters <- c(12, 3, 5, 2, 1) 73 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 74 | 75 | expect_that(generalisedLogistic(time, parameters[1], parameters[2], parameters[3], parameters[4], parameters[5]), 76 | equals(expected, tolerance = MAXERROR)) 77 | }) 78 | 79 | test_that("Inverse Generalised Logistic growth model values", { 80 | parameters <- c(1, 3, 5, 2, 0) 81 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 82 | size <- generalisedLogistic(time, parameters[1], parameters[2], parameters[3], 83 | parameters[4], parameters[5]) 84 | 85 | expect_that(generalisedLogistic.inverse(size, parameters[1], parameters[2], 86 | parameters[3], parameters[4], parameters[5]), 87 | equals(time, tolerance = MAXERROR)) 88 | 89 | parameters <- c(12, 3, 5, 2, 1) 90 | size <- generalisedLogistic(time, parameters[1], parameters[2], parameters[3], 91 | parameters[4], parameters[5]) 92 | 93 | expect_that(generalisedLogistic.inverse(size, parameters[1], parameters[2], 94 | parameters[3], parameters[4], parameters[5]), 95 | equals(time, tolerance = MAXERROR)) 96 | }) 97 | -------------------------------------------------------------------------------- /tests/testthat/testRichard.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Tests for the Richard growth model 3 | ## 4 | ## Created by Daniel Rodríguez Pérez on 28/7/2013. 5 | ## 6 | ## Copyright (c) 2013 Daniel Rodríguez Pérez. 7 | ## 8 | ## This program is free software: you can redistribute it and/or modify 9 | ## it under the terms of the GNU General Public License as published by 10 | ## the Free Software Foundation, either version 3 of the License, or 11 | ## (at your option) any later version. 12 | ## 13 | ## This program is distributed in the hope that it will be useful, 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ## GNU General Public License for more details. 17 | ## 18 | ## You should have received a copy of the GNU General Public License 19 | ## along with this program. If not, see 20 | ## 21 | 22 | context("Richard growth model") 23 | 24 | MAXERROR <- 1e-6 25 | 26 | test_that("Richard growth model invalid values", { 27 | parameters <- c(1, -2, 3, 4) 28 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0) 29 | 30 | result <- richard(time, parameters[1], parameters[2], parameters[3], 31 | parameters[4]) 32 | 33 | for (i in 1:length(time)) { 34 | expect_that(is.na(result[i]), is_true()) 35 | } 36 | }) 37 | 38 | test_that("Richard growth model values", { 39 | expected <- c(1.875713e-001, 2.726213e-001, 3.947771e-001, 5.628574e-001, 40 | 7.598357e-001, 9.118815e-001, 9.765486e-001, 9.945214e-001, 41 | 9.987644e-001) 42 | parameters <- c(1, 2, 3, 4) 43 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 44 | 45 | expect_that(richard(time, parameters[1], parameters[2], parameters[3], 46 | parameters[4]), 47 | equals(expected, tolerance = MAXERROR)) 48 | 49 | expected <- c(1.485410e-002, 6.628579e-002, 2.914668e-001, 1.204411e+000, 50 | 4, 8.297261e+000, 1.091332e+001, 1.173918e+001, 1.194080e+001) 51 | parameters <- c(12, 2, 3, 1) 52 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 53 | 54 | expect_that(richard(time, parameters[1], parameters[2], parameters[3], 55 | parameters[4]), 56 | equals(expected, tolerance = MAXERROR)) 57 | }) 58 | 59 | test_that("Inverse Richards growth model values", { 60 | parameters <- c(1, 2, 3, 4) 61 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 62 | size <- richard(time, parameters[1], parameters[2], 63 | parameters[3], parameters[4]) 64 | 65 | expect_that(richard.inverse(size, parameters[1], parameters[2], 66 | parameters[3], parameters[4]), 67 | equals(time, tolerance = MAXERROR)) 68 | 69 | parameters <- c(12, 2, 3, 1) 70 | size <- richard(time, parameters[1], parameters[2], 71 | parameters[3], parameters[4]) 72 | 73 | expect_that(richard.inverse(size, parameters[1], parameters[2], 74 | parameters[3], parameters[4]), 75 | equals(time, tolerance = MAXERROR)) 76 | }) 77 | 78 | test_that("Generalised Richard growth model values", { 79 | expected <- c(1.138049e+000, 1.257893e+000, 1.481437e+000, 1.891192e+000, 80 | 2.519671e+000, 2.925422e+000, 2.993318e+000, 2.999447e+000, 81 | 2.999955e+000) 82 | parameters <- c(1, 3, 5, 4, 2, 0) 83 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 84 | 85 | expect_that(generalisedRichard(time, parameters[1], parameters[2], parameters[3], 86 | parameters[4], parameters[5], parameters[6]), 87 | equals(expected, tolerance = MAXERROR)) 88 | 89 | expected <- c(1.200000e+001, 1.199999e+001, 1.199982e+001, 1.199779e+001, 90 | 1.197314e+001, 1.168460e+001, 9.333333e+000, 5.128151e+000, 91 | 4.106374e+000) 92 | parameters <- c(12, 4, 5, 1, 2, 1) 93 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 94 | 95 | expect_that(generalisedRichard(time, parameters[1], parameters[2], parameters[3], 96 | parameters[4], parameters[5], parameters[6]), 97 | equals(expected, tolerance = MAXERROR)) 98 | }) 99 | 100 | test_that("Inverse Richards growth model values", { 101 | parameters <- c(1, 3, 5, 4, 2, 0) 102 | time <- c(-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0) 103 | size <- generalisedRichard(time, parameters[1], parameters[2], 104 | parameters[3], parameters[4], 105 | parameters[5], parameters[6]) 106 | 107 | expect_that(generalisedRichard.inverse(size, parameters[1], parameters[2], 108 | parameters[3], parameters[4], parameters[5], 109 | parameters[6]), 110 | equals(time, tolerance = MAXERROR)) 111 | 112 | parameters <- c(12, 4, 5, 1, 2, 1) 113 | size <- generalisedRichard(time, parameters[1], parameters[2], 114 | parameters[3], parameters[4], 115 | parameters[5], parameters[6]) 116 | 117 | expect_that(generalisedRichard.inverse(size, parameters[1], parameters[2], 118 | parameters[3], parameters[4], parameters[5], 119 | parameters[6]), 120 | equals(time, tolerance = MAXERROR)) 121 | }) 122 | --------------------------------------------------------------------------------