View source: R/sleepint2Brown.R
| sleep_int2Brown | R Documentation |
Takes a dataset with sleep/wake intervals and recodes them to Brown state
intervals. Specifically, it recodes the sleep intervals to night, reduces
wake intervals by a specified evening.length and recodes them to
evening and day intervals. The evening.length is the time between day
and night. The result can be used as input for interval2state() and might
be used subsequently with Brown2reference().
sleep_int2Brown(
dataset,
Interval.colname = Interval,
Sleep.colname = State,
wake.state = "wake",
sleep.state = "sleep",
Brown.day = "day",
Brown.evening = "evening",
Brown.night = "night",
evening.length = lubridate::dhours(3),
Brown.state.colname = State.Brown,
output.dataset = TRUE
)
dataset |
A dataset with sleep/wake intervals. |
Interval.colname |
The name of the column with the intervals. Defaults to |
Sleep.colname |
The name of the column with the sleep/wake states. Defaults to |
wake.state, sleep.state |
The names of the wake and sleep states in the |
Brown.day, Brown.evening, Brown.night |
The names of the Brown states that will be used. Defaults to |
evening.length |
The length of the evening interval in seconds. Can also use lubridate duration or period objects. Defaults to 3 hours. |
Brown.state.colname |
The name of the column with the newly created Brown states. Works as a simple renaming of the |
output.dataset |
Whether to return the whole |
The function will filter out any non-sleep intervals that are shorter than the specified evening.length. This prevents problematic behaviour when the evening.length is longer than the wake intervals or, e.g., when the first state is sleep after midnight and there is a prior NA interval from midnight till sleep. This behavior might, however, result in problematic results for specialized experimental setups with ultra short wake/sleep cycles. The sleep_int2Brown() function would not be applicable in those cases anyways.
A dataset with the Brown states or a vector with the Brown states. The Brown states are created in a new column with the name specified in Brown.state.colname. The dataset will have more rows than the original dataset, because the wake intervals are split into day and evening intervals.
https://journals.plos.org/plosbiology/article?id=10.1371/journal.pbio.3001571
Other Brown:
Brown2reference(),
Brown_check(),
Brown_cut(),
Brown_rec()
#create a sample dataset
sample <- tibble::tibble(Datetime = c("2023-08-15 6:00:00",
"2023-08-15 23:00:00",
"2023-08-16 6:00:00",
"2023-08-16 22:00:00",
"2023-08-17 6:30:00",
"2023-08-18 1:00:00"),
State = rep(c("wake", "sleep"), 3),
Id = "Participant")
#intervals from sample
sc2interval(sample)
#recoded intervals
sc2interval(sample) %>% sleep_int2Brown()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.