Last active
August 17, 2017 19:48
-
-
Save herbps10/44d965228204c910e3b2a08f430cd920 to your computer and use it in GitHub Desktop.
Computing geometric means of NHANES variables with 95% confidence intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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