[0375db]: / overview / cohort-tables.R

Download this file

52 lines (39 with data), 1.4 kB

 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
data.filename <- '../../data/cohort-sanitised.csv'
source('../lib/shared.R')
# Load the data and convert to data frame to make column-selecting code in
# prepData simpler
COHORT.full <- fread(data.filename)
print(nrow(COHORT.full))
# Remove the patients we shouldn't include
COHORT.full <-
COHORT.full[
# remove negative times to death
COHORT.full$time_death > 0 &
# remove patients who should be excluded
!COHORT.full$exclude
,
]
# Total study population
print(nrow(COHORT.full))
# Age, 5, 50, 95, %missing
print(quantile(COHORT.full$age, c(0.5, 0.05, 0.95)))
# Gender
print(table(COHORT.full$gender))
print(table(COHORT.full$gender))/nrow(COHORT.full)*100
# Deprivation, 5, 50, 95, %missing
print(quantile(COHORT.full$imd_score, c(0.5, 0.05, 0.95), na.rm = TRUE))
print(percentMissing(COHORT.full$imd_score))
# Smoking, by category, %missing
print(table(COHORT.full$smokstatus))/nrow(COHORT.full)*100
print(percentMissing(COHORT.full$smokstatus))
# Diabetes, yes/no
print(
( sum(COHORT.full$diabetes == 'Diabetes unspecified type') +
sum(COHORT.full$diabetes == 'Type 1 diabetes') +
sum(COHORT.full$diabetes == 'Type 2 diabetes')) /nrow(COHORT.full)*100
)
# Follow-up, 5, 50, 95
print(quantile(COHORT.full$endpoint_death_date, c(0.5, 0.05, 0.95)))/365.25
# Death vs censored, %
print(table(COHORT.full$endpoint_death))
print(table(COHORT.full$endpoint_death)) /nrow(COHORT.full)*100