[R] Constrained cubic smoothing spline

Simon Wood s.wood at bath.ac.uk
Wed Mar 6 08:54:00 CET 2013


Victor,

It's a bit clunky, but you can use the 'pcls' function in package 'mgcv' 
for this, by adapting the examples in the help file. The examples 
themselves deal with inequality constraints imposing monotonicity, but 
'pcls' also allows you to impose equality constraints. The examples are 
based on penalized cubic regression splines (i.e. cubic splines with 
fewer knots than you have data). You could use essentially the same code 
for full smoothing splines, but it is somewhat inefficient for that 
purpose, and will be prohibitively expensive for large datasets: 
operations count is O(np^2) where p is number of spline coefficients, so 
setting p=n can get costly.

Simon




On 06/03/13 01:07, Victor hyk wrote:
> Hello everone,
>             Anyone who knows how to force a cubic smoothing spline to pass through a particular point?
>             I found on website  someone said that we can use "cobs package" to force the spline pass through certain points or impose shape           constraints (increasing, decreasing). However,  this package is using  B-spline and can only do linear and quadratic B-spline.
>             In my research, I need to force a cubic smoothing spline to pass a point.
>             Thanks!
>
>            Victor
>
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
+44 (0)1225 386603               http://people.bath.ac.uk/sw283



More information about the R-help mailing list