# # 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. # #----- set.seed(0) library(ElemStatLearn) # loads the data frame bone #postscript("../../WriteUp/Graphics/Chapter5/dup_fig_5_6.eps", onefile=FALSE, horizontal=FALSE) males = bone$gender == "male" females = bone$gender == "female" boneMaleSmooth = smooth.spline( bone[males,"age"], bone[males,"spnbmd"], df=12 ) boneFemaleSmooth = smooth.spline( bone[females,"age"], bone[females,"spnbmd"], df=12 ) plot(boneMaleSmooth, ylim=c(-0.05,0.20), col="blue", type="l", xlab="Age", ylab="spnbmd") points(bone[males,c(2,4)], col="blue", pch=20) lines(boneFemaleSmooth, ylim=c(-0.05,0.20), col="red") points(bone[females,c(2,4)], col="red", pch=20) #dev.off()