MyNixOS website logo
Description

Calculate Diversity and Segregation Indices.

Implements common measures of diversity and spatial segregation. This package has tools to compute the majority of measures are reviewed in Massey and Denton (1988) <doi:10.2307/2579183>. Multiple common measures of within-geography diversity are implemented as well. All functions operate on data frames with a 'tidyselect' based workflow.

divseg

R-CMD-check

divseg implements common measures of diversity (within-geography) and segregation (across-geographies).

Installation

You can install the released version of divseg from GitHub with:

remotes::install_github("christopherkenny/divseg")

Example

The basic workflow relies on a tibble where each row represents a geography and has columns that represent some form of population data.

library(divseg)
#> 
#> Attaching package: 'divseg'
#> The following object is masked from 'package:base':
#> 
#>     interaction

divseg comes with two example datasets. de_county contains 2010 Census data on the counties in Delaware. de_tract likewise has 2010 Census data on the tracts in Delaware.

data('de_county')
data('de_tract')

A pretty standard function call returns a vector, where the first entry is a tibble and the second is tidyselect language.

ds_blau(.data = de_county, .cols = starts_with('pop_')) 
#> [1] 0.5155228 0.5570435 0.4052769

More importantly, if you specify an argument to .name, all functions are pipe-able.

de_county %>% 
  ds_blau(starts_with('pop_'), .name = 'blau') %>% 
  ds_delta(starts_with('pop_'), .name = 'delta') %>% 
  dplyr::relocate(blau, delta)
#> Simple feature collection with 3 features and 22 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -75.78866 ymin: 38.45101 xmax: -75.04894 ymax: 39.83901
#> Geodetic CRS:  NAD83
#> # A tibble: 3 x 23
#>    blau delta GEOID NAME     pop pop_white pop_black pop_hisp pop_aian pop_asian
#>   <dbl> <dbl> <chr> <chr>  <dbl>     <dbl>     <dbl>    <dbl>    <dbl>     <dbl>
#> 1 0.516 0.345 10001 Kent~ 162310    105891     37812     9346      916      3266
#> 2 0.557 0.345 10003 New ~ 538479    331836    124426    46921      984     23132
#> 3 0.405 0.345 10005 Suss~ 197145    149025     24544    16954      924      1910
#> # ... with 13 more variables: pop_nhpi <dbl>, pop_other <dbl>, pop_two <dbl>,
#> #   vap <dbl>, vap_white <dbl>, vap_black <dbl>, vap_hisp <dbl>,
#> #   vap_aian <dbl>, vap_asian <dbl>, vap_nhpi <dbl>, vap_other <dbl>,
#> #   vap_two <dbl>, geometry <MULTIPOLYGON [°]>

Each function has a partner that can go inside calls to dplyr::mutate() by dropping the ds_ prefix:

de_county %>% 
  dplyr::mutate(herf = hhi(starts_with('pop_'))) %>% 
  dplyr::relocate(herf)
#> Simple feature collection with 3 features and 21 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -75.78866 ymin: 38.45101 xmax: -75.04894 ymax: 39.83901
#> Geodetic CRS:  NAD83
#> # A tibble: 3 x 22
#>    herf GEOID NAME           pop pop_white pop_black pop_hisp pop_aian pop_asian
#>   <dbl> <chr> <chr>        <dbl>     <dbl>     <dbl>    <dbl>    <dbl>     <dbl>
#> 1 0.484 10001 Kent Count~ 162310    105891     37812     9346      916      3266
#> 2 0.443 10003 New Castle~ 538479    331836    124426    46921      984     23132
#> 3 0.595 10005 Sussex Cou~ 197145    149025     24544    16954      924      1910
#> # ... with 13 more variables: pop_nhpi <dbl>, pop_other <dbl>, pop_two <dbl>,
#> #   vap <dbl>, vap_white <dbl>, vap_black <dbl>, vap_hisp <dbl>,
#> #   vap_aian <dbl>, vap_asian <dbl>, vap_nhpi <dbl>, vap_other <dbl>,
#> #   vap_two <dbl>, geometry <MULTIPOLYGON [°]>
Metadata

Version

0.0.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows