make_moment_function {aghq} | R Documentation |
Moments of Positive Functions
Description
Given an object quad
of class aghq
returned by aghq::aghq()
, aghq::compute_moment()
will compute the moment of a positive function g(theta)
of parameter theta
. The present function,
aghq::make_moment_function()
, assists the user in constructing the appropriate input to aghq::compute_moment()
.
Usage
make_moment_function(...)
## S3 method for class 'aghqmoment'
make_moment_function(gg, ...)
## S3 method for class 'aghqtrans'
make_moment_function(gg, ...)
## S3 method for class ''function''
make_moment_function(gg, ...)
## S3 method for class 'character'
make_moment_function(gg, ...)
## S3 method for class 'list'
make_moment_function(gg, ...)
## Default S3 method:
make_moment_function(gg, ...)
Arguments
... |
Used to pass arguments to methods. |
gg |
LOGARITHM of function |
Details
The approximation of moments of positive functions implemented in aghq::compute_moment()
achieves the same asymptotic rate of convergence as the marginal likelihood. This involves computing a new mode and
Hessian depending on the original posterior mode and Hessian, and g
. These computations are handled by aghq::compute_moment()
,
re-using information from the original quadrature when feasible.
Computation of moments is defined only for scalar-valued functions, with a vector moment just defined as a vector of moments. Consequently,
the user may input to aghq:compute_moment()
a function g: R^p -> R^q+
for any q
, and that function will return the corresponding
vector of moments. This is handled within aghq::compute_moment()
. The aghq::make_moment_function()
interface accepts the logarithm of gg: R^p -> R^+
, i.e.
a multivariable, scalar-valued positive function. This is mostly to keep first and second derivatives as 1d and 2d arrays (i.e. the gradient and the Hessian);
I deemed it too confusing for the user and the code-base to work with Jacobians and 2nd derivative tensors (if you're confused just reading this, there you go!).
But, see aghq::compute_moment()
for how to handle the very common case where the same transformation is desired of all parameter coordinates; for example
when all parameters are on the log-scale and you want to compute E(exp(theta))
for vector theta
.
If gg
is a function
or a character
(like 'exp'
) it is first passed to match.fun
, and then the output
object is constructed using numDeriv::grad()
and numDeriv::hessian()
. If gg
is a list
then it is assumed to
have elements fn
, gr
, and he
of the correct form, and these elements are extracted and then passed back to make_moment_function()
.
If gg
is an object of class aghqtrans
returned by aghq::make_transformation()
, then gg$fromtheta
is passed back to make_moment_function()
. If gg
is an object of class aghqtrans
then it is just returned.
Value
Object of class aghqmoment
, which is a list with elements fn
,
gr
, and he
, exactly like the input to aghq::aghq()
and related functions. Here gg$fn
is
log(gg(theta))
, gg$gr
is its gradient, and gg$he
its Hessian.
Object is suitable for checking with aghq::validate_moment()
and for inputting into aghq::compute_moment()
.
See Also
Other moments:
validate_moment()
Examples
# E(exp(x))
mom1 <- make_moment_function(force) # force = function(x) x
mom2 <- make_moment_function('force')
mom3 <- make_moment_function(list(fn=function(x) x,gr=function(x) 1,he = function(x) 0))