Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ README.md
^docs$
^pkgdown$
^codecov\.yml$
inst/shiny-examples/SCD-effect-sizes/rsconnect
inst/shiny-examples/SCD-effect-sizes/rsconnect/shinyapps.io/jepusto/SCD-effect-sizes.dcf
^CRAN-SUBMISSION$
^init.R$
^run.R$
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Authors@R: c(
person(c("James","E."), "Pustejovsky", email = "jepusto@gmail.com", role = c("aut", "cre")),
person("Man", "Chen", email = "manchen9005@gmail.com", role = "aut"),
person(c("Daniel","M."), "Swan", email = "dms031000@gmail.com", role = "aut"),
person("Paulina", "Grekov", email = "grekov.paulina@gmail.com", role = "ctb"),
person("Amy", "Cai", email = "amycai2023@gmail.com", role = "ctb")
person("Paulina", "Grekov", email = "grekov.paulina@gmail.com", role = "ctb")
)
Description:
Provides R functions for calculating basic effect size indices for
Expand All @@ -20,8 +19,6 @@ Description:
URL: https://jepusto.github.io/SingleCaseES/
BugReports: https://github.com/jepusto/SingleCaseES/issues
License: GPL-3
Depends:
R (>= 4.1.0)
Imports:
stats,
purrr,
Expand All @@ -36,6 +33,7 @@ Suggests:
shinytest2 (>= 0.5.0),
stringr,
rvest,
xml2,
ggplot2,
purrrlyr,
testthat,
Expand Down
105 changes: 65 additions & 40 deletions R/calculate-effect-sizes.R
Original file line number Diff line number Diff line change
Expand Up @@ -456,46 +456,62 @@ batch_calc_ES <- function(dat,
if (utils::packageVersion("dplyr") >= '1.1.0') {
dat |>
dplyr::group_by(!!!rlang::syms(c(grouping, aggregate))) |>
dplyr::reframe(
calc_ES(
condition = .data[[condition]],
outcome = .data[[outcome]],
baseline_phase = baseline_phase,
intervention_phase = intervention_phase,
ES = ES_names,
improvement = .data[[improvement]],
scale = .data[[scale]],
intervals = .data[[intervals]],
observation_length = .data[[observation_length]],
goal = if ("PoGO" %in% ES_names) .data[[goal]] else NULL,
confidence = confidence,
format = "long",
...,
warn = warn
dplyr::reframe(
tryCatch(
calc_ES(
condition = .data[[condition]],
outcome = .data[[outcome]],
baseline_phase = baseline_phase,
intervention_phase = intervention_phase,
ES = ES_names,
improvement = .data[[improvement]],
scale = .data[[scale]],
intervals = .data[[intervals]],
observation_length = .data[[observation_length]],
goal = if ("PoGO" %in% ES_names) .data[[goal]] else NULL,
confidence = confidence,
format = "long",
...,
warn = warn
),
error = function(e) {
stop(
paste0("Effect size calculation failed: ", conditionMessage(e)),
call. = FALSE
)
}
)
)
)
} else {
dat |>
dplyr::group_by(!!!rlang::syms(c(grouping, aggregate))) |>
dplyr::summarise(
calc_ES(
condition = .data[[condition]],
outcome = .data[[outcome]],
baseline_phase = baseline_phase,
intervention_phase = intervention_phase,
ES = ES_names,
improvement = .data[[improvement]],
scale = .data[[scale]],
intervals = .data[[intervals]],
observation_length = .data[[observation_length]],
goal = if ("PoGO" %in% ES_names) .data[[goal]] else NULL,
confidence = confidence,
format = "long",
...,
warn = warn
),
.groups = "drop"
)
dplyr::group_by(!!!rlang::syms(c(grouping, aggregate))) |>
dplyr::summarise(
tryCatch(
calc_ES(
condition = .data[[condition]],
outcome = .data[[outcome]],
baseline_phase = baseline_phase,
intervention_phase = intervention_phase,
ES = ES_names,
improvement = .data[[improvement]],
scale = .data[[scale]],
intervals = .data[[intervals]],
observation_length = .data[[observation_length]],
goal = if ("PoGO" %in% ES_names) .data[[goal]] else NULL,
confidence = confidence,
format = "long",
...,
warn = warn
),
error = function(e) {
stop(
paste0("Effect size calculation failed: ", conditionMessage(e)),
call. = FALSE
)
}
),
.groups = "drop"
)
}

ES_long_names <- names(ES_ests_long)
Expand Down Expand Up @@ -548,15 +564,24 @@ 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(
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 |>
Expand Down
Loading
Loading