Giter VIP home page Giter VIP logo

raceland's Introduction

raceland

R build status Codecov test coverage CRAN status CRAN RStudio mirror downloads

The raceland package implements a computational framework for a pattern-based, zoneless analysis, and visualization of (ethno)racial topography (Dmowska et al., 2020). It is a reimagined approach for analyzing residential segregation and racial diversity based on the concept of ‘landscape’ used in the domain of landscape ecology. A racial landscape, represented by a high-resolution raster grid with each cell containing only inhabitants of a single race, is quantified by two metrics (entropy and mutual information) derived from Information Theory concept (IT). Entropy is the measure of racial diversity and mutual information measures racial segregation.

Racial landscape method is based on the raster gridded data, and unlike the previous methods, does not depend on the division of specific zones (census tract, census block, etc.). Calculation of racial diversity (entropy) and racial segregation (mutual information) can be performed for the whole area of interests (i.e., metropolitan area) without introducing any arbitrary divisions. Racial landscape method also allows for performing calculations at different spatial scales.

Installation

You can install the released version of raceland from CRAN with:

install.packages("raceland")

You can install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("Nowosad/raceland")

Example

library(raceland)
library(terra)
#> terra 1.5.40
# Plot the input data
race_raster = rast(system.file("extdata/race_raster.tif", package = "raceland"))
plot(race_raster)

# Construct racial landscape
real_raster = create_realizations(x = race_raster, n = 100)
race_colors = c("#F16667", "#6EBE44", "#7E69AF", "#C77213","#F8DF1D")
plot(real_raster, col = race_colors, maxnl = 9)

# Plot racial ladnscape 
plot_realization(x = real_raster[[1]], y = race_raster, hex = race_colors)

# Calculate local subpopulation densities
dens_raster = create_densities(real_raster, race_raster, window_size = 10)
plot(dens_raster, maxnl = 9)

# Calculate IT-metrics 
metr_df = calculate_metrics(x = real_raster, w = dens_raster,
                            neighbourhood = 4, fun = "mean", 
                            size = NULL, threshold = 1)
head(metr_df)
#>   realization row col      ent  joinent  condent    mutinf
#> 1           1   1   1 1.634765 3.137711 1.502945 0.1318199
#> 2           2   1   1 1.633231 3.165357 1.532126 0.1011056
#> 3           3   1   1 1.639965 3.164693 1.524728 0.1152377
#> 4           4   1   1 1.649191 3.181056 1.531865 0.1173264
#> 5           5   1   1 1.640224 3.167782 1.527558 0.1126660
#> 6           6   1   1 1.634800 3.149787 1.514986 0.1198139
# Summarize IT metrics 
summary(metr_df[, c("ent", "mutinf")])
#>       ent            mutinf       
#>  Min.   :1.608   Min.   :0.09286  
#>  1st Qu.:1.629   1st Qu.:0.10838  
#>  Median :1.635   Median :0.11413  
#>  Mean   :1.635   Mean   :0.11429  
#>  3rd Qu.:1.640   3rd Qu.:0.11990  
#>  Max.   :1.656   Max.   :0.13964

References

Contribution

Contributions to this package are welcome. The preferred method of contribution is through a GitHub pull request. Feel free to contact us by creating an issue.

raceland's People

Contributors

nowosad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

raceland's Issues

raceland perhaps vulnerable to forthcoming changes in sp and rgdal

Running revdep checks for current rgdal on R-Forge - see:

https://stat.ethz.ch/pipermail/r-sig-geo/2019-November/027801.html

shows the errors in the attached test failure log, related to use of
PROJ&/GDAL3 and required changes to sp and rgdal.


R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(testthat)
> library(raceland)
> library(raster)
Loading required package: sp
> library(sf)
Linking to GEOS 3.8.0, GDAL 3.0.2, PROJ 6.2.1
> 
> test_check("raceland")
── 1. Failure: (unknown) (@test-results.R#23)  ─────────────────────────────────
`real_raster2` not equal to `real_raster`.
Attributes: < Component "crs": Attributes: < Names: 1 string mismatch > >
Attributes: < Component "crs": Attributes: < Length mismatch: comparison on first 2 components > >
Attributes: < Component "crs": Attributes: < Component 2: 1 string mismatch > >
Attributes: < Component "layers": Component 1: Attributes: < Component 2: Attributes: < Names: 1 string mismatch > > >
Attributes: < Component "layers": Component 1: Attributes: < Component 2: Attributes: < Length mismatch: comparison on first 2 components > > >
Attributes: < Component "layers": Component 1: Attributes: < Component 2: Attributes: < Component 2: 1 string mismatch > > >
Attributes: < Component "layers": Component 2: Attributes: < Component 2: Attributes: < Names: 1 string mismatch > > >
Attributes: < Component "layers": Component 2: Attributes: < Component 2: Attributes: < Length mismatch: comparison on first 2 components > > >
Attributes: < Component "layers": Component 2: Attributes: < Component 2: Attributes: < Component 2: 1 string mismatch > > >
...

── 2. Failure: (unknown) (@test-results.R#24)  ─────────────────────────────────
`weig_raster2` not equal to `weig_raster`.
Attributes: < Component "crs": Attributes: < Names: 1 string mismatch > >
Attributes: < Component "crs": Attributes: < Length mismatch: comparison on first 2 components > >
Attributes: < Component "crs": Attributes: < Component 2: 1 string mismatch > >
Attributes: < Component "layers": Component 1: Attributes: < Component 2: Attributes: < Names: 1 string mismatch > > >
Attributes: < Component "layers": Component 1: Attributes: < Component 2: Attributes: < Length mismatch: comparison on first 2 components > > >
Attributes: < Component "layers": Component 1: Attributes: < Component 2: Attributes: < Component 2: 1 string mismatch > > >
Attributes: < Component "layers": Component 2: Attributes: < Component 2: Attributes: < Names: 1 string mismatch > > >
Attributes: < Component "layers": Component 2: Attributes: < Component 2: Attributes: < Length mismatch: comparison on first 2 components > > >
Attributes: < Component "layers": Component 2: Attributes: < Component 2: Attributes: < Component 2: 1 string mismatch > > >
...

── 3. Failure: (unknown) (@test-results.R#26)  ─────────────────────────────────
`grid_sf2` not equal to `grid_sf`.
Component "geom": Attributes: < Component "crs": Component "proj4string": 1 string mismatch >

── 4. Failure: (unknown) (@test-results.R#27)  ─────────────────────────────────
`popdens_raster2` not equal to `popdens_raster`.
Attributes: < Component "crs": Attributes: < Names: 1 string mismatch > >
Attributes: < Component "crs": Attributes: < Length mismatch: comparison on first 2 components > >
Attributes: < Component "crs": Attributes: < Component 2: 1 string mismatch > >
Attributes: < Component "layers": Component 1: Attributes: < Component 2: Attributes: < Names: 1 string mismatch > > >
Attributes: < Component "layers": Component 1: Attributes: < Component 2: Attributes: < Length mismatch: comparison on first 2 components > > >
Attributes: < Component "layers": Component 1: Attributes: < Component 2: Attributes: < Component 2: 1 string mismatch > > >
Attributes: < Component "layers": Component 2: Attributes: < Component 2: Attributes: < Names: 1 string mismatch > > >
Attributes: < Component "layers": Component 2: Attributes: < Component 2: Attributes: < Length mismatch: comparison on first 2 components > > >
Attributes: < Component "layers": Component 2: Attributes: < Component 2: Attributes: < Component 2: 1 string mismatch > > >
...

══ testthat results  ═══════════════════════════════════════════════════════════
[ OK: 10 | SKIPPED: 0 | WARNINGS: 93 | FAILED: 4 ]
1. Failure: (unknown) (@test-results.R#23) 
2. Failure: (unknown) (@test-results.R#24) 
3. Failure: (unknown) (@test-results.R#26) 
4. Failure: (unknown) (@test-results.R#27) 

Error: testthat unit tests failed
Execution halted

upcoming sf breaks raceland

upcoming sf breaks raceland:

  Running ‘testthat.R’
Running the tests in ‘tests/testthat.R’ failed.
Last 13 lines of output:
  Loading required package: sp
  > library(sf)
  Linking to GEOS 3.8.0, GDAL 3.0.2, PROJ 6.2.1
  >
  > test_check("raceland")
  ── 1. Failure: (unknown) (@test-results.R#26)  ─────────────────────────────────
  `grid_sf2` not equal to `grid_sf`.
  Component "geom": Attributes: < Component "crs": Component "proj4string": 1 string mismatch >

  ══ testthat results  ═══════════════════════════════════════════════════════════
  [ OK: 13 | SKIPPED: 0 | WARNINGS: 0 | FAILED: 1 ]
  1. Failure: (unknown) (@test-results.R#26)

  Error: testthat unit tests failed
  Execution halted

Function not exported

Hi, I am was using the Raceland code, and before I did not have this issue when calculating the realizations, densities, or metrics but recently I have been having this error message and cannot seem to have an output for the metrics. Here is the error message:

Error in get_metrics(x = raster::as.matrix(x), w = raster::as.matrix(w), :
Function not exported: C++ function with signature 'double(*rcpp_ent)(const Rcpp::NumericMatrix,std::string)' not found in comat.

Have any recommendations to solve this? Thank you.

'invalid argument type' when using plot_realization

Hi,

I'm getting this error for plot_realization:

Error in !all.equal(dim(x)[c(1, 2)], dim(y)[c(1, 2)]) : invalid argument type

I was able to use this function without issues for a different dataset, but I'm not sure what about my new data could be causing it. The other functions I'm using (zones_to_raster, quantify_raceland and create_realizations) seem to be working perfectly well on the data. Do you have any idea?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.