Last updated: 2024-10-03

Checks: 6 1

Knit directory: SAPPHIRE/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20240923) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version b3f933f. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rapp.history
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store

Untracked files:
    Untracked:  analysis/data_cleaning_1.Rmd
    Untracked:  analysis/data_cleaning_2.Rmd

Unstaged changes:
    Deleted:    analysis/data_cleaning.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


About: This is the second iteration of data cleaning that must be done after data_cleaning_1. Here, I clean the screening_long long-form dataset to have columns for body_site and reflectance_type (as well as collection_period, which was done in data_cleaning_1).

Set Up

  1. Load the relevant packages.
library(tidyr)
  1. Load the data.
data <- read.csv("data/screening_long.csv")
  1. View the first few rows.
head(data)
  participant_centre_id interviewer_name today_date age_years date_of_birth
1               VDKH001            Betty 2013-02-11        20    1993-08-07
2               VDKH002            Betty 2013-02-11        23    1990-01-20
3               VDKH003            Betty 2013-02-11        23    1989-05-05
4               VDKH004            Betty 2013-02-12        20    1992-08-10
5               VDKH005            Betty 2013-02-12        19    1993-05-06
6               VDKH006            Betty 2013-02-12        21    1992-04-14
  gender ethnicity_coloured ethnicity_white ethnicity_african_black
1      1              FALSE           FALSE                    TRUE
2      1              FALSE           FALSE                    TRUE
3      2              FALSE           FALSE                    TRUE
4      2              FALSE           FALSE                    TRUE
5      1              FALSE           FALSE                    TRUE
6      1              FALSE           FALSE                    TRUE
  ethnicity_indian_asian ethnicity_other ethnicity_specify_other ethnicity
1                  FALSE           FALSE                      NA        NA
2                  FALSE           FALSE                      NA        NA
3                  FALSE           FALSE                      NA        NA
4                  FALSE           FALSE                      NA        NA
5                  FALSE           FALSE                      NA        NA
6                  FALSE           FALSE                      NA        NA
  refuse_to_answer weight_measure1 weight_measure2 avg_weight height_measure1
1            FALSE            60.6            60.6       60.6           1.728
2            FALSE            60.5            60.5       60.5           1.678
3            FALSE            63.5            63.5       63.5           1.588
4            FALSE            64.4            64.4       64.4           1.595
5            FALSE            53.7            53.7       53.7           1.632
6            FALSE            53.3            53.3       53.3           1.523
  height_measure2 avg_height      bmi sore_throat_yes sore_throat_no
1           1.728      1.728 20.29482           FALSE           TRUE
2           1.678      1.678 21.48679           FALSE           TRUE
3           1.588      1.588 25.18098           FALSE           TRUE
4           1.595      1.595 25.31421           FALSE           TRUE
5           1.632      1.632 20.16202           FALSE           TRUE
6           1.523      1.523 22.97880           FALSE           TRUE
  runny_nose_yes runny_nose_no cough_yes cough_no fever_yes fever_no
1          FALSE          TRUE     FALSE     TRUE     FALSE     TRUE
2          FALSE          TRUE     FALSE     TRUE     FALSE     TRUE
3          FALSE          TRUE     FALSE     TRUE     FALSE     TRUE
4          FALSE          TRUE     FALSE     TRUE     FALSE     TRUE
5          FALSE          TRUE     FALSE     TRUE     FALSE     TRUE
6          FALSE          TRUE     FALSE     TRUE     FALSE     TRUE
  night_sweats_yes night_sweats_no unexplained_weight_loss_yes
1            FALSE            TRUE                       FALSE
2            FALSE            TRUE                       FALSE
3            FALSE            TRUE                       FALSE
4            FALSE            TRUE                       FALSE
5            FALSE            TRUE                       FALSE
6            FALSE            TRUE                       FALSE
  unexplained_weight_loss_no currently_taking_supplements_yes
1                       TRUE                            FALSE
2                       TRUE                            FALSE
3                       TRUE                            FALSE
4                       TRUE                            FALSE
5                       TRUE                            FALSE
6                       TRUE                            FALSE
  currently_taking_supplements_no supplements currently_taking_medications_yes
1                            TRUE        <NA>                            FALSE
2                            TRUE        <NA>                            FALSE
3                            TRUE        <NA>                            FALSE
4                            TRUE        <NA>                            FALSE
5                            TRUE        <NA>                            FALSE
6                            TRUE        <NA>                            FALSE
  currently_taking_medications_no medications participant_included_yes
1                            TRUE        <NA>                     TRUE
2                            TRUE        <NA>                     TRUE
3                            TRUE        <NA>                     TRUE
4                            TRUE        <NA>                     TRUE
5                            TRUE        <NA>                     TRUE
6                            TRUE        <NA>                     TRUE
  participant_included_no if_no_reason_for_exclusion
1                   FALSE                       <NA>
2                   FALSE                       <NA>
3                   FALSE                       <NA>
4                   FALSE                       <NA>
5                   FALSE                       <NA>
6                   FALSE                       <NA>
  smoking_do_you_regularly_smoke_at_least1cigarette5daysa_week smoking_comments
1                                                        FALSE             <NA>
2                                                        FALSE             <NA>
3                                                        FALSE             <NA>
4                                                        FALSE             <NA>
5                                                        FALSE             <NA>
6                                                        FALSE             <NA>
  skin_reflectance_forehead_e1 skin_reflectance_forehead_e2
1                        17.01                        18.73
2                        17.22                        19.82
3                        14.33                        16.13
4                        22.46                        21.45
5                        18.57                        19.73
6                        14.06                        15.28
  skin_reflectance_forehead_e3 skin_reflectance_forehead_m1
1                        18.61                        55.99
2                        17.41                        76.41
3                        14.25                        71.54
4                        20.53                        77.36
5                        21.06                        62.27
6                        16.76                        82.08
  skin_reflectance_forehead_m2 skin_reflectance_forehead_m3
1                        70.57                        76.28
2                        70.03                        74.73
3                        69.23                        69.63
4                        58.49                        57.67
5                        62.95                        65.07
6                        80.85                        85.21
  skin_reflectance_forehead_r1 skin_reflectance_forehead_r2
1                           70                           50
2                           44                           51
3                           49                           52
4                           46                           67
5                           57                           59
6                           38                           40
  skin_reflectance_forehead_r3 skin_reflectance_forehead_g1
1                           44                           47
2                           45                           30
3                           51                           36
4                           67                           26
5                           57                           36
6                           34                           27
  skin_reflectance_forehead_g2 skin_reflectance_forehead_g3
1                           33                           30
2                           32                           30
3                           36                           37
4                           42                           42
5                           38                           36
6                           28                           23
  skin_reflectance_forehead_b1 skin_reflectance_forehead_b2
1                           43                           30
2                           26                           29
3                           28                           30
4                           24                           38
5                           29                           34
6                           25                           26
  skin_reflectance_forehead_b3 skin_reflectance_forehead_l_1
1                           27                         19.93
2                           26                         11.93
3                           32                         13.88
4                           37                          8.59
5                           32                         15.02
6                           22                          9.24
  skin_reflectance_forehead_l_2 skin_reflectance_forehead_l_3
1                         13.10                         11.45
2                         12.82                         12.02
3                         14.54                         13.98
4                         16.59                         17.97
5                         15.19                         14.38
6                         10.28                          7.74
  skin_reflectance_foreheada_1 skin_reflectance_foreheada_2
1                        14.37                        11.16
2                         8.13                        12.65
3                         7.69                         9.87
4                        10.58                        16.24
5                        13.25                        13.04
6                         7.36                         7.99
  skin_reflectance_foreheada_3 skin_reflectance_foreheadb_1
1                         9.18                        11.62
2                         8.84                        10.60
3                        10.20                        13.20
4                        15.90                         5.72
5                        13.87                        14.01
6                         7.65                         6.62
  skin_reflectance_foreheadb_2 skin_reflectance_foreheadb_3
1                         9.28                         8.64
2                         9.39                        10.69
3                        12.56                        10.37
4                        11.40                        12.58
5                         9.78                         9.77
6                         7.15                         4.98
  skin_reflectance_right_upper_inner_arm_e1
1                                     20.92
2                                     20.11
3                                     16.17
4                                     14.98
5                                     20.45
6                                     18.83
  skin_reflectance_right_upper_inner_arm_e2
1                                     19.88
2                                     19.56
3                                     17.44
4                                     14.61
5                                     22.16
6                                     18.95
  skin_reflectance_right_upper_inner_arm_e3
1                                     19.99
2                                     19.41
3                                     16.59
4                                     12.84
5                                     19.50
6                                     18.95
  skin_reflectance_right_upper_inner_arm_m1
1                                     74.58
2                                     70.30
3                                     59.75
4                                     48.55
5                                     65.67
6                                     67.29
  skin_reflectance_right_upper_inner_arm_m2
1                                     71.88
2                                     70.57
3                                     62.50
4                                     46.70
5                                     70.56
6                                     66.16
  skin_reflectance_right_upper_inner_arm_m3
1                                     70.71
2                                     70.17
3                                     62.05
4                                     43.95
5                                     62.95
6                                     66.66
  skin_reflectance_right_upper_inner_arm_r1
1                                        47
2                                        50
3                                        64
4                                        84
5                                        56
6                                        54
  skin_reflectance_right_upper_inner_arm_r2
1                                        49
2                                        50
3                                        60
4                                        87
5                                        49
6                                        56
  skin_reflectance_right_upper_inner_arm_r3
1                                        50
2                                        50
3                                        60
4                                        89
5                                        60
6                                        55
  skin_reflectance_right_upper_inner_arm_g1
1                                        31
2                                        32
3                                        44
4                                        59
5                                        35
6                                        34
  skin_reflectance_right_upper_inner_arm_g2
1                                        31
2                                        32
3                                        40
4                                        63
5                                        30
6                                        36
  skin_reflectance_right_upper_inner_arm_g3
1                                        32
2                                        32
3                                        41
4                                        64
5                                        38
6                                        35
  skin_reflectance_right_upper_inner_arm_b1
1                                        29
2                                        29
3                                        39
4                                        54
5                                        32
6                                        31
  skin_reflectance_right_upper_inner_arm_b2
1                                        28
2                                        30
3                                        35
4                                        56
5                                        27
6                                        31
  skin_reflectance_right_upper_inner_arm_b3
1                                        30
2                                        30
3                                        36
4                                        58
5                                        35
6                                        32
  skin_reflectance_right_upper_inner_arm_l_1
1                                      12.03
2                                      12.73
3                                      18.41
4                                      25.68
5                                      14.38
6                                      13.83
  skin_reflectance_right_upper_inner_arm_l_2
1                                      12.27
2                                      12.68
3                                      16.64
4                                      26.54
5                                      11.90
6                                      14.34
  skin_reflectance_right_upper_inner_arm_l_3
1                                      12.68
2                                      12.68
3                                      16.95
4                                      27.43
5                                      16.23
6                                      14.28
  skin_reflectance_right_upper_inner_arma_1
1                                     10.72
2                                     11.94
3                                     12.36
4                                     14.09
5                                     13.87
6                                     13.23
  skin_reflectance_right_upper_inner_arma_2
1                                     12.00
2                                     12.09
3                                     12.58
4                                     14.51
5                                     12.78
6                                     13.02
  skin_reflectance_right_upper_inner_arma_3
1                                     12.09
2                                     12.09
3                                     11.97
4                                     14.54
5                                     13.47
6                                     13.17
  skin_reflectance_right_upper_inner_armb_1
1                                      7.97
2                                      9.29
3                                     12.24
4                                     14.37
5                                      9.77
6                                      9.62
  skin_reflectance_right_upper_inner_armb_2
1                                      9.18
2                                      8.25
3                                     12.04
4                                     15.54
5                                      9.15
6                                     10.73
  skin_reflectance_right_upper_inner_armb_3
1                                      8.25
2                                      8.25
3                                     10.95
4                                     14.65
5                                     11.03
6                                      9.68
  skin_reflectance_left_upper_inner_arm_e1
1                                    18.45
2                                    19.83
3                                    17.43
4                                    16.39
5                                    21.18
6                                    20.32
  skin_reflectance_left_upper_inner_arm_e2
1                                    18.08
2                                    20.32
3                                    17.19
4                                    14.77
5                                    21.63
6                                    20.12
  skin_reflectance_left_upper_inner_arm_e3
1                                    20.77
2                                    18.59
3                                    16.80
4                                    14.96
5                                    20.96
6                                    19.72
  skin_reflectance_left_upper_inner_arm_m1
1                                    73.11
2                                    70.30
3                                    62.95
4                                    49.64
5                                    69.23
6                                    65.55
  skin_reflectance_left_upper_inner_arm_m2
1                                    67.04
2                                    71.82
3                                    63.65
4                                    46.54
5                                    67.67
6                                    67.04
  skin_reflectance_left_upper_inner_arm_m3
1                                    69.36
2                                    70.99
3                                    65.19
4                                    46.78
5                                    65.67
6                                    66.66
  skin_reflectance_left_upper_inner_arm_r1
1                                       50
2                                       51
3                                       59
4                                       81
5                                       51
6                                       57
  skin_reflectance_left_upper_inner_arm_r2
1                                       53
2                                       49
3                                       59
4                                       86
5                                       52
6                                       55
  skin_reflectance_left_upper_inner_arm_r3
1                                       51
2                                       50
3                                       57
4                                       85
5                                       55
6                                       55
  skin_reflectance_left_upper_inner_arm_g1
1                                       33
2                                       32
3                                       40
4                                       56
5                                       31
6                                       35
  skin_reflectance_left_upper_inner_arm_g2
1                                       35
2                                       31
3                                       40
4                                       60
5                                       32
6                                       34
  skin_reflectance_left_upper_inner_arm_g3
1                                       31
2                                       33
3                                       39
4                                       59
5                                       34
6                                       35
  skin_reflectance_left_upper_inner_arm_b1
1                                       30
2                                       29
3                                       35
4                                       50
5                                       29
6                                       32
  skin_reflectance_left_upper_inner_arm_b2
1                                       33
2                                       28
3                                       36
4                                       54
5                                       30
6                                       31
  skin_reflectance_left_upper_inner_arm_b3
1                                       28
2                                       29
3                                       34
4                                       54
5                                       31
6                                       31
  skin_reflectance_left_upper_inner_arm_l_1
1                                     13.10
2                                     12.82
3                                     16.55
4                                     24.07
5                                     12.31
6                                     14.38
  skin_reflectance_left_upper_inner_arm_l_2
1                                     14.05
2                                     12.27
3                                     16.50
4                                     25.79
5                                     12.86
6                                     13.88
  skin_reflectance_left_upper_inner_arm_l_3
1                                     12.36
2                                     12.73
3                                     16.55
4                                     24.95
5                                     13.56
6                                     13.92
  skin_reflectance_left_upper_inner_arma_1
1                                    11.16
2                                    12.65
3                                    11.89
4                                    14.94
5                                    12.87
6                                    13.87
  skin_reflectance_left_upper_inner_arma_2
1                                    11.91
2                                    12.00
3                                    12.03
4                                    15.52
5                                    13.51
6                                    13.08
  skin_reflectance_left_upper_inner_arma_3
1                                    12.71
2                                    11.94
3                                    11.89
4                                    15.62
5                                    14.72
6                                    13.94
  skin_reflectance_left_upper_inner_armb_1
1                                     9.28
2                                     9.39
3                                    11.96
4                                    14.26
5                                     8.28
6                                     9.77
  skin_reflectance_left_upper_inner_armb_2
1                                     8.43
2                                     9.18
3                                    10.90
4                                    13.55
5                                     8.46
6                                    10.68
  skin_reflectance_left_upper_inner_armb_3 pathcare_sticker_barcode   req_num
1                                     9.28                785293139 785293139
2                                     9.29                785293140 785293140
3                                    11.96                785293141 785293141
4                                    13.45                785293142        NA
5                                     9.76                785293143 785293143
6                                     9.72                785293144 785293144
            serv_date vit_d_result       res_date_time collection_period
1 2013-02-11 10:40:00        29.50 2013-02-13 12:13:00            Summer
2 2013-02-11 11:00:00        17.80 2013-02-13 12:13:00            Summer
3 2013-02-11 00:00:11        25.00 2013-02-13 12:13:00            Summer
4          2013-02-12        20.83                <NA>            Summer
5 2013-02-12 00:00:11        29.20 2013-02-13 14:39:00            Summer
6 2013-02-12 00:00:11        20.50 2013-02-13 12:13:00            Summer
  continued_in_study if_not_continued_in_study_reason
1               <NA>                             <NA>
2               <NA>                             <NA>
3               <NA>                             <NA>
4               <NA>                             <NA>
5               <NA>                             <NA>
6               <NA>                             <NA>
  1. Reshaping the data to include each reflectance value in its own row, with separate columns for body site and reflectance type. This will create a long format dataset with two new columns:
  • Measurement: Contains the original column names (e.g., skin_reflectance_forehead_M1).
  • Reflectance: Contains the reflectance values.
data_long <- pivot_longer(data, 
                          cols = starts_with("skin_reflectance"), 
                          names_to = "measurement", 
                          values_to = "reflectance")
  1. Separate the measurement column into body_site and reflectance_type.
data_long <- separate(data_long, 
                      col = "measurement", 
                      into = c("Prefix", "body_site", "reflectance_type"), 
                      sep = "_", 
                      extra = "drop")

sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.6.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Detroit
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tidyr_1.3.1

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.9    dplyr_1.1.4       compiler_4.4.1    promises_1.3.0   
 [5] tidyselect_1.2.1  Rcpp_1.0.13       stringr_1.5.1     git2r_0.33.0     
 [9] later_1.3.2       jquerylib_0.1.4   yaml_2.3.10       fastmap_1.2.0    
[13] R6_2.5.1          generics_0.1.3    workflowr_1.7.1   knitr_1.48       
[17] tibble_3.2.1      rprojroot_2.0.4   bslib_0.8.0       pillar_1.9.0     
[21] rlang_1.1.4       utf8_1.2.4        cachem_1.1.0      stringi_1.8.4    
[25] httpuv_1.6.15     xfun_0.47         fs_1.6.4          sass_0.4.9       
[29] cli_3.6.3         withr_3.0.1       magrittr_2.0.3    digest_0.6.37    
[33] rstudioapi_0.16.0 lifecycle_1.0.4   vctrs_0.6.5       evaluate_1.0.0   
[37] glue_1.7.0        fansi_1.0.6       rmarkdown_2.28    purrr_1.0.2      
[41] tools_4.4.1       pkgconfig_2.0.3   htmltools_0.5.8.1