qrnn (version 2.0.5)

quantile.dtn: Interpolated quantile distribution with exponential tails

Description

dquantile gives a probability density function (pdf) by combining step-interpolation of probability densities for specified tau-quantiles (quant) with exponential lower/upper tails (Quiñonero-Candela, 2006; Cannon, 2011). Point mass (e.g., as might occur when using censored QRNN models) can be defined by setting lower to the left censoring point. pquantile gives the cumulative distribution function (cdf); the integrate function is used for values outside the range of quant. The inverse cdf is given by qquantile; the uniroot function is used for values outside the range of tau. rquantile is used for generating random variates.

Note: these functions have not been extensively tested or optimized and should be considered experimental.

Usage

dquantile(x, tau, quant, lower=-Inf)
pquantile(q, tau, quant, lower=-Inf, ...)
qquantile(p, tau, quant, lower=-Inf,
          tol=.Machine$double.eps^0.25, maxiter=1000,
          range.mult=1.1, max.error=100, ...)
rquantile(n, tau, quant, lower=-Inf,
          tol=.Machine$double.eps^0.25, maxiter=1000,
          range.mult=1.1, max.error=100, ...)

Value

dquantile gives the pdf, pquantile gives the cdf, qquantile gives the inverse cdf (or quantile function), and rquantile generates random deviates.

Arguments

x, q

vector of quantiles.

p

vector of cumulative probabilities.

n

number of random samples.

tau

ordered vector of cumulative probabilities associated with quant argument.

quant

ordered vector of quantiles associated with tau argument.

lower

left censoring point.

tol

tolerance passed to uniroot.

maxiter

maximum number of iterations passed to uniroot.

range.mult

values of lower and upper in uniroot are initialized to
quant[1]-range.mult*diff(range(quant)) and
quant[length(quant)]+range.mult*diff(range(quant)) respectively; range.mult is squared, lower and upper are recalculated, and uniroot is rerun if the current values lead to an exception.

max.error

maximum number of uniroot errors allowed before termination.

...

additional arguments passed to integrate.

References

Cannon, A.J., 2011. Quantile regression neural networks: implementation in R and application to precipitation downscaling. Computers & Geosciences, 37: 1277-1284. doi:10.1016/j.cageo.2010.07.005

Quiñonero-Candela, J., C. Rasmussen, F. Sinz, O. Bousquet, B. Scholkopf, 2006. Evaluating Predictive Uncertainty Challenge. Lecture Notes in Artificial Intelligence, 3944: 1-27.

See Also

integrate, uniroot, qrnn.predict

Examples

Run this code
## Normal distribution
tau <- seq(0.05, 0.95, by=0.05)
quant <- qnorm(tau)

x <- seq(-3, 3, length=500)
plot(x, dnorm(x), type="l", col="red", lty=2, lwd=2,
     main="pdf")
lines(x, dquantile(x, tau, quant), col="blue")

q <- seq(-3, 3, length=20)
plot(q, pnorm(q), type="b", col="red", lty=2, lwd=2,
     main="cdf")
lines(q, pquantile(q, tau, quant),
      col="blue")

p <- c(0.001, 0.01, 0.025, seq(0.05, 0.95, by=0.05),
       0.975, 0.99, 0.999)
plot(p, qnorm(p), type="b", col="red", lty=2, lwd=2,
     main="inverse cdf")
lines(p, qquantile(p, tau, quant), col="blue")

## Distribution with point mass at zero
tau.0 <- c(0.3, 0.5, 0.7, 0.8, 0.9)
quant.0 <- c(0, 5, 7, 15, 20)

r.0 <- rquantile(500, tau=tau.0, quant=quant.0, lower=0)
x.0 <- seq(0, 40, by=0.5)
d.0 <- dquantile(x.0, tau=tau.0, quant=quant.0, lower=0)
p.0 <- pquantile(x.0, tau=tau.0, quant=quant.0, lower=0)
q.0 <- qquantile(p.0, tau=tau.0, quant=quant.0, lower=0)

par(mfrow=c(2, 2))
plot(r.0, pch=20, main="random")
plot(x.0, d.0, type="b", col="red", main="pdf")
plot(x.0, p.0, type="b", col="blue", ylim=c(0, 1),
     main="cdf")
plot(p.0, q.0, type="b", col="green", xlim=c(0, 1),
     main="inverse cdf")

Run the code above in your browser using DataCamp Workspace