forked from child-growth/Co-occurrence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_outcome_and_covariates.R
137 lines (85 loc) · 3.17 KB
/
merge_outcome_and_covariates.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
rm(list=ls())
library(tidyverse)
library(reshape2)
#merge outcomes with covariates
setwd("U:/UCB-SuperLearner/Co-occurrence/")
#load covariates
cov<-readRDS("U:/ucb-superlearner/stunting rallies/FINAL_clean_covariates.rds")
#load outcomes
load("co_prev.RData")
load("co_CI_rf_outcomes.RData")
load("pooled_CI_res.RData")
#convert subjid to character for the merge with covariate dataset
dmn$subjid <- as.character(dmn$subjid)
co_ci$subjid <- as.character(co_ci$subjid)
#------------------------------------
# Create cumulative incidence dataset
#------------------------------------
#merge in covariates
cuminc <- cuminc %>% subset(., select = -c(tr))
dim(cuminc)
dim(cov)
d <- left_join(cuminc, cov, by=c("studyid", "subjid", "country"))
dim(d)
head(d)
#Vector of outcome names
Y<-c("ever_coed")
#Vector of risk factor names
A<-c( "sex", "mage", "mhtcm", "mwtkg",
"mbmi", "single", "fage", "fhtcm",
"nrooms", "nchldlt5", "nhh",
"hhwealth_quart", "brthmon", "parity", "meducyrs",
"feducyrs", "hfoodsec")
#Vector of covariate names
W<-c("")
#Subgroup variable
V <- c("agecat")
#clusterid ID variable
id <- c("id")
save(d, Y, A,V, id, file="co_cuminc_rf.Rdata")
#------------------------------------
# Create cumulative incidence dataset
# - no birth incidence
#------------------------------------
#merge in covariates
cuminc_nobirth <- cuminc_nobirth %>% subset(., select = -c(tr))
cuminc_nobirth <- bind_rows(cuminc_nobirth, cuminc[cuminc$agecat=="6-24 months",])
d <- left_join(cuminc_nobirth, cov, by=c("studyid", "subjid", "country"))
head(d)
#Vector of outcome names
Y<-c("ever_coed")
#Vector of risk factor names
A<-c( "gagebrth", "birthwt",
"birthlen", "vagbrth", "hdlvry",
"enwast", "anywast06", "pers_wast",
"trth2o", "cleanck", "impfloor",
"impsan", "safeh20",
"perdiar6", "perdiar24",
"predfeed3", "exclfeed3", "predfeed6", "exclfeed6", "predfeed36", "exclfeed36",
"predexfd6", "earlybf", "month")
#Vector of covariate names
W<-c("")
#Subgroup variable
V <- c("agecat")
#clusterid ID variable
id <- c("id")
save(d, Y, A,V, id, file="co_cuminc_nobirth_rf.Rdata")
#------------------------------------
# Create prevalence dataset
#------------------------------------
#merge in covariates
d <- left_join(prev, cov, by=c("studyid", "subjid", "country"))
head(d)
#Vector of outcome names
Y<-c("wasted","swasted")
A<-c( "sex", "gagebrth", "birthwt",
"birthlen", "vagbrth", "hdlvry", "mage", "mhtcm", "mwtkg",
"mbmi", "single", "fage", "fhtcm", "nrooms", "nhh", "nchldlt5",
"hhwealth_quart", "month", "brthmon", "parity", "meducyrs",
"feducyrs", "hfoodsec",
"enwast", "anywast06", "pers_wast",
"trth2o", "cleanck", "impfloor", "impsan", "safeh20",
"perdiar6", "perdiar24", "predexfd6",
"predfeed3", "exclfeed3", "predfeed6", "exclfeed6", "predfeed36", "exclfeed36",
"earlybf")
save(d, Y, A,V, id, file="co_prev_rf.Rdata")