activAnalyzer

The activAnalyzer package was primarily built for working through a Shiny app. The procedure for using the app is explained in the related user’s guide. The functions used in this app can also be used to analyze data outside the app, as shown below.

Loading packages

library(activAnalyzer)
library(magrittr)
library(ggplot2)
library(patchwork)
library(dplyr)

Getting file

file <- system.file("extdata", "acc.agd", package = "activAnalyzer")

Preparing dataset

mydata <- prepare_dataset(data = file)

Getting nonwear/wear time marks

mydata_with_wear_marks <- 
  mydata %>%
  mark_wear_time(
    to_epoch = 60,
    cts = "vm",
    frame = 90, 
    allowanceFrame = 2, 
    streamFrame = 30
    )
#> frame is 90
#> streamFrame is 30
#> allowanceFrame is 2

Viewing data with nonwear/wear time marks

plot_data(data = mydata_with_wear_marks, metric = "vm")

Plot with nonwear/wear time marks

Viewing data with nonwear/wear time marks and with a zoom in on the figure

plot_data(
  data = mydata_with_wear_marks, 
  metric = "vm",
  zoom_from = "16:00:00",
  zoom_to = "18:00:00"
  )

Plot with nonwear/wear time marks and with a zoom in on the figure

Getting activity intensity marks

mydata_with_intensity_marks <- 
  mark_intensity(
     data = mydata_with_wear_marks, 
     col_axis = "vm", 
     equation = "Sasaki et al. (2011) [Adults]",
     sed_cutpoint = 200, 
     mpa_cutpoint = 2690, 
     vpa_cutpoint = 6167, 
     age = 32,
     weight = 67,
     sex = "male"
    )

Viewing data with activity intensity marks

plot_data_with_intensity(
  mydata_with_intensity_marks, 
  metric = "vm",
  valid_wear_time_start = "00:00:00",
  valid_wear_time_end = "23:59:59"
  )

Plot with activity intensity marks

Viewing data with activity intensity marks and grey bands to highlight the daily period considered for analysis

plot_data_with_intensity(
  mydata_with_intensity_marks, 
  metric = "vm",
  valid_wear_time_start = "07:00:00",
  valid_wear_time_end = "22:00:00"
  )

Plot with activity intensity marks and grey bands to highlight the daily period considered for analysis

Viewing data with activity intensity marks and a zoom in on the figure

plot_data_with_intensity(
  mydata_with_intensity_marks, 
  metric = "vm",
  zoom_from = "13:00:00",
  zoom_to = "16:30:00"
  )

Plot with activity intensity marks and a zoom in on the figure

Getting activity metrics by day

results_by_day <-
  mydata_with_intensity_marks %>%
  recap_by_day(
    age = 32, 
    weight = 67, 
    sex = "male",
    valid_wear_time_start = "07:00:00",
    valid_wear_time_end = "22:00:00",
    start_first_bin = 0,
    start_last_bin = 10000,
    bin_width = 500
    )

Computing means of the metrics using the valid days

mean_results <-
  results_by_day$df_all_metrics  %>%
  average_results(minimum_wear_time = 10, fun = "mean")

Computing medians of the metrics using the valid days

median_results <-
  results_by_day$df_all_metrics  %>%
  average_results(minimum_wear_time = 10, fun = "median")

Showing activity volume metrics

Results by day: Tabular view

results_by_day$df_all_metrics %>% 
  dplyr::select(date:total_steps) %>%
  reactable::reactable(striped = TRUE, defaultColDef = reactable::colDef(align = "center", minWidth = 180))
date
wear_time
total_counts_axis1
total_counts_vm
axis1_per_min
vm_per_min
minutes_SED
minutes_LPA
minutes_MPA
minutes_VPA
minutes_MVPA
percent_SED
percent_LPA
percent_MPA
percent_VPA
percent_MVPA
ratio_mvpa_sed
mets_hours_mvpa
total_kcal
pal
total_steps
2021-04-07
720
359125
721645.79
498.78
1002.29
288
355
73
4
77
40
49.31
10.14
0.56
10.69
0.27
5.56
1510.89
1.74
14056
2021-04-08
811
495257
946481.61
610.67
1167.06
292
407
105
7
112
36
50.18
12.95
0.86
13.81
0.38
7.84
1694.79
1.95
14595
2021-04-09
718
1222315
1945733.91
1702.39
2709.94
295
208
51
164
215
41.09
28.97
7.1
22.84
29.94
0.73
26.15
2694.09
3.1
21635
2021-04-10
770
320847
806592.09
416.68
1047.52
201
519
49
1
50
26.1
67.4
6.36
0.13
6.49
0.25
3.02
1548.93
1.78
13744
2021-04-11
820
167999
431269.63
204.88
525.94
339
470
11
0
11
41.34
57.32
1.34
0
1.34
0.03
0.59
1201.52
1.38
10315
2021-04-12
0
0
0
0
0
0
0
0
0
965.25
1.11
0

Results by day: Graphical view

create_fig_res_by_day(
  results_by_day$df_all_metrics, 
  minimum_wear_time_for_analysis = 10, 
  start_day_analysis = "00:00:00", 
  end_day_analysis = "23:59:00", 
  metrics = "volume",
  epoch_label = "60s"
  ) + theme(plot.margin = margin(1, 1, 1, 1, "cm"))

Graphical view of the results by day for the activity volume metrics

Means | Medians computed using valid days

create_flextable_summary(
  results_summary_means = mean_results, 
  results_summary_medians = median_results, 
  metrics = "volume",
  epoch_label = "60s"
  )


Comparisons with norms and recommendations

# PAL
g_pal <- create_fig_pal(score = mean_results[["pal"]], "en") + theme(plot.margin = margin(2, 1, 0.5, 1, "cm"))
  
# Steps
g_steps <- create_fig_steps(score = mean_results[["total_steps"]], "en") + theme(plot.margin = margin(0, 1, 0.5, 1, "cm"))

# MVPA
g_mvpa <- create_fig_mvpa(score = mean_results[["minutes_MVPA"]], "en") + theme(plot.margin = margin(0, 1, 0, 1, "cm"))

# SED
g_sed <- create_fig_sed(score = mean_results[["minutes_SED"]], "en") + theme(plot.margin = margin(0, 1, 0, 1, "cm"))

# MVPA/SED ratio
g_ratio <- create_fig_ratio_mvpa_sed(score = mean_results[["ratio_mvpa_sed"]], "en") + theme(plot.margin = margin(0, 1, 1, 1, "cm"))

# Whole figure
(g_pal + theme(legend.position = "top")) / g_steps / (g_mvpa | g_sed | g_ratio) + 
    plot_layout(heights = c(0.8, 0.7, 1.5)) & theme(legend.justification = "center")

Comparisons with norms and recommendations

Showing step accumulation metrics

Results by day: Tabular view

results_by_day$df_all_metrics %>% 
  dplyr::select(date, max_steps_60min:peak_steps_1min) %>%
  reactable::reactable(striped = TRUE, defaultColDef = reactable::colDef(align = "center", minWidth = 180))
date
max_steps_60min
max_steps_30min
max_steps_20min
max_steps_5min
max_steps_1min
peak_steps_60min
peak_steps_30min
peak_steps_20min
peak_steps_5min
peak_steps_1min
2021-04-07
75.18
100.93
102.8
119
121
89.03
114.33
117.55
120
121
2021-04-08
50.9
71.63
83.05
116.8
120
70.88
86.73
97.7
117.6
120
2021-04-09
101.33
104.9
107.55
112.8
118
110.07
112.23
113.4
117.2
118
2021-04-10
38.85
43.9
47.5
85.6
118
57.73
68.7
76.15
109.6
118
2021-04-11
23
28.9
30.55
41.8
68
45.3
51
53.95
61.8
68
2021-04-12

Results by day: Graphical view

create_fig_res_by_day(
  results_by_day$df_all_metrics, 
  minimum_wear_time_for_analysis = 10, 
  start_day_analysis = "00:00:00", 
  end_day_analysis = "23:59:00", 
  metrics = "step_acc",
  epoch_label = "60s"
  ) + theme(plot.margin = margin(1, 1, 1, 1, "cm"))

Graphical view of the results by day for the step accumulation metrics

Means | Medians computed using valid days

create_flextable_summary(
  results_summary_means = mean_results, 
  results_summary_medians = median_results,
  metrics = "step_acc",
  epoch_label = "60s"
  )


Showing intensity gradient and MX metrics

Distribution of time spent in intensity bins

  results_by_day$p_band

Distribution of time spent in intensity bins | Bar plot

  results_by_day$p_log

Distribution of time spent in intensity bins | Log-log plot

Results by day: Tabular view

results_by_day$df_all_metrics %>% 
  dplyr::select(date, ig:M5) %>%
  reactable::reactable(striped = TRUE, defaultColDef = reactable::colDef(align = "center", minWidth = 180))
date
ig
M1/3
M120
M60
M30
M15
M5
2021-04-07
-1.33
80.33
1998.67
3054.71
4721.17
5828.83
6160.1
2021-04-08
-1.36
323.79
2619.29
3671.61
4944.65
5763.85
6385.89
2021-04-09
-0.68
66.66
7560.33
9226.3
10066.52
10999.13
12113.34
2021-04-10
-2.03
477.97
2063.99
2612.85
3196.95
3603.35
5263.99
2021-04-11
-2.13
200.89
1202.82
1635.32
1963.83
2458.2
2870.01
2021-04-12

Results by day: Graphical view

create_fig_res_by_day(
  results_by_day$df_all_metrics, 
  minimum_wear_time_for_analysis = 10, 
  start_day_analysis = "00:00:00", 
  end_day_analysis = "23:59:00", 
  metrics = "int_distri",
  epoch_label = "60s"
  ) + theme(plot.margin = margin(1, 1, 1, 1, "cm"))

Graphical view of the results by day for the intensity gradient and MX metrics

Means | Medians computed using valid days

create_flextable_summary(
  results_summary_means = mean_results, 
  results_summary_medians = median_results,
  metrics = "int_distri",
  epoch_label = "60s"
  )


Radar view based on the means of valid days

create_fig_mx_summary(
data = mean_results,
labels = NULL,
mpa_cutpoint = 2690, 
vpa_cutpoint = 6167
)

Radar plot for the MX metrics

Showing sedentary behaviour accumulation metrics based on valid days

Getting results

accum_metrics_sed <- 
  compute_accumulation_metrics(
    data = mydata_with_intensity_marks, 
    behaviour = "sed",
    dates = c("2021-04-07", "2021-04-08", "2021-04-09", "2021-04-10", "2021-04-11")
    )

Temporal distribution of sedentary bouts

accum_metrics_sed$p_breaks

Temporal distribution of sedentary bouts

Alpha coefficient, median bout duration (MBD), usual bout duration (UBD), and Gini index

p1 <- accum_metrics_sed$p_alpha  + guides(color = "none", fill = "none")
p2 <- accum_metrics_sed$p_MBD    + guides(color = "none", fill = "none")
p3 <- accum_metrics_sed$p_UBD
p4 <- accum_metrics_sed$p_gini

(p1 | p2) / (p3 | p4) + plot_layout(guides = "collect") & theme(legend.position = 'bottom') 

Alpha coefficient, median bout duration (MBD), usual bout duration (UBD), and Gini index related to sedentary behaviour

Showing physical activity accumulation metrics based on valid days

Getting results

accum_metrics_pa <- 
  compute_accumulation_metrics(
    mydata_with_intensity_marks, 
    behaviour = "pa",
    dates = c("2021-04-07", "2021-04-08", "2021-04-09", "2021-04-10", "2021-04-11")
    )

Temporal distribution of physical activity bouts

accum_metrics_pa$p_breaks

Temporal distribution of physical activity bouts

Alpha coefficient, median bout duration (MBD), usual bout duration (UBD), and Gini index

p1 <- accum_metrics_pa$p_alpha  + guides(color = "none", fill = "none")
p2 <- accum_metrics_pa$p_MBD    + guides(color = "none", fill = "none")
p3 <- accum_metrics_pa$p_UBD
p4 <- accum_metrics_pa$p_gini

(p1 | p2) / (p3 | p4) + plot_layout(guides = "collect") & theme(legend.position = 'bottom') 

Alpha coefficient, median bout duration (MBD), usual bout duration (UBD), and Gini index related to physical activity