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...