# # EPage 138 # # 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. # #----- library(DAAG) nswpsid3 = rbind( psid3, subset(nswdemo, trt==1) ) nCols = dim( nswpsid3 )[2] bInds_control = nswpsid3[,1] == 0 bInds_treated = nswpsid3[,1] == 1 oldpar = par(mfrow=c(3,3)) for( ci in 2:nCols ){ # Split analysis of continuous variables appart from the discrete variables: # if( ci %in% c(4,5,6,7) ){ # A discrete variable: # print( table( nswpsid3[,c(1,ci)] ) ) }else{ # A continuous variable: # d_treated = density( nswpsid3[bInds_treated,ci], na.rm=TRUE ) d_control = density( nswpsid3[bInds_control,ci], na.rm=TRUE ) min_x = min( min(d_control$x), min(d_treated$x) ) max_x = max( max(d_control$x), max(d_treated$x) ) min_y = min( min(d_control$y), min(d_treated$y) ) max_y = max( max(d_control$y), max(d_treated$y) ) plot( d_control, col="red", xlim=c(min_x,max_x), ylim=c(min_y,max_y), main=colnames(nswpsid3)[ci] ) lines( d_treated, col="green", xlim=c(min_x,max_x), ylim=c(min_y,max_y) ) } } par(oldpar)