Boston house price dataset

boston <- read.table("housing.data")
dplyr::glimpse(boston)
## Observations: 506
## Variables: 14
## $ V1  <dbl> 0.00632, 0.02731, 0.02729, 0.03237, 0.06905, 0.02985, 0.08...
## $ V2  <dbl> 18.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.5, 12.5, 12.5, 12.5, 12....
## $ V3  <dbl> 2.31, 7.07, 7.07, 2.18, 2.18, 2.18, 7.87, 7.87, 7.87, 7.87...
## $ V4  <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...
## $ V5  <dbl> 0.538, 0.469, 0.469, 0.458, 0.458, 0.458, 0.524, 0.524, 0....
## $ V6  <dbl> 6.575, 6.421, 7.185, 6.998, 7.147, 6.430, 6.012, 6.172, 5....
## $ V7  <dbl> 65.2, 78.9, 61.1, 45.8, 54.2, 58.7, 66.6, 96.1, 100.0, 85....
## $ V8  <dbl> 4.0900, 4.9671, 4.9671, 6.0622, 6.0622, 6.0622, 5.5605, 5....
## $ V9  <int> 1, 2, 2, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4...
## $ V10 <dbl> 296, 242, 242, 222, 222, 222, 311, 311, 311, 311, 311, 311...
## $ V11 <dbl> 15.3, 17.8, 17.8, 18.7, 18.7, 18.7, 15.2, 15.2, 15.2, 15.2...
## $ V12 <dbl> 396.90, 396.90, 392.83, 394.63, 396.90, 394.12, 395.60, 39...
## $ V13 <dbl> 4.98, 9.14, 4.03, 2.94, 5.33, 5.21, 12.43, 19.15, 29.93, 1...
## $ V14 <dbl> 24.0, 21.6, 34.7, 33.4, 36.2, 28.7, 22.9, 27.1, 16.5, 18.9...
# 컬럼명 넣기
values <- c("crim", "zn", "indus", "chas", "nox", "rm", "age", "dis", "rad", "tax", "ptratio", "black","lstat", "medv")
names(boston) <- values
############
# "crim", 범죄발생율
# "zn", 주거지 중 25000 sq.ft 이상 크기의 대형주택이 차지하는 비율
# "indus", 소매상 이외의 상업지구의 면적비율
# "chas", 찰스강과 접한 지역은 1, 아니면 0인 더미변수
# "nox", 산화질소 오염도
# "rm", 주거지당 평균 방개수
# "age", 소유자 주거지(비 전세/월세) 중 1940년 이전에 지어진 집들의 비율
# "dis", 보스턴의 5대 고용중심으로부터의 가중평균 거리
# "rad", 도시순환 고속도로에의 접근 용이지수
# "tax", 만 달러당 주택 제산세율
# "ptratio", 힉생-교사 비율
# "black", 흑인인구 비율이 0.63 과 다른 정도의 제곱
# "lstat", 저소득층 주민들의 비율 퍼센트
# "medv" 소유자 주거지(비 전세/월세) 주택가격 
############

# 상관행렬계수 만들기
boston_cor <- cor(boston)
round(boston_cor, digit=2)
##          crim    zn indus  chas   nox    rm   age   dis   rad   tax
## crim     1.00 -0.20  0.41 -0.06  0.42 -0.22  0.35 -0.38  0.63  0.58
## zn      -0.20  1.00 -0.53 -0.04 -0.52  0.31 -0.57  0.66 -0.31 -0.31
## indus    0.41 -0.53  1.00  0.06  0.76 -0.39  0.64 -0.71  0.60  0.72
## chas    -0.06 -0.04  0.06  1.00  0.09  0.09  0.09 -0.10 -0.01 -0.04
## nox      0.42 -0.52  0.76  0.09  1.00 -0.30  0.73 -0.77  0.61  0.67
## rm      -0.22  0.31 -0.39  0.09 -0.30  1.00 -0.24  0.21 -0.21 -0.29
## age      0.35 -0.57  0.64  0.09  0.73 -0.24  1.00 -0.75  0.46  0.51
## dis     -0.38  0.66 -0.71 -0.10 -0.77  0.21 -0.75  1.00 -0.49 -0.53
## rad      0.63 -0.31  0.60 -0.01  0.61 -0.21  0.46 -0.49  1.00  0.91
## tax      0.58 -0.31  0.72 -0.04  0.67 -0.29  0.51 -0.53  0.91  1.00
## ptratio  0.29 -0.39  0.38 -0.12  0.19 -0.36  0.26 -0.23  0.46  0.46
## black   -0.39  0.18 -0.36  0.05 -0.38  0.13 -0.27  0.29 -0.44 -0.44
## lstat    0.46 -0.41  0.60 -0.05  0.59 -0.61  0.60 -0.50  0.49  0.54
## medv    -0.39  0.36 -0.48  0.18 -0.43  0.70 -0.38  0.25 -0.38 -0.47
##         ptratio black lstat  medv
## crim       0.29 -0.39  0.46 -0.39
## zn        -0.39  0.18 -0.41  0.36
## indus      0.38 -0.36  0.60 -0.48
## chas      -0.12  0.05 -0.05  0.18
## nox        0.19 -0.38  0.59 -0.43
## rm        -0.36  0.13 -0.61  0.70
## age        0.26 -0.27  0.60 -0.38
## dis       -0.23  0.29 -0.50  0.25
## rad        0.46 -0.44  0.49 -0.38
## tax        0.46 -0.44  0.54 -0.47
## ptratio    1.00 -0.18  0.37 -0.51
## black     -0.18  1.00 -0.37  0.33
## lstat      0.37 -0.37  1.00 -0.74
## medv      -0.51  0.33 -0.74  1.00
library(corrplot)
## corrplot 0.84 loaded
corrplot(boston_cor)

# 색을 입힌 사각형을 넣고 검은색 라벨을 위쪽만 45도 회전한 상관행렬
corrplot(boston_cor, method = "shade", shade.col = NA, tl.col = "black", tl.srt = 45)

#옅은 색의 팔레트 생성
col = colorRampPalette(c("#BB4444", "#EE9988", "#FFFFFF", "#77AADD", "#4477AA"))

# 상관계수 추가, "AOE" (Angular order of Eigebvectors) 순 정렬
corrplot(boston_cor, method = "shade", shade.col = NA, tl.col = "black", tl.srt = 45,
         diag=FALSE, # 대각선 값 미제시
         col = col(200), addCoef.col = "black", order = "AOE")

# 산점도 행렬  scatter plot matrix
plot(boston)