Package 'NHSRepisodes'

Title: Package Relating to Hospital Episode Intervals
Description: Hospital episodes can overlap or have gaps which can result in under or over counting. This package contains functions which can be used to rectify this common analytical issue in NHS data.
Authors: Zoë Turner [aut, cre] , Tim Taylor [aut] , NHS R [cph]
Maintainer: Zoë Turner <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0.9000
Built: 2024-11-15 13:53:43 UTC
Source: https://github.com/nhs-r-community/NHSRepisodes

Help Index


Calculate parent intervals

Description

add_parent_interval() calculates the minimum spanning interval that contains overlapping episodes and adds this to the input. Methods are provided for data.frame like objects.

Usage

add_parent_interval(x, ...)

## Default S3 method:
add_parent_interval(x, ...)

## S3 method for class 'data.table'
add_parent_interval(x, id = "id", start = "start", end = "end", ...)

## S3 method for class 'tbl_df'
add_parent_interval(x, id = "id", start = "start", end = "end", ...)

## S3 method for class 'data.frame'
add_parent_interval(x, id = "id", start = "start", end = "end", ...)

Arguments

x

R object.

...

Not currently used.

id

⁠[character]⁠

Variable in x representing the id associated with an episode.

start

⁠[character]⁠

Variable in x representing the start of the episode.

Must refer to a variable that is either class ⁠<Date>⁠ or ⁠<POSIXct>⁠.

end

⁠[character]⁠

Variable in x representing the start of the episode.

Must refer to a variable that is the same class as start.

Value

The input data with additional columns for the corresponding parent interval (split across id values).

Additional columns will be labelled '.parent_start', '.parent_end' and '.interval_number' where the interval number is in order of occurrence of the corresponding parent interval.

The returned object will be of the same class as the input x (i.e. a data.frame, data.table or tibble).

Examples

dat <- data.frame(
    id = c(1, 1, 2, 2, 2, 1),
    start = as.Date(c(
        "2020-01-01", "2020-01-03", "2020-04-01",
        "2020-04-15", "2020-04-17", "2020-05-01"
    )),
    end = as.Date(c(
        "2020-01-10", "2020-01-10", "2020-04-30",
        "2020-04-16", "2020-04-19", "2020-10-01"
    ))
)

add_parent_interval(dat)

Merge overlapping episodes

Description

merge_episodes() combines overlapping episodes in to a minimal spanning interval split by in individual identifier. Methods are provided for data.frame like objects.

Usage

merge_episodes(x, ...)

## Default S3 method:
merge_episodes(x, ...)

## S3 method for class 'data.table'
merge_episodes(x, id = "id", start = "start", end = "end", ...)

## S3 method for class 'tbl_df'
merge_episodes(x, id = "id", start = "start", end = "end", ...)

## S3 method for class 'data.frame'
merge_episodes(x, id = "id", start = "start", end = "end", ...)

Arguments

x

R object.

...

Not currently used.

id

⁠[character]⁠

Variable in x representing the id associated with the episode.

start

⁠[character]⁠

Variable in x representing the start of the episode.

Must refer to a variable that is either class ⁠<Date>⁠ or ⁠<POSIXct>⁠.

end

⁠[character]⁠

Variable in x representing the start of the episode.

Must refer to a variable that is the same class as start.

Value

The resulting combined episode intervals split by id and ordered by interval number.

The returned object will be of the same class as the input x (i.e. a data.frame, data.table or tibble).

Examples

dat <- data.frame(
    id = c(1, 1, 2, 2, 2, 1),
    start = as.Date(c(
        "2020-01-01", "2020-01-03", "2020-04-01",
        "2020-04-15", "2020-04-17", "2020-05-01"
    )),
    end = as.Date(c(
        "2020-01-10", "2020-01-10", "2020-04-30",
        "2020-04-16", "2020-04-19", "2020-10-01"
    ))
)

merge_episodes(dat)