| Title: | Simulate Pregnancy Data with Time-Varying Exposure |
| Version: | 0.1.0 |
| Description: | Simulates pregnancy data in a time-to-event framework, allowing a time-varying exposure. Default parameters for gestational length and exposure timing are provided but may also be user-specified. Users can further specify hazard ratios for spontaneous and non-spontaneous live birth and late miscarriage/stillbirth following exposure. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Depends: | R (≥ 3.5) |
| LazyData: | true |
| Config/roxygen2/version: | 8.1.0 |
| Suggests: | knitr, rmarkdown, survival, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Packaged: | 2026-09-16 05:47:18 UTC; SINS |
| Author: | Siri N. Skodvin [aut, cre], Miriam Gjerdevik [ctb], Hakon K. Gjessing [ctb] |
| Maintainer: | Siri N. Skodvin <siri.skodvin@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-27 16:10:02 UTC |
Default daily hazard of exposure
Description
Approximate daily hazard rates of exposure by gestational day, from day 1 through day 301 of gestation.
Usage
haz.exposure.default
Format
A numeric vector of length 301. Element i corresponds to
gestational day i.
Default daily hazard of late miscarriage/stillbirth
Description
Approximate daily hazard rates of late miscarriage/stillbirth by gestational day, from day 1 through day 301 of gestation. Hazard rates are set to 0 for gestational days 1 through 83 because the data used to specify the default hazard do not include early miscarriage. Positive hazard rates begin at gestational day 84.
Usage
haz.late.miscarriage.stillbirth.default
Format
A numeric vector of length 301. Element i corresponds to
gestational day i.
Default daily hazard of non-spontaneous live birth
Description
Approximate daily hazard rates of non-spontaneous live birth by gestational day, from day 1 through day 301 of gestation. Hazard rates are set to 0 for gestational days 1 through 153, reflecting that 22 weeks of gestation is approximately the lower gestational-age limit at which active neonatal care is considered in Norwegian clinical practice. Positive hazard rates begin at gestational day 154.
Usage
haz.nonspont.livebirth.default
Format
A numeric vector of length 301. Element i corresponds to
gestational day i.
Default daily hazard of spontaneous live birth
Description
Approximate daily hazard rates of spontaneous live birth by gestational day, from day 1 through day 301 of gestation. Hazard rates are set to 0 for gestational days 1 through 153, reflecting that 22 weeks of gestation is approximately the lower gestational-age limit at which active neonatal care is considered in Norwegian clinical practice. Positive hazard rates begin at gestational day 154.
Usage
haz.spont.livebirth.default
Format
A numeric vector of length 301. Element i corresponds to
gestational day i.
Simulate distributions of pregnancy outcomes and gestational duration
Description
Calculates proportions of pregnancies experiencing spontaneous live birth, non-spontaneous live birth, or late miscarriage/stillbirth by gestational age and timing of exposure, given daily hazard rates and hazard ratios.
Usage
simPregProp(
haz.spont.livebirth = haz.spont.livebirth.default,
haz.nonspont.livebirth = haz.nonspont.livebirth.default,
haz.late.miscarriage.stillbirth = haz.late.miscarriage.stillbirth.default,
haz.exposure = haz.exposure.default,
hr.spont.livebirth = NULL,
hr.nonspont.livebirth = NULL,
hr.late.miscarriage.stillbirth = NULL
)
Arguments
haz.spont.livebirth |
Numeric vector of daily hazards of spontaneous
live birth. Defaults to the package-provided
|
haz.nonspont.livebirth |
Numeric vector of daily hazards of
non-spontaneous live birth. Defaults to the package-provided
|
haz.late.miscarriage.stillbirth |
Numeric vector of daily hazards of
late miscarriage/stillbirth. Defaults to the package-provided
|
haz.exposure |
Numeric vector of daily hazards of exposure. Defaults
to the package-provided |
hr.spont.livebirth |
Numeric vector of hazard ratios for spontaneous
live birth following exposure. Must have the same length as the hazard
vectors. Defaults to |
hr.nonspont.livebirth |
Numeric vector of hazard ratios for
non-spontaneous live birth following exposure. Must have the same length
as the hazard vectors. Defaults to |
hr.late.miscarriage.stillbirth |
Numeric vector of hazard ratios for
late miscarriage/stillbirth following exposure. Must have the same length
as the hazard vectors. Defaults to |
Value
A data frame with class preg.prop containing the following
columns:
- GA
Gestational age in days.
- ExpGA
Gestational age at exposure.
NAindicates no exposure.- Outcome
Pregnancy outcome:
spontaneous_live_birth,nonspontaneous_live_birth, orlate_miscarriage_stillbirth.- Prop
Proportion of pregnancies corresponding to the gestational age, exposure timing, and outcome combination.
Examples
# Use the package-provided default hazard vectors
data.prop <- simPregProp()
head(data.prop)
# Illustrate an exposure associated with increased risk of preterm live birth
hr <- rep(1, 301)
hr[1:258] <- 2
data.prop <- simPregProp(
hr.spont.livebirth = hr,
hr.nonspont.livebirth = hr
)
Sample pregnancies from simulated distributions
Description
Generates a sample of pregnancy outcomes from the proportions produced by
simPregProp().
Usage
simPregSamp(df, n, expand = FALSE)
Arguments
df |
A data frame with class |
n |
Number of pregnancies to sample. Must be a positive integer. |
expand |
Logical value indicating whether to expand the sampled
counts into one row per pregnancy. Defaults to |
Value
A data frame with class data.frame containing the sampled
pregnancy outcomes and their frequencies. The returned data frame retains
the columns of df and includes an additional Freq column containing
the number of sampled pregnancies for each gestational age, exposure
timing, and outcome combination.
If expand = TRUE, rows are expanded so that each row represents one
pregnancy, and Freq is set to 1.
Examples
# Generate pregnancy outcome proportions
data.prop <- simPregProp()
# Sample 1000 pregnancies
data.samp <- simPregSamp(data.prop, 1000)
head(data.samp)
# Expand to one row per pregnancy
data.samp <- simPregSamp(data.prop, 1000, expand = TRUE)
head(data.samp)