Skip to content

Commit

Permalink
170102
Browse files Browse the repository at this point in the history
  • Loading branch information
maclomaclee committed Jan 17, 2024
1 parent 449398c commit dae5313
Showing 1 changed file with 72 additions and 2 deletions.
74 changes: 72 additions & 2 deletions util/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dae5313

Please sign in to comment.