Skip to content
Create privacy protected maps with R
R TeX Rebol
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R
data-raw
data
example
inst/app
man
tests
useR2019
vignettes
.Rbuildignore
.gitignore
.travis.yml
DESCRIPTION
NAMESPACE
NEWS.md
README.Rmd
README.md
_pkgdown.yml
appveyor.yml
sdcSpatial.Rproj

README.md

CRAN status Travis build status AppVeyor build status Mentioned in Awesome Official Statistics

sdcSpatial

Publishing a raster density map can reveal sensitive values. sdcSpatial is an opensource R package for creating spatial density (raster) maps from point data while protecting the privacy of individual observations.

sdcSpatial offers a sdc_raster class that allows to:

  • find out which locations are considered sensitive / unsafe for publishing: plot_sensitive, is_sensitive, sensitivity_score.
  • apply protection methods that reduce sensitiviy and enhance spatial patterns: protect_smooth, protect_quadtree.
  • remove sensitive locations: remove_sensitive.
  • extract relative as well as absolute density rasters that can be used with visualisation packages, such as tmap and leaflet: x$value$mean, x$value$sum, mean, sum.

Installation

install.packages("sdcSpatial")

To install the current development version of sdcSpatial with devtools

remotes::install_github("edwindj/sdcSpatial")

Example

library(sdcSpatial)
library(raster)
#> Loading required package: sp

data(enterprises)

# create a sdc_raster from point data with raster with
# a resolution of 200m
production <- sdc_raster(enterprises, variable = "production"
                        , r = 200, min_count = 3)

print(production)
#> numeric sdc_raster object: 
#>    resolution: 200 200 ,  max_risk: 0.95 , min_count: 3 
#>    mean sensitivity score [0,1]:  0.6328234

# plot the raster
zlim <- c(0, 3e4)
# show which raster cells are sensitive
plot(production, zlim=zlim)

# but we can also retrieve directly the raster
sensitive <- is_sensitive(production, min_count = 3)
plot(sensitive, col = c('white', 'red'))

# what is the sensitivy fraction?
sensitivity_score(production)
#> [1] 0.6328234
# or equally
cellStats(sensitive, mean)
#> [1] 0.6328234

# let's smooth to reduce the sensitivity
smoothed <- protect_smooth(production, bw = 400)
plot(smoothed)

# what is the sensitivy fraction?
sensitivity_score(smoothed)
#> [1] 0.01408451

# let's remove the sensitive data.
smoothed_safe <- remove_sensitive(smoothed, min_count = 3)
plot(smoothed_safe, zlim=zlim)

# let's communicate!
production_mean <- mean(smoothed_safe)
production_total <- sum(smoothed_safe)

# and create a contour plot
raster::filledContour(production_mean, nlevels = 6, main = "Mean production")

# generated with R 3.6 >=
#col <- hcl.colors(10, rev=TRUE)
col <- c("#FDE333", "#BBDD38", "#6CD05E", "#00BE7D",
         "#00A890", "#008E98",  "#007094", "#185086", "#422C70", "#4B0055")
raster::filledContour(production_total, nlevels = 10
             , col = col
             , main="Total production")

You can’t perform that action at this time.