r - 如何在r中将平面回归变为曲面?
问题描述
我正在尝试将平面更改为曲面,但这很困难。
查看散点图,表面应该是弯曲的而不是平坦的。如何修改我的代码?
代码和图片如下。
由于数据文件太多,无法附上,非常抱歉。我认为 lm 函数可能会创建该平面。有想法吗?
谢谢!
library(scatterplot3d)
library(plot3D)
library(readxl)
RoomA <- read_excel("Data_without_outlier_RoomA.xlsx")
# x, y, z variables
x <- RoomA$Ammonia
y <- RoomA$Ventilation
z <- RoomA$Emissions
# Compute the linear regression (z = ax + by + d)
fit <- lm(z ~ x + y)
# predict values on regular xy grid
grid.lines = 25
x.pred <- seq(min(x), max(x), length.out = grid.lines)
y.pred <- seq(min(y), max(y), length.out = grid.lines)
xy <- expand.grid( x = x.pred, y = y.pred)
z.pred <- matrix(predict(fit, newdata = xy),
nrow = grid.lines, ncol = grid.lines)
# fitted points for droplines to surface
fitpoints <- predict(fit)
# scatter plot with regression plane
scatter3D(x, y, z, pch = 20, cex = 1.5,
theta = 320, phi = 25, ticktype = "detailed",
xlab = "", ylab = "", zlab = "",
surf = list(x = x.pred, y = y.pred, z = z.pred,
facets = NA), main = "Room A")
解决方案
推荐阅读
- javascript - 我如何填充画布而不是圆圈
- jquery - 获取隐藏字段的值
- postgresql - 为什么插入主键不影响顺序?
- javascript - 使用 ajax 和 javascript 更新 innerHTML 值
- javascript - 即使在剑道网格列中,如何调用按钮单击java脚本模具
- amazon-web-services - kubectl error 访问EKS集群时必须登录服务器(未授权)
- css - 如何在 Angular 应用程序中检查 CSS 加载大小
- android - Google Play 警告:您的应用包含基于文件的 XSS 问题?JavaScript 启用 = 真
- php - 安装我的自定义插件后创建自定义 wordpress 页面
- python - 字符串中的一个热门 - 获取唯一列表中的索引