#' @noRd
ml <- function(par, size1, td, size2,model,fixed.A) {
  if (is.null(fixed.A)) {
    A     <- par[1]
    k     <- par[2]
    sigma <- par[3]
  } else {
    A     <- fixed.A  # use the fixed value
    k     <- par[1]   # only k and sigma estimated
    sigma <- par[2]
  }

  if(model=="gompertz"){pred <- gompertz(A = A, k = k, size1 = size1, td = td)}else{
    if(model=="logistic"){pred <- logistic(A = A, k = k, size1 = size1, td = td)}else{
      pred <- vb(A = A, k = k, size1 = size1, td = td)}
      }

  # Sum of negative log-likelihood under normal distribution
  nll <- -sum(dnorm(size2, mean = pred, sd = sigma, log = TRUE))
  nll
}


