Dyadic time interval
Packages: dplyr, tidyr, ggplot2
In ESM dyadic studies, it is often expected to have a delay between the partners’ answers, but this delay must remain within a pre-defined expected range. For instance, it can be predetermined that the delay between the partners’ answer to the same beep must not exceed 30 minutes. Such aspects might have important implications, especially when plotting dyadic time series or when using discrete-time models.
Here, we propose to investigate two relevant types of delay. Note that the data might need to be reformatted to get a dyadic format.
- Intervals of time (in minutes) between partners’ responses to a same beep. In this context, we can investigate either the start time or the end time. A high value would suggest a significant duration between the initiation of the same beep questionnaire for partners within a dyad.
# Compute time interval
= data_dyad %>% filter(valid_1==1 & valid_2==1) %>%
df_dyad_int mutate(time_int = abs(difftime(start_1, start_2, units="mins")))
#Create plot
%>% filter(time_int < 2000) %>%
df_dyad_int ggplot(aes(x = time_int)) +
geom_histogram(bins=100)
- Interval of time (in minutes) between answer to current survey of partner 1 and answer to next survey of partner 2 (‘time_int_1’ variable), and vice versa (‘time_int_2’ variable).
When using longitudinal dyadic models, it is anticipated that the distribution will exhibit a reasonable range. Paying special attention to outliers is crucial to prevent potential bias in the model due to the heterogeneity of time intervals. To display those two variables we can use either an identity, stacked or fill histogram.
# Compute time interval
= data_dyad %>%
df_dyad_int group_by(dyad, daycum_1) %>%
mutate(time_int_1 = difftime(as.POSIXct(lead(start_1)), start_2, units="mins"),
time_int_2 = difftime(as.POSIXct(lead(start_2)), start_1, units="mins"))
#Create plot
%>%
df_dyad_int gather(time_int, val, time_int_1, time_int_2) %>%
ggplot(aes(x = val, fill=time_int)) +
geom_histogram(alpha=.5, position="identity")