| Title: | Calculate Diversity and Segregation Indices | 
| Version: | 0.1.0 | 
| Description: | 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. | 
| License: | MIT + file LICENSE | 
| Encoding: | UTF-8 | 
| LazyData: | true | 
| RoxygenNote: | 7.3.2 | 
| BugReports: | https://github.com/christopherkenny/divseg/issues | 
| URL: | https://github.com/christopherkenny/divseg/, https://christophertkenny.com/divseg/ | 
| Suggests: | roxygen2, testthat (≥ 3.0.0) | 
| Imports: | sf (≥ 1.0.0), rlang (≥ 0.4.11), dplyr, tidyselect, tibble, units | 
| Depends: | R (≥ 4.1.0) | 
| Config/testthat/edition: | 3 | 
| NeedsCompilation: | no | 
| Packaged: | 2025-09-02 21:35:27 UTC; chris | 
| Author: | Christopher T. Kenny | 
| Maintainer: | Christopher T. Kenny <ctkenny@proton.me> | 
| Repository: | CRAN | 
| Date/Publication: | 2025-09-02 23:20:02 UTC | 
de_county
Description
This data contains 2010 Census data for each of the three counties in DE.
Usage
data("de_county")
Format
An sf dataframe with 3 observations
Examples
data('de_county')
de_tract
Description
This data contains 2010 Census data for each of the 218 tracts in DE.
Usage
data("de_tract")
Format
An sf dataframe with 218 observations
Examples
data('de_tract')
Compute Absolute Centralization
Description
Compute Absolute Centralization
Usage
ds_abs_cent(.data, .cols, .name)
abs_cent(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with absolute centralization. Leave missing to return a vector. | 
| ... | arguments to forward to ds_abs_cent from abs_cent | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_abs_cent(de_county, c(pop_white, starts_with('pop_')))
ds_abs_cent(de_county, c(pop_white, starts_with('pop_')), 'abs_cent')
Compute Absolute Clustering
Description
Compute Absolute Clustering
Usage
ds_abs_clust(.data, .cols, .name)
abs_clust(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with absolute clustering. Leave missing to return a vector. | 
| ... | arguments to forward to ds_abs_clust from abs_clust | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_abs_clust(de_county, c(pop_white, starts_with('pop_')))
ds_abs_clust(de_county, c(pop_white, starts_with('pop_')), 'abs_clust')
Compute Absolute Concentration
Description
Compute Absolute Concentration
Usage
ds_abs_conc(.data, .cols, .name)
abs_conc(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with absolute concentration. Leave missing to return a vector. | 
| ... | arguments to forward to ds_abs_conc from abs_conc | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_abs_conc(de_county, c(pop_black, starts_with('pop_')))
ds_abs_conc(de_county, c(pop_black, starts_with('pop_')), 'abs_conc')
Compute Atkinson b Index
Description
Compute Atkinson b Index
Usage
ds_atkinson(.data, .cols, .name, b = 0.5)
atkinson(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with Atkinson b index. Leave missing to return a vector. | 
| b | Default 0.5. Exponent parameter b, where 0 <= b <= 1. | 
| ... | arguments to forward to ds_atkinson from atkinson | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_atkinson(de_county, c(pop_white, starts_with('pop_')))
ds_atkinson(de_county, starts_with('pop_'), 'atkinson')
Compute Blau's Index
Description
Compute Blau's Index
Usage
ds_blau(.data, .cols, .name)
blau(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with Blau index. Leave missing to return a vector. | 
| ... | arguments to forward to ds_blau from blau | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_blau(de_county, starts_with('pop_'))
ds_blau(de_county, starts_with('pop_'), 'blau')
Compute Correlation Index
Description
Compute Correlation Index
Usage
ds_correlation(.data, .cols, .name)
correlation(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with Correlation index. Leave missing to return a vector. | 
| ... | arguments to forward to ds_correlation from correlation | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_correlation(de_county, c(pop_white, starts_with('pop_')))
ds_correlation(de_county, starts_with('pop_'), 'correlation')
Compute Distance Decay Interaction
Description
Compute Distance Decay Interaction
Usage
ds_dd_interaction(.data, .cols, .name, .comp = FALSE)
dd_interaction(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with distance decay interaction. Leave missing to return a vector. | 
| .comp | Default is FALSE. FALSE returns the sum, TRUE returns the components. | 
| ... | arguments to forward to ds_dd_interaction from dd_interaction | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_dd_interaction(de_county, c(pop_black, starts_with('pop_')))
ds_dd_interaction(de_county, c(pop_black, starts_with('pop_')), 'dd_interaction')
Compute Distance Decay Isolation
Description
Compute Distance Decay Isolation
Usage
ds_dd_isolation(.data, .cols, .name, .comp = FALSE)
dd_isolation(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with distance decay isolation. Leave missing to return a vector. | 
| .comp | Default is FALSE. FALSE returns the sum, TRUE returns the components. | 
| ... | arguments to forward to ds_dd_isolation from dd_isolation | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_dd_isolation(de_county, c(pop_black, starts_with('pop_')))
ds_dd_isolation(de_county, c(pop_black, starts_with('pop_')), 'dd_isolation')
Compute Delta Index
Description
Compute Delta Index
Usage
ds_delta(.data, .cols, .name, .comp = FALSE)
delta(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with delta index. Leave missing to return a vector. | 
| .comp | Default is FALSE. FALSE returns the sum, TRUE returns the components. | 
| ... | arguments to forward to ds_delta from delta | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_delta(de_county, c(pop_white, starts_with('pop_')))
ds_delta(de_county, starts_with('pop_'), 'delta')
Compute Dissimilarity Index
Description
Compute Dissimilarity Index
Usage
ds_dissim(.data, .cols, .name, .comp = FALSE)
dissim(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with dissimilarity index. Leave missing to return a vector. | 
| .comp | Default is FALSE. FALSE returns the sum, TRUE returns the components. | 
| ... | arguments to forward to ds_dissim from dissim | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_dissim(de_county, c(pop_white, starts_with('pop_')))
ds_dissim(de_county, c(pop_white, starts_with('pop_')), .comp = TRUE)
ds_dissim(de_county, starts_with('pop_'), 'dissim')
Compute Diversity
Description
This is equivalent to perplexity.
Usage
ds_diversity(.data, .cols, .name, q = 1)
diversity(..., .data = dplyr::across(everything()))
ds_perplexity(.data, .cols, .name, q = 1)
perplexity(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with diversity. Leave missing to return a vector. | 
| q | exponent parameter. Default 0. Can not be 1. | 
| ... | arguments to forward to ds_diversity from diversity | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_diversity(de_county, starts_with('pop_'))
ds_diversity(de_county, starts_with('pop_'), 'diversity')
Compute Entropy Index
Description
Compute Entropy Index
Usage
ds_entropy(.data, .cols, .name, .comp = FALSE)
entropy(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with entropy index. Leave missing to return a vector. | 
| .comp | Default is FALSE. FALSE returns the sum, TRUE returns the components. | 
| ... | arguments to forward to ds_entropy from entropy | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_entropy(de_county, c(pop_white, starts_with('pop_')))
ds_entropy(de_county, starts_with('pop_'), 'entropy')
Compute Gini Index
Description
Compute Gini Index
Usage
ds_gini(.data, .cols, .name, .comp = FALSE)
gini(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with gini index. Leave missing to return a vector. | 
| .comp | Default is FALSE. FALSE returns the sum, TRUE returns the components. | 
| ... | arguments to forward to ds_gini from gini | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_gini(de_county, c(pop_white, starts_with('pop_')))
ds_gini(de_county, starts_with('pop_'), 'gini')
Compute Herfindahl-Hirshman Index
Description
This is equivalent to the Simpson Index.
Usage
ds_hhi(.data, .cols, .name)
hhi(..., .data = dplyr::across(everything()))
ds_simpson(.data, .cols, .name)
simpson(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with HHI. Leave missing to return a vector. | 
| ... | arguments to forward to ds_hhi from hhi | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_hhi(de_county, starts_with('pop_'))
ds_hhi(de_county, starts_with('pop_'), 'blau')
Compute Interaction Index
Description
Compute Interaction Index
Usage
ds_interaction(.data, .cols, .name, .comp = FALSE)
interaction(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with Interaction index. Leave missing to return a vector. | 
| .comp | Default is FALSE. FALSE returns the sum, TRUE returns the components. | 
| ... | arguments to forward to ds_interaction from interaction | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_interaction(de_county, c(pop_white, starts_with('pop_')))
ds_interaction(de_county, starts_with('pop_'), 'interaction')
Compute Simpson Index
Description
Compute Simpson Index
Usage
ds_inv_simpson(.data, .cols, .name)
inv_simpson(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with Simpson Index Leave missing to return a vector. | 
| ... | arguments to forward to ds_inv_simpson from inv_simpson | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_inv_simpson(de_county, starts_with('pop_'))
ds_inv_simpson(de_county, starts_with('pop_'), 'blau')
Compute Isolation Index
Description
Compute Isolation Index
Usage
ds_isolation(.data, .cols, .name, .comp = FALSE)
isolation(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with Isolation index. Leave missing to return a vector. | 
| .comp | Default is FALSE. FALSE returns the sum, TRUE returns the components. | 
| ... | arguments to forward to ds_isolation from isolation | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_isolation(de_county, c(pop_white, starts_with('pop_')))
ds_isolation(de_county, starts_with('pop_'), 'isolation')
Compute Relative Centralization
Description
Compute Relative Centralization
Usage
ds_rel_cent(.data, .cols, .name)
rel_cent(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with relative centralization. Leave missing to return a vector. | 
| ... | arguments to forward to ds_rel_cent from rel_cent | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_rel_cent(de_county, c(pop_white, starts_with('pop_')))
ds_rel_cent(de_county, c(pop_white, starts_with('pop_')), 'rel_cent')
Compute Relative Clustering
Description
Compute Relative Clustering
Usage
ds_rel_clust(.data, .cols, .name)
rel_clust(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with relative clustering. Leave missing to return a vector. | 
| ... | arguments to forward to ds_rel_clust from rel_clust | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_rel_clust(de_county, c(pop_black, starts_with('pop_')))
ds_rel_clust(de_county, c(pop_black, starts_with('pop_')), 'rel_clust')
Compute Relative Concentration
Description
Compute Relative Concentration
Usage
ds_rel_conc(.data, .cols, .name)
rel_conc(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with relative concentration. Leave missing to return a vector. | 
| ... | arguments to forward to ds_rel_conc from rel_conc | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_rel_conc(de_county, c(pop_black, starts_with('pop_')))
ds_rel_conc(de_county, c(pop_black, starts_with('pop_')), 'rel_conc')
Compute Reyni Entropy
Description
Compute Reyni Entropy
Usage
ds_reyni(.data, .cols, .name, q = 0)
reyni(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with Reyni entropy. Leave missing to return a vector. | 
| q | exponent parameter. Default 0. Can not be 1. | 
| ... | arguments to forward to ds_reyni from reyni | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_reyni(de_county, starts_with('pop_'))
ds_reyni(de_county, starts_with('pop_'), 'reyni')
Compute Shannon Index
Description
Compute Shannon Index
Usage
ds_shannon(.data, .cols, .name)
shannon(..., .data = dplyr::across(everything()))
Arguments
| .data | |
| .cols | 
 | 
| .name | name for column with Shannon index. Leave missing to return a vector. | 
| ... | arguments to forward to ds_shannon from shannon | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_shannon(de_county, starts_with('pop_'))
ds_shannon(de_county, starts_with('pop_'), 'shannon')
Compute Spatial Proximity
Description
Compute Spatial Proximity
Usage
ds_spat_prox(.data, .cols, .name)
spat_prox(..., .data = dplyr::across(everything()))
Arguments
| .data | tibble with sf geometry | 
| .cols | 
 | 
| .name | name for column with spatial proximity. Leave missing to return a vector. | 
| ... | arguments to forward to ds_spat_prox from spat_prox | 
Value
a tibble or numeric vector if .name missing
Examples
data('de_county')
ds_spat_prox(de_county, c(pop_black, starts_with('pop_')))
ds_spat_prox(de_county, c(pop_black, starts_with('pop_')), 'spat_prox')
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- tidyselect
- all_of,- any_of,- contains,- ends_with,- everything,- last_col,- matches,- num_range,- one_of,- starts_with
Tidy eval helpers
Description
This page lists the tidy eval tools reexported in this package from rlang. To learn about using tidy eval in scripts and packages at a high level, see the dplyr programming vignette and the ggplot2 in packages vignette. The Metaprogramming section of Advanced R may also be useful for a deeper dive.
- The tidy eval operators - {{,- !!, and- !!!are syntactic constructs which are specially interpreted by tidy eval functions. You will mostly need- {{, as- !!and- !!!are more advanced operators which you should not have to use in simple cases.- The curly-curly operator - {{allows you to tunnel data-variables passed from function arguments inside other tidy eval functions.- {{is designed for individual arguments. To pass multiple arguments contained in dots, use- ...in the normal way.- my_function <- function(data, var, ...) { data |> group_by(...) |> summarise(mean = mean({{ var }})) }
-  enquo()andenquos()delay the execution of one or several function arguments. The former returns a single expression, the latter returns a list of expressions. Once defused, expressions will no longer evaluate on their own. They must be injected back into an evaluation context with!!(for a single expression) and!!!(for a list of expressions).my_function <- function(data, var, ...) { # Defuse var <- enquo(var) dots <- enquos(...) # Inject data |> group_by(!!!dots) |> summarise(mean = mean(!!var)) }In this simple case, the code is equivalent to the usage of {{and...above. Defusing withenquo()orenquos()is only needed in more complex cases, for instance if you need to inspect or modify the expressions in some way.
- The - .datapronoun is an object that represents the current slice of data. If you have a variable name in a string, use the- .datapronoun to subset that variable with- [[.- my_var <- "disp" mtcars |> summarise(mean = mean(.data[[my_var]])) 
- Another tidy eval operator is - :=. It makes it possible to use glue and curly-curly syntax on the LHS of- =. For technical reasons, the R language doesn't support complex expressions on the left of- =, so we use- :=as a workaround.- my_function <- function(data, var, suffix = "foo") { # Use `{{` to tunnel function arguments and the usual glue # operator `{` to interpolate plain strings. data |> summarise("{{ var }}_mean_{suffix}" := mean({{ var }})) }
- Many tidy eval functions like - dplyr::mutate()or- dplyr::summarise()give an automatic name to unnamed inputs. If you need to create the same sort of automatic names by yourself, use- as_label(). For instance, the glue-tunnelling syntax above can be reproduced manually with:- my_function <- function(data, var, suffix = "foo") { var <- enquo(var) prefix <- as_label(var) data |> summarise("{prefix}_mean_{suffix}" := mean(!!var)) }- Expressions defused with - enquo()(or tunnelled with- {{) need not be simple column names, they can be arbitrarily complex.- as_label()handles those cases gracefully. If your code assumes a simple column name, use- as_name()instead. This is safer because it throws an error if the input is not a name as expected.