Skip to content

Commit

Permalink
130102
Browse files Browse the repository at this point in the history
  • Loading branch information
maclomaclee committed Jan 13, 2024
1 parent 86314d3 commit a8bacec
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
64 changes: 61 additions & 3 deletions util/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ forest_subgroup <- function(modelsumm, moderator, outcome, moderator_text) {

axis_min <- min(floor(min(model$ci_l, model$ci_u)),-1)
axis_max <- max(ceiling(max(model$ci_l, model$ci_u)),1)
span2 <- 2 + (axis_max - axis_min)
span1 <- span2 * 0.7
span2 <- 1 + (axis_max - axis_min)
span1 <- span2 * 0.8
span3 <- span2 * 0.5
r1 <- span1
l2 <- span1 + 1
Expand Down Expand Up @@ -1177,6 +1177,7 @@ run_sse_plot_SMD <- function(df, rho_value = 0.5) {
return(plot)
}

###with intercept, to allow calculation of effect of moderators - returns intercept as B0 for first category, b1 for other categories against intercept
subgroup_SMD <- function(df, experiment_type, outcome, moderator, rho_value) {

# Ensure the moderator is a character string for later conversion to symbol
Expand Down Expand Up @@ -1224,13 +1225,70 @@ subgroup_SMD <- function(df, experiment_type, outcome, moderator, rho_value) {
V = VCVM_SMD,
random = ~1 | Strain / StudyId / ExperimentID_I,
data = df2,
mods = as.formula(paste("~", moderator, "-1")),
mods = as.formula(paste("~", moderator)), #"-1")),
method = 'REML',
test = "t",
dfs = "contain"
)
return(subgroup_analysis)
} }

subgroup_SMDI <- function(df, experiment_type, outcome, moderator, rho_value) {
# this gives beta co-efficients for every moderator variable compared with no effect;
# so is used to report these and their 95% CIs, but not whether or not the effects of
# moderators is significant - for which we use subgroup_SMD, which includes an
# intercept in the model
# Ensure the moderator is a character string for later conversion to symbol
moderator <- as.character(moderator)

df2 <- df %>%
filter(SortLabel == experiment_type) %>%
filter(outcome_type == outcome) %>%
filter(!is.na(SMDv)) %>%
filter(!is.na(!!sym(moderator))) # Filter out NA values in moderator column

# Convert character to factor if necessary
if (is.character(df2[[moderator]])) {
df2[[moderator]] <- factor(df2[[moderator]])}

# Add a check for the number of levels in the moderator variable
if (length(levels(df2[[moderator]])) <= 1) {
message("In this iteration of the review, there was insufficient data to perform subgroup analysis for this variable (data for one subgroup only)")
return(NULL)
}

if ((n_distinct(df$StudyId) > 2) & (n_distinct(df$ExperimentID_I) >10)) {
#df2$RoBScore <- as.numeric(df2$RoBScore)
#df2$RoBScore <- factor(df2$RoBScore, levels = c(0, 1, 2))


#df2<-df2 %>%
#filter(SMD>-6) %>%
#filter(SMD<6) # delete missing values and some weirdly large values, like -15 and 16

df2 <- df2 %>% mutate(effect_id = row_number()) # add effect_id column

#calculate variance-covariance matrix of the sampling errors for dependent effect sizes

VCVM_SMD <- vcalc(vi = SMDv,
cluster = StudyId,
subgroup= ExperimentID_I,
obs=effect_id,
data = df2,
rho = rho_value)

# ML model on df2 with subgroup
subgroup_analysis <- rma.mv(
yi = SMD,
V = VCVM_SMD,
random = ~1 | Strain / StudyId / ExperimentID_I,
data = df2,
mods = as.formula(paste("~", moderator, "-1")),
method = 'REML',
test = "t",
dfs = "contain"
)
return(subgroup_analysis)
} }


2 changes: 1 addition & 1 deletion wrangling/data_wrangle_script.R
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ df <- df %>%
# Calculate standardised dose for overall dose-response meta-regression
df <- df %>%
mutate(DoseOfIntervention_mgkg = as.numeric(DoseOfIntervention_mgkg)) %>%
mutate(StandardisedDose = (log(DoseOfIntervention_mgkg))/((MolarMass*1000)*(EC50mM/1000000)))
mutate(StandardisedDose = log((DoseOfIntervention_mgkg/1000)/((MolarMass)*(EC50mM/1000000))))


###### For RoB subgroup analysis ######
Expand Down

0 comments on commit a8bacec

Please sign in to comment.