class: center, middle, inverse, title-slide .title[ #
B
eyond
T
he
B
order ] .subtitle[ ## Spatial smoothing with R
] .author[ ### The Use of R in Official Statistics (uRos), december 2022 ] --- class: inverse_sommaire, middle | Numéro|Partie | |-------|-------| | 01| Spatial smoothing with `R` | | 02| Example: the housing prices in Paris in 2021 | --- class: inverse .partie[01] .NumeroPartie[01] .TitrePartie[Spatial smoothing with `R`] --- .partie[01] # Introduction ## 3 ways of mapping geographical data .left-column[  ] .right-column[ 1. **The territory**: a non-regular division of space. Several difficulties: mainly the Modifiable areal unit problem (MAUP) effect ;</br></br></br> 2. **The grid**: a regular division of space in the form of a grid of square cells. By construction, the gridded data can be very erratic ; </br></br></br> 3. **Spatial smoothing**: an extension of gridding consisting in describing the population environment within a given radius. ] ??? There are many way of mapping geographical data. 1) Usually, you can see maps of administrative territories. For example, counties and states in the US. These non-regular divisions of space can lead to the modifiable areal unit problem effect. That is to say the fact that a spatial indicator is strongly influenced by both shape and scale of the aggregation unit. 2) One solution is to map the data on a regular grid whose size depends on the phenomenon to be observed. Small grids make it possible to observe sub-municipal spatial phenomena, but the rendering can be visually erratic. 3) Finally, spatial smoothing is a key method for analyzing spatial organization of data available at a small geographic level, by providing simplified and clearer mapping, relieved of the arbitrariness of territorial boundary lines. --- .partie[01] # btb R package .pull-left[ ## Existing packages + `KernSmooth` + `spatstat`... ➡️ Often, **Fast Fourier Transform**. Not suitable for **edge effects** </br> ## btb + developed in 2018 (Insee, France) + deals with edge effects + allows quantile smoothing (less sensitive to extreme values) + developed in C++ (`Rcpp`) ] .pull-right[  ] ??? Several R packages make it possible to perform smoothing. [For example, the spatstat package dedicated to the analysis of spatial point processes is very complete. It includes a smoothing function (density.ppp) and various functions for choosing optimal bandwidths (bw.diggle, bw.frac...).] Often, their functions rely on a Fast Fourier Transform to calculate the smoothing. But this process is not suitable for situations where edge effects are important... The btb R package was developed in 2018 by the French National Institute of Statistics and Economic Studies (Insee). It deals with edge effects and also makes it possible to use quantile smoothing, which has the advantage of being less sensitive to extreme values [and thus enriches the analysis of some variables, in particular income variables.] [R software is very polyvalent and has a very flexible grammar but on the other hand it is slow. To circumvent this limitation, ] The btb package has been developed in C++ using the Rcpp package. We thus benefit from the R Syntax and the power of C++ with a relatively modest development cost. --- .partie[01] # Spatial smoothing .pull-left[ **Choice of parameters** + The **kernel** describes how the neighborhood is approached ; + The **bandwidth** quantifies the "size" of this neighborhood (to be chosen according to a bias/variance trade-off) ; + The **geographical level** from which the smoothed values are estimated ; + The **treatment of edge effects** makes explicit how geographical boundaries and the limits of observation territory are taken into account in the analysis. ] -- .pull-right[ **In btb...** + _**quadratic kernel** estimation method_ </br> + _a **variable bandwidth**_ </br> + _**square** whose size can be chosen_ </br> + _taken into account. **conservative method**_ ] ??? [Spatial smoothing is a non-parametric estimation method for the intensity function of a point process with observed values in R².] In spatial smoothing, the intensity function in one point x is found by calculating the average points observed per unit surface on neighbourhoods containing x. And you have to determine various parameters: - the kernel which describes how the neighborhood is approached ; - the bandwidth which is the size of this neighborhood - the geographical level - and how to deal or not with edge effects. In btb - the kernel is quadratic - the variable can be chosen by the user - we use a squared grid with chosen size - and the edge effects are taken into account, using a conservative method : that is to say that before and after smoothing, the number of points observed is identical. - --- class: inverse .partie[02] .NumeroPartie[02] .TitrePartie[Example: the housing prices in Paris in 2021] --- .partie[02] # Database ## « [**D**emandes de **V**aleurs **F**oncières](https://www.data.gouv.fr/fr/datasets/demandes-de-valeurs-foncieres-geolocalisees/) », - Real-estate transactions database (houses and apartments) - In 2021 - Paris region - Geolocalized (1 transaction = 1 geographic point) Variables used in the following example : - `id_mutation` : id for each transaction - `valeur_fonciere` : price in euros - `surface_reelle_bati` : surface in square meters - `x` : longitude (**Lambert 93 projection**) - `y` : latitude (**Lambert 93 projection **) ??? In this example, we will extract our data from the source "Demande de valeur foncière". This source gives information about real estate transactions in France. In particular, the transactions are geolocalized thanks to the longitude and latitude variables. We'll show how to smooth prices per square meters in the town of Paris in 2021. --- .partie[02] # Load data .pull-left[ ## Load map layer ```r url_suburbs <-"https://minio.lab.sspcloud.fr/projet-formation/r-lissage-spatial/depCouronne.gpkg" suburbs_sf <- sf::st_read(url_suburbs) ``` ```r suburbs_sf <- suburbs_sf %>% rename(geometry=geom) ```
] .pull-right[ ## Load database ```r url_file <- url("https://minio.lab.sspcloud.fr/projet-formation/r-lissage-spatial/ventesImmo_couronneParis.RDS") dfBase <- readRDS(url_file) dfBase <- dfBase[,c("id_mutation", "valeur_fonciere", "surface_reelle_bati", "x","y")] ``` <div style="border: 1px solid #ddd; padding: 0px; overflow-y: scroll; height:200px; overflow-x: scroll; width:500px; "><table> <thead> <tr> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> id_mutation </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> valeur_fonciere </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> surface_reelle_bati </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> x </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> y </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 2021-447023 </td> <td style="text-align:right;"> 480000 </td> <td style="text-align:right;"> 64 </td> <td style="text-align:right;"> 647357.3 </td> <td style="text-align:right;"> 6868635 </td> </tr> <tr> <td style="text-align:left;"> 2021-447024 </td> <td style="text-align:right;"> 345000 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 644483.5 </td> <td style="text-align:right;"> 6867695 </td> </tr> <tr> <td style="text-align:left;"> 2021-447025 </td> <td style="text-align:right;"> 384000 </td> <td style="text-align:right;"> 41 </td> <td style="text-align:right;"> 648001.8 </td> <td style="text-align:right;"> 6866153 </td> </tr> <tr> <td style="text-align:left;"> 2021-447027 </td> <td style="text-align:right;"> 261900 </td> <td style="text-align:right;"> 44 </td> <td style="text-align:right;"> 647414.8 </td> <td style="text-align:right;"> 6868937 </td> </tr> <tr> <td style="text-align:left;"> 2021-447029 </td> <td style="text-align:right;"> 407200 </td> <td style="text-align:right;"> 24 </td> <td style="text-align:right;"> 646929.9 </td> <td style="text-align:right;"> 6864730 </td> </tr> </tbody> </table></div> ] ??? First, we import layer to get Paris boundaries. Here, you can see the 3 departments called Petite Couronne. It's the dense urbain area around the town of Paris (the polygon in the middle). Secondly, we import our transactions data and we select the useful variables. --- .partie[02] # Selecting data and dealing with edge effects .pull-left[ **1.** Transform observations into geometric points ```r sfBase <- sf::st_as_sf(dfBase, coords = c("x", "y"), crs = 2154) ``` **2.** Buffer zone ```r paris_sf <- suburbs_sf %>% filter(code=="75") buffer_sf <- st_buffer(paris_sf,dist = 2000) ``` **3.** Geographical intersection ```r sfBase_buffer <- st_join(sfBase, buffer_sf, left=FALSE) ``` ] .pull-right[
] ??? Handling potential edge effects is an important part of spatial smoothing. Here, we are only interested about prices inside Paris Town. Anyway, it can be important (and sometimes mandatory) to use data beyond the very border of your studied zone. Otherwise, it can generate artifacts on the edge of this zone. That's why we'll smooth the transactions in Paris plus a buffer (here 2000 meters). On the left, you can see a way to handle it. --- .partie[02] # Step 0 : Cells aggregations .pull-left[ + Better understand your data before smoothing it : **aggregation** inside grid cells ! + It's really easy using `btb` functions such as : + `btb_add_centroids` + `btb_ptsToGrid` ➡️ Let's calculate the mean price per square meters (among 2021 transactions) ] .pull-right[ <!-- --> ] ??? Now, you could directly smooth your data and get the result. But, to better understand your data, you can use a grid and calculate mean prices inside all the cells (here with 50 meters squares). The package makes it very easy using the following functions. The result is far from synthetic (and beautiful) : but still, it's a first insight ! For example, it seems that prices are much higher in the center and the west than on the borders of the city and on the north east. --- .partie[02] # Smoothing [1/3] ## Spatial smoothing with `btb::btb_smooth` <small> - `pts` : table of points with only numeric variables (geometric object or not) ; - `iCellSize` : cell size in meters (granularity of the underlying grid) ; - `iBandwidth` : smoothing bandwidth in meters. </small> ```r pts <- sfBase_buffer[,c("valeur_fonciere","surface_reelle_bati")] smooth_result <- btb::btb_smooth(pts = pts, iCellSize = 50, iBandwidth = 800) ``` <div style="border: 1px solid #ddd; padding: 0px; overflow-y: scroll; height:200px; "><table> <thead> <tr> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> x </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> y </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> valeur_fonciere </th> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> surface_reelle_bati </th> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> geometry </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> 651075 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 1631.677 </td> <td style="text-align:right;"> 0.3346249 </td> <td style="text-align:left;"> POLYGON ((651050 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651125 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 1609.976 </td> <td style="text-align:right;"> 0.3315480 </td> <td style="text-align:left;"> POLYGON ((651100 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651175 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 1584.218 </td> <td style="text-align:right;"> 0.3279684 </td> <td style="text-align:left;"> POLYGON ((651150 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651225 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 1556.653 </td> <td style="text-align:right;"> 0.3240574 </td> <td style="text-align:left;"> POLYGON ((651200 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651275 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 1536.788 </td> <td style="text-align:right;"> 0.3216315 </td> <td style="text-align:left;"> POLYGON ((651250 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651325 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 1544.332 </td> <td style="text-align:right;"> 0.3254294 </td> <td style="text-align:left;"> POLYGON ((651300 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651375 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 1625.804 </td> <td style="text-align:right;"> 0.3469070 </td> <td style="text-align:left;"> POLYGON ((651350 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651425 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 1802.801 </td> <td style="text-align:right;"> 0.3856498 </td> <td style="text-align:left;"> POLYGON ((651400 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651475 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 2050.376 </td> <td style="text-align:right;"> 0.4335484 </td> <td style="text-align:left;"> POLYGON ((651450 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651525 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 2335.153 </td> <td style="text-align:right;"> 0.4846045 </td> <td style="text-align:left;"> POLYGON ((651500 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651575 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 2629.270 </td> <td style="text-align:right;"> 0.5346698 </td> <td style="text-align:left;"> POLYGON ((651550 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651625 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 2908.360 </td> <td style="text-align:right;"> 0.5799479 </td> <td style="text-align:left;"> POLYGON ((651600 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651675 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 3148.775 </td> <td style="text-align:right;"> 0.6164544 </td> <td style="text-align:left;"> POLYGON ((651650 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651725 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 3332.209 </td> <td style="text-align:right;"> 0.6412037 </td> <td style="text-align:left;"> POLYGON ((651700 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651775 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 3447.298 </td> <td style="text-align:right;"> 0.6524546 </td> <td style="text-align:left;"> POLYGON ((651750 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652325 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4018.197 </td> <td style="text-align:right;"> 0.7358110 </td> <td style="text-align:left;"> POLYGON ((652300 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652375 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4196.404 </td> <td style="text-align:right;"> 0.7874709 </td> <td style="text-align:left;"> POLYGON ((652350 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652425 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4397.223 </td> <td style="text-align:right;"> 0.8454570 </td> <td style="text-align:left;"> POLYGON ((652400 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652475 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4582.997 </td> <td style="text-align:right;"> 0.8990014 </td> <td style="text-align:left;"> POLYGON ((652450 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652525 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4724.783 </td> <td style="text-align:right;"> 0.9392723 </td> <td style="text-align:left;"> POLYGON ((652500 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652575 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4794.874 </td> <td style="text-align:right;"> 0.9634176 </td> <td style="text-align:left;"> POLYGON ((652550 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652625 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4782.901 </td> <td style="text-align:right;"> 0.9702811 </td> <td style="text-align:left;"> POLYGON ((652600 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652675 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4690.995 </td> <td style="text-align:right;"> 0.9612632 </td> <td style="text-align:left;"> POLYGON ((652650 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652725 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4542.880 </td> <td style="text-align:right;"> 0.9437466 </td> <td style="text-align:left;"> POLYGON ((652700 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652775 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4392.034 </td> <td style="text-align:right;"> 0.9236667 </td> <td style="text-align:left;"> POLYGON ((652750 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652825 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4251.584 </td> <td style="text-align:right;"> 0.9012250 </td> <td style="text-align:left;"> POLYGON ((652800 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652875 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 4118.135 </td> <td style="text-align:right;"> 0.8757284 </td> <td style="text-align:left;"> POLYGON ((652850 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652925 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 3993.116 </td> <td style="text-align:right;"> 0.8479880 </td> <td style="text-align:left;"> POLYGON ((652900 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 652975 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 3879.341 </td> <td style="text-align:right;"> 0.8193450 </td> <td style="text-align:left;"> POLYGON ((652950 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 653025 </td> <td style="text-align:right;"> 6855175 </td> <td style="text-align:right;"> 3777.985 </td> <td style="text-align:right;"> 0.7904079 </td> <td style="text-align:left;"> POLYGON ((653000 6855200, 6... </td> </tr> <tr> <td style="text-align:right;"> 651075 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 2296.463 </td> <td style="text-align:right;"> 0.4743923 </td> <td style="text-align:left;"> POLYGON ((651050 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651125 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 2226.652 </td> <td style="text-align:right;"> 0.4621298 </td> <td style="text-align:left;"> POLYGON ((651100 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651175 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 2149.563 </td> <td style="text-align:right;"> 0.4476953 </td> <td style="text-align:left;"> POLYGON ((651150 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651225 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 2067.726 </td> <td style="text-align:right;"> 0.4324835 </td> <td style="text-align:left;"> POLYGON ((651200 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651275 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 2000.062 </td> <td style="text-align:right;"> 0.4206806 </td> <td style="text-align:left;"> POLYGON ((651250 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651325 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 2007.709 </td> <td style="text-align:right;"> 0.4264468 </td> <td style="text-align:left;"> POLYGON ((651300 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651375 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 2134.100 </td> <td style="text-align:right;"> 0.4547018 </td> <td style="text-align:left;"> POLYGON ((651350 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651425 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 2383.931 </td> <td style="text-align:right;"> 0.5035333 </td> <td style="text-align:left;"> POLYGON ((651400 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651475 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 2716.738 </td> <td style="text-align:right;"> 0.5653020 </td> <td style="text-align:left;"> POLYGON ((651450 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651525 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 3101.017 </td> <td style="text-align:right;"> 0.6339710 </td> <td style="text-align:left;"> POLYGON ((651500 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651575 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 3496.909 </td> <td style="text-align:right;"> 0.7018816 </td> <td style="text-align:left;"> POLYGON ((651550 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651625 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 3866.389 </td> <td style="text-align:right;"> 0.7627798 </td> <td style="text-align:left;"> POLYGON ((651600 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651675 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 4186.182 </td> <td style="text-align:right;"> 0.8127948 </td> <td style="text-align:left;"> POLYGON ((651650 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651725 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 4443.669 </td> <td style="text-align:right;"> 0.8496359 </td> <td style="text-align:left;"> POLYGON ((651700 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651775 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 4626.341 </td> <td style="text-align:right;"> 0.8710843 </td> <td style="text-align:left;"> POLYGON ((651750 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651825 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 4737.540 </td> <td style="text-align:right;"> 0.8775063 </td> <td style="text-align:left;"> POLYGON ((651800 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651875 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 4779.346 </td> <td style="text-align:right;"> 0.8694993 </td> <td style="text-align:left;"> POLYGON ((651850 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651925 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 4740.050 </td> <td style="text-align:right;"> 0.8460192 </td> <td style="text-align:left;"> POLYGON ((651900 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 651975 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 4666.035 </td> <td style="text-align:right;"> 0.8177179 </td> <td style="text-align:left;"> POLYGON ((651950 6855250, 6... </td> </tr> <tr> <td style="text-align:right;"> 652025 </td> <td style="text-align:right;"> 6855225 </td> <td style="text-align:right;"> 4670.863 </td> <td style="text-align:right;"> 0.8081251 </td> <td style="text-align:left;"> POLYGON ((652000 6855250, 6... </td> </tr> </tbody> </table></div> ??? Now, let's smooth your data. We'll use the btb_smooth function, the most important function of the BTB package. In this example, we only need 3 parameters : ...... - we select prices and surfaces for our transactions - we smooth it Let's take a look at the output - This is a sf table, a table of geometric square cells - Price and surface variables have been smoothed. --- .partie[02] # Smoothing [2/3] .pull-left[ ## Get the smoothed prices per m² ```r smooth_result <- smooth_result %>% mutate(smooth_price= valeur_fonciere / surface_reelle_bati) ``` ## Only keep the cells inside Paris ```r smooth_result <- smooth_result %>% st_join(paris_sf[,"geometry"],left=F) ``` <!-- ```{r showSmoothed, echo=FALSE} --> <!-- kbl(smooth_result[1:50,]) %>% --> <!-- scroll_box(width = "500px", height = "500px") --> <!-- ``` --> ] .pull-right[ ## Map the result <!-- --> ] ??? Then : - we calculate the smoothed ratio : the smoothed price per square meters - And, finally, we only keep the results in Paris using geographic intersection. The map shows a spatially smoothed representation of prices for each square meters sold in Paris in 2021. --- .partie[02] # Smoothing [3/3] ## Possible with different bandwidths .pull-left[ <!-- --> ] .pull-right[ <!-- --> ] ??? Depending whether you want structural or specific results, you can choose a wider or a smaller bandwidth. --- .partie[02] # Find BTB .pull-left[ ## `btb` available on CRAN and Github ```r install.packages("btb") ``` ## Find all the documentation you need Please visit `btb` website : ➡️ https://inseefr.github.io/btb/ ## And do not hesitate to contact us ! ➡️ analyse-urbaine@insee.fr ] .pull-right[ ## Thank you for your attention !  ] --- class: thanks, center, middle ## Find us on: [<img src="css/img/inseeFR.svg" style="height:18px"></img>](https://insee.fr/fr/accueil)  [<img src="css/img/Twitter.svg" style="height:18px"></img>](https://twitter.com/InseeFr)  [<img src="css/img/YouTube.svg" style="height:18px"></img>](https://www.youtube.com/channel/UChCCvJTbZEYsCXyfu27eQ6g)  [<img src="css/img/LinkedIn.svg" style="height:18px"></img>](https://www.linkedin.com/company/insee) <div class="auteur"> <p>Kim Antunez <br> Julien Pramil <br> Insee, France <br> <a href="mailto:analyse-urbaine@insee.fr" class="email">analyse-urbaine@insee.fr</a></p> </div> .rappel_contexte[]