Apply a function from the survey package to NHANES data

Description

Apply a function from the survey package to NHANES data

Usage

1
2
3
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

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.

Value

a data frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## 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)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.