Welcome to the RPubs for the book ‘Applied Spatial Statistics And Econometrics: Data Analysis in R’ (Routledge, 2nd edition, 2026) (ed.Katarzyna Kopczewska).

The book was written by Spatial Warsaw team based at the Faculty of Economic Sciences at University of Warsaw. Visit us on LinkedIn.

This site is a collection of all R codes included in this book. These are just the codes - no comments, no explanations what, why and how. All those details are in the book.

This is introductory part. It references all data used in the book and includes links to RPubs for analytical chapters:

#Introduction: Reading the data and datasets description (Katarzyna Kopczewska)

The book uses a few datasets that are available here. They are as follows:

Please download them, unzip without subfolders and put to your Working Directory.

# starter for work
# set working directory – please set own path
setwd("C:/my_folder_with_data") # please set own path

# read the universal packages (when downloaded) and set seed
library(sf)           # to operate in sf class
library(ggplot2)    # for plotting
set.seed(9876)      # for reproducibility of all analyses

# read regional data
data<-read.csv("regional_dataset.csv", header=TRUE, sep=";", dec=",", encoding="UTF-8")
data23<-data[data$year==2023,]

# read point data for firms
points<-read.csv("firms_data_utf8.csv", header=TRUE, sep=",", dec=".", encoding="UTF-8")
points.sf<-st_as_sf(points, coords=c("crds.x", "crds.y"), crs=4326)

# read poviat and NUTS2 contour maps (shapefile) 
pov<-st_read("powiaty.shp", options = "ENCODING=UTF-8") # 380 units
pov<-st_transform(pov, 4326)        # reproject to WGS84

voi<-st_read("wojewodztwa.shp", options="ENCODING=UTF-8") # 16 units 
voi<-st_transform(voi, 4326)        # reproject to WGS84

# create fragments of maps
region.voi<-voi[voi$JPT_NAZWA_=="lubelskie",] # create a map subset
units<-which(data23$region_name=="lubelskie")
region.pov<-pov[units, ] 

# read population grid for Lubelskie region
grid<-st_read("POP_lub.shp", stringsAsFactors=FALSE)
grid<-st_transform(grid, 4326)

# read locations of cities in lubelskie region
cities<-read.csv("cities in lubelskie region.csv", header=TRUE, sep=";", dec=".", encoding="UTF-8")

# read data on population in the biggest cities in Poland
popul<-read.csv("population_in_cities.csv", header=TRUE, dec=".", sep=",")

# read point data on population in Lubelskie region
popul.points<-read.csv("points_popul_lub.csv", header=TRUE, dec=".", sep=",")

# read postal adresses of firms in Warsaw
firms_waw<-read.csv("firms_warszawa.csv", header=TRUE, sep=",", dec=".", encoding="UTF-8")

Figure A.1: Plots of contour maps from shapefiles: a) NUTS2 with 16 units, b) poviats with 380 units

Figure A.2: Plot of grid: a) contours only, b) contours filled with variable values

Figure A.3: Plots of contour maps from shapefiles: a) Lubelskie NUTS2 region, b) poviats in lubelskie region