calculate_trimesters: Calculate trimesters and preterm births

View source: R/calculate.R

calculate_trimestersR Documentation

Calculate trimesters and preterm births

Description

calculate_trimesters calculates dates for pregnancy trimesters and if the birth was pre-term.

Usage

calculate_trimesters(
  data,
  dob,
  gestation,
  avg_pregnancy = 40,
  avg_tri = 13,
  buffer = 0
)

Arguments

data

A data object.

dob

The column name for date of birth.

gestation

The column name containing the numeric weeks of gestation (optional).

avg_pregnancy

Integer value for the expected number of weeks in an average pregnancy (default: 40).

avg_tri

Integer value for the expected length of each trimester (default: 13 weeks).

buffer

Integer value. Will extend the date of first trimester. Useful when you want to keep average pregnancy the same but want to include a higher maximum of pregnancies (i.e. longer third trimester).

Details

Uses the date of birth (required field) and any available information on the gestation time (in weeks) to calculate the start and end of the trimesters, in separate columns, along with a flag for a suspected preterm birth. If no gestation information is provided, the default average pregnancy length of 40 weeks is used. One can extend the length of pregnancy by adjusting avg_pregnancy but it is advised to use buffer to extend the start date of the first trimester instead. The average length of each trimester can also be adjusted from the default of 13 weeks; again, it is advised to leave this at the accepted default.

Value

A new dataset with the start and end dates of trimesters and whether or not the birth is suspected as pre-term.

Examples

tempData <- data.frame(date_of_birth = as.Date(c('1991-01-01', '1990-02-04', '1992-01-21')), gestation = c(35, 41, NA))
calculate_trimesters(tempData, date_of_birth, gestation)


al-obrien/farrago documentation built on April 14, 2023, 6:20 p.m.