simPregSamp: Sample pregnancies from simulated distributions

View source: R/simPregSamp.R

simPregSampR Documentation

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 preg.prop, such as the output from simPregProp().

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 FALSE.

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)


simPreg documentation built on Sept. 27, 2026, 5:06 p.m.