Import LEBA

Author

Johannes Zauner

Preface

This document imports the LEBA and shows descriptive statistics for the site.

Setup

library(tidyverse)
library(LightLogR)
Warning: package 'LightLogR' was built under R version 4.5.2
library(glue)
library(readxl)
library(gt)
library(gtsummary)

remote <- 
  "https://raw.githubusercontent.com/MeLiDosProject/Data_Metadata_Conventions/main/scripts/"

c("labeling",
  "radio_factors",
  "add_label",
  "prepare_codebook",
  "filefinder",
  "general_parameters",
  "coltype_checker",
  "tables"
) |> walk(\(x) source(paste0(remote, x, ".R")))

Preparation

#collect codebook
codebook <- 
  prepare_codebook("MeLiDosDischargeQuestionnaire_DataDictionary_2024-10-16.csv",
                   "your_light_behaviour_leba")
#collect files
files <- filefinder("discharge",individual = FALSE)
files <- files |> 
          subset(grepl("LEBA", files))
#import files
data <- 
  read_csv(files, show_col_types = FALSE) |> 
  rename_with(\(x) str_remove_all(x, "_v2")) |> 
  drop_na(redcap_repeat_instance)
#check column types
coltype_check <- coltype_checker(codebook, data)
coltype_check$details |> gt()
col expected present actual type_ok issue expected_example
leba_f2_04 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f2_05 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f2_06 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f2_07 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f2_08 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f2_09 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f3_10 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f3_11 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f3_12 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f3_13 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f3_14 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f4_15 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f4_16 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f4_17 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f4_18 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f5_19 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f5_20 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f5_21 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f5_22 numeric TRUE numeric TRUE ok as.numeric(...)
leba_f5_23 numeric TRUE numeric TRUE ok as.numeric(...)
record_id character TRUE character TRUE ok as.character(...)
#collect relevant columns
relevant_columns <- 
  coltype_check$details |> 
  pull(col)
#select relevant columns
data <- data |> select(any_of(relevant_columns))
#label
data <-
data |> 
  add_radio_factors(codebook, 
                    var_col = `Variable / Field Name`, 
                    type_col = `Field Type`,
                    levels_col = `Choices, Calculations, OR Slider Labels`
                    ) |> 
  add_col_labels(codebook, var_col = `Variable / Field Name`, label_col = `Field Label`)

#reorder variables
data <- 
  data |> 
  relocate(any_of(codebook$`Variable / Field Name`))

Calculate LEBA factors

#Factor calculation
factors_leba <- list(
  F2 = paste0("leba_f2_0", 4:9),
  F3 = paste0("leba_f3_1", 0:4),
  F4 = paste0("leba_f4_1", 5:8),
  F5 = paste0("leba_f5_", 19:23)
)
Fs <- paste0("F", 2:5)

data <-
data |> 
  rowwise() |> 
  mutate(leba_f2_04 = fct_rev(leba_f2_04), 
         leba_f2 = rowSums(across(contains(factors_leba$F2), as.numeric)),
         leba_f3 = rowSums(across(contains(factors_leba$F3), as.numeric)),
         leba_f4 = rowSums(across(contains(factors_leba$F4), as.numeric)),
         leba_f5 = rowSums(across(contains(factors_leba$F5), as.numeric)),
         ) |> 
  mutate(leba_f2_04 = fct_rev(leba_f2_04)) |> 
  relocate(leba_f2:leba_f5, .after = record_id)

leba_factors <- c(
  leba_f2 = "F2: Spending time outdoors",
  leba_f3 = "F3: Using phones and smartwatches in bed before sleep",
  leba_f4 = "F4: Controlling and using ambient light before bedtime",
  leba_f5 = "F5: Using light in the morning and during daytime"
)


#label variables
data <- 
  data |> 
  add_labels(leba_factors)

data <-
data |> 
  add_col_labels(codebook, var_col = `Variable / Field Name`, label_col = `Field Label`)

Summarize results

table_leba(data)
Light exposure behaviour (LEBA) N N = 231
F2: Spending time outdoors 23 15.0 (12.0, 18.0)
F3: Using phones and smartwatches in bed before sleep 23 14.0 (10.0, 16.0)
F4: Controlling and using ambient light before bedtime 23 11.0 (8.0, 12.0)
F5: Using light in the morning and during daytime 23 14.00 (11.00, 16.00)
I spend 30 minutes or less per day (in total) outside. 23 3.00 (2.00, 4.00)
I spend between 30 minutes and 1 hour per day (in total) outside. 23 3.00 (3.00, 4.00)
I spend between 1 and 3 hours per day (in total) outside. 23 3.00 (2.00, 4.00)
I spend more than 3 hours per day (in total) outside. 23 2.00 (1.00, 3.00)
I spend as much time outside as possible. 23 2.00 (1.00, 3.00)
I go for a walk or exercise outside within 2 hours after waking up. 23 2.00 (1.00, 4.00)
I use my mobile phone within 1 hour before attempting to fall asleep.Note: this does not include the time spent filling in the questionnaires. 23 4.00 (4.00, 5.00)
I look at my mobile phone screen immediately after waking up.Note: this does not include the time spent filling in the questionnaires. 23 4.00 (2.00, 5.00)
I check my phone when I wake up at night. 23 2.00 (1.00, 3.00)
I look at my smartwatch within 1 hour before attempting to fall asleep.Note: please answer with regard to your personal smartwatch (if you own one), not the one actimeter given to you for the study 23 1.00 (1.00, 2.00)
I look at my smartwatch when I wake up at night.Note: please answer with regard to your personal smartwatch (if you own one), not the one actimeter given to you for the study 23 1.00 (1.00, 2.00)
I dim my mobile phone screen within 1 hour before attempting to fall asleep. 23 3.00 (1.00, 5.00)
I use a blue-filter app on my computer screen within 1 hour before attempting to fall asleep. 23 1.00 (1.00, 4.00)
I use as little light as possible when I get up during the night. 23 4.00 (1.00, 5.00)
I dim my computer screen within 1 hour before attempting to fall asleep. 23 1.00 (1.00, 4.00)
I use tunable lights to create a healthy light environment. 23 3.00 (1.00, 4.00)
I use LEDs to create a healthy light environment. 23 4.00 (2.00, 5.00)
I use a desk lamp when I do focused work. 23 4.00 (3.00, 5.00)
I use an alarm with a dawn simulation light. 23 1.00 (1.00, 1.00)
I turn on the lights immediately after waking up. 23 3.00 (1.00, 4.00)
Items are coded as follows. 1: Never | 2: Rarely | 3: Sometimes | 4: Often | 5: Always. Factors ('F') are numerical summations
1 Median (Q1, Q3)
gtsave(table_leba(data), filename = "../output/tables/table_leba.png", vwidth = 800)
file:////var/folders/9p/326_k3kx43qbn_cyl1rqfhb00000gn/T//Rtmp0VQsSI/file17a6a216f98f2.html screenshot completed

Export

data <- data |> rename(Id = record_id)
leba <- data
path <- "../data/imported/"
if(!dir.exists(path)) dir.create(path, recursive = TRUE)
save(leba, file = "../data/imported/leba.RData")