inst/doc/Introduction.R

## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(ineq.2d)

## -----------------------------------------------------------------------------
data(us16)
str(us16)

## -----------------------------------------------------------------------------
theil.2d(us16, "hitotal", "sex", "hitotal", "hpopwgt")

## -----------------------------------------------------------------------------
scv.2d(us16, "hitotal", "sex", "hitotal", "hpopwgt")

## -----------------------------------------------------------------------------
theil.2d(us16, "hitotal", "sex", c("hilabour", "hicapital", 
                                   "hitransfer"), "hpopwgt")

## -----------------------------------------------------------------------------
scv.2d(us16, "hitotal", "sex", c("hilabour", "hicapital", 
                                 "hitransfer"), "hpopwgt")

## -----------------------------------------------------------------------------
theil.2d(us16, "hitotal", "sex", c("hilabour", "hicapital", 
                                   "hitransfer"), "hpopwgt", perc = TRUE)

scv.2d(us16, "hitotal", "sex", c("hilabour", "hicapital", 
                                 "hitransfer"), "hpopwgt", perc = TRUE)

## -----------------------------------------------------------------------------
theil1 <- theil.2d(us16, "hitotal", "sex", c("hilabour", "hicapital", 
                                             "hitransfer"), "hpopwgt")
sum(theil1[,-1])

scv1 <- scv.2d(us16, "hitotal", "sex", c("hilabour", "hicapital", 
                                         "hitransfer"), "hpopwgt")
sum(scv1[,-1])

## -----------------------------------------------------------------------------
theil.2d(us16, "hitotal", weights = "hpopwgt")

scv.2d(us16, "hitotal", weights = "hpopwgt")

## -----------------------------------------------------------------------------
us16$cohort <- 0
us16[us16$age < 25, "cohort"] <- "t24"
us16[us16$age >= 25 & us16$age < 50, "cohort"] <- "f25t49"
us16[us16$age >= 50 & us16$age < 75, "cohort"] <- "f50t74"
us16[us16$age >= 75, "cohort"] <- "f75"

## -----------------------------------------------------------------------------
theil.2d(us16, "hitotal", "cohort", c("hilabour", "hicapital", 
                                      "hitransfer"), "hpopwgt")

scv.2d(us16, "hitotal", "cohort", c("hilabour", "hicapital", 
                                    "hitransfer"), "hpopwgt")

Try the ineq.2d package in your browser

Any scripts or data that you put into this service are public.

ineq.2d documentation built on June 7, 2023, 6:22 p.m.