Title: | Beyond the Border - Kernel Density Estimation for Urban Geography |
---|---|
Description: | The kernelSmoothing() function allows you to square and smooth geolocated data. It calculates a classical kernel smoothing (conservative) or a geographically weighted median. There are four major call modes of the function. The first call mode is kernelSmoothing(obs, epsg, cellsize, bandwidth) for a classical kernel smoothing and automatic grid. The second call mode is kernelSmoothing(obs, epsg, cellsize, bandwidth, quantiles) for a geographically weighted median and automatic grid. The third call mode is kernelSmoothing(obs, epsg, cellsize, bandwidth, centroids) for a classical kernel smoothing and user grid. The fourth call mode is kernelSmoothing(obs, epsg, cellsize, bandwidth, quantiles, centroids) for a geographically weighted median and user grid. Geographically weighted summary statistics : a framework for localised exploratory data analysis, C.Brunsdon & al., in Computers, Environment and Urban Systems C.Brunsdon & al. (2002) <doi:10.1016/S0198-9715(01)00009-6>, Statistical Analysis of Spatial and Spatio-Temporal Point Patterns, Third Edition, Diggle, pp. 83-86, (2003) <doi:10.1080/13658816.2014.937718>. |
Authors: | Arlindo Dos Santos [aut], François Sémécurbe [aut], Julien Pramil [aut], Kim Antunez [cre, ctb], Auriane Renaud [ctb], Farida Marouchi [ctb], Joachim Timotéo [ctb], Institut national de la statistique et des études économiques [cph] |
Maintainer: | Kim Antunez <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.2.0 |
Built: | 2024-11-07 05:29:46 UTC |
Source: | https://github.com/inseefr/btb |
The kernelSmoothing() function allows you to square and smooth geolocated data. It calculates a classical kernel smoothing (conservative) or a geographically weighted median. There are four major call modes of the function. The first call mode is kernelSmoothing(obs, epsg, cellsize, bandwidth) for a classical kernel smoothing and automatic grid. The second call mode is kernelSmoothing(obs, epsg, cellsize, bandwidth, quantiles) for a geographically weighted median and automatic grid. The third call mode is kernelSmoothing(obs, epsg, cellsize, bandwidth, centroids) for a classical kernel smoothing and user grid. The fourth call mode is kernelSmoothing(obs, epsg, cellsize, bandwidth, quantiles, centroids) for a geographically weighted median and user grid.
Link some points to their centroids in a grid segmentation
Relie des points aux centroides des carreaux auxquels ces points appartiennent (dans un découpage de l'espace en grille carroyée)
btb_add_centroids( pts, iCellSize, offset = c(0L, 0L), names_coords = c("x", "y"), names_centro = c("x_centro", "y_centro"), add = TRUE )
btb_add_centroids( pts, iCellSize, offset = c(0L, 0L), names_coords = c("x", "y"), names_centro = c("x_centro", "y_centro"), add = TRUE )
pts |
: points ( |
iCellSize |
:
|
offset |
(numeric vector of size 2)
|
names_coords |
:
|
names_centro |
|
add |
(boolean)
|
Works with sf points but only with coordinates in meters (and not degrees !). Do not use sf points with GPS coordinates for example.
pts
table with additional centroids coordinates x_centro
and y_centro
(df
of sf
object)
Table pts
avec les coordonnées des centroïdes x_centro
and y_centro
(objet df
of sf
)
pts <- data.frame( x = c(656913.1 , 348296.3 , 842276.3 , 716750.0 , 667418.2), y = c(6855995 , 6788073 , 6385680 , 7003984 , 6585793), val = 1:5) btb_add_centroids(pts, 100, names_centro = c("centroX", "centroY")) btb_add_centroids(pts, 100, offset = c(50, 50), names_centro = c("centroX", "centroY")) pts2 <- sf::st_as_sf(pts, coords = c("x","y"), crs = 2154) btb_add_centroids(pts2, 50)
pts <- data.frame( x = c(656913.1 , 348296.3 , 842276.3 , 716750.0 , 667418.2), y = c(6855995 , 6788073 , 6385680 , 7003984 , 6585793), val = 1:5) btb_add_centroids(pts, 100, names_centro = c("centroX", "centroY")) btb_add_centroids(pts, 100, offset = c(50, 50), names_centro = c("centroX", "centroY")) pts2 <- sf::st_as_sf(pts, coords = c("x","y"), crs = 2154) btb_add_centroids(pts2, 50)
Creates Inpire names for a grid defined with :
centroids coordinates
Squares size(s)
Projection system
Ajoute les noms des identifiants en norme Inspire des carreaux définis à partir :
des coordonnées de leurs centroides
de la taille de leur côté en mètres
d'un système de projection)
btb_add_inspire( pts_centro, sEPSG, iCellSize, names_centro = c("x_centro", "y_centro") )
btb_add_inspire( pts_centro, sEPSG, iCellSize, names_centro = c("x_centro", "y_centro") )
pts_centro |
(df object) : table of centroids. |
sEPSG |
(integer or character) : epsg code. |
iCellSize |
(integer) : cells size(s) in meters. Can be a vector for irregular grids |
names_centro |
(character vector) : vector of names for longitude/latitude variables. Default c("x_centro","y_centro"). |
(df) pts_centro table with additional idInspire variable
pts_centro <- data.frame(x_centro = c(100, 100, 300, 300, 500), y_centro = c(100, 300, 100, 300, 100)) btb_add_inspire(pts_centro, sEPSG = 2154, iCellSize = 200)
pts_centro <- data.frame(x_centro = c(100, 100, 300, 300, 500), y_centro = c(100, 300, 100, 300, 100)) btb_add_inspire(pts_centro, sEPSG = 2154, iCellSize = 200)
Function to compute a grid (regular or not) from centroid points.
(Fonction permettant de générer une grille (régulière ou non) à partir de centroïdes)
btb_ptsToGrid( pts, sEPSG = NA, iCellSize = NULL, names_centro = c("x_centro", "y_centro"), inspire = F )
btb_ptsToGrid( pts, sEPSG = NA, iCellSize = NULL, names_centro = c("x_centro", "y_centro"), inspire = F )
pts |
A simple (Un simple |
sEPSG |
EPSG code of projection ( (code EPSG de la projection ( |
iCellSize |
Cell size of the grid. If this argument is provided, the grid is regular. (Taille des carreaux de la grille. Si cet argument est fourni, la grille est régulière.) |
names_centro |
(character vector)
|
inspire |
(boolean) : if TRUE, returns a column for Inspire grid names. |
Returns an object of class sf
and data.frame
.
(Retourne un objet de classe sf
et data.frame
.)
# example 1 - regular grid pts <- data.frame(x_centro = c(100, 100, 300, 300, 500), y_centro = c(100, 300, 100, 300, 100)) carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154", iCellSize = 200) # write_sf(obj = carResult, dsn = "regularGrid.shp", delete_layer = TRUE) # example 2 - irregular grid pts <- data.frame(x = c(50, 50, 150, 150, 300) , y = c(50, 150, 50, 150, 100) , iCellSize = c(50, 50, 50, 50, 100)) carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154",names_centro=c("x","y")) # write_sf(obj = carResult, dsn = "irregularGrid.shp", delete_layer = TRUE) # Exemple 3 : sf points (no epsg) pts <- data.frame(x = c(100, 100, 300, 300, 500), y = c(100, 300, 100, 300, 100)) pts <- sf::st_as_sf(pts,coords=c("x","y")) carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154", iCellSize = 200) # Exemple 3 : sf points (no epsg) pts <- data.frame(x = c(100, 100, 300, 300, 500), y = c(100, 300, 100, 300, 100)) pts <- sf::st_as_sf(pts,coords=c("x","y"),crs=2154) carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154", iCellSize = 200)
# example 1 - regular grid pts <- data.frame(x_centro = c(100, 100, 300, 300, 500), y_centro = c(100, 300, 100, 300, 100)) carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154", iCellSize = 200) # write_sf(obj = carResult, dsn = "regularGrid.shp", delete_layer = TRUE) # example 2 - irregular grid pts <- data.frame(x = c(50, 50, 150, 150, 300) , y = c(50, 150, 50, 150, 100) , iCellSize = c(50, 50, 50, 50, 100)) carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154",names_centro=c("x","y")) # write_sf(obj = carResult, dsn = "irregularGrid.shp", delete_layer = TRUE) # Exemple 3 : sf points (no epsg) pts <- data.frame(x = c(100, 100, 300, 300, 500), y = c(100, 300, 100, 300, 100)) pts <- sf::st_as_sf(pts,coords=c("x","y")) carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154", iCellSize = 200) # Exemple 3 : sf points (no epsg) pts <- data.frame(x = c(100, 100, 300, 300, 500), y = c(100, 300, 100, 300, 100)) pts <- sf::st_as_sf(pts,coords=c("x","y"),crs=2154) carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154", iCellSize = 200)
Smoothing function with a bisquare kernel or median.
(Fonction de lissage à partir d'un noyau bisquare ou de la médiane.)
btb_smooth( pts, sEPSG = NA, iCellSize = NA, iBandwidth, vQuantiles = NULL, dfCentroids = NULL, iNeighbor = NULL, inspire = F, iNbObsMin = 250 )
btb_smooth( pts, sEPSG = NA, iCellSize = NA, iBandwidth, vQuantiles = NULL, dfCentroids = NULL, iNeighbor = NULL, inspire = F, iNbObsMin = 250 )
pts |
A (Un |
sEPSG |
EPSG code of projection ( (code EPSG de la projection ( |
iCellSize |
Cell size of the grid ( (Taille des carreaux ( |
iBandwidth |
Radius of the Kernel Density Estimator ( (Rayon de lissage de l'estimation d'intensité par noyau ( |
vQuantiles |
Percentile vector to calculate. For example c(0.1, 0.25, 0.5) will calculate the first decile, the first quartile and the median. (Vecteur des quantiles à calculer. Par exemple c(0.1, 0.25, 0.5) retournera le premier décile, le premier quartile et la mediane.)' |
dfCentroids |
A (Un |
iNeighbor |
Technical parameter, leave empty. ( (Paramètre technique pour calculer l'étendue des points d'estimations, à ne pas remplir. ( |
inspire |
(boolean) : if TRUE, returns a column for Inspire grid names. |
iNbObsMin |
Minimum size of constituted grappes for median smoothing. ( (Taille minimale des grappes constituées pour le lissage "médian" (géographiquement pondéré). ( |
Returns an object inheriting from the data.frame
class. (Retourne un objet qui se comporte comme un data.frame
, par heritage.)
Smoothing covers a set of methods to extract pertinent and structuring information from noisy data. In the field of spatial analysis, and most widely in quantitative geography, smoothing is used to modelise density variations of a population distribution in geographical space. Kernel smoothing methods are widely used. In this method, for each location x, we count the number of events of a process within a distance h of x, and weighted by the square reciprocal of the radius h. We apply a edge-correction to deal with edge-effects. So the method is conservative..
Le lissage recouvre un ensemble de méthodes pour extraire d'une source de données bruitées une information pertinente et structurante. Dans le champ de l'analyse spatiale et plus largement de la géographie quantitative, le lissage est principalement utilisé pour modéliser les variations de densités d'une distribution de population dans l'espace géographique. On utilise principalement des méthodes de lissage par noyau. Il s'agit ici, pour chaque point x, de comptabliser le nombre d' "évènements" d'un processus à une distance h de ce point, tout en ponderant ce nombre par l'inverse de la distance h au carré. On applique une correction à la ponderation afin de traiter les effets de bord. Cette méthode est conservative.
"Geographically weighted summary statistics : a framework for localised exploratory data analysis", C.Brunsdon & al., in Computers, Environment and Urban Systems 2002
Statistical Analysis of Spatial and Spatio-Temporal Point Patterns, Third Edition, Diggle, 2003, pp. 83-86
## Not run: # Example 1 data(dfPrix_SP95_2016) dfPrix_SP95_2016$nbObs <- 1L dfSmoothed <- btb::btb_smooth(pts = dfPrix_SP95_2016, sEPSG = "2154", iCellSize = 5000L, iBandwidth = 30000L, inspire = TRUE) dfSmoothed$prix95 <- dfSmoothed$SP95 / dfSmoothed$nbObs * 100 library(mapsf) mf_map(dfSmoothed, type = "choro", var = "prix95", breaks = "fisher", nbreaks = 5, border = NA, leg_title = "prix du SP95 en centimes") # Example 2 data(reunion) # Call mode 1: classic smoothing - automatic grid reunionSmoothed <- btb_smooth( pts = reunion, sEPSG = "32740", iCellSize = 200L, iBandwidth = 400L) library(mapsf) mf_map(reunionSmoothed, type = "choro", var = "houhold", breaks = "fisher", nbreaks = 5, border = NA) # Call mode 2: median smoothing - automatic grid reunionSmoothed <- btb_smooth( pts = reunion, sEPSG = "32740", iCellSize = 200L, iBandwidth = 400L, vQuantiles = c(0.1, 0.5, 0.9)) mf_map(reunionSmoothed, type = "choro", var = "houhold_05", breaks = "fisher", nbreaks = 5, border = NA) # Call mode 3: classic smoothing - user grid dfCentroidsUser <- merge( x = seq(from = 314400L, to = 378800L, by = 200L), y = seq(from = 7634000L, to = 7691200L, by = 200L)) reunionSmoothed <- btb_smooth( pts = reunion, sEPSG = "32740", iCellSize = 200L, iBandwidth = 400L, dfCentroids = dfCentroidsUser) reunionSmoothed <- reunionSmoothed[reunionSmoothed$houhold > 0, ] mf_map(reunionSmoothed, type = "choro", var = "houhold", breaks = "fisher", nbreaks = 5, border = NA) # Call mode 4: median smoothing - user grid reunionSmoothed <- btb_smooth( pts = reunion, sEPSG = "32740", iCellSize = 200L, iBandwidth = 400L, vQuantiles = c(0.1, 0.5, 0.9), dfCentroids = dfCentroidsUser) reunionSmoothed <- reunionSmoothed[reunionSmoothed$nbObs > 0, ] mf_map(reunionSmoothed, type = "choro", var = "houhold_05", breaks = "fisher", nbreaks = 5, border = NA) ## End(Not run)
## Not run: # Example 1 data(dfPrix_SP95_2016) dfPrix_SP95_2016$nbObs <- 1L dfSmoothed <- btb::btb_smooth(pts = dfPrix_SP95_2016, sEPSG = "2154", iCellSize = 5000L, iBandwidth = 30000L, inspire = TRUE) dfSmoothed$prix95 <- dfSmoothed$SP95 / dfSmoothed$nbObs * 100 library(mapsf) mf_map(dfSmoothed, type = "choro", var = "prix95", breaks = "fisher", nbreaks = 5, border = NA, leg_title = "prix du SP95 en centimes") # Example 2 data(reunion) # Call mode 1: classic smoothing - automatic grid reunionSmoothed <- btb_smooth( pts = reunion, sEPSG = "32740", iCellSize = 200L, iBandwidth = 400L) library(mapsf) mf_map(reunionSmoothed, type = "choro", var = "houhold", breaks = "fisher", nbreaks = 5, border = NA) # Call mode 2: median smoothing - automatic grid reunionSmoothed <- btb_smooth( pts = reunion, sEPSG = "32740", iCellSize = 200L, iBandwidth = 400L, vQuantiles = c(0.1, 0.5, 0.9)) mf_map(reunionSmoothed, type = "choro", var = "houhold_05", breaks = "fisher", nbreaks = 5, border = NA) # Call mode 3: classic smoothing - user grid dfCentroidsUser <- merge( x = seq(from = 314400L, to = 378800L, by = 200L), y = seq(from = 7634000L, to = 7691200L, by = 200L)) reunionSmoothed <- btb_smooth( pts = reunion, sEPSG = "32740", iCellSize = 200L, iBandwidth = 400L, dfCentroids = dfCentroidsUser) reunionSmoothed <- reunionSmoothed[reunionSmoothed$houhold > 0, ] mf_map(reunionSmoothed, type = "choro", var = "houhold", breaks = "fisher", nbreaks = 5, border = NA) # Call mode 4: median smoothing - user grid reunionSmoothed <- btb_smooth( pts = reunion, sEPSG = "32740", iCellSize = 200L, iBandwidth = 400L, vQuantiles = c(0.1, 0.5, 0.9), dfCentroids = dfCentroidsUser) reunionSmoothed <- reunionSmoothed[reunionSmoothed$nbObs > 0, ] mf_map(reunionSmoothed, type = "choro", var = "houhold_05", breaks = "fisher", nbreaks = 5, border = NA) ## End(Not run)
Quadtree variant function.
(Variante de la fonction Quadtree.)
constituerGrappes(iNbObsMin, mEffectifs)
constituerGrappes(iNbObsMin, mEffectifs)
iNbObsMin |
|
mEffectifs |
|
Returns a matrix
with the cluster number for each cell .
Retourne une matrix
avec le numéro de grappe pour chaque cellule.
Psar Analyse Urbaine Insee
Arlindo Dos Santos
Francois Semecurbe
Function constituting a membership matrix (Fonction constituant une matrice des effectifs)
constituerMatriceEffectifs(vLigneObservation, vColonneObservation)
constituerMatriceEffectifs(vLigneObservation, vColonneObservation)
vLigneObservation |
:
|
vColonneObservation |
:
|
Returns a matrix
with the number of observations for each cell.
(Retourne une matrix
avec le nombre d'observations pour chaque cellule.)
Psar Analyse Urbaine Insee
Arlindo Dos Santos
Francois Semecurbe
Unleaded 95 price in France in 2016 (prix du sans-plomb 95 en France en 2016)
dfPrix_SP95_2016
dfPrix_SP95_2016
dfPrix_SP95_2016
A data frame with 5,573 rows and 3 columns:
longitude
latitude
Unleaded price - prix du sans plomb
https://www.prix-carburants.gouv.fr/rubrique/opendata/
Parisian restaurants (Restaurants parisiens)
dfRestaurantParis
dfRestaurantParis
dfRestaurantParis
A data frame with 13,823 rows and 17 columns:
longitude
latitude
French restaurant
asian restaurant
caribbean restaurant
maghreb restaurant
african restaurant
european restaurant
south_american restaurant
indian restaurant
world food restaurant
cafeteria restaurant
tea_house
brasserie restaurant
fastfood restaurant
bar
restaurant
source : https://opendata.paris.fr
Function dfToGrid has been replaced by btb_ptsToGrid
dfToGrid(df, sEPSG, iCellSize = NULL)
dfToGrid(df, sEPSG, iCellSize = NULL)
df |
centroid points |
sEPSG |
epsg code |
iCellSize |
cell size |
a grid
Function kernelSmoothing has been replaced by btb_smooth
kernelSmoothing( dfObservations, sEPSG, iCellSize, iBandwidth, vQuantiles = NULL, dfCentroids = NULL, fUpdateProgress = NULL, iNeighbor = NULL, iNbObsMin = 250 )
kernelSmoothing( dfObservations, sEPSG, iCellSize, iBandwidth, vQuantiles = NULL, dfCentroids = NULL, fUpdateProgress = NULL, iNeighbor = NULL, iNbObsMin = 250 )
dfObservations |
points |
sEPSG |
epsg code |
iCellSize |
cell size |
iBandwidth |
smoothing bandwidth |
vQuantiles |
quantiles |
dfCentroids |
user grid |
fUpdateProgress |
message parameter |
iNeighbor |
number of neighbors pixels |
iNbObsMin |
technical parameter |
a warning message
Whole France grid with 1km square tiles. Lambert 93 projection.
(Grille France entière avec des carreaux d'1km de côté. Projection Lambert 93)
pixel_france
pixel_france
pixel_france
A data frame with 54,8495 rows and 2 columns:
longitude of pixel's centroids
latitude of pixel's centroids
source : https://opendata.paris.fr
Households of Reunion (Menages de La Reunion) Gridded database with a grid cell resolution of 200 meters. (Données carroyées à 200 mètres).
reunion
reunion
reunion
A data frame with 14,076 rows and 4 columns:
longitude
latitude
number of households - nombre de ménages
number of poor households - nombre de ménages pauvres
Source : Insee, Localized data : Fiscal Revenue - 31/12/2010 and Housing Tax - 01/01/2011
Source : Insee, Revenus Fiscaux Localisés (RFL) au 31 decembre 2010 et Taxe d'habitation (TH) au 1er janvier 2011)