gh_Df <- read.csv("C:/Users/PC/Documents/R_4DS/Ghana/health-facilities-gh.csv")
str(gh_Df)
## 'data.frame': 3756 obs. of 8 variables:
## $ Region : Factor w/ 10 levels "Ashanti","Brong Ahafo",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ District : Factor w/ 171 levels "Abura-Asebu-Kwamankese",..: 119 37 4 6 93 119 33 31 62 101 ...
## $ FacilityName: Factor w/ 3544 levels "1000 Acre CHPS",..: 14 23 35 38 41 45 65 75 86 120 ...
## $ Type : Factor w/ 25 levels "Centre","CHPS",..: 4 4 9 9 9 9 11 4 9 9 ...
## $ Town : Factor w/ 2447 levels "",".Sampa","1000 Acre",..: 156 353 32 33 37 39 62 71 79 113 ...
## $ Ownership : Factor w/ 12 levels "CHAG","Clinic",..: 1 11 4 4 4 4 11 1 4 4 ...
## $ Latitude : num 7.41 6.46 6.22 6.84 6.84 ...
## $ Longitude : num -1.96 -1.59 -1.35 -1.61 -1.61 ...
summary(gh_Df)
## Region District FacilityName
## Ashanti :658 Accra Metropolitan : 277 Rabito Clinic : 11
## Greater Accra:504 Kumasi Metropolitan: 263 Adom Maternity Home : 7
## Western :496 Tema Metropolitan : 118 Christian Eye Centre : 6
## Volta :398 Shama Ahanta East : 71 Police Clinic : 6
## Eastern :393 Ho Municipal : 51 Salvation Army Clinic: 6
## Brong Ahafo :348 Bia : 49 SDA Hospital : 6
## (Other) :959 (Other) :2927 (Other) :3714
## Type Town Ownership
## Clinic :1171 : 153 Government :2210
## Health Centre : 786 Sunyani : 29 Private :1179
## CHPS : 652 Koforidua: 17 CHAG : 257
## Maternity Home: 369 Berekum : 16 Quasi-Government: 91
## Hospital : 277 Ho : 15 government : 6
## RCH : 152 Osu : 15 Islamic : 4
## (Other) : 349 (Other) :3511 (Other) : 9
## Latitude Longitude
## Min. : 4.796 Min. :-3.2359
## 1st Qu.: 5.688 1st Qu.:-1.8098
## Median : 6.469 Median :-1.0581
## Mean : 6.956 Mean :-1.0746
## 3rd Qu.: 7.431 3rd Qu.:-0.2159
## Max. :11.147 Max. : 1.1914
## NA's :24 NA's :24
null_loc <- gh_Df %>%
filter(is.na(Latitude))
null_loc
## Region District FacilityName
## 1 Ashanti Bosome Freho Dunkura Health Centre
## 2 Ashanti Bosome Freho Yapesa St.Mary Clinic
## 3 Eastern Akyemansa St Johns Clinic
## 4 Northern Gushegu Nabuli Health Centre
## 5 Northern Gushegu Damakung Clinic
## 6 Northern Gushegu Gushegu Hospital
## 7 Western Nzema East Municipal Ewuku CHPS
## 8 Western Nzema East Municipal Kutukrom Health Centre
## 9 Western Ellembele Aiyinase Health Centre
## 10 Western Ellembele Nana Benie M. Clinic
## 11 Western Ellembele A. B. Bokazo Clinic
## 12 Western Ellembele St. Martin de Porres Hospitakl
## 13 Western Ellembele Krisan Camp Clinic
## 14 Western Ellembele Esiama Health Centre
## 15 Western Ellembele Kamgbunli CHPS
## 16 Western Ellembele Mobile Clinic
## 17 Western Ellembele Ampain Refugee Camp
## 18 Western Ellembele Aidoosuazo CHPS
## 19 Western Ellembele Kwasikrom CHPS
## 20 Western Ellembele Asomase CHPS
## 21 Western Ellembele Asasetre Health Centre
## 22 Western Ellembele NASS SCH Clinic
## 23 Western Ellembele West African Rescue Association Clinic
## 24 Western Ellembele Ellembele District Health Directorate
## Type Town Ownership Latitude Longitude
## 1 Health Centre Dunkura Government NA NA
## 2 Clinic Yapesa CHAG NA NA
## 3 Clinic Ofoase CHAG NA NA
## 4 Health Centre Nabuli Government NA NA
## 5 Clinic Damankung Government NA NA
## 6 Hospital Gushiegu Government NA NA
## 7 CHPS Ewuku Government NA NA
## 8 Health Centre Kutukrom Government NA NA
## 9 Health Centre Aiyinase Government NA NA
## 10 Clinic Private NA NA
## 11 Clinic Private NA NA
## 12 Hospital CHAG NA NA
## 13 Clinic CHAG NA NA
## 14 Health Centre Esiama Government NA NA
## 15 CHPS Kamgbunli Government NA NA
## 16 Clinic Government NA NA
## 17 Clinic Ampain Government NA NA
## 18 CHPS Aidoosuazo Government NA NA
## 19 CHPS Kwasikrom Government NA NA
## 20 CHPS Asomase Government NA NA
## 21 Health Centre Asasetre Government NA NA
## 22 Clinic Government NA NA
## 23 Clinic Government NA NA
## 24 District Health Directorate Government NA NA
fill_lat_long_na <- function(val, lat, long){
if(is.na(gh_Df[gh_Df$FacilityName == val,]$Latitude)){
gh_Df[gh_Df$FacilityName == val,]$Latitude <- lat
gh_Df[gh_Df$FacilityName == val,]$Longitude <- long
}
return(gh_Df)
}
## Check
gh_Df <- fill_lat_long_na("Yapesa St.Mary Clinic", 6.43011, -1.33299)
# For values with multiple entry
## Dunkura Health Centre
gh_Df$Latitude[358] = 7.14327
gh_Df$Longitude[358] = -1.52221
##
gh_Df$Latitude[3664] = 5.04234
gh_Df$Longitude[3664] = -2.46608
## Aidoosuazo CHPS
gh_Df$Latitude[3673] = 5.09531
gh_Df$Longitude[3673] = -2.84933
## Kwasikrom CHPS
gh_Df$Latitude[3674] = 5.34836
gh_Df$Longitude[3674] = -2.43058
## Asasetre Health Centre
gh_Df$Latitude[3676] = 5.02475
gh_Df$Longitude[3676] = -2.34777
null_loc <- gh_Df %>%
filter(is.na(Latitude))
cat("Latitude and Longitude have", dim(null_loc)[1], "missing values")
## Latitude and Longitude have 0 missing values
gh_Df %>%
select(District, FacilityName, Town) %>%
filter(Town == "") %>%
head()
## District FacilityName Town
## 1 Kumasi Metropolitan Amansie Enterprise Clinic
## 2 Kumasi Metropolitan Restoration Clinic
## 3 Mampong Municipal Calvary Health Service
## 4 Offinso Municipal Offinso District Health Directorate
## 5 Dormaa Municipal Florence Maternity Home
## 6 Dormaa Municipal EMC Kwaku Any Maternity Home
gh_Df$Town <- as.character(gh_Df$Town)
gh_Df$Town[gh_Df$Town == ""] <- "UnIdentified"
gh_Df$Town <- as.factor(gh_Df$Town)
The first thing the Author Noticed is how most of the Facilities here are either Privately owned or District Directorates.
gh_Df$Type <- as.character(gh_Df$Type)
# gh_Df <- within(gh_Df, {
# Type[Type == c(, "clinic")] <- "Clinibzc"
# })
# recode(gh_Df$Type,
# "clinic" = "Clinic",
# "Centre" = "Health Centre",
# "CHPS" = "CPHS",
# "DHD" = "District Health Centre",
# "District Health Directorate" = "District Health Centre",
# "District Hospital" = "District Health Centre",
# "Metropolitan Health Directorate" = "Metro Health Centre",
# "Metropolitan Hospital" = "Metro Health Centre",
# "Municipal Health Directorate" = "Municipal Health Centre",
# "Municipal Health Directorate" = "Municipal Health Centre",
# "Municipal Hospital" = "Municipal Health Centre",
# "RCH" = "Regional Health Centre",
# "Regional Health Directorate" = "Regional Health Centre",
# "Regional Hospital" = "Regional Health Centre"
# )
gh_Df$Type[gh_Df$Type == "clinic"] <- "Clinic"
gh_Df$Type[gh_Df$Type == "DHD"] <- "District Health Centre"
gh_Df$Type[gh_Df$Type == "District Health Directorate"] <- "District Health Centre"
gh_Df$Type[gh_Df$Type == "District Hospital"] <- "District Health Centre"
gh_Df$Type[gh_Df$Type == "Centre"] <- "Local Health Centre"
gh_Df$Type[gh_Df$Type == "CPHS"] <- "CHPS"
gh_Df$Type[gh_Df$Type == "Psychiatric Hospital"] <- "Hospital"
gh_Df$Type[gh_Df$Type == "Teaching Hospital"] <- "Hospital"
gh_Df$Type[gh_Df$Type == "Metropolitan Health Directorate"] <- "Metro Health Centre"
gh_Df$Type[gh_Df$Type == "Metropolitan Hospital"] <- "Metro Health Centre"
gh_Df$Type[gh_Df$Type == "Municipal Health Directorate"] <- "Municpal Health Centre"
gh_Df$Type[gh_Df$Type == "Municipal Health Directorate"] <- "Municpal Health Centre"
gh_Df$Type[gh_Df$Type == "Municipal Hospital"] <- "Municpal Health Centre"
gh_Df$Type[gh_Df$Type == "RCH"] <- "Regional Health Centre"
gh_Df$Type[gh_Df$Type == "Regional Health Directorate"] <- "Regional Health Centre"
gh_Df$Type[gh_Df$Type == "Regional Hospital"] <- "Regional Health Centre"
gh_Df$Type[gh_Df$Type == "Research Institution"] <- "Institutional Health Centre"
gh_Df$Type[gh_Df$Type == "Training Institution"] <- "Institutional Health Centre"
gh_Df$Type <- as.factor(gh_Df$Type)
levels(gh_Df$Type)
## [1] "CHPS" "Clinic"
## [3] "District Health Centre" "Health Centre"
## [5] "Hospital" "Institutional Health Centre"
## [7] "Local Health Centre" "Maternity Home"
## [9] "Metro Health Centre" "Municpal Health Centre"
## [11] "Others" "Polyclinic"
## [13] "Regional Health Centre"
gh_Df$Ownership <- as.character(gh_Df$Ownership)
gh_Df$Ownership <- ifelse(gh_Df$Ownership == c("government", "Government", "Quasi-Government"), "Government",
ifelse(gh_Df$Ownership == c("NGO", "CHAG"), "NGO", "Private"))
gh_Df$Ownership <- as.factor(gh_Df$Ownership)
levels(gh_Df$Ownership)
## [1] "Government" "NGO" "Private"
table(gh_Df$Type, gh_Df$Region)
##
## Ashanti Brong Ahafo Central Eastern Greater Accra
## CHPS 14 35 98 91 5
## Clinic 269 155 65 85 285
## District Health Centre 16 21 21 14 11
## Health Centre 136 55 54 45 23
## Hospital 90 19 11 13 100
## Institutional Health Centre 12 6 5 6 18
## Local Health Centre 1 1 0 0 0
## Maternity Home 113 49 30 41 50
## Metro Health Centre 0 0 2 0 0
## Municpal Health Centre 2 2 1 0 0
## Others 0 0 0 0 2
## Polyclinic 0 1 1 0 8
## Regional Health Centre 5 4 11 98 2
##
## Northern Upper East Upper West Volta Western
## CHPS 81 94 60 49 126
## Clinic 16 50 10 49 189
## District Health Centre 27 10 12 24 26
## Health Centre 108 36 59 201 69
## Hospital 9 0 4 15 22
## Institutional Health Centre 7 6 4 5 7
## Local Health Centre 0 0 0 0 0
## Maternity Home 6 2 4 30 44
## Metro Health Centre 1 0 0 0 0
## Municpal Health Centre 0 3 1 3 0
## Others 1 28 0 0 0
## Polyclinic 2 0 0 2 2
## Regional Health Centre 9 3 7 20 11
library(dplyr)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
plotdata <- gh_Df %>%
group_by(Region, Type) %>%
summarise(Total_Facilities = n()) %>%
mutate(Average_Facilities = Total_Facilities/sum(Total_Facilities),
label = percent(Average_Facilities)) %>%
arrange(desc(Total_Facilities))
## `summarise()` regrouping output by 'Region' (override with `.groups` argument)
plotdata %>%
ggplot(aes(x = Total_Facilities, fill = Type)) +
geom_histogram() +
#coord_flip() +
facet_wrap(~Region, ncol = 2) +
theme_minimal()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
# input data
library(readr)
# create a table
tbl <- xtabs(~Region + Type + Ownership, gh_Df)
ftable(tbl)
## Ownership Government NGO Private
## Region Type
## Ashanti CHPS 5 0 9
## Clinic 17 24 228
## District Health Centre 6 0 10
## Health Centre 33 4 99
## Hospital 3 7 80
## Institutional Health Centre 3 0 9
## Local Health Centre 0 0 1
## Maternity Home 3 0 110
## Metro Health Centre 0 0 0
## Municpal Health Centre 0 0 2
## Others 0 0 0
## Polyclinic 0 0 0
## Regional Health Centre 2 0 3
## Brong Ahafo CHPS 13 0 22
## Clinic 32 6 117
## District Health Centre 7 0 14
## Health Centre 20 1 34
## Hospital 5 3 11
## Institutional Health Centre 1 0 5
## Local Health Centre 1 0 0
## Maternity Home 1 1 47
## Metro Health Centre 0 0 0
## Municpal Health Centre 0 0 2
## Others 0 0 0
## Polyclinic 0 0 1
## Regional Health Centre 2 0 2
## Central CHPS 32 0 66
## Clinic 12 6 47
## District Health Centre 8 0 13
## Health Centre 14 1 39
## Hospital 1 1 9
## Institutional Health Centre 2 0 3
## Local Health Centre 0 0 0
## Maternity Home 2 1 27
## Metro Health Centre 1 0 1
## Municpal Health Centre 0 0 1
## Others 0 0 0
## Polyclinic 0 0 1
## Regional Health Centre 7 0 4
## Eastern CHPS 32 0 59
## Clinic 4 8 73
## District Health Centre 3 0 11
## Health Centre 14 1 30
## Hospital 2 3 8
## Institutional Health Centre 2 0 4
## Local Health Centre 0 0 0
## Maternity Home 1 1 39
## Metro Health Centre 0 0 0
## Municpal Health Centre 0 0 0
## Others 0 0 0
## Polyclinic 0 0 0
## Regional Health Centre 35 0 63
## Greater Accra CHPS 1 0 4
## Clinic 17 5 263
## District Health Centre 4 0 7
## Health Centre 6 1 16
## Hospital 7 2 91
## Institutional Health Centre 5 0 13
## Local Health Centre 0 0 0
## Maternity Home 0 0 50
## Metro Health Centre 0 0 0
## Municpal Health Centre 0 0 0
## Others 1 0 1
## Polyclinic 2 0 6
## Regional Health Centre 1 0 1
## Northern CHPS 26 1 54
## Clinic 2 2 12
## District Health Centre 8 1 18
## Health Centre 32 10 66
## Hospital 3 1 5
## Institutional Health Centre 2 0 5
## Local Health Centre 0 0 0
## Maternity Home 1 0 5
## Metro Health Centre 0 0 1
## Municpal Health Centre 0 0 0
## Others 0 0 1
## Polyclinic 0 0 2
## Regional Health Centre 3 0 6
## Upper East CHPS 30 0 64
## Clinic 10 5 35
## District Health Centre 3 0 7
## Health Centre 8 4 24
## Hospital 0 0 0
## Institutional Health Centre 1 0 5
## Local Health Centre 0 0 0
## Maternity Home 0 0 2
## Metro Health Centre 0 0 0
## Municpal Health Centre 1 1 1
## Others 7 2 19
## Polyclinic 0 0 0
## Regional Health Centre 1 0 2
## Upper West CHPS 22 0 38
## Clinic 1 1 8
## District Health Centre 3 0 9
## Health Centre 21 4 34
## Hospital 0 1 3
## Institutional Health Centre 1 0 3
## Local Health Centre 0 0 0
## Maternity Home 0 0 4
## Metro Health Centre 0 0 0
## Municpal Health Centre 0 0 1
## Others 0 0 0
## Polyclinic 0 0 0
## Regional Health Centre 1 0 6
## Volta CHPS 16 0 33
## Clinic 6 2 41
## District Health Centre 4 1 19
## Health Centre 68 5 128
## Hospital 1 3 11
## Institutional Health Centre 2 0 3
## Local Health Centre 0 0 0
## Maternity Home 0 0 30
## Metro Health Centre 0 0 0
## Municpal Health Centre 0 0 3
## Others 0 0 0
## Polyclinic 0 0 2
## Regional Health Centre 5 0 15
## Western CHPS 39 0 87
## Clinic 16 8 165
## District Health Centre 5 0 21
## Health Centre 23 1 45
## Hospital 4 2 16
## Institutional Health Centre 3 1 3
## Local Health Centre 0 0 0
## Maternity Home 0 0 44
## Metro Health Centre 0 0 0
## Municpal Health Centre 0 0 0
## Others 0 0 0
## Polyclinic 1 0 1
## Regional Health Centre 6 0 5
ggplot(gh_Df,
aes(x = Region,
fill = Type)) +
geom_bar(position = position_dodge(preserve = "single")) +
coord_flip() +
theme_minimal()
Region constant.## Chi Sq distribution
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
df_factor <- select_if(gh_Df, is.factor)
for (var in names(df_factor)) {
if (var != "Region" && length(levels(gh_Df[, var])) < 20){
cat("+----------------------+")
cat("\n","Data Table for",var, "Variable","\n")
# contigency table
factor_hd <- table(gh_Df[[var]], gh_Df$Region)
cat("----------------------")
print(factor_hd)
cat("----------------------")
cat("\n","Chi Square Test @ 0.05")
# chiSq
print(chisq.test(factor_hd))
cat("+----------------------+","\n\n")
Xsq <- chisq.test(factor_hd)
# barplot(Xsq$observed, Xsq$expected, beside = TRUE)
}
}
## +----------------------+
## Data Table for Type Variable
## ----------------------
## Ashanti Brong Ahafo Central Eastern Greater Accra
## CHPS 14 35 98 91 5
## Clinic 269 155 65 85 285
## District Health Centre 16 21 21 14 11
## Health Centre 136 55 54 45 23
## Hospital 90 19 11 13 100
## Institutional Health Centre 12 6 5 6 18
## Local Health Centre 1 1 0 0 0
## Maternity Home 113 49 30 41 50
## Metro Health Centre 0 0 2 0 0
## Municpal Health Centre 2 2 1 0 0
## Others 0 0 0 0 2
## Polyclinic 0 1 1 0 8
## Regional Health Centre 5 4 11 98 2
##
## Northern Upper East Upper West Volta Western
## CHPS 81 94 60 49 126
## Clinic 16 50 10 49 189
## District Health Centre 27 10 12 24 26
## Health Centre 108 36 59 201 69
## Hospital 9 0 4 15 22
## Institutional Health Centre 7 6 4 5 7
## Local Health Centre 0 0 0 0 0
## Maternity Home 6 2 4 30 44
## Metro Health Centre 1 0 0 0 0
## Municpal Health Centre 0 3 1 3 0
## Others 1 28 0 0 0
## Polyclinic 2 0 0 2 2
## Regional Health Centre 9 3 7 20 11
## ----------------------
## Chi Square Test @ 0.05
## Warning in chisq.test(factor_hd): Chi-squared approximation may be incorrect
##
## Pearson's Chi-squared test
##
## data: factor_hd
## X-squared = 2227.4, df = 108, p-value < 2.2e-16
##
## +----------------------+
## Warning in chisq.test(factor_hd): Chi-squared approximation may be incorrect
## +----------------------+
## Data Table for Ownership Variable
## ----------------------
## Ashanti Brong Ahafo Central Eastern Greater Accra Northern
## Government 72 82 79 93 44 77
## NGO 35 11 9 13 8 15
## Private 551 255 211 287 452 175
##
## Upper East Upper West Volta Western
## Government 61 49 102 97
## NGO 12 6 11 12
## Private 159 106 285 387
## ----------------------
## Chi Square Test @ 0.05
## Pearson's Chi-squared test
##
## data: factor_hd
## X-squared = 147.19, df = 18, p-value < 2.2e-16
##
## +----------------------+
If p-value < 0.05, we reject our HoNull Hypothesis that the examined variables are independent of each other.