DC7
August 11, 2020, 1:28pm
1
Hi there!!! Here is a correlation table generated from my data frame with bacterial relative abundance. The 3rd and 4th columns respectively denotes correlation co-efficient (cor) and their P-value (p). Now, I want to filter this table to generate an output that will have interactions with p < 0.05
and cor > 0.6
and cor < -0.6.
Can anyone please tell me how can I do that? Here's a portion of table:
row
column
cor
p
Actinobaculum_sp_oral_taxon_183
Actinomyces_graevenitzii
-0.083166733306677
0.557766591033679
Actinobaculum_sp_oral_taxon_183
Actinomyces_naeslundii
-0.057666197516258
0.684693748325992
Actinomyces_graevenitzii
Actinomyces_naeslundii
-0.057666197516258
0.684693748325992
Actinobaculum_sp_oral_taxon_183
Actinomyces_odontolyticus
0.082972778302491
0.558688695520664
Actinomyces_graevenitzii
Actinomyces_odontolyticus
0.086259815138003
0.543159275510664
Actinomyces_naeslundii
Actinomyces_odontolyticus
0.260101357406385
0.062572519939439
Actinobaculum_sp_oral_taxon_183
Actinomyces_oris
0.001812984437111
0.989822610583224
Actinomyces_graevenitzii
Actinomyces_oris
0.078226921082765
0.581472276924872
Actinomyces_naeslundii
Actinomyces_oris
0.164725112347852
0.243223831404869
Actinomyces_odontolyticus
Actinomyces_oris
0.321304480536897
0.02020092245847
Actinobaculum_sp_oral_taxon_183
Actinomyces_sp_HMSC035G02
-0.009475829184974
0.946843170060088
Actinomyces_graevenitzii
Actinomyces_sp_HMSC035G02
0.223167925805104
0.111768183795273
Actinomyces_naeslundii
Actinomyces_sp_HMSC035G02
0.127195351524484
0.368876768685618
Actinomyces_odontolyticus
Actinomyces_sp_HMSC035G02
0.728031815255434
9.61068558069655E-10
Actinomyces_oris
Actinomyces_sp_HMSC035G02
0.489804314937454
0.000228307144797
Actinobaculum_sp_oral_taxon_183
Actinomyces_sp_HPA0247
-0.122407920609607
0.387315423215962
Many thanks
dc7
FJCC
August 11, 2020, 1:33pm
2
If your data frame is named DF, you can get the result you want with the filter() function from dplyr.
library(dplyr)
DF_filtered <- filter(DF, abs(cor) > 0.6, p < 0.05)
2 Likes
DC7
August 11, 2020, 2:56pm
3
I don't know why DF_fileterd doesn't contain a single negative (-ve) cor value
. It is strange. Is it taking values only greater than 0.6? Also similar value coming multiple times:
Eisenbergiella_tayi
Ruthenibacterium_lactatiformans
0.679759843314795
2.99746081289243E-08
Clostridium_bolteae
Clostridium_symbiosum
0.68096900743543
2.77191414266298E-08
Eggerthella_lenta
Flavonifractor_plautii
0.685541202470124
2.05520234164425E-08
Actinomyces_naeslundii
Parascardovia_denticolens
0.68600532975442
1.99312686355313E-08
Bifidobacterium_pullorum
Rothia_dentocariosa
0.68600532975442
1.99312686355313E-08
Bifidobacterium_pullorum
Prevotella_sp_CAG_891
0.68600532975442
1.99312686355313E-08
Actinomyces_naeslundii
Parabacteroides_gordonii
0.68600532975442
1.99312686355313E-08
Prevotella_disiens
Bacillus_sp_FJAT_27916
0.68600532975442
1.99312686355313E-08
Bacteroides_sp_CAG_530
Enterococcus_hirae
0.68600532975442
1.99312686355313E-08
Bacteroides_sp_CAG_661
Enterococcus_hirae
0.68600532975442
1.99312686355313E-08
Prevotella_sp_AM42_24
Enterococcus_hirae
0.68600532975442
1.99312686355313E-08
Lactobacillus_acidophilus
Lactobacillus_amylovorus
0.68600532975442
1.99312686355313E-08
Prevotella_timonensis
Lactobacillus_crispatus
0.68600532975442
1.99312686355313E-08
Bacteroides_sp_CAG_530
Lactobacillus_fermentum
0.68600532975442
1.99312686355313E-08
Bacteroides_sp_CAG_661
Lactobacillus_fermentum
0.68600532975442
1.99312686355313E-08
Prevotella_sp_AM42_24
Lactobacillus_fermentum
0.68600532975442
1.99312686355313E-08
Bacteroides_sp_CAG_530
Lactobacillus_johnsonii
0.68600532975442
1.99312686355313E-08
Bacteroides_sp_CAG_661
Lactobacillus_johnsonii
0.68600532975442
1.99312686355313E-08
Prevotella_sp_AM42_24
Lactobacillus_johnsonii
0.68600532975442
1.99312686355313E-08
FJCC
August 11, 2020, 3:05pm
4
Do you know that there are some rows where cor < -0.6? You can make a subset of the data to check that
NegCor <- filter(DF, cor < -0.6)
I also notice now that your p values can be greater than 1, so something is wrong with the construction of your data frame.
DC7
August 11, 2020, 5:42pm
5
Yes. there was only one cor <-0.6 that I didn't notice earlier. However, where did you find P-value > 1? filter(final_mat, p > 1)
This code shows no P-value greater than 1.
thanks
dc7
FJCC
August 11, 2020, 5:46pm
6
I misread the data when I thought I saw p values above 1.
1 Like
system
Closed
September 1, 2020, 5:46pm
7
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.