text: user292: Note: I also posted this issue (with less context) in the bioconductor support site: https://support.bioconductor.org/p/97424/
  I'm working on a snakemake workflow that identifies various small RNA species in C. elegans small RNA-seq libraries. Some are endogenous siRNAs supposedly generated from RNA templates (through RNA-dependant RNA polymerases (RdRP)) that can be variously classified (protein-coding genes, transposons, and other repeat types).
  I count such small RNA reads in a set of libraries and try to identify differentially producing sources. For this, I use DESeq2 (that I run using rpy2 from within snakemake).
  I'm not sure DESeq2 is always appropriate for this kind of data, but so far, the analyses would at least complete.
  However, I recently added new potential types of small RNA source (simple repeats and satellites), and these happen to have low counts. I'm not 100% sure, but I suspect these low counts are the reason for failures during DESeq2 analyses (for debugging purposes, I ran this manually in R):
  > dds <- DESeq(dds, betaPrior=T)
  estimating size factors
  estimating dispersions
  gene-wise dispersion estimates
  mean-dispersion relationship
  -- note: fitType='parametric', but the dispersion trend was not well captured by the
     function: y = a/x + b, and a local regression fit was automatically substituted.
     specify fitType='local' or 'mean' to avoid this message next time.
  Error in lfproc(x, y, weights = weights, cens = cens, base = base, geth = geth,  : 
    newsplit: out of vertex space
  In addition: There were 12 warnings (use warnings() to see them)
  > warnings()
  Warning messages:
  1: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  2: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  3: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  4: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  5: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  6: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  7: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  8: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  9: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  10: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  11: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  12: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  
  The count matrix indeed contains a high proportion of zeroes, the rest are mostly ones, but there are some sources that seem a little more significantly producing small RNAs:
  > mean(counts_data == 0)
  [1] 0.7488889
  > mean(counts_data == 1)
  [1] 0.1507407
  > max(counts_data)
  [1] 34
  
  How would you recommend handling such kind of data?
  Should I for instance discard rows without enough counts?
  If so, what would be a reasonable threshold?
  Edits: trying to get a dispersion plot:
  The same error occurs when trying to estimate dispersion:
  > dds <- estimateSizeFactors(dds)
  > dds <- estimateDispersions(dds)
  gene-wise dispersion estimates
  mean-dispersion relationship
  -- note: fitType='parametric', but the dispersion trend was not well captured by the
     function: y = a/x + b, and a local regression fit was automatically substituted.
     specify fitType='local' or 'mean' to avoid this message next time.
  Error in lfproc(x, y, weights = weights, cens = cens, base = base, geth = geth,  : 
    newsplit: out of vertex space
  In addition: There were 12 warnings (use warnings() to see them)
  
  This seems to prevent the generation of dispersion plots:
  > plotDispEsts(dds)
  Error in min(py[py > 0], na.rm = TRUE) : 
    invalid 'type' (list) of argument
  In addition: Warning message:
  In structure(x, class = unique(c("AsIs", oldClass(x)))) :
    Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
    Consider 'structure(list(), *)' instead.
  
  Using fitType="local" also fails:
  > dds <- DESeq(dds, betaPrior=T, fitType="local")
  using pre-existing size factors
  estimating dispersions
  gene-wise dispersion estimates
  mean-dispersion relationship
  Error in lfproc(x, y, weights = weights, cens = cens, base = base, geth = geth,  : 
    newsplit: out of vertex space
  In addition: There were 12 warnings (use warnings() to see them)
  
  But fitType="mean" works:
  > dds <- DESeq(dds, betaPrior=T, fitType="mean")
  estimating size factors
  estimating dispersions
  gene-wise dispersion estimates
  mean-dispersion relationship
  final dispersion estimates
  fitting model and testing
  
  The dispersion plot then looks as follows:
  
  What do these fitType options mean, and are there good reasons why they would have to be changed in order to accomodate for low counts?
  
  user599: Remove low-count features in advance. This is standard for most tools including DESeq2 and edgeR (see section 2.6). 
  This will keep you from testing a lot of features that cannot be differentially expressed (using NB model you need at least four reads - below that the uncertainty is too high to ever be DE) and you will make the false discovery correction unnecessarily hard.
  
  user77: I don't think that the issue is the low counts, but rather the number of features without any real variance (the black dots at the bottom).
  So what the heck is the dispersion plot and why does one need to fit it anyway?
  In a typical RNAseq experiment, one measures many thousands of genes with only a few replicates per biological group. This then leads to issues when performing testing, since your variance measurement for any given gene will be larger or smaller than reality, simply due to the lack of a large number of replicates. Consequently, at least since the limma package came out, most RNAseq packages have tried to fit the mean-dispersion with some sort of line and then used that as a background distribution toward which the variance assigned to each gene should be "shrunken" (i.e., moved toward). Getting this at least approximately correct is important, since if you have few replicates and the final "shrunken variance" is significantly wrong, then your p-values will also be wrong.
  What are the various fitType options and what are they doing?
  The three options that one can use to fit this relationship are parametric, local, and mean. parametric is the default and basically results in fitting to a bent line. This usually works quite well, but you can see that you have two clouds of data, one shaped like a bent line (at the top) and another (the black dots at the bottom) with no variance. That's causing this fit type to fail. Likewise, local is doing a local fit and failing for the same reason. mean is just taking the mean (average) of all of the estimates. This is fool-proof, but you're then regressing to something that really doesn't fit your data. mean is really a last choice if nothing else works.
  For your particular dataset, my main concerns would be figuring out (1) why the maximum mean counts are around 20 (that's really low) and (2) why so many of these features have incredibly low variance.
  
original_text: 292: <p>Note: I also posted this issue (with less context) in the bioconductor support site: <a href="https://support.bioconductor.org/p/97424/" rel="noreferrer">https://support.bioconductor.org/p/97424/</a></p>
  
  <p>I'm working on a snakemake workflow that identifies various small RNA species in <em>C. elegans</em> small RNA-seq libraries. Some are endogenous siRNAs supposedly generated from RNA templates (through RNA-dependant RNA polymerases (RdRP)) that can be variously classified (protein-coding genes, transposons, and other repeat types).</p>
  
  <p>I count such small RNA reads in a set of libraries and try to identify differentially producing sources. For this, I use DESeq2 (that I run <a href="https://stackoverflow.com/q/42157335/1878788">using rpy2</a> from within snakemake).</p>
  
  <p>I'm not sure DESeq2 is always appropriate for this kind of data, but so far, the analyses would at least complete.
  However, I recently added new potential types of small RNA source (simple repeats and satellites), and these happen to have low counts. I'm not 100% sure, but I suspect these low counts are the reason for failures during DESeq2 analyses (for debugging purposes, I ran this manually in R):</p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; dds &lt;- DESeq(dds, betaPrior=T)
  estimating size factors
  estimating dispersions
  gene-wise dispersion estimates
  mean-dispersion relationship
  -- note: fitType='parametric', but the dispersion trend was not well captured by the
     function: y = a/x + b, and a local regression fit was automatically substituted.
     specify fitType='local' or 'mean' to avoid this message next time.
  Error in lfproc(x, y, weights = weights, cens = cens, base = base, geth = geth,  : 
    newsplit: out of vertex space
  In addition: There were 12 warnings (use warnings() to see them)
  &gt; warnings()
  Warning messages:
  1: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  2: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  3: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  4: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  5: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  6: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  7: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  8: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  9: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  10: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  11: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  12: In lfproc(x, y, weights = weights, cens = cens, base = base,  ... :
    procv: no points with non-zero weight
  </code></pre>
  
  <p>The count matrix indeed contains a high proportion of zeroes, the rest are mostly ones, but there are some sources that seem a little more significantly producing small RNAs:</p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; mean(counts_data == 0)
  [1] 0.7488889
  &gt; mean(counts_data == 1)
  [1] 0.1507407
  &gt; max(counts_data)
  [1] 34
  </code></pre>
  
  <p><strong>How would you recommend handling such kind of data?</strong></p>
  
  <p>Should I for instance discard rows without enough counts?
  If so, what would be a reasonable threshold?</p>
  
  <h3>Edits: trying to get a dispersion plot:</h3>
  
  <p>The same error occurs when trying to estimate dispersion:</p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; dds &lt;- estimateSizeFactors(dds)
  &gt; dds &lt;- estimateDispersions(dds)
  gene-wise dispersion estimates
  mean-dispersion relationship
  -- note: fitType='parametric', but the dispersion trend was not well captured by the
     function: y = a/x + b, and a local regression fit was automatically substituted.
     specify fitType='local' or 'mean' to avoid this message next time.
  Error in lfproc(x, y, weights = weights, cens = cens, base = base, geth = geth,  : 
    newsplit: out of vertex space
  In addition: There were 12 warnings (use warnings() to see them)
  </code></pre>
  
  <p>This seems to prevent the generation of dispersion plots:</p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; plotDispEsts(dds)
  Error in min(py[py &gt; 0], na.rm = TRUE) : 
    invalid 'type' (list) of argument
  In addition: Warning message:
  In structure(x, class = unique(c("AsIs", oldClass(x)))) :
    Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
    Consider 'structure(list(), *)' instead.
  </code></pre>
  
  <p>Using <code>fitType="local"</code> also fails:</p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; dds &lt;- DESeq(dds, betaPrior=T, fitType="local")
  using pre-existing size factors
  estimating dispersions
  gene-wise dispersion estimates
  mean-dispersion relationship
  Error in lfproc(x, y, weights = weights, cens = cens, base = base, geth = geth,  : 
    newsplit: out of vertex space
  In addition: There were 12 warnings (use warnings() to see them)
  </code></pre>
  
  <p>But <code>fitType="mean"</code> works:</p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; dds &lt;- DESeq(dds, betaPrior=T, fitType="mean")
  estimating size factors
  estimating dispersions
  gene-wise dispersion estimates
  mean-dispersion relationship
  final dispersion estimates
  fitting model and testing
  </code></pre>
  
  <p>The dispersion plot then looks as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/647fF.png" rel="noreferrer"><img src="https://i.stack.imgur.com/647fF.png" alt="enter image description here"></a></p>
  
  <p><strong>What do these <code>fitType</code> options mean, and are there good reasons why they would have to be changed in order to accomodate for low counts?</strong></p>
   599: <p>Remove low-count features in advance. This is standard for most tools including <a href="http://bioconductor.org/packages/release/bioc/vignettes/DESeq2/inst/doc/DESeq2.html#pre-filtering" rel="nofollow noreferrer">DESeq2</a> and <a href="http://bioconductor.org/packages/release/bioc/vignettes/edgeR/inst/doc/edgeRUsersGuide.pdf" rel="nofollow noreferrer">edgeR</a> (see section 2.6). </p>
  
  <p>This will keep you from testing a lot of features that cannot be differentially expressed (using NB model you need at least four reads - below that the uncertainty is too high to ever be DE) and you will make the false discovery correction unnecessarily hard.</p>
   77: <p>I don't think that the issue is the low counts, but rather the number of features without any real variance (the black dots at the bottom).</p>
  
  <h1>So what the heck is the dispersion plot and why does one need to fit it anyway?</h1>
  
  <p>In a typical RNAseq experiment, one measures many thousands of genes with only a few replicates per biological group. This then leads to issues when performing testing, since your variance measurement for any given gene will be larger or smaller than reality, simply due to the lack of a large number of replicates. Consequently, at least since the <code>limma</code> package came out, most RNAseq packages have tried to fit the mean-dispersion with some sort of line and then used that as a background distribution toward which the variance assigned to each gene should be "shrunken" (i.e., moved toward). Getting this at least approximately correct is important, since if you have few replicates and the final "shrunken variance" is significantly wrong, then your p-values will also be wrong.</p>
  
  <h1>What are the various fitType options and what are they doing?</h1>
  
  <p>The three options that one can use to fit this relationship are <code>parametric</code>, <code>local</code>, and <code>mean</code>. <code>parametric</code> is the default and basically results in fitting to a bent line. This usually works quite well, but you can see that you have two clouds of data, one shaped like a bent line (at the top) and another (the black dots at the bottom) with no variance. That's causing this fit type to fail. Likewise, <code>local</code> is doing a local fit and failing for the same reason. <code>mean</code> is just taking the mean (average) of all of the estimates. This is fool-proof, but you're then regressing to something that really doesn't fit your data. <code>mean</code> is really a last choice if nothing else works.</p>
  
  <p>For your particular dataset, my main concerns would be figuring out (1) why the maximum mean counts are around 20 (that's really low) and (2) why so many of these features have incredibly low variance.</p>
  