Source Image: Analisis Peubah Ganda
library(readxl)
## Warning: package 'readxl' was built under R version 3.6.3
Jateng <- read_excel("F:/Semester 6/APG/Paper 1/data_fix.xlsx",
sheet = "Jateng")
Jatim <- read_excel("F:/Semester 6/APG/Paper 1/data_fix.xlsx",
sheet = "Jatim")
#Ringkasan Data
summary(Jateng)
## Dati2 L Un PPP
## Length:35 Min. :1.200 Min. :3.850 Min. :0.6670
## Class :character 1st Qu.:1.315 1st Qu.:4.860 1st Qu.:0.7665
## Mode :character Median :1.390 Median :6.070 Median :0.8130
## Mean :1.421 Mean :6.402 Mean :0.8273
## 3rd Qu.:1.515 3rd Qu.:7.500 3rd Qu.:0.9025
## Max. :1.690 Max. :9.830 Max. :1.0100
## Y
## Min. : 6.312
## 1st Qu.: 15.038
## Median : 20.563
## Mean : 27.545
## 3rd Qu.: 28.965
## Max. :137.610
summary(Jatim)
## Dati2 L Un PPP
## Length:38 Min. :1.150 Min. : 2.280 Min. :0.6300
## Class :character 1st Qu.:1.302 1st Qu.: 4.210 1st Qu.:0.7292
## Mode :character Median :1.345 Median : 5.185 Median :0.8010
## Mean :1.362 Mean : 5.624 Mean :0.8010
## 3rd Qu.:1.420 3rd Qu.: 6.593 3rd Qu.:0.8920
## Max. :1.560 Max. :10.970 Max. :0.9970
## Y
## Min. : 4.723
## 1st Qu.: 12.960
## Median : 22.416
## Mean : 42.550
## 3rd Qu.: 52.229
## Max. :390.936
#Analisis Deskriptif
library(GGally)
## Loading required package: ggplot2
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
plot2 <- ggpairs(Jateng[,c(2,3,4,5)],title = "Persebaran Data Jawa Tengah")
plot3<-ggpairs(Jatim[,c(2,3,4,5)],title = "Persebaran Data Jawa Timur")
plot2
plot3
#Analisis Deskriptif Lanjutan
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
pairs.panels(Jateng[,c(2,3,4,5)],
method = "pearson", # correlation method
hist.col = "grey",
density = TRUE, # show density plots
ellipses = TRUE, # show correlation ellipses
lm = FALSE)
#Pendefinisian Matriks
mJateng<-matrix(c(Jateng$L,Jateng$Un,Jateng$PPP,Jateng$Y),35,4)
mJateng
## [,1] [,2] [,3] [,4]
## [1,] 1.24 9.10 0.733 90.011584
## [2,] 1.36 6.00 0.779 39.121624
## [3,] 1.43 6.10 0.791 17.182874
## [4,] 1.35 5.86 0.909 15.045885
## [5,] 1.28 6.07 0.875 19.527665
## [6,] 1.31 4.04 0.751 13.138294
## [7,] 1.29 5.37 0.695 13.566176
## [8,] 1.39 4.27 0.863 22.865152
## [9,] 1.35 5.28 0.681 22.409733
## [10,] 1.46 5.46 0.719 27.480359
## [11,] 1.52 6.93 0.904 26.616503
## [12,] 1.31 4.27 0.809 20.563144
## [13,] 1.51 5.96 0.834 26.103228
## [14,] 1.42 4.75 0.792 26.367261
## [15,] 1.30 4.50 0.667 19.383027
## [16,] 1.28 4.89 0.776 17.483887
## [17,] 1.34 4.83 0.761 13.409631
## [18,] 1.32 4.74 0.823 30.527473
## [19,] 1.69 5.53 0.760 70.961748
## [20,] 1.66 6.70 0.675 20.973089
## [21,] 1.50 7.31 0.898 18.374562
## [22,] 1.45 4.57 0.779 34.688037
## [23,] 1.39 3.85 0.804 14.890755
## [24,] 1.39 7.56 0.822 30.449024
## [25,] 1.52 6.92 0.905 15.031084
## [26,] 1.59 6.97 0.837 16.047512
## [27,] 1.31 7.64 0.966 18.155597
## [28,] 1.39 9.82 0.934 24.492666
## [29,] 1.20 9.83 0.772 32.693081
## [30,] 1.47 8.59 0.968 6.312054
## [31,] 1.57 7.92 0.998 34.815965
## [32,] 1.52 7.44 0.901 9.503711
## [33,] 1.55 9.57 1.010 137.609712
## [34,] 1.55 7.02 0.813 7.337834
## [35,] 1.51 8.40 0.953 10.949122
mJatim<-matrix(c(Jatim$L,Jatim$Un,Jatim$PPP,Jatim$Y),38,4)
mJatim
## [,1] [,2] [,3] [,4]
## [1,] 1.32 2.28 0.790 10.83787
## [2,] 1.25 4.45 0.850 14.16862
## [3,] 1.22 4.11 0.750 12.50239
## [4,] 1.35 4.61 0.736 26.45576
## [5,] 1.34 3.82 0.831 24.94546
## [6,] 1.42 5.24 0.740 28.49095
## [7,] 1.42 5.49 0.838 66.54547
## [8,] 1.34 3.36 0.736 21.93379
## [9,] 1.35 5.12 0.677 52.58656
## [10,] 1.36 5.34 0.736 53.29511
## [11,] 1.28 4.13 0.677 13.45177
## [12,] 1.21 3.85 0.708 13.28284
## [13,] 1.36 4.86 0.711 22.89824
## [14,] 1.31 6.24 0.897 103.15280
## [15,] 1.48 10.97 0.997 135.30532
## [16,] 1.39 5.75 0.852 57.81842
## [17,] 1.37 7.48 0.802 27.65758
## [18,] 1.29 4.80 0.640 17.99036
## [19,] 1.28 4.80 0.698 12.93958
## [20,] 1.30 3.74 0.704 13.02089
## [21,] 1.33 5.44 0.630 13.47974
## [22,] 1.34 4.92 0.787 69.70342
## [23,] 1.29 4.81 0.766 42.70501
## [24,] 1.34 5.13 0.800 26.97265
## [25,] 1.49 8.21 0.886 97.61660
## [26,] 1.33 8.77 0.818 17.51462
## [27,] 1.15 3.35 0.680 13.95374
## [28,] 1.33 3.49 0.727 11.11762
## [29,] 1.21 2.84 0.894 23.54651
## [30,] 1.48 6.21 0.922 84.37498
## [31,] 1.46 6.68 0.900 4.72255
## [32,] 1.56 9.61 0.914 51.15453
## [33,] 1.44 6.70 0.896 8.03527
## [34,] 1.44 6.33 0.819 5.70660
## [35,] 1.42 6.74 0.925 4.80146
## [36,] 1.41 8.32 0.863 10.26244
## [37,] 1.54 9.79 0.911 390.93643
## [38,] 1.55 5.93 0.929 11.02581
#Uji kenormalan data metode chi-square
#Fungsi chi-square
grafikchi<-function(mdt){
#vektor rata-rata
mrata<-colMeans(mdt)
S2<-cov(mdt)
#membuat d-square
dsq<-apply(mdt, MARGIN = 1,function(mdt)+
t(mdt-mrata)%*%solve(S2)%*%(mdt-mrata))
#construct chi-square plot
par(mfrow=c(1,1))
plot(qchisq((1:nrow(mdt)-1/2)/nrow(mdt),df=2),sort(dsq),
xlab = expression(paste(chi[2]^2,"Quantile")),
ylab = "Ordered Squared of Distance",
main="Nama Provinsi"); abline(a=0, b=2)
print(sort(dsq))
}
grafikchi(mJateng)
## [1] 0.3738290 0.7110495 0.7348639 0.7909981 1.0564141 1.1049058
## [7] 1.1348372 1.1794805 1.4969739 1.7684214 1.7956675 1.8381286
## [13] 2.0497802 2.2738719 2.3359952 2.3470625 2.3612699 2.5226536
## [19] 2.6181990 2.6318006 2.7040330 2.7460052 2.9059850 3.2681216
## [25] 3.2986342 3.3942008 3.9221441 4.2022517 4.2703670 5.0043756
## [31] 10.0887178 10.9606906 11.4201563 13.0093353 21.6787796
grafikchi(mJatim)
## [1] 0.1306848 0.4636043 0.6031539 0.6830448 0.8009078 0.8731075
## [7] 1.0921019 1.2931583 1.5366289 1.5460471 1.7263504 1.7269109
## [13] 1.7413654 2.0128711 2.1228177 2.1712150 2.1871780 2.3144269
## [19] 2.4854371 2.5076199 2.6199573 2.7289604 2.8136065 3.0386027
## [25] 3.2912489 3.5872817 4.0385637 4.0530386 4.5277602 4.8246125
## [31] 5.2922892 5.3412483 6.0702400 8.4552138 8.5263677 9.1744219
## [37] 10.6890861 28.9088690
#Uji kenormalan data multivariate shapiro wilks
library(mvnormtest)
mshapiro.test(t(mJateng))
##
## Shapiro-Wilk normality test
##
## data: Z
## W = 0.66594, p-value = 1.147e-07
mshapiro.test(t(mJatim))
##
## Shapiro-Wilk normality test
##
## data: Z
## W = 0.54924, p-value = 1.263e-09
#Uji kesamaan varians 2 populasi
#Generalized Variance
GV1=det(var(mJateng))
GV2=det(var(mJatim))
GV1
## [1] 0.137199
GV2
## [1] 0.2710045
#Bartlet test
bartlet <- read_excel("F:/Semester 6/APG/Paper 1/Data Tugas 1 APG.xlsx", sheet = "Join")
head(bartlet)
## # A tibble: 6 x 7
## Dati2 L Un Y Pov PPP Prov
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Kab Cilacap 1.24 9.1 90.0 11.7 0.733 1
## 2 Kab Banyumas 1.36 6 39.1 13.7 0.779 1
## 3 Kab Purbalingga 1.43 6.1 17.2 16.2 0.791 1
## 4 Kab Banjarnegara 1.35 5.86 15.0 16.2 0.909 1
## 5 Kab Kebumen 1.28 6.07 19.5 17.8 0.875 1
## 6 Kab Purworejo 1.31 4.04 13.1 12.4 0.751 1
library(biotools)
## Loading required package: MASS
## Warning: package 'MASS' was built under R version 3.6.3
## ---
## biotools version 4.2
mbart<-matrix(c(bartlet$L,bartlet$Y,bartlet$Pov,bartlet$PPP,bartlet$Prov),73,5)
boxM(mbart[,1:4],mbart[,5])
##
## Box's M-test for Homogeneity of Covariance Matrices
##
## data: mbart[, 1:4]
## Chi-Sq (approx.) = 41.975, df = 10, p-value = 7.575e-06
#Uji Hipotesis
#Fungsi aproximasi
multvar<-function(mdt1, mdt2, Ho,alfa=0.05){
#populasi 1
n1<-nrow(mdt1)
p1<-ncol(mdt1)
#Membentuk vektor rata-rata sampel
xbar1=apply(mdt1, 2, mean)
varcovar1=cov(mdt1)
#populasi 2
n2<-nrow(mdt2)
p2<-ncol(mdt2)
#Membentuk vektor rata-rata sampel
xbar2=apply(mdt2, 2, mean)
varcovar2=cov(mdt2)
#T hotelling
Tsq<-t((xbar1-xbar2)-Ho)%*%solve((varcovar1/n1)+(varcovar2/n2))%*%((xbar1-xbar2)-Ho)
#wilayah kritis
chis<-qchisq(1-alfa,p1)
uji<-ifelse(Tsq>chis, "Tolak Ho","Gagal Tolak Ho")
hasil<-list(xbar1, varcovar1, xbar2, varcovar2,Tsq,chis,uji)
names(hasil)<-c("Vektor rata 1","matriks var-covar1","Vektor rata 2",
"matriks var-covar2","Statistik Uji","Chi Tabel","Keputusan")
return(hasil)
}
#Hipotesis nul
Ho=matrix(c(0,0,0,0),4,1)
multvar(mJateng, mJatim, Ho, alfa=0.01)
## $`Vektor rata 1`
## [1] 1.4205714 6.4017143 0.8273429 27.5454016
##
## $`matriks var-covar1`
## [,1] [,2] [,3] [,4]
## [1,] 0.014540840 0.03711958 0.003137151 0.3746293
## [2,] 0.037119580 2.97582050 0.086112630 15.0463194
## [3,] 0.003137151 0.08611263 0.008784291 0.2501230
## [4,] 0.374629262 15.04631944 0.250123048 632.8433727
##
## $`Vektor rata 2`
## [1] 1.3618421 5.6239474 0.8009737 42.5502568
##
## $`matriks var-covar2`
## [,1] [,2] [,3] [,4]
## [1,] 0.009372191 0.1407709 0.005827617 2.687376
## [2,] 0.140770910 4.0138840 0.116510107 67.636921
## [3,] 0.005827617 0.1165101 0.008882945 2.262313
## [4,] 2.687376198 67.6369212 2.262312842 4328.608388
##
## $`Statistik Uji`
## [,1]
## [1,] 12.46762
##
## $`Chi Tabel`
## [1] 13.2767
##
## $Keputusan
## [,1]
## [1,] "Gagal Tolak Ho"