Learn R Programming

RNHANES (version 1.1.0)

nhanes_survey: Apply a function from the survey package to NHANES data

Description

Apply a function from the survey package to NHANES data

Usage

nhanes_survey(survey_fun, nhanes_data, column, comment_column = "", weights_column = "", filter = NULL, analyze = "values", callback = NULL, ...)

Arguments

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

Value

a data frame

Details

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.

Examples

Run this code
## 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)
# 
# ## End(Not run)

Run the code above in your browser using DataLab