#' Make Negative Loglikelihood Function to be Minimized
#'
#' Note that the general
#' form of the model has parameters in addition to those in the loss model,
#' namely the power for the variance and the constant of proprtionality that
#' varies by column. So if the original model has k parameters with size
#' columns of data, the total objective function has k + size + 1 parameters
#' @param a do not know
#' @param A do not know
#' @param dnom numeric vector representing the exposures (claims) used in the
#' denominator
#' @param g_obj objective function
#' @export
make_negative_log_likelihood <- function(a, A, dnom, g_obj) {
npar = length(a) - 2
size <- length(dnom)
# Generate a matrix to reflect exposure count in the variance structure
logd = log(matrix(dnom, size, size))
e = g_obj(a[1:npar])
v = exp(-outer(logd[, 1], rep(a[npar + 1], size), "-")) * (e^2)^a[npar + 2]
t1 = log(2 * pi * v) / 2
t2 = (A - e) ^ 2 / (2 * v)
sum(t1 + t2, na.rm = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.