compute_deriv: Derivative of the negative log-likelihood

View source: R/compute_deriv.R

compute_derivR Documentation

Derivative of the negative log-likelihood

Description

Compute the derivative of the negative log-likelihood of a GLM w.r.t. the linear predictor

Let f_y(t) be the negative log-likelihood function when the linear predictor is t and the response is y. This function computes

g(t) = f'_y(t)

and

g'(t)=f''_y(t).

This function uses *formula* of GLM likelihoods. Currently, it supports Poisson regression (log link) and binary regression (with logit/probit link).

For a logistic regression, f_y(t) = \log(1+e^{-yt}), where y \in \pm 1. Then

g(t) = \frac{-y}{1+e^{yt}},

and

g'(t) = \frac{1}{(1+e^{yt})(1+e^{-yt})}.

For a probit regression, f_y(t) = -\log(\Phi(yt)) where \Phi(\cdot) is the normal cdf. Then,

g(t) = -\frac{y\phi(yt)}{\Phi(yt)},

where \phi is the normal pdf, and

g'(t) = \frac{\phi(yt)^2}{\Phi(yt)^2} - \frac{\phi'(yt)}{\Phi(yt)}.

For a Poisson regression, f_y(t) = e^t - yt + \log(y!), so

g(t) = e^t - y,

and

g't(t) = e^t.

Usage

compute_deriv(family)

Arguments

family

A GLM family with family and link

Value

A list of two functions

g

A function which takes two inputs – a vector of response y and a vector of linear predictors t – and returns the derivative of the negative log-likelihood w.r.t. the linear predictor at y

gprime

A function which takes two inputs – a vector of response y and a vector of linear predictors t – and returns the *second* derivative of the negative log-likelihood w.r.t. the linear predictor at y


zq00/glmhd documentation built on April 7, 2023, 7:45 a.m.