Data Analysis

Author

OJALA BRIAN

# Clear R environment
rm(list = ls())
# Setwd
setwd("C:/RB")
# Load data set
library(readxl)
birth <- read_excel("birth.xls",sheet="Sheet1")
View(birth)

Subsetting

birth1 <- subset(birth, select=-c(id))
View(birth1)

Data cleaning

#Data cleaning
birth1$ui<-ordered(birth$ui,levels=c(0,1),
                     labels=c("No","Yes"))
birth1$smoke<-ordered(birth$smoke,levels=c(0,1),
                   labels=c("No","Yes"))
birth1$ht<-ordered(birth$ht,levels=c(0,1),
                   labels=c("No","Yes"))
birth1$smoke<-as.factor(birth1$smoke)
birth1$race<-as.factor(birth1$race)
birth1$ht<-as.factor(birth1$ht)
birth1$ui<-as.factor(birth1$ui)
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(gtsummary)
library(flextable)

Attaching package: 'flextable'
The following object is masked from 'package:gtsummary':

    continuous_summary
library(officer)

Attaching package: 'officer'
The following object is masked from 'package:readxl':

    read_xlsx
library(broom)
p08 <-birth1 %>%
  tbl_summary(
     by = low,  # Uncomment if you want group-wise summary
    statistic = list(
      all_continuous() ~ "{median} ({p25}, {p75})",
      all_categorical() ~ "{n} ({p}%)"
    ),
    percent = "column",
    missing = "no"
  ) %>%
    add_overall() %>%
   add_p(pvalue_fun = ~style_pvalue(.x, digits = 2)) %>%
   modify_footnote(all_stat_cols() ~ "Median (IQR)") %>%
   modify_spanning_header(c("stat_1", "stat_2") ~ "**Birth Status **") %>%
  modify_caption("Table 1: Maternal mothers characteristics") %>%
  bold_labels() %>%
  add_n() %>%
  as_flex_table()
sect_properties <- prop_section(page_size = page_size(orient = "portrait"))#, width = 8.3, height = 11.7)
save_as_docx(p08,path="Table1a.docx", pr_section = sect_properties)
p08

Birth Status

Characteristic

N

Overall
N = 1891

0
N = 1301

1
N = 591

p-value2

age

189

23.0 (19.0, 26.0)

23.0 (19.0, 28.0)

22.0 (19.0, 25.0)

0.25

lwt

189

121 (110, 140)

124 (113, 147)

120 (103, 130)

0.013

race

189

0.082

Black

26 (14%)

15 (12%)

11 (19%)

Other

67 (35%)

42 (32%)

25 (42%)

White

96 (51%)

73 (56%)

23 (39%)

smoke

189

74 (39%)

44 (34%)

30 (51%)

0.026

ptl

189

<0.001

0

159 (84%)

118 (91%)

41 (69%)

1

24 (13%)

8 (6.2%)

16 (27%)

2

5 (2.6%)

3 (2.3%)

2 (3.4%)

3

1 (0.5%)

1 (0.8%)

0 (0%)

ht

189

12 (6.3%)

5 (3.8%)

7 (12%)

0.052

ui

189

28 (15%)

14 (11%)

14 (24%)

0.020

ftv

189

0.29

0

100 (53%)

64 (49%)

36 (61%)

1

47 (25%)

36 (28%)

11 (19%)

2

30 (16%)

23 (18%)

7 (12%)

3

7 (3.7%)

3 (2.3%)

4 (6.8%)

4

4 (2.1%)

3 (2.3%)

1 (1.7%)

6

1 (0.5%)

1 (0.8%)

0 (0%)

1Median (IQR)

2Wilcoxon rank sum test; Pearson's Chi-squared test; Fisher's exact test