cor_mass_dataset

cor_mass_dataset(
  x,
  y = NULL,
  margin = c("variable", "sample"),
  use = c("everything", "all.obs", "complete.obs", "na.or.complete",
    "pairwise.complete.obs"),
  method = c("spearman", "pearson", "kendall"),
  data_type = c("wider", "longer"),
  p_adjust_method = c(c("BH", "holm", "hochberg", "hommel", "bonferroni", "BY", "fdr",
    "none"))
)

Arguments

x

mass_dataset class

y

NULL

margin

sample or variable

use

an optional character string giving a method for computing covariances in the presence of missing values. This must be (an abbreviation of) one of the strings "everything", "all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs".

method

a character string indicating which correlation coefficient (or covariance) is to be computed. One of "pearson" (default), "kendall", or "spearman": can be abbreviated.

data_type

wider or longer

p_adjust_method

see ?p.adjust

Value

dist returns an object of class "dist".

Author

Xiaotao Shen shenxt1990@outlook.com

Examples

library(massdataset)
library(magrittr)
library(dplyr)

data("liver_aging_pos")
liver_aging_pos
#> -------------------- 
#> massdataset version: 0.01 
#> -------------------- 
#> 1.expression_data:[ 21607 x 24 data.frame]
#> 2.sample_info:[ 24 x 4 data.frame]
#> 3.variable_info:[ 21607 x 3 data.frame]
#> 4.sample_info_note:[ 4 x 2 data.frame]
#> 5.variable_info_note:[ 3 x 2 data.frame]
#> 6.ms2_data:[ 0 variables x 0 MS2 spectra]
#> -------------------- 
#> Processing information (extract_process_info())
#> 1 processings in total
#> Creation ---------- 
#>       Package         Function.used                Time
#> 1 massdataset create_mass_dataset() 2021-12-23 00:24:02

qc_id <-
  liver_aging_pos %>%
  activate_mass_dataset(what = "sample_info") %>%
  dplyr::filter(group == "QC") %>%
  dplyr::pull(sample_id)

object <-
  mutate_rsd(liver_aging_pos, according_to_samples = qc_id)

###only remain the features with rt > 100, mz > 150 and rsd < 30
object <-
  object %>%
  activate_mass_dataset(what = "variable_info") %>%
  dplyr::filter(rt > 100) %>%
  dplyr::filter(mz > 150) %>%
  dplyr::filter(rsd < 30)

##only remain the week 24 samples
object <-
  object %>%
  activate_mass_dataset(what = "sample_info") %>%
  dplyr::filter(group == "24W")

dim(object)
#> variables   samples 
#>       751        10 

object <-
  object %>%
  `+`(1) %>%
  log(10) %>%
  scale_data(method = "auto")

cor_data <-
  object %>%
  cor_mass_dataset(margin = "variable", data_type = "wider")

head(cor_data$correlation[,1:5])
#>             M150T707   M151T618   M151T609   M152T412   M153T518
#> M150T707  1.00000000  0.2727273 -0.2000000  0.2848485  0.1151515
#> M151T618  0.27272727  1.0000000 -0.2363636  0.6969697  0.1151515
#> M151T609 -0.20000000 -0.2363636  1.0000000 -0.4909091  0.3939394
#> M152T412  0.28484848  0.6969697 -0.4909091  1.0000000 -0.1030303
#> M153T518  0.11515152  0.1151515  0.3939394 -0.1030303  1.0000000
#> M153T577  0.04242424 -0.1757576  0.1636364 -0.3090909 -0.3818182
head(cor_data$p_value[,1:5])
#>           M150T707   M151T618  M151T609   M152T412  M153T518
#> M150T707        NA 0.44583834 0.5795840 0.42503815 0.7514197
#> M151T618 0.4458383         NA 0.5108853 0.02509668 0.7514197
#> M151T609 0.5795840 0.51088532        NA 0.14965567 0.2599978
#> M152T412 0.4250382 0.02509668 0.1496557         NA 0.7769985
#> M153T518 0.7514197 0.75141965 0.2599978 0.77699846        NA
#> M153T577 0.9073638 0.62718834 0.6514773 0.38484123 0.2762553
head(cor_data$n[,1:5])
#>          M150T707 M151T618 M151T609 M152T412 M153T518
#> M150T707       10       10       10       10       10
#> M151T618       10       10       10       10       10
#> M151T609       10       10       10       10       10
#> M152T412       10       10       10       10       10
#> M153T518       10       10       10       10       10
#> M153T577       10       10       10       10       10

cor_data <-
  object %>%
  cor_mass_dataset(margin = "variable", data_type = "longer")

head(cor_data)
#>       from       to correlation    p_value number  p_adjust
#> 1 M151T618 M150T707   0.2727273 0.44583834     10 0.9625970
#> 2 M151T609 M150T707  -0.2000000 0.57958400     10 0.9723318
#> 3 M151T609 M151T618  -0.2363636 0.51088532     10 0.9683021
#> 4 M152T412 M150T707   0.2848485 0.42503815     10 0.9614259
#> 5 M152T412 M151T618   0.6969697 0.02509668     10 0.6847366
#> 6 M152T412 M151T609  -0.4909091 0.14965567     10 0.8874314