Gradients of common densities
gfun.RdGradients of common density functions in their standard forms, i.e.,
with zero location (mean) and unit scale. These are implemented in C
for speed and care is taken that the correct results are provided for
the argument being NA, NaN, Inf, -Inf or
just extremely small or large.
Details
The gradients are given by:
gnorm: If \(f(x)\) is the normal density with mean 0 and spread 1, then the gradient is $$f'(x) = -x f(x)$$
glogis: If \(f(x)\) is the logistic density with mean 0 and scale 1, then the gradient is $$f'(x) = 2 \exp(-x)^2 (1 + \exp(-x))^{-3} - \exp(-x)(1+\exp(-x))^{-2}$$
pcauchy: If \(f(x) = [\pi(1 + x^2)^2]^{-1}\) is the cauchy density with mean 0 and scale 1, then the gradient is $$f'(x) = -2x [\pi(1 + x^2)^2]^{-1}$$
These gradients are used in the Newton-Raphson algorithms in fitting
cumulative link models with clm and cumulative link
mixed models with clmm.
Examples
x <- -5:5
gnorm(x)
#> [1] 7.433598e-06 5.353209e-04 1.329555e-02 1.079819e-01 2.419707e-01
#> [6] 0.000000e+00 -2.419707e-01 -1.079819e-01 -1.329555e-02 -5.353209e-04
#> [11] -7.433598e-06
glogis(x)
#> [1] 0.006559068 0.017027336 0.040891575 0.079962501 0.090857748
#> [6] 0.000000000 -0.090857748 -0.079962501 -0.040891575 -0.017027336
#> [11] -0.006559068
gcauchy(x)
#> [1] 0.004708726 0.008811346 0.019098593 0.050929582 0.159154943
#> [6] 0.000000000 -0.159154943 -0.050929582 -0.019098593 -0.008811346
#> [11] -0.004708726