Description Usage Arguments Details Value Author(s) Examples
Panel functions for predicted values and SE bands using 'layer' and 'glayer' in the package latticeExtra
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | panel.fit(x, y, fit,
subscripts, ..., type = 'l', font, fontface)
panel.fit(...) # when called within 'layer' or 'glayer' in 'latticeExtra'
panel.band(x, y, lower, upper, subscripts, ...,
col, group.number, alpha,
col.symbol, border = F, font, fontface) # see examples belor
panel.band(...) # when called within 'layer' or 'glayer' in 'latticeExtra'
panel.labels(x, y, labels , subscripts, ...)
panel.labels(...) # when called within 'layer' or 'glayer' in 'latticeExtra'
fillin(data, form, n = 200, xpd = 1.0)
|
data |
data frame to be used to add additional values of numeric variable |
form |
formula evaluated in data. The first term defines the variable with values to be filled in and the remaining terms define the variables to be used for grouping determining the minima and maxima within which values are added. |
n |
the number of values to be added between the global mininum and maximum. Values falling outside conditional minima and maxima are culled. Default 200. |
xpd |
expansion factor to add points beyond minima and maxima. Default 1.0. |
y |
|
fit |
fitted values of a model, generally passed through 'layer' from a call to 'xyplot': e.g. |
lower |
|
upper |
|
subscripts |
|
... |
|
col |
|
group.number |
|
alpha |
to deal with the problem that 'trellis.par.get' will pass a value of alpha = 1, 'panel.band' will set alpha = .3 if alpha = 1. To get a nearly opaque band, use alpha = .99. |
col.symbol |
is used to control color when using 'groups' |
border |
default = FALSE for panel.band. |
font |
|
fontface |
With 'layer' and 'glayer' in 'latticeExtra', these functions can be used to easily generate fitted values and confidence or prediction bands that have a reasonable appearance whether a plot uses 'groups' or not.
The 'panel.bands', 'panel.fit', and 'panel.labels' functions are invoked for their graphical effect.
Georges Monette <georges@yorku.ca>
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
library(spida)
library(latticeExtra)
library(car)
fit <- lm(prestige ~ (income + I(income^2)) * type, Prestige,
na.action = na.exclude)
pred <- cbind( Prestige, predict(fit, newdata = Prestige, se = TRUE))
head(pred)
(p <- xyplot( prestige ~ income , pred, groups = type,
subscripts = T,
fit = pred$fit,
lower = with(pred, fit - 2*se.fit),
upper = with(pred, fit + 2*se.fit)))
p + glayer(gpanel.band(...))
p + glayer(gpanel.band(...)) + glayer(gpanel.fit(...))
# Another example
# to illustrate 'fillin'
fit <- lm( income ~
(education+I(education^2)+I(education^3) +I(education^4))* type,
Prestige, na.action = na.exclude) # overfitting!
# adding extra values of predictor to get smooth line
Prestige$occupation <- rownames(Prestige)
z <- fillin(Prestige, ~education + type,xpd = 1.1)
dim(z)
dim(Prestige)
z <- cbind(z, predict(fit, newdata = z, se = TRUE))
head(z)
gd(3,cex=2,lwd=2, alpha = .7)
(p <- xyplot( income ~ education, z, groups = type,
subscripts = T,
fit = z$fit,
lower = z$fit - z$se,
upper = z$fit + z$se,
auto.key = list(space='right', lines= T)))
p + glayer( gpanel.fit(...))
p + glayer( gpanel.fit(...)) + glayer(gpanel.band(...))
p + glayer( gpanel.band(..., alpha = .1))
gd(3,lty=1,lwd=2)
p + glayer( gpanel.band(...,alpha = .1)) + glayer(gpanel.fit(...))
# with panels and no groups:
(p <- xyplot( income ~ education| type, z,
subscripts = T,
fit = z$fit,
lower = z$fit - z$se,
upper = z$fit + z$se,
auto.key = list(space='right', lines= T)))
p + layer( gpanel.fit(...)) + layer( gpanel.band(...))
gd(basecol = 'tomato4')
p + layer( gpanel.band(..., col = 'grey10')) + layer(gpanel.fit(...))
p + layer( gpanel.band(...)) + layer(gpanel.fit(...))
# With panels and groups
z <- Prestige
z$gender <- with(z, cut( women, c(-1,15,50,101),labels = c("Male","Mixed","Female")))
tab(z, ~ gender + type)
z <- fillin( z, ~ education + type + gender, xpd = 1.1)
fit <- lm( income ~ (education+I(education^2)+I(education^3) )* type * gender,
z, na.action = na.exclude) # overfitting!
summary(fit)
z <- cbind( z, predict(fit, newdata = z, se = TRUE))
head(z)
(p <- xyplot( income ~ education| gender, z, groups = type,
subscripts = T,
fit = z$fit,
lower = z$fit - z$se,
upper = z$fit + z$se,
layout = c(1,3),
auto.key = list(space='right', lines= T, cex = 1.5)))
p + glayer( gpanel.band(...)) + glayer(gpanel.fit(...))
# trellis.focus()
# panel.identify(labels= z$occupation)
# trellis.unfocus()
z$type2 <- with( z, reorder(type,education, mean, na.rm=T))
gd(3)
(p <- xyplot( income ~ education| type2, z, groups = gender,
subscripts = T,
fit = z$fit,
lower = z$fit - z$se,
upper = z$fit + z$se,
layout = c(1,3),
par.strip.text = list(cex = 2),
auto.key = list(space='right', lines= T, cex = 1.5)))
p + glayer( gpanel.fit(...))
p + glayer( gpanel.band(...))
p + glayer( gpanel.band(...)) + glayer(gpanel.fit(...))
# trellis.focus()
# panel.identify(labels= z$occupation)
# trellis.unfocus()
# With panels^2
# need to remove 'col = col.line'
z <- Prestige
z$occ <- rownames(Prestige)
z$gender <- with(z, cut( women, c(-1,15,50,101),labels = c("Male","Mixed","Female")))
z$type2 <- with( z, reorder(type,education, mean, na.rm=T))
tab(z, ~ gender + type2)
z <- fillin( z, ~ education + type + gender, xpd = 1.1)
fit <- lm( income ~ (education+I(education^2)+I(education^3) )* type * gender,
z, na.action = na.exclude) # overfitting!
summary(fit)
z <- cbind( z, predict(fit, newdata = z, se = TRUE))
head(z)
(p <- xyplot( income ~ education| gender*type, z,
subscripts = T,
fit = z$fit,
labels = z$occ,
lower = z$fit - z$se,
upper = z$fit + z$se,
auto.key = list(space='right', lines= T, cex = 1.5)))
p + layer( gpanel.fit(...)) + layer( gpanel.band(...))
p + layer( gpanel.band(..., col = 'black', alpha = .1)) + layer(gpanel.fit(...)) +
layer(gpanel.text(...))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.