Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
Running Code
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.3.2
Warning: package 'ggplot2' was built under R version 4.3.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.2 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ purrr 1.0.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(here)
Warning: package 'here' was built under R version 4.3.2
here() starts at C:/Users/GAMcleod/OneDrive - University of Dundee/Edin MSc/Vascular
library(janitor)
Warning: package 'janitor' was built under R version 4.3.2
Attaching package: 'janitor'
The following objects are masked from 'package:stats':
chisq.test, fisher.test
library(skimr)
Warning: package 'skimr' was built under R version 4.3.2
library(gapminder)
Warning: package 'gapminder' was built under R version 4.3.2
library(lubridate)library(survival)library(Hmisc)
Warning: package 'Hmisc' was built under R version 4.3.2
Attaching package: 'Hmisc'
The following objects are masked from 'package:dplyr':
src, summarize
The following objects are masked from 'package:base':
format.pval, units
library(rms)
Warning: package 'rms' was built under R version 4.3.2
library(finalfit)
Warning: package 'finalfit' was built under R version 4.3.2
library(forcats)library(survminer)
Warning: package 'survminer' was built under R version 4.3.3
Loading required package: ggpubr
Warning: package 'ggpubr' was built under R version 4.3.2
Attaching package: 'survminer'
The following object is masked from 'package:survival':
myeloma
library(here)
The echo: false option disables the printing of code (only output is displayed).
vascular <-read_csv("C:/Users/GAMcleod/OneDrive - University of Dundee/Edin MSc/Vascular/data/vascular.csv")
New names:
Rows: 455 Columns: 358
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(58): Date_Admission...9, Date_NSTI, Date_Admission...145, Date_Critica... dbl
(253): No, Age, Sex, Admissions, Admissions_Infection, Censor_NSTI, NSTI... lgl
(47): NSTI_13, NSTI_14, ...59, ...89, ...90, Duration_Hosp_11, Duration...
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `Date_Admission` -> `Date_Admission...9`
• `` -> `...59`
• `` -> `...80`
• `` -> `...89`
• `` -> `...90`
• `` -> `...105`
• `` -> `...106`
• `` -> `...107`
• `` -> `...136`
• `` -> `...137`
• `` -> `...138`
• `` -> `...139`
• `` -> `...140`
• `` -> `...141`
• `` -> `...142`
• `` -> `...143`
• `` -> `...144`
• `Date_Admission` -> `Date_Admission...145`
• `Date of Discharge` -> `Date of Discharge...147`
• `Date of Admission` -> `Date of Admission...148`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...149`
• `Date of Discharge` -> `Date of Discharge...150`
• `Date of Admission` -> `Date of Admission...151`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...152`
• `Date of Discharge` -> `Date of Discharge...153`
• `Date of Admission` -> `Date of Admission...154`
• `` -> `...155`
• `Date of Discharge` -> `Date of Discharge...156`
• `Date of Admission` -> `Date of Admission...157`
• `` -> `...158`
• `Date of Discharge` -> `Date of Discharge...159`
• `Date of Admission` -> `Date of Admission...160`
• `` -> `...161`
• `Date of Discharge` -> `Date of Discharge...162`
• `Date of Admission` -> `Date of Admission...163`
• `` -> `...164`
• `Date of Discharge` -> `Date of Discharge...165`
• `Date of Admission` -> `Date of Admission...166`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...167`
• `Date of Discharge` -> `Date of Discharge...168`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...170`
• `Date of Admin` -> `Date of Admin...172`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...173`
• `Date of Discharge` -> `Date of Discharge...174`
• `Date of Admin` -> `Date of Admin...175`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...176`
• `Date of Discharge` -> `Date of Discharge...177`
• `Date of Admin` -> `Date of Admin...178`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...179`
• `Date of Discharge` -> `Date of Discharge...180`
• `Date of Admin` -> `Date of Admin...181`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...182`
• `Date of Discharge` -> `Date of Discharge...183`
• `Date of Admin` -> `Date of Admin...184`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...185`
• `Date of Discharge` -> `Date of Discharge...186`
• `Date of Critical Care Admission` -> `Date of Critical Care Admission...188`
• `` -> `...345`
• `` -> `...346`
• `` -> `...347`
• `` -> `...348`
• `` -> `...349`
• `` -> `...350`
• `` -> `...351`
• `` -> `...352`
• `` -> `...353`
• `` -> `...354`
• `` -> `...355`
• `` -> `...356`
• `` -> `...357`
• `` -> `...358`
Warning in fitter(..., strata = strata, rownames = rownames, offset = offset, :
Ran out of iterations and did not converge
Warning in fitter(..., strata = strata, rownames = rownames, offset = offset, :
Ran out of iterations and did not converge
Divergence or singularity in 5 samples
index.orig training test optimism index.corrected n
Dxy 0.5862 0.7008 0.4446 0.2563 0.3299 45
R2 0.2759 0.4439 0.1187 0.3252 -0.0493 45
Slope 1.0000 1.0000 0.2663 0.7337 0.2663 45
D 0.1349 0.2479 0.0527 0.1952 -0.0603 45
U -0.0053 -0.0056 0.5760 -0.5815 0.5762 45
Q 0.1402 0.2534 -0.5233 0.7767 -0.6365 45
g 1.5577 3.4216 0.8382 2.5834 -1.0257 45
Iteration_2
fit_death<-cph(Surv(T_Death, Censor_Death) ~ Age + Sex + Censor_NSTI + Pseudoaneurysm+ Admissions+ Admissions_Infection + Dur_Crit + Dur_Crit_Censor + Censor_Amp +rcs(Hb,3) + WCC + CRP +Na +Albumin +Urea +Creatinine +Lactate +Glucose, x =TRUE, y =TRUE,surv=TRUE,data=vascular)anova(fit_death)
index.orig training test optimism index.corrected n
Dxy 0.5380 0.6454 0.4483 0.1971 0.3409 48
R2 0.2427 0.3774 0.1162 0.2612 -0.0185 48
Slope 1.0000 1.0000 0.3811 0.6189 0.3811 48
D 0.1162 0.1978 0.0515 0.1463 -0.0301 48
U -0.0053 -0.0054 0.2156 -0.2210 0.2157 48
Q 0.1215 0.2032 -0.1641 0.3673 -0.2458 48
g 1.3434 2.3750 0.8533 1.5217 -0.1782 48
Iteration_3
fit_death_surv3<-cph(Surv(T_Death, Censor_Death) ~ Age + Dur_Crit_Censor + Hb + WCC +rcs(CRP,3) + Albumin +rcs(Urea,3) + Creatinine*Lactate, x =TRUE, y =TRUE,surv=TRUE,data=vascular)anova(fit_death_surv3)
Wald Statistics Response: Surv(T_Death, Censor_Death)
Factor Chi-Square d.f. P
Age 7.53 1 0.0061
Dur_Crit_Censor 8.02 1 0.0046
Hb 4.45 1 0.0349
WCC 2.22 1 0.1359
CRP 2.96 2 0.2274
Nonlinear 2.80 1 0.0941
Albumin 1.00 1 0.3168
Urea 11.75 2 0.0028
Nonlinear 10.92 1 0.0010
Creatinine (Factor+Higher Order Factors) 5.78 2 0.0556
All Interactions 1.62 1 0.2031
Lactate (Factor+Higher Order Factors) 2.70 2 0.2595
All Interactions 1.62 1 0.2031
Creatinine * Lactate (Factor+Higher Order Factors) 1.62 1 0.2031
TOTAL NONLINEAR 12.53 2 0.0019
TOTAL NONLINEAR + INTERACTION 13.03 3 0.0046
TOTAL 35.06 12 0.0005
validate(fit_death_surv3, B =50,dxy=TRUE)
index.orig training test optimism index.corrected n
Dxy 0.4208 0.4802 0.3776 0.1026 0.3182 50
R2 0.1451 0.1949 0.0810 0.1139 0.0312 50
Slope 1.0000 1.0000 0.5310 0.4690 0.5310 50
D 0.0640 0.0903 0.0340 0.0563 0.0077 50
U -0.0039 -0.0040 0.2073 -0.2112 0.2073 50
Q 0.0679 0.0943 -0.1733 0.2675 -0.1996 50
g 0.9628 1.2279 0.6419 0.5860 0.3769 50
fit_death_surv3
Frequencies of Missing Values Due to Each Variable
Surv(T_Death, Censor_Death) Age
0 0
Dur_Crit_Censor Hb
0 6
WCC CRP
47 46
Albumin Urea
51 47
Creatinine Lactate
124 127
Cox Proportional Hazards Model
cph(formula = Surv(T_Death, Censor_Death) ~ Age + Dur_Crit_Censor +
Hb + WCC + rcs(CRP, 3) + Albumin + rcs(Urea, 3) + Creatinine *
Lactate, data = vascular, x = TRUE, y = TRUE, surv = TRUE)
Model Tests Discrimination
Indexes
Obs 250 LR chi2 33.77 R2 0.145
Events 56 d.f. 12 R2(12,250)0.083
Center 2.3614 Pr(> chi2) 0.0007 R2(12,56)0.322
Score chi2 39.28 Dxy 0.421
Pr(> chi2) 0.0001
Coef S.E. Wald Z Pr(>|Z|)
Age 0.0609 0.0222 2.74 0.0061
Dur_Crit_Censor 0.9638 0.3403 2.83 0.0046
Hb 0.0197 0.0093 2.11 0.0349
WCC -0.0420 0.0281 -1.49 0.1359
CRP 0.0085 0.0050 1.71 0.0879
CRP' -0.0082 0.0049 -1.67 0.0941
Albumin -0.0360 0.0360 -1.00 0.3168
Urea -0.5445 0.1732 -3.14 0.0017
Urea' 0.7828 0.2369 3.30 0.0010
Creatinine 0.0106 0.0055 1.92 0.0548
Lactate 0.2179 0.1457 1.50 0.1348
Creatinine * Lactate -0.0023 0.0018 -1.27 0.2031
glm(formula = Censor_Death ~ Age + Sex + Dur_Crit_Censor + Pseudoaneurysm + Dur_Hosp + Dur_Crit_Censor + Hb + WCC + CRP + Albumin + Urea + Creatinine +Lactate, family =binomial(), data = vascular, x =TRUE, y =TRUE)
Call: glm(formula = Censor_Death ~ Age + Sex + Dur_Crit_Censor + Pseudoaneurysm +
Dur_Hosp + Dur_Crit_Censor + Hb + WCC + CRP + Albumin + Urea +
Creatinine + Lactate, family = binomial(), data = vascular,
x = TRUE, y = TRUE)
Coefficients:
(Intercept) Age Sex Dur_Crit_Censor
-2.865734 0.032457 0.945874 1.109779
Pseudoaneurysm Dur_Hosp Hb WCC
0.003058 0.007323 0.009353 -0.014403
CRP Albumin Urea Creatinine
-0.000359 -0.054742 -0.033030 0.006512
Lactate
0.028035
Degrees of Freedom: 249 Total (i.e. Null); 237 Residual
(205 observations deleted due to missingness)
Null Deviance: 266
Residual Deviance: 235.4 AIC: 261.4
Mortality - Logistic regression model Iteration_1
glm(formula = Censor_Death ~ Age + Admissions + Dur_Crit_Censor +Hb + WCC+ CRP +Na + Albumin + Urea+ Creatinine +Lactate, family =binomial(), data = vascular, x =TRUE, y =TRUE)
Call: glm(formula = Censor_Death ~ Age + Admissions + Dur_Crit_Censor +
Hb + WCC + CRP + Na + Albumin + Urea + Creatinine + Lactate,
family = binomial(), data = vascular, x = TRUE, y = TRUE)
Coefficients:
(Intercept) Age Admissions Dur_Crit_Censor
-3.829e+00 2.966e-02 1.309e-01 1.001e+00
Hb WCC CRP Na
9.247e-03 -1.686e-02 -8.755e-05 8.263e-03
Albumin Urea Creatinine Lactate
-5.071e-02 -2.995e-02 6.532e-03 2.522e-02
Degrees of Freedom: 246 Total (i.e. Null); 235 Residual
(208 observations deleted due to missingness)
Null Deviance: 264.4
Residual Deviance: 238.7 AIC: 262.7
fit_Death_lrm2<-lrm(formula = Censor_Death ~ Age + Sex + Admissions_Infection + Dur_Crit_Censor +Hb + WCC +rcs(CRP,3) +Na + Albumin +rcs(Urea,3) + Creatinine +Lactate, data = vascular, x =TRUE, y =TRUE)fit_Death_lrm2
Frequencies of Missing Values Due to Each Variable
Censor_Death Age Sex
0 0 0
Admissions_Infection Dur_Crit_Censor Hb
0 0 6
WCC CRP Na
47 46 57
Albumin Urea Creatinine
51 47 124
Lactate
127
Logistic Regression Model
lrm(formula = Censor_Death ~ Age + Sex + Admissions_Infection +
Dur_Crit_Censor + Hb + WCC + rcs(CRP, 3) + Na + Albumin +
rcs(Urea, 3) + Creatinine + Lactate, data = vascular, x = TRUE,
y = TRUE)
Model Likelihood Discrimination Rank Discrim.
Ratio Test Indexes Indexes
Obs 247 LR chi2 38.33 R2 0.219 C 0.753
0 191 d.f. 14 R2(14,247)0.094 Dxy 0.505
1 56 Pr(> chi2) 0.0005 R2(14,129.9)0.171 gamma 0.505
max |deriv| 0.0002 Brier 0.148 tau-a 0.178
Coef S.E. Wald Z Pr(>|Z|)
Intercept -1.5340 7.8444 -0.20 0.8450
Age 0.0523 0.0246 2.12 0.0337
Sex 0.8304 0.3653 2.27 0.0230
Admissions_Infection 0.2638 0.1175 2.25 0.0247
Dur_Crit_Censor 1.1417 0.4343 2.63 0.0086
Hb 0.0159 0.0109 1.46 0.1453
WCC -0.0238 0.0233 -1.02 0.3070
CRP 0.0054 0.0054 1.01 0.3109
CRP' -0.0056 0.0053 -1.06 0.2886
Na -0.0137 0.0542 -0.25 0.8008
Albumin -0.0584 0.0400 -1.46 0.1439
Urea -0.4586 0.2029 -2.26 0.0238
Urea' 0.6117 0.2803 2.18 0.0291
Creatinine 0.0082 0.0048 1.71 0.0868
Lactate 0.0130 0.0442 0.30 0.7678