-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.Rhistory
512 lines (512 loc) · 18.7 KB
/
.Rhistory
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
multi <- TRUE
} else {
multi <- FALSE
Data_MCMC <- Data_MCMC[-which(names(Data_MCMC) %in% c("H", "PREC"))]
}
##
par_save <- c("precision", "beta", "gamma", "sigma", "p.cons", "sd", "d") #parameteres saved in the MCMC
if (NMA_data$p == 1) {
one_IF <- TRUE
Data_MCMC$x <- as.vector(Data_MCMC$x)
par_save <- par_save[-which(par_save == "sigma")]
if(zellner){
Data_MCMC <- Data_MCMC[-which(names(Data_MCMC) == "ZTZ")]
}
} else {
one_IF <- FALSE
}
if(!zellner){
Data_MCMC <- Data_MCMC[-which(names(Data_MCMC) == "ZTZ")]
if("sigma" %in% par_save){
par_save <- par_save[-which(par_save == "sigma")]
}
}
if (is.null(psi) == TRUE) {
#Pilot NMA MCMC run
Data_MCMC_pilot <- Data_MCMC
if(one_IF){
Data_MCMC_pilot <- Data_MCMC_pilot[-which(names(Data_MCMC_pilot) == "p")]
}
model <- R2jags::jags(
model.file = textConnection(NMApilot(multi, one_IF, zellner)),
n.iter = M_pilot, n.burnin = B_pilot, n.thin = n_thin_pilot, n.chains = n_chains_pilot,
parameters.to.save = c("beta"), data = Data_MCMC_pilot
)
##
Data_MCMC[["psi"]] <- model$BUGSoutput$summary[-which(rownames(model$BUGSoutput$summary) == "deviance"), 2]
} else {
Data_MCMC[["psi"]] <- rep(psi, Data_MCMC$p)
}
##
Data_MCMC[["c"]] <- c
m_NMA <- NMAmodel(multi, one_IF, rpcons, pcons, zellner)
##
model <- R2jags::jags(
model.file = textConnection(m_NMA), n.iter = M, n.burnin = B, n.thin = n_thin, n.chains = n_chains,
parameters.to.save = par_save, DIC = FALSE, data = Data_MCMC
)
n.iter=1000
##
model <- R2jags::jags(
model.file = textConnection(m_NMA), n.iter = M, n.burnin = B, n.thin = n_thin, n.chains = n_chains,
parameters.to.save = par_save, DIC = FALSE, data = Data_MCMC
)
n.iter
M=1000
##
model <- R2jags::jags(
model.file = textConnection(m_NMA), n.iter = M, n.burnin = B, n.thin = n_thin, n.chains = n_chains,
parameters.to.save = par_save, DIC = FALSE, data = Data_MCMC
)
M=10000
##
model <- R2jags::jags(
model.file = textConnection(m_NMA), n.iter = M, n.burnin = B, n.thin = n_thin, n.chains = n_chains,
parameters.to.save = par_save, DIC = FALSE, data = Data_MCMC
)
# Transform numerical comparisons to the original comparison's names
IF <- transformIF(NMA_data$IF, trt_trans, method)
##
Z_matrix <- as.data.frame(NMA_data$Z)
Z_t1 <- plyr::mapvalues(NMA_data$Z_MCMC$treat1, from = trt_trans$to, to=trt_trans$from, warn_missing = FALSE)
Z_t2 <- plyr::mapvalues(NMA_data$Z_MCMC$treat2, from = trt_trans$to, to=trt_trans$from, warn_missing = FALSE)
Z_matrix <- data.frame("treat1" = Z_t1,"treat2" = Z_t2, "studlab" = NMA_data$Z_MCMC$studlab ,Z_matrix)
colnames(Z_matrix)[4:dim(Z_matrix)[2]] <- IF
covariates <- model$parameters.to.save
# jags output
model_effects <- model$BUGSoutput
model_effects_summary <- as.data.frame(model_effects$summary)
# Table with the MCMC NMA results
result <- data.frame(matrix(nrow = dim(model_effects_summary)[1], ncol = 4))
colnames(result) <- c("Parameter", "Estimate", "lb", "ub")
##
result$Parameter <- row.names(model_effects_summary)
result$Estimate <- model_effects_summary$`50%`
result$lb <- model_effects_summary$`2.5%`
result$ub <- model_effects_summary$`97.5%`
##
result[-grep(paste(covariates[-which(covariates == "d")], collapse = "|"), result$Parameter), "Parameter"] <- paste(trt_trans$from, "vs", trt_trans$from[as.numeric(Data_MCMC$ref)])
##
result[which(result$Parameter == "precision"), 2:4] <- 1 / result[which(result$Parameter == "precision"), 2:4]
result[which(result$Parameter == "precision"), "Parameter"] <- "tau2"
result[which(result$Parameter == "sigma"), "Parameter"] <- "sigma2"
beta <- result[grep(paste("beta", sep = "|", collapse = "|"), result$Parameter), ]
beta <- beta[(dim(beta)[1] - Data_MCMC$p + 1):dim(beta)[1], ]
##
gamma <- result[grep(paste("gamma", sep = "|", collapse = "|"), result$Parameter), ]
gamma$Estimate <- model$BUGSoutput$mean$gamma
gamma <- gamma[(dim(gamma)[1] - Data_MCMC$p + 1):dim(gamma)[1], ]
IF_PIP <- data.frame(matrix(ncol = 6, nrow = dim(gamma)[1]))
colnames(IF_PIP) <- c("Comparison", "Design", "PIP", "b", "b.lb", "b.ub")
IF
trt_trans
IF
strsplit(IF, split = "_")
sapply(strsplit(IF, split = "_"), print[1])
sapply(strsplit(IF, split = "_"), print)
z <- sapply(strsplit(IF, split = "_")
IF_PIP$Comparison <-
}
IF_PIP$IF <- IF
IF_PIP$PIP <- round(gamma$Estimate, digits = digits)
IF_PIP$b <- round(beta$Estimate, digits = digits)
IF_PIP$b.lb <- round(beta$lb, digits = digits)
IF_PIP$b.ub <- round(beta$ub, digits = digits)
##
# Posterior Odds
##
drawns <- as.matrix(model$BUGSoutput$sims.matrix)
drawns <- as.data.frame(drawns[, grep("gamma", colnames(drawns))])
drawns$model <- NA
colnames(drawns)[1:length(IF)] <- IF
if (dim(drawns)[2] == 2) {
drawns$model <- sapply(drawns[, -dim(drawns)[2]], FUN = function(x) {
paste(colnames(drawns)[which(x == 1)], collapse = ",", sep = " ")
})
} else {
drawns$model <- apply(drawns[, -dim(drawns)[2]], 1, function(x) {
paste(colnames(drawns)[which(x == 1)], collapse = ",", sep = " ")
})
}
models <- as.data.frame(table(drawns$model), stringsAsFactors = F)
models <- models[order(models$Freq, decreasing = T), ]
models$Percent <- models$Freq / dim(drawns)[1]
models$Var1[which(models$Var1 == "")] <- "No IFs"
colnames(models)[c(1, 3)] <- c("IFs", "f(m|y)")
models$PO_IFCONS <- models$`f(m|y)`[which(models$IFs == "No IFs")] / models$`f(m|y)`
##
# Bayes Factor of the consistent NMA model versus the inconsistent NMA model
##
fm1y <- models$`f(m|y)`[which(models$IFs=="No IFs")]
fm2y <- 1 - fm1y
fm1 <- result$Estimate[which(result$Parameter=="p.cons")]
fm2 <- 1 - fm1
##
BF_m1m2 <- round((fm1y*fm2)/(fm2y*fm1), digits = digits)
# Round results
for (i in 2:4) {
result[, i] <- round(result[, i], digits = digits)
models[, i] <- round(models[, i], digits = digits)
}
# Change the names according to inconsistency factors names
result[grep("beta",result$Parameter),"Parameter"] <- paste("Effect of",IF,sep = " ")
result[grep("gamma",result$Parameter),"Parameter"] <- paste("P.I.P of",IF,sep = " ")
res <- list(
"Summary" = result,
"PIP" = IF_PIP,
"PO" = models,
"BF"=BF_m1m2)
}
z <- strsplit(IF, split = "_")
z
sapply(z , FUN = function(x){print(x[1])})
sapply(z , FUN = function(x){print(x[1])})
z
sapply(z , FUN = function(x){print(x[[1]])})
sapply(z , FUN = function(x){print(x[[1]][1])})
sapply(z, dim)
sapply(z, length)
z_len <- sapply(z, length)
z[[1]]
z[[10]]
print(z)
sapply(z , FUN = function(x){x[[1]][1])})
sapply(z , FUN = function(x){x[[1]][1]})
sapply(z , FUN = function(x){x[1]})
sapply(z , FUN = function(x){x[1]})
sapply(z , FUN = function(x){x[2]})
sapply(z , FUN = function(x){x[1]})
z_len
IF_PIP$Comparison <- sapply(z , FUN = function(x){x[1]})
IF_PIP
IF_PIP <- data.frame(matrix(ncol = 6, nrow = dim(gamma)[1]))
colnames(IF_PIP) <- c("Comparison", "Design", "PIP", "b", "b.lb", "b.ub")
IF_PIP$Comparison <- sapply(z , FUN = function(x){x[1]})
IF_PIP
IF_PIP$Comparison <- IF_PIP$Design <- sapply(z , FUN = function(x){x[1]})
z_len
z_len > 1
sum(z_len > 1)
sum(z_len > 1) > 0
z[which(z_len > 1)]
sapply(z[which(z_len > 1)], FUN = function(x){x[2]})
IF_PIP
if( sum(z_len > 1) > 0){
IF_PIP$Design[which(z_len > 1)] <- sapply(z[which(z_len > 1)], FUN = function(x){x[2]})
}
IF_PIP
paste(IF_PIP$Design, collapse = ";")
paste(IF_PIP$Design, collapse = " ; ")
paste(IF_PIP$Design, sep = " ; ")
sum(z_len == 1) > 0
z[which(z_len == 1)]
sapply(z[which(z_len == 1)], FUN = function(x){paste(strsplit(x, split = ";"))})
strsplit(x, split = ";")
sapply(z[which(z_len == 1)], FUN = function(x){paste0(unlist(strsplit(x, split = ";")))})
z[which(z_len == 1)]
x=z[1]
paste0(unlist(strsplit(x, split = ";")))
strsplit(x, split = ";")
x
x=z[[1]]
strsplit(x, split = ";")
unlist(strsplit(x, split = " ; ")
(unlist(strsplit(x, split = ";"))
)
(trimws(unlist(strsplit(x, split = ";"))))
paste0(trimws(unlist(strsplit(x, split = ";"))))
paste0(trimws(unlist(strsplit(x, split = ";"))), collapse = "")
sapply(z[which(z_len == 1)], FUN = function(x){paste0(trimws(unlist(strsplit(x, split = ";"))), collapse = "")})
sapply(z[which(z_len == 1)], FUN = function(x){paste0(trimws(unlist(strsplit(x, split = ";"))), collapse = "")})
sapply(z[which(z_len == 1)], FUN = function(x){paste0(trimws(unlist(strsplit(x, split = ";"))), collapse = "")})
sapply(z[which(z_len == 1)], FUN = function(x){paste0(trimws(unlist(strsplit(x, split = ";"))), collapse = "")})
IF_PIP$Design[which(z_len == 1)] <- sapply(z[which(z_len == 1)], FUN = function(x){paste0(trimws(unlist(strsplit(x, split = ";"))), collapse = "")})
IF_PIP
devtools::load_all(".")
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes")
m$Posterior_inclusion_probabilities
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT")
m
m$Posterior_inclusion_probabilities
IF
library(ssifs)
install.packages("styler")
devtools::load_all(".")
subnet(data)
igraph::graph.data.frame(cbind(as.character(data$treat1),as.character(data$treat2)), directed = F)
igraph::graph.data.frame(cbind(as.character(data$treat1),as.character(data$treat2)), directed = F)
t <- igraph::graph.data.frame(cbind(as.character(data$treat1),as.character(data$treat2)), directed = F)
# Find the Strong Connected Components using Kosaraju algorithm
op <- options(listexpressions=500000)
SCC <- RevEcoR::KosarajuSCC(t)
SCC
RevEcoR::KosarajuSCC(t)
SCC <- RevEcoR::KosarajuSCC(t)
SCC <- RevEcoR::KosarajuSCC(t)
?graphs.dfs
??graphs.dfs
metabolic.data <- getOrgMetabolicData("buc")
metabolic.data <-RevEcoR::getOrgMetabolicData("buc")
net <- reconstructGsMN(metabolic.data)
metabolic.data <-RevEcoR::getOrgMetabolicData("buc")
install.packages("RevEcoR")
SCC <- RevEcoR::KosarajuSCC(t)
devtools::load_all(".")
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes")
m
library(ssifs)
#install.packages("devtools")
#devtools::install_github("georgiosseitidis\\ssifs")
library(ssifs)
data("Alcohol", package = "ssifs")
TE <- Alcohol$TE
seTE <- Alcohol$seTE
study <- Alcohol$studyid
treat1 <- Alcohol$treat1
treat2 <- Alcohol$treat2
set.seed(10)
m <- ssifs(TE = TE, seTE = seTE, studlab = study, treat1 = treat1, treat2 = treat2, ref = "AO-CT")
m$Posterior_inclusion_probabilities
m$Posterior_Odds
m$Posterior_Odds
head(m$Posterior_Odds)
0.03/0.72
0.72/0.03
devtools::load_all(".")
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes")
studlab <- Alcohol$studyid
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes")
devtools::load_all(".")
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes")
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes", rpcons = T)
m$Posterior_inclusion_probabilities
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes", rpcons = F)
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes", rpcons = 2)
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes", rpcons = 1)
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes", rpcons = F, pcons = 2)
m <- ssifs(TE, seTE, treat1, treat2, studlab, ref = "AO-CT", method = "LuAdes", rpcons = F, pcons = 1)
m$Posterior_inclusion_probabilities
0.72/0.03
devtools::load_all(".")
library(ssifs)
0.7991/0.0210
m$Global
m$Global
m$Posterior_Odds
m$Posterior_inclusion_probabilities
library(ssifs)
devtools::document()
library(ssifs)
0.7967/0.0196
0.7967/0.0199
0.7967/0.0199
0.7943/0.0194
#install.packages("devtools")
#devtools::install_github("georgiosseitidis\\ssifs")
set.seed(12)
m <- ssifs(TE = TE, seTE = seTE, studlab = study, treat1 = treat1, treat2 = treat2, ref = "AO-CT")
m$Posterior_inclusion_probabilities
m$Posterior_Odds
0.7943/0.0194
View(m$Posterior_Odds)
sum(m$Posterior_Odds$Freq)
63543/80000
1549/80000
0.7942875/0.0193625
m$Posterior_inclusion_probabilities
library(ssifs)
#install.packages("devtools")
#devtools::install_github("georgiosseitidis\\ssifs")
library(ssifs)
library(ssifs)
data("Alcohol", package = "ssifs")
force(Alcohol)
View(Alcohol)
table(Alcohol)
table(Alcohol$studyid)
names(table(Alcohol$studyid))
unique(names(table(Alcohol$studyid)))
length(unique(names(table(Alcohol$studyid))))
63543/80000
1549/80000
0.7942875/0.0193625
round((0.7942875/0.0193625,4)
round(0.7942875/0.0193625,4)
spike.slab(m)
TE <- Alcohol$TE
seTE <- Alcohol$seTE
study <- Alcohol$studyid
treat1 <- Alcohol$treat1
treat2 <- Alcohol$treat2
m <- ssifs(TE = TE, seTE = seTE, studlab = study, treat1 = treat1, treat2 = treat2, ref = "AO-CT")
spike.slab(m)
m$Posterior_inclusion_probabilities$Comparison
which(!m$Posterior_inclusion_probabilities$Comparison == m$Posterior_inclusion_probabilities$Design)
m$Posterior_inclusion_probabilities
paste0(m$Posterior_inclusion_probabilities$Comparison, paste0(m$Posterior_inclusion_probabilities$Design, collapse = "_"))
paste0(m$Posterior_inclusion_probabilities$Comparison, paste0(m$Posterior_inclusion_probabilities$Design))
paste0(m$Posterior_inclusion_probabilities$Comparison, m$Posterior_inclusion_probabilities$Design, collapse = "_")
paste0(m$Posterior_inclusion_probabilities$Comparison, m$Posterior_inclusion_probabilities$Design)
paste(m$Posterior_inclusion_probabilities$Comparison, m$Posterior_inclusion_probabilities$Design, sep="_")
devtools::load_all(".")
spike.slab(m)
is.na(m$Posterior_inclusion_probabilities$Design)
sum(is.na(x$Posterior_inclusion_probabilities$Design))
sum(is.na(m$Posterior_inclusion_probabilities$Design))
devtools::load_all(".")
spike.slab(m)
library(ssifs)
knitr::write_bib("ssifs", width = 60)
knitr::write_bib()
?rmarkdown::html_vignette
devtools::document()
library(ssifs)
devtools::document()
library(ssifs)
styler::style_pkg()
install.packages("rhub")
rhub::check_for_cran()
rhub::check_for_cran(email = "g.seitidis@uoi.gr")
usethis::use_readme_md()
vignette("ssifs", package = "ssifs")
vignette("An_introduction_to_ssifs", package = "ssifs")
vignette("An_introduction_to_ssifs.Rmd", package = "ssifs")
vignette("An_introduction_to_ssifs.Rmd", package = "ssifs")
citation(package = "ssifs")
file.exists("~/.ssh/id_rsa.pub")
usethis::use_github(private = T, protocol = "htpps")
usethis::use_github(private = T, protocol = "https")
usethis::use_git_remote("origin", url = NULL, overwrite = TRUE)
usethis::use_github(private = T, protocol = "https")
vignette("ssifs", package = "ssifs")
devtools::install_github("georgiosseitidis\\ssifs")
devtools::install_github("georgiosseitidis/ssifs")
vignette(package = "ssifs")
vignette(package = "viscomp")
devtools::install_github("georgiosseitidis/viscomp")
vignette(package = "viscomp")
vignette(package = "viscomp")
library(ssifs)
vignette("ssifs", package = "ssifs")
vignette(package = "ssifs")
vignette(package = "ssifs")
vignette("An_introduction_to_ssifs", package = "ssifs")
?devtools::install_github
devtools::install_github(build_vignettes = T)
devtools::install_github(build_vignettes = T, repo = "georgiosseitidis/ssifs")
browseVignettes("ssifs")
install.packages("pandoc")
library(ssifs)
vignette(package="ssifs")
vignette()
devtools::build_vignettes()
vignette(package ="ssifs")
vignette(package ="ssifs")
vignette(package ="ssifs")
vignette(package ="ssifs")
library(ssifs)
library(ssifs)
library(ssifs)
vignette("ssifs")
vignette(package="ssifs")
devtools::build()
vignette(package = "ssifs")
library(ssifs)
vignette(package = "ssifs")
library(ssifs)
devtools::install(build_vignettes = TRUE)
devtools::install(build_vignettes = TRUE)
vignette("ssifs")
vignette(package = "ssifs")
vignette("An_introduction_to_ssifs" package = "ssifs")
vignette("An_introduction_to_ssifs", package = "ssifs")
usethis::use_news_md()
rhub::check_for_cran()
validate_email(email = "g.seitidis@uoi.gr")
rhub::validate_email(email = "g.seitidis@uoi.gr")
rhub::validate_email(email = "g.seitidis@uoi.gr", token = 8fac4e2c1dc64660ab77f6996ba7a607)
rhub::validate_email(email = "g.seitidis@uoi.gr", token ="8fac4e2c1dc64660ab77f6996ba7a607")
rhub::check_for_cran()
rhub::check(platform = "ubuntu-rchk")
library(ssifs)
styler::style_pkg()
devtools::document()
devtools::check_win_devel()
devtools::check_rhub()
rhub::platforms()
rhub::check_for_cran()
rhub::check_for_cran(platforms ="macos-highsierra-release" )
devtools::document()
devtools::install(build_vignettes = T)
devtools::check_win_devel()
setwd("C:/Users/delse/Drive Uoi/UOI/notes/phd/SSIFS/Datasets/Autism data")
data <- readxl::read_xlsx("Master Dataset clean.xlsx")
data.pair <- netmeta::pairwise(treat = data$treat, studlab = data$StudyID,
mean=data$mean, sd=data$SD, n=data$`N.comp+imputed.for.continuous`,
sm = "MD")
length(unique(data.pair$studlab))
TE= data.pair$TE
seTE = data.pair$seTE
treat1 = data.pair$treat1
treat2 = data.pair$treat2
studlab = data.pair$studlab
ref = "placebo"
treat1 <- as.character(treat1)
treat2 <- as.character(treat2)
ref <- as.character(ref)
studlab <- as.character(studlab)
data <- data.frame(TE = TE, seTE = seTE, studlab = studlab, treat1 = treat1, treat2 = treat2, stringsAsFactors = FALSE)
# Exclude studies with NAs
NAs <- apply(data, 1, FUN = function(x) {
sum(is.na(x))
})
omit_stud <- data$studlab[NAs > 0]
if (length(omit_stud) > 0) {
data <- data[-which(data$studlab %in% omit_stud), ]
}
# Keep the studies that belong to the largest sub-network
cnet <- connet(data)
devtools::load_all("~/ssifs")
# Keep the studies that belong to the largest sub-network
cnet <- connet(data)
if (!ref %in% unlist(cnet$data[, c("treat1", "treat2")])) {
stop("The reference category must a node of the largest sub-network", call. = FALSE)
}
data <- cnet$data
# Check if the data are correctly specified
correct.data(data)
# Make all treatments names numeric values
trt_orig <- unique(c(data$treat1, data$treat2))
trt_trans <- data.frame("from" = trt_orig, "to" = 1:length(trt_orig))
data$treat1 <- plyr::mapvalues(data$treat1, from = trt_trans$from, to = trt_trans$to, warn_missing = FALSE)
data$treat2 <- plyr::mapvalues(data$treat2, from = trt_trans$from, to = trt_trans$to, warn_missing = FALSE)
ref <- plyr::mapvalues(ref, from = trt_trans$from, to = trt_trans$to, warn_missing = FALSE)
# NMA MCMC model requires multi-arm studies to be at the end of the dataframe
Multiarm_studies <- labels(which(table(data$studlab) >= 3))
if (length(Multiarm_studies) > 0) {
data_multi <- data[which(data$studlab %in% Multiarm_studies), ]
data <- rbind(data[-which(data$studlab %in% Multiarm_studies), ], data_multi[order(data_multi$studlab), ])
}
LA <- LuAdes(data, ref, Multiarm_studies)
cl <- cloop(data)
# Network's geometry
data_2 <- unique(data.frame("treat1" = data$treat1, "treat2" = data$treat2))
tt <- igraph::graph.data.frame(data_2, directed = F)
tt
# A list with the closed loops of the network
S <- list()
for (i in 1:length(igraph::V(tt))) {
SP <- SP2 <- NULL
# All possible paths that start and end in the node V(tt)[i]
SP <- igraph::all_simple_paths(tt, from = igraph::V(tt)[i], to = igraph::neighbors(tt, v = igraph::V(tt)[i]))
# length SP>1 because if a node is only compared with one other node it stops
if (!is.null(unlist(SP)) & length(SP) > 1) {
# Exclude the paths that have length <=2 since they are not closed loops.
SP2 <- SP[sapply(SP, function(p) length(p) > 2)]
# Make the igraph object to character
if (length(SP2) != 0) { # star networks
S[[i]] <- lapply(SP2, names)
}
}
}
devtools::document()