# [R] persp( ) Question

Greg Tarpinian sasprog474 at yahoo.com
Fri May 6 16:18:08 CEST 2005

```I have successfully fitted the model

loess.fit1 <- loess(response ~ X*Y)

and plotted it in 3D using

X.grid <- seq(0,10,length=100)
Y.grid <- seq(0,1000,length=100)
pred.loess1 <- predict(loess.fit1,
expand.grid(x = X.grid, y = Y.grid))
persp(X.grid, Y.grid, pred.loess1, theta = 0, phi =
12)

I would like to add a series of points along the
fitted surface at X.grid = 2, in red.  The example

f <- function(x,y)
{ r <- sqrt(x^2+y^2); 10 * sin(r)/r }
trans3d <- function(x,y,z, pmat)
{
tr <- cbind(x,y,z,1) %*% pmat
list(x = tr[,1]/tr[,4], y= tr[,2]/tr[,4])
}
phi <- seq(0, 2*pi, len = 201)
r1 <- 7.725 # radius of 2nd maximum
xr <- r1 * cos(phi)
yr <- r1 * sin(phi)
lines(trans3d(xr,yr, f(xr,yr), res),
col = "pink", lwd=2)

to add points to the fitted mathematical surface. I
have not been able to reproduce this sort of
functionality partly because I don't have a functional
representation of my surface and partly because I
don't understand what trans3d( ) is doing.  Any help
would be greatly appreciated.

Kind regards,

Greg

Stay connected, organized, and protected. Take the tour:

```