findBgnd: Find Background Value

View source: R/findBgnd.R

findBgndR Documentation

Find Background Value

Description

Find the fluorescent value between negative and positive cells

Usage

findBgnd(x, mult = 3, log = TRUE, crit = 0.1, ratio.limit = 1/10)

Arguments

x

fluorescent values to evaluate

mult

numeric multiplier applied to the standard deviation for a non-bimodal distributions, default value of 3

log

a logical flag to use log-transformed values

crit

the critical p-value between 0 and 1 to distinguish bimodal from non-bimodal populations, default of 0.1

ratio.limit

if the ratio of the first peak height to the second peak height exceeds this value (1/10), the population could be bimodal

Details

The modetest function tests whether the values have a bimodal (or multimodal) distribution. If the p-value from this test is less than the critical value (crit), the background value is considered to be the value at the first "valley" in the kernel density distribution. For such bimodal distributions, the mult parameter is ignored.

If the distribution is not bimodal, the population is assumed to be a mixture of values from a normal distribution of low values and a lognormal (or log) distribution of high values. The maximum of low values is determined from a kernel density estimate and the left half of the distribution is fit to a Gaussian distribution with the fitdistr function. The value returned is the position of the peak + mult times the estimated standard deviation of the fitted distribution.

Because fluorescent values are typically log-transformed before analysis, values are log-transformed by default. This can be turned off with the log parameter. Typically, the parameter mult must be empirically determined for non-bimodal distributions. See the examples for the impact of mult on the return value. Note that with mult = 0, the peak value of a non-bimodal distribution will be returned.

If the distribution is very heavily skewed to the left (mostly dark values), the standard deviation of the distribution will be estimated as 1.35x the interquartile range.

It may be helpful to discard exceptionally low values before finding an estimated background should the estimated background be absurdly low. The code currently discards the upper and lower 1 per cent of values before fitting to a normal (or lognormal) distribution.

Value

For bimodally distributed values, the value at the valley between the two populations. For non-bimodally distributed values, the value of the most abundant value + mult * standard deviation of the estimated distribution.

See Also

getZero

getBgnd

Examples

  dev.new(width = 6, height = 8)
  set.seed(1234)
  par(mfrow = c(2, 1))

  x1 <- c(rlnorm(100), rlnorm(30, 4))
  bg <- findBgnd(x1)
  plot(density(log(x1)), main = "Bimodal ('mult' is ignored)")
  abline(v = log(bg), col = 2) # background limit

  x2 <- c(rlnorm(80), rlnorm(40, 6, sdlog = 5))
  bg <- sapply(0:4, function(m) findBgnd(x2, mult = m))
  plot(density(log(x2)), main = "Non-bimodal")
  abline(v = log(bg), col = 1:5) # background limit
  txt <- expression(mult %*% sd)
  legend("topright", legend = 0:4, title = txt, lty = 1, col = 1:5)


ornelles/virustiter documentation built on Oct. 13, 2024, 7:58 a.m.