# Re: [R] 3-d splinefun

From: Dave Roberts <droberts_at_montana.edu>
Date: Sat 11 Feb 2006 - 02:28:04 EST

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
Department of Ecology                         email droberts@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@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
```--