View source: R/compute_deriv.R
compute_deriv | R Documentation |
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.
compute_deriv(family)
family |
A GLM family with family and link |
A list of two functions
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
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.