Principal Component
library(readxl)
jgb2 <- read_xlsx("jgbcm_all.xlsx")
head(jgb2)
## # A tibble: 6 x 16
## `1` `1Y` `2Y` `3Y` `4Y` `5Y` `6Y` `7Y` `8Y` `9Y`
## <dttm> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1974-09-24 00:00:00 10.3 9.36 8.83 8.52 8.35 8.29 8.24 8.12 8.13
## 2 1974-09-25 00:00:00 10.3 9.36 8.83 8.52 8.35 8.29 8.24 8.12 8.13
## 3 1974-09-26 00:00:00 10.3 9.37 8.83 8.52 8.35 8.29 8.24 8.12 8.13
## 4 1974-09-27 00:00:00 10.3 9.37 8.83 8.52 8.35 8.29 8.24 8.12 8.13
## 5 1974-09-28 00:00:00 10.4 9.37 8.83 8.52 8.35 8.29 8.24 8.12 8.13
## 6 1974-09-30 00:00:00 10.4 9.37 8.84 8.52 8.35 8.29 8.24 8.12 8.13
## # i 6 more variables: `10Y` <dbl>, `15Y` <dbl>, `20Y` <dbl>, `25Y` <dbl>,
## # `30Y` <dbl>, `40Y` <dbl>
jgb2[is.na(jgb2)]<-0
jgb3 <- jgb2[,-1]
jgb_pca <-princomp((jgb3), cor=TRUE)
summary(jgb_pca)
## Importance of components:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Standard deviation 3.1433166 1.5537198 1.06638985 0.77222681 0.66221399
## Proportion of Variance 0.6586959 0.1609363 0.07581249 0.03975562 0.02923516
## Cumulative Proportion 0.6586959 0.8196323 0.89544477 0.93520039 0.96443554
## Comp.6 Comp.7 Comp.8 Comp.9
## Standard deviation 0.49534812 0.40145367 0.256220464 0.194928399
## Proportion of Variance 0.01635798 0.01074434 0.004376595 0.002533139
## Cumulative Proportion 0.98079353 0.99153786 0.995914458 0.998447597
## Comp.10 Comp.11 Comp.12 Comp.13
## Standard deviation 0.126705339 0.0629395558 0.0457497667 2.727444e-02
## Proportion of Variance 0.001070283 0.0002640925 0.0001395361 4.959302e-05
## Cumulative Proportion 0.999517880 0.9997819726 0.9999215086 9.999711e-01
## Comp.14 Comp.15
## Standard deviation 1.559118e-02 1.379820e-02
## Proportion of Variance 1.620566e-05 1.269269e-05
## Cumulative Proportion 9.999873e-01 1.000000e+00
## JGB 2000~
#install.packages("readxl")
library(readxl)
jgb00 <- read_xlsx("jgbcm_all2000.xlsx")
jgb00[is.na(jgb00)] <- 0
jgb2000 <- jgb00[,-1]
head(jgb2000)
## # A tibble: 6 x 15
## `1年` `2年` `3年` `4年` `5年` `6年` `7年` `8年` `9年` `10年` `15年` `20年`
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 0.197 0.402 0.53 0.796 1.01 1.24 1.44 1.55 1.75 1.74 2.16 2.4
## 2 0.183 0.38 0.501 0.766 0.977 1.21 1.40 1.52 1.72 1.72 2.14 2.38
## 3 0.192 0.388 0.504 0.764 0.974 1.20 1.39 1.51 1.71 1.71 2.12 2.36
## 4 0.196 0.406 0.543 0.811 1.03 1.25 1.44 1.55 1.74 1.74 2.14 2.38
## 5 0.205 0.421 0.562 0.827 1.03 1.25 1.43 1.55 1.73 1.74 2.13 2.37
## 6 0.217 0.454 0.607 0.874 1.08 1.29 1.47 1.58 1.76 1.76 2.14 2.37
## # i 3 more variables: `25年` <lgl>, `30年` <dbl>, `40年` <lgl>
## JGB 2016~
jgb16 <- read_xlsx("jgbcm_all2016.xlsx")
jgb16[is.na(jgb16)] <- 0
jgb2016 <- jgb16[,-1]
head(jgb2016)
## # A tibble: 6 x 15
## `1年` `2年` `3年` `4年` `5年` `6年` `7年` `8年` `9年` `10年` `15年` `20年`
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 -0.042 -0.028 -0.014 0.003 0.026 0.036 0.059 0.12 0.186 0.264 0.599 0.986
## 2 -0.043 -0.03 -0.014 0.003 0.026 0.036 0.059 0.12 0.181 0.259 0.588 0.971
## 3 -0.044 -0.029 -0.014 0.002 0.022 0.032 0.055 0.115 0.176 0.253 0.583 0.967
## 4 -0.045 -0.028 -0.014 -0.003 0.016 0.027 0.049 0.11 0.171 0.245 0.573 0.958
## 5 -0.045 -0.031 -0.018 -0.003 0.016 0.022 0.039 0.101 0.161 0.23 0.557 0.939
## 6 -0.048 -0.028 -0.018 -0.003 0.017 0.016 0.034 0.097 0.157 0.221 0.548 0.93
## # i 3 more variables: `25年` <dbl>, `30年` <dbl>, `40年` <dbl>
### PCA analysis[multivariate analysis]
### PCA, (M)CA,FAMD,MFA,HCPC,factoextra
## Results
jgb_pca16 <- princomp((jgb2016),cor = TRUE)
summary(jgb_pca16)
## Importance of components:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Standard deviation 3.6682205 1.01380926 0.58014936 0.293227145 0.192111453
## Proportion of Variance 0.8970561 0.06852061 0.02243822 0.005732144 0.002460454
## Cumulative Proportion 0.8970561 0.96557673 0.98801495 0.993747092 0.996207546
## Comp.6 Comp.7 Comp.8 Comp.9
## Standard deviation 0.140859929 0.125726858 0.0908828194 0.0700280652
## Proportion of Variance 0.001322768 0.001053816 0.0005506458 0.0003269287
## Cumulative Proportion 0.997530314 0.998584130 0.9991347756 0.9994617043
## Comp.10 Comp.11 Comp.12 Comp.13
## Standard deviation 0.0576906263 0.04042214 0.0393639466 2.653498e-02
## Proportion of Variance 0.0002218806 0.00010893 0.0001033014 4.694033e-05
## Cumulative Proportion 0.9996835848 0.99979251 0.9998958162 9.999428e-01
## Comp.14 Comp.15
## Standard deviation 2.168769e-02 1.970524e-02
## Proportion of Variance 3.135706e-05 2.588643e-05
## Cumulative Proportion 9.999741e-01 1.000000e+00
biplot(jgb_pca16)

### compute standard deviation, variance, variance explained for each principal component
jgb_pca16$sdev
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7
## 3.66822051 1.01380926 0.58014936 0.29322714 0.19211145 0.14085993 0.12572686
## Comp.8 Comp.9 Comp.10 Comp.11 Comp.12 Comp.13 Comp.14
## 0.09088282 0.07002807 0.05769063 0.04042214 0.03936395 0.02653498 0.02168769
## Comp.15
## 0.01970524
jgb_pca16.var <- jgb_pca$sdev^2
jgb_pca16.var
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6
## 9.8804389838 2.4140452405 1.1371873041 0.5963342508 0.4385273645 0.2453697621
## Comp.7 Comp.8 Comp.9 Comp.10 Comp.11 Comp.12
## 0.1611650453 0.0656489261 0.0379970807 0.0160542429 0.0039613877 0.0020930411
## Comp.13 Comp.14 Comp.15
## 0.0007438953 0.0002430849 0.0001903903
###proportion of variance for screen plot
propve <- jgb_pca16.var/sum(jgb_pca16.var)
#plot variance explained for each p.c.
plot(propve, xlab = "principal component",
ylab = "proportion of variance explained",
ylim = c(0, 1), type = "b",
main = "screen plot")

factor.loadings <- jgb_pca16$loadings[,1:3]
legend.loadings <- c("パラレル", "ツイスト", "バタフライ")
par(xaxt="n")
matplot(factor.loadings,
lty = 1,
lwd = 2)

## JGB 2000~
jgb00 <- read_excel("jgbcm_all2000.xlsx")
jgb00[is.na(jgb00)] <- 0
jgb2000 <- jgb00[,-1]
head(jgb2000)
## # A tibble: 6 x 15
## `1年` `2年` `3年` `4年` `5年` `6年` `7年` `8年` `9年` `10年` `15年` `20年`
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 0.197 0.402 0.53 0.796 1.01 1.24 1.44 1.55 1.75 1.74 2.16 2.4
## 2 0.183 0.38 0.501 0.766 0.977 1.21 1.40 1.52 1.72 1.72 2.14 2.38
## 3 0.192 0.388 0.504 0.764 0.974 1.20 1.39 1.51 1.71 1.71 2.12 2.36
## 4 0.196 0.406 0.543 0.811 1.03 1.25 1.44 1.55 1.74 1.74 2.14 2.38
## 5 0.205 0.421 0.562 0.827 1.03 1.25 1.43 1.55 1.73 1.74 2.13 2.37
## 6 0.217 0.454 0.607 0.874 1.08 1.29 1.47 1.58 1.76 1.76 2.14 2.37
## # i 3 more variables: `25年` <lgl>, `30年` <dbl>, `40年` <lgl>
### PCA analysis[multivariate analysis]
### PCA, (M)CA,FAMD,MFA,HCPC,factoextra
## Results
jgb_pca00 <- princomp((jgb2000),cor = TRUE)
summary(jgb_pca00)
## Importance of components:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Standard deviation 3.5063502 1.2676669 0.85203009 0.51372530 0.279670035
## Proportion of Variance 0.8196328 0.1071320 0.04839702 0.01759425 0.005214355
## Cumulative Proportion 0.8196328 0.9267648 0.97516178 0.99275602 0.997970379
## Comp.6 Comp.7 Comp.8 Comp.9
## Standard deviation 0.125181924 0.0730934190 0.0581743993 0.0485624438
## Proportion of Variance 0.001044701 0.0003561765 0.0002256174 0.0001572207
## Cumulative Proportion 0.999015080 0.9993712563 0.9995968737 0.9997540944
## Comp.10 Comp.11 Comp.12 Comp.13
## Standard deviation 0.0405546375 3.079105e-02 2.275119e-02 1.527995e-02
## Proportion of Variance 0.0001096452 6.320592e-05 3.450779e-05 1.556512e-05
## Cumulative Proportion 0.9998637396 9.999269e-01 9.999615e-01 9.999770e-01
## Comp.14 Comp.15
## Standard deviation 1.404418e-02 1.214431e-02
## Proportion of Variance 1.314927e-05 9.832278e-06
## Cumulative Proportion 9.999902e-01 1.000000e+00
biplot(jgb_pca00)

### compute standard deviation, variance, variance explained for each principal component
jgb_pca00$sdev
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7
## 3.50635025 1.26766689 0.85203009 0.51372530 0.27967003 0.12518192 0.07309342
## Comp.8 Comp.9 Comp.10 Comp.11 Comp.12 Comp.13 Comp.14
## 0.05817440 0.04856244 0.04055464 0.03079105 0.02275119 0.01527995 0.01404418
## Comp.15
## 0.01214431
jgb_pca00.var <- jgb_pca$sdev^2
jgb_pca00.var
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6
## 9.8804389838 2.4140452405 1.1371873041 0.5963342508 0.4385273645 0.2453697621
## Comp.7 Comp.8 Comp.9 Comp.10 Comp.11 Comp.12
## 0.1611650453 0.0656489261 0.0379970807 0.0160542429 0.0039613877 0.0020930411
## Comp.13 Comp.14 Comp.15
## 0.0007438953 0.0002430849 0.0001903903
###proportion of variance for screen plot
propve_2 <- jgb_pca00.var/sum(jgb_pca00.var)
#plot variance explained for each p.c.
plot(propve_2, xlab = "principal component",
ylab = "proportion of variance explained",
ylim = c(0, 1), type = "b",
main = "screen plot")

factor.loadings <- jgb_pca00$loadings[,1:3]
legend.loadings <- c("パラレル", "ツイスト", "バタフライ")
par(xaxt="n")
matplot(factor.loadings,
lty = 1,
lwd = 2)
