[R] rgl 3d surface

S Ellison S.Ellison at LGCGroup.com
Thu Jul 16 15:01:28 CEST 2015



> -----Original Message-----
> > I compute its regression surface doing polynomical regression (fit)
> > ...
> > fit <- lm(z ~ poly(x,2) + poly(y,2))
> >
.....
> > So I want to repressent the surface
.... 
> > How could I do it? Any idea??
> 
> You need to write a function f of x and y that produces the fitted values.  I
> haven't checked, but I'd assume it needs to take vector inputs and produce a
> vector of responses.  

Perhaps worth noting that since the fit was produced by lm(), predict() will generate the surface values without a separate function.

For example, if we said something like [sorry, not yet checked]

xvals <- seq(-35, -15, 0.5)
yvals <- seq(-35, -15, 0.5)
new.data <- data.frame(x=rep(xvals, each=length(yvals)), y=rep(yvals, length(xvals) )
new.data$z <- predict(fit, newdata=new.data)
#This should generate the predicted surface

#Then:
with(new.data, persp3d(x, y, z)) 

#ought to do the job.



> Then
> 
> 
> persp3d(f)
> 
> will draw the surface.  See ?persp3d.function for details on setting the x and y
> ranges, etc.
> 
> Duncan Murdoch
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list