Learn R Programming

cobin (version 1.0.1.3)

rcobin: Random variate generation for cobin (continuous binomial) distribution

Description

Continuous binomial distribution with natural parameter \(\theta\) and dispersion parameter \(1/\lambda\), in short \(Y \sim cobin(\theta, \lambda^{-1})\), has density $$ p(y; \theta, \lambda^{-1}) = h(y;\lambda) \exp(\lambda \theta y - \lambda B(\theta)), \quad 0 \le y \le 1 $$ where \(B(\theta) = \log\{(e^\theta - 1)/\theta\}\) and \(h(y;\lambda) = \frac{\lambda}{(\lambda-1)!}\sum_{k=0}^{\lambda} (-1)^k {\lambda \choose k} \max(0,\lambda y-k)^{\lambda-1}\). When \(\lambda = 1\), it becomes continuous Bernoulli distribution.

Usage

rcobin(n, theta, lambda)

Value

random samples from \(cobin(\theta,\lambda^{-1})\).

Arguments

n

integer, number of samples

theta

scalar or length n vector, natural parameter.

lambda

scalar or length n vector, inverse of dispersion parameter. Must be integer, length should be same as theta

Details

The random variate generation is based on the fact that \(cobin(\theta, \lambda^{-1})\) is equal in distribution to the sum of \(\lambda\) \(cobin(\theta, 1)\) random variables, scaled by \(\lambda^{-1}\). Random variate generation for continuous Bernoulli is done by inverse cdf transform method.

Examples

Run this code
hist(rcobin(1000, 2, 3), freq = FALSE)
xgrid = seq(0, 1, length = 500)
lines(xgrid, dcobin(xgrid, 2, 3))

Run the code above in your browser using DataLab