Skip to content

Commit

Permalink
added adjust_ceiling option for Ruscio's A
Browse files Browse the repository at this point in the history
This sets a limit on the min max of A other than 0 or 1. by recoding a pair of data points. This allows for the probability to converted to finite odds values using a non arbitrary rescoring that scales with the availability of data.
  • Loading branch information
ianhussey committed Apr 23, 2019
1 parent 5736126 commit f8e5d46
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
11 changes: 10 additions & 1 deletion R/ruscios_A_boot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,14 +21,22 @@
#'

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) {
nx <- length(x)
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)
}

Expand Down
8 changes: 5 additions & 3 deletions R/sced_analysis.r
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion man/ruscios_A_boot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions man/sced_analysis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8e5d46

Please sign in to comment.