|
a |
|
b/cox-ph/caliber-scale.R |
|
|
1 |
ageSpline <- function(x) { |
|
|
2 |
max((x-51)/10.289,0)^3 + |
|
|
3 |
(69-51) * (max((x-84)/10.289,0)^3) - |
|
|
4 |
((84-51) * (max(((x-69))/10.289,0))^3)/(84-69) |
|
|
5 |
} |
|
|
6 |
|
|
|
7 |
caliberScaleUnits <- function(x, quantity) { |
|
|
8 |
if(quantity == 'age') { |
|
|
9 |
## Spline function |
|
|
10 |
x <- sapply(x, ageSpline) |
|
|
11 |
} else if(quantity == 'total_chol_6mo') { |
|
|
12 |
## Total cholesterol, per 1 mmol/L increase |
|
|
13 |
x <- x - 5 |
|
|
14 |
} else if(quantity == 'hdl_6mo') { |
|
|
15 |
## HDL, per 0.5 mmol/L increase |
|
|
16 |
x <- (x - 1.5) / 0.5 |
|
|
17 |
} else if(quantity == 'pulse_6mo') { |
|
|
18 |
## Heart rate, per 10 b.p.m increase |
|
|
19 |
x <- (x - 70) / 10 |
|
|
20 |
} else if(quantity == 'crea_6mo') { |
|
|
21 |
## Creatinine, per 30 μmol/L increase |
|
|
22 |
x <- (x - 60) / 30 |
|
|
23 |
} else if(quantity == 'total_wbc_6mo') { |
|
|
24 |
## White cell count, per 1.5 109/L increase |
|
|
25 |
x <- (x - 7.5) / 1.5 |
|
|
26 |
} else if(quantity == 'haemoglobin_6mo') { |
|
|
27 |
## Haemoglobin, per 1.5 g/dL increase |
|
|
28 |
x <- (x - 13.5) / 1.5 |
|
|
29 |
} |
|
|
30 |
|
|
|
31 |
# Return transformed values |
|
|
32 |
x |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
caliberScale <- function(df, surv.time, surv.event) { |
|
|
36 |
# Return a data frame with all quantities normalised/scaled/standardised to |
|
|
37 |
# ranges etc used in Rapsomaniki et al. 2014 |
|
|
38 |
|
|
|
39 |
# imd_score is sometimes turned into a factor, which causes an error with the |
|
|
40 |
# quantile function. Since it's just integers, make it numeric. |
|
|
41 |
df$imd_score <- as.numeric(df$imd_score) |
|
|
42 |
|
|
|
43 |
data.frame( |
|
|
44 |
## Time to event |
|
|
45 |
surv_time = df[, surv.time], |
|
|
46 |
## Death/censorship |
|
|
47 |
surv_event = df[, surv.event] %in% surv.event.yes, |
|
|
48 |
## Rescaled age |
|
|
49 |
age = sapply(df$age, ageSpline), |
|
|
50 |
## Gender |
|
|
51 |
gender = df$gender, |
|
|
52 |
## Most deprived quintile, yes vs. no |
|
|
53 |
most_deprived = |
|
|
54 |
df$imd_score > quantile(df$imd_score, 0.8, na.rm = TRUE), |
|
|
55 |
### SCAD diagnosis and severity ############################################ |
|
|
56 |
## Other CHD / unstable angina / NSTEMI / STEMI vs. stable angina |
|
|
57 |
diagnosis = factorChooseFirst(factor(df$diagnosis), 'SA'), |
|
|
58 |
## PCI in last 6 months, yes vs. no |
|
|
59 |
pci_6mo = df$pci_6mo, |
|
|
60 |
## CABG in last 6 months, yes vs. no |
|
|
61 |
cabg_6mo = df$cabg_6mo, |
|
|
62 |
## Previous/recurrent MI, yes vs. no |
|
|
63 |
hx_mi = df$hx_mi, |
|
|
64 |
## Use of nitrates, yes vs. no |
|
|
65 |
long_nitrate = df$long_nitrate, |
|
|
66 |
### CVD risk factors ####################################################### |
|
|
67 |
## Ex-smoker vs. never / Current smoker vs. never |
|
|
68 |
smokstatus = factorChooseFirst(factor(df$smokstatus), 'Non'), |
|
|
69 |
## Hypertension, present vs. absent |
|
|
70 |
hypertension = df$hypertension, |
|
|
71 |
## Diabetes mellitus, present vs. absent |
|
|
72 |
diabetes_logical = df$diabetes != 'No diabetes', |
|
|
73 |
## Total cholesterol, per 1 mmol/L increase |
|
|
74 |
total_chol_6mo = caliberScaleUnits(df$total_chol_6mo, 'total_chol_6mo'), |
|
|
75 |
## HDL, per 0.5 mmol/L increase |
|
|
76 |
hdl_6mo = caliberScaleUnits(df$hdl_6mo, 'hdl_6mo'), |
|
|
77 |
### CVD co-morbidities ##################################################### |
|
|
78 |
## Heart failure, present vs. absent |
|
|
79 |
heart_failure = df$heart_failure, |
|
|
80 |
## Peripheral arterial disease, present vs. absent |
|
|
81 |
pad = df$pad, |
|
|
82 |
## Atrial fibrillation, present vs. absent |
|
|
83 |
hx_af = df$hx_af, |
|
|
84 |
## Stroke, present vs. absent |
|
|
85 |
hx_stroke = df$hx_stroke, |
|
|
86 |
### Non-CVD comorbidities ################################################## |
|
|
87 |
## Chronic kidney disease, present vs. absent |
|
|
88 |
hx_renal = df$hx_renal, |
|
|
89 |
## Chronic obstructive pulmonary disease, present vs. absent |
|
|
90 |
hx_copd = df$hx_copd, |
|
|
91 |
## Cancer, present vs. absent |
|
|
92 |
hx_cancer = df$hx_cancer, |
|
|
93 |
## Chronic liver disease, present vs. absent |
|
|
94 |
hx_liver = df$hx_liver, |
|
|
95 |
### Psychosocial characteristics ########################################### |
|
|
96 |
## Depression at diagnosis, present vs. absent |
|
|
97 |
hx_depression = df$hx_depression, |
|
|
98 |
## Anxiety at diagnosis, present vs. absent |
|
|
99 |
hx_anxiety = df$hx_anxiety, |
|
|
100 |
### Biomarkers ############################################################# |
|
|
101 |
## Heart rate, per 10 b.p.m increase |
|
|
102 |
pulse_6mo = caliberScaleUnits(df$pulse_6mo, 'pulse_6mo'), |
|
|
103 |
## Creatinine, per 30 μmol/L increase |
|
|
104 |
crea_6mo = caliberScaleUnits(df$crea_6mo, 'crea_6mo'), |
|
|
105 |
## White cell count, per 1.5 109/L increase |
|
|
106 |
total_wbc_6mo = caliberScaleUnits(df$total_wbc_6mo, 'total_wbc_6mo'), |
|
|
107 |
## Haemoglobin, per 1.5 g/dL increase |
|
|
108 |
haemoglobin_6mo = caliberScaleUnits(df$haemoglobin_6mo, 'haemoglobin_6mo') |
|
|
109 |
) |
|
|
110 |
} |