| gradient_log_likelihood2 | R Documentation |
Computes the exact gradient of log_likelihood2 with respect
to all regression coefficients. With the per-observation log-probability
\log p = \mathrm{lchoose}(n, y) + \mathrm{lbeta}(y+\alpha, n-y+\beta)
- \mathrm{lbeta}(\alpha, \beta),
the partial derivatives on the natural scale are (with digamma function
\psi):
\partial \log p/\partial\alpha = \psi(y+\alpha) - \psi(\alpha)
+ \psi(\alpha+\beta) - \psi(n+\alpha+\beta)
\partial \log p/\partial\beta = \psi(n-y+\beta) - \psi(\beta)
+ \psi(\alpha+\beta) - \psi(n+\alpha+\beta)
The chain rule through the log link multiplies by \alpha resp.
\beta; coefficient gradients follow as
-X^\top(w \cdot \partial\ell/\partial\eta) for the negative
log-likelihood. Contributions of observations whose linear predictor is
clamped (see log_likelihood2) are zeroed, which is the exact
subgradient of the clamped objective.
gradient_log_likelihood2(params, X, Z, y, n, weights = NULL, lch = NULL)
params |
A numeric vector containing all model parameters. The first n_alpha elements are coefficients for the alpha model, and the remaining elements are coefficients for the beta model. |
X |
A matrix of predictors for the alpha model. |
Z |
A matrix of predictors for the beta model. |
y |
A numeric vector of response values. |
n |
The maximum score (number of trials). |
weights |
A numeric vector of weights for each observation (NULL = equal weights). |
lch |
Optional precomputed |
Supplying this gradient to optim (L-BFGS-B) replaces
the finite-difference approximation, which required
length(params) + 1 likelihood evaluations per gradient.
Numeric vector: gradient of the negative log-likelihood with
respect to params.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.