Cleaning Obstetrics and Periodontal Therapy Dataset
Learning Goals
- Introduce the R package
medicaldataand the Obstetrics and Periodontal Therapy Dataset. - Clean dataset so that it can be used to create clinical summary table using
gtsummary.
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 ”; “ ” = 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_childbeNoifN.living.kidsisNAor0andYesotherwise.previous_live_preterm_birthbeNAif there is no previous pregnancy.NAif there is previous pregnancy but number of living kidsN.living.kidsisNAandLive.PTBisNo.NAif there is previous pregnancy but number of living kidsN.living.kidsisNAandLive.PTBisNA.NAif there is previous pregnancy but number of living kidsN.living.kidsis0.Noif there is previous pregnancy, number of living kidsN.living.kidsis1to9andLive.PTBisNo.Yesif there is previous pregnancy, number of living kidsN.living.kidsisNAandLive.PTBisYes.Yesif there is previous pregnancy, number of living kidsN.living.kidsis1to9andLive.PTBisYes.
Spont.abbeNAif there is no previous pregnancy.Noif there is previous pregnancy, spontaneous abortionSpont.abisNAorNo.Yesif there is previous pregnancy, spontaneous abortionSpont.abisYes.
Induced.abbeNAif there is no previous pregnancy.Noif there is previous pregnancy, induced abortionInduced.abisNAorNo.Yesif there is previous pregnancy, induced abortionInduced.abisYes.
Any.stillbirthbeNAif there is no previous pregnancy.Noif there is previous pregnancy, stillbirthAny.stillbirthisNAorNo.Yesif there is previous pregnancy, stillbirthAny.stillbirthisYes.
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.weeksbe the columnGA.at.outcomedivided by 7.Preg_duration_32beYesifGA.at.outcome.weeksis less than 32.Nootherwise.
Preg_duration_35beYesifGA.at.outcome.weeksis less than 35.Nootherwise.
Preg_duration_37beYesifGA.at.outcome.weeksis less than 37.Nootherwise.
Preg_duration_37_regressionbe1ifGA.at.outcome.weeksis less than 37.0otherwise.
Outcome Birth Weight
We create the following new columns to identify those with low birth weights.
Birthweight_2500beNAifBirthweightisNA.YesifBirthweightis less than 2500.Nootherwise.
Birthweight_2500_regressionbeNAifBirthweightisNA.1ifBirthweightis less than 2500.0otherwise.
Birthweight_1500beNAifBirthweightisNA.YesifBirthweightis less than 1500.Nootherwise.
Outcome Preterm Live Birth
We create the following new columns to identify those with pre-term live birth.
Recall GA.at.outcome.weeksis the columnGA.at.outcomedivided by 7.Have_Live_BirthbeYesifBirth.outcomeisLive birth.Nootherwise.
Preterm_32beNAifBirth.outcomeisNon-live birth.YesifBirth.outcomeisLive birthandGA.at.outcome.weeksis less than 32.Nootherwise.
Preterm_35beNAifBirth.outcomeisNon-live birth.YesifBirth.outcomeisLive birthandGA.at.outcome.weeksis less than 35.Nootherwise.
Preterm_37beNAifBirth.outcomeisNon-live birth.YesifBirth.outcomeisLive birthandGA.at.outcome.weeksis less than 37.Nootherwise.