diff --git a/util/util.R b/util/util.R index d55b352..523492f 100644 --- a/util/util.R +++ b/util/util.R @@ -1114,7 +1114,7 @@ check_moderator_levels <- function(df, experiment, outcome) { return(x) # Return the formatted string } -run_sse_SMD <- function(df, rho_value = 0.5) { +run_sse_SMD_L <- function(df, rho_value = 0.5) { # df<-filter_experiment_outcome_type(df, experiment, outcome) @@ -1149,7 +1149,42 @@ run_sse_SMD <- function(df, rho_value = 0.5) { return(SMD_sse) } -run_sse_plot_SMD <- function(df, rho_value = 0.5) { +run_sse_SMD_C <- function(df, rho_value = 0.5) { + + # df<-filter_experiment_outcome_type(df, experiment, outcome) + + df<-df %>% + filter(!is.na(SMDv)) %>% + filter(outcome_type == "Cognition") %>% + filter(SortLabel == "TvC") + + df <- df %>% mutate(effect_id = row_number()) # add effect_id column + df$SMDN <- 1/sqrt(as.numeric(df$NumberOfAnimals_C) + as.numeric(df$NumberOfAnimals_I)) + + #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 = df, + rho = rho_value) + + SMD_sse <- rma.mv(yi = SMD, + V = VCVM_SMD, + random = ~1 | Strain / StudyId / ExperimentID_I, # nested levels + mods = ~ SMDN, # sampling error (squart root of N); + test = "t", # use t- and F-tests for making inferences + data = df, + dfs="contain", + control=list(optimizer="nlm") + ) + + return(SMD_sse) +} + +run_sse_plot_SMD_L <- function(df, rho_value = 0.5) { # df<-filter_experiment_outcome_type(df, experiment, outcome) @@ -1185,6 +1220,41 @@ run_sse_plot_SMD <- function(df, rho_value = 0.5) { return(plot) } +run_sse_plot_SMD_C <- function(df, rho_value = 0.5) { + + # df<-filter_experiment_outcome_type(df, experiment, outcome) + + df<-df %>% + filter(!is.na(SMDv)) %>% + filter(outcome_type == "Cognition") %>% + filter(SortLabel == "TvC") + + df <- df %>% mutate(effect_id = row_number()) # add effect_id column + df$SMDN <- 1/sqrt(as.numeric(df$NumberOfAnimals_C) + as.numeric(df$NumberOfAnimals_I)) + + #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 = df, + rho = rho_value) + + SMD_sse <- rma.mv(yi = SMD, + V = VCVM_SMD, + random = ~1 | Strain / StudyId / ExperimentID_I, # nested levels + mods = ~ SMDN, # sampling error (squart root of N); + test = "t", # use t- and F-tests for making inferences + data = df, + dfs="contain", + control=list(optimizer="nlm") + ) + + plot <- bubble_plot(SMD_sse, mod = "SMDN", group = "StudyId", xlab = "1/SQRT(N) associated with SMD estimate", ylab = "SMD estimate", legend.pos = "none") + return(plot) +} subgroup_SMD <- function(df, experiment_type, outcome, moderator, rho_value) { # with intercept, to allow calculation of effect of moderators - returns intercept # as beta-coefficient for first category, and beta coefficients for other categories