diff --git a/R/ruscios_A_boot.R b/R/ruscios_A_boot.R index 6f8da42..3c4724d 100644 --- a/R/ruscios_A_boot.R +++ b/R/ruscios_A_boot.R @@ -10,6 +10,7 @@ #' @param Conf.Level 1 - alpha value (e.g., .95). #' @param seed seed value for reproducability #' @param B Number of boostrapped resamples +#' @param adjust_ceiling Should Ruscio's A estimates of 0 and 1 be adjusted so that they can be converted to finite odds ratios? This is done by rescoring a single data point as being was inferior to a single second data point between the conditions. Ie., it uses the best granularity allowed by the data, as more data points will result in a more extreme possible values of A. #' @return ruscios_A_estimate Ruscio's A. #' @return ruscios_A_se Standard error of bootstrapped Ruscio's A values. #' @return ruscios_A_ci_lwr Lower 95% bootstrapped confidence interval via the BCA method @@ -20,7 +21,8 @@ #' ruscios_A_boot <- function(data, variable, group, value1 = 1, value2 = 0, - B = 2000, Conf.Level = .95, seed = 1) { + B = 2000, Conf.Level = .95, seed = 1, + adjust_ceiling = FALSE) { # Fast calculation of the A statistic ruscios_A_function <- function(x, y) { @@ -28,6 +30,13 @@ ruscios_A_boot <- function(data, variable, group, value1 = 1, value2 = 0, ny <- length(y) rx <- sum(rank(c(x, y))[1:nx]) A = (rx / nx - (nx + 1) / 2) / ny + # if adjust_ceiling == TRUE & A == 0 or 1, rescore it as if a single data point was inferior to a single second data point between conditions. + # Ie., use the lowest granularity allowed by the data for rescoring. More data points will result in a higher adjusted A. + if(adjust_ceiling == TRUE & A == 1){ + A <- ruscios_A_function(c(rep(4, length(x)), 2), c(rep(1, length(y)), 3)) + } else if(adjust_ceiling == TRUE & A == 0){ + A <- 1 - ruscios_A_function(c(rep(4, length(x)), 2), c(rep(1, length(y)), 3)) + } return(A) } diff --git a/R/sced_analysis.r b/R/sced_analysis.r index 303d6a8..4231bc5 100644 --- a/R/sced_analysis.r +++ b/R/sced_analysis.r @@ -4,6 +4,7 @@ #' @param data Experiment data. This must contain columns named "Participant", "Timepoint" (integer), "Score" (numeric; your DV), and "Condition" (must include only "A" and "B" as a string or factor). See the included simulated_data dataset for an example using \code{View(simulated_data)}. #' @param n_boots: number of bootstrapped resamples for Hedges' g and Ruscio's A. N for p value permutation is n_boots*10. #' @param invert_effect_sizes: Effect sizes are reported assuming that scores in timepoint B are expected to be higher than timepoint A (i.e., that the intervention causes scores to increase). If invert_effect_sizes == TRUE then effect sizes are inverted, e.g., if the intervention is expected to causes scores to decrease. +#' @param adjust_probability_ceiling: Should Ruscio's A estimates of 0 and 1 be adjusted so that they can be converted to finite odds ratios? This is done by rescoring a single data point as being was inferior to a single second data point between the conditions. Ie., it uses the best granularity allowed by the data, as more data points will result in a more extreme possible values of A. #' @return Baseline trend: standardized beta OLS regression coefficient for the slope between the timepoint A data points. Treats the timepoints as equally spaced integers (e.g., rather than modelling them as dates). Can be used to exclude participants from consideration in meta analysis, e.g., on the basis that improvements at followup are due to improvement trends at baseline. #' @return Intervention trend: standardized beta OLS regression coefficient for the slope between the timepoint B data points. Treats the timepoints as equally spaced integers (e.g., rather than modelling them as dates). #' @return p: Hypothesis test p value via permutation test. Calculated via Monte-Carlo simulation (10000 runs) rather than brute force. @@ -12,9 +13,9 @@ #' @return hedges_g: Effect size Hedge's g effect size via bootstrapping, a version of Cohen's d that is bias corrected for small sample sizes. Identical range, interpretation and cutoffs as Cohen's d. Included here for familiarity: it's parametric assumtions (equal variances) and sensitivity to equal number of timepoints in A and B make it somewhat unrobust in many SCED contexts. In order to relax the assumption of normality a bootstrapped implemenation is employed. #' @export #' @examples -#' sced_results <- sced_analysis(data = simulated_data) +#' sced_results <- sced_analysis(data = simulated_data, adjust_probability_ceiling = TRUE) -sced_analysis <- function(data, n_boots = 2000, invert_effect_sizes = FALSE) { +sced_analysis <- function(data, n_boots = 2000, invert_effect_sizes = FALSE, adjust_probability_ceiling = TRUE) { require(tidyverse) require(coin) require(effsize) @@ -81,7 +82,8 @@ sced_analysis <- function(data, n_boots = 2000, invert_effect_sizes = FALSE) { data = ., value1 = "B", value2 = "A", - B = n_boots)) %>% + B = n_boots, + adjust_ceiling = adjust_probability_ceiling)) %>% ungroup() # bootstrapped Hedges' g effect size (removes assumption of normality but not equality of variances or equal N per condition) diff --git a/man/ruscios_A_boot.Rd b/man/ruscios_A_boot.Rd index f09451d..43a6217 100644 --- a/man/ruscios_A_boot.Rd +++ b/man/ruscios_A_boot.Rd @@ -5,7 +5,7 @@ \title{Bootstrapped Ruscio's A with 95 percent CIs and standard error} \usage{ ruscios_A_boot(data, variable, group, value1 = 1, value2 = 0, - B = 2000, Conf.Level = 0.95, seed = 1) + B = 2000, Conf.Level = 0.95, seed = 1, adjust_ceiling = FALSE) } \arguments{ \item{data}{data} @@ -23,6 +23,8 @@ ruscios_A_boot(data, variable, group, value1 = 1, value2 = 0, \item{Conf.Level}{1 - alpha value (e.g., .95).} \item{seed}{seed value for reproducability} + +\item{adjust_ceiling}{Should Ruscio's A estimates of 0 and 1 be adjusted so that they can be converted to finite odds ratios? This is done by rescoring a single data point as being was inferior to a single second data point between the conditions. Ie., it uses the best granularity allowed by the data, as more data points will result in a more extreme possible values of A.} } \value{ ruscios_A_estimate Ruscio's A. diff --git a/man/sced_analysis.Rd b/man/sced_analysis.Rd index b87fdcb..7c0278c 100644 --- a/man/sced_analysis.Rd +++ b/man/sced_analysis.Rd @@ -4,7 +4,8 @@ \alias{sced_analysis} \title{Analyse data} \usage{ -sced_analysis(data, n_boots = 2000, invert_effect_sizes = FALSE) +sced_analysis(data, n_boots = 2000, invert_effect_sizes = FALSE, + adjust_probability_ceiling = TRUE) } \arguments{ \item{data}{Experiment data. This must contain columns named "Participant", "Timepoint" (integer), "Score" (numeric; your DV), and "Condition" (must include only "A" and "B" as a string or factor). See the included simulated_data dataset for an example using \code{View(simulated_data)}.} @@ -12,6 +13,8 @@ sced_analysis(data, n_boots = 2000, invert_effect_sizes = FALSE) \item{n_boots:}{number of bootstrapped resamples for Hedges' g and Ruscio's A. N for p value permutation is n_boots*10.} \item{invert_effect_sizes:}{Effect sizes are reported assuming that scores in timepoint B are expected to be higher than timepoint A (i.e., that the intervention causes scores to increase). If invert_effect_sizes == TRUE then effect sizes are inverted, e.g., if the intervention is expected to causes scores to decrease.} + +\item{adjust_probability_ceiling:}{Should Ruscio's A estimates of 0 and 1 be adjusted so that they can be converted to finite odds ratios? This is done by rescoring a single data point as being was inferior to a single second data point between the conditions. Ie., it uses the best granularity allowed by the data, as more data points will result in a more extreme possible values of A.} } \value{ Baseline trend: standardized beta OLS regression coefficient for the slope between the timepoint A data points. Treats the timepoints as equally spaced integers (e.g., rather than modelling them as dates). Can be used to exclude participants from consideration in meta analysis, e.g., on the basis that improvements at followup are due to improvement trends at baseline. @@ -30,5 +33,5 @@ hedges_g: Effect size Hedge's g effect size via bootstrapping, a version of Cohe Analyse data from an AB design SCED experiment using non-parametric frequentist tests } \examples{ -sced_results <- sced_analysis(data = simulated_data) +sced_results <- sced_analysis(data = simulated_data, adjust_probability_ceiling = TRUE) }