Skip to content

Commit

Permalink
Merge pull request #93 from Big-Life-Lab/dev
Browse files Browse the repository at this point in the history
cchsflow 1.8.0
  • Loading branch information
wyusuf068 authored Jan 22, 2021
2 parents ed7eebe + 6277ac9 commit 6569450
Show file tree
Hide file tree
Showing 128 changed files with 7,770 additions and 3,022 deletions.
Binary file removed .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.Rhistory
.RData
.Ruserdata
.DS_Store
*.DS_Store
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: cchsflow
Type: Package
Title: Transforming and Harmonizing CCHS Variables
Version: 1.7.1
Date: 2020-09-16
Version: 1.8.0
Date: 2021-01-22
Authors@R: c(
person(given = "Doug",
family = "Manuel",
Expand Down Expand Up @@ -49,6 +49,6 @@ Encoding: UTF-8
LazyData: true
URL: https://github.com/Big-Life-Lab/cchsflow
BugReports: https://github.com/Big-Life-Lab/cchsflow/issues
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
Suggests:
testthat (>= 2.1.0)
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@ export(ALCDTTM)
export(ALCDTYP)
export(ALWDDLY)
export(ALWDWKY)
export(COPD_Emph_der_fun1)
export(COPD_Emph_der_fun2)
export(DPSDPP)
export(DPSDSF)
export(GEN_02A2)
export(LBFA_31A)
export(LBFA_31A_a)
export(LBFA_31A_b)
export(RACDPAL_fun)
export(adl_fun)
export(adl_score_5_fun)
export(age_cat_fun)
export(binge_drinker_fun)
export(bmi_fun)
export(diet_score_fun)
export(food_insecurity_der)
export(if_else2)
export(is_equal)
export(merge_rec_data)
export(multiple_conditions_fun1)
export(multiple_conditions_fun2)
export(pack_years_fun)
Expand All @@ -24,6 +32,8 @@ export(resp_condition_fun1)
export(resp_condition_fun2)
export(resp_condition_fun3)
export(set_data_labels)
export(smoke_simple_fun)
export(time_quit_smoking_fun)
importFrom(dplyr,do)
importFrom(dplyr,rowwise)
importFrom(dplyr,select)
Expand Down
38 changes: 37 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
# cchsflow 1.7.1 (Latest build)
# cchsflow 1.8.0
2021-01-22

## Features
- New function `merge_rec_data()` that merges and labels transformed CCHS
datasets.

## Minor improvements
- Improved support for `tagged_na` in derived variables. Additional
documentation added for creating derived variables in the [tagged_na](https://big-life-lab.github.io/cchsflow/articles/tagged_na_usage.html)
article.
- Updates to labels and variable classification on `variables.csv` and
`variable_details.csv`.

## New variables
- [**COPD_Emph_der:**](https://big-life-lab.github.io/reference/COPD_Emph_der_fun1.html)
derived variable that determines if a respondent has either COPD or Emphysema.
- [**ADL_score_5:**](https://big-life-lab.github.io/reference/adl_score_5_fun.html)
derived variable that scores the number of daily tasks that a respondent needs
help with.
- [**diet_score:**](https://big-life-lab.github.io/reference/diet_score_fun.html)
derived variable that scores respondents based on daily consumption of fruit,
vegetables, and fruit juice.
- [**smoke_simple:**](https://big-life-lab.github.io/reference/smoke_simple_fun.html)
derived variable that identifies respondents smoking status.
- [**time_quit_smoking:**](https://big-life-lab.github.io/reference/time_quit_smoking_fun.html)
derived variable that estimates approximate time since respondent has quit
smoking if they are a former smoker.
- [**LBFA_31A/LBFA_31A_a/LBFA_31A_b:**](https://big-life-lab.github.io/reference/LBFA_31A.html)
Occupation group. 3 different variables with differing categories were created
to harmonize between CCHS cycles.
- **CCC_041:** Fibromyalgia.
- **CCC_061:** Back problems.
- **CCC_081:** Migraine headaches.
- **CCC_290:** Anxiety disorder.

# cchsflow 1.7.1
2020-09-16

## Minor improvements
Expand Down
110 changes: 106 additions & 4 deletions R/adl.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#'
#' # To transform ADL_der, use rec_with_table() for each CCHS cycle
#' # and specify ADL_der, along with the various ADL variables.
#' # Then by using bind_rows() you can combine ADL_der across cycles.
#' # Then by using merge_rec_data() you can combine ADL_der across cycles.
#'
#' library(cchsflow)
#' adl2001 <- rec_with_table(
Expand All @@ -89,7 +89,7 @@
#'
#' tail(adl2009_2010)
#'
#' combined_adl <- bind_rows(adl2001, adl2009_2010)
#' combined_adl <- merge_rec_data(adl2001, adl2009_2010)
#'
#' head(combined_adl)
#'
Expand All @@ -107,7 +107,6 @@
#' print(ADL_der)
#'
#' @export

adl_fun <- function (ADL_01, ADL_02, ADL_03, ADL_04, ADL_05) {
# Check to see if all values are in range
if_else2((ADL_01 %in% 1:2) & (ADL_02 %in% 1:2) & (ADL_03 %in% 1:2) &
Expand All @@ -122,4 +121,107 @@ adl_fun <- function (ADL_01, ADL_02, ADL_03, ADL_04, ADL_05) {
"NA(b)"
)

}
}

#' @title The number of activities of daily living tasks that require help.
#'
#' @description A 6 category variable (ADL_score_5) representing the number of
#' activities of daily living tasks that require help. This variable tallies
#' the number of daily living tasks that a respondent requires help with based
#' on various ADL variables that a respondent answered yes or no to. The ADL
#' variables used are common across all CCHS cycles from 2001 to 2014.
#'
#' @param ADL_01 Needs help preparing meals.
#' @param ADL_02 Needs help getting to appointments/errands.
#' @param ADL_03 Needs help doing housework.
#' @param ADL_04 Needs help doing personal care.
#' @param ADL_05 Needs help moving inside house.
#'
#' @return A derived variable (ADL_score_5) with 6 categories:
#' \enumerate{
#' \item 0 - Needs help with 0 tasks
#' \item 1 - Needs help with at least 1 task
#' \item 2 - Needs help with at least 2 tasks
#' \item 3 - Needs help with at least 3 tasks
#' \item 4 - Needs help with at least 4 tasks
#' \item 5 - Needs help with at least 5 tasks
#' }
#'
#'
#' @examples
#' # Use adl_score_5_fun() to create the variable ADL_score_5 across CCHS
#' # cycles adl_score_5_fun() is specified in variable_details.csv along with
#' # the CCHS variables and cycles included.
#'
#' # To transform ADL_score_5, use rec_with_table() for each CCHS cycle
#' # and specify ADL_score_5, along with the various ADL variables.
#' # Then by using merge_rec_data() you can combine ADL_der across cycles.
#'
#' library(cchsflow)
#' adl2001 <- rec_with_table(
#' cchs2001_p, c(
#' "ADL_01", "ADL_02", "ADL_03", "ADL_04", "ADL_05", "ADL_score_5"
#' )
#' )
#'
#' head(adl2001)
#'
#' adl2009_2010 <- rec_with_table(
#' cchs2009_2010_p, c(
#' "ADL_01", "ADL_02", "ADL_03", "ADL_04", "ADL_05", "ADL_score_5"
#' )
#' )
#'
#' tail(adl2009_2010)
#'
#' combined_adl <- merge_rec_data(adl2001, adl2009_2010)
#'
#' head(combined_adl)
#'
#' tail(combined_adl)
#'
#' # Using adl_score_5_fun() to generate to ADL_score_5 based on user inputted
#' # values.
#' # Let's say you do not need help preparing meals, you need help getting to
#' # appointments or errands, you need help doing housework, do not need help
#' # doing personal care, and do not need help moving inside the house. Using
#' # adl_score_5_fun() we can check the number of tasks you need help with
#'
#' ADL_score_5 <- adl_score_5_fun(2, 1, 1, 2, 2)
#'
#' print(ADL_score_5)
#'
#' @export
adl_score_5_fun <-
function(ADL_01, ADL_02, ADL_03, ADL_04, ADL_05) {

# Create vector of ADL input variables
all_adl_vector <- c(ADL_01, ADL_02, ADL_03, ADL_04, ADL_05)
# Count the number of missing values in vector
count_missing_adl <- sum(all_adl_vector == "NA(b)")
# Count the number of not applicable values in vector
count_not_applicable_adl <- sum(all_adl_vector == "NA(a)")
# Count the number of ADLs that require help (value of 2)
count_adl <- sum(all_adl_vector == 2)


# If the individual had missing data for any of the variables then set
# the score to missing
# If the individual has "not applicable" for any of the variables, then
# set the score to "not applicable"
# Otherwise set the score for each individual to the count of the number
# of tasks they needed help with
total_num_adls <- 5
ADL_score_5 <-
ifelse(
count_not_applicable_adl >= 1,
"NA(a)",
ifelse(
count_missing_adl >= 1,
"NA(b)",
count_adl
)
)

return(ADL_score_5)
}
3 changes: 2 additions & 1 deletion R/age-categorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ age_cat_fun <- function(DHHGAGE_cont) {
(DHHGAGE_cont %in% 70:74), 14,
if_else2(
(DHHGAGE_cont %in% 75:79), 15,
if_else2((DHHGAGE_cont >= 80), 16, NA)
if_else2((DHHGAGE_cont >= 80), 16,
"NA(b)")
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions R/bmi.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#'
#' # To transform the derived BMI variable, use rec_with_table() for each cycle
#' # and specify HWTGBMI_der, along with height (HWTGHTM) and weight (HWTGWTK).
#' # Then by using dplyr::bind_rows(), you can combined HWTGBMI_der across
#' # Then by using merge_rec_data(), you can combined HWTGBMI_der across
#' # cycles.
#'
#' library(cchsflow)
Expand All @@ -69,7 +69,7 @@
#'
#' tail(bmi2011_2012)
#'
#' combined_bmi <- bind_rows(bmi2001, bmi2011_2012)
#' combined_bmi <- merge_rec_data(bmi2001, bmi2011_2012)
#' head(combined_bmi)
#' tail(combined_bmi)
#'
Expand Down
20 changes: 10 additions & 10 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ NULL
#' @return \item{cchs2001_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=3359}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=3359}
#'
#' @keywords datasets
#' @examples
Expand Down Expand Up @@ -89,7 +89,7 @@ NULL
#' @return \item{cchs2003_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=4995}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=4995}
#'
#' @keywords datasets
#' @examples
Expand Down Expand Up @@ -120,7 +120,7 @@ NULL
#' @return \item{cchs2005_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=22642}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=22642}
#'
#' @keywords datasets
#' @examples
Expand Down Expand Up @@ -151,7 +151,7 @@ NULL
#' @return \item{cchs2007_2008_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=29539}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=29539}
#'
#' @keywords datasets
#' @examples
Expand Down Expand Up @@ -182,7 +182,7 @@ NULL
#' @return \item{cchs2009_2010_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=67251}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=67251}
#'
#' @keywords datasets
#' @examples
Expand Down Expand Up @@ -217,7 +217,7 @@ NULL
#' @return \item{cchs2010_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=81424}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=81424}
#'
#' @keywords datasets
#' @examples
Expand Down Expand Up @@ -248,7 +248,7 @@ NULL
#' @return \item{cchs2011_2012_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=114112}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=114112}
#'
#' @keywords datasets
#' @examples
Expand Down Expand Up @@ -283,7 +283,7 @@ NULL
#' @return \item{cchs2012_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=135927}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=135927}
#'
#' @keywords datasets
#' @examples
Expand Down Expand Up @@ -314,7 +314,7 @@ NULL
#' @return \item{cchs2013_2014_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=144170}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=144170}
#'
#' @keywords datasets
#' @examples
Expand Down Expand Up @@ -349,7 +349,7 @@ NULL
#' @return \item{cchs2014_p}{a data frame}
#'
#' @source
#' \url{http://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=164081}
#' \url{https://www23.statcan.gc.ca/imdb/p2SV.pl?Function=getSurvey&Id=164081}
#'
#' @keywords datasets
#' @examples
Expand Down
Loading

0 comments on commit 6569450

Please sign in to comment.