quantile.dtn | R Documentation |
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.
Alternative formulations (without left censoring) based on the
Nadaraya-Watson estimator [p,q,r]quantile.nw
are also provided
(Passow and Donner, 2020).
Note: these functions have not been extensively tested or optimized and should be considered experimental.
dquantile(x, tau, quant, lower=-Inf)
pquantile(q, tau, quant, lower=-Inf, ...)
pquantile.nw(q, tau, quant, h=0.001, ...)
qquantile(p, tau, quant, lower=-Inf,
tol=.Machine$double.eps^0.25, maxiter=1000,
range.mult=1.1, max.error=100, ...)
qquantile.nw(p, tau, quant, h=0.001)
rquantile(n, tau, quant, lower=-Inf,
tol=.Machine$double.eps^0.25, maxiter=1000,
range.mult=1.1, max.error=100, ...)
rquantile.nw(n, tau, quant, h=0.001)
x , q |
vector of quantiles. |
p |
vector of cumulative probabilities. |
n |
number of random samples. |
tau |
ordered vector of cumulative probabilities associated with |
quant |
ordered vector of quantiles associated with |
lower |
left censoring point. |
tol |
tolerance passed to |
h |
bandwidth for Nadaraya-Watson kernel. |
maxiter |
maximum number of iterations passed to |
range.mult |
values of |
max.error |
maximum number of |
... |
additional arguments passed to |
dquantile
gives the pdf, pquantile
gives the cdf,
qquantile
gives the inverse cdf (or quantile function), and
rquantile
generates random deviates.
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
Passow, C., R.V. Donner, 2020. Regression-based distribution mapping for bias correction of climate model outputs using linear quantile regression. Stochastic Environmental Research and Risk Assessment, 34:87-102. doi:10.1007/s00477-019-01750-7
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.
integrate
, uniroot
, qrnn.predict
## Normal distribution
tau <- c(0.01, seq(0.05, 0.95, by=0.05), 0.99)
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")
abline(v=1.96, lty=2)
abline(h=pnorm(1.96), lty=2)
abline(h=pquantile(1.96, tau, quant), lty=3)
abline(h=pquantile.nw(1.96, tau, quant, h=0.01), lty=3)
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.