uerror: Create Table of U-Errors for Numerical Inversion Method

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/uerror.R

Description

Function for creating a table of u-errors of a numerical inversion method (i.e., it uses an approximate quantile function of the target distribution). Thus the domain of the inverse distribution function is partitioned into intervals for which maxima, minima and some other quantiles of the u-errors are computed.

Currently the function only works for generators for continuous univariate distribution.

Usage

1
2
uerror(n, aqdist, pdist, ..., trunc=NULL, udomain=c(0,1),
       res=1000, tails=FALSE, plot=FALSE)

Arguments

n

sample size for one repetition.

aqdist

approximate inverse distribution function (quantile function) for a continuous univariate distribution.

pdist

cumulative distribution function for distribution.

...

parameters to be passed to pdist.

trunc

boundaries of truncated domain. (optional)

udomain

domain of investigation for (approximate) quantile function aqdist.

res

resolution (number of intervals).

tails

logical. If TRUE, then the tail regions are treated more accurately. However, this doubles the given sample size.

plot

logical. If TRUE, the (range of the) u-errors is plotted.

Details

The u-error of an approximate inverse distribution function (quantile function) G^[-1] for some u in (0,1) is given by

e_u(u) = |u - F(G^[-1](u))|

where F denotes the (exact) cumulative distribution. It is a convenient measure for approximation errors in non-uniform random variate generators bases on numerical inversion, see the reference below for our arguments.

Computing, plotting and analyzing of such u-errors can be quite time consuming.

e_u(u)

is a very volatile function and requires the computation at a lot of points. For plotting we can condense the information by partitioning (0,1) into intervals of equal length. In each of these the u-error is computed at equidistributed points and some quantiles (see below) are estimated and stored. Thus we save memory and it is much faster to plot and compare u-errors for different methods or distributions.

If trunc is given, then function pdist is rescaled to this given domain. Notice, however, that this has some influence on the accuracy of the results of the distribution function pdist.

Using argument udomain it is possible to restrict the domain of the given (approximate) quantile function aqdist, i.e., of its argument u.

When tails=TRUE we use additional n points for the first and last interval (which correspond to the tail regions of the distribution).

Value

An object of class "rvgt.ierror" which is a list with components:

n

sample size.

res

resolution (number of intervals).

kind

kind of error (string).

udomain

domain for u.

min

an array of minimum u-errors (of length res).

lqr

an array of lower quartile of u-errors (of length res).

med

an array of median u-errors (of length res).

uqr

an array of upper quartile of u-errors (of length res).

max

an array of maximum u-errors (of length res).

mad

an array of mean absolute deviations (of length res).

mse

an array of mean squared errors (of length res).

Note

It should be noted that uerror computes the numerical error of the composed function pdist(aqdist(u)). Thus one needs a distribution function pdist that is numerically (much) more accurate than aqdist.

The random variate generator rdist can alternatively be a generator object form the Runuran package.

Author(s)

Josef Leydold [email protected]

References

G. Derflinger, W. H\"ormann, and J. Leydold (2009): ACM Trans. Model. Comput. Simul., to appear.

See Also

See plot.rvgt.ierror for the syntax of the plotting method. See xerror for computing x-errors.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Create a table of u-errors for spline interpolation of
## the inverse CDF of the standard normal distribution.
aqn <- splinefun(x=pnorm((-100:100)*0.05), y=(-100:100)*0.05,
                 method="monoH.FC")
## Use a sample of size of 10^5 random variates.
uerrn <- uerror(n=1e5, aqdist=aqn, pdist=pnorm)

## Plot u-errors
plot(uerrn)

## Investigate tails more accurately, and use
## a resolution of 1000 intervals.
uerrn <- uerror(n=1e5, aqdist=aqn, pdist=pnorm, res=1000, tails=TRUE)


## Same for a gamma distribution.
## But this time we immediately plot the error.
aqg <- splinefun(x=pgamma((0:500)*0.1,shape=5),
                 y=(0:500)*0.1, method="monoH.FC")
uerrg <- uerror(n=1e5, aqdist=aqg, pdist=pgamma, shape=5,
                plot=TRUE)


## Compute u-error for a subdomain of a beta distribution
aqb <- splinefun(x=pbeta((0:100)*0.01,shape1=2,shape2=5),
                 y=(0:100)*0.01, method="monoH.FC")
uerrb <- uerror(n=1e5, aqdist=aqb, pdist=pbeta, shape1=2, shape2=5,
                udomain=c(0.6,0.65), plot=TRUE)

## Show all u-errors in one plot
plot.rvgt.ierror(list(uerrn,uerrg,uerrb))

## An inverse CDF for a truncated normal distribution
aqtn <- splinefun(x=(pnorm((0:100)*0.015) - pnorm(0))/(pnorm(1.5)-pnorm(0)),
                  y=(0:100)*0.015, method="monoH.FC")
uerrtn <- uerror(n=1e5, aqdist=aqtn, pdist=pnorm, trunc=c(0,1.5),
                 plot=TRUE)

rvgtest documentation built on May 29, 2017, 9:11 a.m.