addNoise: Add Noise

View source: R/addNoise.R

addNoiseR Documentation

Add Noise

Description

Add noise to time series.

Usage

addNoise(x, input.folder = "", output.folder = "", expIds = c(),
  add = FALSE, seqdepths = c(), vary.seqdepth = FALSE,
  scaling.factor = 1, noise.distrib = "pois", param1 = 1,
  param2 = 1, scale.noise = 1)

Arguments

x

matrix with taxa as rows and time points as columns (optional, can be set to NULL if an input.folder is provided)

input.folder

folder from which to read time series (optional, input folder should have subfolders as generated by function generateTS.R)

output.folder

folder to which modified time series are written (optional)

expIds

set of experiment identifiers to process (only needed if input.folder is provided)

add

whether to sample the abundance value from the noise distribution (the default) or whether to add noise, where the noise value is sampled from the noise distribution with user-specified parameters (add is not possible for noise.distrib = multi)

seqdepths

specify a vector of sequencing depths with as many entries as x has columns or a single value if sequencing depth should be constant (only needed for noise.distrib = multi)

vary.seqdepth

if a constant sequencing depth is provided: vary sequencing depth by adding a value randomly selected from the uniform distribution between 0 and seqdepths/2 (only applicable for noise.distrib = multi)

scaling.factor

if unequal to one: scale observed values with the given scaling factor and round (rounding will convert non-count data into counts, recommended for Poisson and negative binomial distribution)

noise.distrib

which noise distribution to use (pois = Poisson, the default, nb = negative binomial, norm = Gaussian, multi = multinomial)

param1

first parameter for noise distribution (when add is false: standard deviation for Gaussian distribution, success probability for negative binomial, when add is true: mean for Gaussian distribution, lambda for Poisson, size for negative binomial)

param2

second parameter for noise distribution (only when add is true: standard deviation for Gaussian distribution, success probability for negative binomial)

scale.noise

divide noise value by scale.noise before adding it to the observed value (only when add is true)

Details

Noise is either generated by setting a noise parameter to the observed value and sampling a new value from this noise distribution (add=FALSE) or by sampling the selected noise distribution with user-provided parameters and adding the noise value to each time point independently (add=TRUE). When choosing to add Gaussian noise and the resulting value is negative, it will be set to zero. When generating modified values with the negative binomial and add set to false, the resulting value is added to the observed value. It is not recommended to enable add when using the Poisson or negative binomial distribution.

Value

if x is provided without an output.folder, the modified matrix is returned; if input.folder is provided without an output folder, the last processed experiment identifier is returned

Examples

## Not run: 
  N <- 50
  metapop <- generateAbundances(N=500, mode=5, probabs=TRUE)
  ts <- simHubbell(N=N, M=500,I=1500,d=N, m.vector=metapop, tskip=500, tend=1000)
  ts.noisy <- addNoise(ts)
 
## End(Not run)

hallucigenia-sparsa/seqtime documentation built on Jan. 9, 2023, 11:53 p.m.