Time started and missed

Packages: dplyr, ggplot2, hms


Based on your sampling scheme, we can expect the participants to answer in specific ranges of time in the day (e.g., from 20:00 to 20:30). However, we can often observe deviations from the expected pattern (e.g., answers at 1 am), which can be due to a variety of factors, such as the participant’s daily routine, or an issue with the expiration time of the beep. Moreover, there are always large inter-individual differences in when the participant started to answer and at what time they missed beeps, even with a fixed-contingent design. The purpose of this topic is to introduce how to gather information on when the participants started to answer or missed the beeps (start time and end time).

Distributions

The easiest way to check this is to create an histogram that displays at what time of day the beeps were started (‘start’ variable) and missed (‘sent’ when ‘valid’=0). In the plot below, we will use a set of functions:

  • ‘hms::as_hms()’ to convert the time to an h/m/s format, hence removing the date.
  • ‘scales::date_breaks()’ to set the breaks of the x-axis at 2-hour intervals.
  • ‘strftime()’ to format the x-axis labels in hours and minutes.

Note that the proposed version of the code relies on the ‘valid’ variable (see Flag (in)valid observations topic), but you can adapt it to your own needs and data.

Warning

To plot the missing/invalid beeps, those must be a-priori recorded by the software used to collect data. If this is not the case, then you probably lose the information

data %>% 
    filter(valid==1) %>% # Filter for valid observations
    ggplot(aes(x = hms::as_hms(start))) +
        geom_histogram(bins=100) +
        scale_x_time(limits=hms::as_hms(c("00:00:00", "24:00:00")), 
                     breaks = scales::date_breaks("2 hours"),
                     labels = function(x) strftime(x, format = "%H:%M"))

Another visualization option is to only plot the hours of the day rather than the full time format. Here, the ‘hour()’ function from the ‘lubridate’ package is used to extract the hour from the ‘start’ and ‘sent’ variables.

data %>% 
    filter(valid==1) %>% 
    ggplot(aes(x = hour(start))) +
        geom_bar() + 
        scale_x_continuous(limits=c(0,24), breaks=c(0:24))

More plots

Since this series of visualizations follows the same underlying logic as the ones created for the Hour sent time topic of Step 2, you can discover there additional plots that can be adapted to the current context.