tongfen

Convenience functions for making data on different geometries, especially Canadian census geometries, comparable.

https://github.com/mountainmath/tongfen

Science Score: 39.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.8%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Convenience functions for making data on different geometries, especially Canadian census geometries, comparable.

Basic Info
  • Host: GitHub
  • Owner: mountainMath
  • License: other
  • Language: R
  • Default Branch: main
  • Size: 20.4 MB
Statistics
  • Stars: 28
  • Watchers: 2
  • Forks: 4
  • Open Issues: 1
  • Releases: 3
Created about 8 years ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog License

README.md

tongfen

R-CMD-check CRAN_Status_Badge CRAN_Downloads_Badge <!-- badges: end -->

tongfen logo TongFen (通分) means to convert two fractions to the least common denominator, typically in preparation for further manipulation like addition or subtraction. In English, that's a mouthful and sounds complicated. But in Chinese there is a word for this, TongFen, which makes this process appear very simple.

When working with geospatial datasets we often want to compare data that is given on different regions. For example census data and election data. Or data from two different censuses. To properly compare this data we first need to convert it to a common geography. The process to do this is quite analogous to the process of TongFen for fractions, so we appropriate this term to give it a simple name. Using the tongfen package, preparing data on disparate geographies for comparison by converting them to a common geography is as easy as typing tongfen.

Reference

TongFen home page and reference guide

Installing the package

install.packages("tongfen")

The latest development version can be installed from GitHub. remotes::install_github("mountainmath/tongfen") library(tongfen)

Caching correspondence files

The get_tongfen_census_ct and get_tongfen_census_ct_from_da methods make use of the StatCan correspondence files. To speed up this process it is useful to permanently cache these files instead of having to download them repeatedly. If caching is desired, set either

  • options("tongfen.cache_path"="<your local cache path>")
  • Sys.setenv("tongfen.cache_path"="<your local cache path>")
  • options("custom_data_path"="<your local cache path>")

in your .Rprofile or .Renviron file.

General TongFen

The tongfen package is build around the following basic TongFen workflow:

  1. Given a list of datasets on diverse geographies, generate a correspondence table that links the geographies and specifies how to aggregate them up to a (least) common geography via estimate_tongfen_correspondence.
  2. generate metadata that specifies how variables can be aggregated up, the meta_for_additive_variables function does this for additive variables.
  3. Use the correspondence table and metadata to generate a dataset with variables from the original datasets aggregated up on a common geography via tongfen_aggregate.

A convenience function to validate geographic TongFen fit via area comparison is available via check_tongfen_areas, it allows to explore and deal with spatial mismatches during TongFen.

Aggregation of variables

Finding a common tiling of several different yet congruent geographies is only one part of the problem TongFen addresses, aggregating up the variables is the other part. The tongfen package deals with this using a metadata table that specifies how variables should be aggregated. In it's simplest form values are simply added up. The meta_for_additive_variables convenience function builds the metadata for additive variables. Metadata for non-additive variables like averages, ratios or percentages needs more care to build, it requires additional information on the parent variable that specifies the denominator of the average, ratio or percentage. Other data, like medians, can't be aggregated up, although tongfen can provide estimates of medians on aggregated geographies by treating them as averages.

Packaged data

The package ships with a subset of voting data from Elections Canada for the 42nd and 43rd federal elections as well as the polling district geographies for the 42nd and 43rd. This facilitates running the example vignette on polling districts without having to download external data. Both are available as open data covered under the Open Government Licence - Canda.

Data-specific implementations

The need for TongFen comes up frequently with certain types of geographies. Census geographies is one such example. In some cases these data sources come with their own correspondence files that go beyond geographic matchup but also join regions to alleviate data integrity problems like geocoding issues.

In such cases it can be worthwhile to wrap data acquisition and TongFen into one convenience function, and also extend the TongFen method parameter to allow for external correspondence files to be used.

Canadian census data

The package is well-integrated to work with Canadian census data in two essential ways. * meta_for_ca_census_vectors builds rich metadata for a given list of Canadian census variables by utilizing the metadata available via CensusMapper. In particular, this automates the proper aggregation of non-count variables like averages, ratios and percentages. * get_tongfen_ca_census wraps the process of data acquisition (via CensusMapper and the cancensus package and tongfen into one convenience function. At the same time it adds the TongFen method = "statcan" option that uses the Statistics Canada correspondence files to build the common geography. * The get_tongfen_correspondence_ca_census function breaks out the correspondence generation to aid the process of accessing the Statistics Canada correspondence files (and better integration of generating correspondences for Canadian census geographies in general) to facilitate mixing in non-census data coming on census geographies, like for example CMHC data.

US census data

  • get_tongfen_us_census integrates the data acquisition (via the tidycensus package) with TongFen, and adds the tongfen method = "census.gov" to use the US Census Bureau correspondence files for matching.

Other implementations

The tongfen package is open to add extensions for other specialized data sources, as well as extensions of existing ones.

Fixed target geography estimation

When geographies aren't sufficiently congruent or the target geography is fixed, we won't be able to use the tongfen methods to compute the data on a common geography but have to instead rely on estimates. The tongfen_estimate makes no assumption on the underlying geographies and returns estimates of the data on the target geography. It uses area-weighted interpolation to achieve this, and can be refined to dasymmetric estimates using the proportional_reaggregate function.

This method has the example that it works independent of the nature of the underlying geographies, but comes at the heavy price of only being an estimate. To be useful for research purposes we also need methods to estimate the errors this introduces and the effects this has on subsequent analysis results.

Methods to facilitate this are still under active development.

Cite tongfen

If you wish to cite tongfen:

von Bergmann, J. (2024). tongfen: R package to Make Data Based on Different Geographies Comparable. v0.3.6. DOI: 10.32614/CRAN.package.tongfen

A BibTeX entry for LaTeX users is @Manual{tongfen, author = {Jens {von Bergmann}}, title = {tongfen: R package to Make Data Based on Different Geographies Comparable}, year = {2024}, doi = {10.32614/CRAN.package.tongfen}, note = {R package version 0.3.6}, url = {https://mountainmath.github.io/tongfen/}, }

Owner

  • Name: Jens von Bergmann
  • Login: mountainMath
  • Kind: user
  • Location: Vancouver
  • Company: MountainMath

GitHub Events

Total
  • Issues event: 3
  • Delete event: 1
  • Issue comment event: 2
  • Push event: 12
  • Pull request event: 2
  • Create event: 1
Last Year
  • Issues event: 3
  • Delete event: 1
  • Issue comment event: 2
  • Push event: 12
  • Pull request event: 2
  • Create event: 1

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 116
  • Total Committers: 1
  • Avg Commits per committer: 116.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Jens von Bergmann j****s@m****a 116
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 5
  • Total pull requests: 6
  • Average time to close issues: about 1 year
  • Average time to close pull requests: 7 days
  • Total issue authors: 2
  • Total pull request authors: 1
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 1
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 24 days
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mountainMath (3)
  • cgauvi (1)
Pull Request Authors
  • mountainMath (7)
Top Labels
Issue Labels
enhancement (2) bug (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 251 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 4
  • Total maintainers: 1
cran.r-project.org: tongfen

Make Data Based on Different Geographies Comparable

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 251 Last month
Rankings
Stargazers count: 10.4%
Forks count: 12.8%
Dependent packages count: 29.8%
Average: 31.9%
Dependent repos count: 35.5%
Downloads: 71.1%
Maintainers (1)
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • R >= 2.10 depends
  • dplyr >= 1.0 imports
  • lifecycle * imports
  • purrr * imports
  • readr * imports
  • rlang * imports
  • sf * imports
  • stringr * imports
  • tibble * imports
  • tidyr >= 1.0 imports
  • utils * imports
  • RColorBrewer * suggests
  • cancensus * suggests
  • geojsonsf * suggests
  • ggplot2 * suggests
  • knitr * suggests
  • readxl * suggests
  • rmarkdown * suggests
  • scales * suggests
  • spelling * suggests
  • tidycensus * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v1 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v1 composite