Last active
June 14, 2016 04:11
-
-
Save tyokota/9e58711fc72ad8ea5d5652f51f5ce204 to your computer and use it in GitHub Desktop.
BRFSS
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
# thomasyokota[at]gmail.com | |
# project/purpose: CDC BRFSS in R for free.99 | |
# DEPENDENCIES ----------------------------------------------------------------- | |
install.packages('pacman') | |
pacman::p_load(RCurl, foreign, downloader, foreign) | |
# DATA ------------------------------------------------------------------------- | |
source_url("https://raw.githubusercontent.com/ajdamico/asdfree/master/Download%20Cache/download%20cache.R", prompt=F, echo=F) | |
# download ez-pz brought to you by anthony joseph damico [ajdamico@gmail.com] | |
# note: brfss 2014 | |
tf <- tempfile(); td <- tempdir() | |
xpt <- "http://www.cdc.gov/brfss/annual_data/2014/files/LLCP2014XPT.ZIP" | |
download_cached(xpt, tf, mode='wb') | |
local.fn <- unzip(tf, exdir=td) | |
brfss14 <- read.xport(local.fn) | |
# ANALYSIS---------------------------------------------------------------------- | |
pacman::p_load(survey) | |
brfss.design14 <- svydesign( | |
weight = ~X_LLCPWT, | |
nest = TRUE, | |
strata = ~X_STSTR, | |
id = ~X_PSU, | |
data = brfss14) | |
# note: Told by a doctor or health professional that you have diabetes | |
# translation: eh, brah. You get diabetes or wat? | |
# http://health.hawaii.gov/brfss/files/2015/08/HBRFSS_2014_results.pdf | |
# page 91/200 | |
svymean(~as.factor(DIABETE3), subset(brfss.design14, X_STATE==15)) | |
# note: 95% confidence intervals | |
# translation: wea da confidence intervals stay bu?! | |
dm.hi <- svymean(~as.factor(DIABETE3), subset(brfss.design14, X_STATE==15)) | |
se.row.pct <- sqrt(diag(attr(dm.hi, 'var'))) | |
dm.hi - qnorm(0.975) * se.row.pct | |
dm.hi + qnorm(0.975) * se.row.pct |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment