Learn R Programming

DiscreteFDR (version 2.1.0)

generate.pvalues: Generation of P-Values and Their Supports After Data Transformations

Description

Simple wrapper for generating p-values of discrete tests and their supports after preprocessing the input data. The user only has to provide 1.) a function that generates p-values and supports and 2.) an optional function that preprocesses (i.e. transforms) the input data (if necessary) before it can be used for p-value calculations. The respective arguments are provided

Usage

generate.pvalues(
  dat,
  test.fun,
  test.args = NULL,
  preprocess.fun = NULL,
  preprocess.args = NULL
)

Value

A DiscreteTestResults R6 class object.

Arguments

dat

input data; must be suitable for the first parameter of the provided preprocess.fun function or, if preprocess.fun is NULL, for the first parameter of the test.fun function.

test.fun

function from package DiscreteTests, i.e. one whose name ends with *_test_pv and which performs hypothesis tests and provides an object with \(p\)-values and their support sets; can be specified by a single character string (which is automatically checked for being a suitable function from that package and may be abbreviated) or a single function object.

test.args

optional named list with arguments for test.fun; the names of the list fields must match the test function's parameter names. The first parameter of the test function (i.e. the data) MUST NOT be included!

preprocess.fun

optional function for pre-processing the input data; its result must be suitable for the first parameter of the test.fun function.

preprocess.args

optional named list with arguments for preprocess.fun; the names of the list fields must match the pre-processing function's parameter names. The first parameter of the test function (i.e. the data) MUST NOT be included!

Examples

Run this code
X1 <- c(4, 2, 2, 14, 6, 9, 4, 0, 1)
X2 <- c(0, 0, 1, 3, 2, 1, 2, 2, 2)
N1 <- rep(148, 9)
N2 <- rep(132, 9)
Y1 <- N1 - X1
Y2 <- N2 - X2
df <- data.frame(X1, Y1, X2, Y2)
df

# Compute p-values and their supports of Fisher's exact test
test.result <- generate.pvalues(df, "fisher")
raw.pvalues <- test.result$get_pvalues()
pCDFlist <- test.result$get_pvalue_supports()

# Compute p-values and their supports of Fisher's exact test 
# with preprocessing
df2 <- data.frame(X1, N1, X2, N2)
generate.pvalues(
  dat = df2,
  test.fun = "fisher_test_pv",
  preprocess.fun = function(tab) {
    for(col in c(2, 4)) tab[, col] <- tab[, col] - tab[, col - 1]
    return(tab)
  }
)

# Compute p-values and their supports of a binomial test with preprocessing
generate.pvalues(
  dat = rbind(c(5, 2, 7), c(3, 4, 0)), 
  test.fun = "binom_test_pv",
  test.args = list(n = c(9, 8, 11), p = 0.6, alternative = "two.sided"),
  preprocess.fun = colSums
)

Run the code above in your browser using DataLab