Universitas : UIN MAULANA MALIK IBRAHIM MALANG
Jurusan : Teknik Informatika
Regresi linier merupakan metode yang digunakan dalam memperoleh hubungan antara 1 variable dependen dengan 1 atau lebih variabel independen. Apabila variable idependen yang digunakan hanya satu maka disebut regresi linear sederhana sedangkan apabila lebih dari satu maka disebut regresi linear berganda. Berikut contoh regresi linear berganda pada data positif Covid-19 & Google Mobility Index pada bulan Mei 2020.
library(readxl)
## Warning: package 'readxl' was built under R version 4.1.2
Data<- read_excel(path = "DataMobility1-7.xlsx")
Data
## # A tibble: 1,048,551 x 13
## Tanggal Kota Positif Dirawat Sembuh Meninggal `Self Isolation`
## <dttm> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2020-07-01 00:00:00 Jakarta 551009 24184 468461 8528 49836
## 2 2020-07-02 00:00:00 Jakarta 560408 25380 473467 8547 53014
## 3 2020-07-03 00:00:00 Jakarta 570110 27442 479150 8577 54941
## 4 2020-07-04 00:00:00 Jakarta 580595 27687 484949 8652 59307
## 5 2020-07-05 00:00:00 Jakarta 591498 28290 491556 8779 62873
## 6 2020-07-06 00:00:00 Jakarta 600937 29136 497492 8861 65448
## 7 2020-07-07 00:00:00 Jakarta 610303 30418 501199 9042 69644
## 8 2020-07-08 00:00:00 JAKARTA 13069 417 8429 667 3556
## 9 2020-07-09 00:00:00 JAKARTA 13359 451 8647 677 3584
## 10 2020-07-10 00:00:00 JAKARTA 13598 476 8825 684 3613
## # ... with 1,048,541 more rows, and 6 more variables:
## # retail_and_recreation_percent_change_from_baseline <dbl>,
## # grocery_and_pharmacy_percent_change_from_baseline <dbl>,
## # parks_percent_change_from_baseline <dbl>,
## # transit_stations_percent_change_from_baseline <dbl>,
## # workplaces_percent_change_from_baseline <dbl>,
## # residential_percent_change_from_baseline <dbl>
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.1.2
library(reshape2)
## Warning: package 'reshape2' was built under R version 4.1.3
x <- Data$Meninggal
retail <- Data$retail_and_recreation_percent_change_from_baseline
grocery <- Data$grocery_and_pharmacy_percent_change_from_baseline
park <- Data$parks_percent_change_from_baseline
station <- Data$transit_stations_percent_change_from_baseline
workplace <- Data$workplaces_percent_change_from_baseline
residental <- Data$residential_percent_change_from_baseline
df <- data.frame(x, retail, grocery, park, station, workplace,residental )
# melt the data to a long format
df2 <- melt(data = df, id.vars = "x")
# plot, using the aesthetics argument 'colour'
ggplot(data = df2, aes(x = x, y = value, colour = variable))+
geom_point() +
geom_line() +
theme(legend.justification = "top") +
labs(title = "Google Mobility Index",
subtitle = "Provinsi DKI Jakarta Indonesia Bulan Juli 2020",
y = "Mobility", x = "Data Meninggal") +
theme(axis.text.x = element_text(angle = -90))
## Warning: Removed 6291120 rows containing missing values (geom_point).
## Warning: Removed 6291120 row(s) containing missing values (geom_path).
model <- lm(Data$Meninggal~Data$retail_and_recreation_percent_change_from_baseline+Data$grocery_and_pharmacy_percent_change_from_baseline+Data$parks_percent_change_from_baseline+Data$transit_stations_percent_change_from_baseline+Data$workplaces_percent_change_from_baseline+Data$residential_percent_change_from_baseline)
model
##
## Call:
## lm(formula = Data$Meninggal ~ Data$retail_and_recreation_percent_change_from_baseline +
## Data$grocery_and_pharmacy_percent_change_from_baseline +
## Data$parks_percent_change_from_baseline + Data$transit_stations_percent_change_from_baseline +
## Data$workplaces_percent_change_from_baseline + Data$residential_percent_change_from_baseline)
##
## Coefficients:
## (Intercept)
## -60452.330
## Data$retail_and_recreation_percent_change_from_baseline
## -990.984
## Data$grocery_and_pharmacy_percent_change_from_baseline
## 1316.928
## Data$parks_percent_change_from_baseline
## -145.704
## Data$transit_stations_percent_change_from_baseline
## -835.430
## Data$workplaces_percent_change_from_baseline
## -26.566
## Data$residential_percent_change_from_baseline
## 3.368
Dalam menampilkan hasil regresi kita dapat menggunakan fungsi summary.
summary(model)
##
## Call:
## lm(formula = Data$Meninggal ~ Data$retail_and_recreation_percent_change_from_baseline +
## Data$grocery_and_pharmacy_percent_change_from_baseline +
## Data$parks_percent_change_from_baseline + Data$transit_stations_percent_change_from_baseline +
## Data$workplaces_percent_change_from_baseline + Data$residential_percent_change_from_baseline)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3162.4 -1544.8 -406.6 1055.7 4691.8
##
## Coefficients:
## Estimate Std. Error
## (Intercept) -60452.330 17163.484
## Data$retail_and_recreation_percent_change_from_baseline -990.984 303.785
## Data$grocery_and_pharmacy_percent_change_from_baseline 1316.928 269.954
## Data$parks_percent_change_from_baseline -145.704 92.351
## Data$transit_stations_percent_change_from_baseline -835.430 218.504
## Data$workplaces_percent_change_from_baseline -26.566 85.985
## Data$residential_percent_change_from_baseline 3.368 51.559
## t value Pr(>|t|)
## (Intercept) -3.522 0.001744 **
## Data$retail_and_recreation_percent_change_from_baseline -3.262 0.003303 **
## Data$grocery_and_pharmacy_percent_change_from_baseline 4.878 5.66e-05 ***
## Data$parks_percent_change_from_baseline -1.578 0.127723
## Data$transit_stations_percent_change_from_baseline -3.823 0.000822 ***
## Data$workplaces_percent_change_from_baseline -0.309 0.760017
## Data$residential_percent_change_from_baseline 0.065 0.948462
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2384 on 24 degrees of freedom
## (1048520 observations deleted due to missingness)
## Multiple R-squared: 0.6036, Adjusted R-squared: 0.5046
## F-statistic: 6.092 on 6 and 24 DF, p-value: 0.0005512
Nilai Minimum adalah -3162.4
Nilai Quartal ke-1 adalah -1544.8
Nilai Tengah adalah -406.6
Nilai Quartal ke-3 adalah 1055.7
Nilai Maksimum adalah 4691.8
Dasar teori yang digunakan dalam interpretasi hasilregre adalah apabila nilai signifikansi (Pr(>|t|)) < 0.05 maka variabel independent (variabel x) secara parsial berpengaruh terhadap variable dependent (variable y). Sehingga dapat disimpulkan :
Variable retail_and_recreation_percent_change_from_baseline signifikan berpengaruh terhadap variable meninggal. Variable grocery_and_pharmacy_percent_change_from_baseline tidak signifikan berpengaruh terhadap variable meninggal. Variable parks_percent_change_from_baseline signifikan berpengaruh terhadap variable meninggal. Variable transit_stations_percent_change_from_baselineidak signifikan berpengaruh terhadap variable meninggal. Variable workplaces_percent_change_from_baseline signifikan berpengaruh terhadap variable meninggal. Variable residential_percent_change_from_baseline signifikan berpengaruh terhadap variable meninggal. Selain itu kita dapat disimpulkan apakah seluruh variable independent berpengaruh secara simultan terhadap variable dependent dimana dasar dari penentuan tersebut yaitu apabila nilai p-value dari F-statistic < 0.05 maka keseluruahan variable independent signifikan berpengaruh secara simultan (bersama-sama) terhadap variable dependent (variable meninggal). Besar pengaruh tersebut dapat dilihat dari nilai R-squared dimana pada model diatas bernilai 0.7864. Sehingga dapat disimpulkan variable independent signifikan berpengaruh terhadap variable dependent sebesar 78.64 %.
plot(Data$retail_and_recreation_percent_change_from_baseline, Data$Meninggal, col = "blue")
plot(Data$grocery_and_pharmacy_percent_change_from_baseline, Data$Meninggal, col = "red")
plot(Data$parks_percent_change_from_baseline, Data$Meninggal, col = "darkorange")
plot(Data$transit_stations_percent_change_from_baseline, Data$Meninggal, col = "darkgreen")
plot(Data$workplaces_percent_change_from_baseline, Data$Meninggal, col = "blueviolet")
plot(Data$residential_percent_change_from_baseline, Data$Meninggal, col = "darkcyan")
plot(model)
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced
https://bookdown.org/moh_rosidi2610/Metode_Numerik/datamod.html#reglin
https://rpubs.com/suhartono-uinmaliki/861286
https://duwiconsultant.blogspot.com/2011/11/uji-normalitas-regresi.html
https://www.statistikian.com/2016/11/uji-multikolinearitas.html
https://www.statistikian.com/2017/01/uji-autokorelasi-durbin-watson-spss.html
https://belalangtue.wordpress.com/2010/08/05/uji-homogenitas-dengan-spss/