Entering edit mode
5.7 years ago
pablo
▴
310
Hi guys,
I've got this kind of matrix : https://ibb.co/r47yY3m
I would like to compute correlations between each pair of OTUs according to this formula (rho coefficient):
(for example between the first and second OTU)
1-((var(lol[1,]-lol[2,]))/(var(lol[1,])+var(lol[2,])))
How could I create a function to compute automatically each correlation between each pair according to get a result like this :
OTU0001 OTU0004 X
OTU0001 OTU0014 X
....
OTU0016 OTU0017 X
Thanks
Actually, the problem here is to create the function to compute the correlations between each pairs of OTUs. I do not want to use the function cor() but create the function like I did between the first and the second OTU. I just want to "automatize" this function for each pair
All that you have to do is replace the
cor()
function (in my previous example) with your new function.I know what you mean, but my main problem is to create this new function.. I checked on Biostars but didn't find anything about my problem..
Is this not your formula? -
1-((var(lol[1,]-lol[2,]))/(var(lol[1,])+var(lol[2,])))
Implementing it in the
foreach
loop would be something like:I found this formula in a paper "propr: An R-package for Identifying Proportionally Abundant Features Using Compositional Data Analysis."
I tried :
It doesn't give me what I want. Actually, I don't really know how I could get a result like this :
Try it on a small subset of your data, first, and do it manually. Then you can tackle the issue of doing it over the entire data.
I created a small subset with 5 rows and 5 columns.
When I try :
It returns me an error. The problem is really to create the function which computes "my" formula to compute all correlations. It's a bit tricky for me to create this function actually...
This seems to do it(?). Here, there is only one layer of parallelisation. If you want a double layer, you can additionally parallelise where I use the
apply()
function withinforeach
Thanks a lot for this answer. Do you think it is possible to only get the lower or the upper triangle of the matrix? In order to reduce the time of the script