Description Usage Arguments Value Author(s) Examples
Used to plot confidence bars or confidence bands in lattice plots.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
x, subscripts, col.line, lwd, ... |
arguments passed to
|
y |
central value (point estimate). |
ly |
lower limit. |
uy |
upper limit. |
cty |
string that is the confidence type. Values current acepted
are |
desloc |
a numeric vetor with length equal to |
fill |
a color to fill the polygon defined by the confidence
bands. Default is 1 that is the black color. Not used when
|
alpha |
transparecy level for the polygon defined by the
confidence bands. Default is 0.1. Not used when |
length |
is the length of the upper/lower error bars
whiskers. Default is 0.05. Not used when |
None is returned.
Walmes Zeviani, walmes@ufpr.br, based on the R-help mail list.
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | library(lattice)
library(latticeExtra)
#--------------------------------------------
m0 <- lm(sqrt(dist) ~ speed, data = cars)
pred <- with(cars,
data.frame(speed = seq(min(speed), max(speed),
length.out = 20)))
aux <- predict(m0, newdata = pred, interval = "confidence")
pred <- cbind(pred, aux)
xyplot(sqrt(dist) ~ speed, data = cars,
ylab = expression(sqrt(distance)),
xlab = "Speed") +
as.layer(xyplot(fit ~ speed, data = pred, type = "l",
ly = pred$lwr, uy = pred$upr,
cty = "bands", fill = "blue", alpha = 0.3,
prepanel = prepanel.cbH,
panel = panel.cbH))
#--------------------------------------------
m1 <- lm(weight ~ feed, data = chickwts)
pred <- with(chickwts, data.frame(feed = levels(feed)))
aux <- predict(m1, newdata = pred, interval = "confidence")
pred <- cbind(pred, aux)
xyplot(weight ~ feed, data = chickwts,
xlab = "Feed", ylab = "Weight") +
as.layer(xyplot(fit ~ feed, data = pred,
ly = pred$lwr, uy = pred$upr, cty = "bars",
desloc = rep(0.15, length(pred$fit)),
prepanel = prepanel.cbH,
panel = panel.cbH))
#-----------------------------------------------------------------------
set.seed(123)
da <- expand.grid(trt = gl(2, 1), x = 1:7)
da$y <- with(da, as.integer(trt) + 0.5 * x + rnorm(x, 0, 0.3))
xyplot(y ~ x, groups = trt, data = da)
m2 <- lm(y ~ trt + x, data = da)
pred <- with(da,
expand.grid(trt = levels(trt),
x = seq(min(x), max(x), length.out = 20)))
aux <- predict(m2, newdata = pred, interval = "confidence")
pred <- cbind(pred, aux)
xyplot(y ~ x, groups = trt, data = da) +
as.layer(xyplot(fit ~ x, groups = trt, data = pred, type = "l",
ly = pred$lwr, uy = pred$upr,
cty = "bands", alpha = 0.75,
prepanel = prepanel.cbH,
panel = panel.superpose,
panel.groups = panel.cbH),
under = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.