Title: | Random Variate Generator for the Argus Distribution |
---|---|
Description: | Random variate generation, density, CDF and quantile function for the Argus distribution. Especially, it includes for random variate generation a flexible inversion method that is also fast in the varying parameter case. A Ratio-of-Uniforms method is provided as second alternative. |
Authors: | Wolfgang Hormann [aut, cre], Christoph Baumgarten [aut] |
Maintainer: | Wolfgang Hormann <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.1 |
Built: | 2024-12-24 06:31:01 UTC |
Source: | CRAN |
Random variate generation, density, CDF and quantile function for the Argus distribution. Especially, it includes for random variate generation a flexible inversion method that is also fast in the varying parameter case. A Ratio-of-Uniforms method is provided as second alternative.
The Argus distribution has the density (pdf) which is proportional to
Package: | argus |
License: | GPL 2 or later |
Package argus provides the routines:
rargus
generates argus distributed random variates.
dargus
computes the density of the argus distribution.
pargus
computes the CDF of the argus distribution.
qargus
computes the quantile function (ie. the inverse CDF )of the argus distribution.
Wolfgang Hörmann & Christoph Baumgarten
Christoph Baumgarten: Random Variate Generation by Fast Numerical Inversion in the Varying Parameter Case.
## Evaluate the pdf (density) dargus(c(0.1,0.5,0.9), chi=0.3) ## Evaluate the CDF for different chi values pargus(c(0.1,0.5,0.9), chi=c(0.3,1.3,2.3)) ## Evaluate the quantile function pargus(c(0.1,0.5,0.9), chi=4.5) ## Draw a random sample rargus(n=10, chi=0.3) ## compare histogram and density system.time(y<-rargus(1.e5,chi=2.5)) hist(y,breaks=100,freq=FALSE) lines(x<-seq(0,1,1.e-3),dargus(x,2.5),col=2,lwd=2)
## Evaluate the pdf (density) dargus(c(0.1,0.5,0.9), chi=0.3) ## Evaluate the CDF for different chi values pargus(c(0.1,0.5,0.9), chi=c(0.3,1.3,2.3)) ## Evaluate the quantile function pargus(c(0.1,0.5,0.9), chi=4.5) ## Draw a random sample rargus(n=10, chi=0.3) ## compare histogram and density system.time(y<-rargus(1.e5,chi=2.5)) hist(y,breaks=100,freq=FALSE) lines(x<-seq(0,1,1.e-3),dargus(x,2.5),col=2,lwd=2)
Density, distribution function, quantile function and random generation for the Argus distribution with parameter chi
.
rargus()
uses very efficient random variate generation methods. Inversion or the Ratio of Uniforms method can be selected.
rargus(n=length(chi) , chi, method = c("inversion","RoU") ) dargus(x, chi, log = FALSE) pargus(x, chi, lower = TRUE, log.p = FALSE) qargus(p, chi, lower = TRUE, log.p = FALSE)
rargus(n=length(chi) , chi, method = c("inversion","RoU") ) dargus(x, chi, log = FALSE) pargus(x, chi, lower = TRUE, log.p = FALSE) qargus(p, chi, lower = TRUE, log.p = FALSE)
n |
Number of observations |
chi |
parameter vector |
method |
random variate generation method to be used (details are below) |
x |
x-value for the density or CDF |
log |
If |
lower |
If |
log.p |
|
p |
probability of the quantile |
The Argus distribution has the density (pdf) which is proportional to
The generators used for rargus()
are very efficient also for the varying parameter case,
i.e. when the vector chi
has length n
.
method = "inversion"
: transforms the uniform variate into an argus variate
using a close to exact approximation of the inverse CDF. It is also well suited for the
varying parameter case as the theorem that an argus variate can be represented as a transformed
truncated Gamma(1.5) variate allows to express the inverse CDF of the argus distribution as a
simple transform of the inverse CDF of the Gamma(1.5) distribution.
The use of the pinv.new()
function of the Runuran
package makes that evaluation very fast.
When loading the argus-package pinv.new()
calculates and stores the required tables.
method = "RoU"
: uses the Ratio of Uniforms method which requires 2 or more uniform variates
to generate one argus variate. It is also a bit slower than the inversion method and is added here
mainly for the case that the Runuran
-package is not available.
rargus
creates a random sample of size n
.
dargus
gives the density, dargus
give the CDF and qargus
gives the quantile function.
The length of the result for these 3 functions is the maximum of the lengths of the numerical arguments that
are recycled to the length of the result. Only the first elements of the logical arguments are used.
Wolfgang Hörmann and Christoph Baumgarten
Christoph Baumgarten: Random Variate Generation by Fast Numerical Inversion in the Varying Parameter Case.
library(argus) # pdf, cdf and quantile function dargus((0:10)/10,.6) qargus(0.9,2) pargus(qargus(0.9,2),2) y<-rargus(n=1.e5,chi=0.3,method="inversion") hist(y,breaks=100,main="Argus pdf with chi=0.3",freq=FALSE) lines(xv<-seq(0,1,0.001),dargus(xv,chi=0.3),lwd=0.2,col=2) n=1.e5 chiv <- 1. +runif(n)*5 # chi-values in (1,5) system.time({set.seed(123);y<-rargus(chi=chiv)}) set.seed(123);u<- runif(n) mean(abs(pargus(y,chiv)-u)) # random variate generation with the inversion method y<-rargus(n=1.e5,chi=0.3,method="inversion") hist(y,breaks=100,main="Argus pdf with chi=0.3",freq=FALSE) lines(xv<-seq(0,1,0.001),dargus(xv,chi=0.3),lwd=0.2,col=2) # using Ratio of Uniforms y<-rargus(n=1.e5,chi=3,method="RoU") hist(y,breaks=100,main="Argus pdf with chi=3",freq=FALSE) lines(xv<-seq(0,1,0.001),dargus(xv,chi=3),lwd=2,col=2) # generating for different chi values y<-rargus(n=100,chi=runif(100)*2,method="RoU")
library(argus) # pdf, cdf and quantile function dargus((0:10)/10,.6) qargus(0.9,2) pargus(qargus(0.9,2),2) y<-rargus(n=1.e5,chi=0.3,method="inversion") hist(y,breaks=100,main="Argus pdf with chi=0.3",freq=FALSE) lines(xv<-seq(0,1,0.001),dargus(xv,chi=0.3),lwd=0.2,col=2) n=1.e5 chiv <- 1. +runif(n)*5 # chi-values in (1,5) system.time({set.seed(123);y<-rargus(chi=chiv)}) set.seed(123);u<- runif(n) mean(abs(pargus(y,chiv)-u)) # random variate generation with the inversion method y<-rargus(n=1.e5,chi=0.3,method="inversion") hist(y,breaks=100,main="Argus pdf with chi=0.3",freq=FALSE) lines(xv<-seq(0,1,0.001),dargus(xv,chi=0.3),lwd=0.2,col=2) # using Ratio of Uniforms y<-rargus(n=1.e5,chi=3,method="RoU") hist(y,breaks=100,main="Argus pdf with chi=3",freq=FALSE) lines(xv<-seq(0,1,0.001),dargus(xv,chi=3),lwd=2,col=2) # generating for different chi values y<-rargus(n=100,chi=runif(100)*2,method="RoU")