Compute a matrix of stages transitions counts.

transitions(
  hypnogram,
  stages = c("AWA", "REM", "N1", "N2", "N3"),
  plot = FALSE
)

Arguments

hypnogram

A hypnogram dataframe. Dataframe must contain begin (POSIXt), end (POSIXt) and event (character) columns.

stages

Stages to include in transitions Defaults to c("N1", "N2", "N3", "N4", "REM").

plot

Plot the transition matrix or not. Takes "heatmap" to plot a heatmap of transitions or FALSE to return the matrix as a dataframe without plotting it.

Value

A matrix with count of stages transitions, or a plot.

Examples

download.file("https://rsleep.org/data/hypnodensity.csv", "hypnodensity.csv")

hypnodensity <- read.csv2("hypnodensity.csv")

unlink("hypnodensity.csv")

events <- hypnogram(hypnodensity)

transitions(events, plot = "heatmap")