For a given PowerRelation
object create a relations::relation()
object.
Usage
powerRelationMatrix(
powerRelation,
domainNames = c("pretty", "numericPrec", "numeric")
)
# S3 method for PowerRelation
as.relation(x, ...)
Arguments
- powerRelation
A
PowerRelation
object created byPowerRelation()
oras.PowerRelation()
- domainNames
How should the row and column names be formatted?
pretty
: Coalitions such as c(1,2) are formatted as 12. To ensure that it's correctly sorted alphabetically, every name is preceded by a certain amount of the invisible Unicode character \u200bnumericPrec
: Coalitions such as c(1,2) are formatted as 1{12}, the number in front of the curly brace marking its sorted spot. While less pretty, it won't use Unicode characters.numeric
: Drop coalition names, only count from 1 upwards. Each number corresponds to the index in TODOpowerRelation$rankingCoalitions
function(x)
: A custom function that is passed a number from1
throughlength(powerRelation$rankingCoalitions)
. Must return acharacter
object.
- x
A
PowerRelation
object- ...
Further parameters (ignored)
Value
relations::relation()
object to the corresponding power relation.
Details
Turn a PowerRelation
object into a relations::relation()
object. The incidence matrix can be viewed with
relations::relation_incidence()
.
The columns and rows of a PowerRelation
object are ordered by TODO powerRelation$rankingCoalitions
.
The relations
package automatically sorts the columns and rows by their domain names, which is the reason the
parameter domainNames
is included. This way we ensure that the columns and rows are sorted by
the order of the power relation.
Cycles
A PowerRelation
object is defined as being transitive. If a power relation includes a cycle,
meaning that the same coalition appears twice in the ranking, all coalitions within that cycle will be considered
to be indifferent from one another.
For example, given the power relation \(1 \succ 2 \succ 3 \succ 1 \succ 12\), the relation is somewhat equivalent to \(1 \sim 2 \sim 3 \succ 12\). There is no way to check for cycles in the incidence matrix only.
Call transitiveClosure()
to remove cycles in a PowerRelation
object.
Examples
pr <- as.PowerRelation("12 > 1 > 2")
relation <- powerRelationMatrix(pr)
# do relation stuff
# Incidence matrix
# 111
# 011
# 001
relations::relation_incidence(relation)
#> Incidences:
#> 12 1 2
#> 12 1 1 1
#> 1 0 1 1
#> 2 0 0 1
# all TRUE
stopifnot(all(
relations::relation_is_acyclic(relation),
relations::relation_is_antisymmetric(relation),
relations::relation_is_linear_order(relation),
relations::relation_is_complete(relation),
relations::relation_is_reflexive(relation),
relations::relation_is_transitive(relation)
))
# a power relation where coalitions {1} and {2} are indifferent
pr <- as.PowerRelation("12 > (1 ~ 2)")
relation <- powerRelationMatrix(pr)
# Incidence matrix
# 111
# 011
# 011
relations::relation_incidence(relation)
#> Incidences:
#> 12 1 2
#> 12 1 1 1
#> 1 0 1 1
#> 2 0 1 1
# FALSE
stopifnot(!any(
relations::relation_is_acyclic(relation),
relations::relation_is_antisymmetric(relation),
relations::relation_is_linear_order(relation)
))
# TRUE
stopifnot(all(
relations::relation_is_complete(relation),
relations::relation_is_reflexive(relation),
relations::relation_is_transitive(relation)
))
# a pr with cycles
pr <- suppressWarnings(as.PowerRelation("12 > 1 > 2 > 1"))
relation <- powerRelationMatrix(pr)
# Incidence matrix
# 1111
# 0111
# 0111
# 0111
relations::relation_incidence(relation)
#> Incidences:
#> 12 1 2 1
#> 12 1 1 1 1
#> 1 0 1 1 1
#> 2 0 1 1 1
#> 1 0 1 1 1
# custom naming convention
relation <- powerRelationMatrix(
pr,
function(x) paste0(letters[x], ":", paste(pr$rankingCoalitions[[x]], collapse = "|"))
)
relations::relation_incidence(relation)
#> Incidences:
#> a: b: c: d:
#> a: 1 1 1 1
#> b: 0 1 1 1
#> c: 0 1 1 1
#> d: 0 1 1 1
# Incidences:
# a:1|2 b:1 c:2 d:1
# a:1|2 1 1 1 1
# b:1 0 1 1 1
# c:2 0 1 1 1
# d:1 0 1 1 1