Description Usage Arguments Details Value Functions Author(s) Examples
Panel functions for predicted values and SE bands using 'layer' and 'glayer' in the package latticeExtra
gpanel.labels: shows all labels, for selected labels see the examples with
trellis.focus
and panel.identify
:
trellis.focus()
panel.identify(labels = rownames(data),rot=-15,col = col.symbol, etc.)
trellis.unfocus()
1 2 3 4 5 6 7 8 9 10 11 12 | gpanel.fit(x, y, fit, lower, upper, subscripts, ..., type, group.number, alpha,
col, col.line, col.symbol, border = F, font, fontface)
panel.fit(x, y, fit, lower, upper, subscripts, ..., type, group.number, alpha,
col, col.line, col.symbol, border = F, font, fontface)
gpanel.band(x, y, fit, lower, upper, subscripts, ..., type, group.number, alpha,
col, col.line, col.symbol, border = F, font, fontface)
gpanel.labels(x, y, labels, subscripts, ...)
fillin(data, form, n = 200, xpd = 1)
|
y |
|
fit |
fitted values of a model, generally passed through 'layer' from a call to 'xyplot': e.g. |
lower,upper |
|
subscripts |
|
group.number |
|
alpha |
|
col |
|
col.symbol |
is used to control color when using 'groups' |
border |
default = FALSE for panel.band. |
font |
|
fontface |
|
labels |
to display |
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. |
dots |
|
data |
data frame with values of x that need filling in |
n |
number of additional points over range of predictor (default 200) |
form |
formula idenfying variable x to fill in and grouping variables, g1, g2, etc.
using syntax: |
xpd |
expansion beyond range of predictor (default 1.0, i.e. no expansion) |
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.
panel.fit
: to be used with 'layer' – but, actually, identical to 'glayer'
gpanel.band
: identical to gpanel.fit but kept for backward compatibility
gpanel.labels
:
fillin
:
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 129 130 131 | ## Not run:
library(spida)
library(spidanew)
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.fit(...))
###
### Use 'fillin' to add points in sparse regions of the predictor
### to produce smoother bands
###
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(..., alpha = .1))
# Using spida:gd() to get a ggplot-like appearance
gd(3,lty=1,lwd=2)
p + glayer( gpanel.fit(...,alpha = .1))
###
### Using gpanel.fit with 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(...))
# gd_(basecol = 'tomato4') # Use 'gd_' to set parameters without groups
gd_(base = 'tomato4') # Use 'gd_' to set parameters without groups
p + layer( gpanel.fit(..., col = 'grey10'))
###
### 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.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(...))
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(...))
p + layer( gpanel.fit(..., col = 'black', alpha = .1)) + layer(gpanel.text(...))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.