Apply a function from the survey package to NHANES data
nhanes_survey(survey_fun, nhanes_data, column, comment_column = "", weights_column = "", filter = NULL, analyze = "values", callback = NULL, ...)
survey_fun | the survey package function (e.g. svyquantile or svymean) |
---|---|
nhanes_data | data frame containing NHANES data |
column | column name of the variable to compute quantiles for |
comment_column | comment column name of the variable |
weights_column | name of the weights column |
filter | logical expression used to subset the data |
analyze | one of "values" or "comments", whether to apply the survey function to the value or comment column. |
callback | optional function to execute on each row of the dataframe |
... | other arguments to pass to the survey function |
a data frame
This function provides a generic way to apply any function from the survey package to NHANES data. RNHANES provides specific wrappers for computing quantiles (nhanes_quantile) and detection frequencies (nhanes_detection_frequency), and this function provides a general way to use any survey function.
# NOT RUN { library(survey) nhanes_data <- nhanes_load_data("EPH", "2011-2012", demographics = TRUE) # Compute the mean of triclosan using the svymean function nhanes_survey(svymean, nhanes_data, "URXTRS", "URDTRSLC", na.rm = TRUE) # Compute the variance using svyvar nhanes_survey(svyvar, nhanes_data, "URXTRS", "URDTRSLC", na.rm = TRUE) # }