From 172f77836b054855fc5cbd64910c8158d45565cc Mon Sep 17 00:00:00 2001 From: Chao Cheng Date: Fri, 15 Mar 2024 10:50:13 +0800 Subject: [PATCH] Fix a bug in `decompose.network()` `decompose.network()` failes to run when all studies in `network` are multi-arm trials. That's becauses `filter.network()` call in `decompose.network()` can not successfully construct the non-existing 2-arm trials network in this scenario. This patch adds a check for this scenario and directly construct the network when all studies are multi-arm and filter for 2-arm trials is not necessary. --- gemtc/R/anohe.R | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gemtc/R/anohe.R b/gemtc/R/anohe.R index e73c62bc..d7737f83 100644 --- a/gemtc/R/anohe.R +++ b/gemtc/R/anohe.R @@ -114,7 +114,9 @@ decompose.network <- function(network, result) { data[['study']] <- as.character(data[['study']]) studies <- unique(data[['study']]) studies <- studies[sapply(studies, function(study) { sum(data[['study']] == study) > 2 })] - + # check if all studies are multi-arm + all.multiarm <- length(studies) == length(unique(data[['study']])) + data <- decompose.trials(result) data.re <- do.call(rbind, lapply(studies, function(study) { do.call(rbind, lapply(1:length(data[['m']][[study]]), function(j) { @@ -127,10 +129,15 @@ decompose.network <- function(network, result) { ) })) })) + + if(all.multiarm){ + mtc.network(data.ab = network[['data.ab']], data.re = data.re, treatments = network$treatments) + }else{ + ta.network <- filter.network(network, function(row) { !(row['study'] %in% studies) }) + ta.data.re <- ta.network[['data.re']][ , c('study','treatment','diff','std.err')] + mtc.network(data.ab=ta.network[['data.ab']], data.re=rbind(ta.data.re, data.re), treatments=network$treatments) + } - ta.network <- filter.network(network, function(row) { !(row['study'] %in% studies) }) - ta.data.re <- ta.network[['data.re']][ , c('study','treatment','diff','std.err')] - mtc.network(data.ab=ta.network[['data.ab']], data.re=rbind(ta.data.re, data.re), treatments=network$treatments) } mtc.anohe <- function(network, ...) {