-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfall.Rmd
171 lines (131 loc) · 4.93 KB
/
fall.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
---
title: "fall"
output:
word_document: default
html_notebook: default
pdf_document: default
---
a.table3
table2
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
library(tidyverse)
library(rio)
library(tidyr)
library(dplyr)
library(stringr)
library(tableone)
## Loading the csv file
url <- "https://raw.githubusercontent.com/titco/titco-I/master/titco-I-full-dataset-v1.csv"
titco_fall <- import(url) %>% as_tibble()
## Filter all fall patients
fall <- filter(titco_fall, moi == "Fall" )
## to find the sample size
nrow(fall)
## Find no and % of males and females
m <- fall$sex == "Male"
n.m <- sum(m)
p.m <- round(mean(m) * 100)
f <- fall$sex == "Female"
n.f <- sum(f)
p.f <- round(mean(f)*100)
## Summarize age
ages <- fall$age
ages <- as.numeric(ages)
summary(ages)
## Break age into groups
fall["agegroup"] <- agegroup <- cut(ages,
breaks = c(0, 17, 25, 45, 65, 85),
labels = c("less than 18","18-24", "25-44", "45-64", "65+"))
table1 <- table(agegroup)
## Find percentage transferred
t <- fall$tran == "Yes"
n.t <- sum(t,na.rm=T)
p.t <- round(mean(t,na.rm=T)*100)
## Find mode of transport
am <- fall$mot == "Ambulance"
n.am <- sum(am,na.rm=T)
p.am <- round(mean(am,na.rm=T)*100)
## Find percentage of Type of injury
ti <- fall$ti == "Blunt"
n.ti <- sum(ti,na.rm=T)
p.ti <- round(mean(ti,na.rm=T)*100)
## Create GCS group
a.gcs <- fall$gcs_t_1
## Break GCS into groups
fall["gcsgroup"] <- gcsgroup <- cut(a.gcs,
breaks = c(2, 8, 13, 15),
labels = c( "3-8", "9-13", "14-15"))
gcs.table <- table(gcsgroup)
## Find number of surgery done
tos <- fall$tos
surg1<- ifelse(tos == 0, 0,
ifelse(tos == 999, 0, 1))
surgery1 <- fall["Surgery"] <- surg1 == 1
n.s <- sum(surgery1, na.rm = TRUE)
p.s <- round(mean(surgery1, na.rm = TRUE)*100)
## Find mortality
died <- fall$died == "Yes"
n.died <- sum(died, na.rm = TRUE)
p.died <- round(mean(died, na.rm = TRUE) * 100)
## Find discharged against medical advice
dama <- fall$dama == "Yes"
n.dama <- sum(dama,na.rm = T)
p.dama <- round(mean(dama,na.rm = T)*100)
## Creating Table for TBI patients demography using table one
table1.data <- with(fall,
data.frame("Age" = age,
"Sex" = sex,
"Age group" = agegroup,
"Type of injury" = ti,
"Mode of transport" = mot,
"Transferred" = ifelse(tran == "Yes", "Transferred", "Direct"),
"Systolic blood pressure" = sbp_1,
"Heart rate" = hr_1,
"Saturation" = spo2_1,
"Respiratory rate" = rr_1,
"Glasgow coma scale" = gcsgroup,
"Surgery" = ifelse(tos == "0", "Conservative", "Operative"),
"Mortality" = ifelse(died == "Yes", "Died", "Survived"),
check.names = FALSE
))
a.table3 <- CreateTableOne(data=table1.data)
a.table3 <- knitr::kable(print(a.table3, caption = "Table 1. Characteristics of Fall Patients", showAllLevels = TRUE, printToggle = FALSE))
summary(fall$niss)
issbreaks <- c(1,9,16,25,109)
isslabels <- c("Mild","Moderate","Severe","Profound")
fall$isspv <-cut(fall$iss,
breaks = issbreaks,
right = FALSE,
labels = isslabels)
table2 <- table(fall$isspv)
## delay
fall_d <- select(fall,doi, toi, doar,toar,dodd,todd,died,age,sex,tran)
## removing all NA's
fall_d <- fall_d[complete.cases(fall_d),]
nrow(fall_d)
col2 <- c("doi","toi")
y <- fall_d$date_time_injury <- apply (fall_d[,col2],1, paste,collapse ="")
date.time.injury <- as.POSIXct(y)
col3 <- c("doar","toar")
x <- fall_d$date_time_arrival <- apply (fall_d[,col3],1,paste,collapse ="")
date.time.arrival <- as.POSIXct(x)
delay <-difftime(date.time.arrival, date.time.injury)
fall_d["delay"] <- delay_hours <- as.numeric(delay/60)
summary(delay_hours)
m.delay <- median(delay_hours)
q1.delay <- quantile(delay_hours,0.25)
q3.delay <- quantile(delay_hours,0.75)
range.delay <- range(delay_hours)
## length of hospital stay
col3 <- c("doar","toar")
x <- fall_d$date_time_arrival <- apply (fall_d[,col3],1,paste,collapse ="")
date.time.arrival <- as.POSIXct(x)
col4 <- c("dodd","todd")
z <- fall_d$date_time_discharge <- apply(fall_d[,col4],1,paste,collapse = "")
data.time.discharge <- as.POSIXct(z)
los <-difftime(data.time.discharge, date.time.arrival)
fall_d["LOS"] <- los_hrs <- as.numeric(delay/60)
summary(los_hrs)
```