library(gtsummary)
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
library(ggplot2)
library(magrittr)
library(broom)
library(dataset)
mch_data <- data.frame(
age_mother = c(22, 25, 19, 30, 27, 24, 33, 20, 29, 26),
education_level = c("Primary", "Secondary", "None", "Higher", "Secondary",
"Primary", "Higher", "None", "Secondary", "Primary"),
antenatal_visits = c(4, 5, 2, 6, 3, 4, 7, 1, 5, 4),
birth_weight = c(2.8, 3.1, 2.5, 3.4, 2.9, 3.0, 3.6, 2.3, 3.2, 3.0),
delivery_place = c("Hospital", "Hospital", "Home", "Hospital", "Home",
"Hospital", "Hospital", "Home", "Hospital", "Home"),
child_survival = c("Yes", "Yes", "No", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "Yes")
)
head(mch_data)
#Structure of dataset
str(mch_data)
## 'data.frame': 10 obs. of 6 variables:
## $ age_mother : num 22 25 19 30 27 24 33 20 29 26
## $ education_level : chr "Primary" "Secondary" "None" "Higher" ...
## $ antenatal_visits: num 4 5 2 6 3 4 7 1 5 4
## $ birth_weight : num 2.8 3.1 2.5 3.4 2.9 3 3.6 2.3 3.2 3
## $ delivery_place : chr "Hospital" "Hospital" "Home" "Hospital" ...
## $ child_survival : chr "Yes" "Yes" "No" "Yes" ...
#Summary statistics
summary(mch_data)
## age_mother education_level antenatal_visits birth_weight
## Min. :19.0 Length:10 Min. :1.00 Min. :2.300
## 1st Qu.:22.5 Class :character 1st Qu.:3.25 1st Qu.:2.825
## Median :25.5 Mode :character Median :4.00 Median :3.000
## Mean :25.5 Mean :4.10 Mean :2.980
## 3rd Qu.:28.5 3rd Qu.:5.00 3rd Qu.:3.175
## Max. :33.0 Max. :7.00 Max. :3.600
## delivery_place child_survival
## Length:10 Length:10
## Class :character Class :character
## Mode :character Mode :character
##
##
##
#univariate analysis # Distribution of mother’s age
hist(mch_data$age_mother,
main = "Distribution of Mother's Age",
xlab = "Age of Mother (years)",
col = "lightblue", border = "black")
boxplot(mch_data$birth_weight,
main = "Boxplot of Birth Weight",
ylab = "Birth Weight (kg)",
col = "lightgreen")
barplot(table(mch_data$delivery_place),
main = "Delivery Place Distribution",
col = c("orange", "pink"),
xlab = "Delivery Place",
ylab = "Count")
#bivariate Analysis # Scatter plot: Mother’s age vs Birth weight
plot(mch_data$age_mother, mch_data$birth_weight,
main = "Mother's Age vs Birth Weight",
xlab = "Age of Mother",
ylab = "Birth Weight (kg)",
pch = 19, col = "purple")
boxplot(birth_weight ~ delivery_place, data = mch_data,
main = "Birth Weight by Delivery Place",
xlab = "Delivery Place",
ylab = "Birth Weight (kg)",
col = c("lightcoral", "lightcyan"))
table(mch_data$antenatal_visits, mch_data$child_survival)
##
## No Yes
## 1 1 0
## 2 1 0
## 3 0 1
## 4 0 3
## 5 0 2
## 6 0 1
## 7 0 1
#multivariate visualization
ggplot(mch_data, aes(x = age_mother, y = birth_weight,
color = delivery_place, size = antenatal_visits)) +
geom_point() +
labs(title = "Multivariate Analysis: Age, Birth Weight, Delivery Place, and Antenatal Visits")
#correlation analysis
numeric_data <- mch_data[, c("age_mother", "antenatal_visits", "birth_weight")]
cor(numeric_data)
## age_mother antenatal_visits birth_weight
## age_mother 1.0000000 0.8701858 0.9384344
## antenatal_visits 0.8701858 1.0000000 0.9776258
## birth_weight 0.9384344 0.9776258 1.0000000
#summary report
summary(mch_data)
## age_mother education_level antenatal_visits birth_weight
## Min. :19.0 Length:10 Min. :1.00 Min. :2.300
## 1st Qu.:22.5 Class :character 1st Qu.:3.25 1st Qu.:2.825
## Median :25.5 Mode :character Median :4.00 Median :3.000
## Mean :25.5 Mean :4.10 Mean :2.980
## 3rd Qu.:28.5 3rd Qu.:5.00 3rd Qu.:3.175
## Max. :33.0 Max. :7.00 Max. :3.600
## delivery_place child_survival
## Length:10 Length:10
## Class :character Class :character
## Mode :character Mode :character
##
##
##