interval_detect {cycleRtools} | R Documentation

## Detect Intervals in a Ride.

### Description

Section a ride file according to power output.

### Usage

    interval_detect(data, sections, plot = FALSE, ...)

### Arguments

`data` | a formatted dataset produced by `read*()`.
`sections` | how many sections should be identified? Includes stoppages.
`plot` | logical; if `TRUE`, graphically displays the resultant sections.
`...` | graphical parameters to be passed to `par()`. Ignored if `plot = FALSE`.

### Details

Often a ride will contain intervals/efforts that are not in any way marked in the device data (e.g. as "laps"). Using changepoint analysis, it is possible to retrospectively identify these efforts. This is contingent on supplying the number of changepoints to the underlying algorithm, simplified here as a `"sections"` argument.

For example, if there are two efforts amidst a ride, this means we are looking to identify 5 sections (i.e. neutral-effort-neutral-effort-neutral). See examples.

Depends on the package `"changepoint"`.

### Value

if `plot = TRUE` nothing is returned. If `plot = FALSE` (default) a vector of section "levels" is returned.

### Examples

    data(intervaldata)

    ## "intervaldata" is a ride that includes two efforts (2 & 5 minutes) and a cafe
    ## stop. The efforts are marked in the lap column, which we can use as a
    ## criterion.

    with(intervaldata, tapply(X = delta.t, INDEX = lap, sum)) / 60  # Minutes.

    ## The above shows the efforts were laps two and four. What was the power?
    with(intervaldata, tapply(X = power.W, INDEX = lap, mean))[c(2, 4)]

    ## And for the sake of example, some other summary metrics...
    l <- split(intervaldata, intervaldata$lap)
    names(l) <- paste("Lap", names(l))  # Pretty names.
    vapply(l, FUN.VALUE = numeric(3), FUN = function(x)
      c(t.min = ride_time(x$timer.s) / 60, NP = NP(x), TSS = TSS(x)))

    ## Could we have gotten the same information without the lap column?
    ## Two efforts and a cafe stop == 7 sections.
    interval_detect(intervaldata, sections = 7, plot = TRUE)

    ## An overzealous start to the first effort is being treated as a seperate section,
    ## so let's allow for an extra section...
    interval_detect(intervaldata, sections = 8, plot = TRUE)

    ## Looks okay, so save the output and combine the second and third sections.
    intervaldata$intv <- interval_detect(intervaldata, sections = 8, plot = FALSE)
    intervaldata$intv[intervaldata$intv == 3] <- 2

    ## Are the timings as expected?
    with(intervaldata, tapply(X = delta.t, INDEX = intv, sum)) / 60  # Minutes.

    ## Close enough!

    i <- split(intervaldata, intervaldata$intv)
    names(i) <- paste("Interval", seq_along(i))  # Pretty names.
    toplot <- vapply(i, FUN.VALUE = numeric(3), FUN = function(x)
      c(t.min = ride_time(x$timer.s) / 60, NP = NP(x), TSS = TSS(x)))

    print(toplot)

    par(mfrow = c(3, 1))
    mapply(function(r, ylab) barplot(
      toplot[r, c(1:3, 5:7)], names.arg = seq_along(toplot[r, c(1:3, 5:7)]),
      xlab = "Section", ylab = ylab),
      r = 1:3, ylab = c("Ride time (minutes)", "NP", "TSS"))

[Package cycleRtools version 1.1.1 Index]