Easy splines in R, and chess ratings

When plotting data sometimes is necessary to fit data points to some high order polynomial but that usually brings a problem called the Runge’s phenomenon where the fit presents high oscillations in the edges of the interval. To solve this one usually uses splines that are much smoother and can convey greater information to the reader.

Using splines in R is very simple.

In this illustrative example I just used the live ratings of the 41 +2700 players in the world. First plotted Rating vs. Year of Birth. Then, to add the spline one just need to use the smooth.spline function in R stats package.

Chess Rating vs.Year of Birth

The code for the generation of this is:

> chess<-read.table('chessratings.txt', header=T)
> plot(chess$Born, chess$Rating, xlab='Year of Birth', 
+ ylab='Elo Rating', main='ELO>2700: Does Chess Rating depend on age?')
> lines(smooth.spline(chess$Born, chess$Rating, spar=0.5))

the interesting parameter spar is the smoothing parameter that allows you to control the shape of the curve. Experiment with it until you get ‘nice’ results.