R/RcppExports.R

Defines functions dwell_time_ interleaved_preference interleaved_confint interleaved_bootstraps exact_binom

Documented in exact_binom interleaved_bootstraps interleaved_confint interleaved_preference

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' @title Sample size for exact, one sample binomial test
#' @description Estimates sample size required to detect difference from a
#'   constant proportion.
#' @param constant_prop The proportion under the null hypothesis.
#' @param effect_size Positive size of the difference between your null
#'   hypothesis and the alternative hypothesis that you hope to detect.
#'   **Heads-up** that values less than 1% might take a while to calculate.
#' @param alpha Probability of rejecting the null hypothesis even though it is
#'   true.
#' @param power Probability of rejecting the null hypothesis (getting a
#'   significant result) when the real difference is equal to the minimum
#'   effect size.
#' @param two_tail Whether to perform two-tail or one-tail power analysis.
#'   `TRUE` (default) tests in both directions of difference.
#' @examples
#' exact_binom(0.75, 0.03)
#' @references [Power analysis](http://www.biostathandbook.com/power.html) and
#'   [Exact test of goodness-of-fit](http://www.biostathandbook.com/exactgof.html) from
#'   John H. McDonald's [_Handbook of Biological Statistics_](http://www.biostathandbook.com/)
#' @export
exact_binom <- function(constant_prop, effect_size, alpha = 0.05, power = 0.8, two_tail = TRUE) {
    .Call('_wmfastr_exact_binom', PACKAGE = 'wmfastr', constant_prop, effect_size, alpha, power, two_tail)
}

#' @param bootstraps number of times to sample unique sessions
#'   (with replacement); 1000 by default
#' @examples
#' data("interleaved_data", package = "wmf")
#' x <- interleaved_data[interleaved_data$event == "click", ]
#' x <- x[order(x$session_id, x$timestamp), ]
#' data("interleaved_data_a", package = "wmf")
#' y <- interleaved_data_a[interleaved_data_a$event == "click", ]
#' y <- y[order(y$session_id, y$timestamp), ]
#' data("interleaved_data_b", package = "wmf")
#' z <- interleaved_data_b[interleaved_data_b$event == "click", ]
#' z <- z[order(z$session_id, z$timestamp), ]
#'
#' # Bootstrapped preference statistics:
#'
#' ## Data without a clear preference:
#' b <- interleaved_bootstraps(x$session_id, x$ranking_function)
#' hist(b)
#'
#' ## Data where A is preferred over B:
#' b <- interleaved_bootstraps(y$session_id, y$ranking_function)
#' hist(b)
#'
#' ## Data where B is preferred over A:
#' b <- interleaved_bootstraps(z$session_id, z$ranking_function)
#' hist(b)
#' @rdname interleaved
#' @export
interleaved_bootstraps <- function(sessions, clicks, bootstraps = 1000L) {
    .Call('_wmfastr_interleaved_bootstraps', PACKAGE = 'wmfastr', sessions, clicks, bootstraps)
}

#' @param confidence level; 0.95 by default
#' @examples
#'
#' # Preference statistic confidence intervals:
#'
#' ## Data without a clear preference:
#' interleaved_confint(x$session_id, x$ranking_function)
#'
#' ## Data where A is preferred over B:
#' interleaved_confint(y$session_id, y$ranking_function)
#'
#' ## Data where B is preferred over A:
#' interleaved_confint(z$session_id, z$ranking_function)
#' @rdname interleaved
#' @export
interleaved_confint <- function(sessions, clicks, bootstraps = 1000L, confidence = 0.95) {
    .Call('_wmfastr_interleaved_confint', PACKAGE = 'wmfastr', sessions, clicks, bootstraps, confidence)
}

#' @param sessions vector of session IDs used to group `positions` and
#'   `ranking_functions`
#' @param clicks vector that shows which ranking function the
#'   clicked search result came from ("A" or "B")
#' @examples
#'
#' # Preference statistic calculation:
#'
#' ## Data without a clear preference:
#' interleaved_preference(x$session_id, x$ranking_function)
#'
#' ## Data where A is preferred over B:
#' interleaved_preference(y$session_id, y$ranking_function)
#'
#' ## Data where B is preferred over A:
#' interleaved_preference(z$session_id, z$ranking_function)
#' @rdname interleaved
#' @export
interleaved_preference <- function(sessions, clicks) {
    .Call('_wmfastr_interleaved_preference', PACKAGE = 'wmfastr', sessions, clicks)
}

dwell_time_ <- function(timestamps) {
    .Call('_wmfastr_dwell_time_', PACKAGE = 'wmfastr', timestamps)
}
wikimedia/wikimedia-discovery-ortiz documentation built on Aug. 23, 2020, 9:46 a.m.