% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calc.growth.R
\name{calc.growth}
\alias{calc.growth}
\title{Calculate growth curves}
\usage{
calc.growth(
  x,
  size0 = NULL,
  age.vect = NULL,
  models = c("vb", "gompertz", "logistic"),
  fixed.A = NULL,
  initial.A = NULL,
  initial.k = 0.5,
  size1.col = "size1",
  size2.col = "size2",
  times.col = "td",
  type = "ML",
  runs = 5000,
  seed = 1701,
  return.plot = TRUE,
  optimizer = "L-BFGS-B"
)
}
\arguments{
\item{x}{(data frame) Output from \code{MRgrowth::format.data()} Data frame with columns of size at capture, size at recapture, and amount of time between captures.}

\item{size0}{(numeric) Initial body size at birth/hatching (should be in the same units used to calculate A and k). This will generally be a species average, rather than being specific per individual, but it can be a vector of specific birth/hatching sizes per individual if known. Note that this will not affect the final values of A, k, or their confidence intervals, but it will affect the estimated sizes at ages.}

\item{age.vect}{(numeric vector) Vector of ages for which you would like expected sizes and confidence intervals around the size (used for plotting growth curves). If age.vect is not supplied, a vector from 1 to 4x the largest time interval will be used (default = NULL)}

\item{models}{(character vector) The model(s) used to calculate A and k. Can be any combination of "vb", "gompertz","logistic". Fitted parameters, model diagnostics, and sizes at expected ages will be returned for all included models (default = c("vb", "gompertz","logistic"))}

\item{fixed.A}{(numeric) This fixes the asymptotic size (A) at the specified value, meaning that only the growth rate (k) will be estimated. Use with caution (see vignette; default = NULL)}

\item{initial.A}{(numeric) Starting value for the search algorithm for the asymptotic size (A). This has no impact on the results, but an initial.A that is close to the final A will result in a faster run time (default = max size in your data set).}

\item{initial.k}{(numeric) Starting value for the search algorithm for the growth rate (k). This has no impact on the results, but an initial.k that is close to the final k will result in a faster run time (default = 0.5).}

\item{size1.col}{(character) Name of column containing size data at capture (default = "size1"; the output from \code{MRgrowth::format.data()})}

\item{size2.col}{(character) Name of column containing size data at recapture (default = "size2"; the output from \code{MRgrowth::format.data()})}

\item{times.col}{(character) Name of column containing time interval between captures (default = "td"; the output from \code{MRgrowth::format.data()})}

\item{type}{(character) Method used of fitting the model. One of "ML" (Maximum Likelihood) or "OLS" (Ordinary Least Squares; default = "ML")}

\item{runs}{(integer) The number of bootstraps to use for calculating confidence intervals. Large values result in long run times (see Vignette; default = 5000)}

\item{seed}{(integer) Seed to use for random selections when calculating bootstrapped confidence intervals (default = 1701).}

\item{return.plot}{(logical) Determines whether a plot of growth curves should be printed (default = TRUE)}

\item{optimizer}{(character) One of the optimization methods available in \code{\link[stats]{optim}} (default = "L-BFGS-B")}
}
\value{
A list of two objects:
\describe{
 \item{parameters}{A data frame with one row per model containing the following columns:
    \describe{
      \item{model}{The growth model fitted}
      \item{A}{Estimated asymptotic size}
      \item{A.lower}{Lower 95\% bootstrap confidence interval for A}
      \item{A.upper}{Upper 95\% bootstrap confidence interval for A}
      \item{k}{Estimated growth coefficient}
      \item{k.lower}{Lower 95\% bootstrap confidence interval for k}
      \item{k.upper}{Upper 95\% bootstrap confidence interval for k}
      \item{convergence}{Convergence code from \code{\link[stats]{optim}}; 0 indicates successful convergence}
      \item{NLL}{Negative log-likelihood of the fitted model (only returned when \code{type="ML"})}
      \item{SS}{Sum of squares (only returned when \code{type="OLS"})}
      \item{AIC}{Akaike Information Criterion (only returned when \code{type="ML"})}
      \item{AICc}{Sample size corrected AIC (only returned when \code{type="ML"})}
      \item{fixed.AIC}{Akaike Information Criterion calculated with 2 parameters when A is fixed (only returned when \code{type="ML"} and a value is entered for \code{fixed.A})}
      \item{fixed.AICc}{Sample size corrected AIC calculated with 2 parameters when A is fixed (only returned when \code{type="ML"} and a value is entered for \code{fixed.A})}

    }
  }
  \item{sizes.at.ages}{A data frame with one row per age per model containing the following columns:
    \describe{
      \item{model}{The growth model fitted}
      \item{age}{Age from \code{age.vect}}
      \item{size}{Predicted size at a given age}
      \item{upper}{Upper 95\% bootstrap confidence interval for predicted size}
      \item{lower}{Lower 95\% bootstrap confidence interval for predicted size}
    }
  }
}
}
\description{
Calculate, compare, and plot growth curves based on different models
}
\details{
This is the primary function for MRgrowth. It takes the output from \code{format.data()}, calculates growth curves the selected model(s), and returns the model parameters and the data for plotting curves. The output includes model diagnostics like AIC values that can be used to evaluate model fit and compare models.
}
\examples{

data(MRdata)

#format the data
formatted.data <- format.data(
 x = MRdata,
 id.col = "id",
 date.col = "date",
 size.col = "size",
 units = "years",
 retain = "max")

#get growth curves for the gompertz and logistic methods.
#runs are set to 10 to keep the run time low.
#For actual CI estimates, much higher values are needed
#likewise, the plot function has been turned off
g.result <- calc.growth(formatted.data,
   size0=50,
   age.vect=c(1:40),
   models=c("gompertz","logistic"),
   runs=10,
   return.plot=FALSE)

}
\references{
von Bertalanffy, L. (1957). Quantitative laws in metabolism and growth.
\emph{The Quarterly Review of Biology}, 32, 217-231.

Fabens, A.J. (1965). Properties and fitting of the Von Bertalanffy growth curve.
\emph{Growth}, 29, 265-289.

Gompertz, B. (1833). On the nature of the function expressive of the law of human
mortality, and on a new mode of determining the value of life contingencies.
\emph{Philosophical Transactions of the Royal Society of London}, 123, 252-253.

Schoener, T.W. and Schoener, A. (1978). Estimating and interpreting body-size
growth in some Anolis lizards. \emph{Copeia}, 1978, 390-405.
}
