library(readxl)
#baca data excel
mobindexjkt <- read_excel("mobindex_jkt.xlsx")
covidjkt <- read_excel("c19data_jkt.xlsx")
Datagab <- read_excel("Datagab.xlsx")
retail <- mobindexjkt$retail_and_recreation_percent_change_from_baseline
grocery <- mobindexjkt$grocery_and_pharmacy_percent_change_from_baseline
park <- mobindexjkt$parks_percent_change_from_baseline
station <- mobindexjkt$transit_stations_percent_change_from_baseline
workplace <- mobindexjkt$workplaces_percent_change_from_baseline
residental <- mobindexjkt$residential_percent_change_from_baseline
date <- mobindexjkt$date
tanggal <- Datagab$Tanggal
Sembuh <- Datagab$Sembuh
Station <- Datagab$Station
Positif <- covidjkt$Positif
Dirawat <- covidjkt$Dirawat
Sembuh <- covidjkt$Sembuh
Meninggal <- covidjkt$Meninggal
Isoman <- covidjkt$SelfIsolation
#Visualisasi Data Menggunakan Fungsi plot(). #Fungsi plot() merupakan fungsi umum yang digunakan untuk membuat pola pada R.
#korelasi kasus Sembuh vs retail
cor(Sembuh,retail)
## [1] 0.3549348
#korelasi kasus dirawat vs grocery
cor(Sembuh,grocery)
## [1] -0.1303234
#korelasi kasus dirawat vs park
cor(Sembuh,park)
## [1] 0.2194496
#korelasi kasus dirawat vs station
cor(Sembuh,station)
## [1] 0.5154747
#korelasi kasus dirawat vs workplace
cor(Sembuh,workplace)
## [1] 0.09943055
#korelasi kasus dirawat vs residental
cor(Sembuh,residental)
## [1] -0.1478056
summary(covidjkt)
## Tanggal Positif Dirawat
## Min. :2021-09-01 00:00:00 Min. :851256 Min. : 510.0
## 1st Qu.:2021-09-08 06:00:00 1st Qu.:853676 1st Qu.: 708.8
## Median :2021-09-15 12:00:00 Median :855512 Median :1044.0
## Mean :2021-09-15 12:00:00 Mean :855112 Mean :1155.8
## 3rd Qu.:2021-09-22 18:00:00 3rd Qu.:856709 3rd Qu.:1521.5
## Max. :2021-09-30 00:00:00 Max. :857765 Max. :2172.0
## Sembuh Meninggal SelfIsolation
## Min. :831293 Min. :13302 Min. :1195
## 1st Qu.:835822 1st Qu.:13389 1st Qu.:1506
## Median :838851 Median :13460 Median :2158
## Mean :838165 Mean :13438 Mean :2353
## 3rd Qu.:841002 3rd Qu.:13492 3rd Qu.:2944
## Max. :842541 Max. :13519 Max. :4489
#dataframe KASUS SEMBUH
dataku <- data.frame(date, retail, grocery, park, station, workplace, residental)
library(ggplot2)
library(reshape2)
dataku1 <- melt(data = dataku, id.vars = "date")
ggplot(data = dataku1, aes(x = date, y = value, colour = variable))+
geom_point() +
geom_line() +
theme(legend.justification = "top") +
labs(title = "Grafik Google Mobility Index",
subtitle = "Propinsi DKI Jakarta Indonesia Sept 2021",
y = "Index Moility", x = "Tanggal") +
theme(axis.text.x = element_text(angle = -90))
head(Datagab)
## # A tibble: 6 x 3
## Tanggal Sembuh Station
## <dttm> <dbl> <dbl>
## 1 2021-09-01 00:00:00 831293 -41
## 2 2021-09-02 00:00:00 832130 -42
## 3 2021-09-03 00:00:00 832952 -41
## 4 2021-09-04 00:00:00 833437 -35
## 5 2021-09-05 00:00:00 833765 -38
## 6 2021-09-06 00:00:00 834489 -41
p <- ggplot(Datagab, aes(x = tanggal))
p <- p + geom_line(aes(y = Sembuh/30, colour = "Sembuh"))
p <- p + geom_line(aes(y = Station, colour = "station"))
p <- p + scale_y_continuous(sec.axis = sec_axis(~.*1, name = "station"))
p
model <- lm(Sembuh ~ Station)
summary(model)
##
## Call:
## lm(formula = Sembuh ~ Station)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6078 -1770 513 2580 3692
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 858169.4 6306.9 136.067 < 2e-16 ***
## Station 533.0 167.4 3.183 0.00355 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2917 on 28 degrees of freedom
## Multiple R-squared: 0.2657, Adjusted R-squared: 0.2395
## F-statistic: 10.13 on 1 and 28 DF, p-value: 0.003554
anova(model)
## Analysis of Variance Table
##
## Response: Sembuh
## Df Sum Sq Mean Sq F value Pr(>F)
## Station 1 86201451 86201451 10.132 0.003554 **
## Residuals 28 238212709 8507597
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(covidjkt$Sembuh ~ covidjkt$Tanggal, data = covidjkt, col = "dodgerblue", pch = 20, cex = 1.5, main = "Kasus Sembuh Covid 19")
abline(model)
plot(cooks.distance(model), pch = 16, col = "blue")
plot(model)
AIC(model)
## [1] 567.7606
BIC(model)
## [1] 571.9642
head(predict(model), n = 30)
## 1 2 3 4 5 6 7 8
## 836317.6 835784.7 836317.6 839515.5 837916.5 836317.6 836850.6 836850.6
## 9 10 11 12 13 14 15 16
## 837383.6 837383.6 840581.4 838982.5 837383.6 834718.7 837916.5 837383.6
## 17 18 19 20 21 22 23 24
## 837916.5 841114.4 838982.5 837916.5 837916.5 837383.6 837916.5 838449.5
## 25 26 27 28 29 30
## 842713.3 841114.4 838449.5 838449.5 838982.5 840048.4
plot(head(predict(model), n = 10))
head(resid(model), n = 30)
## 1 2 3 4 5 6 7
## -5024.6415 -3654.6727 -3365.6415 -6078.4543 -4151.5479 -1828.6415 -1820.6103
## 8 9 10 11 12 13 14
## -1150.6103 -1196.5791 -739.5791 -3548.3919 -1618.4855 421.4209 3587.2649
## 15 16 17 18 19 20 21
## 763.4521 1638.4209 1462.4521 -1491.3607 820.5145 2295.4521 2608.4521
## 22 23 24 25 26 27 28
## 3428.4209 3148.4521 2943.4833 -1121.2671 604.6393 3530.4833 3691.4833
## 29 30
## 3353.5145 2492.5769
coef(model)
## (Intercept) Station
## 858169.3625 532.9688
Datagab$residuals <- model$residuals
Datagab$predicted <- model$fitted.values
Datagab
## # A tibble: 30 x 5
## Tanggal Sembuh Station residuals predicted
## <dttm> <dbl> <dbl> <dbl> <dbl>
## 1 2021-09-01 00:00:00 831293 -41 -5025. 836318.
## 2 2021-09-02 00:00:00 832130 -42 -3655. 835785.
## 3 2021-09-03 00:00:00 832952 -41 -3366. 836318.
## 4 2021-09-04 00:00:00 833437 -35 -6078. 839515.
## 5 2021-09-05 00:00:00 833765 -38 -4152. 837917.
## 6 2021-09-06 00:00:00 834489 -41 -1829. 836318.
## 7 2021-09-07 00:00:00 835030 -40 -1821. 836851.
## 8 2021-09-08 00:00:00 835700 -40 -1151. 836851.
## 9 2021-09-09 00:00:00 836187 -39 -1197. 837384.
## 10 2021-09-10 00:00:00 836644 -39 -740. 837384.
## # ... with 20 more rows
scatter.smooth(x=Datagab$Tanggal, y=Datagab$Sembuh, main="Tanggal ~ Sembuh")
boxplot(Datagab$Sembuh, main="Sembuh", boxplot.stats(Datagab$Sembuh)$out)
require(fuzzyreg)
## Loading required package: fuzzyreg
data(fuzzydat)
f = fuzzylm(Sembuh ~ Station, data = Datagab)
plot(f, res = 20, col = "lightblue", main = "PLRLS")