dist.expl2<-function(x1, x2) { x <- c(x1, x2) n1 <- length(x1) n2 <- length(x2) m1 <- median(x1) m2 <- median(x2) y <- c(rep(1, n1), rep(2, n2)) par(mfrow = c(2, 2)) plot(x, jitter(y), ylab = "", xlab = "", axes = F, cex = 1.5) title(main = "Dot Plot", xlab = "Medians Indicated") points(m1, 1, pch = "|", cex = 2) points(m2, 2, pch = "|", cex = 2) axis(1) axis(2, at = c(1, 2), lab = c("x1", "x2")) box() iqr1 <- summary(x1)[5] - summary(x1)[2] h1 <- (4 * 1.06 * iqr1)/1.34 * n1^(-1/5) iqr2 <- summary(x2)[5] - summary(x2)[2] h2 <- (4 * 1.06 * iqr2)/1.34 * n2^(-1/5) hm <- (h1 + h2)/2 den1 <- density(x1, width = hm) den2 <- density(x2, width = hm) ymax <- max(max(den1$y), max(den2$y)) xlim1 <- min(min(den1$x), min(den2$x)) xlim2 <- max(max(den1$x), max(den2$x)) plot(den1, type = "l", xlab = "dotted curve is for x2", ylab = "", xlim = c(xlim1, xlim2), ylim = c(0, ymax), main = "Smoothed Density Estimates") lines(den2, type = "l", lty = 2, lwd = 5) rug(jitter(x1)) rug(jitter(x2), side = 3) boxplot(split(c(x1, x2), c(rep("x1", n1), rep("x2", n2))), main = "Boxplots") cdf.compare2(x1, x2) box() par(mfrow = c(1, 1)) invisible() }