R/checkGH.R

Defines functions checkGH

Documented in checkGH

checkGH <- function(object, tol = 1e-4) {

    nll <- function(parm) -logLik(object, parm = parm)

    ### check gradient  and hessian
    suppressWarnings(gr <- numDeriv::grad(nll, coef(object))) 
    s <- Gradient(object)
    ret <- isTRUE(all.equal(gr, s, check.attributes = FALSE, tol = tol))

    suppressWarnings(H1 <- numDeriv::hessian(nll, coef(object)))
    H2 <- Hessian(object)
    ret <- ret & isTRUE(all.equal(H1, H2, check.attributes = FALSE, tol = tol))
    return(ret)
}

Try the mlt.docreg package in your browser

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

mlt.docreg documentation built on April 3, 2025, 9:24 p.m.