Description Usage Arguments Details Value Author(s) Examples
Extract chunks from a DataFrame and get the Fstatistics on the rows of
data
, comparing the models mod
(alternative) and mod0
(null).
1 2 3 4 5 6 7 8 9 10 
index 
An index (logical Rle is the best for saving memory) indicating which rows of the DataFrame to use. 
data 
The DataFrame containing the coverage information. Normally
stored in 
mod 
The design matrix for the alternative model. Should be m by p where p is the number of covariates (normally also including the intercept). 
mod0 
The design matrix for the null model. Should be m by p_0. 
adjustF 
A single value to adjust that is added in the denominator of the Fstat calculation. Useful when the Residual Sum of Squares of the alternative model is very small. 
lowMemDir 
The directory where the processed chunks are saved when
using 
method 
Has to be either 'Matrix' (default), 'Rle' or 'regular'. See details. 
scalefac 
The scaling factor used in

If lowMemDir
is specified then index
is expected to
specify the chunk number.
fstats.apply has three different implemenations which are controlled
by the method
parameter. method='regular'
coerces the data to
a standard 'matrix' object. method='Matrix'
coerces the data to a
sparseMatrix which reduces the required memory. This method
is only usable when the projection matrices have row sums equal to 0. Note
that these row sums are not exactly 0 due to how the computer works, thus
leading to very small numerical differences in the Fstatistics calculated
versus method='regular'
. Finally, method='Rle'
calculates the
Fstatistics using the Rle compressed data without coercing it to other
types of objects, thus using less memory that the other methods. However,
it's speed is affected by the number of samples (n) as the current
implementation requires n (n + 1) operations, so it's only recommended for
small data sets. method='Rle'
does result in small numerical
differences versus method='regular'
.
Overall method='Matrix'
is faster than the other options and requires
less memory than method='regular'
. With tiny example data sets,
method='Matrix'
can be slower than method='regular'
because the
coercion step is slower.
In derfinder versions <= 0.0.62, method='regular'
was the only option
available.
A numeric Rle with the Fstatistics per base for the chunk in question.
Leonardo ColladoTorres, Jeff Leek
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59  ## Create some toy data
library("IRanges")
toyData < DataFrame(
"sample1" = Rle(sample(0:10, 1000, TRUE)),
"sample2" = Rle(sample(0:10, 1000, TRUE)),
"sample3" = Rle(sample(0:10, 1000, TRUE)),
"sample4" = Rle(sample(0:10, 1000, TRUE))
)
## Create the model matrices
group < c("A", "A", "B", "B")
mod.toy < model.matrix(~group)
mod0.toy < model.matrix(~ 0 + rep(1, 4))
## Get the Fstatistics
fstats < fstats.apply(
data = toyData, mod = mod.toy, mod0 = mod0.toy,
scalefac = 1
)
## Example with data from derfinder package
## Not run:
## Load the data
library("derfinder")
## Create the model matrices
mod < model.matrix(~ genomeInfo$pop)
mod0 < model.matrix(~ 0 + rep(1, nrow(genomeInfo)))
## Run the function
system.time(fstats.Matrix < fstats.apply(
data = genomeData$coverage, mod = mod,
mod0 = mod0, method = "Matrix", scalefac = 1
))
fstats.Matrix
## Compare methods
system.time(fstats.regular < fstats.apply(
data = genomeData$coverage,
mod = mod, mod0 = mod0, method = "regular"
))
system.time(fstats.Rle < fstats.apply(
data = genomeData$coverage, mod = mod,
mod0 = mod0, method = "Rle"
))
## Small numerical differences can occur
summary(fstats.regular  fstats.Matrix)
summary(fstats.regular  fstats.Rle)
## You can make the effect negligible by appropriately rounding
## findRegions(cutoff) so the DERs will be the same regardless of the method
## used.
## Extra comparison, although the method to compare against is 'regular'
summary(fstats.Rle  fstats.Matrix)
## End(Not run)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.