scatterplot3d用于R中的响应曲面 [英] scatterplot3d for Response Surface in R
问题描述
library(rsm)$ b $我想通过scatterplot3d对响应表面进行图形化处理,但通过一个错误发现下面的代码。 (swiss2.lm,Education〜Agriculture,zlab =Fertility)
(生育〜聚(农业,教育,学位= 2),数据=瑞士)
persp
library(scatterplot3d)
s3d< -
scatterplot3d(
swiss
#,type =h
,highlight.3d = TRUE
,angle = 55
,scale.y = 0.7
,pch = 16
)
s3d $ plane3d(swiss2.lm,lty.box =固体)
如果您能帮助解决问题,我将非常感激。谢谢
Eidt
段(x,z1,x + y.max * yx.f,z2 + yz.f * y.max,lty = ltya,:
不能混合零长度和非零长度坐标
我从<$ c $使用 swiss
数据c> rsm library。
如何使用 scatterplot3d
?如果你愿意在 rgl
中执行,那很简单。 $ b
设置均匀排列的网格并进行预测:
newdat< - expand.grid(Education = seq( 0,50,by = 5),
Agriculture = seq(0,100,by = 10))
newdat $ pp < - 预测(swiss2.lm,newdata = newdat)
绘制点并添加曲面:
<$ c (农业,教育,生育)
与(newdat,surface3d(独特(农业),独特(教育),pp,
alpha = 0.3,front =line))
rgl.snapshot(swiss.png)
rgl
具有一些优点(隐藏线删除,光照效果,动态旋转和缩放)和一些缺点(不适合基本包装布局等。难以操纵字体,包括 plotmath
方程等;难以调整标签的位置和绘图风格)。 car
包中的 scatter3d
函数具有一些很好的功能,可将回归曲面添加到 rgl
情节,但据我所见,它可以做加法模型,但不允许使用二次多项式模型...
到目前为止正如我所看到的,为了在 scatterplot3d
框架中执行此操作,您必须构建与回归曲面中的四边形相对应的点,并使用 xyz.convert
和段
来绘制它们...
I want to graph response surface through scatterplot3d but the following code through an error.
library(rsm)
swiss2.lm <- lm(Fertility ~ poly(Agriculture, Education, degree = 2), data = swiss)
persp(swiss2.lm, Education ~ Agriculture, zlab = "Fertility")
library(scatterplot3d)
s3d <-
scatterplot3d(
swiss
# , type = "h"
, highlight.3d = TRUE
, angle = 55
, scale.y = 0.7
, pch = 16
)
s3d$plane3d(swiss2.lm, lty.box = "solid")
I'd highly appreciate if you help to figure out the issue. Thanks
Eidt
Error in segments(x, z1, x + y.max * yx.f, z2 + yz.f * y.max, lty = ltya, :
cannot mix zero-length and non-zero-length coordinates
I'm using swiss
data from rsm
library.
How attached are you to using scatterplot3d
? If you're willing to do it in rgl
it's pretty easy. Following from your example:
Set up evenly spaced grid and make predictions:
newdat <- expand.grid(Education=seq(0,50,by=5),
Agriculture=seq(0,100,by=10))
newdat$pp <- predict(swiss2.lm,newdata=newdat)
Plot points and add surface:
library(rgl)
with(swiss,plot3d(Agriculture,Education,Fertility))
with(newdat,surface3d(unique(Agriculture),unique(Education),pp,
alpha=0.3,front="line"))
rgl.snapshot("swiss.png")
rgl
has some advantages (hidden line removal, lighting effects, dynamic rotation and zooming) and some disadvantages (doesn't fit well into base-package layouts etc.; harder to manipulate fonts, include plotmath
equations, etc.; harder to adjust label placement and plot style). The scatter3d
function in the car
package has some nice features for adding regression surfaces to an rgl
plot, but as far as I can see it does additive models, but doesn't allow for quadratic polynomial models ...
As far as I can see, in order to do this in the scatterplot3d
framework you would have to construct the points corresponding to the quadrangles in the regression surface and use xyz.convert
and segments
to draw them ...
这篇关于scatterplot3d用于R中的响应曲面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!