calculate_test_date | R Documentation |
Calculates the recommended date for taking a pregnancy test based on a start date and type. The function supports both urine and blood tests, with blood tests typically being viable 2 days earlier than urine tests.
calculate_test_date(
start_date,
start_type = c("LMP", "conception", "transfer_day_3", "transfer_day_5",
"transfer_day_6"),
cycle = 28,
test_type = c("urine", "blood")
)
start_date |
Date or character string representing a date, e.g. "YYYY-MM-DD".
The starting reference date. The interpretation of this date depends on the
|
start_type |
character. One of:
|
cycle |
numeric. Length of menstrual cycle in days. Only used when
|
test_type |
character. One of:
|
The test date is calculated as follows:
First, the ovulation date is calculated (see calculate_due_date()
for details)
For urine tests: 14 days are added to the ovulation date
For blood tests: 12 days are added to the ovulation date
Blood tests can typically detect pregnancy earlier than urine tests due to their greater sensitivity in detecting hCG hormone levels.
If start_date
is a character string, the conversion to a Date
is handled by anytime::anydate()
.
Returns a Date object invisibly representing the recommended test date. Also prints informative messages showing:
The recommended date for a urine test
The recommended date for a blood test
calculate_due_date()
for calculating the estimated due date
# Calculate test date from last menstrual period
calculate_test_date("2025-01-31")
# Calculate for blood test from conception date
calculate_test_date(
start_date = "5023-02-14",
start_type = "conception",
test_type = "blood"
)
# Calculate from day 5 embryo transfer
calculate_test_date(
as.Date("2025-02-19"),
start_type = "transfer_day_5"
)
# Calculate with non-standard cycle length
calculate_test_date("2025-01-31", cycle = 35)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.