Load Data
data(anscombe)
summary(anscombe)
## x1 x2 x3 x4 y1
## Min. : 4.0 Min. : 4.0 Min. : 4.0 Min. : 8 Min. : 4.260
## 1st Qu.: 6.5 1st Qu.: 6.5 1st Qu.: 6.5 1st Qu.: 8 1st Qu.: 6.315
## Median : 9.0 Median : 9.0 Median : 9.0 Median : 8 Median : 7.580
## Mean : 9.0 Mean : 9.0 Mean : 9.0 Mean : 9 Mean : 7.501
## 3rd Qu.:11.5 3rd Qu.:11.5 3rd Qu.:11.5 3rd Qu.: 8 3rd Qu.: 8.570
## Max. :14.0 Max. :14.0 Max. :14.0 Max. :19 Max. :10.840
## y2 y3 y4
## Min. :3.100 Min. : 5.39 Min. : 5.250
## 1st Qu.:6.695 1st Qu.: 6.25 1st Qu.: 6.170
## Median :8.140 Median : 7.11 Median : 7.040
## Mean :7.501 Mean : 7.50 Mean : 7.501
## 3rd Qu.:8.950 3rd Qu.: 7.98 3rd Qu.: 8.190
## Max. :9.260 Max. :12.74 Max. :12.500
Load Library
library(Hmisc)
## Warning: 套件 'Hmisc' 是用 R 版本 4.1.3 來建造的
## 載入需要的套件:lattice
## 載入需要的套件:survival
## 載入需要的套件:Formula
## Warning: 套件 'Formula' 是用 R 版本 4.1.1 來建造的
## 載入需要的套件:ggplot2
## Warning: 套件 'ggplot2' 是用 R 版本 4.1.3 來建造的
##
## 載入套件:'Hmisc'
## 下列物件被遮斷自 'package:base':
##
## format.pval, units
Correlation
round(cor(anscombe), 3)
## x1 x2 x3 x4 y1 y2 y3 y4
## x1 1.000 1.000 1.000 -0.500 0.816 0.816 0.816 -0.314
## x2 1.000 1.000 1.000 -0.500 0.816 0.816 0.816 -0.314
## x3 1.000 1.000 1.000 -0.500 0.816 0.816 0.816 -0.314
## x4 -0.500 -0.500 -0.500 1.000 -0.529 -0.718 -0.345 0.817
## y1 0.816 0.816 0.816 -0.529 1.000 0.750 0.469 -0.489
## y2 0.816 0.816 0.816 -0.718 0.750 1.000 0.588 -0.478
## y3 0.816 0.816 0.816 -0.345 0.469 0.588 1.000 -0.155
## y4 -0.314 -0.314 -0.314 0.817 -0.489 -0.478 -0.155 1.000
(x1,y1)
round(cor(anscombe$x1, anscombe$y1), 3)
## [1] 0.816
(x2,y2)
round(cor(anscombe$x2, anscombe$y2), 3)
## [1] 0.816
(x3,y3)
round(cor(anscombe$x3, anscombe$y3), 3)
## [1] 0.816
(x4,y4)
round(cor(anscombe$x4, anscombe$y4), 3)
## [1] 0.817
(x1,y1)
plot(anscombe$x1, anscombe$y1, col='blue', pch=16)
abline(lm(anscombe$y1 ~ anscombe$x1), col = "red", lwd = 3)
(x2,y2)
plot(anscombe$x2, anscombe$y2, col='blue', pch=16)
abline(lm(anscombe$y2 ~ anscombe$x2), col = "red", lwd = 3)
(x3,y3)
plot(anscombe$x3, anscombe$y3, col='blue', pch=16)
abline(lm(anscombe$y3 ~ anscombe$x3), col = "red", lwd = 3)
(x4,y4)
plot(anscombe$x4, anscombe$y4, col='blue', pch=16)
abline(lm(anscombe$y4 ~ anscombe$x4), col = "red", lwd = 3)
雖然回歸線和相關都幾乎一樣,但是資料實際的分布狀況卻可能差距很大,所以不能單純以相關來做出結論