knitr::opts_chunk$set(
  collapse = TRUE,
  message = FALSE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

rsegregation

Travis build status Codecov test coverage R build status

A shortcut package with formulas for several different indices of segregation. rsegregation is designed to fit into the tidyverse framework, particularly dplyr.

Installation

<!-- You can install the released version of rsegregation from CRAN with:

install.packages("rsegregation")

--> The development version from GitHub can be installed with:

``` {r eval=FALSE} # install.packages("devtools") devtools::install_github("arthurgailes/rsegregation")

## Usage

rsegregation depends upon dplyr (>1.0.0), and can be used with it. To return a single divergence score for Bay Area County:

### Divergence and Entropy

#### Calculate the divergence score for the entire dataset

rsegregation can work with base r, or within several dplyr verbs:
```r
library(rsegregation)
library(dplyr)
## included dataset of Bay Area Census tracts
# Using dplyr
bay_divergence <- bay_race %>% 
  summarize(bay_divergence = divergence(white,black,asian, hispanic, all_other,
    population=total_pop, summed = T))

# Using base r
bay_divergence <- divergence(bay_race[c('white','black','asian', 'hispanic', 'all_other')], 
  population=bay_race$total_pop, summed = T)
# or
bay_divergence <- divergence(bay_race$white,bay_race$black,bay_race$asian, 
  bay_race$hispanic, bay_race$all_other, population=bay_race$total_pop, summed = T)
# all return the same result:
bay_divergence

Calculate divergence by group

Using the included Bay Area dataset of 2010 racial groups, divergence can be calculated by county using dplyr::group_by().

#library(dplyr)
group_by(bay_race, county) %>% 
  summarize(bay_divergence = divergence(white,black,asian, hispanic, all_other, 
    population=total_pop, summed = T))

By-observation divergence scores

Divergence and entropy are both calculated rowwise by default (summed = FALSE).

bay_entropy <- bay_race
bay_entropy$entropy <- entropy(bay_race[c('white','black','asian',
  'hispanic','all_other')], population=bay_race$total_pop, summed = F)
head(bay_entropy)

Miscellaneous

Dataframes should be formatted as long on geographic observations (e.g. tracts), but wide on group observations (e.g. races), as in the included dataset of the San Francisco Bay Area.

head(bay_race)

Future development:

License

This package is free and open source software, licensed under GPL-3.



arthurgailes/rsegregation documentation built on May 23, 2021, 6:33 a.m.