Last data update: 2014.03.03

R: Inversion Tests for Distributions
inversionTestsR Documentation

Inversion Tests for Distributions

Description

Functions to check performance of distribution and quantile functions. Applying the distribution function followed by the quantile function to a set of numbers should reproduce the original set of numbers. Likewise applying the quantile function followed by the distribution function to numbers in the range (0,1) should produce the original numbers.

Usage

inversionTestpq(densFn = "norm", n = 10,
                intTol = .Machine$double.eps^0.25,
                uniTol = intTol, x = NULL, method = "spline", ...)
inversionTestqp(densFn = "norm",
                qs = c(0.001, 0.01, 0.025, 0.05, 0.1, 0.2, 0.4, 0.5,
                       0.6, 0.8, 0.9, 0.95, 0.975, 0.99, 0.999),
                uniTol = .Machine$double.eps^0.25,
                intTol = uniTol, method = "spline", ...)

Arguments

densFn

Character. The root name of the distribution to be tested.

qs

Numeric. Set of quantiles to which quantile function then distribution function will be applied. See Details.

n

Numeric. Number of values to be sampled from the distribution. See Details.

x

Numeric. Values at which the distribution function is to be evaluated. If NULL values are drawn at random from the distribution.

intTol

Value of rel.tol and hence abs.tol in calls to integrate. See integrate.

uniTol

Value of tol in calls to uniroot. See uniroot.

method

Character. If "spline" quantiles are found from a spline approximation to the distribution function. If "integrate", the distribution function used is always obtained by integration.

...

Additional arguments to allow specification of the parameters of the distribution.

Details

inversionTestpq takes a sample from the specified distribution of size n then applies the distribution function, followed by the quantile function. inversionTestqp applies the quantile function, followed by the distribution function to the set of quantiles specified by qs.

In both cases the starting and ending values should be the same.

These tests are used in base R to check the standard distribution functions. The code may be found in the file d-p-q-r.tests.R in the tests directory.

Value

inversionTestpq returns a list with components:

qpx

Numeric. The result of applying the distribution function (‘p’ function) then the quantile function (‘q’ function) to the randomly generated set of x values.

x

Numeric. The set of x values generated by the ‘r’ function.

diffs

Numeric. The differences qpx minus x.

n

Numeric. Number of values sampled from the distribution.

inversionTestqp returns a list with components:

pqqs

Numeric. The result of applying the quantile function (‘q’ function) then the distribution function (‘p’ function) to the quantiles qs.

qs

Numeric. The set of quantiles.

diffs

Numeric. The differences pqqs minus qs.

Author(s)

David Scott d.scott@auckland.ac.nz, Christine Yang Dong c.dong@auckland.ac.nz

Examples

## Default distribution is normal
inversionTestpq()
inversionTestqp()
## Supply parameters
inversionTestpq(mean = 1, sd = 2)
inversionTestqp(mean = 1, sd = 2)
## Gamma distribution, must specify shape
inversionTestpq("gamma", shape = 1)
inversionTestqp("gamma", shape = 1)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DistributionUtils)
Loading required package: RUnit
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DistributionUtils/inversionTests.Rd_%03d_medium.png", width=480, height=480)
> ### Name: inversionTests
> ### Title: Inversion Tests for Distributions
> ### Aliases: inversionTestpq inversionTestqp
> ### Keywords: distribution univariate
> 
> ### ** Examples
> 
> ## Default distribution is normal
> inversionTestpq()
$qpx
 [1] -1.84441987  0.50050529  1.03314074  0.08316506  0.35427339 -1.73502949
 [7]  0.53864332  0.47927936 -0.46716913 -0.73263676

$x
 [1] -1.84440097  0.50050551  1.03313872  0.08316835  0.35424893 -1.73502910
 [7]  0.53864948  0.47927941 -0.46716915 -0.73261758

$diffs
 [1] -1.889832e-05 -2.278248e-07  2.015823e-06 -3.296078e-06  2.446070e-05
 [6] -3.869718e-07 -6.156923e-06 -5.224606e-08  2.070762e-08 -1.918600e-05

$n
[1] 10

> inversionTestqp()
$pqqs
 [1] 0.0009999714 0.0099997964 0.0249996441 0.0499999898 0.1000000871
 [6] 0.1999972731 0.4000000240 0.4999974458 0.5999999760 0.8000027272
[11] 0.8999999130 0.9500000102 0.9750003555 0.9900002037 0.9990000286

$qs
 [1] 0.001 0.010 0.025 0.050 0.100 0.200 0.400 0.500 0.600 0.800 0.900 0.950
[13] 0.975 0.990 0.999

$diffs
 [1] -2.864192e-08 -2.035915e-07 -3.558819e-07 -1.017832e-08  8.713340e-08
 [6] -2.726853e-06  2.397406e-08 -2.554158e-06 -2.397560e-08  2.727152e-06
[11] -8.697636e-08  1.016941e-08  3.555057e-07  2.037472e-07  2.864629e-08

> ## Supply parameters
> inversionTestpq(mean = 1, sd = 2)
$qpx
 [1]  1.5066370  0.9429062  0.9142571  3.7372042  0.5484581  4.0329416
 [7] -2.0975064  2.1692279  1.2477088  1.4318831

$x
 [1]  1.5066370  0.9429065  0.9142591  3.7372046  0.5484580  4.0329412
 [7] -2.0975056  2.1692275  1.2477085  1.4318831

$diffs
 [1] -7.186498e-08 -2.442755e-07 -1.943442e-06 -3.423013e-07  7.778838e-08
 [6]  4.128044e-07 -8.124250e-07  4.135073e-07  3.068431e-07 -7.253819e-08

$n
[1] 10

> inversionTestqp(mean = 1, sd = 2)
$pqqs
 [1] 0.0009999612 0.0099999739 0.0249995359 0.0499998803 0.0999985637
 [6] 0.1999974328 0.4000000139 0.5000003590 0.5999999861 0.8000025672
[11] 0.9000014360 0.9500001197 0.9750004630 0.9900000261 0.9990000388

$qs
 [1] 0.001 0.010 0.025 0.050 0.100 0.200 0.400 0.500 0.600 0.800 0.900 0.950
[13] 0.975 0.990 0.999

$diffs
 [1] -3.875092e-08 -2.613719e-08 -4.640982e-07 -1.196796e-07 -1.436320e-06
 [6] -2.567246e-06  1.387543e-08  3.590049e-07 -1.387547e-08  2.567211e-06
[11]  1.436023e-06  1.196968e-07  4.630322e-07  2.613428e-08  3.875100e-08

> ## Gamma distribution, must specify shape
> inversionTestpq("gamma", shape = 1)
$qpx
 [1] 0.69516175 0.48001834 1.74586164 0.71420068 0.03335256 5.18989135
 [7] 2.40268148 0.34370546 0.20789194 3.17576445

$x
 [1] 0.69516581 0.48001813 1.74584207 0.71422531 0.03334971 5.18987976
 [7] 2.40265625 0.34370301 0.20788589 3.17576083

$diffs
 [1] -4.055891e-06  2.155659e-07  1.956315e-05 -2.463441e-05  2.845905e-06
 [6]  1.159010e-05  2.522493e-05  2.444167e-06  6.046741e-06  3.616868e-06

$n
[1] 10

There were 36 warnings (use warnings() to see them)
> inversionTestqp("gamma", shape = 1)
$pqqs
 [1] 0.0009537344 0.0099818866 0.0249783099 0.0499991523 0.0999930218
 [6] 0.1999935392 0.4000004336 0.4999991367 0.5999998937 0.8000027749
[11] 0.9000000292 0.9500014959 0.9750003063 0.9899997158 0.9989999721

$qs
 [1] 0.001 0.010 0.025 0.050 0.100 0.200 0.400 0.500 0.600 0.800 0.900 0.950
[13] 0.975 0.990 0.999

$diffs
 [1] -4.626563e-05 -1.811339e-05 -2.169008e-05 -8.476552e-07 -6.978172e-06
 [6] -6.460825e-06  4.335688e-07 -8.633216e-07 -1.062808e-07  2.774914e-06
[11]  2.922898e-08  1.495915e-06  3.063489e-07 -2.842158e-07 -2.790377e-08

There were 36 warnings (use warnings() to see them)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>