sleep_annotation: Score sleep behaviour from immobility

Description Usage Arguments Details Value References See Also Examples

View source: R/sleep-annotation.R

Description

This function first uses a motion classifier to decide whether an animal is moving during a given time window. Then, it defines sleep as contiguous immobility for a minimum duration.

Usage

1
2
3
4
5
sleep_annotation(data, time_window_length = 10,
  min_time_immobile = 300, motion_detector_FUN = max_velocity_detector,
  ...)

sleep_dam_annotation(data, min_time_immobile = 300)

Arguments

data

data.table containing behavioural variable from or one multiple animals. When it has a key, unique values, are assumed to represent unique individuals (e.g. in a behavr table). Otherwise, it analysis the data as coming from a single animal. data must have a column t representing time.

time_window_length

number of seconds to be used by the motion classifier. This corresponds to the sampling period of the output data.

min_time_immobile

Minimal duration (in s) of a sleep bout. Immobility bouts longer or equal to this value are considered as sleep.

motion_detector_FUN

function used to classify movement

...

extra arguments to be passed to motion_classifier_FUN.

Details

The default time_window_length is 300 seconds – it is also known as the "5-minute rule". sleep_annotation is typically used for ethoscope data, whilst sleep_dam_annotation only works on DAM2 data. These functions are rarely used directly, but rather passed as an argument to a data loading function, so that analysis can be performed on the go.

Value

a behavr table similar to data with additional variables/annotations (i.e. moving and asleep). The resulting data will only have one data point every time_window_length seconds.

References

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
dt_one_animal <- toy_ethoscope_data(seed=2)
####### Ethoscope, corrected velocity classification #########
sleep_dt <-  sleep_annotation(dt_one_animal, masking_duration=0)
print(sleep_dt)
# We could make a sleep `barecode'
## Not run: 
library(ggplot2)
ggplot(sleep_dt, aes(t,y="Animal 1",fill=asleep)) +
                                   geom_tile() + scale_x_time()

## End(Not run)
####### Ethoscope, virutal beam cross classification #########
sleep_dt2 <-  sleep_annotation(dt_one_animal,
                             motion_detector_FUN=virtual_beam_cross_detector)
## Not run: 
library(ggplot2)
ggplot(sleep_dt2, aes(t,y="Animal 1",fill=asleep)) +
                                   geom_tile() + scale_x_time()

## End(Not run)
####### DAM data, de facto beam cross classification ######
dt_one_animal <- toy_dam_data(seed=7)
sleep_dt <- sleep_dam_annotation(dt_one_animal)
## Not run: 
library(ggplot2)
ggplot(sleep_dt, aes(t,y="Animal 1",fill=asleep)) +
                                   geom_tile() + scale_x_time()

## End(Not run)

rethomics/sleepr documentation built on Dec. 11, 2019, 6:57 a.m.