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