Learn R Programming

Compounding (version 1.0.2)

qCompound: function qCompound

Description

Function qCompound calculates quantiles of the random variable X.

Usage

qCompound(p,parent,compound,compoundDist,params,...)

Arguments

p
vector of probabilities
parent
name of the parent distribution. It can be any continuous distribution supported by R.
compound
name of the compound distribution. It can be any discrete distribution supported by this package.
compoundDist
list of available compounding distributions
params
Parameter or list of parameters of compounding distribution.
...
Parameters of continuous distribution could be provided as additional parameters.

Details

Parameters of the parent distribution must be provided in the same way as it is in built in R functions. See

http://127.0.0.1:23174/library/stats/html/Distributions.html

References

Nadarajah S, Popovic B.V, Ristic M.M (2011) Compounding: An R Package for Computing Continuous Distributions Obtained by Compounding a Continuous and a Discrete Distribution (submitted)

Examples

Run this code
compoundDist <- c("geometric","poisson","negativebinomial","binomial",
"logarithmic","binomialbinomial","binomialpoisson",
"poissonbinomial","neymantypea","polyaaeppli",
"poissonpascal","pascalpoisson",
"logarithmicbinomial","logarithmicpoisson",
"poissonlindley",
"hyperpoisson","yule","waring","kattitypeh1",
"kattitypeh2","neymantypeb","neymantypec",
"hypergeometric","thomas")
p<-0.5
parentD<-"beta"
compoundD<-"hypergeometric"
params<-c(3,2,0.5)
qCompound(p,parentD,compoundD,params,shape1=2,shape2=0.3)

## The function is currently defined as
qCompound <- function(p,parent,compound,compoundDist,params,...) {
    if (!exists(paste("p",parent,sep=""))) {
        return(paste("The parent distribution",parent,"doesn't exist"))
    }
    if (!is.element(compound,compoundDist)) {
        return(paste("The discrete distribution",compound,"doesn't exist"))
    }

    l<-p[p<0|p>1]
    if (length(l)>0) stop("Parameter p is probability") 

    xval <- real(length(p))
    Finv <- get(paste("q", parent, sep = ""), mode = "function")
    phi <- get(paste("pgf", compound, sep = ""), mode = "function")
    phiInv <- get(paste("pgfI", compound, sep = ""), mode = "function")
    xval <- Finv(1-phiInv(1-p*(1-phi(0,params)),params),...)
    return(xval)
}

Run the code above in your browser using DataLab