| Title: | Map Quantiles for Physical Activity from 'NHANES' |
|---|---|
| Description: | Maps physical activity from the National Health and Nutrition Examination Survey ('NHANES') study into population-based quantiles. |
| Authors: | John Muschelli [aut, cre] (ORCID: <https://orcid.org/0000-0001-6469-1750>) |
| Maintainer: | John Muschelli <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0 |
| Built: | 2026-10-11 12:46:04 UTC |
| Source: | https://github.com/jhuwit/mapnhanespa |
map_nhanes_pa_quantiles() adds a population-level quantile column and the
NHANES age category used for each row to a
participant-level data frame. Quantiles are evaluated from NHANES
accelerometer cumulative distribution functions stratified by age category,
sex/gender, measure, and optionally survey wave.
Accepted measure names and their CDF summaries are listed by
nhanes_pa_measure_map(). Unmapped names return missing quantiles and are
listed in a warning.
map_nhanes_pa_quantiles( data, id = NULL, age = "age", sex = "sex", measure = "measure", value = "value", wave = NULL, age_category = NULL, quantile_col = "nhanes_quantile" )map_nhanes_pa_quantiles( data, id = NULL, age = "age", sex = "sex", measure = "measure", value = "value", wave = NULL, age_category = NULL, quantile_col = "nhanes_quantile" )
data |
A data frame with one row per participant-measure observation. |
id |
Optional participant identifier column name. The column is checked when supplied, but otherwise left unchanged. |
age, sex, measure, value
|
Column names in |
wave |
Optional NHANES wave column name or scalar value. Supported values
are |
age_category |
Optional column name containing NHANES age categories
such as |
quantile_col |
Name of the output quantile column. |
data with an added quantile column and age_category_pa_map, the
NHANES age category used to select the CDF. The category is "Overall"
when age = NULL and is taken directly from age_category when supplied.
example_data <- data.frame( id = 1:2, age = c(25, 62), sex = c("Female", "Male"), measure = c("mims", "ssl_steps"), value = c(15000, 7500) ) map_nhanes_pa_quantiles(example_data) map_nhanes_pa_quantiles(example_data, sex = NULL) map_nhanes_pa_quantiles(example_data, age = NULL, wave = "2011-2012") map_nhanes_pa_quantiles(example_data, age = NULL, sex = NULL)example_data <- data.frame( id = 1:2, age = c(25, 62), sex = c("Female", "Male"), measure = c("mims", "ssl_steps"), value = c(15000, 7500) ) map_nhanes_pa_quantiles(example_data) map_nhanes_pa_quantiles(example_data, sex = NULL) map_nhanes_pa_quantiles(example_data, age = NULL, wave = "2011-2012") map_nhanes_pa_quantiles(example_data, age = NULL, sex = NULL)
NHANES PA data
nhanes_measure_datanhanes_measure_data
A data frame with 87619 rows and 9 variables:
ID variable
wave/data release cycle
age category
sex/gender designation
normalized weight for surveys
PSU - sampling unit
sampling stratum
number of valid days of wear >= 1396 minutes
measure that was calculated
value for the measure
NHANES 2011-2012 and 2013-2014 accelerometer data.
Ages are grouped into 10-year bins from [0,10) through [70,80). Ages
greater than or equal to 80 are assigned to the oldest available CDF
category, "[80,85)". Ages greater than 85 also map to "[80,85)", with a
warning by default.
nhanes_pa_age_category(age, warn = TRUE)nhanes_pa_age_category(age, warn = TRUE)
age |
Numeric age in years. |
warn |
Logical. If |
A character vector of NHANES age category labels.
nhanes_pa_age_category(c(8, 25, 84, 90))nhanes_pa_age_category(c(8, 25, 84, 90))
Uses the explicit aliases in nhanes_pa_measure_map() to select the CDF
calculated from the corresponding summary in nhanes_measure_data.
nhanes_pa_measure_cdf( measure, age = NULL, sex = NULL, wave = NULL, age_category = NULL )nhanes_pa_measure_cdf( measure, age = NULL, sex = NULL, wave = NULL, age_category = NULL )
measure |
A single supported measure name. |
age |
Age in years, or |
sex |
Sex/gender, or |
wave |
Optional NHANES wave ( |
age_category |
Optional NHANES age category, used instead of |
A CDF function, or NA_real_ if no CDF is available.
Returns every accepted measure name and the NHANES summary used to build its CDF. Matching ignores case, spaces, underscores, and punctuation. Measures absent from this table have no supported CDF.
nhanes_pa_measure_map()nhanes_pa_measure_map()
A data frame with measure (accepted name) and summary (the
measure in nhanes_measure_data used for its CDF).
Evaluate a single NHANES physical activity quantile
nhanes_pa_quantile( value, age = NULL, sex = NULL, measure, wave = NULL, age_category = NULL )nhanes_pa_quantile( value, age = NULL, sex = NULL, measure, wave = NULL, age_category = NULL )
value |
Observed physical activity value. |
age |
Age in years. Set to |
sex |
Sex/gender. Common values such as |
measure |
Physical activity measure. See |
wave |
Optional NHANES wave. Supported values are |
age_category |
Optional NHANES age category such as |
A numeric quantile in [0, 1], or NA_real_ when no matching CDF is
available.
nhanes_pa_quantile( value = 15000, age = 25, sex = "Female", measure = "mims" ) nhanes_pa_quantile( value = 15000, age = 25, sex = NULL, measure = "mims", wave = "2013-2014" )nhanes_pa_quantile( value = 15000, age = 25, sex = "Female", measure = "mims" ) nhanes_pa_quantile( value = 15000, age = 25, sex = NULL, measure = "mims", wave = "2013-2014" )
Builds every supported CDF combination and stores the result in the internal cache. This covers combined and by-wave CDFs, age-specific and age-overall strata, sex/gender-specific and sex/gender-overall strata, and the overall-overall combination for each supported measure.
precompute_nhanes_pa_cdfs()precompute_nhanes_pa_cdfs()
Invisibly returns a list with the cached combined and by-wave tables.