Motivation When you run simulations with spatially dependent data, you can use a weight matrix to quantify the nature and degree of dependence between observations. For example, suppose you would like to generate spatially correlated shocks (errors), (\varepsilon), specified as follows:
[ \varepsilon = \lambda W \cdot \varepsilon + u ]
where (W) is the weight matrix, (\lambda \in [0,1]) is a parameter that determines the degree of spatial dependence, and (u \sim N(0,\sigma^2)).
In this short blog post, I will show three ways to convert a raster (gridded) data into polygons. In the course of my research, I faced the need of this type of conversion on multiple occasions. As far as I am aware, there are two options to achieve this operation with (significantly) differing computation time.
library(raster) library(rgdal) library(sp) library(sf)
We use PRISM () data to demonstrate how we can get raster-to-polygons conversions done.