This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
function to calculate the length of ICU stay
- Loading branch information
Showing
5 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,13 @@ Type: Package | |
Title: The Critical Care Clinical Data Processing Tools | ||
Version: 0.1 | ||
Date: 2017-01-30 | ||
Author: Sinan Shi, David Pérez-Suárez, Steve Harris, Niall MacCallum, David Brealey, Mervyn Singer, James Hetherington | ||
Author: Sinan Shi, David Pérez-Suárez, Steve Harris, Niall MacCallum, David | ||
Brealey, Mervyn Singer, James Hetherington | ||
Maintainer: Sinan Shi <[email protected]> | ||
Description: | ||
A toolset to deal with the Critical Care Health Informatics Collaborative | ||
dataset. It is created to address various data reliability and accessibility | ||
problems of electronic healthcare records (EHR). It provides a unique | ||
platform which enables data manipulation, transformation, reduction, | ||
Description: A toolset to deal with the Critical Care Health Informatics | ||
Collaborative dataset. It is created to address various data reliability and | ||
accessibility problems of electronic healthcare records (EHR). It provides a | ||
unique platform which enables data manipulation, transformation, reduction, | ||
anonymisation, cleaning and validation. | ||
Depends: | ||
R (>= 3.1.0) | ||
|
@@ -25,7 +25,7 @@ Imports: | |
methods, | ||
knitr, | ||
ggplot2, | ||
pander, | ||
pander, | ||
stats, | ||
utils | ||
VignetteBuilder: knitr | ||
|
@@ -38,6 +38,7 @@ Collate: | |
'create2dclean.R' | ||
'data.quality.report.R' | ||
'deltaTime.R' | ||
'demographics.R' | ||
'filter.categorical.R' | ||
'filter.missingness.R' | ||
'filter.range.R' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#' Calculate the lenght of stay in the ICU. | ||
#' | ||
#' Calculate the lenght of stay in the ICU and append it to the original demographic | ||
#' table. | ||
#' @param demg data.table the demograhic table which should at least contain | ||
#' column DAICU and DDICU | ||
#' @param units character The unit of lenstay column, by default the output will be in hours | ||
#' @return data.table It is the original data.table with lenstay column (in | ||
#' difftime) appended. | ||
#' @export lenstay | ||
lenstay <- function(demg, units="hours") { | ||
len <- difftime(xmlTime2POSIX(demg$DDICU, allow=T), | ||
xmlTime2POSIX(demg$DAICU, allow=T), | ||
units=units) | ||
return(cbind(demg, lenstay = len)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
context("Testing functionalities for the demographic table") | ||
|
||
test_that("calculate length of stay in the ICU",{ | ||
demg <- data.table(DAICU="2007-01-01", DDICU="2007-01-02") | ||
demg_ <- lenstay(demg) | ||
expect_true(is.data.frame(demg_)) | ||
expect_equal(ncol(demg) + 1, ncol(demg_)) | ||
expect_equal(as.numeric(demg_$lenstay), 24) | ||
|
||
demg <- data.table(DAICU="2007-01-01T00:00:00", DDICU="2007-01-01T22:00:00") | ||
demg_ <- lenstay(demg) | ||
expect_equal(as.numeric(demg_$lenstay), 22) | ||
|
||
demg <- data.table(DAICU="2007-01-01", DDICU="wrong_format") | ||
demg_ <- lenstay(demg) | ||
expect_true(is.na(demg_$lenstay)) | ||
|
||
demg <- data.table(DAICU="wrong_format1", DDICU="wrong_format1") | ||
demg_ <- lenstay(demg) | ||
expect_true(is.na(demg_$lenstay)) | ||
|
||
demg <- data.table(DAICU="2007-01-01T00:00:00", DDICU="2007-01-01T22:00:00") | ||
demg_ <- lenstay(demg, "days") | ||
expect_equal(as.numeric(demg_$lenstay), 1-2/24) | ||
}) | ||
|