# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- # Generate data from distributions with different means (and hence medians in the Gaussian case) # set.seed(12345) x_mean = 2.0 X = rnorm( 100, mean=x_mean, sd=3 ) y_mean = -3.0 Y = rnorm( 100, mean=y_mean, sd=2 ) plot( density( c(X,Y) ) ) # just do see the density cdf_x_range = c( min( c(X,Y) ), max( c(X,Y) ) ) # Plot the CDFs (on the same x-axis): # #postscript("../../WriteUp/Graphics/Chapter2/ex_15_cdf_plots.eps", onefile=FALSE, horizontal=FALSE) plot( ecdf(X), xlim=cdf_x_range, col='blue', main='CDFs' ) lines( ecdf(Y), xlim=cdf_x_range, col='red' ) grid() legend( cdf_x_range[1], 1.0, legend=c(sprintf("median= %.1f", x_mean), sprintf("median=%.1f", y_mean)), col=c('blue', 'red'), lty=c(1,1) ) #dev.off()