-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
better_forestplot.R
128 lines (108 loc) · 4.5 KB
/
better_forestplot.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
# code to generate better plots by Thodoris
library(DSI)
library(DSOpal)
library(devtools)
library(dsBaseClient)
library(meta)
library(dplyr)
library(pheatmap)
library(gridExtra)
library(dsSurvivalClient)
rm(list=ls())
builder <- DSI::newDSLoginBuilder()
#CLUSTER simulated data
builder$append(server = "study1",
url = "http://192.168.56.100:8080/",
user = "administrator", password = "datashield_test&",
table = "CLUSTER.CLUSTER_SLO1", driver = "OpalDriver")
builder$append(server = "study2",
url = "http://192.168.56.100:8080/",
user = "administrator", password = "datashield_test&",
table = "CLUSTER.CLUSTER_SLO2", driver = "OpalDriver")
builder$append(server = "study3",
url = "http://192.168.56.100:8080/",
user = "administrator", password = "datashield_test&",
table = "CLUSTER.CLUSTER_SLO3", driver = "OpalDriver")
builder$append(server = "study4",
url = "http://192.168.56.100:8080/",
user = "administrator", password = "datashield_test&",
table = "CLUSTER.CLUSTER_INT1", driver = "OpalDriver")
builder$append(server = "study5",
url = "http://192.168.56.100:8080/",
user = "administrator", password = "datashield_test&",
table = "CLUSTER.CLUSTER_INT2", driver = "OpalDriver")
builder$append(server = "study6",
url = "http://192.168.56.100:8080/",
user = "administrator", password = "datashield_test&",
table = "CLUSTER.CLUSTER_INT3", driver = "OpalDriver")
logindata <- builder$build()
# Log onto the remote Opal training servers
connections <- DSI::datashield.login( logins = logindata
, assign = TRUE
, symbol = "D")
#Example without heterogeneity
OR <- ds.glmSLMA(formula = "diabetes ~ Male",
dataName="D",
family="binomial",
newobj="summaryOR",
combine.with.metafor=T)
OR$SLMA.pooled.ests.matrix[2,]
#Example with heterogeneity
MD <- ds.glmSLMA(formula = "incid_rate ~ trtGrp",
dataName="D",
family="gaussian",
newobj="summaryMD",
combine.with.metafor=T)
MD$SLMA.pooled.ests.matrix[2,]
MD$betamatrix.valid[2,]
MD$sematrix.valid[2,]
studylabels <- c("center1","center2","center3","center4","center5","center6")
#Variables should be formatted as a matrix
effects <- matrix(c(MD$betamatrix.valid[2,]
,MD$sematrix.valid[2,])
,dimnames = list(studylabels,c("TE","seTE"))
,nrow=length(studylabels)
,ncol=2)
mtotal <- metagen(TE=TE, seTE=seTE, data=as.data.frame(effects)
, method.tau = 'REML', prediction=T, hakn=F)
meta::forest(mtotal, xlim = c(12,16))
meta::baujat(mtotal)
heatPlot <- function (x, method.tau = 'REML'){
bootstrap <- function(x) {
#x needs a label column
nrs <- nrow(x)
res <- Reduce(function(ag, xr){
ag[[rownames(x)[xr]]] <- x[-xr,]
return(ag)
}, 1:nrs, list() )
res$total <- x
return(res)
}
effs <- bootstrap(x)
res <- lapply(effs, function(ef){
mt <- metagen(TE=ef[,"TE"], seTE=ef[,"seTE"]
, method.tau = method.tau, prediction=T)
return(list(I2=mt$I2, tau=mt$tau, Q=mt$Q))
})
labels <- rownames(as.matrix(res))
out <- matrix(unlist(res)
,ncol = length(labels)
,dimnames = list(c("I2","tau","Q"),labels))
plist <- list(pheatmap(t(out[1,]), labels_row=expression(I^2),
show_colnames=F,
silent=T,
display_numbers = T,
cluster_cols = F,cluster_rows=F,
color = colorRampPalette(c("firebrick3", "yellow", "blue"))(150)
)$gtable
,pheatmap(t(out[2,]),
color = colorRampPalette(c("firebrick3", "yellow", "blue"))(150),
labels_row=expression(tau), show_colnames=F,silent=T,display_numbers = T,cluster_cols = F,cluster_rows=F)$gtable
,pheatmap(t(out[3,]),
color = colorRampPalette(c("firebrick3", "yellow", "blue"))(150),
labels_row="Q", display_numbers = T,cluster_cols = F,silent=T,cluster_rows=F)$gtable
)
do.call("grid.arrange", c(plist, ncol=1))
return(out)
}
heatPlot(effects)