Perform enrichtment analysis from a weave
weave_coverage.RdPerform enrichtment analysis from a weave
Arguments
- x
A LinkMap with coverage metadata from
weave_coverage().- .path
Either a
formulaor acharacter vectorof length 2 with the names of the desired combination of feature types.- .data
Optional
Character vector. Lists observed features from the found within the first element of.path. Alternatively, adata.framewith the same information. (Also see.data_columnargument).- metric
Character scalar. One or more of'set_count','set_size','coverage','complete'.- out.format
Character scalar. One of'LinkMap','matrix'.- .data_column
Character scalar. if.datais a table, where to find feature IDs- log_base
Integer. Base of logarithm for log-fold (default: 2).
Examples
set.seed(2612)
# Draw five cards from a deck
drawn <- draw_cards(5)
drawn
#> [1] "Jack♦️" "5♥️" "King♠️" "7♥️" "6♦️"
scores <- poker_scores()
scores
#> A MultiFactor::MultiFactor list S7_object,
#> 4 feature types across 3 LinkMaps.
#>
#> card rank suit straight
#> card2rank 52 13 . .
#> card2suit 52 . 4 .
#> rank2straight . 13 . 10
#>
#> Values represent unique feature names in that LinkMap.
#>
#> @ levels:
#> $ card : 52 Levels: Ace♥️ ... King♣️
#> $ rank : 13 Levels: Ace ... King
#> $ suit : 4 Levels: hearts spades diamonds clubs
#> $ straight : 10 Levels: Ace to 5 ... Royal straight
# Now enrich input
result <- weave_coverage(
x = scores, .path = card ~ suit, .data = drawn, metric = "set_count"
)
result
#> A MultiFactor::LinkMap data.frame S7_object: 52 rows.
#> card suit
#> 1 Ace♣️ clubs
#> 2 2♣️ clubs
#> 3 3♣️ clubs
#> 4 4♣️ clubs
#> 5 5♣️ clubs
#> 6 6♣️ clubs
#> 7 7♣️ clubs
#> 8 8♣️ clubs
#> 9 9♣️ clubs
#> 10 10♣️ clubs
#> + 42 more rows. Use `print(n = ...)` to see more rows.
#>
#> @ levels: 2 variables:
#> $ card : 52 Levels: Ace♥️ ... King♣️
#> $ suit : 4 Levels: hearts spades diamonds clubs
#>
#> @ metadata: 2 variables:
#> List of 2
#> $ observed : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
#> $ set_count: int 0 0 0 0 0 0 0 0 0 0 ...
# Now let's spike our hand with a royal straight flush
cheat <- draw_cards()[c(10, 11, 12, 13, 1)]
cheat
#> [1] "10♥️" "Jack♥️" "Queen♥️" "King♥️" "Ace♥️"
.path = card ~ straight
result <- weave_coverage(scores, card ~ straight, .data = cheat)
result
#> A MultiFactor::LinkMap data.frame S7_object: 200 rows.
#> card straight
#> 1 Ace♥️ Ace to 5
#> 2 2♥️ Ace to 5
#> 3 3♥️ Ace to 5
#> 4 4♥️ Ace to 5
#> 5 5♥️ Ace to 5
#> 6 Ace♠️ Ace to 5
#> 7 2♠️ Ace to 5
#> 8 3♠️ Ace to 5
#> 9 4♠️ Ace to 5
#> 10 5♠️ Ace to 5
#> + 190 more rows. Use `print(n = ...)` to see more rows.
#>
#> @ levels: 2 variables:
#> $ card : 52 Levels: Ace♥️ ... King♣️
#> $ straight : 10 Levels: Ace to 5 ... Royal straight
#>
#> @ metadata: 5 variables:
#> List of 5
#> $ observed : logi TRUE FALSE FALSE FALSE FALSE FALSE ...
#> $ set_count: int 1 1 1 1 1 1 1 1 1 1 ...
#> $ set_size : int 20 20 20 20 20 20 20 20 20 20 ...
#> $ coverage : num 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 ...
#> $ complete : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
test_enrichment(result)
#> expected observed fold log_fold p.value p.adj
#> Ace to 5 0.09615385 0.05 0.52 -0.94341647 0.922516699 1.00000000
#> 2 to 6 0.09615385 0.00 0.00 -Inf 1.000000000 1.00000000
#> 3 to 7 0.09615385 0.00 0.00 -Inf 1.000000000 1.00000000
#> 4 to 8 0.09615385 0.00 0.00 -Inf 1.000000000 1.00000000
#> 5 to 9 0.09615385 0.00 0.00 -Inf 1.000000000 1.00000000
#> 6 to 10 0.09615385 0.05 0.52 -0.94341647 0.922516699 1.00000000
#> 7 to Jack 0.09615385 0.10 1.04 0.05658353 0.645790624 1.00000000
#> 8 to Queen 0.09615385 0.15 1.56 0.64154603 0.283184043 0.94394681
#> 9 to King 0.09615385 0.20 2.08 1.05658353 0.065620094 0.32810047
#> Royal straight 0.09615385 0.25 2.60 1.37851162 0.005965463 0.05965463