Muhammad Fikru Rizal
This step is used to install the necessary package for our ‘project’
This code if you want to install only one package.
# Importing dataset from csv file
hospital <- read_csv("hospital.csv") %>% as_tibble()
# Labeling the dataset
hospital <- hospital %>%
set_variable_labels(
id_rs = "Hospital ID",
gp_FTE = "Number of General Practitioners",
spec_FTE = "Number of Medical Specialists",
nurse_total = "Number of Nurses",
other_prof = "Number of other employees",
beds = "Number of beds",
outpatients = "Number of outpatient services",
bed_days = "Total Bed Days",
admissions1 = "Number of admissions",
bed_occ = "Bed Occupancy",
throughput = "Throughput",
alos = "Average Length of Stay",
totalcost_op = "Total cost of outpatient services",
total_cost_bd = "Total cost of beddays",
totalcost_ip = "Total cost of admission/inpatient",
publichospital = "Public Hospital",
poorins = "Proportion with Social Health Insurance",
classCD = "Class C/D",
non_JavaBali = "Non Java-Bali") %>%
set_value_labels(
publichospital = c("Public"=1, "Private"=0),
classCD = c("Class C/D"=1, "Class A/B"=0),
non_JavaBali = c("Non Java-Bali"=1, "Java-Bali"=0))
gtsummary
package that can create a publication-ready table.hospital %>%
select(gp_FTE,spec_FTE,publichospital) %>% # Select variable
to_factor() %>% # Set categorical variable to "factor"
tbl_summary(digits = all_continuous() ~ 2, # Number of digits for cont. variables
statistic = all_continuous() ~ "{mean} ({sd})") %>% # What type of summary statistics
as_flex_table() # Presented as flex_table, easy to copy to Word processing software
Characteristic | N = 198 |
---|---|
Number of General Practitioners | 15.41 (9.95) |
Number of Medical Specialists | 19.86 (20.52) |
Public Hospital | |
Public | 120 (61%) |
Private | 78 (39%) |
Mean (SD); n (%) |
outpatients
), number of admissions (admissions1
), and location of hospital (non_JavaBali
)We will use the ggplot
package to make a versatile and nice data visualisation. Source: https://ggplot2.tidyverse.org/index.html
Some basic plot like histogram, scatter plot, and box-plot will be used as an example.
nurse_total
) vs number of admissions (admissions1
)publichospital
)mutate
function from the dplyr
package.tbl_summary
function from the gtsummary
package.Characteristic | N = 198 |
---|---|
Inpatient Unit Cost | 297.58 (194.62) |
Bed days Unit Cost | 82.35 (54.61) |
Mean (SD) |
totalcost_op
divided by outpatients
) and present the tablethroughput
) and bed occupancy ratio (bed-occ
).hospital %>% to_factor() %>%
ggplot(aes(x=bed_occ, y=throughput, colour=publichospital, size=beds)) +
geom_point(alpha=0.5) +
geom_hline(yintercept=mean_btr) +
geom_vline(xintercept=mean_bor) +
labs(title="Model Pabon-Lasso",
x="Bed Occupancy Rate",
y="Bed Turnover",
colour="Ownership",
size= "Number of beds")
eff_pl
.benchmarking
and frontier
package.# Combining results from DEA
dea_id <- data.frame(
cbind(id_rs=hospital$id_rs,
EI=c(dea_input$eff),
EI_bc=c(dea_input$eff.bc),
EI_CI_low=c(dea_input$conf.int[,1]),
EI_CI_hi=c(dea_input$conf.int[,2]),
EO=c(dea_output$eff),
EO_bc=c(dea_output$eff.bc),
EO_CI_low=c(dea_output$conf.int[,1]),
EO_CI_hi=c(dea_output$conf.int[,2])))
# Merge with hospital data
hospital_dea <- merge(
hospital, dea_id, by="id_rs", all = TRUE)
tbl_summary
function.# Two-sample t-test (unequal variance, Welch two-sample t-test)
hospital %>%
to_factor() %>%
select(unitcost_ip, lnuc_ip, publichospital) %>%
tbl_summary(by=publichospital, digits = all_continuous() ~ 3,
statistic = all_continuous() ~ "{mean} ({sd})") %>%
add_p(test=all_continuous() ~ "t.test") %>%
as_flex_table()
Characteristic | Public, N = 1201 | Private, N = 781 | p-value2 |
---|---|---|---|
Inpatient Unit Cost | 273.839 (186.983) | 334.099 (201.611) | 0.036 |
Log (Inpatient Unit Cost) | 5.423 (0.626) | 5.650 (0.566) | 0.009 |
1 Mean (SD) | |||
2 Welch Two Sample t-test |
summary
), tbl_regression
function from the gtsummary
package, modelsummary
function, or many other options.
Call:
lm(formula = gp_FTE ~ publichospital + classCD + non_JavaBali +
poorins, data = .)
Residuals:
Min 1Q Median 3Q Max
-15.489 -5.460 -1.102 2.868 46.368
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 17.7474 1.7312 10.252 < 2e-16 ***
publichospital 7.1797 1.3301 5.398 1.96e-07 ***
classCD -4.2448 1.5165 -2.799 0.005647 **
non_JavaBali -0.8601 1.3301 -0.647 0.518658
poorins -14.3360 4.2856 -3.345 0.000988 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 8.725 on 193 degrees of freedom
Multiple R-squared: 0.247, Adjusted R-squared: 0.2314
F-statistic: 15.83 on 4 and 193 DF, p-value: 3.206e-11
Call:
glm(formula = eff_pl ~ publichospital + classCD + non_JavaBali +
poorins, family = binomial, data = .)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.5355 -0.9421 -0.7739 1.1929 1.8367
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.5624 0.4243 -1.326 0.18500
publichospital 0.5235 0.3344 1.565 0.11748
classCD -0.3133 0.3715 -0.843 0.39899
non_JavaBali -0.8621 0.3277 -2.631 0.00852 **
poorins 2.1924 1.0382 2.112 0.03470 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 262.73 on 197 degrees of freedom
Residual deviance: 247.62 on 193 degrees of freedom
AIC: 257.62
Number of Fisher Scoring iterations: 4
gtsummary
Characteristic | Beta | 95% CI1 | p-value |
---|---|---|---|
Public Hospital | 7.2 | 4.6, 9.8 | <0.001 |
Class C/D | -4.2 | -7.2, -1.3 | 0.006 |
Non Java-Bali | -0.86 | -3.5, 1.8 | 0.5 |
Proportion with Social Health Insurance | -14 | -23, -5.9 | <0.001 |
1 CI = Confidence Interval |
Characteristic | OR | 95% CI | p-value |
---|---|---|---|
Public Hospital | 1.69 | 0.88, 3.29 | 0.12 |
Class C/D | 0.73 | 0.35, 1.53 | 0.4 |
Non Java-Bali | 0.42 | 0.22, 0.80 | 0.009 |
Proportion with Social Health Insurance | 8.96 | 1.17, 70.3 | 0.035 |
OR = Odds Ratio, CI = Confidence Interval |
# Linear regression table using modelsummary
# Labelling the covariates or regressors
ols_gp_label <- ols_gp
names(ols_gp_label$coefficients) <-
c("Constant", "Class C/D", "Public", "Non Java-Bali", "Proportion with SHI")
# Produce table
modelsummary(list("Number of GP" = ols_gp_label), # List of the model(s) and their label
fmt=3, # Number of digits
estimate = "{estimate}{stars}", # Format of coefficients
gof_omit = ".*") # Goodness of fit statistics are excluded
Number of GP | |
---|---|
Constant | 17.747*** |
(1.731) | |
Class C/D | 7.180*** |
(1.330) | |
Public | -4.245** |
(1.517) | |
Non Java-Bali | -0.860 |
(1.330) | |
Proportion with SHI | -14.336*** |
(4.286) |
# Labelling the covariates or regressors
logit_pl_label <- logit_pl
names(logit_pl_label$coefficients) <-
c("Constant", "Class C/D", "Public", "Non Java-Bali", "Proportion with SHI")
# Produce table
modelsummary(list("Efficient Hospital (PL)" = logit_pl_label), # List of the model(s) and their label
fmt=NULL, # Number of digits
estimate = "{round(exp(estimate), 3)}{stars}", # Format of coefficients
statistic = "({round(exp(estimate) * std.error, 3)})",
gof_omit = ".*") # Goodness of fit statistics are excluded
Efficient Hospital (PL) | |
---|---|
Constant | 0.57 |
(0.242) | |
Class C/D | 1.688 |
(0.564) | |
Public | 0.731 |
(0.272) | |
Non Java-Bali | 0.422** |
(0.138) | |
Proportion with SHI | 8.957* |
(9.299) |
Run a linear regression with number of specialists as the outcome variable (y) and hospital ownership, location, class, and district-level proportion of population with social health insurance as the explanatory variables (x).
Present the result/coefficient using either base function or other functions.