[R] smooth.spline

Rolf Turner rolf at math.unb.ca
Fri Mar 17 16:09:35 CET 2006

I have noticed a slightly puzzling behaviour exhibited by
smooth.spline().  If I do

	sss <- smooth.spline(x,y)

for a certain pair of data vectors x and y, and then do


I get the result ``18''.  However if I do


I get ``27''.  Trying to force smooth.spline() to use more knots I

	sss <- smooth.spline(x,y,all.knots=TRUE)

but again got output of length 18 again.  I then tried

	sss <- smooth.spline(x,y,nknots=27)

and got an error message.  Finally I was inspired to re-scale the
x-values.  Doing

	x <- x - min(x)
	sss <- smooth.spline(x,y)

gave me output of length 27 as expected.  Apparently smooth.spline()
is using a criterion for distinctness of x values which is based on a
tolerance relative to the size of the x's.  (I.e. a different
criterion from unique().)  While this is assuredly a Good Thing, it
might be nice to have some sort of warning in the help file to keep
young players from getting confused.


					Rolf Turner
					rolf at math.unb.ca

More information about the R-help mailing list