小编Fra*_*urg的帖子

scatterplot3d:带残差的回归平面

scatterplot3d在 R 中使用,我试图从观察到回归平面绘制红线:

wh <- iris$Species != "setosa"
x  <- iris$Sepal.Width[wh]
y  <- iris$Sepal.Length[wh]
z  <- iris$Petal.Width[wh]
df <- data.frame(x, y, z)

LM <- lm(y ~ x + z, df)
library(scatterplot3d)
G  <- scatterplot3d(x, z, y, highlight.3d = FALSE, type = "p")
G$plane3d(LM, draw_polygon = TRUE, draw_lines = FALSE)
Run Code Online (Sandbox Code Playgroud)

回归平面

要获得下图的 3D 等效项:

在此处输入图片说明

在 2D 中,我可以使用segments

pred  <- predict(model) 
segments(x, y, x, pred, col = 2)
Run Code Online (Sandbox Code Playgroud)

但是在 3D 中,我对坐标感到困惑。

r scatter-plot scatter3d

6
推荐指数
2
解决办法
3819
查看次数

标签 统计

r ×1

scatter-plot ×1

scatter3d ×1