diff --git a/R/nhanes.R b/R/nhanes.R index d7a2e41..42b3d8a 100644 --- a/R/nhanes.R +++ b/R/nhanes.R @@ -313,7 +313,7 @@ nhanesDXA <- function(year, suppl=FALSE, destfile=NULL) { return(sasxport.get(tf,lowernames=FALSE)) } } - } else { #If no specific year is given then just retrieve all years + } else { # Year not provided - no data will be returned stop("Year is required") } } diff --git a/vignettes/Introducing_nhanesA.Rmd b/vignettes/Introducing_nhanesA.Rmd index 38872f5..75c5aa7 100644 --- a/vignettes/Introducing_nhanesA.Rmd +++ b/vignettes/Introducing_nhanesA.Rmd @@ -100,7 +100,7 @@ Some discretion is applied by nhanesTranslate such that not all of the coded col ### Import Dual X-Ray Absorptiometry Data Dual X-Ray Absorptiometry (DXA) Data were acquired from 1999-2006. The tables are considerably larger than most -NHANES data tables and are available via ftp server only. More information may be found at http://www.cdc.gov/nchs/nhanes/dxx/dxa.htm. By default the DXA data are imported into the R environment, however, because the tables are quite large it may be desirable to save the data to a local file then import to R as needed. Note that nhanesTranslate can be applied to DXA data but that only the 2005-2006 translation tables are used as those are the only DXA codes that are available in html format. +NHANES data tables and are available via ftp server only. More information may be found at http://www.cdc.gov/nchs/nhanes/dxx/dxa.htm. By default the DXA data are imported into the R environment, however, because the tables are quite large it may be desirable to save the data to a local file then import to R as needed. Note that nhanesTranslate can be applied to DXA data but that only the 2005-2006 translation tables are used as those are the only DXA codes that are currently available in html format. ```{r, eval=FALSE} #Import into R dxx_b <- nhanesDXA(2001) @@ -113,6 +113,8 @@ dxalist <- c('DXAEXSTS', 'DXITOT', 'DXIHE') dxx_b <- nhanesTranslate(colnames=dxalist, data=dxx_b, dxa=T) ``` +If you are interested in working with accelerometer data from 2003-2006 then please see packages nhanesaccel http://r-forge.r-project.org/R/?group_id=1733 and accelerometry http://cran.r-project.org/package=accelerometry. + #### Please send any feedback or requests to cjendres1@gmail.com. Hope you enjoy your experience with nhanesA! Sincerely, Christopher Endres \ No newline at end of file diff --git a/vignettes/Introducing_nhanesA.html b/vignettes/Introducing_nhanesA.html index ba88376..ea65654 100644 --- a/vignettes/Introducing_nhanesA.html +++ b/vignettes/Introducing_nhanesA.html @@ -10,7 +10,7 @@ - +
To quickly get familiar with NHANES data, it is helpful to display a listing of tables. Use nhanesTables to get information on tables that are available for a given category for a given year.
-suppressWarnings(library(nhanesA))
-nhanesTables('EXAM', 2005)
+suppressWarnings(library(nhanesA))
+nhanesTables('EXAM', 2005)
## FileName Description
## 1 AUX_D Audiometry
## 2 AUXAR_D Audiometry - Acoustic Reflex
@@ -91,7 +109,7 @@ List NHANES Tables
List Variables in an NHANES Table
After viewing the output, we decide we are interested in table ‘BMX_D’ that contains body measures data. To better determine if that table is of interest, we can display detailed information on the table contents using nhanesTableVars.
-nhanesTableVars('EXAM', 'BMX_D')
+nhanesTableVars('EXAM', 'BMX_D')
## Variable.Name Variable.Description
## 1 SEQN Respondent sequence number.
## 2 BMDSTATS Body Measures Component status Code
@@ -121,14 +139,14 @@ List Variables in an NHANES Table
## 26 BMXSUB Subscapular Skinfold (mm)
## 27 BMISUB Subscapular Skinfold Comment
We see that there are 27 columns in table BMX_D. The first column (SEQN) is the respondent sequence number and is included in every NHANES table. Effectively, SEQN is a subject identifier that is used to join information across tables. We now import BMX_D along with the demographics table DEMO_D.
-bmx_d <- nhanes('BMX_D')
+bmx_d <- nhanes('BMX_D')
## Processing SAS dataset BMX_D ..
-demo_d <- nhanes('DEMO_D')
+demo_d <- nhanes('DEMO_D')
## Processing SAS dataset DEMO_D ..
We then merge the tables and compute average values by gender for several variables:
-bmx_demo <- merge(demo_d, bmx_d)
+bmx_demo <- merge(demo_d, bmx_d)
options(digits=4)
-aggregate(cbind(BMXHT,BMXWT, BMXLEG, BMXCALF, BMXTHICR)~RIAGENDR, bmx_demo, mean)
+aggregate(cbind(BMXHT,BMXWT, BMXLEG, BMXCALF, BMXTHICR)~RIAGENDR, bmx_demo, mean)
## RIAGENDR BMXHT BMXWT BMXLEG BMXCALF BMXTHICR
## 1 1 170.0 76.91 40.50 37.48 51.46
## 2 2 158.9 68.18 37.19 36.89 51.09
@@ -136,21 +154,21 @@ List Variables in an NHANES Table
Translation of Coded Values
NHANES uses coded values for many fields. In the preceding example, gender is coded as 1 or 2. To determine what the values mean, we can list the code translations for the gender field RIAGENDR in table DEMO_D
-nhanesTranslate('DEMO_D', 'RIAGENDR')
+nhanesTranslate('DEMO_D', 'RIAGENDR')
## $RIAGENDR
## Code.or.Value Value.Description
## 1 1 Male
## 2 2 Female
## 3 . Missing
If desired, we can use nhanesTranslate to apply the code translation to demo_d directly by assigning data=demo_d.
-levels(as.factor(demo_d$RIAGENDR))
+levels(as.factor(demo_d$RIAGENDR))
## [1] "1" "2"
-demo_d <- nhanesTranslate('DEMO_D', 'RIAGENDR', data=demo_d)
+demo_d <- nhanesTranslate('DEMO_D', 'RIAGENDR', data=demo_d)
## Translated columns: RIAGENDR
-levels(demo_d$RIAGENDR)
+levels(demo_d$RIAGENDR)
## [1] "Male" "Female"
-bmx_demo <- merge(demo_d, bmx_d)
-aggregate(cbind(BMXHT, BMXWT, BMXLEG, BMXCALF, BMXTHICR)~RIAGENDR, bmx_demo, mean)
+bmx_demo <- merge(demo_d, bmx_d)
+aggregate(cbind(BMXHT, BMXWT, BMXLEG, BMXCALF, BMXTHICR)~RIAGENDR, bmx_demo, mean)
## RIAGENDR BMXHT BMXWT BMXLEG BMXCALF BMXTHICR
## 1 Male 170.0 76.91 40.50 37.48 51.46
## 2 Female 158.9 68.18 37.19 36.89 51.09
@@ -158,16 +176,16 @@ Translation of Coded Values
Downloading a Complete Survey
The primary goal of nhanesA is to enable fully customizable processing of select NHANES tables. However, it is quite easy to download entire surveys using nhanesA functions. Say we want to download every questionnaire in the 2007-2008 survey. We first get a list of the table names by using nhanesTables with namesonly = TRUE. The tables can then be downloaded using nhanes with lapply.
-q2007names <- nhanesTables('Q', 2007, namesonly=TRUE)
+q2007names <- nhanesTables('Q', 2007, namesonly=TRUE)
q2007tables <- lapply(q2007names, nhanes)
-names(q2007tables) <- q2007names
+names(q2007tables) <- q2007names
Apply All Possible Code Translations to a Table
An NHANES table may have dozens of columns with coded values. Translating all possible columns is a three step process. 1: Download the table 2: Save a list of table variables 3: Pass the table and variable list to nhanesTranslate
-bpx_d <- nhanes('BPX_D')
+bpx_d <- nhanes('BPX_D')
## Processing SAS dataset BPX_D ..
-head(bpx_d[,6:11])
+head(bpx_d[,6:11])
## BPQ150A BPQ150B BPQ150C BPQ150D BPAARM BPACSZ
## 1 NA NA NA NA NA NA
## 2 2 2 2 2 1 3
@@ -175,11 +193,11 @@ Apply All Possible Code Translations to a Table
## 4 2 2 2 2 1 3
## 5 2 2 2 2 1 4
## 6 2 2 2 2 1 4
-bpx_d_vars <- nhanesTableVars('EXAM', 'BPX_D', namesonly=TRUE)
+bpx_d_vars <- nhanesTableVars('EXAM', 'BPX_D', namesonly=TRUE)
#Alternatively may use bpx_d_vars = names(bpx_d)
-bpx_d <- suppressWarnings(nhanesTranslate('BPX_D', bpx_d_vars, data=bpx_d))
+bpx_d <- suppressWarnings(nhanesTranslate('BPX_D', bpx_d_vars, data=bpx_d))
## Translated columns: PEASCST1 PEASCCT1 BPQ150A BPQ150B BPQ150C BPQ150D BPAARM BPACSZ BPXPULS BPXPTY BPAEN2 BPAEN3 BPAEN4
-head(bpx_d[,6:11])
+head(bpx_d[,6:11])
## BPQ150A BPQ150B BPQ150C BPQ150D BPAARM BPACSZ
## 1 <NA> <NA> <NA> <NA> <NA> <NA>
## 2 No No No No Right Adult (12X22)
@@ -191,8 +209,8 @@ Apply All Possible Code Translations to a Table
Import Dual X-Ray Absorptiometry Data
-Dual X-Ray Absorptiometry (DXA) Data were acquired from 1999-2006. The tables are considerably larger than most NHANES data tables and are available via ftp server only. More information may be found at http://www.cdc.gov/nchs/nhanes/dxx/dxa.htm. By default the DXA data are imported into the R environment, however, because the tables are quite large it may be desirable to save the data to a local file then import to R as needed. Note that nhanesTranslate can be applied to DXA data but that only the 2005-2006 translation tables are used as those are the only DXA codes that are available in html format.
-#Import into R
+Dual X-Ray Absorptiometry (DXA) Data were acquired from 1999-2006. The tables are considerably larger than most NHANES data tables and are available via ftp server only. More information may be found at http://www.cdc.gov/nchs/nhanes/dxx/dxa.htm. By default the DXA data are imported into the R environment, however, because the tables are quite large it may be desirable to save the data to a local file then import to R as needed. Note that nhanesTranslate can be applied to DXA data but that only the 2005-2006 translation tables are used as those are the only DXA codes that are currently available in html format.
+#Import into R
dxx_b <- nhanesDXA(2001)
#Save to file
nhanesDXA(2001, destfile="dxx_b.xpt")
@@ -200,10 +218,12 @@ Import Dual X-Ray Absorptiometry Data
dxx_c_s <- nhanesDXA(2003, suppl=TRUE)
#Apply code translations
dxalist <- c('DXAEXSTS', 'DXITOT', 'DXIHE')
-dxx_b <- nhanesTranslate(colnames=dxalist, data=dxx_b, dxa=T)
+dxx_b <- nhanesTranslate(colnames=dxalist, data=dxx_b, dxa=T)
+If you are interested in working with accelerometer data from 2003-2006 then please see packages nhanesaccel http://r-forge.r-project.org/R/?group_id=1733 and accelerometry http://cran.r-project.org/package=accelerometry.
Please send any feedback or requests to cjendres1@gmail.com. Hope you enjoy your experience with nhanesA!
-Sincerely,
Christopher Endres
+Sincerely,
+Christopher Endres