Lembaga = Universitas Islam Negeri Maulana Malik Ibrahim Malang
Jurusan = Teknik Informatika
library(readxl)
datamobility <- read_excel(path = "DataCovid19 DKI Jakarta.xlsx")
datamobility
## # A tibble: 31 x 12
## Tanggal retail_and_recreation_~ grocery_and_pha~ parks_percent_c~
## <dttm> <dbl> <dbl> <dbl>
## 1 2022-01-01 00:00:00 3 24 46
## 2 2022-01-02 00:00:00 11 35 28
## 3 2022-01-03 00:00:00 14 36 20
## 4 2022-01-04 00:00:00 11 33 15
## 5 2022-01-05 00:00:00 12 34 17
## 6 2022-01-06 00:00:00 10 30 12
## 7 2022-01-07 00:00:00 6 25 6
## 8 2022-01-08 00:00:00 8 31 10
## 9 2022-01-09 00:00:00 7 28 13
## 10 2022-01-10 00:00:00 7 27 6
## # ... with 21 more rows, and 8 more variables:
## # transit_stations_percent_change_from_baseline <dbl>,
## # workplaces_percent_change_from_baseline <dbl>,
## # residential_percent_change_from_baseline <dbl>, POSITIF <dbl>,
## # Dirawat <dbl>, Sembuh <dbl>, Meninggal <dbl>, SelfIsolation <dbl>
summary(datamobility)
## Tanggal
## Min. :2022-01-01 00:00:00
## 1st Qu.:2022-01-08 12:00:00
## Median :2022-01-16 00:00:00
## Mean :2022-01-16 00:00:00
## 3rd Qu.:2022-01-23 12:00:00
## Max. :2022-01-31 00:00:00
## retail_and_recreation_percent_change_from_baseline
## Min. : 1.000
## 1st Qu.: 6.000
## Median : 7.000
## Mean : 7.452
## 3rd Qu.: 9.000
## Max. :14.000
## grocery_and_pharmacy_percent_change_from_baseline
## Min. :20.00
## 1st Qu.:25.00
## Median :26.00
## Mean :27.55
## 3rd Qu.:29.50
## Max. :36.00
## parks_percent_change_from_baseline
## Min. :-1.00
## 1st Qu.: 5.50
## Median : 9.00
## Mean :10.94
## 3rd Qu.:14.00
## Max. :46.00
## transit_stations_percent_change_from_baseline
## Min. :-17.00
## 1st Qu.:-15.00
## Median :-14.00
## Mean :-12.65
## 3rd Qu.:-10.00
## Max. : -4.00
## workplaces_percent_change_from_baseline
## Min. :-49.000
## 1st Qu.: -4.000
## Median : 0.000
## Mean : -1.677
## 3rd Qu.: 3.000
## Max. : 8.000
## residential_percent_change_from_baseline POSITIF Dirawat
## Min. :3.000 Min. :865415 Min. : 116
## 1st Qu.:4.500 1st Qu.:867106 1st Qu.: 278
## Median :5.000 Median :870929 Median : 781
## Mean :5.258 Mean :876297 Mean :1635
## 3rd Qu.:6.000 3rd Qu.:880304 3rd Qu.:2126
## Max. :7.000 Max. :913355 Max. :6809
## Sembuh Meninggal SelfIsolation
## Min. :851280 Min. :13588 Min. : 342
## 1st Qu.:851783 1st Qu.:13589 1st Qu.: 1456
## Median :853522 Median :13591 Median : 3035
## Mean :855268 Mean :13598 Mean : 5749
## 3rd Qu.:856934 3rd Qu.:13597 3rd Qu.: 7646
## Max. :867519 Max. :13666 Max. :25361
pairs(datamobility)
pairs(datamobility, lower.panel=NULL)
plot(datamobility$SelfIsolation ~ datamobility$Tanggal, data = datamobility)
plot(datamobility$SelfIsolation ~ datamobility$
retail_and_recreation_percent_change_from_baseline+datamobility$
grocery_and_pharmacy_percent_change_from_baseline+datamobility$
parks_percent_change_from_baseline+datamobility$
transit_stations_percent_change_from_baseline+datamobility$
workplaces_percent_change_from_baseline+datamobility$
residential_percent_change_from_baseline, data = datamobility)
cor(datamobility$SelfIsolation,datamobility$
retail_and_recreation_percent_change_from_baseline)
## [1] 0.2955484
cor(datamobility$SelfIsolation,datamobility$
grocery_and_pharmacy_percent_change_from_baseline)
## [1] 0.1444971
cor(datamobility$SelfIsolation,datamobility$
parks_percent_change_from_baseline)
## [1] -0.01763091
cor(datamobility$SelfIsolation,datamobility$
transit_stations_percent_change_from_baseline)
## [1] -0.3553029
cor(datamobility$SelfIsolation,datamobility$
workplaces_percent_change_from_baseline)
## [1] 0.3360928
cor(datamobility$SelfIsolation,datamobility$
residential_percent_change_from_baseline)
## [1] 0.4904604
model <- lm(datamobility$SelfIsolation ~ datamobility$Tanggal, data = datamobility)
summary(model)
##
## Call:
## lm(formula = datamobility$SelfIsolation ~ datamobility$Tanggal,
## data = datamobility)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3782.7 -2552.3 -612.5 1694.3 10446.8
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.161e+07 1.311e+06 -8.858 9.58e-10 ***
## datamobility$Tanggal 7.072e-03 7.980e-04 8.863 9.48e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3433 on 29 degrees of freedom
## Multiple R-squared: 0.7303, Adjusted R-squared: 0.721
## F-statistic: 78.55 on 1 and 29 DF, p-value: 9.481e-10
anova(model)
## Analysis of Variance Table
##
## Response: datamobility$SelfIsolation
## Df Sum Sq Mean Sq F value Pr(>F)
## datamobility$Tanggal 1 925938731 925938731 78.546 9.481e-10 ***
## Residuals 29 341867024 11788518
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(datamobility$SelfIsolation ~ datamobility$
Tanggal,
data = datamobility, col = "green", pch = 20, cex = 1.5,
main = "Data Covid Self Isolation di DKI Jakarta dan Google Mobility Index")
abline(model) #Add a regression line
plot(cooks.distance(model), pch = 16, col = "green") #Plot the Cooks Distances.
plot(model)
AIC(model)
## [1] 596.6685
BIC(model)
## [1] 600.9705
head(predict(model), n = 11)
## 1 2 3 4 5 6 7
## -3416.8629 -2805.8290 -2194.7952 -1583.7613 -972.7274 -361.6935 249.3403
## 8 9 10 11
## 860.3742 1471.4081 2082.4419 2693.4758
plot(head(predict(model), n = 10))
## 12 Memunculkan Nilai Residuals
head(resid(model), n = 11)
## 1 2 3 4 5 6 7 8
## 3758.8629 3233.8290 2748.7952 2210.7613 1759.7274 1317.6935 923.6597 475.6258
## 9 10 11
## 103.5919 -275.4419 -612.4758
coef(model)
## (Intercept) datamobility$Tanggal
## -1.160878e+07 7.072151e-03
datamobility$residuals <- model$residuals
datamobility$predicted <- model$fitted.values
datamobility
## # A tibble: 31 x 14
## Tanggal retail_and_recreation_~ grocery_and_pha~ parks_percent_c~
## <dttm> <dbl> <dbl> <dbl>
## 1 2022-01-01 00:00:00 3 24 46
## 2 2022-01-02 00:00:00 11 35 28
## 3 2022-01-03 00:00:00 14 36 20
## 4 2022-01-04 00:00:00 11 33 15
## 5 2022-01-05 00:00:00 12 34 17
## 6 2022-01-06 00:00:00 10 30 12
## 7 2022-01-07 00:00:00 6 25 6
## 8 2022-01-08 00:00:00 8 31 10
## 9 2022-01-09 00:00:00 7 28 13
## 10 2022-01-10 00:00:00 7 27 6
## # ... with 21 more rows, and 10 more variables:
## # transit_stations_percent_change_from_baseline <dbl>,
## # workplaces_percent_change_from_baseline <dbl>,
## # residential_percent_change_from_baseline <dbl>, POSITIF <dbl>,
## # Dirawat <dbl>, Sembuh <dbl>, Meninggal <dbl>, SelfIsolation <dbl>,
## # residuals <dbl>, predicted <dbl>
scatter.smooth(x=datamobility$Tanggal, y=datamobility$SelfIsolation,
main="Tanggal ~ SelfIsolation")
boxplot(datamobility$SelfIsolation, main="SelfIsolation",
boxplot.stats(datamobility$SelfIsolation)$out)
plot(density(datamobility$SelfIsolation), main="Google Mobility Index: Self Isolation",
ylab="Frequency")
coefs <- coef(model)
plot(SelfIsolation ~ Tanggal, data = datamobility)
abline(coefs)
text(x = 12, y = 10, paste('expression = ', round(coefs[1], 2), '+',
round(coefs[2], 2), '*SelfIsolation'))
## 15 Melakukan Uji Korelasi Antar Variabel ### Adanya korelasi antar variabel dapat dilakukan melalui visualisasi menggunakan scatterplot dan perhitungan matematis menggunakan metode Pearson untuk metode parametrik dan metode rangking Spearman dan Kendall untuk metode non-parametrik. Pada R uji korelasi dapat dilakukan dengan menggunakan fungsi cor.test(). Format fungsi tersebut adalah sebagai berikut:
cor.test(datamobility$
retail_and_recreation_percent_change_from_baseline,
datamobility$SelfIsolation)
##
## Pearson's product-moment correlation
##
## data: datamobility$retail_and_recreation_percent_change_from_baseline and datamobility$SelfIsolation
## t = 1.666, df = 29, p-value = 0.1065
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.06566892 0.58828096
## sample estimates:
## cor
## 0.2955484
cor.test(datamobility$
grocery_and_pharmacy_percent_change_from_baseline,
datamobility$SelfIsolation)
##
## Pearson's product-moment correlation
##
## data: datamobility$grocery_and_pharmacy_percent_change_from_baseline and datamobility$SelfIsolation
## t = 0.78639, df = 29, p-value = 0.438
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.2211670 0.4745402
## sample estimates:
## cor
## 0.1444971
cor.test(datamobility$
parks_percent_change_from_baseline,
datamobility$SelfIsolation)
##
## Pearson's product-moment correlation
##
## data: datamobility$parks_percent_change_from_baseline and datamobility$SelfIsolation
## t = -0.09496, df = 29, p-value = 0.925
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.3696616 0.3388260
## sample estimates:
## cor
## -0.01763091
cor.test(datamobility$
transit_stations_percent_change_from_baseline,
datamobility$SelfIsolation)
##
## Pearson's product-moment correlation
##
## data: datamobility$transit_stations_percent_change_from_baseline and datamobility$SelfIsolation
## t = -2.0469, df = 29, p-value = 0.04982
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.630290652 -0.001101465
## sample estimates:
## cor
## -0.3553029
cor.test(datamobility$
workplaces_percent_change_from_baseline,
datamobility$SelfIsolation)
##
## Pearson's product-moment correlation
##
## data: datamobility$workplaces_percent_change_from_baseline and datamobility$SelfIsolation
## t = 1.9217, df = 29, p-value = 0.06452
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.02071425 0.61695857
## sample estimates:
## cor
## 0.3360928
cor.test(datamobility$
residential_percent_change_from_baseline,
datamobility$SelfIsolation)
##
## Pearson's product-moment correlation
##
## data: datamobility$residential_percent_change_from_baseline and datamobility$SelfIsolation
## t = 3.0308, df = 29, p-value = 0.005092
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.1647526 0.7197205
## sample estimates:
## cor
## 0.4904604