-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrace_kern.R
57 lines (51 loc) · 2.19 KB
/
race_kern.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
race_kern = function(race4ce,
dailycount,
country="USA",
cohorts,
sev="pts_all",
site.register){
expit = function(mm){mm=as.numeric(mm);return(exp(mm)/(exp(mm)+1))}
if(country=="ALL"){site.sel=site.register$SiteID
} else{site.sel=site.register$SiteID[site.register$Country==country]}
dailycount=filter(dailycount, siteid %in% site.sel, cohort %in% cohorts)
count=NULL
for(ss in site.sel){
junk=dailycount[dailycount$siteid==ss,]
date.keep = max(as.Date(junk$calendar_date))
count = rbind.data.frame(count,
dailycount[dailycount$siteid==ss&dailycount$calendar_date==date.keep,])
}
if(grepl("pts_all",sev,fixed = T)){count=count[,1:4]
}else if(grepl("pts_ever_severe",sev,fixed = T)){count=count[,c(1:3,7)]
}else if(grepl("pts_never_severe",sev,fixed = T)){count=count[,c(1:3,14)]}
count$sc=paste0(count$siteid,count$cohort)
count=count[order(count$sc),]
rownames(count)=c()
race4ce=filter(race4ce,siteid%in%site.sel,cohort %in% cohorts)
race4ce$sc=paste0(race4ce$siteid,race4ce$cohort)
race4ce=merge(race4ce,count,by="sc",all.x=TRUE)
res=NULL
for(rr in unique(race4ce$race_4ce)){
tryCatch({
junk=filter(race4ce,race_4ce==rr)
junk.plo=escalc(xi=junk[,sev],
ni=junk[,colnames(count)[4]],
measure="PLO")
rma.res = rma(yi=junk.plo$yi,
vi=junk.plo$vi,
method="DL",
drop00=TRUE)
res=rbind.data.frame(res,
cbind.data.frame("country"=country,
"cohort"=paste(cohorts,collapse = ''),
"setting"=sev,
"subgroup"=rr,
"p"=expit(rma.res$b),
"se"=rma.res$se,
"ci.95L"=expit(rma.res$ci.lb),
"ci.95U"=expit(rma.res$ci.ub)))
},error=function(e){NA})
}
rownames(res)=c()
return(res)
}