简体   繁体   English

3D 散点图 plot 带有拟合回归 3D 平面 ZE1E1D3D40573127E9EE0480CAF128 语言

[英]3D scatter plot with a fitted regression 3D plane in R language

I am trying to plot a 3D Multiple polynomial regression.我正在尝试 plot 一个 3D 多项式回归。 I have two independent variables (area and number of bedrooms) and one dependent variable (price).我有两个自变量(卧室面积和数量)和一个因变量(价格)。 Each independent variable has its own polynomial degree (the area has 3 degrees polynomial, and the number of bedrooms has 4 degrees polynomial).每个自变量都有自己的多项式次数(面积有3次多项式,卧室数量有4次多项式)。

So far, I was only able to plot in 3D with the package "scatterplot3d", but I was not able to create the fitted regression 3D plane in my plot. So far, I was only able to plot in 3D with the package "scatterplot3d", but I was not able to create the fitted regression 3D plane in my plot.

My questions: I want to create a 3D graph with the fitted regression 3D plane and the scatter plot, which package should I use?我的问题:我想用拟合回归 3D 平面和散点 plot 创建一个 3D 图,ZEFE90A8E604A7F840 应该使用哪一个? How would the code look like to have the fitted regression 3D plane in my plot (if you have a general idea)?在我的 plot (如果您有一个大致的想法)中,代码看起来如何具有拟合回归 3D 平面?

Thank You for your help:)谢谢您的帮助:)

Note: I am using r language in r studio cloud.注意:我在 r 工作室云中使用 r 语言。

Here's an example using plotPlane from the rockchalk package, which uses the persp function "under the hood" but simplifies the details of the plotting operations.这是一个使用来自rockchalk package 的persp plotPlane “在引擎盖下”,但简化了绘图操作的细节。 See the help for plotPlane (type ?plotPlane ) for details on how the function works and the wide range of options for customizing the plot.有关 function 的工作原理以及自定义 plot 的各种选项的详细信息,请参阅plotPlane (类型?plotPlane )的帮助。

library(rockchalk)

m1 = lm(mpg ~ poly(wt,2) + disp, data=mtcars)

old.par = par(mfrow=c(1,2), mar=c(1,1,1,1))

plotPlane(m1, "wt", "disp", pch=16, col=rgb(0,0,1,0.1), drawArrows=TRUE, alength=0, 
          acol="red", alty=1,alwd=1, theta=25, phi=0)
plotPlane(m1, "wt", "disp", pch=16, col=rgb(0,0,1,0.1), drawArrows=TRUE, alength=0, 
          acol="red", alty=1,alwd=1, theta=35, phi=20)

在此处输入图像描述

If you have more than two dependent variables in the model, plotPlane will set the additional variables (the ones not being plotted) to their mean (for numeric variables) or mode (for factors).如果 model 中有两个以上的因变量, plotPlane会将附加变量(未绘制的变量)设置为其平均值(对于数值变量)或众数(对于因子)。 For example:例如:

m2 = lm(mpg ~ poly(wt,2) + disp + poly(hp,2) + poly(wt,2), data=mtcars)

plotPlane(m2, "wt", "disp", pch=16, col=rgb(0,0,1,0.1), drawArrows=TRUE, alength=0, 
          acol="red", alty=1,alwd=1, theta=25, phi=0)
plotPlane(m2, "wt", "disp", pch=16, col=rgb(0,0,1,0.1), drawArrows=TRUE, alength=0, 
          acol="red", alty=1,alwd=1, theta=35, phi=20)

在此处输入图像描述

# Reset graphical parameters back to defaults
par(old.par)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM