radjust: Calculate rate ratios restricted by confidence level

View source: R/CSSA.R

radjustR Documentation

Calculate rate ratios restricted by confidence level

Description

radjust is designed to calculate rate ratios of sequencing results. It uses the binomial distribution to calculate confidence intervals of rate ratios (and the normal approximation for large counts), and returns the log2-transformed confidence limit that is closest to 0.

Usage

radjust(
  t1,
  t0,
  conf.level = 0.8,
  normfun = "sum",
  normsubset,
  log = 2,
  belowxreads = 300
)

Arguments

t1

Integer vector or matrix. Raw sequencing reads in test sample

t0

Integer vector or matrix. Raw sequencing reads in control sample

conf.level

Numeric. Sets the confidence level of the rate ratio. If FALSE, an unadjusted rate ratio will be returned. Default = 0.8

normfun

Character string. Specify with which function to standardize the data. Default = "sum"

normsubset

Integer vector. Specify the indices of features that are to be used in standardization

log

Logical or numeric. Specify whether to log-transform the rate ratio, and with what base. If TRUE, uses natural logarithm. Default = 2

belowxreads

Logical or numeric. Set threshold above which the confidence limit is approximated. Default = 300

Details

The core of this function utilizes the poisson.test function from the stats package, with x = c(t1, t0) and T = c(sumreads1, sumreads0). Above the belowxreads cutoff, the confidence interval is approximated as logr +/- Z*sqrt(1/t1 + 1/t0). Here logr is the log-transformed rate ratio and Z is the number of standard units corresponding with the chosen confidence interval. If conf.level is not FALSE, the (log-transformed) confidence limit closest to 0 is returned. If the log-transformed upper and lower limit have opposite signs, i.e. the null hypothesis lies within the confidence interval, 0 is returned. If the function is performed on matrices for t0 and t1, then columns of t0 and t1 are expected to be paired. See rrep for unpaired data.

Value

Returns the (log2-transformed) adjusted rate ratio.

Note

If conf.level is set to 0, it will be interpreted as FALSE. This is intended, as radjust will then return an unadjusted rate ratio estimate, instead of giving an error.

Author(s)

Jos B. Poell

See Also

rrep, nestedradjust, getdeg,oddscores, ess, noness

Examples

ut <- CRISPRsim(200, 4, a = c(3,3), allseed = 1, perfectseq = TRUE)
tr <- CRISPRsim(200, 4, a = c(3,3), e = TRUE, allseed = 1, perfectseq = TRUE)
cgi <- tr$d > -0.05 & tr$d < 0.05 & tr$e > -0.05 & tr$e < 0.05
r0 <- radjust(ut$t3, ut$t0, belowxreads = 300, normsubset = cgi)
r1 <- radjust(tr$t3, ut$t3, belowxreads = 300, normsubset = cgi)
hcr0 <- radjust(ut$t3, ut$t0, conf.level = 0.8, normsubset = cgi)
hcr1 <- radjust(tr$t3, ut$t3, conf.level = 0.8, normsubset = cgi)
plot(r0, hcr0)
abline(0, 1)
plot(r1, hcr1)
abline(0, 1)


tgac-vumc/CSSA documentation built on Oct. 10, 2022, 7:27 p.m.