Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/cleanSizeFactors.R

Coerce non-positive size factors to positive values based on the number of detected features.

1 2 3 4 5 6 7 8 | ```
cleanSizeFactors(
size.factors,
num.detected,
control = nls.control(warnOnly = TRUE),
iterations = 3,
nmads = 3,
...
)
``` |

`size.factors` |
A numeric vector containing size factors for all libraries. |

`num.detected` |
A numeric vector of the same length as |

`control` |
Argument passed to |

`iterations` |
Integer scalar specifying the number of robustness iterations. |

`nmads` |
Numeric scalar specifying the multiple of MADs to use for the tricube bandwidth in robustness iterations. |

`...` |
Further arguments to pass to |

This function will first fit a non-linear curve of the form

*y = ax/(1 + bx)*

where `y`

is `num.detected`

and `x`

is `size.factors`

for all positive size factors.
This is a purely empirical expression, chosen because it is passes through the origin, is linear near zero and asymptotes at large `x`

.
The fitting is done robustly with iterations of tricube weighting to eliminate outliers.

We then consider the number of detected features for all samples with non-positive size factors.
This is treated as `y`

and used to solve for `x`

based on the curve fitted above.
The result is the “cleaned” size factor, which must always be positive for `y < a/b`

.
For `y > a/b`

, there is no solution so the cleaned size factor is defined as the largest positive value in `size.factors`

.

Negative size factors can occasionally be generated by `computeSumFactors`

, see the documentation there for more details.
By coercing them to positive values, we can proceed to normalization and downstream analyses.
Here, we use the number of detected features as this is more robust to differential expression that would cause biases in the library size.
Of course, it is not theoretically guaranteed to yield the correct size factor, but a rough guess is better than a negative value.

A numeric vector identical to `size.factors`

but with all non-positive size factors replaced with fitted values from the curve.

Aaron Lun

`computeSumFactors`

, which can occasionally generate negative size factors.

`nls`

, which performs the curve fitting.

1 2 3 4 5 6 7 8 9 10 |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.