This is a test version of Biostars. For the public version, visit https://www.biostars.org.
error in hcluster although there is no NA/NAN/infinite

I have big datamatrix and I want to learn to set the clustering before drawing heatmap.

> hc <- hclust(as.dist(1-cor(t(mydat1))))
Error in hclust(as.dist(1 - cor(t(mydat1)))) : 
  NA/NaN/Inf in foreign function call (arg 10)
In addition: Warning message:
In cor(t(mydat1)) : the standard deviation is zero

I have tested the matrix using:

> sumis.na(mydat1))
[1] 0
> sum(is.nan(mydat1))
[1] 0
> sum(is.infinite(mydat1))
[1] 0

What happened in my situation? It looks that the warning is that the standard deviation is zero. What does it mean, will it affect the following steps?

If warning is a big issue why not set it as error?

Thanks

r heatmap clustering

1 answer

This is not really a bioinformatics question, more of an R programming one. The warning tells you that you have at least one constant row in your matrix (i.e constant column of the transpose). That's not a problem in itself. However, remember how correlation is computed: there's a division by the standard deviation. R is happy to divide by 0, it just produces NA. Now a distance matrix can contain NA but hclust doesn't know how to deal with it so that's where the error happens.

Thank you very much for your comments. It looks that I need to learn some mathematics. I was trying to understand how to use different way to cluster the gene expression level. I know some methods like pearson/speraman but I cannot understand them. Also R learning is still not there yet.

Thank you again

Log in to answer this question.