Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions R/calculate-effect-sizes.R
Original file line number Diff line number Diff line change
Expand Up @@ -548,20 +548,30 @@ batch_calc_ES <- function(dat,
n_weights <-
dat |>
dplyr::filter(!!rlang::sym(condition) %in% c(baseline_phase, intervention_phase)) |>
dplyr::mutate(!!rlang::sym(condition) := ifelse(!!rlang::sym(condition) == baseline_phase, "A", "B")) |>
dplyr::mutate(
!!rlang::sym(condition) := ifelse(
!!rlang::sym(condition) == baseline_phase,
"A",
"B"
)
) |>
dplyr::group_by(!!!rlang::syms(c(grouping, aggregate, condition))) |>
dplyr::summarise(n = dplyr::n(), .groups = "drop") |>
tidyr::pivot_wider(names_from = !!rlang::sym(condition), values_from = n) |>
tidyr::pivot_wider(
names_from = !!rlang::sym(condition),
values_from = n
) |>
dplyr::ungroup() |>
dplyr::mutate(
A = ifelse(is.na(A), 0, A),
B = ifelse(is.na(B), 0, B),
weights = calc_ES_weights(weighting, A = A, B = B)
) |>
dplyr::select(-c(A,B))
dplyr::select(-dplyr::any_of(c("A", "B")))

ES_weights <-
ES_ests_long |>
dplyr::left_join(n_weights, by = c(grouping, aggregate))

}

# Aggregate
Expand Down Expand Up @@ -611,18 +621,21 @@ batch_calc_ES <- function(dat,

}

calc_ES_weights <- function(weighting, A, B) {

if (weighting %in% c("nA", "n_A")) {
as.numeric(A)
} else if (weighting %in% c("nB", "n_B")) {
as.numeric(B)
} else if (weighting %in% c("nAnB", "nA*nB", "nA * nB", "n_A*n_B", "n_A * n_B")) {
as.numeric(A*B)
} else if (weighting %in% c("1/nA+1/nB", "1/nA + 1/nB", "1/n_A+1/n_B", "1/n_A + 1/n_B")) {
as.numeric(1/A + 1/B)
} else {
NULL
}

}
calc_ES_weights <- function(weighting, A, B) {

if (weighting %in% c("nA", "n_A")) {
return(as.numeric(A))

} else if (weighting %in% c("nB", "n_B")) {
return(as.numeric(B))

} else if (weighting %in% c("nAnB", "nA*nB", "nA * nB", "n_A*n_B", "n_A * n_B")) {
return(as.numeric(A * B))

} else if (weighting %in% c("1/nA+1/nB", "1/nA + 1/nB", "1/n_A+1/n_B", "1/n_A + 1/n_B")) {
return(as.numeric(1 / A + 1 / B))

} else {
stop("Unsupported weighting argument in calc_ES_weights().")
}
}
Loading
Loading