Title: | Partially Ordered Sets in R |
---|---|
Description: | Provides a set of basic tools for generating, analyzing, summarizing and visualizing finite partially ordered sets. In particular, it implements flexible and very efficient algorithms for the extraction of linear extensions and for the computation of mutual ranking probabilities and other user-defined functionals, over them. The package is meant as a computationally efficient "engine", for the implementation of data analysis procedures, on systems of multidimensional ordinal indicators and partially ordered data, in the spirit of Fattore, M. (2016) "Partially ordered sets and the measurement of multidimensional ordinal deprivation", Social Indicators Research <DOI:10.1007/s11205-015-1059-6>, and Fattore M. and Arcagni, A. (2018) "A reduced posetic approach to the measurement of multidimensional ordinal deprivation", Social Indicators Research <DOI:10.1007/s11205-016-1501-4>. |
Authors: | Alberto Arcagni [aut, cre], Alessandro Avellone [aut], Marco Fattore [aut] |
Maintainer: | Alberto Arcagni <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1.4 |
Built: | 2024-10-31 18:37:11 UTC |
Source: | https://github.com/cran/POSetR |
Provides a set of basic tools for generating, analyzing, summarizing and visualizing finite partially ordered sets. In particular, it implements flexible and very efficient algorithms for the extraction of linear extensions and for the computation of mutual ranking probabilities and other user-defined functionals, over them. The package is meant as a computationally efficient "engine", for the implementation of data analysis procedures, on systems of multidimensional ordinal indicators and partially ordered data, in the spirit of Fattore, M. (2016) "Partially ordered sets and the measurement of multidimensional ordinal deprivation", Social Indicators Research <DOI:10.1007/s11205-015-1059-6>, and Fattore M. and Arcagni, A. (2018) "A reduced posetic approach to the measurement of multidimensional ordinal deprivation", Social Indicators Research <DOI:10.1007/s11205-016-1501-4>.
Alberto Arcagni [aut, cre], Alessandro Avellone [aut], Marco Fattore [aut]
The function produces an antichain from the vector of elements' labels elements
.
If elements
is a numeric vector, it is first coerced to a character vector.
An antichain is a poset with no comparabilities, therefore the order of the labels in
elements
does not matter.
antiChain(elements)
antiChain(elements)
elements |
a vector of characters with elements' labels. |
an environment of class poset
.
function poset
for more details and to create a generic poset and function chain
to create a complete order.
antiChain(LETTERS[1:5])
antiChain(LETTERS[1:5])
The function produces a complete order from the vector of elements' labels elements
.
If elements
is a numeric vector, it is first coerced to a character vector.
A complete order is a poset where all of the elements are comparable; the order of the labels in elements
defines their position in the chain, from bottom to top.
chain(elements)
chain(elements)
elements |
a vector of characters listing the elements' labels. |
an environment of class poset
.
function poset
for more details and to create a generic poset and function antiChain
to create an anti-chain.
chain(LETTERS[1:5])
chain(LETTERS[1:5])
The function returns the cover matrix for objects of class poset
.
coverMatrix(x)
coverMatrix(x)
x |
an object of class |
a logical square matrix.
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) coverMatrix(p)
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) coverMatrix(p)
The function returns the incidence matrix for objects of class poset
.
incidenceMatrix(x)
incidenceMatrix(x)
x |
an object of class |
a logical square matrix.
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) incidenceMatrix(p)
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) incidenceMatrix(p)
Given two posets X
and Y
on the same set, intersection
returns the poset Z defined by a < b
in Z
if and only if a < b
in X
and a < b
in Y
.
intersection(x, y) x %it% y
intersection(x, y) x %it% y
x |
an S4 object of class |
y |
an S4 object of class |
an S4 object of class Rcpp_POSet
, see poset
for details
Davey BA, Priestley HA (2002). Introduction to lattices and order. Cambridge university press.
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) plot(p) dom <- matrix(c( "a", "b", "c", "b", "d", "b" ), ncol = 2, byrow = TRUE) q <- poset(x = dom) plot(q) plot(p %it% q)
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) plot(p) dom <- matrix(c( "a", "b", "c", "b", "d", "b" ), ncol = 2, byrow = TRUE) q <- poset(x = dom) plot(q) plot(p %it% q)
"LEapply"
is composed of three main elements: (i) the linear extensions generator, (ii) the application of the argument functions to the linear extensions and (iii) the computation of the averages of the results, for each function separately; see Fattore M (2016).
“Partially ordered sets and the measurement of multidimensional ordinal deprivation.”
Social Indicators Research, 128(2), 835–858..
LEapply(x, ...) ## S3 method for class 'poset' LEapply( x, FUN = "MutualRankingProbability", ..., generator = c("AllLE", "BubleyDyer"), bubleydyer.precision = 10, bubleydyer.nit = NULL, bubleydyer.progressBar = TRUE, degrees = NULL )
LEapply(x, ...) ## S3 method for class 'poset' LEapply( x, FUN = "MutualRankingProbability", ..., generator = c("AllLE", "BubleyDyer"), bubleydyer.precision = 10, bubleydyer.nit = NULL, bubleydyer.progressBar = TRUE, degrees = NULL )
x |
an environment of class |
... |
optional arguments to |
FUN |
the function, or a list of functions, to be applied to each linear extension: see 'Details'. |
generator |
a string specifying the method used to generate the linear extensions. The default value is |
bubleydyer.precision |
considered only if |
bubleydyer.nit |
considered only if |
bubleydyer.progressBar |
logical that indicates whether to show a text progress bar or not |
degrees |
to generate the lexicographic linear extensions of a product order, the poset |
Argument FUN
must be either a function or a list of functions, each one depending on a vector of characters representing the names of the elements of the poset.
If degrees
is not NULL
but a numerical vector as long as the number of elements in the poset, the poset elements are considered as ordinal variables. Therefore degrees
represents their number of degrees that are represented as integer numbers starting from 0. In this case, LEapply
generates the lexicographical linear extensions of the product order of the ordeinal variables. Its elements are called profiles and they are obtained by the combination of the degrees of variables separated by a dash. For details about lexicographical linear extensions and profiles see Fattore M, Arcagni A (2018).
“A reduced posetic approach to the measurement of multidimensional ordinal deprivation.”
Social Indicators Research, 136(3), 1053–1070..
Some functions are already implemented in the C++
library and they can be called by their names. Currently, such functions are "MutualRankingProbability"
, "Separation"
, and "AverageHeight"
.
Each function in FUN
must return a numerical or logical matrix.
Each function can depend on additional arguments that can be passed through ...
; such additional arguments must be the same for all the functions in the list.
Argument generator
specifies the linear extension generation algorithm. The available generators are "AllLE"
, that produces all of the linear extensions of the input poset, and "BubleyDyer"
, which samples uniformly from the set of linear extensions, through an MCMC algorithm (Bubley and Dyer 1999).
The average values of the argument functions FUN
over the set of linear extensions (or lexicographic ones if degrees
argument is not NULL
).
Bubley R, Dyer M (1999). “Faster random generation of linear extensions.” Discrete mathematics, 201(1-3), 81–88.
Fattore M (2016). “Partially ordered sets and the measurement of multidimensional ordinal deprivation.” Social Indicators Research, 128(2), 835–858.
Fattore M, Arcagni A (2018). “A reduced posetic approach to the measurement of multidimensional ordinal deprivation.” Social Indicators Research, 136(3), 1053–1070.
Habib M, Medina R, Nourine L, Steiner G (2001). “Efficient algorithms on distributive lattices.” Discrete Applied Mathematics, 110(2-3), 169–187.
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) ## Not run: LEapply( x = p, FUN = "MutualRankingProbability", generator = "AllLE", degrees = c(3, 2, 3, 2) ) a_rank_dist <- function(le) { return(matrix(le == "a")) } LEapply(x = p, FUN = a_rank_dist) ## End(Not run)
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) ## Not run: LEapply( x = p, FUN = "MutualRankingProbability", generator = "AllLE", degrees = c(3, 2, 3, 2) ) a_rank_dist <- function(le) { return(matrix(le == "a")) } LEapply(x = p, FUN = a_rank_dist) ## End(Not run)
plot
produces an igraph
object and shows the Hasse diagram.
## S3 method for class 'poset' plot( x, vertex.color = rgb(1, 1, 1, 1), vertex.label = x$pointer$elements(), vertex.label.color = rgb(0, 0, 0, 1), vertex.label.family = "sans", edge.color = rgb(0, 0, 0, 1), edge.label = NA, edge.arrow.mode = "-", asp = 0, ..., equispaced = FALSE, show = TRUE )
## S3 method for class 'poset' plot( x, vertex.color = rgb(1, 1, 1, 1), vertex.label = x$pointer$elements(), vertex.label.color = rgb(0, 0, 0, 1), vertex.label.family = "sans", edge.color = rgb(0, 0, 0, 1), edge.label = NA, edge.arrow.mode = "-", asp = 0, ..., equispaced = FALSE, show = TRUE )
x |
an S4 object of class |
vertex.color |
argument of the |
vertex.label |
argument of the |
vertex.label.color |
argument of the |
vertex.label.family |
argument of the |
edge.color |
argument of the |
edge.label |
argument of the |
edge.arrow.mode |
argument of the |
asp |
argument of the |
... |
additional plotting parameters, see |
equispaced |
logical, if |
show |
logical, if |
plot.poset
computes the cover relation and produces the corresponding Directed Acyclic Graph (DAG), as an igraph
object, returned as invisible output.
Function layout_with_sugiyama
generates the DAG layout with edges oriented from top to bottom. When equispaced=TRUE
, nodes on the same Hasse diagram level are horizontally equispaced.
The Hasse diagram is displayed by a call to plot.igraph
(some default argument values are set to get a cleaner plot, by exploiting Hasse diagram properties.
Setting show = FALSE
produces the igraph
object, without showing the Hasse diagram.
Note that
an igraph
object.
poset
, igraph
, igraph.plotting
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) hasse <- plot(p) class(hasse)
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) hasse <- plot(p) class(hasse)
Function poset
creates a poset from a dominance list. x
argument is a two-column matrix, each row defines a pair of comparable elements, where the element in the first column is dominated by or coincide with the element in the second column. If the elements of x
are numeric, they are first coerced to character and used as elements labels.
poset(x = NULL, elements = unique(as.character(x)))
poset(x = NULL, elements = unique(as.character(x)))
x |
an object of class |
elements |
a vector of characters listing all the labels of the elements. |
A partial order relation is reflexive, transitive and anti-symmetric. Given the dominance list provided by the user, the function produces the smallest poset comprising them (reflexive and transitive closure); in case the dominances provided by the user imply non-trivial cicles, violating anti-simmetry, the function returns an error.
By default elements
is equal to all the different labels available in x
.
If some elements are incomparable, list all of the elements in elements
or include self-comparabilities in x
. Notice that antichains can be created in a simpler way, by function
antiChain
.
an environment of class poset
; this class contains a pointer with different C++ methods used by other functions of the package.
in the package are available functions that simply the creation of particular posets: antiChain
to create a poset without comparabilities,
chain
to create a complete order,
poset_from_dataframe
to create a poset from a statistical population.
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) poset(x = dom) poset(x = dom, elements = letters[1:5])
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) poset(x = dom) poset(x = dom, elements = letters[1:5])
This function generates a poset from an object x
of class data.frame
that lists by rows all the observations in a statistical population and by columns the values of different orderable variables (i.e. vectors of class ordered
or numeric
).
poset_from_dataframe(x, collapse = "-")
poset_from_dataframe(x, collapse = "-")
x |
an object of class |
collapse |
an object of class |
The poset is generated through the component-wise comparability relation (Davey and Priestley 2002). Note that some observations may have the same profile (i.e. the same values for all the variables) therefore they have to be included into the same element of the poset, than the label of such element correspond to the labels of the statistical units separated by the collapse
character.
an S4 object of class Rcpp_POSet
; this class contains different C++ methods used by other functions of the package.
Davey BA, Priestley HA (2002). Introduction to lattices and order. Cambridge university press.
set <- ordered(letters[1:5]) set.seed(0) n <- 30 x <- data.frame( A = sample(set, n, replace = TRUE), B = sample(set, n, replace = TRUE), C = sample(set, n, replace = TRUE) ) p <- poset_from_dataframe(x, collapse = ",") plot(p, equispaced = TRUE, vertex.frame.color = "lightgray", vertex.color = "lightgray")
set <- ordered(letters[1:5]) set.seed(0) n <- 30 x <- data.frame( A = sample(set, n, replace = TRUE), B = sample(set, n, replace = TRUE), C = sample(set, n, replace = TRUE) ) p <- poset_from_dataframe(x, collapse = ",") plot(p, equispaced = TRUE, vertex.frame.color = "lightgray", vertex.color = "lightgray")
This function generates a poset from an objectg
. The function checks if the graph is directed and cyclic in oreder it represent the cover-relation.
poset_from_igraph(g)
poset_from_igraph(g)
g |
an |
Note that the Hasse diagram represents the cover relation from the top to the bottom, therefore its representation is the opposite of the plot of the graph with Sugiyama layout.
an environment of class poset
.
Davey BA, Priestley HA (2002). Introduction to lattices and order. Cambridge university press.
library(igraph) g <- make_tree(10) ly <- igraph::layout_with_sugiyama(g)$layout g$layout <- ly plot(g) p <- poset_from_igraph(g) plot(p)
library(igraph) g <- make_tree(10) ly <- igraph::layout_with_sugiyama(g)$layout g$layout <- ly plot(g) p <- poset_from_igraph(g) plot(p)
This function generates a poset from an incidence matrix x
. Such matrix is a named and logical
that is TRUE
if the row element is dominated by the column one, FALSE
otherwise. Such incidence relation should be reflexive, anti-symmetric, and transitive..
poset_from_incidence(x)
poset_from_incidence(x)
x |
a |
an environment of class poset
.
Davey BA, Priestley HA (2002). Introduction to lattices and order. Cambridge university press.
x <- c( TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE ) x <- matrix(x, nrow = 6, ncol = 6) rownames(x) <- colnames(x) <- LETTERS[1:6] p <- poset_from_incidence(x) plot(p)
x <- c( TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE ) x <- matrix(x, nrow = 6, ncol = 6) rownames(x) <- colnames(x) <- LETTERS[1:6] p <- poset_from_incidence(x) plot(p)
print
prints the list of poset elements and all of the strict dominances in it.
## S3 method for class 'poset' print(x, max = NULL, ...)
## S3 method for class 'poset' print(x, max = NULL, ...)
x |
an object of class |
max |
a non-null value for max specifies the approximate maximum number of entries to be printed. The default, NULL, uses |
... |
further arguments passed to or from other methods. |
nothing
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) print(p)
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) print(p)
print
prints the poset summary.
## S3 method for class 'summary_poset' print(x, ...)
## S3 method for class 'summary_poset' print(x, ...)
x |
an object of class |
... |
further arguments passed to or from other methods. |
nothing
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) summary(p) summary(chain(1:4)) summary(antiChain(LETTERS[1:5]))
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) summary(p) summary(chain(1:4)) summary(antiChain(LETTERS[1:5]))
The function returns the product poset of two posets X
and Y
.
productOrder(x, y, sep = "-") x %po% y
productOrder(x, y, sep = "-") x %po% y
x |
an S4 object of class |
y |
an S4 object of class |
sep |
a character object indicating the separator to be used to paste profiles names. |
an environment of class poset
, see poset
for details
Davey BA, Priestley HA (2002). Introduction to lattices and order. Cambridge university press.
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) q <- chain(1:3) plot(p %po% q)
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) q <- chain(1:3) plot(p %po% q)
Method of the summary
function for objects of class poset
.
## S3 method for class 'poset' summary(object, ...)
## S3 method for class 'poset' summary(object, ...)
object |
an object of class |
... |
further arguments passed to or from other methods. |
An S3 object of class summary_poset
listing and counting the poset elements, their strict dominances and their incomparabilities.
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) summary(p) summary(chain(1:4)) summary(antiChain(LETTERS[1:5]))
dom <- matrix(c( "a", "b", "c", "b", "b", "d" ), ncol = 2, byrow = TRUE) p <- poset(x = dom) summary(p) summary(chain(1:4)) summary(antiChain(LETTERS[1:5]))