Gregory Gentlemen
2006-Jun-24 18:41 UTC
[R] getting the smoother matrix from smooth.spline
Can anyone tell me the trick for obtaining the smoother matrix from
smooth.spline when there are non-unique values for x. I have the following code
but, of course, it only works when all values of x are unique.
## get the smoother matrix (x having unique values
smooth.matrix = function(x, df){
n = length(x);
A = matrix(0, n, n);
for(i in 1:n){
y = rep(0, n); y[i]=1;
yi = smooth.spline(x, y, df=df)$y;
A[,i]= yi;
}
(A+t(A))/2;
}
Thanks for any assistance,
Gregory
---------------------------------
---------------------------------
Get a sneak peak at messages with a handy reading pane.
[[alternative HTML version deleted]]
>>>>> "Gregory" == Gregory Gentlemen <gregory_gentlemen at yahoo.ca> >>>>> on Sat, 24 Jun 2006 14:41:37 -0400 (EDT) writes:Gregory> Can anyone tell me the trick for obtaining the Gregory> smoother matrix from smooth.spline when there are Gregory> non-unique values for x. I have the following code Gregory> but, of course, it only works when all values of x Gregory> are unique. >> ## get the smoother matrix (x having unique values >> smooth.matrix = function(x, df){ >> n = length(x); >> A = matrix(0, n, n); >> for(i in 1:n){ >> y = rep(0, n); y[i]=1; >> yi = smooth.spline(x, y, df=df)$y; >> A[,i]= yi; >> } >> (A+t(A))/2; >> } { All the extraneous ";" at the end of lines make the above unncessarily ugly (and potentially even slightly inefficient).} Package 'sfsmisc' has had a function hatMat() which returns the hat matrix aka smoother matrix, in a slightly more general way -- you can use it also for other smoothers, see the examples in help(hatMat). The smoother defaults to smooth.spline(), so you can directly use it, e.g., hatMat(x, df=5) Why do you think your code or hatMat() would not work for non-unique x-values? Gregory> Thanks for any assistance, Gregory> Gregory Gregory> --------------------------------- Gregory> [[alternative HTML version deleted]] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [please do read the posting guide, and hence get rid of the line above ! ] Gregory> ______________________________________________ Gregory> R-help at stat.math.ethz.ch mailing list Gregory> https://stat.ethz.ch/mailman/listinfo/r-help Gregory> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
smooth.matrix = function(x, df){
n = length(x);
A = matrix(0, n, n);
for(i in 1:n){
y = rep(0, n); y[i]=1;
yi = predict(smooth.spline(x, y, df=df),x)$y;
A[,i]= yi;
}
(A+t(A))/2;
}
>- Simon Wood, Mathematical Sciences, University of Bath, Bath BA2 7AY
>- +44 (0)1225 386603 www.maths.bath.ac.uk/~sw283/
On Sat, 24 Jun 2006, Gregory Gentlemen wrote:
> Can anyone tell me the trick for obtaining the smoother matrix from
smooth.spline when there are non-unique values for x. I have the following code
but, of course, it only works when all values of x are unique.
>
> ## get the smoother matrix (x having unique values
> smooth.matrix = function(x, df){
> n = length(x);
> A = matrix(0, n, n);
> for(i in 1:n){
> y = rep(0, n); y[i]=1;
> yi = smooth.spline(x, y, df=df)$y;
> A[,i]= yi;
> }
> (A+t(A))/2;
> }
>
>
> Thanks for any assistance,
> Gregory
>
>
> ---------------------------------
>
> ---------------------------------
> Get a sneak peak at messages with a handy reading pane.
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
Gabor Grothendieck
2006-Jun-30 16:14 UTC
[R] getting the smoother matrix from smooth.spline
Perhaps this could be developed into a spline smooth method for model.matrix and included in R. On 6/30/06, Simon Wood <sw283 at maths.bath.ac.uk> wrote:> smooth.matrix = function(x, df){ > n = length(x); > A = matrix(0, n, n); > for(i in 1:n){ > y = rep(0, n); y[i]=1; > yi = predict(smooth.spline(x, y, df=df),x)$y; > A[,i]= yi; > } > (A+t(A))/2; > } > > > >- Simon Wood, Mathematical Sciences, University of Bath, Bath BA2 7AY > >- +44 (0)1225 386603 www.maths.bath.ac.uk/~sw283/ > > > On Sat, 24 Jun 2006, Gregory Gentlemen wrote: > > > Can anyone tell me the trick for obtaining the smoother matrix from smooth.spline when there are non-unique values for x. I have the following code but, of course, it only works when all values of x are unique. > > > > ## get the smoother matrix (x having unique values > > smooth.matrix = function(x, df){ > > n = length(x); > > A = matrix(0, n, n); > > for(i in 1:n){ > > y = rep(0, n); y[i]=1; > > yi = smooth.spline(x, y, df=df)$y; > > A[,i]= yi; > > } > > (A+t(A))/2; > > } > > > > > > Thanks for any assistance, > > Gregory > > > > > > --------------------------------- > > > > --------------------------------- > > Get a sneak peak at messages with a handy reading pane. > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Possibly Parallel Threads
- How to choose a proper smoothing spline in GAM of mgcv package?
- Use pcls in "mgcv" package to achieve constrained cubic spline
- Smooth periodic splines
- Constrained cubic smoothing spline
- Smoothing spline with smoothing parameters selected by "generalized maximum likelihood"