Skip to contents

Sort a full object of class assoc_scores based on some criterion. It's the same that print does but with a bit more flexibility.

Usage

# S3 method for assoc_scores
sort(x, decreasing = TRUE, sort_order = "none", ...)

Arguments

x

Object of class assoc_scores.

decreasing

Boolean value.

If sort_order = "alpha" and decreasing = FALSE, the rows will follow the alphabetic order of the types. If decreasing = TRUE instead, it will follow an inverted alphabetic order (from Z to A). This follows the behavior of applying sort() to a character vector: note that the default value is probably not what you would want.

If sort_order is a column for which a lower value indicates a higher association, i.e. it's a form of p-value, decreasing = TRUE will place lower values on top and higher values at the bottom.

For any other column, decreasing = TRUE will place higher values on top and lower values at the bottom.

sort_order

Criterion to order the rows. Possible values are "alpha" (meaning that the items are to be sorted alphabetically), "none" (meaning that the items are not to be sorted) and any present column name.

...

Additional arguments.

Value

An object of class assoc_scores.

Examples

a <- c(10,    30,    15,    1)
b <- c(200, 1000,  5000,  300)
c <- c(100,   14,    16,    4)
d <- c(300, 5000, 10000, 6000)
types <- c("four", "fictitious", "toy", "examples")
(scores <- assoc_abcd(a, b, c, d, types = types))
#> Association scores (types in list: 4)
#>         type  a    PMI G_signed|   b   c     d dir  exp_a DP_rows
#> 1       four 10 -1.921  -45.432| 200 100   300  -1 37.869  -0.202
#> 2 fictitious 30  2.000   56.959|1000  14  5000   1  7.498   0.026
#> 3        toy 15  0.536    2.984|5000  16 10000   1 10.343   0.001
#> 4   examples  1  2.067    1.473| 300   4  6000   1  0.239   0.003
#> <number of extra columns to the right: 7>
#> 

print(scores, sort_order = "PMI")
#> Association scores (types in list: 4, sort order criterion: PMI)
#>         type  a    PMI G_signed|   b   c     d dir  exp_a DP_rows
#> 1   examples  1  2.067    1.473| 300   4  6000   1  0.239   0.003
#> 2 fictitious 30  2.000   56.959|1000  14  5000   1  7.498   0.026
#> 3        toy 15  0.536    2.984|5000  16 10000   1 10.343   0.001
#> 4       four 10 -1.921  -45.432| 200 100   300  -1 37.869  -0.202
#> <number of extra columns to the right: 7>
#> 
sorted_scores <- sort(scores, sort_order = "PMI")
sorted_scores
#> Association scores (types in list: 4)
#>         type  a    PMI G_signed|   b   c     d dir  exp_a DP_rows
#> 1   examples  1  2.067    1.473| 300   4  6000   1  0.239   0.003
#> 2 fictitious 30  2.000   56.959|1000  14  5000   1  7.498   0.026
#> 3        toy 15  0.536    2.984|5000  16 10000   1 10.343   0.001
#> 4       four 10 -1.921  -45.432| 200 100   300  -1 37.869  -0.202
#> <number of extra columns to the right: 7>
#> 

sort(scores, decreasing = FALSE, sort_order = "PMI")
#> Association scores (types in list: 4)
#>         type  a    PMI G_signed|   b   c     d dir  exp_a DP_rows
#> 1       four 10 -1.921  -45.432| 200 100   300  -1 37.869  -0.202
#> 2        toy 15  0.536    2.984|5000  16 10000   1 10.343   0.001
#> 3 fictitious 30  2.000   56.959|1000  14  5000   1  7.498   0.026
#> 4   examples  1  2.067    1.473| 300   4  6000   1  0.239   0.003
#> <number of extra columns to the right: 7>
#>