user3083324 - 1 year ago 89

R Question

How do I generate a b-spline surface, let's say:

`x=attitude$rating`

y=attitude$complaints

z=attitude$privileges

would be x and y for the spline basis. z is the set of control points.

Answer Source

If I understand you, you have x,y, and z data and you want to use bivariate spline interpolation on x and y, using z for the control points. You can do this with `interp(...)`

in the `akima`

package.

```
library(akima)
spline <- interp(x,y,z,linear=FALSE)
# rotatable 3D plot of points and spline surface
library(rgl)
open3d(scale=c(1/diff(range(x)),1/diff(range(y)),1/diff(range(z))))
with(spline,surface3d(x,y,z,alpha=.2))
points3d(x,y,z)
title3d(xlab="rating",ylab="complaints",zlab="privileges")
axes3d()
```

The plot itself is fairly uninteresting with your dataset because x, y, and x are highly correlated.

**EDIT** response to OP's comment.

If you want a b-spline surface, try out `mba.surf(...)`

in the unfortunately named `MBA`

package.

```
library(MBA)
spline <- mba.surf(data.frame(x,y,z),100,100)
library(rgl)
open3d(scale=c(1/diff(range(x)),1/diff(range(y)),1/diff(range(z))))
with(spline$xyz,surface3d(x,y,z,alpha=.2))
points3d(x,y,z)
title3d(xlab="rating",ylab="complaints",zlab="privileges")
axes3d()
```