Introduction

Research Question: Difference in Mean Baby Weight between Smokers and Nonsmokers The data I used for this Project is titled babies provided by OpenIntro (link: https://www.openintro.org/data/index.php?data=babies) The Child Health and Development Studies conducted a study investigating all pregnancies between 1960-1967 among women in Kaiser Foundation Health in San Francisco. This data recorded 1236 different cases of birth and 8 variables including id number, birthweight of baby in ounces, length of gestation, the mother’s age, height and weight, and whether the mother is a smoker or a non-smoker.

The variables used in this data set will help in finding whether the birthweight of the baby differs when the mother is a smoker or a nonsmoker. birth weight (bwt) - birthweight, in ounces Smoke - binary indicator for whether the mother smokes Case - id number

Data Analysis

I will load in my data set I downloaded, and clean the data. I will also check the head and structure of this data set. I will select the three variables I need for my data set, which is birth weight, smoke, and case id number. Once my data set is cleaned, I will check the summary of the data set and perform a difference in means independent test.

For my visual I will create a histogram and a box plot to get a closer look at the birth weight of babies with mothers who smoke versus mothers who don’t smoke. The box plot will overlook the averages, 1st and 3rd quadrant of the birth weights.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
setwd("C:/Users/ninar/OneDrive/12")

babies <- read.csv("babies.csv")
str(babies)
## 'data.frame':    1236 obs. of  8 variables:
##  $ case     : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ bwt      : int  120 113 128 123 108 136 138 132 120 143 ...
##  $ gestation: int  284 282 279 NA 282 286 244 245 289 299 ...
##  $ parity   : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ age      : int  27 33 28 36 23 25 33 23 25 30 ...
##  $ height   : int  62 64 64 69 67 62 62 65 62 66 ...
##  $ weight   : int  100 135 115 190 125 93 178 140 125 136 ...
##  $ smoke    : int  0 0 1 0 1 0 0 0 0 1 ...
 head(babies)
##   case bwt gestation parity age height weight smoke
## 1    1 120       284      0  27     62    100     0
## 2    2 113       282      0  33     64    135     0
## 3    3 128       279      0  28     64    115     1
## 4    4 123        NA      0  36     69    190     0
## 5    5 108       282      0  23     67    125     1
## 6    6 136       286      0  25     62     93     0
babies_cleaned <- babies |>
  select(case, bwt, smoke)


head(babies_cleaned)
##   case bwt smoke
## 1    1 120     0
## 2    2 113     0
## 3    3 128     1
## 4    4 123     0
## 5    5 108     1
## 6    6 136     0
# Mean and data of birthweight of babies from mothers who does'nt smoke (0) and mothers who smoke (1)
bwt_summary <- babies_cleaned |>
  group_by(smoke)|>
  filter(!is.na(smoke)) |>
  summarise(
    mean_bwt = mean(bwt, na.rm = TRUE),
    median_bwt = median(bwt, na.rm = TRUE),
    sd_bwt = sd(bwt, na.rm = TRUE),
    min_bwt = min(bwt, na.rm = TRUE),
    max_bwt = max(bwt, na.rm = TRUE)
  )
bwt_summary
## # A tibble: 2 × 6
##   smoke mean_bwt median_bwt sd_bwt min_bwt max_bwt
##   <int>    <dbl>      <dbl>  <dbl>   <int>   <int>
## 1     0     123.        123   17.4      55     176
## 2     1     114.        115   18.1      58     163

Visuals

#Boxplot
table(babies_cleaned$smoke)
## 
##   0   1 
## 742 484
babies_cleaned$smoke <- factor(
  babies_cleaned$smoke, 
  levels = c(0, 1), 
  labels = c("nonsmokers", "smokers")
)

boxplot(bwt ~ smoke, 
        data = babies_cleaned, 
        ylab = "birth weight (ounces) ", 
        xlab = "smokers",
        cex.axis = 0.9
)

barplot(
  bwt_summary$mean_bwt,
  names.arg = c("Nonsmokers", "Smokers"),
  main = "Birthweight of babies between smokers and nonsmokers",
  xlab = "Smoker status",
  ylab = "Mean birthweight in ounces",
  col = c("darkgreen", "darkred"),
  ylim = c(0, 160)
)

2 sample independent T-test

t.test(bwt ~ smoke, data = babies_cleaned)
## 
##  Welch Two Sample t-test
## 
## data:  bwt by smoke
## t = 8.5813, df = 1003.2, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group nonsmokers and group smokers is not equal to 0
## 95 percent confidence interval:
##   6.89385 10.98148
## sample estimates:
## mean in group nonsmokers    mean in group smokers 
##                 123.0472                 114.1095

Statistical Analysis To find the difference in mean baby weight between smokers and nonsmokers

Hypothesis: H₀: μ₁= μ₂;There is no difference in the birth weight of a baby if the mother is a smoker or not
Ha: μ₁ ≠ μ₂ There is a significant difference in birth weight of a baby when the mother is a smoker

Significance level a = 0.05

We reject the null hypothesis because the p-value is 2.2e-16 which is less than 0.05. At a 5% significance level, there is enough evidence that the birth weight in babies differs when a mother is a smoker or not. This means the baby may weigh lower if the mother is a smoker.

Conclusion

My data analysis shows a key differences of birth weight of baby when a mother smokes. The average birth weight of babies who were born to nonsmokers was 123.05 ounces, while the birth weight of babies were born to smokers had a mean weight of 114.11 ounces.it is 95% confident the babies that come from nonsmokers are 6.89 and 10.98 higher than mothers who smoke.

References summarary function: https://intro2r.com/summarising-data-frames.html

box plot: https://intro2r.com/simple-base-r-plots.html#box-and-violin-plots

welch two sample t test: https://intro2r.com/one-and-two-sample-tests.html