Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • ToddB
    Junior Member
    • Aug 2013
    • 2

    Error Message in nbinomLRT in DESeq2

    Hello all. I am working on some code for my lab and I have run into an error message I can seem to get around. My goal is to test each variable in the model given all other variables are present. Here is the code and the error that are tripping me up.

    DESrun=nbinomLRT(DESrun, useOptim=FALSE, maxit = 500 reduced=as.formula(paste("~",paste(Vars[-i],collapse="+"))))

    Error in optim(betaRow, objectiveFn, method = "L-BFGS-B", lower = -large, :
    L-BFGS-B needs finite values of 'fn'


    Vars contain my variables of interest, for example Vars = c("Age","Gender","Disorder"). And DESrun has my full model, dispersion estimates, size factor estimates, and data. I am using DESeq2 version 1.0.18.

    If I am still getting this error with the useOptim set to false and maxit set to 500 anyone have a suggestion?

    Thanks,
    Todd
  • Yohann
    Junior Member
    • Aug 2013
    • 7

    #2
    Hi,

    I have a pretty similar problem :

    Error in optim(betaRow, objectiveFn, method = "L-BFGS-B", lower = -large, :
    non-finite finite-difference value [3]


    What is weird is that i'm pretty sure it worked with an older version of DESeq2 as i'm re-running an old script.

    Did you find a solution ?

    Comment

    • dpryan
      Devon Ryan
      • Jul 2011
      • 3478

      #3
      Can you post the relevant portion of your script (including the design data.frame)? I suspect that something is off in your fit function.

      Comment

      • ToddB
        Junior Member
        • Aug 2013
        • 2

        #4
        No solution yet. But, I have been in contact with Mike Love and he is tracking it down. He sent me the following to see which rows are causing an issue.


        if you do:

        debug(DESeq2:::fitNbinomGLMs)

        this will show which rows are crashing.

        nbinomLRT first runs fitNbinomGLMs on the full formula which is not
        throwing the error. So you can hit enter through the function once.
        The second time it is fitting the reduced formula. On the second time,
        after this code chunk, you can identify the rows causing the problem:

        # switch based on whether we should also use optim
        # on rows which did not converge
        if (useOptim) {
        rowsForOptim <- which(!betaConv | !rowStable | !rowVarPositive)
        } else {
        rowsForOptim <- which(!rowStable | !rowVarPositive)
        }

        The rowsForOptim is the subset of rows which are causing problems.

        My current plan is to use this to find the rows causing a problem and remove them, then rerun DESeq2.

        Comment

        • Michael Love
          Senior Member
          • Jul 2013
          • 333

          #5
          I now am committing DESeq2 version 1.0.19 to Bioc which uses Nelder-Mead for this back-up optimization rather than L-BFGS-B. This appears to avoid this halting error.

          Furthermore, for Todd's data, it is necessary, for now, to also standardize the numeric predictors, e.g.:

          # scale the numeric predictors
          for (var in c("age","weight")) {
          colData(dds)[[var]] <- as.numeric(scale(colData(dds)[[var]]))
          }

          Then in the end, the log2 fold changes and lfcSE can be multiplied by sd(age) to obtain what would have been the original log2 fold change expected per year for the age variable. (Or you can leave them as they are and they are interpretable as log2 fold changes expected per standard deviation)

          I am working on improving the fitting algorithm in the devel branch, so that this manual scaling will not be necessary.

          Comment

          • Yohann
            Junior Member
            • Aug 2013
            • 7

            #6
            Hi,

            I was using a continuous variable that was the number of bacteria as a covariate.
            This value scales from ~ 1e4 to 1e7
            If i use this scale, i have the error message : "Error in optim(betaRow, objectiveFn, method = "L-BFGS-B", lower = -large, : non-finite finite-difference value [3]"
            If i instead divide my values by 1e6 (it's now millions of bacteria), it works.

            Comment

            • Simon Anders
              Senior Member
              • Feb 2010
              • 995

              #7
              Are you sure that you don't want to rather regress on the logarithm of your predictor, given its huge dynamic range?

              Comment

              • Yohann
                Junior Member
                • Aug 2013
                • 7

                #8
                Originally posted by Simon Anders View Post
                Are you sure that you don't want to rather regress on the logarithm of your predictor, given its huge dynamic range?
                That's a good idea, thanks!
                I'll check that !

                Comment

                • Michael Love
                  Senior Member
                  • Jul 2013
                  • 333

                  #9
                  I have implemented a change to the fitting algorithm in DESeq2 version >= 1.1.32 which should eliminate the need to standardize predictors as described in my post above.

                  Comment

                  • Yohann
                    Junior Member
                    • Aug 2013
                    • 7

                    #10
                    Hi Michael,

                    Here is a part of my code :

                    Code:
                    colData <- data.frame(
                    	AFcomp = sub_individuals$AFcomp,
                    	bacteria_count = sub_individuals$Contact,
                    	batch = as.factor(paste0("F", sub_individuals$Flowcell)))
                    
                    dds <- DESeqDataSetFromMatrix(
                    	countData = sub_reads,
                    	colData = colData,
                    	design = ~ AFcomp + bacteria_count + batch)
                    
                    dds <- estimateSizeFactors(dds)
                    dds <- estimateDispersions(dds, maxit = 500, quiet = TRUE)
                    dds <- nbinomLRT(dds, full = design(dds), maxit = 500, reduced = ~ bacteria_count + batch)
                    Where :
                    • AFcomp is a continuous variable scaling from 0 to 1.
                    • bacteria_count is a continuous variable from 1e6 to 8e6.
                    • batch is a discrete variable (batch name).


                    if i use the bacteria_count like that, i get this error :

                    Code:
                    Error in solve.default(xtwx + ridge) :
                      system is computationally singular: reciprocal condition number = 9.67189e-20
                    If i divide the bacteria_count by 1e6 (now looking at millions of bacteria), it works.

                    I'm using the 1.1.33 version from the dev branch of bioconductor.

                    Do you have an idea?

                    Thanks!
                    Last edited by Yohann; 09-04-2013, 10:18 AM.

                    Comment

                    • Michael Love
                      Senior Member
                      • Jul 2013
                      • 333

                      #11
                      hi Yohann,

                      I see the problem and will look into it.

                      Comment

                      • Michael Love
                        Senior Member
                        • Jul 2013
                        • 333

                        #12
                        hi Yohann,

                        The problem was coming from some code which goes over rows which did not converge in the standard GLM fitting steps using R's optimization function. So I had not updated this code to account for very large columns in the design matrix. I have now updated this bit of code in version 1.1.35 and added a unit test to confirm that the coefficients and standard errors are identical with or without this extra optimization loop.

                        If you could check if this solves your error that would be great.

                        Comment

                        • Yohann
                          Junior Member
                          • Aug 2013
                          • 7

                          #13
                          hi Michael, thanks for your answer.

                          It looks like i can only retrieve the 1.1.34 version on http://bioconductor.org/packages/dev...ml/DESeq2.html.

                          Is there an other way to get the 1.1.35 ?

                          Thanks,

                          Comment

                          • Michael Love
                            Senior Member
                            • Jul 2013
                            • 333

                            #14
                            It should show up on the Bioc site around this time tomorrow.

                            Comment

                            Latest Articles

                            Collapse

                            • SEQadmin2
                              From Collection to Sequencing: Why Sample Preparation and Preservation Define Sequencing Data
                              by SEQadmin2


                              Data variability is still an issue in sequencing technologies despite the advances in reproducibility and accuracy of these platforms. But the problem does not originate in the sequencing itself, but in the previous steps, before the sample reaches the sequencer.


                              The first step is collection, followed by preservation and sample preparation for analysis. Most scientists overlook those steps, but not being careful might just be skewing the experiment’s results.
                              ...
                              06-02-2026, 10:05 AM
                            • SEQadmin2
                              Single-Cell Sequencing at an Inflection Point: Early Impacts of New Platforms and Emerging Trends
                              by SEQadmin2


                              With the launch of new single-cell sequencing platforms in 2026, the field stands at an exciting inflection point. This article surveys the most impactful advances in the field and discusses how they’re reshaping research in cancer, immunology, and beyond.


                              Introduction

                              Single-cell sequencing technologies have undergone remarkable advances over the past decade, transitioning from low-throughput experimental approaches to highly scalable platforms capable of...
                              05-22-2026, 06:42 AM
                            • SEQadmin2
                              Environmental Genomics in the Age of NGS: From Microbes to Conservation Strategies
                              by SEQadmin2

                              Studying ecosystems means dealing with complex, multi-species communities that are hard to observe at scale. This complexity, however, hides many important questions to be answered, from how biogeochemical cycles work and how climate change can affect species distribution to how conservation strategies can work best.


                              Genomics, particularly since the expansion of NGS, has transformed ecosystem ecology. By sequencing environmental DNA, we can now assess biodiversity without direct...
                              05-06-2026, 09:04 AM

                            ad_right_rmr

                            Collapse

                            News

                            Collapse

                            Topics Statistics Last Post
                            Started by SEQadmin2, 06-02-2026, 12:03 PM
                            0 responses
                            21 views
                            0 reactions
                            Last Post SEQadmin2  
                            Started by SEQadmin2, 06-02-2026, 11:40 AM
                            0 responses
                            14 views
                            0 reactions
                            Last Post SEQadmin2  
                            Started by SEQadmin2, 05-28-2026, 11:40 AM
                            0 responses
                            29 views
                            0 reactions
                            Last Post SEQadmin2  
                            Started by SEQadmin2, 05-26-2026, 10:12 AM
                            0 responses
                            31 views
                            0 reactions
                            Last Post SEQadmin2  
                            Working...