0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

重回帰分析の状況を3次元表示で見てみる

Posted at

2 変数 x, y を使って z を予測する重回帰判別を行い,その結果を3次元表示してみる。
rgl で表示されるグラフィックスはマウスでグリグリ回転できる。
黒のデータがオレンジ色の平面で分割される様子が観察できる。

スクリーンショット 2022-07-02 21.34.43.png

library(rgl)
library(MASS)
set.seed(123)
n <- 2000
r12 <- r21 <- 0.6
r13 <- r31 <- 0.7
r23 <- r32 <- 0.8
d <- mvrnorm(n, mu=rep(0, 3), Sigma=matrix(c(1, r12, r13, r21, 1, r23, r31, r32, 1), 3),  empirical=TRUE)
d <- data.frame(d)
colnames(d) <- c("x", "y", "z")
a <- lm(z ~ x + y, d)
rx <- range(d$x)
ry <- range(d$y)
density <- 150
x2 <- seq(rx[1], rx[2], length=density)
y2 <- seq(ry[1], ry[2], length=density)
d2 <- data.frame(expand.grid(x2, y2))
colnames(d2) <- c("x", "y")
d2$z <- predict(a, newdata=d2)
plot3d(d, xlab="Var-x", ylab="Var-y", zlab="Var-z")
points3d(d2$x, d2$y, d2$z, col="#ffaa00", cex=0.5)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?