Input Data

library(readxl)
data.indodapoer <- read_xlsx("C:/Users/BANGSIS-1/OneDrive/Documents/indodapoer300822.xlsx")

Source: https://databank.worldbank.org/source/indonesia-database-for-policy-and-economic-research#

Eksplorasi Data

colnames(data.indodapoer)
##  [1] "Provinces Name"                                                                             
##  [2] "Birth attended by Skilled Health worker (in % of total birth)"                              
##  [3] "Capital expenditure (in IDR)"                                                               
##  [4] "Education function expenditure (in IDR)"                                                    
##  [5] "Environment function expenditure (in IDR)"                                                  
##  [6] "Goods and services expenditure (in IDR)"                                                    
##  [7] "Health function expenditure (in IDR)"                                                       
##  [8] "Household Access to Electricity: Total (in % of total household)"                           
##  [9] "Household Access to safe Sanitation (in % of total Household)"                              
## [10] "Household Access to Safe Water (in % of total household)"                                   
## [11] "Household per capita expenditure (in IDR)"                                                  
## [12] "Literacy Rate for Population age 15 and over (in % of total population)"                    
## [13] "Monthly Per Capita Household Education Expenditure (in IDR)"                                
## [14] "Monthly Per Capita Household Health Expenditure (in IDR)"                                   
## [15] "Monthly Per Capita TOTAL Household Expenditure for The Poorest 20 percent (in IDR)"         
## [16] "Morbidity Rate (in %)"                                                                      
## [17] "Net Enrollment Ratio: Junior Secondary (in %)"                                              
## [18] "Net Enrollment Ratio: Primary (in %)"                                                       
## [19] "Net Enrollment Ratio: Senior Secondary (in %)"                                              
## [20] "Others expenditure (in IDR)"                                                                
## [21] "Personnel expenditure (in IDR)"                                                             
## [22] "Public, law and order function expenditure (in IDR)"                                        
## [23] "Total Expenditure (in IDR)"                                                                 
## [24] "Total General Allocation Grant/DAU (in IDR)"                                                
## [25] "Total Natural Resources Revenue Sharing from Fishery (in IDR, realization value)"           
## [26] "Total Natural Resources Revenue Sharing from Forestry (in IDR, realization value)"          
## [27] "Total Natural Resources Revenue Sharing from Gas (in IDR, realization value)"               
## [28] "Total Natural Resources Revenue Sharing from Geothermal  Energy (in IDR, realization value)"
## [29] "Total Natural Resources Revenue Sharing from Mining (in IDR, realization value)"            
## [30] "Total Natural Resources Revenue Sharing from Oil (in IDR, realization value)"               
## [31] "Total Other Revenue (in IDR)"                                                               
## [32] "Total Own Source Revenue/PAD (in IDR)"                                                      
## [33] "Total Population (in number of people)"                                                     
## [34] "Total Revenue (in IDR)"                                                                     
## [35] "Total Revenue Sharing"                                                                      
## [36] "Total Special Allocation Grant/DAK (in IDR)"                                                
## [37] "Total Tax Revenue Sharing from income tax (PPh) (in IDR, realization value)"                
## [38] "Total Tax Revenue Sharing from land and building tax (PBB) (in IDR, realization value)"     
## [39] "Tourism and culture function expenditure (in IDR)"
dim(data.indodapoer)
## [1] 34 39
View(data.indodapoer)
str(data.indodapoer)
## tibble [34 x 39] (S3: tbl_df/tbl/data.frame)
##  $ Provinces Name                                                                             : chr [1:34] "Bali" "Banten" "Bengkulu" "DI Yogyakarta" ...
##  $ Birth attended by Skilled Health worker (in % of total birth)                              : num [1:34] 99.7 91.8 97.8 100 99.3 ...
##  $ Capital expenditure (in IDR)                                                               : num [1:34] 4.58e+11 9.94e+11 4.17e+11 9.41e+11 3.17e+12 ...
##  $ Education function expenditure (in IDR)                                                    : num [1:34] 1.90e+12 4.30e+12 1.15e+12 1.75e+12 1.46e+13 ...
##  $ Environment function expenditure (in IDR)                                                  : num [1:34] 0.00 4.00e+10 3.91e+10 4.41e+10 2.75e+12 ...
##  $ Goods and services expenditure (in IDR)                                                    : num [1:34] 1.55e+12 2.18e+12 5.59e+11 7.83e+11 1.68e+13 ...
##  $ Health function expenditure (in IDR)                                                       : num [1:34] 4.21e+11 6.87e+11 3.29e+11 1.77e+11 9.39e+12 ...
##  $ Household Access to Electricity: Total (in % of total household)                           : num [1:34] 99.9 99.8 99 99.9 100 ...
##  $ Household Access to safe Sanitation (in % of total Household)                              : num [1:34] 82.9 84.7 85.7 80.5 84.4 ...
##  $ Household Access to Safe Water (in % of total household)                                   : num [1:34] 88.4 72.5 52.3 79.9 92.8 ...
##  $ Household per capita expenditure (in IDR)                                                  : num [1:34] 1509675 1517042 1140076 1411985 2257984 ...
##  $ Literacy Rate for Population age 15 and over (in % of total population)                    : num [1:34] 96.1 100 99.9 96.3 100.6 ...
##  $ Monthly Per Capita Household Education Expenditure (in IDR)                                : num [1:34] 75472 64586 53109 120990 121808 ...
##  $ Monthly Per Capita Household Health Expenditure (in IDR)                                   : num [1:34] 45464 32213 29649 57555 54800 ...
##  $ Monthly Per Capita TOTAL Household Expenditure for The Poorest 20 percent (in IDR)         : num [1:34] 520473 557254 473963 428572 795473 ...
##  $ Morbidity Rate (in %)                                                                      : num [1:34] 25.5 32.2 30.2 38.1 33.8 ...
##  $ Net Enrollment Ratio: Junior Secondary (in %)                                              : num [1:34] 92.9 89.3 78.5 86 84.3 ...
##  $ Net Enrollment Ratio: Primary (in %)                                                       : num [1:34] 95.4 95 100.6 98 103.6 ...
##  $ Net Enrollment Ratio: Senior Secondary (in %)                                              : num [1:34] 71.6 61 68.6 71.9 60.8 ...
##  $ Others expenditure (in IDR)                                                                : num [1:34] 2.75e+12 4.80e+12 6.56e+11 2.15e+12 1.55e+13 ...
##  $ Personnel expenditure (in IDR)                                                             : num [1:34] 1.60e+12 1.91e+12 1.07e+12 1.56e+12 1.67e+13 ...
##  $ Public, law and order function expenditure (in IDR)                                        : num [1:34] 4.89e+10 6.02e+10 4.79e+10 4.40e+10 1.49e+12 ...
##  $ Total Expenditure (in IDR)                                                                 : num [1:34] 6.36e+12 9.88e+12 2.70e+12 5.43e+12 5.21e+13 ...
##  $ Total General Allocation Grant/DAU (in IDR)                                                : num [1:34] 1.20e+12 1.04e+12 1.22e+12 1.23e+12 0.00 ...
##  $ Total Natural Resources Revenue Sharing from Fishery (in IDR, realization value)           : num [1:34] 0.00 0.00 0.00 0.00 1.33e+09 ...
##  $ Total Natural Resources Revenue Sharing from Forestry (in IDR, realization value)          : num [1:34] 0.00 1.67e+08 4.08e+08 1.43e+07 1.08e+06 ...
##  $ Total Natural Resources Revenue Sharing from Gas (in IDR, realization value)               : num [1:34] 0.00 0.00 0.00 0.00 1.26e+10 ...
##  $ Total Natural Resources Revenue Sharing from Geothermal  Energy (in IDR, realization value): num [1:34] 0.00 4.69e+08 2.80e+08 0.00 0.00 ...
##  $ Total Natural Resources Revenue Sharing from Mining (in IDR, realization value)            : num [1:34] 0.00 2.50e+09 2.82e+10 1.61e+07 0.00 ...
##  $ Total Natural Resources Revenue Sharing from Oil (in IDR, realization value)               : num [1:34] 0.00 0.00 0.00 0.00 6.69e+10 ...
##  $ Total Other Revenue (in IDR)                                                               : num [1:34] 8.45e+10 5.25e+10 5.50e+10 1.36e+12 1.57e+12 ...
##  $ Total Own Source Revenue/PAD (in IDR)                                                      : num [1:34] 3.07e+12 5.91e+12 7.12e+11 1.88e+12 3.74e+13 ...
##  $ Total Population (in number of people)                                                     : num [1:34] 4380824 13160496 2019848 3882288 10644986 ...
##  $ Total Revenue (in IDR)                                                                     : num [1:34] 5.72e+12 1.03e+13 2.79e+12 5.61e+12 5.59e+13 ...
##  $ Total Revenue Sharing                                                                      : num [1:34] 2.07e+11 7.02e+11 7.11e+10 1.14e+11 1.36e+13 ...
##  $ Total Special Allocation Grant/DAK (in IDR)                                                : num [1:34] 1.15e+12 2.63e+12 7.29e+11 1.03e+12 3.25e+12 ...
##  $ Total Tax Revenue Sharing from income tax (PPh) (in IDR, realization value)                : num [1:34] 2.02e+11 6.91e+11 3.87e+10 1.11e+11 1.39e+13 ...
##  $ Total Tax Revenue Sharing from land and building tax (PBB) (in IDR, realization value)     : num [1:34] 2.17e+09 7.27e+09 5.42e+09 1.70e+09 5.79e+10 ...
##  $ Tourism and culture function expenditure (in IDR)                                          : num [1:34] 5.87e+10 2.16e+10 1.22e+10 3.13e+11 3.30e+11 ...
summary(data.indodapoer)
##  Provinces Name    
##  Length:34         
##  Class :character  
##  Mode  :character  
##                    
##                    
##                    
##                    
##  Birth attended by Skilled Health worker (in % of total birth)
##  Min.   : 68.40                                               
##  1st Qu.: 92.11                                               
##  Median : 96.11                                               
##  Mean   : 93.48                                               
##  3rd Qu.: 97.95                                               
##  Max.   :100.00                                               
##                                                               
##  Capital expenditure (in IDR) Education function expenditure (in IDR)
##  Min.   :1.998e+11            Min.   :5.113e+11                      
##  1st Qu.:6.169e+11            1st Qu.:1.337e+12                      
##  Median :8.792e+11            Median :1.876e+12                      
##  Mean   :9.899e+11            Mean   :3.339e+12                      
##  3rd Qu.:1.104e+12            3rd Qu.:3.333e+12                      
##  Max.   :3.173e+12            Max.   :1.519e+13                      
##                                                                      
##  Environment function expenditure (in IDR)
##  Min.   :0.000e+00                        
##  1st Qu.:9.675e+09                        
##  Median :1.619e+10                        
##  Mean   :1.289e+11                        
##  3rd Qu.:3.987e+10                        
##  Max.   :2.754e+12                        
##                                           
##  Goods and services expenditure (in IDR) Health function expenditure (in IDR)
##  Min.   :3.461e+11                       Min.   :1.140e+11                   
##  1st Qu.:7.520e+11                       1st Qu.:3.795e+11                   
##  Median :1.295e+12                       Median :5.215e+11                   
##  Mean   :2.094e+12                       Mean   :1.015e+12                   
##  3rd Qu.:2.081e+12                       3rd Qu.:9.592e+11                   
##  Max.   :1.678e+13                       Max.   :9.390e+12                   
##                                                                              
##  Household Access to Electricity: Total (in % of total household)
##  Min.   : 73.83                                                  
##  1st Qu.: 98.68                                                  
##  Median : 99.26                                                  
##  Mean   : 97.79                                                  
##  3rd Qu.: 99.71                                                  
##  Max.   :100.00                                                  
##                                                                  
##  Household Access to safe Sanitation (in % of total Household)
##  Min.   :61.74                                                
##  1st Qu.:76.27                                                
##  Median :82.33                                                
##  Mean   :80.92                                                
##  3rd Qu.:85.49                                                
##  Max.   :93.55                                                
##                                                               
##  Household Access to Safe Water (in % of total household)
##  Min.   :37.22                                           
##  1st Qu.:67.07                                           
##  Median :74.05                                           
##  Mean   :73.20                                           
##  3rd Qu.:80.47                                           
##  Max.   :93.41                                           
##                                                          
##  Household per capita expenditure (in IDR)
##  Min.   : 794365                          
##  1st Qu.:1065363                          
##  Median :1133381                          
##  Mean   :1252580                          
##  3rd Qu.:1381392                          
##  Max.   :2257984                          
##                                           
##  Literacy Rate for Population age 15 and over (in % of total population)
##  Min.   : 79.04                                                         
##  1st Qu.: 96.17                                                         
##  Median :100.09                                                         
##  Mean   : 98.22                                                         
##  3rd Qu.:100.63                                                         
##  Max.   :102.12                                                         
##                                                                         
##  Monthly Per Capita Household Education Expenditure (in IDR)
##  Min.   : 25683                                             
##  1st Qu.: 33884                                             
##  Median : 41576                                             
##  Mean   : 49883                                             
##  3rd Qu.: 55463                                             
##  Max.   :121808                                             
##                                                             
##  Monthly Per Capita Household Health Expenditure (in IDR)
##  Min.   :13379                                           
##  1st Qu.:20397                                           
##  Median :27078                                           
##  Mean   :28673                                           
##  3rd Qu.:35134                                           
##  Max.   :57555                                           
##                                                          
##  Monthly Per Capita TOTAL Household Expenditure for The Poorest 20 percent (in IDR)
##  Min.   :305599                                                                    
##  1st Qu.:397088                                                                    
##  Median :459221                                                                    
##  Mean   :487203                                                                    
##  3rd Qu.:557323                                                                    
##  Max.   :797480                                                                    
##                                                                                    
##  Morbidity Rate (in %) Net Enrollment Ratio: Junior Secondary (in %)
##  Min.   :15.97         Min.   :55.50                                
##  1st Qu.:25.10         1st Qu.:71.93                                
##  Median :28.02         Median :78.48                                
##  Mean   :28.10         Mean   :78.15                                
##  3rd Qu.:32.16         3rd Qu.:82.64                                
##  Max.   :44.00         Max.   :97.76                                
##                                                                     
##  Net Enrollment Ratio: Primary (in %)
##  Min.   : 81.16                      
##  1st Qu.: 96.15                      
##  Median : 98.79                      
##  Mean   : 98.05                      
##  3rd Qu.:100.53                      
##  Max.   :103.60                      
##                                      
##  Net Enrollment Ratio: Senior Secondary (in %) Others expenditure (in IDR)
##  Min.   :41.30                                 Min.   :5.363e+11          
##  1st Qu.:60.89                                 1st Qu.:1.217e+12          
##  Median :64.85                                 Median :2.329e+12          
##  Mean   :64.14                                 Mean   :4.343e+12          
##  3rd Qu.:68.50                                 3rd Qu.:4.771e+12          
##  Max.   :78.17                                 Max.   :2.556e+13          
##                                                                           
##  Personnel expenditure (in IDR)
##  Min.   :5.266e+11             
##  1st Qu.:1.098e+12             
##  Median :1.541e+12             
##  Mean   :2.444e+12             
##  3rd Qu.:2.128e+12             
##  Max.   :1.669e+13             
##                                
##  Public, law and order function expenditure (in IDR) Total Expenditure (in IDR)
##  Min.   :1.176e+10                                   Min.   :1.805e+12         
##  1st Qu.:3.150e+10                                   1st Qu.:4.219e+12         
##  Median :4.193e+10                                   Median :6.119e+12         
##  Mean   :8.554e+10                                   Mean   :9.871e+12         
##  3rd Qu.:4.990e+10                                   3rd Qu.:9.846e+12         
##  Max.   :1.491e+12                                   Max.   :5.209e+13         
##                                                                                
##  Total General Allocation Grant/DAU (in IDR)
##  Min.   :0.000e+00                          
##  1st Qu.:1.126e+12                          
##  Median :1.436e+12                          
##  Mean   :1.567e+12                          
##  3rd Qu.:1.728e+12                          
##  Max.   :3.663e+12                          
##                                             
##  Total Natural Resources Revenue Sharing from Fishery (in IDR, realization value)
##  Min.   :0.000e+00                                                               
##  1st Qu.:0.000e+00                                                               
##  Median :0.000e+00                                                               
##  Mean   :4.021e+07                                                               
##  3rd Qu.:0.000e+00                                                               
##  Max.   :1.327e+09                                                               
##  NA's   :1                                                                       
##  Total Natural Resources Revenue Sharing from Forestry (in IDR, realization value)
##  Min.   :0.000e+00                                                                
##  1st Qu.:3.494e+08                                                                
##  Median :2.360e+09                                                                
##  Mean   :1.934e+10                                                                
##  3rd Qu.:1.062e+10                                                                
##  Max.   :1.590e+11                                                                
##  NA's   :1                                                                        
##  Total Natural Resources Revenue Sharing from Gas (in IDR, realization value)
##  Min.   :0.000e+00                                                           
##  1st Qu.:0.000e+00                                                           
##  Median :0.000e+00                                                           
##  Mean   :1.028e+11                                                           
##  3rd Qu.:1.547e+10                                                           
##  Max.   :1.641e+12                                                           
##  NA's   :1                                                                   
##  Total Natural Resources Revenue Sharing from Geothermal  Energy (in IDR, realization value)
##  Min.   :0.000e+00                                                                          
##  1st Qu.:0.000e+00                                                                          
##  Median :0.000e+00                                                                          
##  Mean   :1.126e+10                                                                          
##  3rd Qu.:5.851e+08                                                                          
##  Max.   :3.538e+11                                                                          
##  NA's   :1                                                                                  
##  Total Natural Resources Revenue Sharing from Mining (in IDR, realization value)
##  Min.   :0.000e+00                                                              
##  1st Qu.:4.316e+09                                                              
##  Median :2.851e+10                                                              
##  Mean   :1.668e+11                                                              
##  3rd Qu.:8.306e+10                                                              
##  Max.   :2.340e+12                                                              
##  NA's   :1                                                                      
##  Total Natural Resources Revenue Sharing from Oil (in IDR, realization value)
##  Min.   :0.000e+00                                                           
##  1st Qu.:0.000e+00                                                           
##  Median :9.535e+08                                                           
##  Mean   :7.621e+10                                                           
##  3rd Qu.:4.803e+10                                                           
##  Max.   :1.024e+12                                                           
##  NA's   :1                                                                   
##  Total Other Revenue (in IDR) Total Own Source Revenue/PAD (in IDR)
##  Min.   :1.207e+09            Min.   :3.469e+11                    
##  1st Qu.:3.895e+10            1st Qu.:1.044e+12                    
##  Median :8.219e+10            Median :1.846e+12                    
##  Mean   :7.709e+11            Mean   :4.374e+12                    
##  3rd Qu.:1.219e+11            3rd Qu.:3.365e+12                    
##  Max.   :8.005e+12            Max.   :3.741e+13                    
##                                                                    
##  Total Population (in number of people) Total Revenue (in IDR)
##  Min.   :  768505                       Min.   :1.863e+12     
##  1st Qu.: 2313847                       1st Qu.:3.771e+12     
##  Median : 4093134                       Median :5.692e+12     
##  Mean   : 7972540                       Mean   :9.801e+12     
##  3rd Qu.: 8172977                       3rd Qu.:9.941e+12     
##  Max.   :49935858                       Max.   :5.589e+13     
##                                                               
##  Total Revenue Sharing Total Special Allocation Grant/DAK (in IDR)
##  Min.   :1.626e+10     Min.   :3.740e+11                          
##  1st Qu.:1.480e+11     1st Qu.:7.230e+11                          
##  Median :3.094e+11     Median :1.135e+12                          
##  Mean   :1.065e+12     Mean   :2.024e+12                          
##  3rd Qu.:8.206e+11     3rd Qu.:2.251e+12                          
##  Max.   :1.365e+13     Max.   :1.085e+13                          
##                                                                   
##  Total Tax Revenue Sharing from income tax (PPh) (in IDR, realization value)
##  Min.   :1.389e+10                                                          
##  1st Qu.:4.729e+10                                                          
##  Median :1.034e+11                                                          
##  Mean   :6.109e+11                                                          
##  3rd Qu.:2.194e+11                                                          
##  Max.   :1.387e+13                                                          
##                                                                             
##  Total Tax Revenue Sharing from land and building tax (PBB) (in IDR, realization value)
##  Min.   :1.696e+09                                                                     
##  1st Qu.:9.058e+09                                                                     
##  Median :2.940e+10                                                                     
##  Mean   :7.019e+10                                                                     
##  3rd Qu.:5.946e+10                                                                     
##  Max.   :5.251e+11                                                                     
##                                                                                        
##  Tourism and culture function expenditure (in IDR)
##  Min.   :0.000e+00                                
##  1st Qu.:1.505e+10                                
##  Median :2.425e+10                                
##  Mean   :4.724e+10                                
##  3rd Qu.:4.437e+10                                
##  Max.   :3.297e+11                                
## 

1. Histogram

hist(data.indodapoer$`Household per capita expenditure (in IDR)`, breaks = 25, col = "coral",
     xlab = "Household per capita expenditure (in IDR)",
     main = "Household per capita expenditure Distribution (in IDR)")

2. Boxplot

boxplot(data.indodapoer$`Household per capita expenditure (in IDR)`, horizontal = TRUE, col = 'coral', xlab="Household per capita expenditure (in IDR)")

3. Density Plot (Naïve and Kernel)

3.1. Naïve Estimator

pengeluaranperkapita <- data.indodapoer$`Household per capita expenditure (in IDR)`
hist(pengeluaranperkapita, breaks= 25, col = "coral",
     xlab= "Household per capita expenditure (in IDR)",
     main = "",
     freq = FALSE)

h = 100000
n = length(pengeluaranperkapita)
x <- seq(0, 3000000, by=10000)
fx <- NULL
for (i in 1:length(x)) {
  fx[i] = sum(ifelse(abs(pengeluaranperkapita - x[i]) < h, 1, 0))/(2*h*n)
}
lines(x, fx, type="l", col="blue", lwd=2)

3.2. Kernel Estimator

dense <- density(data.indodapoer$`Household per capita expenditure (in IDR)`, bw=100000, kernel="epanechnikov")

hist(data.indodapoer$`Household per capita expenditure (in IDR)`, freq = FALSE, breaks = 100, col = "skyblue1", main = "", xlab = "Household per capita expenditure (in IDR)")

lines(dense, col="blue", lwd=2, main="", ylim=c(0, 0.000006))

4. Pie Chart

Eksplorasi Data Kategorik

mean(data.indodapoer$`Household per capita expenditure (in IDR)`)
## [1] 1252579
expenditure_above_mean <- ifelse(data.indodapoer$`Household per capita expenditure (in IDR)` > 1252579, "Yes","No")
table(expenditure_above_mean)
## expenditure_above_mean
##  No Yes 
##  20  14
frekuensi <- table(expenditure_above_mean)
prop.table(frekuensi)
## expenditure_above_mean
##        No       Yes 
## 0.5882353 0.4117647
pie(frekuensi)

5. Bar Chart

barplot(frekuensi)

6. Scatter Plot

plot(data.indodapoer$`Household per capita expenditure (in IDR)`, data.indodapoer$`Household Access to Electricity: Total (in % of total household)`, ylab="Household per capita expenditure (in IDR)",
     xlab = "Household Access to Electricity: Total (in % of total household)",
     pch = 19, cex = 1.5,
     col=ifelse(data.indodapoer$`Household per capita expenditure (in IDR)` > 
                  1252579, "coral", "navyblue"))

7. Matrix Correlation

library(PerformanceAnalytics)
## Warning: package 'PerformanceAnalytics' was built under R version 4.1.3
## Loading required package: xts
## Warning: package 'xts' was built under R version 4.1.3
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
chart.Correlation(data.indodapoer[,3:7], histogram = TRUE, pch= 19)

pairs(data.indodapoer[,3:7], pch=19, col="coral", cex=1.5)

8. Bubble Plot

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.2 --
## v ggplot2 3.3.6     v purrr   0.3.4
## v tibble  3.1.6     v dplyr   1.0.9
## v tidyr   1.2.0     v stringr 1.4.0
## v readr   2.1.2     v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.1.3
## Warning: package 'dplyr' was built under R version 4.1.3
## Warning: package 'stringr' was built under R version 4.1.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::first()  masks xts::first()
## x dplyr::lag()    masks stats::lag()
## x dplyr::last()   masks xts::last()
library(hrbrthemes)
## Warning: package 'hrbrthemes' was built under R version 4.1.3
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
##       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
##       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
library(viridis)
## Warning: package 'viridis' was built under R version 4.1.3
## Loading required package: viridisLite
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     combine
library(ggplot2)
pengeluaran <- data.indodapoer$`Household per capita expenditure (in IDR)`
data.indodapoer %>%
  mutate(pengeluaran = pengeluaran/1000) %>%
  arrange(desc(pengeluaran)) %>%
  mutate(country = factor(`Provinces Name`, `Provinces Name`)) %>%
  ggplot( aes(x=`Household Access to safe Sanitation (in % of total Household)`, y=`Household Access to Safe Water (in % of total household)`, size = data.indodapoer$`Household per capita expenditure (in IDR)`, color = `Provinces Name`)) +
    geom_point(alpha=0.7) +
    scale_size(range = c(1.4, 19), name="Pengeluaran") +
    scale_color_viridis(discrete=TRUE, guide="none") +
    theme_ipsum() +
    theme(legend.position="bottom")
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database

## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

9. Local Regression

library(readxl)
data.indodapoer.jabar <- read_xlsx("C:/Users/BANGSIS-1/Downloads/data_indodapoer_jabar.xlsx")
pengeluaran <- data.indodapoer.jabar$`Household per capita expenditure (in IDR)`
data.indodapoer.jabar$index <- 1:nrow(data.indodapoer.jabar)  # create index variable
loessMod10 <- loess(pengeluaran ~ index, data=data.indodapoer.jabar, span=0.10) # 10% smoothing span
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.885
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.115
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.2432
loessMod25 <- loess(pengeluaran ~ index, data=data.indodapoer.jabar, span=0.25) # 25% smoothing span
loessMod50 <- loess(pengeluaran ~ index, data=data.indodapoer.jabar, span=0.50) # 50% smoothing span
smoothed10 <- predict(loessMod10) 
smoothed25 <- predict(loessMod25) 
smoothed50 <- predict(loessMod50)
plot(pengeluaran, x=data.indodapoer.jabar$`Series Name`, type="l", main="Loess Smoothing and Prediction", xlab="Year ", ylab="Household per capita expenditure (in IDR)")

lines(smoothed10, x=data.indodapoer.jabar$`Series Name`, col="red")

lines(smoothed25, x=data.indodapoer.jabar$`Series Name`, col="green")

lines(smoothed50, x=data.indodapoer.jabar$`Series Name`, col="blue")

legend('bottomright', legend=c('.1', '.25', '.5'),
        col=c('red', 'green', 'blue'), pch=19, title='Smoothing Span')


  1. Statistika dan Sains Data, IPB University, ↩︎