Skip to content
Closed

sleep #161

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

# Note: Deprecated alcohol functions removed in v3.0.0 modernization
export(COPD_Emph_der_fun1)
export(COPD_Emph_der_fun2)
export(DPSDPP)
Expand All @@ -10,9 +9,7 @@ export(LBFA_31A)
export(LBFA_31A_a)
export(LBFA_31A_b)
export(RACDPAL_fun)
# Note: Deprecated smoking functions removed in v3.0.0 modernization
export(SPS_5_fun)
# Note: SPU25_fun deprecated and removed
export(active_transport1_fun)
export(active_transport2_fun)
export(active_transport3_fun)
Expand All @@ -21,12 +18,12 @@ export(adl_score_5_fun)
export(adl_score_6_fun)
export(age_cat_fun)
export(assess_adl)
export(assess_binge_drinking)
export(assess_drinking_risk_long)
export(assess_drinking_risk_short)
export(calculate_bmi)
export(calculate_energy_expenditure)
export(categorize_bmi)
export(calculate_pack_years)
export(calculate_smoke_simple)
export(calculate_smoking_status)
export(calculate_time_quit_smoking)
export(diet_score_fun)
export(diet_score_fun_cat)
export(energy_exp_fun)
Expand All @@ -38,28 +35,16 @@ export(is_equal)
export(merge_rec_data)
export(multiple_conditions_fun1)
export(multiple_conditions_fun2)
# Note: Deprecated pack years functions removed in v3.0.0 modernization
export(pct_time_fun)
export(pct_time_fun_cat)
# Note: All preprocess functions removed from exports in v3.0.0
# These are now internal functions used within derived variable functions
# - preprocess_cchs_missing_codes() -> internal use only
# - preprocess_smoking_variable() -> internal use only
# - Deprecated pattern functions removed completely
export(rec_with_table)
export(resp_condition_fun1)
export(resp_condition_fun2)
export(resp_condition_fun3)
export(score_adl)
export(score_adl_6)
export(set_data_labels)
# Modernized v3.0.0 smoking functions
export(calculate_smoking_status)
export(calculate_time_quit_smoking)
export(calculate_pack_years)
export(calculate_smoke_simple)
export(standardise_csv)
# Note: Deprecated time_quit_smoking functions removed in v3.0.0 modernization
export(validate_missing_code_preprocessing)
importFrom(dplyr,do)
importFrom(dplyr,rowwise)
Expand All @@ -70,4 +55,3 @@ importFrom(sjlabelled,"set_label<-")
importFrom(sjlabelled,set_label)
importFrom(sjlabelled,set_labels)
importFrom(stringr,str_match)
# Note: Legacy functions (adl_fun, bmi_fun, binge_drinker_fun, etc.) moved to R/legacy/ - no longer exported
1 change: 1 addition & 0 deletions ceps/cep-005-sleep/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.quarto/
121 changes: 121 additions & 0 deletions ceps/cep-005-sleep/L0_documentation_assessment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# L0 Documentation assessment: Sleep variables

## Overview

This document assesses the documentation and source data for sleep harmonization variables in the CCHS, supporting PR #161.

## Variables in scope

| Variable | Label | Type | Description |
|----------|-------|------|-------------|
| SLP_02 | Trouble sleeping | Categorical | Frequency of trouble going to sleep or staying asleep |
| SLP_02_A | Trouble sleeping | Categorical | 2001 version (different scale) |
| SLP_03 | Sleep refreshing | Categorical | Frequency of finding sleep refreshing |
| SLP_03_A | Sleep refreshing | Categorical | 2001 version (different scale) |
| SLP_04 | Difficulty awake | Categorical | Frequency of difficulty staying awake |
| SLP_04_A | Difficulty awake | Categorical | 2001 version (different scale) |
| SLPG01 | Hours sleep | Categorical | Hours spent sleeping each night (grouped) |
| SLPG01_A | Hours sleep | Categorical | 2001/2007-2008 version |
| SLPG01_B | Hours sleep | Categorical | Master file 2011-2014 |
| SLPG01_C | Hours sleep | Categorical | Master file 2001/2015-2016 |
| SLPG01_cont | Hours sleep | Continuous | Hours sleeping (continuous) |

## PUMF availability by cycle

| Cycle | Sleep hours | Trouble sleeping | Sleep refreshing | Difficulty awake |
|-------|-------------|------------------|------------------|------------------|
| 2001 | GENA_03 | GENA_04 | GENA_05 | GENA_06 |
| 2003 | **NOT AVAILABLE** | **NOT AVAILABLE** | **NOT AVAILABLE** | **NOT AVAILABLE** |
| 2005 | **NOT AVAILABLE** | **NOT AVAILABLE** | **NOT AVAILABLE** | **NOT AVAILABLE** |
| 2007-2008 | SLP_01 | SLP_02 | SLP_03 | SLP_04 |
| 2009-2010 | **NOT AVAILABLE** | **NOT AVAILABLE** | **NOT AVAILABLE** | **NOT AVAILABLE** |
| 2011-2012 | SLPG01 | SLP_02 | SLP_03 | SLP_04 |
| 2013-2014 | SLPG01 | SLP_02 | SLP_03 | SLP_04 |
| 2015-2016 | SLPG005 | SLP_010 | SLP_015 | SLP_020 |
| 2017-2018 | SLPG005 | SLP_010 | SLP_015 | SLP_020 |

## Critical finding: Missing cycles

**Sleep variables are NOT available in 2003, 2005, and 2009-2010 PUMF files.**

This was verified by searching the DDI XML files for all sleep-related variable names. The sleep module was an optional content module that was not included in these cycles.

## Scale differences

### 2001 scale (3-point)
For trouble sleeping (GENA_04), sleep refreshing (GENA_05), difficulty awake (GENA_06):
- 1 = Most of the time
- 2 = Sometimes
- 3 = Never
- 6 = Not applicable
- 7 = Don't know
- 8 = Refusal
- 9 = Not stated

### 2007+ scale (5-point)
For SLP_02, SLP_03, SLP_04 (and renamed versions):
- 1 = None of the time / Never
- 2 = A little of the time / Rarely
- 3 = Some of the time / Sometimes
- 4 = Most of the time
- 5 = All of the time
- 6 = Valid skip / Not applicable
- 7 = Don't know
- 8 = Refusal
- 9 = Not stated

**Important:** The 2001 scale cannot be directly mapped to the 2007+ scale because:
- 2001 has 3 substantive categories (most/sometimes/never)
- 2007+ has 5 substantive categories (none/little/some/most/all)

This explains why there are separate _A variables for 2001 - they cannot be harmonized to the same scale.

## Hours sleep variable encoding

### 2001 (GENA_03) - Continuous-ish
- 1 = < 2 hours
- 2 = 2 - < 3 hours
- ...
- 12 = >= 12 hours
- 96 = Not applicable
- 97 = Don't know
- 98 = Refusal
- 99 = Not stated

### 2007-2008 (SLP_01) - Grouped
Uses similar categorical encoding.

### 2011-2018 (SLPG01, SLPG005) - Grouped
Similar categorical encoding with hour ranges.

## PR #161 review

### Scope
PR adds master file cycles to existing sleep variables:
- SLP_02, SLP_03, SLP_04: Adding cchs2011_2012_m, cchs2013_2014_m, cchs2015_2016_m
- SLP_02_A, SLP_03_A, SLP_04_A: Adding cchs2001_m
- SLPG01_A: Adding cchs2001_p (already has cchs2007_2008_p), cchs2015_2016_m
- SLPG01_B: New variable for cchs2011_2012_m, cchs2013_2014_m
- SLPG01_cont: Adding master cycles

### Issues identified

1. **SLPG01_C variableStart reference**: Uses `cchs2015_2016_m::SLP_009` but need to verify this is the correct Master file variable name (PUMF uses SLPG005).

2. **Scale consistency**: The PR correctly maintains separate _A variables for 2001 due to the scale difference.

3. **Database name format**: Need to verify all database names follow the correct format (e.g., `cchs2011_2012_m` not `cchs_2011_2012_m`).

## Recommendations

1. Verify SLPG01_C source variable for 2015-2016 Master file
2. Document the scale incompatibility between 2001 and later cycles in variable notes
3. Add coverage note about 2003, 2005, 2009-2010 being unavailable

## Sources reviewed

- [x] cchs_available_variables_list.csv
- [x] CCHS 2001 DDI
- [x] CCHS 2015-2016 DDI
- [x] Existing variables.csv
- [x] PR #161 diff
54 changes: 54 additions & 0 deletions ceps/cep-005-sleep/PR-notes.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: "PR #161 review notes"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```

## Summary

PR #161 adds Master file cycles for sleep variables. The review found **no critical errors** requiring fixes. The worksheets correctly:
1. Exclude cycles without sleep data (2003, 2005, 2009-2010)
2. Handle scale incompatibility between 2001 (3-point) and 2007+ (5-point)
3. Map era-specific source variable names correctly

## Sleep variable availability

| Cycle | PUMF sleep data | Notes |
|-------|-----------------|-------|
| 2001 | Yes | GENA_03-06; 3-point scale |
| 2003 | **No** | Not in PUMF |
| 2005 | **No** | Not in PUMF |
| 2007-2008 | Yes | SLP_01-04; 5-point scale |
| 2009-2010 | **No** | Not in PUMF |
| 2011-2012 | Yes | SLPG01, SLP_02-04 |
| 2013-2014 | Yes | SLPG01, SLP_02-04 |
| 2015-2016 | Yes | SLPG005, SLP_010-020 |
| 2017-2018 | Yes | SLPG005, SLP_010-020 |

## Scale incompatibility

The worksheets correctly handle the scale difference:

- **2001 (3-point):** Most of the time / Sometimes / Never → harmonized to `SLP_02_A`, `SLP_03_A`, `SLP_04_A`
- **2007+ (5-point):** None / A little / Some / Most / All → harmonized to `SLP_02`, `SLP_03`, `SLP_04`

## Variable naming verified

| Era | Hours | Trouble | Refreshing | Awake |
|-----|-------|---------|------------|-------|
| 2001 | GENA_03 | GENA_04 | GENA_05 | GENA_06 |
| 2007-2008 | SLP_01 | SLP_02 | SLP_03 | SLP_04 |
| 2011-2014 | SLPG01 | SLP_02 | SLP_03 | SLP_04 |
| 2015-2018 | SLPG005 | SLP_010 | SLP_015 | SLP_020 |

## Verification notes

1. **SLPG01_C source variable (SLP_009):** The worksheet references `cchs2015_2016_m::SLP_009` for Master files. This is consistent with ICES naming conventions where individual hour categories use sequential SLP_XXX codes (SLP_007 = 3-4h, SLP_008 = 4-5h, SLP_009 = 5-6h, etc.), different from PUMF's grouped SLPG005 variable.

2. **Missing cycles:** Verified via DDI XML grep that 2003, 2005, and 2009-2010 PUMF files do not contain sleep variables. The worksheets correctly exclude these cycles.

## Recommendation

**Approve and merge PR #161.** No worksheet fixes required.
59 changes: 59 additions & 0 deletions ceps/cep-005-sleep/PR_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# PR #161 review notes: Sleep variables

**Review date:** 2026-01-26
**PR:** [#161 - Sleep variables](https://github.com/big-life-lab/cchsflow/pull/161)
**Status:** Ready for merge

## Summary

PR #161 adds Master file cycles for sleep variables. The review found **no critical errors** requiring fixes. The worksheets correctly:

1. Exclude cycles without sleep data (2003, 2005, 2009-2010)
2. Handle scale incompatibility between 2001 (3-point) and 2007+ (5-point)
3. Map era-specific source variable names correctly

## Key findings

### Sleep variable availability

| Cycle | PUMF sleep data | Notes |
|-------|-----------------|-------|
| 2001 | Yes | GENA_03-06; 3-point scale |
| 2003 | **No** | Not in PUMF |
| 2005 | **No** | Not in PUMF |
| 2007-2008 | Yes | SLP_01-04; 5-point scale |
| 2009-2010 | **No** | Not in PUMF |
| 2011-2012 | Yes | SLPG01, SLP_02-04 |
| 2013-2014 | Yes | SLPG01, SLP_02-04 |
| 2015-2016 | Yes | SLPG005, SLP_010-020 |
| 2017-2018 | Yes | SLPG005, SLP_010-020 |

### Scale incompatibility

The worksheets correctly handle the scale difference:
- **2001 (3-point):** Most of the time / Sometimes / Never → harmonized to `SLP_02_A`, `SLP_03_A`, `SLP_04_A`
- **2007+ (5-point):** None / A little / Some / Most / All → harmonized to `SLP_02`, `SLP_03`, `SLP_04`

### Variable naming verified

| Era | Hours | Trouble | Refreshing | Awake |
|-----|-------|---------|------------|-------|
| 2001 | GENA_03 | GENA_04 | GENA_05 | GENA_06 |
| 2007-2008 | SLP_01 | SLP_02 | SLP_03 | SLP_04 |
| 2011-2014 | SLPG01 | SLP_02 | SLP_03 | SLP_04 |
| 2015-2018 | SLPG005 | SLP_010 | SLP_015 | SLP_020 |

## Verification notes

1. **SLPG01_C source variable (SLP_009):** The worksheet references `cchs2015_2016_m::SLP_009` for Master files. This is consistent with ICES naming conventions where individual hour categories use sequential SLP_XXX codes (SLP_007 = 3-4h, SLP_008 = 4-5h, SLP_009 = 5-6h, etc.), different from PUMF's grouped SLPG005 variable.

2. **Missing cycles:** Verified via DDI XML grep that 2003, 2005, and 2009-2010 PUMF files do not contain sleep variables. The worksheets correctly exclude these cycles.

## Recommendation

**Approve and merge PR #161.** No worksheet fixes required.

## Related documentation

- [L0_documentation_assessment.md](L0_documentation_assessment.md) - Detailed DDI review
- [integration-test.qmd](integration-test.qmd) - rec_with_table() validation
4 changes: 4 additions & 0 deletions ceps/cep-005-sleep/_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- source: project
quarto-pub:
- id: d4fca22b-634c-4b2a-b380-88696b5dc838
url: https://dmanuel.quarto.pub/cep-005-sleep-variables
22 changes: 22 additions & 0 deletions ceps/cep-005-sleep/_quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
project:
type: website
output-dir: _site

website:
title: "CEP-005: Sleep variables"
navbar:
left:
- href: index.qmd
text: Home
- href: availability-matrix.qmd
text: Availability matrix
- href: integration-test.qmd
text: Integration test
- href: PR-notes.qmd
text: PR notes

format:
html:
theme: cosmo
toc: true
code-fold: true
Loading
Loading