forked from tonymatthews/validate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.R
112 lines (75 loc) · 2.48 KB
/
master.R
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
setwd("I:/EPI/Data/Anthony Matthews/validate/")
# Load packages
library(tableone)
library(labelled)
library(haven)
library(survival)
library(ggplot2)
library(dplyr)
library(survminer)
library(gridExtra)
library(ggpubr)
library(geepack)
library(splitstackshape)
library(boot)
library(tidyr)
# Time code starts
starttime <- Sys.time()
######## CREATE VALUES NEEDED ########
# Outcomes
outcomes <- c("composite", "death", "mi", "bleed")
# Time period
period <- "jan12tomay14"
# Number of bootstraps
numboot <- 500
####### CREATE FUNCTIONS ########
#create ipweights with data in the argument, using the variables selected in this script
source("scripts/func_ipweights.R")
source("scripts/func_ipweights_indikation.R")
######## IDENTIFY BASE DATA #######
dat <- data.frame(read_dta(paste0("mydata/cr_finaldataset_", period, ".dta")))
###### CREATE DATA FRAMES ########
# Create a data frame that only contains the information for each outcome, and one that can be used to calculate ipweights
source("scripts/cr_data.R")
######## RUN ANALYSES ########
## Make a table one
source("scripts/an_tableone.R")
#Kaplan Meier plots
source("scripts/an_kaplanmeier.R")
#Kaplan Meier plots - IP weighted
source("scripts/an_kaplanmeier_ipweighted.R")
# IP weighted risk, risk diff, and risk ratio at 180/30/14 days
source("scripts/an_ipwsurvival_180.R")
source("scripts/an_ipwsurvival_30.R")
source("scripts/an_ipwsurvival_14.R")
# G-formula 180 days
source("scripts/an_gformula_180.R")
#### SENSITIVITY ANALYSES & EFFECT MODIFICATION ######
# Censor at death sensitivity
source("scripts/sens_censdeath_an_ipwsurvival_180.R")
#Other sensitivities & STEMI/NSTEMI EM analysis
analysis <- c(
"sens_stemi_",
"sens_nstemi_",
"sens_allcancer_",
"sens_exp_",
"sens_bleed_",
"sens_confounderlookback_",
"sens_completecase_",
"sens_older_",
"sens_allP2Y12_",
"sens_allhepbef_",
"sens_includegfr_"
)
for (p in analysis) {
######## UPDATE BASE DATA #######
dat <- data.frame(read_dta(paste0("mydata/", p, "cr_finaldataset_", period, ".dta")))
###### UPDATE OUTCOME DATA FRAMES #####
source("scripts/cr_data.R")
#### ANALYSES (run the sensitivity datasets through the previous analysis files) ####
source("scripts/sens_an_ipwsurvival_180.R")
source("scripts/sens_an_ipwsurvival_30.R")
}
endtime <- Sys.time()
#time to run all of the code
endtime-starttime