Canonical Corelation (cca) merupakan metode korelasi untuk dua dataset
library(CCA)
## Warning: package 'CCA' was built under R version 4.3.3
## Loading required package: fda
## Loading required package: splines
## Loading required package: fds
## Warning: package 'fds' was built under R version 4.3.3
## Loading required package: rainbow
## Warning: package 'rainbow' was built under R version 4.3.3
## Loading required package: MASS
## Loading required package: pcaPP
## Warning: package 'pcaPP' was built under R version 4.3.3
## Loading required package: RCurl
## Warning: package 'RCurl' was built under R version 4.3.3
## Loading required package: deSolve
## Warning: package 'deSolve' was built under R version 4.3.3
##
## Attaching package: 'fda'
## The following object is masked from 'package:graphics':
##
## matplot
## Loading required package: fields
## Warning: package 'fields' was built under R version 4.3.3
## Loading required package: spam
## Warning: package 'spam' was built under R version 4.3.3
## Spam version 2.11-1 (2025-01-20) is loaded.
## Type 'help( Spam)' or 'demo( spam)' for a short introduction
## and overview of this package.
## Help for individual functions is also obtained by adding the
## suffix '.spam' to the function name, e.g. 'help( chol.spam)'.
##
## Attaching package: 'spam'
## The following objects are masked from 'package:base':
##
## backsolve, forwardsolve
## Loading required package: viridisLite
##
## Try help(fields) to get started.
library(CCP)
library(readr)
## Warning: package 'readr' was built under R version 4.3.3
library(readxl)
## Warning: package 'readxl' was built under R version 4.3.2
data yang digunkan merupakan data pdrb, pad, dau,jumlah penduduk, biaya rutin dan biaya modal provinsi indonesia data diambil dari:
https://sulut.bps.go.id/id/statistics-table/2/OTU4IzI=/jumlah-penduduk-menurut-provinsi-di-indonesia.html https://djpk.kemenkeu.go.id/portal/data/apbd?periode=12&tahun=2024&provinsi=32&pemda=00 https://djpk.kemenkeu.go.id/wp-content/uploads/2023/09/Rincian-Alokasi-DAU-DBH-TA-2024.pdf
dat=read_excel("kmsv2.xlsx")
data dibagi menjadi variabel pemasukan (pdrb, pad, dau) dan variabel pengeluaran (jumlah peduduk, biaya rutin, biaya modal)
tunel=dat[c("pdrb","pad","DAU")]
chungus=dat[c("penduduk","boperasi","belanjamodal")]
chese <- cc(tunel, chungus)
chese$cor
## [1] 0.9969015 0.8625324 0.3096998
chese[3:4]
## $xcoef
## [,1] [,2] [,3]
## pdrb 2.367680e-09 -4.195291e-06 2.459547e-05
## pad 9.575304e-05 -2.142610e-05 -1.192806e-04
## DAU 1.669328e-10 9.758376e-10 1.212904e-09
##
## $ycoef
## [,1] [,2] [,3]
## penduduk 2.992883e-05 8.531396e-05 7.719211e-05
## boperasi 6.650048e-05 -4.567455e-05 -2.785542e-04
## belanjamodal 5.906648e-05 -1.608549e-04 1.359805e-03
gage <- as.data.frame(chese$scores$xscores)
mbt <- as.data.frame(chese$scores$yscores)
n <- nrow(tunel)
p <- ncol(tunel)
q <- ncol(chungus)
pea <- p.asym(chese$cor, n, p, q, tstat = "Wilks")
## Wilks' Lambda, using F-approximation (Rao's F):
## stat approx df1 df2 p.value
## 1 to 3: 0.001432253 104.281467 9 68.29525 0.000000e+00
## 2 to 3: 0.231480191 15.637768 4 58.00000 9.791640e-09
## 3 to 3: 0.904086022 3.182683 1 30.00000 8.454143e-02
loadings_health <- cor(tunel, gage)
loadings_mental <- cor(chungus, mbt)
plot(gage[,1], mbt[,1],
xlab = "pemasukan Canonical Variate 1",
ylab = "pengeluaran Canonical Variate 1",
main = "Canonical Correlation between pemasukan and pengeluaran")