Calculates cesarean delivery rates and Wilson confidence intervals for processed natality datasets created by prepare_birth_data().

summarize_cesarean_rate(
  df,
  by = NULL,
  NTSV = FALSE,
  hospital_only = FALSE,
  us_born_only = FALSE,
  CI_level = 0.95
)

Arguments

df

A data frame produced by prepare_birth_data().

by

Optional character vector of variable names used for stratification. If NULL (default), overall cesarean rates are returned.

NTSV

If TRUE, restricts the analysis to NTSV births. Default is FALSE.

hospital_only

If TRUE, restricts the analysis to hospital births. Default is FALSE.

us_born_only

If TRUE, restricts the analysis to U.S.-born mothers. Default is FALSE.

CI_level

Confidence level for Wilson confidence intervals. Default is 0.95.

Value

A data frame containing:

  • total_births: Total births included after filtering.

  • missing: Births with missing cesarean status.

  • cesareans: Number of cesarean deliveries.

  • cesarean_rate: Cesarean delivery rate.

  • lower_CI: Lower Wilson confidence limit.

  • upper_CI: Upper Wilson confidence limit.

If by is specified, stratification variables are included as additional columns.

Details

Optional filters may be applied to restrict analyses to NTSV births, hospital births, and/or U.S.-born mothers. Results may also be stratified by one or more variables.

Cesarean rates are calculated using births with non-missing cesarean status. Births with missing cesarean status are reported in the missing column but are excluded from rate and confidence interval calculations.

When NTSV = TRUE, only births meeting the NTSV definition (NTSV == 1) are retained.

When hospital_only = TRUE, only hospital births (hospital == 1) are retained.

When us_born_only = TRUE, only U.S.-born mothers (nativity == 1) are retained. Foreign-born mothers and records with unknown nativity are excluded.

Examples

synthetic_files <- c(
  system.file(
    "extdata",
    "synthetic_2023.txt",
    package = "natalityr"
  ),
  system.file(
    "extdata",
    "synthetic_2024.txt",
    package = "natalityr"
  )
)

natality <- prepare_birth_data(synthetic_files)

summarize_cesarean_rate(natality)
#>   total_births missing cesareans cesarean_rate  lower_CI  upper_CI
#> 1           80       0        40           0.5 0.3929742 0.6070258