mask_weighted_random: Mask coordinates using weighted random pertubation

View source: R/mask_weighted_random.R

mask_weighted_randomR Documentation

Mask coordinates using weighted random pertubation

Description

This method uses per point the distance to the kth neighbor as the maximum pertubation distance. Parameter r can be used to restrict the maximum distance of the kth neighbor.

Usage

mask_weighted_random(x, k = 5, r = NULL, plot = FALSE)

Arguments

x

coordinates, matrix or data.frame (first two columns)

k

integer number of neighbors to be used as the maximum distance

r

numeric maximum pertubation distance (vectorized)

plot

if TRUE points will be plotted.

Value

adapted x with perturbed coordinates

References

Spatial obfuscation methods for privacy protection of household-level data

See Also

Other point pertubation: mask_grid(), mask_random(), mask_voronoi()

Examples

x <- cbind(
  x = c(2.5, 3.5, 7.2, 1.5),
  y = c(6.2, 3.8, 4.4, 2.1)
)

# plotting is only useful from small datasets!

# grid masking
x_g <- mask_grid(x, r=1, plot=TRUE)

# random pertubation
set.seed(3)
x_r <- mask_random(x, r=1, plot=TRUE)

if (requireNamespace("FNN", quietly = TRUE)){
  # weighted random pertubation
  x_wr <- mask_weighted_random(x, k = 2, r = 4, plot=TRUE)
}

if ( requireNamespace("FNN", quietly = TRUE)
  && requireNamespace("sf", quietly = TRUE)
   ){
  # voronoi masking, plotting needs package `sf`
  x_vor <- mask_voronoi(x, r = 1, plot=TRUE)
}

sdcSpatial documentation built on March 24, 2022, 5:05 p.m.