# # 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(splines) x = seq( 0, 4*pi, length.out=50 ) y = cos( x ) + 0.3 * rnorm( length(x) ) #postscript("../../WriteUp/Graphics/Chapter5/dup_fig_5_1_m1.eps", onefile=FALSE, horizontal=FALSE) plot( x, y, type="p" ); m1 = lm( y ~ bs(x,degree=1,df=1) ) lines( x, fitted(m1) ) #dev.off() #postscript("../../WriteUp/Graphics/Chapter5/dup_fig_5_1_m2.eps", onefile=FALSE, horizontal=FALSE) plot( x, y, type="p" ); m2 = lm( y ~ bs(x,degree=1,df=2) ) lines( x, fitted(m2) ) #dev.off() #postscript("../../WriteUp/Graphics/Chapter5/dup_fig_5_1_m3.eps", onefile=FALSE, horizontal=FALSE) plot( x, y, type="p" ); m3 = lm( y ~ bs(x,degree=1,df=3) ) lines( x, fitted(m3) ) #dev.off() #postscript("../../WriteUp/Graphics/Chapter5/dup_fig_5_1_m4.eps", onefile=FALSE, horizontal=FALSE) plot( x, y, type="p" ); m4 = lm( y ~ bs(x,degree=2,df=2) ) lines( x, fitted(m4) ) #dev.off() #postscript("../../WriteUp/Graphics/Chapter5/dup_fig_5_1_m5.eps", onefile=FALSE, horizontal=FALSE) plot( x, y, type="p" ); m5 = lm( y ~ bs(x,degree=2,df=3) ) lines( x, fitted(m5) ) #dev.off() #postscript("../../WriteUp/Graphics/Chapter5/dup_fig_5_1_m6.eps", onefile=FALSE, horizontal=FALSE) plot( x, y, type="p" ); m6 = lm( y ~ bs(x,degree=2,df=4) ) lines( x, fitted(m6) ) #dev.off()