Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain spline surface on R

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.

like image 407
user3083324 Avatar asked Jul 17 '14 18:07

user3083324


People also ask

How the B-spline surface is generated?

We can create a B-Spline surface using a similar method to the Bézier surface. For B-Spline curves, we used two phantom knots to clamp the ends of the curve. For a surface, we will have phantom knots all around the eal knots as shown below for an M+1 by N+1 knot surface.

What is spline surface?

Spline curves originate from flexible strips used to create smooth curves in traditional drafting applications. Much like Bezier curves they are formed mathematically from piecewise approximations of cubic polynomial functions with zero, first and second order continuity.

What is Cubic spline in R?

Cubic regression spline is a form of generalized linear models in regression analysis. Also known as B-spline, it is supported by a series of interior basis functions on the interval with chosen knots. Cubic regression splines are widely used on modeling nonlinear data and interaction between variables.

What is spline analysis?

In the mathematical field of numerical analysis, spline interpolation is a form of interpolation where the interpolant is a special type of piecewise polynomial called a spline.


1 Answers

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()

like image 116
jlhoward Avatar answered Oct 27 '22 20:10

jlhoward