powerRelationMatrix {socialranking} | R Documentation |
Create relation matrix
Description
For a given PowerRelation
object create a relations::relation()
object.
Usage
powerRelationMatrix(
powerRelation,
domainNames = c("pretty", "numericPrec", "numeric")
)
## S3 method for class 'PowerRelation'
as.relation(x, ...)
Arguments
powerRelation |
A |
domainNames |
How should the row and column names be formatted?
|
x |
A |
... |
Further parameters (ignored) |
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.
Value
relations::relation()
object to the corresponding 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.
See Also
Examples
pr <- as.PowerRelation("12 > 1 > 2")
relation <- powerRelationMatrix(pr)
# do relation stuff
# Incidence matrix
# 111
# 011
# 001
relations::relation_incidence(relation)
# 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)
# 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)
# custom naming convention
relation <- powerRelationMatrix(
pr,
function(x) paste0(letters[x], ":", paste(pr$rankingCoalitions[[x]], collapse = "|"))
)
relations::relation_incidence(relation)
# 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