[R] 3-d splinefun

Dave Roberts droberts at montana.edu
Fri Feb 10 16:28:04 CET 2006


Colby,

     Function surf() in package labdsv uses the gam() function from mgcv 
to do this in conjunction with akima.  You might want to look at that 
routine for an idea.  Currently it fits the gam as z <- gam(s(x) + s(y),
but it's possible in the mgcv version of gam to fit z <- gam(s(x,y)) as 
well.  The gam function gives a good interpolation with measured error 
and appropriate fit statistics.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
David W. Roberts                                     office 406-994-4548
Professor and Head                                      FAX 406-994-3190
Department of Ecology                         email droberts at montana.edu
Montana State University
Bozeman, MT 59717-3460


Colby Tanner wrote:
> hello,
> is it possible to do something like splinefun(x,y), but with a 3rd
> dim?
> for example, if i have a 2-dim system like:
> x<-1:100
> y<-rexp(100,1)
> func<-splinefun(x,sort(y))
> 
> func(n) # returns interpolated value of y (after sorting) given x=n
>         # i can check this by: 
> 
> plot(x,sort(y))
> lines(spline(x,sort(y)))
> 
> 
> Can i do the same thing with an x,y, and z? i have found the akima
> interp(x,y,z) for building 3-d images, but nothing about the function
> aspect.  besides building a nice 3-dim image, i would like to have a
> way of finding the interpolated z values if i give an x and y
> coordinate.  something like func(x,y) in the above example.
> 
> thank you,
> colby
> 
> ______________________________________________
> 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
> 
> 


--




More information about the R-help mailing list