Cleaning Obstetrics and Periodontal Therapy Dataset

Author

Jeremy Selva

Learning Goals

Data Preparation

In this section, we highlight in detail how the Obstetrics and Periodontal Therapy Dataset from R package medicaldata is prepared so that we can use gtsummary to create the clinical summary table.

Columns that we need

The dataset can be obtain from medicaldata::opt.

The columns that we use are

  • PID: Participant ID.
  • Group: Randomized treatment assignment, factor.
    • “T” = Intervention.
    • “C” = Control.
  • Age: Age of participant at baseline (years), numeric.
  • Education: Education level of participant, factor.
    • “LT 8 yrs ” = Less than 8 years.
    • “8-12 yrs ” = 8 to 12 years.
    • “MT 12 yrs” = More than 12 years.
    • blank = Missing.
  • Black: Black participant (self-identified), factor; “Yes”, “No ”, “   ”.
  • White: White participant (self-identified), factor; “Yes”, “No ”, “   ”.
  • Asian: Asian participant (self-identified), factor; “Yes”, “No ”, “   ”.
  • Nat.Am: Native American participant, incl. Latin Americans with aboriginal origin(self-identified), factor; “Yes”, “No”, “   ”.
  • Hisp: Hispanic participant (self-identified), factor; “Yes”, “No ”, “   ”.
  • BMI: Body mass index, numeric.
  • Diabetes: Whether participant had diabetes at baseline (self-reported), factor; “Yes”, “No ”, “   ”.
  • Hypertension: Whether participant had chronic hypertension at baseline, factor; “Yes”, “No ”, “   ”.
  • Drug.Add: Self-reported participant history of drug addiction, factor; “Yes”, “No ”, “   ”.
  • Use.Alc: Self-reported participant history of alcohol use, factor; “Yes”, “No ”, “   ”.
  • Use.Tob: Self-reported participant history of tobacco use, factor; “Yes”, “No ”, “   ”.
  • Prev.preg: Any previous pregnancy, factor; “Yes”, “No ”.
  • Spont.ab: Previous spontaneous abortion, factor; “Yes”, “No ”, “   ” = Missing or no previous pregnancies (Prev.preg = No).
  • Induced.ab: Previous induced abortion, factor; “Yes”, “No ”, “   ” = Missing or no previous pregnancies (Prev.preg = No).
  • Any.stillbirth: Previous stillbirth, factor; “Yes”, “No ”, “   ” = Missing or no previous pregnancies (Prev.preg = No).
  • Live.PTB: Previous live preterm birth for those with any previous pregnancy, factor; “Yes”, “No ”, “   ” = Missing or no previous pregnancies (Prev.preg = No).
  • Any.live.ptb.sb.sp.ab.in.ab: Any previous live pre-term birth, stillbirth, spontaneous abortion, or induced abortion, factor; “Yes”, “No ”, “   ” = Missing or no previous pregnancies (Prev.preg = No).
  • N.living.kids: Number of living children the subject had at baseline, numeric.
  • Birth.outcome: Birth outcome, factor,
    • “Elective abortion  ”.
    • “Live birth              ”.
    • “Lost to FU            ” = Lost to Follow-Up.
    • “Non-live birth      ” = Stillbirth or spontaneous abortion.
  • Preg.ended...37.wk: Whether the pregnancy ended before gestational age 37 weeks (259 days), factor, “Yes”; “No&nbsp”; “   ” = Lost to Follow-Up.
  • GA.at.outcome: Gestational age at end of pregnancy, or at mother’s last follow-up visit if lost to follow-up, numeric.
  • Birthweight: Infant birth weight at time of birth, abstracted from obstetrical records (grams), numeric.

We use stringr::str_trim to remove any whitespace in the factor columns.

Treatment and Control

Next, in the Group column, we rename C as Control and T as Treatment.

Education

In the Education column, we rename LT 8 yrs as ≤8 yr, 8-12 yrs as 9-12 yr and MT 12 yrs as > 12 yr to match the labels as seen in Table 1.

Race/Ethnicity

In the Hisp column, we fill in the empty strings “” as No. We also convert Black, White, Asian, Nat.Am and Hisp to factors.

Clinical Risk Factors

In the Hypertension column, we rename N as No and Y as Yes. In the Diabetes, Drug.Add, Use.Alc and Use.Tob columns, we convert “” to NA. We also convert Hypertension, Diabetes, Drug.Add, Use.Alc and Use.Tob to factors.

Previous pregnancy

In the Spont.ab, Induced.ab, Any.stillbirth, Live.PTB and Any.live.ptb.sb.sp.ab.in.ab columns, we convert “” to NA

To match the labels as close as possible to Table 1, we let

  • have_living_child be No if N.living.kids is NA or 0 and Yes otherwise.
  • previous_live_preterm_birth be
    • NA if there is no previous pregnancy.
    • NA if there is previous pregnancy but number of living kids N.living.kids is NA and Live.PTB is No.
    • NA if there is previous pregnancy but number of living kids N.living.kids is NA and Live.PTB is NA.
    • NA if there is previous pregnancy but number of living kids N.living.kids is 0.
    • No if there is previous pregnancy, number of living kids N.living.kids is 1 to 9 and Live.PTB is No.
    • Yes if there is previous pregnancy, number of living kids N.living.kids is NA and Live.PTB is Yes.
    • Yes if there is previous pregnancy, number of living kids N.living.kids is 1 to 9 and Live.PTB is Yes.
  • Spont.ab be
    • NA if there is no previous pregnancy.
    • No if there is previous pregnancy, spontaneous abortion Spont.ab is NA or No.
    • Yes if there is previous pregnancy, spontaneous abortion Spont.ab is Yes.
  • Induced.ab be
    • NA if there is no previous pregnancy.
    • No if there is previous pregnancy, induced abortion Induced.ab is NA or No.
    • Yes if there is previous pregnancy, induced abortion Induced.ab is Yes.
  • Any.stillbirth be
    • NA if there is no previous pregnancy.
    • No if there is previous pregnancy, stillbirth Any.stillbirth is NA or No.
    • Yes if there is previous pregnancy, stillbirth Any.stillbirth is Yes.

Outcome Pregnancy Duration

We create the following new columns to identify those with pregnancy duration if less than 32, 35 and 37 weeks.

  • GA.at.outcome.weeks be the column GA.at.outcome divided by 7.
  • Preg_duration_32 be
    • Yes if GA.at.outcome.weeks is less than 32.
    • No otherwise.
  • Preg_duration_35 be
    • Yes if GA.at.outcome.weeks is less than 35.
    • No otherwise.
  • Preg_duration_37 be
    • Yes if GA.at.outcome.weeks is less than 37.
    • No otherwise.
  • Preg_duration_37_regression be
    • 1 if GA.at.outcome.weeks is less than 37.
    • 0 otherwise.

Outcome Birth Weight

We create the following new columns to identify those with low birth weights.

  • Birthweight_2500 be
    • NA if Birthweight is NA.
    • Yes if Birthweight is less than 2500.
    • No otherwise.
  • Birthweight_2500_regression be
    • NA if Birthweight is NA.
    • 1 if Birthweight is less than 2500.
    • 0 otherwise.
  • Birthweight_1500 be
    • NA if Birthweight is NA.
    • Yes if Birthweight is less than 1500.
    • No otherwise.

Outcome Preterm Live Birth

We create the following new columns to identify those with pre-term live birth.

  • Recall GA.at.outcome.weeks is the column GA.at.outcome divided by 7.
  • Have_Live_Birth be
    • Yes if Birth.outcome is Live birth.
    • No otherwise.
  • Preterm_32 be
    • NA if Birth.outcome is Non-live birth.
    • Yes if Birth.outcome is Live birth and GA.at.outcome.weeks is less than 32.
    • No otherwise.
  • Preterm_35 be
    • NA if Birth.outcome is Non-live birth.
    • Yes if Birth.outcome is Live birth and GA.at.outcome.weeks is less than 35.
    • No otherwise.
  • Preterm_37 be
    • NA if Birth.outcome is Non-live birth.
    • Yes if Birth.outcome is Live birth and GA.at.outcome.weeks is less than 37.
    • No otherwise.

Download processed data