R/hasse.R

Defines functions hasse

Documented in hasse

#' Plot the Hasse diagram of a list of Lorenz or TIP curves
#'
#' hasse plots the Hasse diagram of a list of (ordinary, generalized or
#' absolute) Lorenz or TIP curves
#'
#' A Hasse diagram is a vizualization of the strict partial order generated by
#' the Lorenz curve comparisons.
#'
#' @param object A list of Lorenz curve objects.
#' @param above.p Start comparison of this population fraction.
#' @param lor.type For lorenz curves, gives the type of Lorenz curve.
#' @param ... Additional arguments to dominates.lorenz or dominates.tip.
#' @return A plot.
#' @author Markus Jantti \email{markus.jantti@@iki.fi}
#' @seealso \code{\link{lorenz}}, \code{\link{tip}}.
#' @references
#'
#' \insertRef{atkinsonsmeedingandrainwater1995}{incdist}
#'
#' @examples
#'
#' lor.1 <- lorenz(rep(c(3, 3, 3, 3, 3), each=20), q = FALSE)
#' lor.2 <- lorenz(rep(c(1, 2, 3, 4, 5), each=20), q = FALSE)
#' lor.3 <- lorenz(rep(c(1, 1, 3, 4, 6), each=20), q = FALSE)
#' lor.4 <- lorenz(rep(c(1.5, 2, 3, 4, 5.5), each=20), q = FALSE)
#' lor.5 <- lorenz(rep(c(1, 1, 1, 5, 7), each=20), q = FALSE)
#' hasse(list("a"=lor.1, "b"=lor.2, "c"=lor.3, "d"=lor.4, "e"=lor.5))
#'
#'
#' @importFrom relations relation
#' @export hasse
hasse <- function(object, above.p=.1, lor.type="ord", ...)
{
    ## test if appropiate kind of object
    if(!is.list(object))
      stop("Object is not a list!")
    if(!(all(sapply(object, is.lorenz))|all(sapply(object, is.tip))))
      stop("Some element  is not a Lorenz or TIP curve!")
    ## do either tip or lorenz
    if(is.lorenz(object[[1]]))
        ## lorenz
        dmat <- t(dominates.lorenz_list(object, lor.type=lor.type, above.p=above.p, ...))
    else
        ## tip
        dmat <- t(dominates.tip_list(object, above.p=above.p, ...))
    r <- relation(incidence=dmat)
    plot(r, main = "")
}

## this function takes a lorenz or tip list and plots the
## Hasse diagram
## I would like to develop this to rely on ggplot2 instead.
mjantti/incdist documentation built on Aug. 23, 2023, 5:33 p.m.