Using ScheduledDay, AppointmentDay, Neighbourhood as id variables
BCE
Data Cleaning
```{r}
Convert wide into long
REPORT
We imported the ‘Medical appointment no-shows’ data from Kaggle.
We split it into a qualitative and quantitive dataframes based on the variable type.
Quantitiave Vars: Age, PatientId, AppointmentID, AppointmentDay, ScheduledDay
Qualtiative Vars: Gender, SMS_received, Scholarship, Hipertension, Diabetes, Alcoholism, Handcap, SMS_received, No.show
Gender SMS_received Scholarship Hipertension
Min. :0.00 Min. :0.000 Min. :0.00000 Min. :0.0000
1st Qu.:0.00 1st Qu.:0.000 1st Qu.:0.00000 1st Qu.:0.0000
Median :1.00 Median :0.000 Median :0.00000 Median :0.0000
Mean :0.65 Mean :0.321 Mean :0.09827 Mean :0.1972
3rd Qu.:1.00 3rd Qu.:1.000 3rd Qu.:0.00000 3rd Qu.:0.0000
Max. :1.00 Max. :1.000 Max. :1.00000 Max. :1.0000
Diabetes Alcoholism Handcap No.show
Min. :0.00000 Min. :0.0000 Min. :0.00000 Min. :0.0000
1st Qu.:0.00000 1st Qu.:0.0000 1st Qu.:0.00000 1st Qu.:0.0000
Median :0.00000 Median :0.0000 Median :0.00000 Median :0.0000
Mean :0.07186 Mean :0.0304 Mean :0.02028 Mean :0.2019
3rd Qu.:0.00000 3rd Qu.:0.0000 3rd Qu.:0.00000 3rd Qu.:0.0000
Max. :1.00000 Max. :1.0000 Max. :1.00000 Max. :1.0000
The distribution of our qualitative variables looks like the following:
Linear Reg 1
[1] -0.5596021
Box plot
Bar Graph
[1] -0.06031851
[1] -0.06031851
Call:
lm(formula = Age ~ No.show, data = original)
Residuals:
Min 1Q Median 3Q Max
-38.79 -19.32 0.21 18.21 80.68
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 37.79006 0.07767 486.54 <2e-16 ***
No.show -3.47240 0.17285 -20.09 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 23.07 on 110525 degrees of freedom
Multiple R-squared: 0.003638, Adjusted R-squared: 0.003629
F-statistic: 403.6 on 1 and 110525 DF, p-value: < 2.2e-16
Min. 1st Qu. Median Mean 3rd Qu. Max.
-3.472 -3.472 -3.472 -3.472 -3.472 -3.472
Linear Reg 2
Bar Graph
[1] -1.351175e-05
[1] -0.0001960437
[1] -0.0001960437
Call:
lm(formula = Alcoholism ~ No.show, data = original)
Residuals:
Min 1Q Median 3Q Max
-0.03042 -0.03042 -0.03042 -0.03042 0.96967
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.042e-02 5.781e-04 52.618 <2e-16 ***
No.show -8.384e-05 1.286e-03 -0.065 0.948
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1717 on 110525 degrees of freedom
Multiple R-squared: 3.843e-08, Adjusted R-squared: -9.009e-06
F-statistic: 0.004248 on 1 and 110525 DF, p-value: 0.948
Min. 1st Qu. Median Mean 3rd Qu. Max.
-8.384e-05 -8.384e-05 -8.384e-05 -8.384e-05 -8.384e-05 -8.384e-05
Linear Reg 3
Bar Graph
[1] -0.0004119471
[1] -0.007280746
[1] -0.007280746
Call:
lm(formula = Handcap ~ No.show, data = original)
Residuals:
Min 1Q Median 3Q Max
-0.02079 -0.02079 -0.02079 -0.02079 0.98176
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.0207918 0.0004745 43.814 <2e-16 ***
No.show -0.0025562 0.0010560 -2.421 0.0155 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1409 on 110525 degrees of freedom
Multiple R-squared: 5.301e-05, Adjusted R-squared: 4.396e-05
F-statistic: 5.859 on 1 and 110525 DF, p-value: 0.0155
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.002556 -0.002556 -0.002556 -0.002556 -0.002556 -0.002556
[1] 0.02079176
Linear Reg 4
[1] 0.0007886373
Bar Graph
[1] 0.004118633
[1] 0.004118633
Call:
lm(formula = Gender ~ No.show, data = original)
Residuals:
Min 1Q Median 3Q Max
-0.6539 -0.6490 0.3510 0.3510 0.3510
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.648989 0.001606 404.104 <2e-16 ***
No.show 0.004894 0.003574 1.369 0.171
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.477 on 110525 degrees of freedom
Multiple R-squared: 1.696e-05, Adjusted R-squared: 7.916e-06
F-statistic: 1.875 on 1 and 110525 DF, p-value: 0.1709
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.004894 0.004894 0.004894 0.004894 0.004894 0.004894
Linear Reg 5
[1] 0.02369604
Bar Graph
[1] 0.1264307
[1] 0.1264307
Call:
lm(formula = SMS_received ~ No.show, data = original)
Residuals:
Min 1Q Median 3Q Max
-0.4384 -0.2913 -0.2913 0.5616 0.7087
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.291334 0.001559 186.83 <2e-16 ***
No.show 0.147037 0.003470 42.37 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.4631 on 110525 degrees of freedom
Multiple R-squared: 0.01598, Adjusted R-squared: 0.01598
F-statistic: 1795 on 1 and 110525 DF, p-value: < 2.2e-16
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.147 0.147 0.147 0.147 0.147 0.147
Final
Call:
lm(formula = No.show ~ Age + Alcoholism + Handcap + Gender +
SMS_received, data = original)
Residuals:
Min 1Q Median 3Q Max
-0.3318 -0.2066 -0.1694 -0.1296 0.9144
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.037e-01 2.785e-03 73.155 < 2e-16 ***
Age -1.105e-03 5.253e-05 -21.041 < 2e-16 ***
Alcoholism 2.307e-02 7.046e-03 3.275 0.00106 **
Handcap 3.865e-03 8.519e-03 0.454 0.65002
Gender 5.116e-03 2.542e-03 2.013 0.04414 *
SMS_received 1.094e-01 2.565e-03 42.659 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.3974 on 110521 degrees of freedom
Multiple R-squared: 0.01994, Adjusted R-squared: 0.01989
F-statistic: 449.7 on 5 and 110521 DF, p-value: < 2.2e-16