Learn R Programming

rvgtest (version 0.7.2)

Perturbation: Generate Random Variates from a Perturbed RVG

Description

These functions perturb the distribution of a given random variate generator. Thus it allows to investigate the power of tests for random variate generators.

Usage

pertadd(n, rdist = rnorm, ..., min = 0, max = 1, p = 0.001)
pertsub(n, rdist = rnorm, ..., min = 0, max = 1, p = 0.001)

Arguments

n
sample size.
rdist
given RVG to be perturbed.
...
parameters for given random variate generator.
min, max
left and right boundary of perturbed domain.
p
strength of perturbation.

Value

  • A vector of random variates from the perturbed distribution is returned.

Details

pertadd generates random variates from a mixture of rdist and a uniform distribution on the interval (min,max). The uniform distribution is chosen with probability p.

pertsub generates random variates from the rdist but rejects all points in the interval (min,max) with probability p. By varying the width of uniform distribution (min,max) and probability of error p, different levels of artificial error can be introduced. Thus it allows to investigate the power of tests for random variate generators.

Examples

Run this code
## Generating random sample with default settings
x <- pertadd(n=1000)
y <- pertsub(n=1000)

## Generating random sample, with parent distribution as exponential.
x <- pertadd(n=1000, rdist=rexp, rate=2, min=2, max=3, p=0.005)
y <- pertsub(n=1000, rdist=rexp, rate=2, min=2, max=3, p=0.005)

## Conducting chi-square test on random variates generated from function
## pertsub with parent distribution as exponential.
ft <- rvgt.ftable(n=1e4,rep=10,
                  rdist=function(n){pertsub(n,rdist=rexp,p=0.1)},
                  qdist=qexp,breaks=1001)
plot(ft)
rvgt.chisq(ft)

## Conducting chi-square test on random variates generated from function
## pertadd with parent distribution as Weibull,shape=1,scale=2.
ft <- rvgt.ftable(n=1e4,rep=10,
                  rdist=function(n,...){pertadd(n,rdist=rweibull,...,p=0.05)},
                  qdist=qweibull,shape=1,scale=2)
plot(ft)
rvgt.chisq(ft)

Run the code above in your browser using DataLab