The goal of ppmf
is to convert Census Privacy Protected
Microdata Files into somewhat wider data aggregated to a geographic
level.
To install the stable version from CRAN, use the following code:
install.packages('ppmf')
You can install the development version from GitHub with:
# install.packages('remotes')
::install_github('christopherkenny/ppmf') remotes
Load the package:
library(ppmf)
Download and read data with:
<- download_ppmf(dsn = 'filename.csv', dir = 'some/directory', version = '19')
path <- read_ppmf(state = 'AL', path = path) al
Version ‘19’ reflects the 19.61 finalized parameters used again for the 2020 Census.
For future use, I recommend storing the path to the data for future sessions using:
add_pmmf19_path(path)
Then the path can be recovered with:
<- Sys.getenv('ppmf19') path19
Once you’ve read in what you want, you can aggregate it to the right level:
<- al |> add_geoid()
al <- agg(al) blocks
And aggregated data can use the GEOID to merge with shapefiles:
library(dplyr) # to clean up the data
<- tigris::blocks('AL', year = 2010) |>
shp select(GEOID10, geometry) |> rename(GEOID = GEOID10)
<- shp |> left_join(blocks, by = 'GEOID')
shp
# always clean shp!
is.na(shp)] <- 0 shp[
For users with the newest package version, there is an added
dependency on censable
,
which allows for an easier workflow. If you’ve used the
add_pmmf*_path()
workflow suggested, you don’t even need to
supply the paths!
This will not just read the ppmf
data, it will merge it
with 2010 Census populations (by major race/ethnicity grouping) and add
the corresponding geometries.
<- read_merge_ppmf('AL', level = 'block', versions = '19') al