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='Medians Indicated', axes=F) title('Dot Plot') 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) 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() } cdf.compare2<-function(x, y = NULL, distribution = "normal", title='Empirical CDFs',...) { # two sample if((bad.obs <- sum(!(x.ok <- is.finite(x)))) > 0) { is.not.finite.warning(x) x <- x[x.ok] warning(paste(bad.obs, "observations with NA/NaN/Inf in 'x' removed.")) } nx <- length(x) if((bad.obs <- sum(!(y.ok <- is.finite(y)))) > 0) { is.not.finite.warning(y) y <- y[y.ok] warning(paste(bad.obs, "observations with NA/NaN/Inf in 'y' removed.")) } ny <- length(y) F.x <- c(0, seq(length = nx)/nx, 1) F.y <- c(0, seq(length = ny)/ny, 1) x.sort <- sort(x) y.sort <- sort(y) z.sort <- sort(c(x, y)) eps <- min(diff(x.sort), diff(y.sort)) little <- z.sort[1] - eps big <- z.sort[nx + ny] + eps plot(c(little, x.sort, big), F.x, type = "s", ylim = c(0, 1), xlim = c(little, big), xlab = paste("dotted line is cdf of", deparse(substitute(y))), ylab = "", main = title) lines(c(little, y.sort, big), F.y, type = "s", lty = 2) invisible() }