Error in heatmap.2 (gplots)

前端 未结 3 2027
一整个雨季
一整个雨季 2020-12-18 07:34

Ive moved on to a new server and Installed R version 3.0 on it. (gplots library was no longer available for 2.14)

Using a script that worked for version 2.14 I now e

相关标签:
3条回答
  • 2020-12-18 08:17

    This problem ("node stack overflow" error while using heatmap.2 function) occurs due to too many identical values in a specific column in your matrix, which causes recursion issue on R producing the error.

    What I can suggest (which at least how I solved my very exact problem for my data) is to produce random numbers around the identical numbers and replace them with the original numbers in the matrix:

    for (i in 1:nrow(my_matrix)) {
       if (my_matrix[i,my_column]=="100") { # assume i have too many 100 in my_column
          my_matrix[i,my_column]=runif(1,99,101) # replace 100 with nearby values randomly
        }
    }
    

    In this way, the heatmap is created without any issue since there are not too many identical numbers anymore, and also it virtually doesn't affect your matrix since you can choose a very small interval for random number generation around your identical value which will still reflect the original values with invisible color changes on the heatmap.

    0 讨论(0)
  • 2020-12-18 08:23

    In another post this is from stats:::midcache.dendrogram's function setmid. setmid calls itself recursively, and this recursion might be too deep -- probably the dendrogram is too dense to make any sense visually? You see where the error occurs by looking at the last few lines of traceback() after the error occurs.

    To make further progress with this, you need to be able to provide a minimal reproducible example (using heatmap rather than heatmap.2, or even more refined based on your interpretation of traceback()) , perhaps by making the data file available, or by providing a recipe to simulate the data (m <- matrix(runif(1000), 40) ?) in a way that reliably reproduces the error.

    0 讨论(0)
  • 2020-12-18 08:25

    I'm the author of the gplots package. The 'node stack overflow' error occurs when a byte-compiled function has too many recursive calls.

    In this case, it occurs because the function that plots dendrogram objects (stats:::plotNode) is implemented using a recursive algorithm and the dendrogram object is deeply nested.

    Ultimately, the correct solution is to modify plotNode to use an iterative algorithm, which will prevent the recursion depth error from occuring.

    In the short term, it is possible to force stats:::plotNode to be run as interpreted code rather then byte-compiled code via a nasty hack.

    Here's the recipe:

    ## Convert a byte-compiled function to an interpreted-code function 
    unByteCode <- function(fun)
        {
            FUN <- eval(parse(text=deparse(fun)))
            environment(FUN) <- environment(fun)
            FUN
        }
    
    ## Replace function definition inside of a locked environment **HACK** 
    assignEdgewise <- function(name, env, value)
        {
            unlockBinding(name, env=env)
            assign( name, envir=env, value=value)
            lockBinding(name, env=env)
            invisible(value)
        }
    
    ## Replace byte-compiled function in a locked environment with an interpreted-code
    ## function
    unByteCodeAssign <- function(fun)
        {
            name <- gsub('^.*::+','', deparse(substitute(fun)))
            FUN <- unByteCode(fun)
            retval <- assignEdgewise(name=name,
                                     env=environment(FUN),
                                     value=FUN
                                     )
            invisible(retval)
        }
    
    ## Use the above functions to convert stats:::plotNode to interpreted-code:
    unByteCodeAssign(stats:::plotNode)
    
    ## Now raise the interpreted code recursion limit (you may need to adjust this,
    ##  decreasing if it uses to much memory, increasing if you get a recursion depth error ).
    options(expressions=5e4)
    
    ## heatmap.2 should now work properly 
    heatmap.2( ... )
    
    0 讨论(0)
提交回复
热议问题