Compute a matrix of stages transitions counts.
transitions(
hypnogram,
stages = c("AWA", "REM", "N1", "N2", "N3"),
plot = FALSE
)
A hypnogram dataframe. Dataframe must contain begin
(POSIXt
), end
(POSIXt
) and event
(character
) columns.
Stages to include in transitions Defaults to c("N1", "N2", "N3", "N4", "REM")
.
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.
A matrix with count of stages transitions, or a plot.
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")