q: Quantile of a distribution

Description Usage Arguments Value Examples

Description

This function computes the p-th quantile for any common univariate distribution, s.t. 0 ≤q p ≤q 1. Unlike the usual quantile functions of other distributions (such as qnorm, qpois and etc.) the name of the introduced quantile function is fix for any distribution and the name of corresponded distribution is considered as an argument in this function. Thus q function is applicable for any kind of distribution with a unique form but by considering the name of corresponded distribution and its parameters as two arguments of q function.

Usage

1
q(p, T.dist, T.dist.par)

Arguments

p

A numeric vector (or single real number) of probabilities in bound [0,1]. Function q compute the p-th quantile for the introduced distribution in its arguments part.

T.dist

The distribution name of the random variable is determined by characteristic element T.dist. The names of distributions is similar to stats package.

T.dist.par

A vector of distribution parameters with considered ordering in stats package.

Value

This function gives the p-th quantile of a given distribution for the real-valued or vector-valued p \in [0,1].

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
q(p=0.25, T.dist="norm", T.dist.par=c(0,1)) # Or the first Quartile of N(0,1), i.e.  qnorm(0.25)
q(p=1, T.dist="norm", T.dist.par=c(10,2)) # Is equal to  qnorm(1,10,2)
q(0.9, T.dist="cauchy", T.dist.par=c(3,1)) # Is equal to the 9th Decile of Cauchy 
                     # distribution with parameters (3,1); i.e.  qcauchy(0.5,3,1)
q(0.237, T.dist="pois", T.dist.par=25) # Is equal to  qpois(0.237,25)


## The function is currently defined as
function (p, T.dist, T.dist.par) 
{
    qDis = paste("q", T.dist, sep = "", collapse = "")
    if (length(T.dist.par) == 1) {
        q.t = do.call(qDis, list(p, T.dist.par[1]))
    }
    else {
        if (length(T.dist.par) == 2) {
            q.t = do.call(qDis, list(p, T.dist.par[1], T.dist.par[2]))
        }
        else {
            q.t = do.call(qDis, list(p, T.dist.par[1], T.dist.par[2], 
                T.dist.par[3]))
        }
    }
    return(q.t)
  }

DISTRIB documentation built on May 2, 2019, 2:51 p.m.