This is an example of the cdplot command.
Bring in the Data
## NASA space shuttle o-ring failures
fail <- factor(c(2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1,
1, 2, 1, 1, 1, 1, 1),
levels = 1:2, labels = c("no", "yes"))
temperature <- c(53, 57, 58, 63, 66, 67, 67, 67, 68, 69, 70, 70,
70, 70, 72, 73, 75, 75, 76, 76, 78, 79, 81)
Look at 3 cdplots, and effect of bw
## CD plot
cdplot(fail ~ temperature, main="bw = default")
cdplot(fail ~ temperature, bw = 2, main="bw = 2")
cdplot(fail ~ temperature, bw = "SJ", main="bw = 'SJ'")
Compare with Spinogram
(spineplot(fail ~ temperature, breaks = 3))
## fail
## temperature no yes
## [50,60] 0 3
## (60,70] 8 3
## (70,80] 7 1
## (80,90] 1 0
Highlight for Failures
## highlighting for failures
cdplot(fail ~ temperature, ylevels = 2:1)
Make scatter plot with conditional density
## scatter plot with conditional density
cdens <- cdplot(fail ~ temperature, plot = FALSE)
plot(I(as.numeric(fail) - 1) ~ jitter(temperature, factor = 2),
xlab = "Temperature", ylab = "Conditional failure probability")
lines(53:81, 1 - cdens[[1]](53:81), col = 2)
range(temperature)
## [1] 53 81
Note: cdens is a function valid over the range of temperature (53:81).