Skip to contents

Apply a function on each pair of features

Usage

pairwiseApply(X, ...)

Arguments

X

input object

...

additional arguments

Value

a list containing the output of applying the function to each feature pair. See ?base::mapply()

Examples

web <- randomWeb(10)

# For each feature pair, was the value for x higher than the value for y?
pairwise_gt <- pairwiseApply(
    X = web,
    FUN = function(x, y) x > y,
    MoreArgs = NULL, SIMPLIFY = FALSE, USE.NAMES = TRUE
)

head(pairwise_gt)
#> $x_1y_1
#>  [1]  TRUE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE
#> 
#> $x_1y_2
#>  [1]  TRUE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
#> 
#> $x_1y_4
#>  [1]  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
#> 
#> $x_1y_5
#>  [1]  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
#> 
#> $x_1y_9
#>  [1]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE
#> 
#> $x_1y_10
#>  [1]  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE
#> 

# Run cor.test() on each pair of features
pairwise_cor <- pairwiseApply(
    X = web,
    FUN = function(x, y) cor.test(x, y),
    MoreArgs = NULL, SIMPLIFY = FALSE, USE.NAMES = TRUE
)

pairwise_cor[1]
#> $x_1y_1
#> 
#> 	Pearson's product-moment correlation
#> 
#> data:  x and y
#> t = 0.39731, df = 8, p-value = 0.7015
#> alternative hypothesis: true correlation is not equal to 0
#> 95 percent confidence interval:
#>  -0.5376084  0.7068238
#> sample estimates:
#>       cor 
#> 0.1391034 
#> 
#>