Skip to contents

Converts a population density raster into a probability mass function (PMF) where all cell values sum to 1. Useful for spatial sampling where probability of selection should be proportional to population density.

Usage

transform_pmf(x, return_total = FALSE, snap = FALSE)

Arguments

x

SpatRaster of density values (e.g., population density)

return_total

logical; if TRUE, returns a list containing both PMF raster and total population. If FALSE (default), returns only PMF raster

snap

Logical; if TRUE skip validation and verification

Value

If return_total = FALSE, returns SpatRaster containing probability values that sum to 1. If return_total = TRUE, returns a list with components:

  • pmf: SpatRaster of probability values

  • total: numeric value of total density

Examples

# Basic usage
pop_density <- terra::rast(matrix(1:100, 10, 10))
pmf <- transform_pmf(pop_density)

# Get PMF and total population
result <- transform_pmf(pop_density, return_total = TRUE)
pmf <- result$pmf
total_pop <- result$total