This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(readxl)
Mei <- read_excel(path = "D:/Kuliah/Linier Algebra/Mei_2021_Positif.xlsx")
## New names:
## * `` -> ...10
## * `` -> ...11
Mei
## # A tibble: 31 x 11
## Nama_provinsi Tanggal Positif Retail Grocery Park Station
## <chr> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 DKI Jakarta 2021-05-01 00:00:00 409546 -6 21 -19 -20
## 2 DKI Jakarta 2021-05-02 00:00:00 410400 -7 19 -27 -22
## 3 DKI Jakarta 2021-05-03 00:00:00 411157 -2 25 -9 -21
## 4 DKI Jakarta 2021-05-04 00:00:00 411573 -3 26 -9 -16
## 5 DKI Jakarta 2021-05-05 00:00:00 412418 -1 27 -7 -16
## 6 DKI Jakarta 2021-05-06 00:00:00 413323 -2 26 -9 -31
## 7 DKI Jakarta 2021-05-07 00:00:00 414106 -2 25 -12 -34
## 8 DKI Jakarta 2021-05-08 00:00:00 414838 -4 25 -20 -33
## 9 DKI Jakarta 2021-05-09 00:00:00 415647 -2 26 -23 -35
## 10 DKI Jakarta 2021-05-10 00:00:00 416341 6 36 1 -31
## # ... with 21 more rows, and 4 more variables: Workplace <dbl>,
## # Residental <dbl>, ...10 <lgl>, ...11 <lgl>
summary(Mei)
## Nama_provinsi Tanggal Positif
## Length:31 Min. :2021-05-01 00:00:00 Min. :409546
## Class :character 1st Qu.:2021-05-08 12:00:00 1st Qu.:415243
## Mode :character Median :2021-05-16 00:00:00 Median :419208
## Mean :2021-05-16 00:00:00 Mean :419589
## 3rd Qu.:2021-05-23 12:00:00 3rd Qu.:424419
## Max. :2021-05-31 00:00:00 Max. :430059
## Retail Grocery Park Station
## Min. :-13.000 Min. : 8.00 Min. :-27.000 Min. :-45.00
## 1st Qu.: -5.000 1st Qu.:18.50 1st Qu.: -8.000 1st Qu.:-31.50
## Median : -2.000 Median :23.00 Median : 5.000 Median :-22.00
## Mean : -2.161 Mean :23.87 Mean : 3.677 Mean :-24.32
## 3rd Qu.: -1.000 3rd Qu.:25.50 3rd Qu.: 14.500 3rd Qu.:-17.50
## Max. : 8.000 Max. :55.00 Max. : 34.000 Max. :-14.00
## Workplace Residental ...10 ...11
## Min. :-73.00 Min. : 2.000 Mode:logical Mode:logical
## 1st Qu.:-35.00 1st Qu.: 5.000 NA's:31 NA's:31
## Median :-24.00 Median : 6.000
## Mean :-28.65 Mean : 6.129
## 3rd Qu.:-19.50 3rd Qu.: 7.000
## Max. : -4.00 Max. :12.000
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Mei1 <- select(Mei, Tanggal, Positif)
Mei1
## # A tibble: 31 x 2
## Tanggal Positif
## <dttm> <dbl>
## 1 2021-05-01 00:00:00 409546
## 2 2021-05-02 00:00:00 410400
## 3 2021-05-03 00:00:00 411157
## 4 2021-05-04 00:00:00 411573
## 5 2021-05-05 00:00:00 412418
## 6 2021-05-06 00:00:00 413323
## 7 2021-05-07 00:00:00 414106
## 8 2021-05-08 00:00:00 414838
## 9 2021-05-09 00:00:00 415647
## 10 2021-05-10 00:00:00 416341
## # ... with 21 more rows
pairs(Mei1)
plot(Mei1$Positif ~ Mei1$Tanggal, data = Mei1, main="Data Pasien Positif Covid Mei 2021")
Mei1$Tanggal <- as.numeric(Mei1$Tanggal)
Mei1
## # A tibble: 31 x 2
## Tanggal Positif
## <dbl> <dbl>
## 1 1619827200 409546
## 2 1619913600 410400
## 3 1620000000 411157
## 4 1620086400 411573
## 5 1620172800 412418
## 6 1620259200 413323
## 7 1620345600 414106
## 8 1620432000 414838
## 9 1620518400 415647
## 10 1620604800 416341
## # ... with 21 more rows
cor(Mei1$Positif, Mei1$Tanggal)
## [1] 0.9965461
model <- lm(Mei1$Positif ~ Mei1$Tanggal)
summary(model)
##
## Call:
## lm(formula = Mei1$Positif ~ Mei1$Tanggal)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1065.95 -294.71 75.77 390.97 788.58
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.169e+07 1.874e+05 -62.39 <2e-16 ***
## Mei1$Tanggal 7.471e-03 1.156e-04 64.62 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 497.4 on 29 degrees of freedom
## Multiple R-squared: 0.9931, Adjusted R-squared: 0.9929
## F-statistic: 4176 on 1 and 29 DF, p-value: < 2.2e-16
anova(model)
## Analysis of Variance Table
##
## Response: Mei1$Positif
## Df Sum Sq Mean Sq F value Pr(>F)
## Mei1$Tanggal 1 1033200215 1033200215 4176.4 < 2.2e-16 ***
## Residuals 29 7174383 247393
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(Mei1$Positif ~ Mei1$Tanggal, data = Mei1, col = "magenta", pch = 20, cex = 1.7, main = "Data Pasien Positif Covid Mei 2021")
abline(model, col="blue")
plot(cooks.distance(model), pch = 16, col = "magenta")
plot(model)
AIC(model)
## [1] 476.8874
BIC(model)
## [1] 481.1894
head(predict(model), n = 11)
## 1 2 3 4 5 6 7 8
## 409906.7 410552.2 411197.7 411843.1 412488.6 413134.0 413779.5 414424.9
## 9 10 11
## 415070.4 415715.8 416361.3
plot(head(predict(model), n = 11))
head(resid(model), n = 11)
## 1 2 3 4 5 6 7
## -360.74597 -152.20161 -40.65726 -270.11290 -70.56855 188.97581 326.52016
## 8 9 10 11
## 413.06452 576.60887 625.15323 385.69758
coef(model)
## (Intercept) Mei1$Tanggal
## -1.169110e+07 7.470551e-03
Mei1$residuals <- model$residuals
Mei1$predicted <- model$fitted.values
Mei1
## # A tibble: 31 x 4
## Tanggal Positif residuals predicted
## <dbl> <dbl> <dbl> <dbl>
## 1 1619827200 409546 -361. 409907.
## 2 1619913600 410400 -152. 410552.
## 3 1620000000 411157 -40.7 411198.
## 4 1620086400 411573 -270. 411843.
## 5 1620172800 412418 -70.6 412489.
## 6 1620259200 413323 189. 413134.
## 7 1620345600 414106 327. 413779.
## 8 1620432000 414838 413. 414425.
## 9 1620518400 415647 577. 415070.
## 10 1620604800 416341 625. 415716.
## # ... with 21 more rows
scatter.smooth(x=Mei1$Positif, y=Mei1$Tanggal, main="Data Pasien Positif Covid Mei 2021")
boxplot(Mei1$Positf, Mei1$Tanggal, main="Positif", boxplot.stats(Mei1$Positif)$out)
## Warning: Unknown or uninitialised column: `Positf`.
plot(density(Mei1$Positif), main="Pasien Positif Covid Mei 2021", ylab="Frequency")
coefs <- coef(model)
plot(Mei1$Positif ~ Mei1$Tanggal, data = Mei1)
text(x = 12, y = 10, paste('expression = ', round(coefs[1], 2), '+', round(coefs[2], 2), '*Positif'))
abline(coefs, col="blue")
Mei1$Tanggal <- as.numeric(Mei1$Tanggal)
cor.test(Mei1$Tanggal, Mei1$Positif)
##
## Pearson's product-moment correlation
##
## data: Mei1$Tanggal and Mei1$Positif
## t = 64.625, df = 29, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9927687 0.9983519
## sample estimates:
## cor
## 0.9965461