DF = data.frame( x=seq( 1, 5 ), y=c( 5.1, 2.2, 0.9, 1.9, 5.2 ) ) m = lm( y ~ x + I(x^2) + I(x^3) + I(x^4), data=DF ) x_grid = seq( min(DF$x), max(DF$x), length.out=100 ) y_hat = predict( m, newdata=data.frame( x=x_grid ) ) # Lets plot the data and models: # #postscript("../../WriteUp/Graphics/Chapter2/ex_2_22_part_b.eps", onefile=FALSE, horizontal=FALSE) plot( DF$x, DF$y, type='p', pch=19, cex=1.5, col='black', xlab='x', ylab='y' ) points( x_grid, y_hat, type='l', col='red' ) grid() #dev.off()