Introduction

This vignette demonstrates how to generate a sleep times dataframe and then proceed to process this for modeling with the Three Process Model of Fatigue. The code here demonstrates the usage from a higher-level user perspective.

Note that in future releases, we may seek to create functions that explicitly generate these sleep times for you. Furthermore, it is possible to simply create the sleeptimes in Excel or another program and transform to the format shown here. Therefore, the sleep generation features are presented here for practical purposes.

Data Preparation

Sleep Times Format

The dataframe below shows a prototypical FIPS ‘sleep times’ dataframe. This form of dataframe is intended for individuals who are manually inputting sleep history (e.g., from pencil forms to a spreadsheet). Below, we generate this data structure ourselves for convenience. Specifically, we want to simulate a scenario where an individual obtains exactly 7.5 hours of sleep per night for 6 nights. There are likely multiple ways to achieve this, but the generation function below allows sufficient flexibility to have continuously offset sleeptimes (e.g., by changing by = '24 hours' to another value).

The sleeptimes should correspond to only one participant (multiple people are not currently supported in FIPS without map functions). The default column names for this dataframe are sleep.id, sleep.start, and sleep.end. It is recommended that you explicitly specify timezones in all functions to avoid any silent errors relating to time zone specifications.

example.sleeptimes <- tibble::tibble(
  sleep.start = seq(
    from = lubridate::ymd_hms('2018-05-01 23:00:00', tz = "Australia/Perth"), 
    to = lubridate::ymd_hms('2018-05-07 17:00:00', tz = "Australia/Perth"),
    by = '24 hours'),
  sleep.end = sleep.start + lubridate::dhours(7.5),
  sleep.id = rank(sleep.start))

print(example.sleeptimes)
#> # A tibble: 6 x 3
#>   sleep.start         sleep.end           sleep.id
#>   <dttm>              <dttm>                 <dbl>
#> 1 2018-05-01 23:00:00 2018-05-02 06:30:00        1
#> 2 2018-05-02 23:00:00 2018-05-03 06:30:00        2
#> 3 2018-05-03 23:00:00 2018-05-04 06:30:00        3
#> 4 2018-05-04 23:00:00 2018-05-05 06:30:00        4
#> 5 2018-05-05 23:00:00 2018-05-06 06:30:00        5
#> 6 2018-05-06 23:00:00 2018-05-07 06:30:00        6

Prior to actually conducting the simulation, you must convert the sleep times to the continuous “FIPS_df” format. This format is a continuous time series style dataframe that contains calculated variables to be interpreted by the FIPS model functions. This dataframe contains the following headings: datetime, sleep.id, wake_status, wake_status_int, change_point, switch_direction, status_duration, total_prev, time, day, sim_hours. Information regarding these will be presented in the section below, but first let’s quickly run through how to generate the FIPS dataframe from sleep times.

The parse_sleeptimes function from FIPS will takes in ‘sleep times’ generated previously, and note the arguments below.

  • sleeptimes — The sleep times dataframe generated previously
  • series.start — This is the start datetime of the entire simulation series.
  • series.end — This will be the datetime of the entire simulation series
  • sleep.start.col — This is the name of your sleep.start column in sleep times if changed from default above
  • sleep.end.col — This is the name of your sleep.end column in sleep times if changed from default above
  • sleep.id.col — This is the name of your sleep.id column in sleep times if changed from default above
  • roundvalue — The epoch of the series (i.e., rounding value). Please read further information below!

The setting of roundvalue is critically important. It determines the epoch or spacing between observations in your dataset (in minutes). At a value of 1, the simulation is updated every 1 minute. Consequently, this will increase the size (in rows) of your dataset by a factor of 5 (relative to 5 minutes). In most cases, 5, 10 or even 15 minutes should be sufficient.

Moreover, note that all sleep observations will have their datetime rounded to this value. For example, with a roundvalue = 5 the datetime 2018-05-07 21:02:02 would be rounded to 2018-05-07 21:00:00. For this reason, it is ideal if your series.start and series.end are rounded to the same epoch value as you request. Seconds should never be included in your datetime (biomathematical models are not sensitive to this time resolution anyway).

# Simulation start date time (i.e., when you want first predictions to begin)
simulation.start = lubridate::ymd_hms('2018-05-01 07:00:00', tz = "Australia/Perth")

# Simulation end date time (i.e., when you want predictions to end)
# In this case it ends 
simulation.end = lubridate::ymd_hms('2018-05-07 21:00:00', tz = "Australia/Perth")

# The Continuous FIPS_df dataframe format
# This creates the format ready for simulation
simulated.dataframe = parse_sleeptimes(
  sleeptimes = example.sleeptimes,
  series.start = simulation.start,
  series.end = simulation.end,
  sleep.start.col = "sleep.start",
  sleep.end.col = "sleep.end",
  sleep.id.col = "sleep.id",
  roundvalue = 5)

print(simulated.dataframe)
#> # A tibble: 1,897 x 11
#>    datetime            sleep.id wake_status wake_status_int change_point
#>  * <dttm>                 <dbl> <lgl>                 <int>        <dbl>
#>  1 2018-05-01 07:00:00       NA TRUE                      1            0
#>  2 2018-05-01 07:05:00       NA TRUE                      1            0
#>  3 2018-05-01 07:10:00       NA TRUE                      1            0
#>  4 2018-05-01 07:15:00       NA TRUE                      1            0
#>  5 2018-05-01 07:20:00       NA TRUE                      1            0
#>  6 2018-05-01 07:25:00       NA TRUE                      1            0
#>  7 2018-05-01 07:30:00       NA TRUE                      1            0
#>  8 2018-05-01 07:35:00       NA TRUE                      1            0
#>  9 2018-05-01 07:40:00       NA TRUE                      1            0
#> 10 2018-05-01 07:45:00       NA TRUE                      1            0
#> # ... with 1,887 more rows, and 6 more variables: switch_direction <chr>,
#> #   status_duration <dbl>, total_prev <dbl>, time <dbl>, day <int>,
#> #   sim_hours <dbl>

Bitvector Sequence Format

It is common to represent sleep history information as a bitvector (i.e., a sequence of 1’s and 0’s). In bitvectors, sleep and wake times are represented by 1’s or 0’s, with each bit representing an equal time duration (e.g., 1 minute in that status). The bitvector sequence also must be relative to a start datetime. This format is commonly outputted from actigraphy devices (a form of wearable sleep tracker) and corresponding sleep detection algorithms (e.g., Cole-Kripke). Other proprietary software packages (e.g., SAFTE-FAST) require imported data to be in bit vector form (though the exact required formats do vary).

FIPS expects bitvectors to repesent sleep as 0 and wake as 1. The parse_sleepwake_sequence function can transform a bit vector sequence to a compliant FIPS_df. Below, an example of this data and steps to transform are provided, however, note that we do not use this dataframe again within this vignette.

# Simulation start date time (i.e., when you want first predictions to begin)
simulation.start = lubridate::ymd_hms('2018-05-01 10:00:00', tz = "Australia/Perth")

# Example bitvector sequence. This typically would be imported directly via a textfile.
# Here we generate, though typically this would be returned by a ReadLines/read.delim/read.table
bv.sleep.sequence = rep(rep(c(1,0), 6), sample(20:40, 12))

bv.sim.dataframe = parse_sleepwake_sequence(
  seq = bv.sleep.sequence,
  series.start = simulation.start,
  epoch = 15)

print(bv.sim.dataframe)
#>                datetime sleep.id  time day sim_hours wake_status_int
#> 1   2018-05-01 10:00:00       NA 10.00   1      0.00               1
#> 2   2018-05-01 10:15:00       NA 10.25   1      0.25               1
#> 3   2018-05-01 10:30:00       NA 10.50   1      0.50               1
#> 4   2018-05-01 10:45:00       NA 10.75   1      0.75               1
#> 5   2018-05-01 11:00:00       NA 11.00   1      1.00               1
#> 6   2018-05-01 11:15:00       NA 11.25   1      1.25               1
#> 7   2018-05-01 11:30:00       NA 11.50   1      1.50               1
#> 8   2018-05-01 11:45:00       NA 11.75   1      1.75               1
#> 9   2018-05-01 12:00:00       NA 12.00   1      2.00               1
#> 10  2018-05-01 12:15:00       NA 12.25   1      2.25               1
#> 11  2018-05-01 12:30:00       NA 12.50   1      2.50               1
#> 12  2018-05-01 12:45:00       NA 12.75   1      2.75               1
#> 13  2018-05-01 13:00:00       NA 13.00   1      3.00               1
#> 14  2018-05-01 13:15:00       NA 13.25   1      3.25               1
#> 15  2018-05-01 13:30:00       NA 13.50   1      3.50               1
#> 16  2018-05-01 13:45:00       NA 13.75   1      3.75               1
#> 17  2018-05-01 14:00:00       NA 14.00   1      4.00               1
#> 18  2018-05-01 14:15:00       NA 14.25   1      4.25               1
#> 19  2018-05-01 14:30:00       NA 14.50   1      4.50               1
#> 20  2018-05-01 14:45:00       NA 14.75   1      4.75               1
#> 21  2018-05-01 15:00:00       NA 15.00   1      5.00               1
#> 22  2018-05-01 15:15:00       NA 15.25   1      5.25               1
#> 23  2018-05-01 15:30:00       NA 15.50   1      5.50               1
#> 24  2018-05-01 15:45:00       NA 15.75   1      5.75               1
#> 25  2018-05-01 16:00:00       NA 16.00   1      6.00               1
#> 26  2018-05-01 16:15:00       NA 16.25   1      6.25               1
#> 27  2018-05-01 16:30:00        1 16.50   1      6.50               0
#> 28  2018-05-01 16:45:00        1 16.75   1      6.75               0
#> 29  2018-05-01 17:00:00        1 17.00   1      7.00               0
#> 30  2018-05-01 17:15:00        1 17.25   1      7.25               0
#> 31  2018-05-01 17:30:00        1 17.50   1      7.50               0
#> 32  2018-05-01 17:45:00        1 17.75   1      7.75               0
#> 33  2018-05-01 18:00:00        1 18.00   1      8.00               0
#> 34  2018-05-01 18:15:00        1 18.25   1      8.25               0
#> 35  2018-05-01 18:30:00        1 18.50   1      8.50               0
#> 36  2018-05-01 18:45:00        1 18.75   1      8.75               0
#> 37  2018-05-01 19:00:00        1 19.00   1      9.00               0
#> 38  2018-05-01 19:15:00        1 19.25   1      9.25               0
#> 39  2018-05-01 19:30:00        1 19.50   1      9.50               0
#> 40  2018-05-01 19:45:00        1 19.75   1      9.75               0
#> 41  2018-05-01 20:00:00        1 20.00   1     10.00               0
#> 42  2018-05-01 20:15:00        1 20.25   1     10.25               0
#> 43  2018-05-01 20:30:00        1 20.50   1     10.50               0
#> 44  2018-05-01 20:45:00        1 20.75   1     10.75               0
#> 45  2018-05-01 21:00:00        1 21.00   1     11.00               0
#> 46  2018-05-01 21:15:00        1 21.25   1     11.25               0
#> 47  2018-05-01 21:30:00        1 21.50   1     11.50               0
#> 48  2018-05-01 21:45:00        1 21.75   1     11.75               0
#> 49  2018-05-01 22:00:00        1 22.00   1     12.00               0
#> 50  2018-05-01 22:15:00        1 22.25   1     12.25               0
#> 51  2018-05-01 22:30:00        1 22.50   1     12.50               0
#> 52  2018-05-01 22:45:00        1 22.75   1     12.75               0
#> 53  2018-05-01 23:00:00        1 23.00   1     13.00               0
#> 54  2018-05-01 23:15:00       NA 23.25   1     13.25               1
#> 55  2018-05-01 23:30:00       NA 23.50   1     13.50               1
#> 56  2018-05-01 23:45:00       NA 23.75   1     13.75               1
#> 57  2018-05-02 00:00:00       NA  0.00   2     14.00               1
#> 58  2018-05-02 00:15:00       NA  0.25   2     14.25               1
#> 59  2018-05-02 00:30:00       NA  0.50   2     14.50               1
#> 60  2018-05-02 00:45:00       NA  0.75   2     14.75               1
#> 61  2018-05-02 01:00:00       NA  1.00   2     15.00               1
#> 62  2018-05-02 01:15:00       NA  1.25   2     15.25               1
#> 63  2018-05-02 01:30:00       NA  1.50   2     15.50               1
#> 64  2018-05-02 01:45:00       NA  1.75   2     15.75               1
#> 65  2018-05-02 02:00:00       NA  2.00   2     16.00               1
#> 66  2018-05-02 02:15:00       NA  2.25   2     16.25               1
#> 67  2018-05-02 02:30:00       NA  2.50   2     16.50               1
#> 68  2018-05-02 02:45:00       NA  2.75   2     16.75               1
#> 69  2018-05-02 03:00:00       NA  3.00   2     17.00               1
#> 70  2018-05-02 03:15:00       NA  3.25   2     17.25               1
#> 71  2018-05-02 03:30:00       NA  3.50   2     17.50               1
#> 72  2018-05-02 03:45:00       NA  3.75   2     17.75               1
#> 73  2018-05-02 04:00:00       NA  4.00   2     18.00               1
#> 74  2018-05-02 04:15:00       NA  4.25   2     18.25               1
#> 75  2018-05-02 04:30:00       NA  4.50   2     18.50               1
#> 76  2018-05-02 04:45:00       NA  4.75   2     18.75               1
#> 77  2018-05-02 05:00:00       NA  5.00   2     19.00               1
#> 78  2018-05-02 05:15:00       NA  5.25   2     19.25               1
#> 79  2018-05-02 05:30:00       NA  5.50   2     19.50               1
#> 80  2018-05-02 05:45:00       NA  5.75   2     19.75               1
#> 81  2018-05-02 06:00:00       NA  6.00   2     20.00               1
#> 82  2018-05-02 06:15:00       NA  6.25   2     20.25               1
#> 83  2018-05-02 06:30:00       NA  6.50   2     20.50               1
#> 84  2018-05-02 06:45:00       NA  6.75   2     20.75               1
#> 85  2018-05-02 07:00:00       NA  7.00   2     21.00               1
#> 86  2018-05-02 07:15:00       NA  7.25   2     21.25               1
#> 87  2018-05-02 07:30:00       NA  7.50   2     21.50               1
#> 88  2018-05-02 07:45:00       NA  7.75   2     21.75               1
#> 89  2018-05-02 08:00:00       NA  8.00   2     22.00               1
#> 90  2018-05-02 08:15:00       NA  8.25   2     22.25               1
#> 91  2018-05-02 08:30:00       NA  8.50   2     22.50               1
#> 92  2018-05-02 08:45:00        2  8.75   2     22.75               0
#> 93  2018-05-02 09:00:00        2  9.00   2     23.00               0
#> 94  2018-05-02 09:15:00        2  9.25   2     23.25               0
#> 95  2018-05-02 09:30:00        2  9.50   2     23.50               0
#> 96  2018-05-02 09:45:00        2  9.75   2     23.75               0
#> 97  2018-05-02 10:00:00        2 10.00   2     24.00               0
#> 98  2018-05-02 10:15:00        2 10.25   2     24.25               0
#> 99  2018-05-02 10:30:00        2 10.50   2     24.50               0
#> 100 2018-05-02 10:45:00        2 10.75   2     24.75               0
#> 101 2018-05-02 11:00:00        2 11.00   2     25.00               0
#> 102 2018-05-02 11:15:00        2 11.25   2     25.25               0
#> 103 2018-05-02 11:30:00        2 11.50   2     25.50               0
#> 104 2018-05-02 11:45:00        2 11.75   2     25.75               0
#> 105 2018-05-02 12:00:00        2 12.00   2     26.00               0
#> 106 2018-05-02 12:15:00        2 12.25   2     26.25               0
#> 107 2018-05-02 12:30:00        2 12.50   2     26.50               0
#> 108 2018-05-02 12:45:00        2 12.75   2     26.75               0
#> 109 2018-05-02 13:00:00        2 13.00   2     27.00               0
#> 110 2018-05-02 13:15:00        2 13.25   2     27.25               0
#> 111 2018-05-02 13:30:00        2 13.50   2     27.50               0
#> 112 2018-05-02 13:45:00        2 13.75   2     27.75               0
#> 113 2018-05-02 14:00:00        2 14.00   2     28.00               0
#> 114 2018-05-02 14:15:00        2 14.25   2     28.25               0
#> 115 2018-05-02 14:30:00        2 14.50   2     28.50               0
#> 116 2018-05-02 14:45:00        2 14.75   2     28.75               0
#> 117 2018-05-02 15:00:00       NA 15.00   2     29.00               1
#> 118 2018-05-02 15:15:00       NA 15.25   2     29.25               1
#> 119 2018-05-02 15:30:00       NA 15.50   2     29.50               1
#> 120 2018-05-02 15:45:00       NA 15.75   2     29.75               1
#> 121 2018-05-02 16:00:00       NA 16.00   2     30.00               1
#> 122 2018-05-02 16:15:00       NA 16.25   2     30.25               1
#> 123 2018-05-02 16:30:00       NA 16.50   2     30.50               1
#> 124 2018-05-02 16:45:00       NA 16.75   2     30.75               1
#> 125 2018-05-02 17:00:00       NA 17.00   2     31.00               1
#> 126 2018-05-02 17:15:00       NA 17.25   2     31.25               1
#> 127 2018-05-02 17:30:00       NA 17.50   2     31.50               1
#> 128 2018-05-02 17:45:00       NA 17.75   2     31.75               1
#> 129 2018-05-02 18:00:00       NA 18.00   2     32.00               1
#> 130 2018-05-02 18:15:00       NA 18.25   2     32.25               1
#> 131 2018-05-02 18:30:00       NA 18.50   2     32.50               1
#> 132 2018-05-02 18:45:00       NA 18.75   2     32.75               1
#> 133 2018-05-02 19:00:00       NA 19.00   2     33.00               1
#> 134 2018-05-02 19:15:00       NA 19.25   2     33.25               1
#> 135 2018-05-02 19:30:00       NA 19.50   2     33.50               1
#> 136 2018-05-02 19:45:00       NA 19.75   2     33.75               1
#> 137 2018-05-02 20:00:00       NA 20.00   2     34.00               1
#> 138 2018-05-02 20:15:00       NA 20.25   2     34.25               1
#> 139 2018-05-02 20:30:00       NA 20.50   2     34.50               1
#> 140 2018-05-02 20:45:00       NA 20.75   2     34.75               1
#> 141 2018-05-02 21:00:00        3 21.00   2     35.00               0
#> 142 2018-05-02 21:15:00        3 21.25   2     35.25               0
#> 143 2018-05-02 21:30:00        3 21.50   2     35.50               0
#> 144 2018-05-02 21:45:00        3 21.75   2     35.75               0
#> 145 2018-05-02 22:00:00        3 22.00   2     36.00               0
#> 146 2018-05-02 22:15:00        3 22.25   2     36.25               0
#> 147 2018-05-02 22:30:00        3 22.50   2     36.50               0
#> 148 2018-05-02 22:45:00        3 22.75   2     36.75               0
#> 149 2018-05-02 23:00:00        3 23.00   2     37.00               0
#> 150 2018-05-02 23:15:00        3 23.25   2     37.25               0
#> 151 2018-05-02 23:30:00        3 23.50   2     37.50               0
#> 152 2018-05-02 23:45:00        3 23.75   2     37.75               0
#> 153 2018-05-03 00:00:00        3  0.00   3     38.00               0
#> 154 2018-05-03 00:15:00        3  0.25   3     38.25               0
#> 155 2018-05-03 00:30:00        3  0.50   3     38.50               0
#> 156 2018-05-03 00:45:00        3  0.75   3     38.75               0
#> 157 2018-05-03 01:00:00        3  1.00   3     39.00               0
#> 158 2018-05-03 01:15:00        3  1.25   3     39.25               0
#> 159 2018-05-03 01:30:00        3  1.50   3     39.50               0
#> 160 2018-05-03 01:45:00        3  1.75   3     39.75               0
#> 161 2018-05-03 02:00:00        3  2.00   3     40.00               0
#> 162 2018-05-03 02:15:00        3  2.25   3     40.25               0
#> 163 2018-05-03 02:30:00        3  2.50   3     40.50               0
#> 164 2018-05-03 02:45:00        3  2.75   3     40.75               0
#> 165 2018-05-03 03:00:00        3  3.00   3     41.00               0
#> 166 2018-05-03 03:15:00        3  3.25   3     41.25               0
#> 167 2018-05-03 03:30:00        3  3.50   3     41.50               0
#> 168 2018-05-03 03:45:00        3  3.75   3     41.75               0
#> 169 2018-05-03 04:00:00        3  4.00   3     42.00               0
#> 170 2018-05-03 04:15:00        3  4.25   3     42.25               0
#> 171 2018-05-03 04:30:00        3  4.50   3     42.50               0
#> 172 2018-05-03 04:45:00        3  4.75   3     42.75               0
#> 173 2018-05-03 05:00:00        3  5.00   3     43.00               0
#> 174 2018-05-03 05:15:00        3  5.25   3     43.25               0
#> 175 2018-05-03 05:30:00        3  5.50   3     43.50               0
#> 176 2018-05-03 05:45:00        3  5.75   3     43.75               0
#> 177 2018-05-03 06:00:00        3  6.00   3     44.00               0
#> 178 2018-05-03 06:15:00       NA  6.25   3     44.25               1
#> 179 2018-05-03 06:30:00       NA  6.50   3     44.50               1
#> 180 2018-05-03 06:45:00       NA  6.75   3     44.75               1
#> 181 2018-05-03 07:00:00       NA  7.00   3     45.00               1
#> 182 2018-05-03 07:15:00       NA  7.25   3     45.25               1
#> 183 2018-05-03 07:30:00       NA  7.50   3     45.50               1
#> 184 2018-05-03 07:45:00       NA  7.75   3     45.75               1
#> 185 2018-05-03 08:00:00       NA  8.00   3     46.00               1
#> 186 2018-05-03 08:15:00       NA  8.25   3     46.25               1
#> 187 2018-05-03 08:30:00       NA  8.50   3     46.50               1
#> 188 2018-05-03 08:45:00       NA  8.75   3     46.75               1
#> 189 2018-05-03 09:00:00       NA  9.00   3     47.00               1
#> 190 2018-05-03 09:15:00       NA  9.25   3     47.25               1
#> 191 2018-05-03 09:30:00       NA  9.50   3     47.50               1
#> 192 2018-05-03 09:45:00       NA  9.75   3     47.75               1
#> 193 2018-05-03 10:00:00       NA 10.00   3     48.00               1
#> 194 2018-05-03 10:15:00       NA 10.25   3     48.25               1
#> 195 2018-05-03 10:30:00       NA 10.50   3     48.50               1
#> 196 2018-05-03 10:45:00       NA 10.75   3     48.75               1
#> 197 2018-05-03 11:00:00       NA 11.00   3     49.00               1
#> 198 2018-05-03 11:15:00       NA 11.25   3     49.25               1
#> 199 2018-05-03 11:30:00       NA 11.50   3     49.50               1
#> 200 2018-05-03 11:45:00       NA 11.75   3     49.75               1
#> 201 2018-05-03 12:00:00       NA 12.00   3     50.00               1
#> 202 2018-05-03 12:15:00       NA 12.25   3     50.25               1
#> 203 2018-05-03 12:30:00       NA 12.50   3     50.50               1
#> 204 2018-05-03 12:45:00       NA 12.75   3     50.75               1
#> 205 2018-05-03 13:00:00       NA 13.00   3     51.00               1
#> 206 2018-05-03 13:15:00       NA 13.25   3     51.25               1
#> 207 2018-05-03 13:30:00       NA 13.50   3     51.50               1
#> 208 2018-05-03 13:45:00       NA 13.75   3     51.75               1
#> 209 2018-05-03 14:00:00       NA 14.00   3     52.00               1
#> 210 2018-05-03 14:15:00       NA 14.25   3     52.25               1
#> 211 2018-05-03 14:30:00       NA 14.50   3     52.50               1
#> 212 2018-05-03 14:45:00       NA 14.75   3     52.75               1
#> 213 2018-05-03 15:00:00       NA 15.00   3     53.00               1
#> 214 2018-05-03 15:15:00       NA 15.25   3     53.25               1
#> 215 2018-05-03 15:30:00       NA 15.50   3     53.50               1
#> 216 2018-05-03 15:45:00       NA 15.75   3     53.75               1
#> 217 2018-05-03 16:00:00        4 16.00   3     54.00               0
#> 218 2018-05-03 16:15:00        4 16.25   3     54.25               0
#> 219 2018-05-03 16:30:00        4 16.50   3     54.50               0
#> 220 2018-05-03 16:45:00        4 16.75   3     54.75               0
#> 221 2018-05-03 17:00:00        4 17.00   3     55.00               0
#> 222 2018-05-03 17:15:00        4 17.25   3     55.25               0
#> 223 2018-05-03 17:30:00        4 17.50   3     55.50               0
#> 224 2018-05-03 17:45:00        4 17.75   3     55.75               0
#> 225 2018-05-03 18:00:00        4 18.00   3     56.00               0
#> 226 2018-05-03 18:15:00        4 18.25   3     56.25               0
#> 227 2018-05-03 18:30:00        4 18.50   3     56.50               0
#> 228 2018-05-03 18:45:00        4 18.75   3     56.75               0
#> 229 2018-05-03 19:00:00        4 19.00   3     57.00               0
#> 230 2018-05-03 19:15:00        4 19.25   3     57.25               0
#> 231 2018-05-03 19:30:00        4 19.50   3     57.50               0
#> 232 2018-05-03 19:45:00        4 19.75   3     57.75               0
#> 233 2018-05-03 20:00:00        4 20.00   3     58.00               0
#> 234 2018-05-03 20:15:00        4 20.25   3     58.25               0
#> 235 2018-05-03 20:30:00        4 20.50   3     58.50               0
#> 236 2018-05-03 20:45:00        4 20.75   3     58.75               0
#> 237 2018-05-03 21:00:00        4 21.00   3     59.00               0
#> 238 2018-05-03 21:15:00       NA 21.25   3     59.25               1
#> 239 2018-05-03 21:30:00       NA 21.50   3     59.50               1
#> 240 2018-05-03 21:45:00       NA 21.75   3     59.75               1
#> 241 2018-05-03 22:00:00       NA 22.00   3     60.00               1
#> 242 2018-05-03 22:15:00       NA 22.25   3     60.25               1
#> 243 2018-05-03 22:30:00       NA 22.50   3     60.50               1
#> 244 2018-05-03 22:45:00       NA 22.75   3     60.75               1
#> 245 2018-05-03 23:00:00       NA 23.00   3     61.00               1
#> 246 2018-05-03 23:15:00       NA 23.25   3     61.25               1
#> 247 2018-05-03 23:30:00       NA 23.50   3     61.50               1
#> 248 2018-05-03 23:45:00       NA 23.75   3     61.75               1
#> 249 2018-05-04 00:00:00       NA  0.00   4     62.00               1
#> 250 2018-05-04 00:15:00       NA  0.25   4     62.25               1
#> 251 2018-05-04 00:30:00       NA  0.50   4     62.50               1
#> 252 2018-05-04 00:45:00       NA  0.75   4     62.75               1
#> 253 2018-05-04 01:00:00       NA  1.00   4     63.00               1
#> 254 2018-05-04 01:15:00       NA  1.25   4     63.25               1
#> 255 2018-05-04 01:30:00       NA  1.50   4     63.50               1
#> 256 2018-05-04 01:45:00       NA  1.75   4     63.75               1
#> 257 2018-05-04 02:00:00       NA  2.00   4     64.00               1
#> 258 2018-05-04 02:15:00       NA  2.25   4     64.25               1
#> 259 2018-05-04 02:30:00       NA  2.50   4     64.50               1
#> 260 2018-05-04 02:45:00       NA  2.75   4     64.75               1
#> 261 2018-05-04 03:00:00       NA  3.00   4     65.00               1
#> 262 2018-05-04 03:15:00       NA  3.25   4     65.25               1
#> 263 2018-05-04 03:30:00       NA  3.50   4     65.50               1
#> 264 2018-05-04 03:45:00       NA  3.75   4     65.75               1
#> 265 2018-05-04 04:00:00       NA  4.00   4     66.00               1
#> 266 2018-05-04 04:15:00       NA  4.25   4     66.25               1
#> 267 2018-05-04 04:30:00       NA  4.50   4     66.50               1
#> 268 2018-05-04 04:45:00       NA  4.75   4     66.75               1
#> 269 2018-05-04 05:00:00        5  5.00   4     67.00               0
#> 270 2018-05-04 05:15:00        5  5.25   4     67.25               0
#> 271 2018-05-04 05:30:00        5  5.50   4     67.50               0
#> 272 2018-05-04 05:45:00        5  5.75   4     67.75               0
#> 273 2018-05-04 06:00:00        5  6.00   4     68.00               0
#> 274 2018-05-04 06:15:00        5  6.25   4     68.25               0
#> 275 2018-05-04 06:30:00        5  6.50   4     68.50               0
#> 276 2018-05-04 06:45:00        5  6.75   4     68.75               0
#> 277 2018-05-04 07:00:00        5  7.00   4     69.00               0
#> 278 2018-05-04 07:15:00        5  7.25   4     69.25               0
#> 279 2018-05-04 07:30:00        5  7.50   4     69.50               0
#> 280 2018-05-04 07:45:00        5  7.75   4     69.75               0
#> 281 2018-05-04 08:00:00        5  8.00   4     70.00               0
#> 282 2018-05-04 08:15:00        5  8.25   4     70.25               0
#> 283 2018-05-04 08:30:00        5  8.50   4     70.50               0
#> 284 2018-05-04 08:45:00        5  8.75   4     70.75               0
#> 285 2018-05-04 09:00:00        5  9.00   4     71.00               0
#> 286 2018-05-04 09:15:00        5  9.25   4     71.25               0
#> 287 2018-05-04 09:30:00        5  9.50   4     71.50               0
#> 288 2018-05-04 09:45:00        5  9.75   4     71.75               0
#> 289 2018-05-04 10:00:00        5 10.00   4     72.00               0
#> 290 2018-05-04 10:15:00        5 10.25   4     72.25               0
#> 291 2018-05-04 10:30:00        5 10.50   4     72.50               0
#> 292 2018-05-04 10:45:00        5 10.75   4     72.75               0
#> 293 2018-05-04 11:00:00        5 11.00   4     73.00               0
#> 294 2018-05-04 11:15:00        5 11.25   4     73.25               0
#> 295 2018-05-04 11:30:00        5 11.50   4     73.50               0
#> 296 2018-05-04 11:45:00        5 11.75   4     73.75               0
#> 297 2018-05-04 12:00:00        5 12.00   4     74.00               0
#> 298 2018-05-04 12:15:00        5 12.25   4     74.25               0
#> 299 2018-05-04 12:30:00        5 12.50   4     74.50               0
#> 300 2018-05-04 12:45:00        5 12.75   4     74.75               0
#> 301 2018-05-04 13:00:00        5 13.00   4     75.00               0
#> 302 2018-05-04 13:15:00        5 13.25   4     75.25               0
#> 303 2018-05-04 13:30:00        5 13.50   4     75.50               0
#> 304 2018-05-04 13:45:00       NA 13.75   4     75.75               1
#> 305 2018-05-04 14:00:00       NA 14.00   4     76.00               1
#> 306 2018-05-04 14:15:00       NA 14.25   4     76.25               1
#> 307 2018-05-04 14:30:00       NA 14.50   4     76.50               1
#> 308 2018-05-04 14:45:00       NA 14.75   4     76.75               1
#> 309 2018-05-04 15:00:00       NA 15.00   4     77.00               1
#> 310 2018-05-04 15:15:00       NA 15.25   4     77.25               1
#> 311 2018-05-04 15:30:00       NA 15.50   4     77.50               1
#> 312 2018-05-04 15:45:00       NA 15.75   4     77.75               1
#> 313 2018-05-04 16:00:00       NA 16.00   4     78.00               1
#> 314 2018-05-04 16:15:00       NA 16.25   4     78.25               1
#> 315 2018-05-04 16:30:00       NA 16.50   4     78.50               1
#> 316 2018-05-04 16:45:00       NA 16.75   4     78.75               1
#> 317 2018-05-04 17:00:00       NA 17.00   4     79.00               1
#> 318 2018-05-04 17:15:00       NA 17.25   4     79.25               1
#> 319 2018-05-04 17:30:00       NA 17.50   4     79.50               1
#> 320 2018-05-04 17:45:00       NA 17.75   4     79.75               1
#> 321 2018-05-04 18:00:00       NA 18.00   4     80.00               1
#> 322 2018-05-04 18:15:00       NA 18.25   4     80.25               1
#> 323 2018-05-04 18:30:00       NA 18.50   4     80.50               1
#> 324 2018-05-04 18:45:00       NA 18.75   4     80.75               1
#> 325 2018-05-04 19:00:00       NA 19.00   4     81.00               1
#> 326 2018-05-04 19:15:00       NA 19.25   4     81.25               1
#> 327 2018-05-04 19:30:00        6 19.50   4     81.50               0
#> 328 2018-05-04 19:45:00        6 19.75   4     81.75               0
#> 329 2018-05-04 20:00:00        6 20.00   4     82.00               0
#> 330 2018-05-04 20:15:00        6 20.25   4     82.25               0
#> 331 2018-05-04 20:30:00        6 20.50   4     82.50               0
#> 332 2018-05-04 20:45:00        6 20.75   4     82.75               0
#> 333 2018-05-04 21:00:00        6 21.00   4     83.00               0
#> 334 2018-05-04 21:15:00        6 21.25   4     83.25               0
#> 335 2018-05-04 21:30:00        6 21.50   4     83.50               0
#> 336 2018-05-04 21:45:00        6 21.75   4     83.75               0
#> 337 2018-05-04 22:00:00        6 22.00   4     84.00               0
#> 338 2018-05-04 22:15:00        6 22.25   4     84.25               0
#> 339 2018-05-04 22:30:00        6 22.50   4     84.50               0
#> 340 2018-05-04 22:45:00        6 22.75   4     84.75               0
#> 341 2018-05-04 23:00:00        6 23.00   4     85.00               0
#> 342 2018-05-04 23:15:00        6 23.25   4     85.25               0
#> 343 2018-05-04 23:30:00        6 23.50   4     85.50               0
#> 344 2018-05-04 23:45:00        6 23.75   4     85.75               0
#> 345 2018-05-05 00:00:00        6  0.00   5     86.00               0
#> 346 2018-05-05 00:15:00        6  0.25   5     86.25               0
#> 347 2018-05-05 00:30:00        6  0.50   5     86.50               0
#> 348 2018-05-05 00:45:00        6  0.75   5     86.75               0
#> 349 2018-05-05 01:00:00        6  1.00   5     87.00               0
#> 350 2018-05-05 01:15:00        6  1.25   5     87.25               0
#> 351 2018-05-05 01:30:00        6  1.50   5     87.50               0
#> 352 2018-05-05 01:45:00        6  1.75   5     87.75               0
#> 353 2018-05-05 02:00:00        6  2.00   5     88.00               0
#> 354 2018-05-05 02:15:00        6  2.25   5     88.25               0
#> 355 2018-05-05 02:30:00        6  2.50   5     88.50               0
#> 356 2018-05-05 02:45:00        6  2.75   5     88.75               0
#>     wake_status change_point switch_direction status_duration total_prev
#> 1          TRUE            0                0            0.00       0.00
#> 2          TRUE            0                0            0.25       0.00
#> 3          TRUE            0                0            0.50       0.00
#> 4          TRUE            0                0            0.75       0.00
#> 5          TRUE            0                0            1.00       0.00
#> 6          TRUE            0                0            1.25       0.00
#> 7          TRUE            0                0            1.50       0.00
#> 8          TRUE            0                0            1.75       0.00
#> 9          TRUE            0                0            2.00       0.00
#> 10         TRUE            0                0            2.25       0.00
#> 11         TRUE            0                0            2.50       0.00
#> 12         TRUE            0                0            2.75       0.00
#> 13         TRUE            0                0            3.00       0.00
#> 14         TRUE            0                0            3.25       0.00
#> 15         TRUE            0                0            3.50       0.00
#> 16         TRUE            0                0            3.75       0.00
#> 17         TRUE            0                0            4.00       0.00
#> 18         TRUE            0                0            4.25       0.00
#> 19         TRUE            0                0            4.50       0.00
#> 20         TRUE            0                0            4.75       0.00
#> 21         TRUE            0                0            5.00       0.00
#> 22         TRUE            0                0            5.25       0.00
#> 23         TRUE            0                0            5.50       0.00
#> 24         TRUE            0                0            5.75       0.00
#> 25         TRUE            0                0            6.00       0.00
#> 26         TRUE            0                0            6.25       0.00
#> 27        FALSE            1            Sleep            0.00       6.50
#> 28        FALSE            0                0            0.25       0.00
#> 29        FALSE            0                0            0.50       0.00
#> 30        FALSE            0                0            0.75       0.00
#> 31        FALSE            0                0            1.00       0.00
#> 32        FALSE            0                0            1.25       0.00
#> 33        FALSE            0                0            1.50       0.00
#> 34        FALSE            0                0            1.75       0.00
#> 35        FALSE            0                0            2.00       0.00
#> 36        FALSE            0                0            2.25       0.00
#> 37        FALSE            0                0            2.50       0.00
#> 38        FALSE            0                0            2.75       0.00
#> 39        FALSE            0                0            3.00       0.00
#> 40        FALSE            0                0            3.25       0.00
#> 41        FALSE            0                0            3.50       0.00
#> 42        FALSE            0                0            3.75       0.00
#> 43        FALSE            0                0            4.00       0.00
#> 44        FALSE            0                0            4.25       0.00
#> 45        FALSE            0                0            4.50       0.00
#> 46        FALSE            0                0            4.75       0.00
#> 47        FALSE            0                0            5.00       0.00
#> 48        FALSE            0                0            5.25       0.00
#> 49        FALSE            0                0            5.50       0.00
#> 50        FALSE            0                0            5.75       0.00
#> 51        FALSE            0                0            6.00       0.00
#> 52        FALSE            0                0            6.25       0.00
#> 53        FALSE            0                0            6.50       0.00
#> 54         TRUE            1             Wake            0.00       6.75
#> 55         TRUE            0                0            0.25       0.00
#> 56         TRUE            0                0            0.50       0.00
#> 57         TRUE            0                0            0.75       0.00
#> 58         TRUE            0                0            1.00       0.00
#> 59         TRUE            0                0            1.25       0.00
#> 60         TRUE            0                0            1.50       0.00
#> 61         TRUE            0                0            1.75       0.00
#> 62         TRUE            0                0            2.00       0.00
#> 63         TRUE            0                0            2.25       0.00
#> 64         TRUE            0                0            2.50       0.00
#> 65         TRUE            0                0            2.75       0.00
#> 66         TRUE            0                0            3.00       0.00
#> 67         TRUE            0                0            3.25       0.00
#> 68         TRUE            0                0            3.50       0.00
#> 69         TRUE            0                0            3.75       0.00
#> 70         TRUE            0                0            4.00       0.00
#> 71         TRUE            0                0            4.25       0.00
#> 72         TRUE            0                0            4.50       0.00
#> 73         TRUE            0                0            4.75       0.00
#> 74         TRUE            0                0            5.00       0.00
#> 75         TRUE            0                0            5.25       0.00
#> 76         TRUE            0                0            5.50       0.00
#> 77         TRUE            0                0            5.75       0.00
#> 78         TRUE            0                0            6.00       0.00
#> 79         TRUE            0                0            6.25       0.00
#> 80         TRUE            0                0            6.50       0.00
#> 81         TRUE            0                0            6.75       0.00
#> 82         TRUE            0                0            7.00       0.00
#> 83         TRUE            0                0            7.25       0.00
#> 84         TRUE            0                0            7.50       0.00
#> 85         TRUE            0                0            7.75       0.00
#> 86         TRUE            0                0            8.00       0.00
#> 87         TRUE            0                0            8.25       0.00
#> 88         TRUE            0                0            8.50       0.00
#> 89         TRUE            0                0            8.75       0.00
#> 90         TRUE            0                0            9.00       0.00
#> 91         TRUE            0                0            9.25       0.00
#> 92        FALSE            1            Sleep            0.00       9.50
#> 93        FALSE            0                0            0.25       0.00
#> 94        FALSE            0                0            0.50       0.00
#> 95        FALSE            0                0            0.75       0.00
#> 96        FALSE            0                0            1.00       0.00
#> 97        FALSE            0                0            1.25       0.00
#> 98        FALSE            0                0            1.50       0.00
#> 99        FALSE            0                0            1.75       0.00
#> 100       FALSE            0                0            2.00       0.00
#> 101       FALSE            0                0            2.25       0.00
#> 102       FALSE            0                0            2.50       0.00
#> 103       FALSE            0                0            2.75       0.00
#> 104       FALSE            0                0            3.00       0.00
#> 105       FALSE            0                0            3.25       0.00
#> 106       FALSE            0                0            3.50       0.00
#> 107       FALSE            0                0            3.75       0.00
#> 108       FALSE            0                0            4.00       0.00
#> 109       FALSE            0                0            4.25       0.00
#> 110       FALSE            0                0            4.50       0.00
#> 111       FALSE            0                0            4.75       0.00
#> 112       FALSE            0                0            5.00       0.00
#> 113       FALSE            0                0            5.25       0.00
#> 114       FALSE            0                0            5.50       0.00
#> 115       FALSE            0                0            5.75       0.00
#> 116       FALSE            0                0            6.00       0.00
#> 117        TRUE            1             Wake            0.00       6.25
#> 118        TRUE            0                0            0.25       0.00
#> 119        TRUE            0                0            0.50       0.00
#> 120        TRUE            0                0            0.75       0.00
#> 121        TRUE            0                0            1.00       0.00
#> 122        TRUE            0                0            1.25       0.00
#> 123        TRUE            0                0            1.50       0.00
#> 124        TRUE            0                0            1.75       0.00
#> 125        TRUE            0                0            2.00       0.00
#> 126        TRUE            0                0            2.25       0.00
#> 127        TRUE            0                0            2.50       0.00
#> 128        TRUE            0                0            2.75       0.00
#> 129        TRUE            0                0            3.00       0.00
#> 130        TRUE            0                0            3.25       0.00
#> 131        TRUE            0                0            3.50       0.00
#> 132        TRUE            0                0            3.75       0.00
#> 133        TRUE            0                0            4.00       0.00
#> 134        TRUE            0                0            4.25       0.00
#> 135        TRUE            0                0            4.50       0.00
#> 136        TRUE            0                0            4.75       0.00
#> 137        TRUE            0                0            5.00       0.00
#> 138        TRUE            0                0            5.25       0.00
#> 139        TRUE            0                0            5.50       0.00
#> 140        TRUE            0                0            5.75       0.00
#> 141       FALSE            1            Sleep            0.00       6.00
#> 142       FALSE            0                0            0.25       0.00
#> 143       FALSE            0                0            0.50       0.00
#> 144       FALSE            0                0            0.75       0.00
#> 145       FALSE            0                0            1.00       0.00
#> 146       FALSE            0                0            1.25       0.00
#> 147       FALSE            0                0            1.50       0.00
#> 148       FALSE            0                0            1.75       0.00
#> 149       FALSE            0                0            2.00       0.00
#> 150       FALSE            0                0            2.25       0.00
#> 151       FALSE            0                0            2.50       0.00
#> 152       FALSE            0                0            2.75       0.00
#> 153       FALSE            0                0            3.00       0.00
#> 154       FALSE            0                0            3.25       0.00
#> 155       FALSE            0                0            3.50       0.00
#> 156       FALSE            0                0            3.75       0.00
#> 157       FALSE            0                0            4.00       0.00
#> 158       FALSE            0                0            4.25       0.00
#> 159       FALSE            0                0            4.50       0.00
#> 160       FALSE            0                0            4.75       0.00
#> 161       FALSE            0                0            5.00       0.00
#> 162       FALSE            0                0            5.25       0.00
#> 163       FALSE            0                0            5.50       0.00
#> 164       FALSE            0                0            5.75       0.00
#> 165       FALSE            0                0            6.00       0.00
#> 166       FALSE            0                0            6.25       0.00
#> 167       FALSE            0                0            6.50       0.00
#> 168       FALSE            0                0            6.75       0.00
#> 169       FALSE            0                0            7.00       0.00
#> 170       FALSE            0                0            7.25       0.00
#> 171       FALSE            0                0            7.50       0.00
#> 172       FALSE            0                0            7.75       0.00
#> 173       FALSE            0                0            8.00       0.00
#> 174       FALSE            0                0            8.25       0.00
#> 175       FALSE            0                0            8.50       0.00
#> 176       FALSE            0                0            8.75       0.00
#> 177       FALSE            0                0            9.00       0.00
#> 178        TRUE            1             Wake            0.00       9.25
#> 179        TRUE            0                0            0.25       0.00
#> 180        TRUE            0                0            0.50       0.00
#> 181        TRUE            0                0            0.75       0.00
#> 182        TRUE            0                0            1.00       0.00
#> 183        TRUE            0                0            1.25       0.00
#> 184        TRUE            0                0            1.50       0.00
#> 185        TRUE            0                0            1.75       0.00
#> 186        TRUE            0                0            2.00       0.00
#> 187        TRUE            0                0            2.25       0.00
#> 188        TRUE            0                0            2.50       0.00
#> 189        TRUE            0                0            2.75       0.00
#> 190        TRUE            0                0            3.00       0.00
#> 191        TRUE            0                0            3.25       0.00
#> 192        TRUE            0                0            3.50       0.00
#> 193        TRUE            0                0            3.75       0.00
#> 194        TRUE            0                0            4.00       0.00
#> 195        TRUE            0                0            4.25       0.00
#> 196        TRUE            0                0            4.50       0.00
#> 197        TRUE            0                0            4.75       0.00
#> 198        TRUE            0                0            5.00       0.00
#> 199        TRUE            0                0            5.25       0.00
#> 200        TRUE            0                0            5.50       0.00
#> 201        TRUE            0                0            5.75       0.00
#> 202        TRUE            0                0            6.00       0.00
#> 203        TRUE            0                0            6.25       0.00
#> 204        TRUE            0                0            6.50       0.00
#> 205        TRUE            0                0            6.75       0.00
#> 206        TRUE            0                0            7.00       0.00
#> 207        TRUE            0                0            7.25       0.00
#> 208        TRUE            0                0            7.50       0.00
#> 209        TRUE            0                0            7.75       0.00
#> 210        TRUE            0                0            8.00       0.00
#> 211        TRUE            0                0            8.25       0.00
#> 212        TRUE            0                0            8.50       0.00
#> 213        TRUE            0                0            8.75       0.00
#> 214        TRUE            0                0            9.00       0.00
#> 215        TRUE            0                0            9.25       0.00
#> 216        TRUE            0                0            9.50       0.00
#> 217       FALSE            1            Sleep            0.00       9.75
#> 218       FALSE            0                0            0.25       0.00
#> 219       FALSE            0                0            0.50       0.00
#> 220       FALSE            0                0            0.75       0.00
#> 221       FALSE            0                0            1.00       0.00
#> 222       FALSE            0                0            1.25       0.00
#> 223       FALSE            0                0            1.50       0.00
#> 224       FALSE            0                0            1.75       0.00
#> 225       FALSE            0                0            2.00       0.00
#> 226       FALSE            0                0            2.25       0.00
#> 227       FALSE            0                0            2.50       0.00
#> 228       FALSE            0                0            2.75       0.00
#> 229       FALSE            0                0            3.00       0.00
#> 230       FALSE            0                0            3.25       0.00
#> 231       FALSE            0                0            3.50       0.00
#> 232       FALSE            0                0            3.75       0.00
#> 233       FALSE            0                0            4.00       0.00
#> 234       FALSE            0                0            4.25       0.00
#> 235       FALSE            0                0            4.50       0.00
#> 236       FALSE            0                0            4.75       0.00
#> 237       FALSE            0                0            5.00       0.00
#> 238        TRUE            1             Wake            0.00       5.25
#> 239        TRUE            0                0            0.25       0.00
#> 240        TRUE            0                0            0.50       0.00
#> 241        TRUE            0                0            0.75       0.00
#> 242        TRUE            0                0            1.00       0.00
#> 243        TRUE            0                0            1.25       0.00
#> 244        TRUE            0                0            1.50       0.00
#> 245        TRUE            0                0            1.75       0.00
#> 246        TRUE            0                0            2.00       0.00
#> 247        TRUE            0                0            2.25       0.00
#> 248        TRUE            0                0            2.50       0.00
#> 249        TRUE            0                0            2.75       0.00
#> 250        TRUE            0                0            3.00       0.00
#> 251        TRUE            0                0            3.25       0.00
#> 252        TRUE            0                0            3.50       0.00
#> 253        TRUE            0                0            3.75       0.00
#> 254        TRUE            0                0            4.00       0.00
#> 255        TRUE            0                0            4.25       0.00
#> 256        TRUE            0                0            4.50       0.00
#> 257        TRUE            0                0            4.75       0.00
#> 258        TRUE            0                0            5.00       0.00
#> 259        TRUE            0                0            5.25       0.00
#> 260        TRUE            0                0            5.50       0.00
#> 261        TRUE            0                0            5.75       0.00
#> 262        TRUE            0                0            6.00       0.00
#> 263        TRUE            0                0            6.25       0.00
#> 264        TRUE            0                0            6.50       0.00
#> 265        TRUE            0                0            6.75       0.00
#> 266        TRUE            0                0            7.00       0.00
#> 267        TRUE            0                0            7.25       0.00
#> 268        TRUE            0                0            7.50       0.00
#> 269       FALSE            1            Sleep            0.00       7.75
#> 270       FALSE            0                0            0.25       0.00
#> 271       FALSE            0                0            0.50       0.00
#> 272       FALSE            0                0            0.75       0.00
#> 273       FALSE            0                0            1.00       0.00
#> 274       FALSE            0                0            1.25       0.00
#> 275       FALSE            0                0            1.50       0.00
#> 276       FALSE            0                0            1.75       0.00
#> 277       FALSE            0                0            2.00       0.00
#> 278       FALSE            0                0            2.25       0.00
#> 279       FALSE            0                0            2.50       0.00
#> 280       FALSE            0                0            2.75       0.00
#> 281       FALSE            0                0            3.00       0.00
#> 282       FALSE            0                0            3.25       0.00
#> 283       FALSE            0                0            3.50       0.00
#> 284       FALSE            0                0            3.75       0.00
#> 285       FALSE            0                0            4.00       0.00
#> 286       FALSE            0                0            4.25       0.00
#> 287       FALSE            0                0            4.50       0.00
#> 288       FALSE            0                0            4.75       0.00
#> 289       FALSE            0                0            5.00       0.00
#> 290       FALSE            0                0            5.25       0.00
#> 291       FALSE            0                0            5.50       0.00
#> 292       FALSE            0                0            5.75       0.00
#> 293       FALSE            0                0            6.00       0.00
#> 294       FALSE            0                0            6.25       0.00
#> 295       FALSE            0                0            6.50       0.00
#> 296       FALSE            0                0            6.75       0.00
#> 297       FALSE            0                0            7.00       0.00
#> 298       FALSE            0                0            7.25       0.00
#> 299       FALSE            0                0            7.50       0.00
#> 300       FALSE            0                0            7.75       0.00
#> 301       FALSE            0                0            8.00       0.00
#> 302       FALSE            0                0            8.25       0.00
#> 303       FALSE            0                0            8.50       0.00
#> 304        TRUE            1             Wake            0.00       8.75
#> 305        TRUE            0                0            0.25       0.00
#> 306        TRUE            0                0            0.50       0.00
#> 307        TRUE            0                0            0.75       0.00
#> 308        TRUE            0                0            1.00       0.00
#> 309        TRUE            0                0            1.25       0.00
#> 310        TRUE            0                0            1.50       0.00
#> 311        TRUE            0                0            1.75       0.00
#> 312        TRUE            0                0            2.00       0.00
#> 313        TRUE            0                0            2.25       0.00
#> 314        TRUE            0                0            2.50       0.00
#> 315        TRUE            0                0            2.75       0.00
#> 316        TRUE            0                0            3.00       0.00
#> 317        TRUE            0                0            3.25       0.00
#> 318        TRUE            0                0            3.50       0.00
#> 319        TRUE            0                0            3.75       0.00
#> 320        TRUE            0                0            4.00       0.00
#> 321        TRUE            0                0            4.25       0.00
#> 322        TRUE            0                0            4.50       0.00
#> 323        TRUE            0                0            4.75       0.00
#> 324        TRUE            0                0            5.00       0.00
#> 325        TRUE            0                0            5.25       0.00
#> 326        TRUE            0                0            5.50       0.00
#> 327       FALSE            1            Sleep            0.00       5.75
#> 328       FALSE            0                0            0.25       0.00
#> 329       FALSE            0                0            0.50       0.00
#> 330       FALSE            0                0            0.75       0.00
#> 331       FALSE            0                0            1.00       0.00
#> 332       FALSE            0                0            1.25       0.00
#> 333       FALSE            0                0            1.50       0.00
#> 334       FALSE            0                0            1.75       0.00
#> 335       FALSE            0                0            2.00       0.00
#> 336       FALSE            0                0            2.25       0.00
#> 337       FALSE            0                0            2.50       0.00
#> 338       FALSE            0                0            2.75       0.00
#> 339       FALSE            0                0            3.00       0.00
#> 340       FALSE            0                0            3.25       0.00
#> 341       FALSE            0                0            3.50       0.00
#> 342       FALSE            0                0            3.75       0.00
#> 343       FALSE            0                0            4.00       0.00
#> 344       FALSE            0                0            4.25       0.00
#> 345       FALSE            0                0            4.50       0.00
#> 346       FALSE            0                0            4.75       0.00
#> 347       FALSE            0                0            5.00       0.00
#> 348       FALSE            0                0            5.25       0.00
#> 349       FALSE            0                0            5.50       0.00
#> 350       FALSE            0                0            5.75       0.00
#> 351       FALSE            0                0            6.00       0.00
#> 352       FALSE            0                0            6.25       0.00
#> 353       FALSE            0                0            6.50       0.00
#> 354       FALSE            0                0            6.75       0.00
#> 355       FALSE            0                0            7.00       0.00
#> 356       FALSE            0                0            7.25       0.00

Modelling and the Simulation Dataframe

Now that you have generated the FIPS format, you can now apply the FIPS simulation functions to this to actually run BMM predictions on the series. In the example below, we will run a Three Process Model simulation over the FIPS_df series we just created. To do this, we will use the FIPS_simulation function, which takes in three arguments: a FIPS_df object, a specification of a modeltype (see help for model types currently implemented), and a pvec which is a vector of parameters for the model.

The parameter vectors provided by default in the package are those reported by Ingre et al. (2014). Please see the help files for citations and further information. These defaults are customisable, and if you are using Rstudio or Emacs ESS, you will get full autocompletion with descriptions of each parameter (See help("TPM_make_pvec", "FIPS")).

We will use the default parameter vector for the Three process model created by FIPS::TPM_make_pvec(), which takes on the following values:

Parameter Value
la 2.400
ha 14.300
d -0.035
g -0.381
bl 12.200
Cm 0.000
Ca 2.500
Parameter Value
p 16.80
Um -0.50
Ua 0.50
Wc -5.72
Wd -1.51
S0 7.96
KSS_intercept 10.60
KSS_beta -0.60

Calling FIPS_simulate() will the produces a FIPS_df with model predictions and predicted time-varying process variables (e.g., s, c). The returned FIPS_df will also now inherit the FIPS_simulation class. A FIPS_simulation object has attributes containing the parameter vector, the modeltype string, and the pvec used, and several other values used internally. A custom print function of the object will reveal all this information. Note that this print function does mask some of the columns for ease of reading.

# Run a simulation with the three process model
TPM.simulation.results = FIPS_simulate(
  FIPS_df = simulated.dataframe, # The FIPS_df
  modeltype = "TPM",             # three process model
  pvec = TPM_make_pvec()       # parameter vector
  )

TPM.simulation.results
#> ---------
#> Model Type: TPM 
#> Epoch Value: 5 minutes 
#> Simulation duration: 158 hours 
#> Time points: 1897 
#> Parameters used (pvec input):
#>            la            ha             d             g            bl 
#>     2.4000000    14.3000000    -0.0353000    -0.3813564    12.2000000 
#>            Cm            Ca             p            Um            Ua 
#>     0.0000000     2.5000000    16.8000000    -0.5000000     0.5000000 
#>            Wc            Wd            S0 KSS_intercept      KSS_beta 
#>    -5.7200000    -1.5100000     7.9600000    10.6000000    -0.6000000 
#> For descriptions of these parameters, inspect:  help(FIPS::TPM_make_pvec) 
#> ---------
#> # A tibble: 1,897 x 10
#>    datetime             time wake_status sim_hours     s     c     w         u
#>    <dttm>              <dbl> <lgl>           <dbl> <dbl> <dbl> <dbl>     <dbl>
#>  1 2018-05-01 07:00:00  7    TRUE           0       7.96 -2.10 -5.72 -0.0432  
#>  2 2018-05-01 07:05:00  7.08 TRUE           0.0833  7.94 -2.07 -5.04 -0.0348  
#>  3 2018-05-01 07:10:00  7.17 TRUE           0.167   7.93 -2.04 -4.45 -0.0272  
#>  4 2018-05-01 07:15:00  7.25 TRUE           0.25    7.91 -2.00 -3.92 -0.0206  
#>  5 2018-05-01 07:20:00  7.33 TRUE           0.333   7.89 -1.97 -3.46 -0.0149  
#>  6 2018-05-01 07:25:00  7.42 TRUE           0.417   7.88 -1.94 -3.05 -0.0100  
#>  7 2018-05-01 07:30:00  7.5  TRUE           0.5     7.86 -1.90 -2.69 -0.00616 
#>  8 2018-05-01 07:35:00  7.58 TRUE           0.583   7.85 -1.87 -2.37 -0.00321 
#>  9 2018-05-01 07:40:00  7.67 TRUE           0.667   7.83 -1.83 -2.09 -0.00122 
#> 10 2018-05-01 07:45:00  7.75 TRUE           0.75    7.81 -1.79 -1.84 -0.000171
#> # ... with 1,887 more rows, and 2 more variables: KSS <dbl>, alertness <dbl>
  • datetime = vector of datetime stamps separated at equidistance intervals.
  • sleep.id = a supplementary variable indicating sleep episode identifier.
  • wake_status = Awake (T) or asleep (F) at that epoch interval/epoch
  • wake_status_int = Awake (1) or asleep (0) at that epoch interval/epoch
  • change_point = Whether the individual changed wake status at that interval/epoch.
  • switch_direction = Whether switch was to sleep or to wake
  • status_duration = How long individual has been in status at that current time point
  • total_prev = If a switch has occured, how long were that in the previous status.
  • time = time of day in decimal hour
  • day = days into simulation
  • sim_hours = hours simulation has run for total
  • s — Estimate of S (homeostatic) process at that time
  • l — Estimate of l (lower asmytope) process at that time
  • c — Estimate of C (24-hour circadian) process at that time
  • w — Estimate of W (sleep intertia) process at that time
  • u — Estimate of U (12-hour circadian) process at that time
  • alertness — Currently just s + c + u
  • KSS — This is equal to 10.6 + -0.6 * (alertness)

Plotting

Plot 1: Parameter Plots

FIPS provides a default plot method to visualize model predictions and time-varying process estimates over time, discussed in detail in the plotting vignette. These plots aid with debugging and understanding how the different model parameters contribute to predictions.

# Plot the whole time series
plot(TPM.simulation.results, plot_stat=c("alertness", "s", "c"))


#Narrow in on the first 90 hours
plot(TPM.simulation.results, plot_stat=c("alertness", "s", "c"),
      from= '2018-05-01 23:00:00',
      to= as_datetime('2018-05-01 23:00:00') + hours(90))

Plot 2: Heatmap Prediction Plots

There are many other ways that visualizations could help inform theory and practice. The below heat plot is an example of how dangerous times in a mission, according to the TPM predictions, could be visualized. In the example below, the regions in deep orange indicate a greatly increased risk of fatigue. However, the fact that the increased fatigue occurs at the start of the mission indicates the initalisation parameters (e.g., S0) are to blame, so this isn’t a cause for significant concern.


if (!requireNamespace("colorspace", quietly = TRUE)) {
    stop("Package \"colorspace\" needed for this example to work. Please install it.",
      call. = FALSE)
  }

plot3_w = TPM.simulation.results %>%
  # Change epoch to 30 minutes for this plot (optional)
  mutate(time = strftime(datetime, format = "%H:%M")) %>% 
  separate(time, into = c("plot_hour", "plot_minute"), ":") %>%
  mutate(halfhour = if_else(plot_minute < 30, 0, 0.5) + as.numeric(plot_hour)) %>% 
  group_by(day, plot_hour, halfhour) %>% 
  summarise(KSS = mean(KSS), .groups = "keep") %>% 
  filter(day > 1) %>% 
  # Start Plot
  ggplot(aes(day, halfhour, fill = KSS)) +
  geom_tile(aes(fill = KSS), color = "white") +
  scale_x_continuous(breaks = seq(0,7,1)) +
  scale_y_continuous(breaks = seq(0,23,1)) +
  labs(y = "Hour of Day", x = "Day of Mission") +
  colorspace::scale_fill_continuous_divergingx(name = "KSS", palette = "Zissou 1", limits = c(1,9), mid = 5) +
  ggtitle(label = "Three Process Model (KSS)", subtitle = "Heatmap of TPM predicted performance by 0.5hr") +
  theme(axis.title = element_text(size = 12)) 

plot(plot3_w)