Learn R Programming

BayesLogit (version 0.3)

rks: The Kolmogorov-Smirnov distribution

Description

Generate a random variate from the Kolmogorov-Smirnov distribution.

This is not directly related to the Polya-Gamma technique, but it is a nice example of using an alternating sum to generate a random variate.

Usage

rks(N=1)

Arguments

N
The number of random variates to generate.

Details

The density function of the KS distribution is

$$f(x) = 8 \sum_{i=1}^\infty (-1)^{n+1} n^2 x e^{-2 n^2 x^2}.$$

We follow Devroye (1986) p. 161 to generate random draws from KS.

References

L. Devroye. Non-Uniform Random Variate Generation, 1986.

Examples

Run this code
X = rks(1000)

Run the code above in your browser using DataLab