nint_transform
applies monotonic transformations to some integrand and space.
A common use case is to apply the probability integral transform, or to transform infinite limits to finite ones.nint_transform(f, space, dIdcs, trans, infZero = 0)
function(x, ...)
, the integrand.list(g=function(x), gij=function(y))
where g(x) = y
and gij
evaluates to the column matrix of gi(y) = x
and its first derivative with respect to y<
f
returns 0
.nint_transform
returns a named list containing the transformed integrand and space.y = c(y1, ..., yn) = g(c(x1, ..., xn))
, then each component of y
shall exclusively depend on the corresponding component of x
.
So y[i] = g[i](x[i])
for some implicit function g[i]
.Builtins:
g(x) = atan(x) = y
g(x) = x/abs(x + sign(x))
= y withsign(0) == 1
nint_integrate
, nint_space
, fisherI
## builtins
f = sin
s = nint_space(nint_intvDim(pi/4, 3*pi/4))
nint_integrate(f, s)
tt = nint_transform(f, s, 1, 'tan')
tt$space
nint_integrate(tt$f, tt$space)
tt = nint_transform(f, s, 1, 'ratio')
tt$space
nint_integrate(tt$f, tt$space)
## probability integral transform
tt = nint_transform(f, s, 1, list(
g=pnorm,
gij=function(x) { t1 = qnorm(x); cbind(t1, 1/dnorm(t1)) })
)
tt$space
nint_integrate(tt$f, tt$space)
## infinite limitis
f = function(x) prod(1/(1 + x**2))
s = nint_space(nint_intvDim(-1, Inf),
nint_intvDim(-Inf, Inf))
s
nint_integrate(f, s) # stats::integrate takes care of Inf limits
tt = nint_transform(f, s, 1:2, 'tan')
tt$space
nint_integrate(tt$f, tt$space)
tt = nint_transform(f, s, 1:2, 'ratio')
tt$space
nint_integrate(tt$f, tt$space)
## probability integral transform
tt = nint_transform(f, s, 1:2, list(
g=pnorm,
gij=function(x) { t1 = qnorm(x); cbind(t1, 1/dnorm(t1)) })
)
tt$space
#nint_integrate(tt$f, tt$space) # Do you dare?
## The probability integral transform was used many times with fisherI,
## always with great success and considerable gains.
## It might be stats::integrate; see nint_integrateNCube
Run the code above in your browser using DataLab