Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@herbps10
Last active August 17, 2017 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herbps10/44d965228204c910e3b2a08f430cd920 to your computer and use it in GitHub Desktop.
Save herbps10/44d965228204c910e3b2a08f430cd920 to your computer and use it in GitHub Desktop.
Computing geometric means of NHANES variables with 95% confidence intervals
library(survey)
library(RNHANES)
library(tidyverse)
dat <- nhanes_load_data("EPHPP_H", "2013-2014", demographics = TRUE) %>%
filter(!is.na(URXBPH), !is.na(URXBP3))
des <- nhanes_survey_design(dat, "WTSB2YR")
logmean <- svymean(~log(URXBPH), des, na.rm = TRUE)
# Geometric mean lower 95% confidence interval
exp(logmean[1] - 1.96 * sqrt(attr(logmean, "var")))
# Geometric mean
exp(logmean)[1]
# Geometric mean upper 95% confidence interval
exp(logmean[1] + 1.96 * sqrt(attr(logmean, "var")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment