Error in lm.fit : NA/NaN/Inf in 'y'. When try to transformed into log scale

I'm trying to plot a linear regression model in base R by using vegdist after that fitting them by transformed into log scale
My data frame:

> str(un_sap.bray)
 'dist' num [1:72390] 0.53 0.228 0.48 0.124 0.648 ...
 - attr(*, "Size")= int 381
 - attr(*, "Labels")= chr [1:381] "als1" "als2" "als3" "als4" ...
 - attr(*, "Diag")= logi FALSE
 - attr(*, "Upper")= logi FALSE
 - attr(*, "method")= chr "bray"
 - attr(*, "call")= language vegdist(x = un_sap.otu, method = "bray")

My code:
These all codes are working

> un_sap.bray <- vegdist(un_sap.otu,"bray")
> un_sap.xy.dist=dist(un_sap.xy[,c('x','y')])
> plot(log(un_sap.xy.dist),log(un_sap.bray))

> DDR.un_sap.lm=lm(log(un_sap.bray)~log(un_sap.xy.dist))
> summary(DDR.un_sap.lm)
> abline(DDR.un_sap.lm,col=2)

Then I try to calculate 1-vegdist() after that fitting scatter plot by lm() is getting an error

> un_sap.bray <- 1-vegdist(un_sap.otu,"bray")   #change to similarity
> un_sap.xy.dist=dist(un_sap.xy[,c('x','y')])
> plot(log(un_sap.xy.dist),log(un_sap.bray))

> DDR.un_sap.lm=lm(log(un_sap.bray)~log(un_sap.xy.dist))
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  NA/NaN/Inf in 'y'

I have checked on NAs in my data

> any(is.na(log(un_sap.bray)))
[1] FALSE
> any(is.na(log(un_sap.xy.dist)))
[1] FALSE

How can I fix this? Can someone help me...

Negative numbers and zeros also cannot be displayed in log scale. Maybe there are negatives or zeroes in your data.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.