knitr::opts_chunk$set( collapse = TRUE, message = FALSE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
A shortcut package with formulas for several different indices of segregation. rsegregation is designed to fit into the tidyverse framework, particularly dplyr.
<!-- 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
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))
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)
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)
This package is free and open source software, licensed under GPL-3.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.