Skip to content
Prev 334025 / 398513 Next

How to generate a smoothed surface for a three dimensional dataset?

On Dec 4, 2013, at 8:56 AM, Duncan Murdoch wrote:

            
Newcomers to R may think they would be getting a quadratic in x and y. But R's formula interpretation will collapse x^2 to just x and then it becomes superfluous and is discarded. The same result is obtained with z ~ (x + y)^2).   I would have thought that this would have been the code:

fit <- lm(z ~ poly(x,2) +poly(y,2) + x:y )
With the modified fitting formula one sees a nice saddle (for that particular random draw) using rgl.snapshot().


The result with the earlier formula is a more restrained:




Continued thanks to you Duncan for making this great tool available.