This function processes age data in a survey object. It imputes ages from ranges, handles missing values, and assigns age groups.
assign_age_groups(
survey,
age_limits = NULL,
estimated_participant_age = c("mean", "sample", "missing"),
estimated_contact_age = c("mean", "sample", "missing"),
missing_participant_age = c("remove", "keep"),
missing_contact_age = c("remove", "sample", "keep", "ignore")
)The survey object with processed age data.
a survey() object
lower limits of the age groups over which to construct the matrix. Defaults to NULL. If NULL, age limits are inferred from participant and contact ages.
if set to "mean" (default), people whose ages are given as a range (in columns named "..._est_min" and "..._est_max") but not exactly (in a column named "..._exact") will have their age set to the mid-point of the range; if set to "sample", the age will be sampled from the range; if set to "missing", age ranges will be treated as missing
if set to "mean" (default), contacts whose ages are given as a range (in columns named "..._est_min" and "..._est_max") but not exactly (in a column named "..._exact") will have their age set to the mid-point of the range; if set to "sample", the age will be sampled from the range; if set to "missing", age ranges will be treated as missing
if set to "remove" (default), participants without age information are removed; if set to "keep", participants with missing age are kept and treated as a separate age group
if set to "remove" (default), participants that
have contacts without age information are removed; if set to "keep",
contacts with missing age are kept and treated as a separate age group;
if set to "ignore", contacts with missing age are ignored in the contact
analysis. The "sample" option is defunct (errors). For contacts that
have only an age range (rather than a truly missing age),
estimated_contact_age controls how the range is resolved into a single
age; it is not a substitute for missing_contact_age when the age is
entirely missing.
polymod_grouped <- assign_age_groups(polymod)
polymod_grouped
polymod_custom <- assign_age_groups(polymod, age_limits = c(0, 5, 10, 15))
polymod_custom
Run the code above in your browser using DataLab