Hy4m/linkET

Error in cor(as.vector(xdis), ydis, method = method, use = use) : missing observations in cov/cor

B-1991-ing opened this issue · 4 comments

Hi Houyun,

I am using the linkET to see the correlation between two matrixes, error always happened in the Rstudio.

Error screenshot
Screenshot 2022-11-05 at 12 50 48

The code
linkET_Sib_amo_cox_code.pdf

The excel table
omstrup33_sillebotten_mam copy.xlsx

Do you have any idea why it always occcurs?

Best,

Bing

Hi Houyun,

Update

I noticed that when the table has the number value as "0", the error warning appeared.

Table screenshot
Screenshot 2022-11-05 at 17 53 15

Error screenshot
Screenshot 2022-11-05 at 17 54 12

Best,

Bing

If I have a matrix with the first whole column of 0 in the matrix. Should I directly delete it from the data frame?

Data frame screenshot
Screenshot 2022-11-05 at 23 39 05

Best,

Bing

Hy4m commented

Hi Bing

I think this happens because the default distance method of spec is bray, but for the bray distance method, the row sum of the data (for each selected group) cannot be 0. So, you can solve this problem by setting the parameter spec_dist = dist_func(.FUN = "vegdist", method = "euclidean").

library(linkET)
set.seed(123)
spec <- data.frame(x = sample(0:2, 100, TRUE), y = sample(0:2, 100, TRUE))
env <- data.frame(x = rnorm(100), y = rnorm(100))

## Error: Reproduce your question
mantel_test(spec, env)
## OK
mantel_test(spec, env, spec_dist = dist_func(.FUN = "vegdist", method = "euclidean"))
Hy4m commented

Hi Bing

I think this happens because the default distance method of spec is bray, but for the bray distance method, the row sum of the data (for each selected group) cannot be 0. So, you can solve this problem by setting the parameter spec_dist = dist_func(.FUN = "vegdist", method = "euclidean").

library(linkET)
set.seed(123)
spec <- data.frame(x = sample(0:2, 100, TRUE), y = sample(0:2, 100, TRUE))
env <- data.frame(x = rnorm(100), y = rnorm(100))

## Error: Reproduce your question
mantel_test(spec, env)
## OK
mantel_test(spec, env, spec_dist = dist_func(.FUN = "vegdist", method = "euclidean"))

In the next update, I'll be more careful with spec's default distance algorithm.