shading_hcl(observed, residuals = NULL, expected = NULL, df = NULL,
h = NULL, c = NULL, l = NULL, interpolate = c(2, 4), lty = 1,
eps = NULL, line_col = "black", p.value = NULL, level = 0.95, ...)shading_hsv(observed, residuals = NULL, expected = NULL, df = NULL,
h = c(2/3, 0), s = c(1, 0), v = c(1, 0.5),
interpolate = c(2, 4), lty = 1, eps = NULL, line_col = "black",
p.value = NULL, level = 0.95, ...)
shading_max(observed = NULL, residuals = NULL, expected = NULL, df = NULL,
h = NULL, c = NULL, l = NULL, lty = 1, eps = NULL, line_col = "black",
level = c(0.9, 0.99), n = 1000, ...)
shading_Friendly(observed = NULL, residuals = NULL, expected = NULL, df = NULL,
h = c(2/3, 0), lty = 1:2, interpolate = c(2, 4),
eps = 0.01, line_col = "black", ...)
shading_sieve(observed = NULL, residuals = NULL, expected = NULL, df = NULL,
h = c(260, 0), lty = 1:2, interpolate = c(2, 4),
eps = 0.01, line_col = "black", ...)
shading_binary(observed = NULL, residuals = NULL, expected = NULL, df = NULL,
col = NULL)
hcl2hex(h = 0, c = 35, l = 85, fixup = TRUE)
c(260, 0)
c(100, 20)
.c(90, 50)
for small and large residuals respectively.c(1, 0)
for large and small residuals respectively.c(1, 0.5)
for significant and non-significant results respectively.NULL
(default),
all borders have the default color specified by line_col
shading_sieve
: default sieve color).df
degrees of freedom.
p.value
can be either a scalar or a function(observed, residuals, expect
p.value
is smaller than
1 - level
, bright colors are used, otherwise dark colors are employed. For
shading_max
a vector of levels can be supplied. The corresponding criticoindep_test
."gpar"
object with the
corresponding vector(s)/table(s) of graphical parameter(s).strucplot
to generate
residual-based shadings for contingency tables. strucplot
calls these
functions with the arguments observed
, residuals
, expected
,
df
which give the observed values, residuals, expected values and associated
degrees of freedom for a particular contingency table and associated independence
model.
The shadings shading_hcl
and shading_hsv
do the same thing conceptually,
but use HCL or HSV colors respectively. The former is usually preferred because they
are perceptually based. Both shadings visualize the sign of the residuals of
an independence model using two hues (by default: blue and red). The absolute size of
the residuals is visualized by the colorfulness and the amount of grey, by default in three categories:
very colorful for large residuals (> 4), less colorful for medium sized residuals (< 4 and > 2),
grey/white for small residuals (< 2). More categories or a continuous scale can
be specified by setting interpolate
. Furthermore, the result of a significance
test can be visualized by the amount of grey in the colors. If significant, a colorful
palette is used, if not, the amount of color is reduced.
See Zeileis, Meyer, and Hornik (2007) and diverge_hcl
for more details.
The shading shading_max
is applicable in 2-way contingency tables and uses
a similar strategy as shading_hcl
. But instead of using the cut-offs 2 and 4,
it employs the critical values for the maximum statistic (by default at 90% and 99%).
Consequently, color in the plot signals a significant result at 90% or 99% significance
level, respectively. The test is carried out by calling coindep_test
.
The shading shading_Friendly
is very similar to shading_hsv
, but additionally
codes the sign of the residuals by different line types. See Friendly
(1994) for more details. shading_sieve
is similar, but uses HCL colors.
The shading shading_binary
just visualizes the sign of the residuals by using
two different colors (default: blue HCL(260, 50, 70) and red HCL(0, 50, 70)). The color implementations employed are hsv
from base R and polarLUV
from the hsv
), the function
hex
is employed. A convenience wrapper hcl2hex
is provided.
Meyer D., Zeileis A., and Hornik K. (2006),
The Strucplot Framework: Visualizing Multi-Way Contingency Tables with vignette("strucplot", package = "vcd")
.
Zeileis A., Meyer D., Hornik K. (2007), Residual-Based Shadings for Visualizing (Conditional) Independence. Journal of Computational and Graphical Statistics, 16, 507--525.
Zeileis A., Hornik K. and Murrell P. (2008),
Escaping RGBland: Selecting Colors for Statistical Graphics.
Computational Statistics & Data Analysis, Forthcoming.
Preprint available from
hex
,
polarLUV
,
hsv
,
mosaic
,
assoc
,
strucplot
,
diverge_hcl
## load Arthritis data
data("Arthritis")
art <- xtabs(~Treatment + Improved, data = Arthritis)
## plain mosaic display without shading
mosaic(art)
## with shading for independence model
mosaic(art, shade = TRUE)
## which uses the HCL shading
mosaic(art, gp = shading_hcl)
## the residuals are two small to have color,
## hence the cut-offs can be modified
mosaic(art, gp = shading_hcl, gp_args = list(interpolate = c(1, 1.8)))
## the same with the Friendly palette
## (without significance testing)
mosaic(art, gp = shading_Friendly, gp_args = list(interpolate = c(1, 1.8)))
## assess independence using the maximum statistic
## cut-offs are now critical values for the test statistic
mosaic(art, gp = shading_max)
## association plot with shading as in base R
assoc(art, gp = shading_binary(col = c(1, 2)))
Run the code above in your browser using DataLab