Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.