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(readr)
setwd("C:/PMS/Data_Science/Data101/Project 1")
birth<- read_csv("births.csv")
## Rows: 150 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): premature, sex_baby, smoke
## dbl (6): f_age, m_age, weeks, visits, gained, weight
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Description: Main reason I picked North Carolina births, 100 cases is mainly wanted to see if there is co-relation between premature babies where mother was a smoke. 8 babies born were prematued with less than 7 Lbs out of 50 babies. this is like 16% of the babies were premature.
# Read data
births <- read.csv("births.csv")
#Filtering for records or rows for premature babies with less than 7 lbs and mother was a smoker
premie_smoker_lt7 <- subset(
births,
premature == "premie" &
weight < 7 &
smoke == "smoker"
)
# Displaying the results
premie_smoker_lt7
## f_age m_age weeks premature visits gained weight sex_baby smoke
## 8 28 21 35 premie 9 15 5.50 female smoker
## 9 22 20 32 premie 5 40 2.69 male smoker
## 19 28 27 33 premie 6 18 4.75 male smoker
## 22 NA 38 32 premie 10 16 2.19 female smoker
## 47 30 25 35 premie 15 40 4.50 male smoker
## 67 29 31 36 premie 8 42 5.94 male smoker
## 126 NA 18 33 premie 7 40 1.69 male smoker
## 128 37 33 36 premie 11 15 6.31 male smoker
# Number of matching cases
nrow(premie_smoker_lt7)
## [1] 8
# Plot Bar Chart Showing Each Baby's Weight
library(dplyr)
library(ggplot2)
premie_smoker_lt7 <- births %>%
filter(
premature == "premie",
weight < 7,
smoke == "smoker"
) %>%
mutate(case_id = row_number())
ggplot(premie_smoker_lt7,
aes(x = factor(case_id), y = weight, fill = sex_baby)) +
geom_col() +
geom_text(aes(label = weight),
vjust = -0.3,
size = 3) +
labs(
title = "Premature Babies (< 7 lbs) Born to Smoking Mothers",
x = "Case",
y = "Weight (lbs)",
) +
theme_minimal()
My analysis focused on identifying premature babies weighing less than 7 pounds whose mothers smoked during pregnancy. By filtering the dataset using these criteria, I isolated a subgroup of newborns that may be at higher risk for adverse birth outcomes. The visualization highlighted variations in birth weight within this group, providing a clearer understanding of the characteristics of these births. The findings suggest that smoking during pregnancy is present among several cases of low-birth-weight premature births. While this analysis is descriptive and does not establish causation, it identifies patterns and need further investigation. Visualizing the data also makes it easier to communicate these patterns and identify potential trends.