Learn R Programming

copula (version 0.999-7)

rlog: Sampling Logarithmic Distributions

Description

Generating random variates from a Log(p) distribution with probability mass function $$p_k=\frac{p^k}{-\log(1-p)k},\ k\in\mathbf{N},$$ where $p\in(0,1)$. The implemented algorithm is the one named LK in Kemp (1981).

Usage

rlog(n, p, Ip = 1 - p)

Arguments

n
sample size, that is, length of the resulting vector of random variates.
p
parameter in $(0,1)$.
Ip
$= 1 - p$, possibly more accurate, e.g, when $p\approx 1$.

Value

  • A vector of positive integers of length n containing the generated random variates.

Details

For documentation and didactical purposes, rlogR is a pure-Rimplementation of rlog. However, rlogR is not as fast as rlog (the latter being implemented in C).

References

Kemp, A. W. (1981), Efficient Generation of Logarithmically Distributed Pseudo-Random Variables, Journal of the Royal Statistical Society: Series C (Applied Statistics) 30, 3, 249--253.

Examples

Run this code
## Sample n random variates from a Log(p) distribution and plot a
## histogram
n <- 1000
p <- .5
X <- rlog(n, p)
hist(X, prob = TRUE)

Run the code above in your browser using DataLab