#' Size at age
#'
#' Calculate expected size at a given age
#'
#' @param A (numeric) Asymptotic body size (can be calculated in \code{calc.growth()})
#' @param k (numeric) Growth rate (can be calculated in \code{calc.growth()})
#' @param age (numeric vector) The age(s) for which you want to know the size (should be in the same units used to calculate A and k)
#' @param 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.
#' @param model (character) The model used to calculate A and k. One of "vb", "gompertz","logistic".
#' @return Vector of expected size(s)
#'
#' @details
#' It takes a vector of ages, initial size for the species, and A and k from \code{calc.growth()} and returns the expected body sizes at a given age based on the specified model.
#'
#' @examples
#' #For this example, assume size is in mm and time is in years
#' #Use the gompertz formula to calculate the expected size of a 5-year old
#' #turtle for a species that hatches at an average size of 50 mm
#' size.at.age(A = 396.6738,
#'  k = 0.2029850,
#'  age = 5,
#'  size0 = 50,
#'  model="gompertz")
#'
#' @export
size.at.age <- function(A, k, age, size0,model){
  if(model=="gompertz"){size <- A*(size0/A)^exp(-k*age)}else{
    if(model=="logistic"){size <- (A * size0) / (size0 + (A - size0) * exp(-k * age))}else{
      size <- A-(A-size0)*exp(-k*age)
    }
  }
  size
}
