R/calc_jacobian.R

Defines functions calc_jacobian

calc_jacobian <-
function(ftheta, theta_hat, jacobian_args = NULL){
  stopifnot(is.function(ftheta), is.numeric(theta_hat),
            is.null(jacobian_args) || is.list(jacobian_args))
  func <- function(x) ftheta(x)
  arg_list <- c(list(func = func, x = theta_hat), jacobian_args)
  J <- tryCatch(do.call(numDeriv::jacobian, args = arg_list),
                error = function(e) stop("Unable to compute Jacobian: ", e))
  validate_numeric(J)
  stopifnot(is.matrix(J))
  return(J)
}

Try the distfreereg package in your browser

Any scripts or data that you put into this service are public.

distfreereg documentation built on April 4, 2025, 12:30 a.m.