Skip to content

Commit

Permalink
Merge pull request #11 from Big-Life-Lab/dev
Browse files Browse the repository at this point in the history
Hotfix update
  • Loading branch information
wyusuf068 authored Nov 25, 2019
2 parents ca0e48c + 448e026 commit 3152aa9
Show file tree
Hide file tree
Showing 15 changed files with 302 additions and 170 deletions.
Binary file modified .DS_Store
Binary file not shown.
11 changes: 10 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# cchsflow 0.2.1 (Latest build)
# cchsflow 0.2.2 (Latest build)

## Features:

- Updated ref branch of bllflow to match latest version of `RecWTable()`
- Minor formatting changes in data, function, and derived variable documentation to improve
readability
- Minor corrections to derived variables article

# cchsflow 0.2.1

## Features:

Expand Down
44 changes: 25 additions & 19 deletions R/alcohol.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#'
#' @description \strong{NOTE:} this is not a function.
#'
#' This is a continuous variable derived by Statistics Canada that quantifies the amount of alcohol that is consumed in a week.
#' This is calculated by adding the number of drinks consumed during each day in the past week.
#' Respondents of each CCHS cycle are asked how much alcohol they have consumed each day in the past week (ie. how much alcohol did you consume on Sunday,
#' how much did you consume on Monday etc.). Each day in considered an individual variable and ALWDWKY takes the sum of all daily variables.
#' This is a continuous variable derived by Statistics Canada that quantifies the amount of alcohol
#' that is consumed in a week. This is calculated by adding the number of drinks consumed during
#' each day in the past week. Respondents of each CCHS cycle are asked how much alcohol they have
#' consumed each day in the past week (ie. how much alcohol did you consume on Sunday,
#' how much did you consume on Monday etc.). Each day in considered an individual variable and
#' ALWDWKY takes the sum of all daily variables.
#'
#' @details This variable is used in all CCHS cycles in cchsflow and how it was derived remains consistent from 2001 to 2014.
#' @details This variable is used in all CCHS cycles in cchsflow and how it was derived remains
#' consistent from 2001 to 2014.
#'
#' @param ALWDWKY cchsflow variable name for number of drinks consumed in the past week
#'
Expand All @@ -20,10 +23,11 @@ ALWDWKY <- function(ALWDWKY) {
#'
#' @description \strong{NOTE:} this is not a function.
#'
#' This is a continuous variable derived by Statistics Canada that quantifies the mean daily consumption of alcohol.
#' This takes the value of ALWDWKY and divides it by 7.
#' This is a continuous variable derived by Statistics Canada that quantifies the mean daily
#' consumption of alcohol. This takes the value of ALWDWKY and divides it by 7.
#'
#' @details This variable is used in all CCHS cycles in cchsflow and how it was derived remains consistent from 2001 to 2014.
#' @details This variable is used in all CCHS cycles in cchsflow and how it was derived remains
#' consistent from 2001 to 2014.
#'
#' @param ALWDDLY cchsflow variable name for average daily alcohol consumption
#'
Expand All @@ -36,19 +40,21 @@ ALWDDLY <- function(ALWDDLY) {
#'
#' @description \strong{NOTE:} this is not a function.
#'
#' This is a categorical variable derived by Statistics Canada that uses various intermediate alcohol variables to
#' categorize individuals into 4 distinct groups:
#' This is a categorical variable derived by Statistics Canada that uses various intermediate
#' alcohol variables to categorize individuals into 4 distinct groups:
#'
#' 1. Regular Drinker
#' 2. Occasional Drinker
#' 3. Former Drinker
#' 4. Never Drinker
#'
#' @details This variable is used in CCHS cycles from 2001 to 2007. How it was derived remained consistent during these years.
#' @details This variable is used in CCHS cycles from 2001 to 2007. How it was derived remained
#' consistent during these years.
#'
#' Starting in 2007, Statistics Canada created a derived variable that looked at drinking type in the last 12 months.
#' This new derived variable did not distinguish between former and never drinkers. If your research requires you
#' to differentiate between former and never drinkers, we recommend using earlier cycles fo the CCHS.
#' Starting in 2007, Statistics Canada created a derived variable that looked at drinking type in
#' the last 12 months. This new derived variable did not distinguish between former and never
#' drinkers. If your research requires you to differentiate between former and never drinkers,
#' we recommend using earlier cycles of the CCHS.
#'
#' @param ALCDTYP cchsflow variable name for type of drinker
#'
Expand All @@ -61,16 +67,16 @@ ALCDTYP <- function(ALCDTYP) {
#'
#' @description \strong{NOTE:} this is not a function.
#'
#' This is a categorical variable derived by Statistics Canada that uses various intermediate alcohol variables to
#' categorize individuals into 3 distinct groups:
#' This is a categorical variable derived by Statistics Canada that uses various intermediate
#' alcohol variables to categorize individuals into 3 distinct groups:
#'
#' 1. Regular Drinker
#' 2. Occasional Drinker
#' 3. No drink in the last 12 months.
#'
#' @details This variable was introuced in the 2007-2008 cycle of the CCHS, and became the sole derived variable that categorized
#' people into various drinker types from 2009 onwards. Unlike `ALCDTYP`, this variable does not distinguish between
#' former and never drinkers.
#' @details This variable was introuced in the 2007-2008 cycle of the CCHS, and became the sole
#' derived variable that categorized people into various drinker types from 2009 onwards.
#' Unlike ALCDTYP, this variable does not distinguish between former and never drinkers.
#'
#' @param ALCDTTM cchsflow variable name for type of drinker (12 months)
#'
Expand Down
64 changes: 35 additions & 29 deletions R/bmi.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,34 @@ ifelse2 <- function(x, a, b) {

#' @title Body Mass Index (BMI) derived variable
#'
#' @description This function creates a harmonized BMI variable. The BMI variable provided by the CCHS calculates BMI using methods
#' that vary across cycles, leading to measurement error when using multiple CCHS cycles. In certain CCHS cycles (2001-2003, 2007+),
#' there are age restrictions in which respondents under the age of 20 and over the age of 64 were not included. Across all CCHS cycles,
#' female respondents who identifed as being pregnant were excluded; and in certain CCHS cycles (2003-2007, 2013-2014), females who did not
#' answer the pregnancy question were coded as NS (not stated) for HWTGBMI. As well, in certain CCHS cycles (2001-2003, 2009-2014),
#' respondents outside certain height and weight ranges (0.914-2.108m for height, 0-260kg for weight) were excluded from HWTGBMI.
#'
#' BMI_fun() creates a derived variable (HWTGBMI_der) that is harmonized across all CCHS cycles. This function divides weight by the
#' square of height.
#' @description This function creates a harmonized BMI variable. The BMI variable provided by the
#' CCHS calculates BMI using methods that vary across cycles, leading to measurement error when
#' using multiple CCHS cycles. In certain CCHS cycles (2001-2003, 2007+), there are age
#' restrictions in which respondents under the age of 20 and over the age of 64 were not included.
#' Across all CCHS cycles, female respondents who identifed as being pregnant were excluded; and
#' in certain CCHS cycles (2003-2007, 2013-2014), females who did not answer the pregnancy
#' question were coded as NS (not stated) for HWTGBMI. As well, in certain CCHS cycles (2001-2003,
#' 2009-2014), respondents outside certain height and weight ranges (0.914-2.108m for height,
#' 0-260kg for weight) were excluded from HWTGBMI.
#'
#' BMI_fun() creates a derived variable (HWTGBMI_der) that is harmonized across all CCHS cycles.
#' This function divides weight by the square of height.
#'
#' @details For HWTGBMI_der, there are no restrictions to age, height, weight, or pregnancy status. While pregnancy was consistent across
#' all CCHS cycles, its variable (MAM_037) was not available in the PUMF CCHS datasets so it could not be harmonized and included into
#' the function.
#' @details For HWTGBMI_der, there are no restrictions to age, height, weight, or pregnancy status.
#' While pregnancy was consistent across all CCHS cycles, its variable (MAM_037) was not available
#' in the PUMF CCHS datasets so it could not be harmonized and included into the function.
#'
#' For any single CCHS survey year, it is appropriate to use the CCHS BMI variable (HWTGBMI) that is also available on cchsflow.
#' HWTGBMI_der is recommended when using multiple survey cycles.
#' For any single CCHS survey year, it is appropriate to use the CCHS BMI variable (HWTGBMI) that
#' is also available on cchsflow. HWTGBMI_der is recommended when using multiple survey cycles.
#'
#' HWTGBMI_der uses the CCHS variables for height and weight that have been transformed by cchsflow. In order to
#' generate a value for BMI across CCHS cycles, height and weight must be transformed and harmonized.
#' HWTGBMI_der uses the CCHS variables for height and weight that have been transformed by
#' cchsflow. In order to generate a value for BMI across CCHS cycles, height and weight must be
#' transformed and harmonized.
#'
#' @note In earlier CCHS cycles (2001 and 2003), height was collected in inches; while in later CCHS cycles (2005+)
#' it was collected in meters. To harmonize values across cycles, height was converted to meters (to 3 decimal points).
#' Weight was collected in kilograms across all CCHS cycles, so no transformations were required in the harmonization process.
#' @note In earlier CCHS cycles (2001 and 2003), height was collected in inches; while in later CCHS
#' cycles (2005+) it was collected in meters. To harmonize values across cycles, height was
#' converted to meters (to 3 decimal points). Weight was collected in kilograms across all CCHS
#' cycles, so no transformations were required in the harmonization process.
#'
#' @param HWTGHTM CCHS variable for height (in meters)
#'
Expand All @@ -63,29 +68,30 @@ ifelse2 <- function(x, a, b) {
#'
#' @examples
#' # Using BMI_fun() to create BMI values across cycles
#' # BMI_fun() is specified in variableDetails.csv along with the CCHS variables and cycles included.
#' # BMI_fun() is specified in variableDetails.csv along with the CCHS variables and cycles
#' # included.
#'
#' # To transform the derived BMI variable, use RecWTable() for each CCHS cycle and specify HWTGBMI_der,
#' # along with height (HWTGHTM) and weight (HWTGWTK). Then by using bind_rows(), you can combined HWTGBMI_der
#' # across cycles.
#' # To transform the derived BMI variable, use RecWTable() for each CCHS cycle and specify
#' # HWTGBMI_der, along with height (HWTGHTM) and weight (HWTGWTK). Then by using bind_rows(), you
#' # can combined HWTGBMI_der across cycles.
#'
#' suppressMessages(library(bllflow))
#' library(cchsflow)
#' bmi2010 <- RecWTable(dataSource = cchs2010, variableDetails = variableDetails, datasetName = "cchs2010",
#' variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_der"))
#' bmi2010 <- RecWTable(dataSource = cchs2010, variableDetails = variableDetails,
#' datasetName = "cchs2010", variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_der"))
#' head(bmi2010)
#'
#' bmi2012 <- RecWTable(dataSource = cchs2012, variableDetails = variableDetails, datasetName = "cchs2012",
#' variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_der"))
#' bmi2012 <- RecWTable(dataSource = cchs2012, variableDetails = variableDetails, datasetName =
#' "cchs2012", variables = c("HWTGHTM", "HWTGWTK", "HWTGBMI_der"))
#' tail(bmi2012)
#'
#' combined_bmi <- bind_rows(bmi2010, bmi2012)
#' head(combined_bmi)
#' tail(combined_bmi)
#'
#' # Using BMI_fun() to generate a BMI value with user inputted height and weight values
#' # BMI_fun() can also generate a value for BMI if you input a value for height and weight. Let's say your height is
#' # 170cm (1.7m) and your weight is 50kg, your BMI can be calculated as followed:
#' # BMI_fun() can also generate a value for BMI if you input a value for height and weight. Let's
#' # say your height is 170cm (1.7m) and your weight is 50kg, your BMI can be calculated as follows:
#'
#' library(cchsflow)
#' BMI <- BMI_fun(HWTGHTM = 1.7, HWTGWTK = 50)
Expand Down
79 changes: 49 additions & 30 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#' 2001 CCHS data
#'
#' This is a subset of 200 observations from the 2001 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' This is a subset of 200 observations from the 2001 cycle of the Canadian Community Health Survey
#' (CCHS) Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics
#' Canada.
#'
#' See the open license \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#' Long name: cchs-82M0013-E-2001-c1-1-general-file
#'
Expand All @@ -25,9 +27,11 @@ NULL

#' 2003 CCHS data
#'
#' This is a subset of 200 observations from the 2003 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' This is a subset of 200 observations from the 2003 cycle of the Canadian Community
#' Health Survey (CCHS) Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by
#' Statistics Canada.
#'
#' See the open license\href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#'
#' Long name: cchs-82M0013-E-2003-c2-1-General File
Expand All @@ -51,9 +55,11 @@ NULL

#' 2005 CCHS data
#'
#' This is a subset of 200 observations from the 2005 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' This is a subset of 200 observations from the 2005 cycle of the Canadian Community Health Survey
#' (CCHS) Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by
#' Statistics Canada.
#'
#' See the open license \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#'
#' Long name: cchs-82M0013-E-2005-c3-1-main-file
Expand All @@ -77,9 +83,11 @@ NULL

#' 2007-2008 CCHS data
#'
#' This is a subset of 200 observations from the 2007-2008 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' This is a subset of 200 observations from the 2007-2008 cycle of the Canadian Community Health
#' Survey (CCHS) Public Use Microdata file (PUMF) dataset.
#' The CCHS survey is conducted by Statistics Canada.
#'
#' See the open license \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#' Long name: cchs-E-2007-2008-AnnualComponent
#'
Expand All @@ -102,10 +110,11 @@ NULL

#' 2009-2010 CCHS data
#'
#' This is a subset of 200 observations from the 2009-2010 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' This is a subset of 200 observations from the 2009-2010 cycle of the Canadian Community
#' Health Survey (CCHS) Public Use Microdata file (PUMF) dataset.
#' The CCHS survey is conducted by Statistics Canada.
#'
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' See the open license \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#' Long name: CCHS-82M0013-E-2009-2010-Annualcomponent
#'
Expand All @@ -128,9 +137,11 @@ NULL

#' 2010 CCHS data
#'
#' This is a subset of 200 observations from the 2010 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' This is a subset of 200 observations from the 2010 cycle of the Canadian Community Health Survey
#' (CCHS) Public Use Microdata file (PUMF) dataset.
#' The CCHS survey is conducted by Statistics Canada.
#'
#' See the open license \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#' Long name: CCHS-82M0013-E-2010-AnnualComponent
#'
Expand All @@ -153,9 +164,11 @@ NULL

#' 2011-2012 CCHS data
#'
#' This is a subset of 200 observations from the 2011-2012 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' This is a subset of 200 observations from the 2011-2012 cycle of the Canadian Community Health
#' Survey (CCHS) Public Use Microdata file (PUMF) dataset.
#' The CCHS survey is conducted by Statistics Canada.
#'
#' See the open license \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#'
#' Long name: cchs-82M0013-E-2011-2012-Annual-component
Expand All @@ -179,9 +192,11 @@ NULL

#' 2012 CCHS data
#'
#' This is a subset of 200 observations from the 2012 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' This is a subset of 200 observations from the 2012 cycle of the Canadian Community Health Survey
#' (CCHS) Public Use Microdata file (PUMF) dataset.
#' The CCHS survey is conducted by Statistics Canada.
#'
#' See the open license \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#' Long name: cchs-82M0013-E-2012-Annual-component
#'
Expand All @@ -204,9 +219,11 @@ NULL

#' 2013-2014 CCHS data
#'
#' This is a subset of 200 observations from the 2013-2014 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' This is a subset of 200 observations from the 2013-2014 cycle of the Canadian Community Health
#' Survey (CCHS) Public Use Microdata file (PUMF) dataset.
#' The CCHS survey is conducted by Statistics Canada.
#'
#' See the open license \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#' Long name: cchs-82M0013-E-2013-2014-Annual-component
#'
Expand All @@ -229,9 +246,11 @@ NULL

#' 2014 CCHS data
#'
#' This is a subset of 200 observations from the 2014 cycle of the Canadian Community Health Survey (CCHS)
#' Public Use Microdata file (PUMF) dataset. The CCHS survey is conducted by Statistics Canada.
#' See the Statistics Canada Open License \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#' This is a subset of 200 observations from the 2014 cycle of the Canadian Community Health Survey
#' (CCHS) Public Use Microdata file (PUMF) dataset.
#' The CCHS survey is conducted by Statistics Canada.
#'
#' See the open license \href{https://www.statcan.gc.ca/eng/reference/licence}{here}.
#'
#' Long name: cchs-82M0013-E-2014-Annual-component
#'
Expand Down
Loading

0 comments on commit 3152aa9

Please sign in to comment.