checklaw: Check proper behaviour of a random generator

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

Description

It is desirable to check if a newly added random generator coded in C behaves correctly. To perform this operation, one can superimpose the theoretical density on a histogram of the generated values.

Usage

1
2
checklaw(law.index, sample.size = 50000, law.pars = NULL, density =
NULL, trunc = c(-Inf, Inf), center = FALSE, scale = FALSE)

Arguments

law.index

index of the desired law, as given by getindex.

sample.size

number of observations to generate.

law.pars

vector of parameters for the law. The length of this parameter should not exceed 4. If not provided, the default values are used by means of getindex function.

density

a function of two arguments x and pars. Can also be a function of the arguments x and pars[1], ..., pars[k]. See the two examples below.

trunc

vector of left and right truncation thresholds for the generated sample values. Only those values in between will be kept to build the histogram. This can be useful for a distribution with extreme values.

center

Logical. Should we center the data.

scale

Should we scale the data.

Value

Returns invisibly the data generated and make a plot showing histogram and density superimposed.

Author(s)

P. Lafaye de Micheaux, V. A. Tran

References

Pierre Lafaye de Micheaux, Viet Anh Tran (2016). PoweR: A Reproducible Research Tool to Ease Monte Carlo Power Simulation Studies for Goodness-of-fit Tests in R. Journal of Statistical Software, 69(3), 1–42. doi:10.18637/jss.v069.i03

See Also

gensample

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
dlaplace1 <- function(x, mu, b) {dexp(abs(x - mu), 1 / b) / 2}
checklaw(1, density = dlaplace1)
dlaplace2 <- function(x, pars) {dexp(abs(x - pars[1]), 1 / pars[2]) / 2}
checklaw(1, density = dlaplace2)


checklaw(law.index = 2, sample.size = 50000, law.pars = c(2, 3), density
= dnorm)

## We use the 'trunc' argument to display the density in a region where
## no extreme values are present.
checklaw(27, density = dlaw27, trunc = c(-Inf,10))

# This one (Tukey) does not have a closed form expression for
# the density. But we can use the stats::density() function as
# follows.
res <- checklaw(18)
lines(density(res$sample), col = "blue")

PoweR documentation built on May 2, 2019, 2:09 p.m.

Related to checklaw in PoweR...