New panel functions


Johan Larsson


tactile introduces new panel functions to the latticeverse. confidence intervals adds confidence bands around a line using arguments lower and upper. This is usually of interested after, for instance, having fitted a model and then made predictions using that model.

As an example, we will try to predict petal width from petal length and species, using the iris dataset.

mod <- lm(Petal.Width ~ Petal.Length * Species, data = iris)
newdat <- expand.grid(
  Petal.Length = seq(1, 7, by = 0.1),
  Species = c("setosa", "versicolor", "virginica")
pred <- predict(mod, newdat, interval = "confidence")
dd <- cbind(newdat, pred)

Having predicted values across our grid, we now plot the predictions, including 95% confidence levels using the following lines.

xyplot(fit ~ Petal.Length,
  groups = Species, data = dd,
  prepanel =, auto.key = list(lines = TRUE, points = FALSE),
  ylab = "Petal Width",
  xlab = "Petal Length",
  lower = dd$lwr,
  upper = dd$upr,
  type = "l",
  panel = function(...) {, alpha = 0.15, grid = TRUE)

Example of using

Also note the use of the function that we provide the prepanel argument with so that the axis limits are set properly.

panel.qqmathci(): confidence intervals for lattice::qqmath()

panel.qqmathci() is designed to be used together with lattice::qqmath() and lattice::panel.qqmathline() to provide confidence intervals for the theoretical quantities. A rather contrived example follows.

qqmath(~ height | voice.part,
  aspect = "xy", data = singer,
  prepanel = prepanel.qqmathline,
  distribution = qnorm,
  ci = 0.9,
  panel = function(x, ...) {
    panel.qqmathci(x, ...)
    panel.qqmathline(x, ...)
    panel.qqmath(x, ...)

Example of using panel.qqmathci.