#regex to extract participant Id and wearing position
# pattern <- "[A-Z]+_S[0-9]{3}_[hcw]"
#regex to extract participant Id
pattern <- "[A-Z]+_S[0-9]{3}"Import light chest
Preface
This is a work-in-progress descriptive analysis of the BaezaEtAl2025 dataset.
Overview
Data import: wearable data
The first step is the import of wearable data from the chest position (mounted on chest).
files <- filefinder("actlumus_chest", continuous = TRUE, negate = "Report")data <-
import$ActLumus(files[c(1:18, 20, 22:23)], tzs[site], auto.id = pattern,
dst_adjustment = TRUE)
Successfully read in 1'319'596 observations across 21 Ids from 21 ActLumus-file(s).
Timezone set is Europe/Madrid.
The system timezone is Europe/Berlin. Please correct if necessary!
Observations in the following 2 file(s) and 2 Id(s) cross to or from daylight savings time (DST):
File: FUSPCEU_S007_c_actlumus_Log_4323_20241028170119234, Group:FUSPCEU_S007
File: FUSPCEU_S008_c_actlumus_Log_4039_20241028190458928, Group:FUSPCEU_S008
The Datetime column was adjusted in these files. For more info on what that entails see `?dst_change_handler`.
First Observation: 2024-10-07 15:26:14
Last Observation: 2025-02-12 14:18:41
Timespan: 128 days
Observation intervals:
Id interval.time n pct
1 FUSPCEU_S003 10s 59794 100%
2 FUSPCEU_S003 13s 1 0%
3 FUSPCEU_S004 10s 59788 100%
4 FUSPCEU_S004 15s 1 0%
5 FUSPCEU_S005 10s 60101 100%
6 FUSPCEU_S006 10s 60372 100%
7 FUSPCEU_S007 10s 62317 100%
8 FUSPCEU_S008 10s 62915 100%
9 FUSPCEU_S009 10s 66377 100%
10 FUSPCEU_S010 10s 66886 100%
# ℹ 13 more rows
Two files need further adjustment, as they contains timestamps from yr 2000 and 2008. The former is a typical issue with ActLumus devices after their battery is empty. We will use the other two wearing positions (wrist and head) to derive a valid offset
#getting all wearing positions
files <- list.dirs("../data/raw/individual/FUSPCEU_S023/continuous", full.names = TRUE)
files <- files[str_detect(files, "actlumus")] |> list.files(full.names = TRUE)
files <- files[str_detect(files, "Report", negate = TRUE)]
#loading the data
pattern <- "[A-Z]+_S[0-9]{3}_[hcw]"
data2 <-
import$ActLumus(files, tzs[site], auto.id = pattern,
dst_adjustment = TRUE, not.before = "1970-01-01")
Successfully read in 181'415 observations across 3 Ids from 3 ActLumus-file(s).
Timezone set is Europe/Madrid.
The system timezone is Europe/Berlin. Please correct if necessary!
First Observation: 2000-01-01 00:04:11
Last Observation: 2025-02-03 13:32:52
Timespan: 9166 days
Observation intervals:
Id interval.time n pct
1 FUSPCEU_S023_c 10s 60484 100%
2 FUSPCEU_S023_h 10s 60453 100%
3 FUSPCEU_S023_w 10s 60475 100%
data2 |>
mutate(
Datetime = case_when(
Id == "FUSPCEU_S023_c" ~ Datetime + dyears(25) + ddays(27) + dhours(7) + dminutes(45),
Id == "FUSPCEU_S023_w" ~ Datetime + dhours(4),
.default = Datetime)
) |>
gg_day(geom = "line", aes_col = Id) |>
gg_photoperiod(coordinates[[site]])data2 <-
data2 |>
mutate(
Datetime = case_when(
Id == "FUSPCEU_S023_c" ~ Datetime + dyears(25) + ddays(27) + dhours(7) + dminutes(45),
Id == "FUSPCEU_S023_w" ~ Datetime + dhours(4),
.default = Datetime)
)#getting all wearing positions
files <- list.dirs("../data/raw/individual/FUSPCEU_S021/continuous", full.names = TRUE)
files <- files[str_detect(files, "actlumus")] |> list.files(full.names = TRUE)
files <- files[str_detect(files, "Report", negate = TRUE)]
#loading the data
pattern <- "[A-Z]+_S[0-9]{3}_[hcw]"
data3 <-
import$ActLumus(files, tzs[site], auto.id = pattern,
dst_adjustment = TRUE)
Successfully read in 135'036 observations across 3 Ids from 3 ActLumus-file(s).
Timezone set is Europe/Madrid.
The system timezone is Europe/Berlin. Please correct if necessary!
First Observation: 2008-01-08 00:38:25
Last Observation: 2025-01-27 13:35:42
Data from before 2001-01-01 were not imported. Adjust with `not.before` if needed.
Timespan: 6230 days
Observation intervals:
Id interval.time n pct
1 FUSPCEU_S021_c 10s 12527 100%
2 FUSPCEU_S021_h 10s 61221 100%
3 FUSPCEU_S021_w 10s 61285 100%
data3 |>
mutate(
Datetime = case_when(
Id == "FUSPCEU_S021_c" ~ Datetime + dyears(17) + ddays(13) + dhours(4),
Id == "FUSPCEU_S021_w" ~ Datetime + dhours(4),
.default = Datetime)
) |>
gg_day(geom = "line", aes_col = Id, linewidth = 0.5) |>
gg_photoperiod(coordinates[[site]])+
coord_cartesian(xlim = c(20,24)*3600)data3 <-
data3 |>
mutate(
Datetime = case_when(
# Id == "FUSPCEU_S021_c" ~ Datetime + dyears(17) + ddays(13) + dhours(4),
Id == "FUSPCEU_S021_w" ~ Datetime + dhours(4),
.default = Datetime)
) |>
gg_day(geom = "line", aes_col = Id, linewidth = 0.5) |>
gg_photoperiod(coordinates[[site]])+
coord_cartesian(xlim = c(20,24)*3600)Taken together, S023 is solvable through careful shifting, S021 is not. Thus, we will discard the latter and keep the former.
data2 <-
data2 |>
sample_groups(sample = 1) |>
mutate(Id = "FUSPCEU_S023")
data <-
join_datasets(data, data2)
rm(data2)Regularizing data
In the first step, we will trim the data by the study time.
path_study_dates <- paste0("../data/Study_dates_MeLiDos_", site, ".xlsx")
#import table with study times
Study_dates <- read_excel(path_study_dates)
#gather the important information
Study_dates <-
Study_dates |>
rename(Id = subjectID_device, start = datetime_trial_start, end = datetime_trial_end) |>
select(Id, start, end) |>
mutate(across(c(start, end), \(x) force_tz(x, tzs[site])),
trial = TRUE) |>
filter(str_detect(Id, "_c$")) |>
mutate(Id = str_remove(Id, "_c$")) |>
group_by(Id)
#add the trim information to the dataset and filter by it
data <-
data |>
add_states(Study_dates) |>
dplyr::filter(trial) |>
select(-trial)
data |> gg_overview()data |> has_gaps()[1] FALSE
data |> has_irregulars()[1] FALSE
data |> gg_gaps(group.by.days = TRUE, show.irregulars = TRUE, full.days = FALSE)No gaps nor irregular values were found. Plot creation skipped
data_cleaned <-
data |>
gap_handler(full.days = TRUE)
data_cleaned |> gap_table(MEDI) |> cols_hide(ends_with("_n"))| Summary of available and missing data | |||||||||||||
| Variable: melanopic EDI | |||||||||||||
Data
|
Missing
|
||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Regular
|
Irregular
|
Range
|
Interval
|
Gaps
|
Implicit
|
Explicit
|
|||||||
| Time | % | n1,2 | Time | Time | N | ø | Time | % | Time | % | Time | % | |
| Overall | 21w 4d 1h 22m 30s | 86.8%3 | 0 | 24w 6d 2h | 10 | 44 | 1w 4d 12h 18m 45s | 3w 2d 37m 30s | 13.2%3 | 0s | 0.0%3 | 3w 2d 37m 30s | 13.2%3 |
| FUSPCEU_S003 | |||||||||||||
| 6d 21h 24m | 86.1% | 0 | 1w 1d | 10s | 2 | 13h 18m | 1d 2h 36m | 13.9% | 0s | 0.0% | 1d 2h 36m | 13.9% | |
| FUSPCEU_S004 | |||||||||||||
| 6d 21h 51m 10s | 86.4% | 0 | 1w 1d | 10s | 2 | 13h 4m 25s | 1d 2h 8m 50s | 13.6% | 0s | 0.0% | 1d 2h 8m 50s | 13.6% | |
| FUSPCEU_S005 | |||||||||||||
| 6d 22h 46m | 86.9% | 0 | 1w 1d | 10s | 2 | 12h 37m | 1d 1h 14m | 13.1% | 0s | 0.0% | 1d 1h 14m | 13.1% | |
| FUSPCEU_S006 | |||||||||||||
| 6d 23h 22m | 87.2% | 0 | 1w 1d | 10s | 2 | 12h 19m | 1d 38m | 12.8% | 0s | 0.0% | 1d 38m | 12.8% | |
| FUSPCEU_S007 | |||||||||||||
| 1w 4h 59m 10s | 89.6% | 0 | 1w 1d 1h | 10s | 2 | 10h 25s | 20h 50s | 10.4% | 0s | 0.0% | 20h 50s | 10.4% | |
| FUSPCEU_S008 | |||||||||||||
| 1w 6h 41m 10s | 90.5% | 0 | 1w 1d 1h | 10s | 2 | 9h 9m 25s | 18h 18m 50s | 9.5% | 0s | 0.0% | 18h 18m 50s | 9.5% | |
| FUSPCEU_S009 | |||||||||||||
| 1w 12h 8m | 83.4% | 0 | 1w 2d | 10s | 2 | 17h 56m | 1d 11h 52m | 16.6% | 0s | 0.0% | 1d 11h 52m | 16.6% | |
| FUSPCEU_S010 | |||||||||||||
| 4d 15h 54m 50s | 77.7% | 0 | 6d | 10s | 2 | 16h 2m 35s | 1d 8h 5m 10s | 22.3% | 0s | 0.0% | 1d 8h 5m 10s | 22.3% | |
| FUSPCEU_S011 | |||||||||||||
| 6d 23h 10m | 87.1% | 0 | 1w 1d | 10s | 2 | 12h 25m | 1d 50m | 12.9% | 0s | 0.0% | 1d 50m | 12.9% | |
| FUSPCEU_S012 | |||||||||||||
| 1w 1h 38m | 88.4% | 0 | 1w 1d | 10s | 2 | 11h 11m | 22h 22m | 11.6% | 0s | 0.0% | 22h 22m | 11.6% | |
| FUSPCEU_S013 | |||||||||||||
| 6d 22h 44m | 86.8% | 0 | 1w 1d | 10s | 2 | 12h 38m | 1d 1h 16m | 13.2% | 0s | 0.0% | 1d 1h 16m | 13.2% | |
| FUSPCEU_S014 | |||||||||||||
| 6d 1h 16m | 86.5% | 0 | 1w | 10s | 2 | 11h 22m | 22h 44m | 13.5% | 0s | 0.0% | 22h 44m | 13.5% | |
| FUSPCEU_S015 | |||||||||||||
| 6d 22h 2m | 86.5% | 0 | 1w 1d | 10s | 2 | 12h 59m | 1d 1h 58m | 13.5% | 0s | 0.0% | 1d 1h 58m | 13.5% | |
| FUSPCEU_S016 | |||||||||||||
| 6d 22h 59m 40s | 87.0% | 0 | 1w 1d | 10s | 2 | 12h 30m 10s | 1d 1h 20s | 13.0% | 0s | 0.0% | 1d 1h 20s | 13.0% | |
| FUSPCEU_S017 | |||||||||||||
| 6d 23h 24m 10s | 87.2% | 0 | 1w 1d | 10s | 2 | 12h 17m 55s | 1d 35m 50s | 12.8% | 0s | 0.0% | 1d 35m 50s | 12.8% | |
| FUSPCEU_S018 | |||||||||||||
| 6d 22h 5m 10s | 86.5% | 0 | 1w 1d | 10s | 2 | 12h 57m 25s | 1d 1h 54m 50s | 13.5% | 0s | 0.0% | 1d 1h 54m 50s | 13.5% | |
| FUSPCEU_S019 | |||||||||||||
| 6d 23h 50m 10s | 87.4% | 0 | 1w 1d | 10s | 2 | 12h 4m 55s | 1d 9m 50s | 12.6% | 0s | 0.0% | 1d 9m 50s | 12.6% | |
| FUSPCEU_S020 | |||||||||||||
| 1w 2h 39m 50s | 88.9% | 0 | 1w 1d | 10s | 2 | 10h 40m 5s | 21h 20m 10s | 11.1% | 0s | 0.0% | 21h 20m 10s | 11.1% | |
| FUSPCEU_S022 | |||||||||||||
| 6d 23h 1m 30s | 87.0% | 0 | 1w 1d | 10s | 2 | 12h 29m 15s | 1d 58m 30s | 13.0% | 0s | 0.0% | 1d 58m 30s | 13.0% | |
| FUSPCEU_S023 | |||||||||||||
| 6d 19h 52m 50s | 85.4% | 0 | 1w 1d | 10s | 2 | 14h 3m 35s | 1d 4h 7m 10s | 14.6% | 0s | 0.0% | 1d 4h 7m 10s | 14.6% | |
| FUSPCEU_S024 | |||||||||||||
| 6d 23h 47m 30s | 87.4% | 0 | 1w 1d | 10s | 2 | 12h 6m 15s | 1d 12m 30s | 12.6% | 0s | 0.0% | 1d 12m 30s | 12.6% | |
| FUSPCEU_S025 | |||||||||||||
| 6d 23h 45m 20s | 87.4% | 0 | 1w 1d | 10s | 2 | 12h 7m 20s | 1d 14m 40s | 12.6% | 0s | 0.0% | 1d 14m 40s | 12.6% | |
| 1 If n > 0: it is possible that the other summary statistics are affected, as they are calculated based on the most prominent interval. | |||||||||||||
| 2 Number of (missing or actual) observations | |||||||||||||
| 3 Based on times, not necessarily number of observations | |||||||||||||
Exporting values
data_cleaned <-
data_cleaned |> mutate(position = "chest")
light_chest_1min <-
data_cleaned |>
aggregate_Datetime("1 minute", numeric.handler = \(x) mean(x, na.rm = TRUE)) |>
remove_partial_data(MEDI, threshold.missing = "3 hours", by.date = TRUE)This dataset has irregular or singular data. Singular data will automatically be removed. If you are uncertain about irregular data, you can check them with `gap_finder`, `gap_table`, and `gg_gaps`.
light_chest <- data_cleaned
save(light_chest_1min, file = "../data/imported/light/light_chest_1minute.RData")
save(light_chest, file = "../data/imported/light/light_chest.RData")Visualization
prefix <- paste0(site, "_")
data_cleaned |>
mutate(Id = Id |> fct_relabel(\(x) str_remove(x, prefix))) |>
grand_overview(coordinates[[site]], cities[[site]], countries[[site]],
country_colors[[site]], photoperiod_sequence = 1)Stats
Summary table
summary_table(
data_cleaned,
coordinates = coordinates[[site]],
location = cities[[site]],
site = countries[[site]],
color = country_colors[[site]],
histograms = TRUE
)| Summary table | ||||
| Madrid, Spain, 40.4°N, 3.7°W, TZ: Europe/Madrid | ||||
| Overview | ||||
|---|---|---|---|---|
| Participants | Participants | 22 | ||
| Participant-days | Participant-days | 174 (6 - 9) | ||
| Days ≥80% complete | Days ≥80% complete | 130 (4 - 7) | ||
| Missing/irregular | Missing/Irregular | 13.0% (9.0% - 22.0%) | ||
| Photoperiod | Photoperiod | 11h 7m (10h 19m - 12h 23m) | 1 | |
| Metrics2 | ||||
| Dose | D (lx·h) | 7,135 ±11,522 (11 - 72,133) | ||
| Duration above 250 lx | TAT250 | 2h 32m ±2h 11s (0s - 8h 52m) | ||
| Duration within 1-10 lx | TWT1-10 | 2h 7m ±1h 51m (1m 30s - 13h 47m) | ||
| Duration below 1 lx | TBT1 | 12h 50m ±3h 9m (7h 54m - 23h 31m) | ||
| Period above 250 lx | PAT250 | 23m 34s ±24m 46s (0s - 2h 6m) | ||
| Duration above 1000 lx | TAT1000 | 37m 8s ±49m 43s (0s - 5h 9m) | ||
| First timing above 250 lx | FLiT250 | 09:39 ±02:30 (00:01 - 16:03) | 1 | |
| Mean timing above 250 lx | MLiT250 | 13:59 ±01:35 (09:12 - 20:26) | 1 | |
| Last timing above 250 lx | LLiT250 | 18:51 ±02:40 (09:59 - 23:56) | 1 | |
| Brightest 10h midpoint | M10midpoint | 14:28 ±01:45 (10:05 - 18:59) | 1 | |
| Darkest 5h midpoint | L5midpoint | 02:47 ±00:42 (02:29 - 06:19) | 1 | |
| Brightest 10h mean3 | M10mean (lx) | 89.8 ±97.6 (0.0 - 441.7) | ||
| Darkest 5h mean3 | L5mean (lx) | 0.0 ±0.0 (0.0 - 0.0) | ||
| Interdaily stability | IS | 0.305 ±0.091 (0.171 - 0.481) | ||
| Intradaily variability | IV | 1.428 ±0.398 (0.565 - 1.969) | ||
| values show: mean ±sd (min - max) and are all based on measurements of melanopic EDI (lx) | ||||
| 1 Histogram limits are set from 00:00 to 24:00 | ||||
| 2 Metrics are calculated on a by-participant-day basis (n=130) with the exception of IV and IS, which are calculated on a by-participant basis (n=22). | ||||
| 3 Values were log 10 transformed prior to averaging, with an offset of 0.1, and backtransformed afterwards | ||||