impute_dob: Impute a vector of dates of birth

Description Usage Arguments Details Value See Also Examples

View source: R/impute.R

Description

Given dates and ages, randomly generate dates of birth. Ages are measured in complete years and/or completed months. The dates of birth are generated from a uniform distribution: all dates that fall within the range implied by the date, age_years, and age_months arguments have the same chance of being selected. For instance, if date is "2000-12-31" and age is 0, then every date from "2000-01-01" to "2000-12-31" has the same 1/366 chance of being selected.

Usage

1
impute_dob(date, age_years = NULL, age_months = NULL)

Arguments

date

A vector of dates on which age is measured.

age_years

Age measured in years.

age_months

Age measured in months.

Details

The range of possible dates depends on whether age is specified in years or months. If age is specified in years only, then the range is one year. If age is specified in months, or in a combination of years and months, then the range is one month. See below for an example.

ADD DISCUSSION OF SUBTLETIES OF MEASURING AGE

date must have class Date, or can be coerced to class Date via function as.Date.

date and age must have the same length.

Value

A vector of class Date

See Also

impute_date

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
impute_dob(date = c("2000-06-30", "2001-01-01"),
           age_years = c(4, 10))
impute_dob(date = c("2000-06-30", "2001-01-01"),
           age_months = c(3, 11))
impute_dob(date = c("2000-06-30", "2001-01-01"),
           age_years = c(0, 4),
           age_months = c(3, 11))
## if age is specified in months, then the range of
## possible dates of birth is narrower than if it
## is specified in years
ans_years <- impute_dob(date = rep("2020-01-01", 100),
                        age_years = 1)
ans_months <- impute_dob(date = rep("2020-01-01", 100),
                         age_months = 12)
range(ans_years) # up to one year
range(ans_months) # up to one month

johnrbryant/demprep documentation built on Dec. 31, 2021, 11:58 a.m.