Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

panel.quantile

Plot a quantile regression line with standard error bounds.


Description

Plot a quantile regression line with standard error bounds, using the quantreg package. This is based on the stat_quantile function from ggplot2.

Usage

panel.quantile(x, y, form = y ~ x, method = "rq", ...,
    tau = 0.5, ci = FALSE, ci.type = "default", level = 0.95,
    n = 100, col = plot.line$col, col.se = col,
    lty = plot.line$lty, lwd = plot.line$lwd,
    alpha = plot.line$alpha, alpha.se = 0.25, border = NA,
    superpose = FALSE,
    ## ignored: ##
    subscripts, group.number, group.value,
    type, col.line, col.symbol, fill,
    pch, cex, font, fontface, fontfamily)

Arguments

x, y

data points. If these are missing, they will be looked for in the environment of form. So in many cases you can skip these if passing form. In fact, for convenience, the formula can be passed as the first argument (i.e. x).

form, method

Formula and the name of a modeling function (as a character string). The model is constructed (approximately) as method(form, tau = tau, data = list(x=x, y=y), ...). Currently, method is expected to be either "rq" or "rqss", and for these the corresponding functions in the quantreg package is used. In principle, any other function that supports the same interface can also be specified by name.

...

further arguments passed on to the model function (method), typically rq.

tau

p values for the quantiles to estimate.

Note: only one value for tau can be specified if estimating confidence intervals with ci.

ci, ci.type, level

estimate a confidence interval at level level using the method ci.type; see predict.rq.

n

number of equi-spaced points on which to evaluate the function.

col, col.se, lty, lwd, alpha, alpha.se, border

graphical parameters. col and alpha apply to the line(s), while col.se and alpha.se apply to the shaded ci region.

superpose

if TRUE, plot each quantile line (tau) in a different style (using trellis.par.get("superpose.line")).

subscripts, group.number, group.value, type, col.line, col.symbol, fill, pch, cex, font, fontface, fontfamily

ignored.

Details

It is recommended to look at vignette("rq", package="quantreg").

Author(s)

Felix Andrews felix@nfrac.org

Based on stat_quantile by Hadley Wickham.

See Also

Examples

## library("quantreg")

set.seed(1)
xy <- data.frame(x = runif(100), y = rt(100, df = 5))
xyplot(y ~ x, xy) +
    layer(panel.quantile(x, y, tau = c(.95, .5, .05)))

if (require("splines")) {
    xyplot(y ~ x, xy) +
        layer(panel.quantile(y ~ ns(x, 3), tau = 0.9))

    xyplot(y ~ x, xy) +
        layer(panel.quantile(y ~ ns(x, 3), tau = 0.9, ci = TRUE))
}

xyplot(y ~ x, xy) +
    layer(panel.quantile(x, y, tau = c(.5, .9, .1), superpose = TRUE))

update(trellis.last.object(),
       auto.key = list(text = paste(c(50,90,10), "% quantile"),
                  points = FALSE, lines = TRUE))

xyplot(y ~ x, xy) +
    layer(panel.quantile(y ~ qss(x, lambda=1), method = "rqss"))

latticeExtra

Extra Graphical Utilities Based on Lattice

v0.6-29
GPL (>= 2)
Authors
Deepayan Sarkar <deepayan.sarkar@r-project.org>, Felix Andrews <felix@nfrac.org>
Initial release
2019-12-18

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.