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 |
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.
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", ...)
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", ...)
x |
R object. |
... |
Not currently used. |
id |
Variable in |
start |
Variable in Must refer to a variable that is either class |
end |
Variable in Must refer to a variable that is the same class as |
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).
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)
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_episodes()
combines overlapping episodes in to a minimal spanning
interval split by in individual identifier. Methods are provided for
data.frame like objects.
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", ...)
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", ...)
x |
R object. |
... |
Not currently used. |
id |
Variable in |
start |
Variable in Must refer to a variable that is either class |
end |
Variable in Must refer to a variable that is the same class as |
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).
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)
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)