Computes the score function \(s_a(\alpha) = \partial/\partial a \log g_{a,b}(\alpha)\) for the Gamma(a, b) distribution.
Details
For the Gamma(shape = a, rate = b) distribution with density
$$g_{a,b}(\alpha) = \frac{b^a}{\Gamma(a)} \alpha^{a-1} e^{-b\alpha},$$
the score function with respect to a is:
$$s_a(\alpha) = \log b - \psi(a) + \log \alpha,$$
where \(\psi\) is the digamma function.
A fundamental property of score functions is that their expectation is zero: $$E_{\alpha \sim g_{a,b}}[s_a(\alpha)] = 0.$$
Numerical Note: The log(alpha) term causes slower quadrature
convergence for score-weighted integrands compared to the moments themselves.
Use higher M (e.g., 120-200) for verification purposes.
See also
score_b for the score with respect to b
Examples
# Evaluate score at several points
alpha_vals <- c(0.5, 1.0, 2.0, 5.0)
score_a(alpha_vals, a = 2.0, b = 1.0)
#> [1] -1.1159315 -0.4227843 0.2703628 1.1866536