# Spatial interpolation from categorical data in R

I have a spatial point data set, where each point represents a person pronouncing a word in a specific fashion. Let's say I have six different pronunciations.

In an earlier iteration, I aggregated the point data to a hexagonal grid, the color represents the dominant pronunciation in the hexagon while the opacity represents its dominance, see: https://www.srf.ch/static/srf-data/data/2016/dialektkarten-karte/

Now I'd like to spatially interpolate the data to get a continuous surface, similar as Josh Katz did: http://www4.ncsu.edu/~jakatz2/files/dialectposter.png

He uses something he calls "k-nearest neighbor kernel smoothing" but he's not publishing his R code so I don't fully understand how that is supposed to work with categorical data. I perfectly understand on how to do it with continuous variables, but not with the latter.

The pseudo-algorithm I came up with so far:

• Repeat the "final estimate" formula for each pronunciation, using `yi = 1` for points where that pronunciation is used, `yi = 0` if not. By doing so, you get a grid for each pronunciation. The cells represent the probabilities of the respective pronunciation appearing at that grid cell.
• Now, find the most probable pronunciation in each grid cell. This determines the cell color (hue). Its probability determines the color value (i.e.: the higher, the darker, and vice versa).
• Find a way to map that resulting grid / raster - might be tricky because it contains two variables that need to be mapped to visual variables (dominant pronunciation and its probability).

But maybe this is completely off - and also, I wonder whether there are R packages for spatial interpolation of categorical data. So far I have only found `knn` methods and the like and I suppose I have to build something myself.

• Have you tried kknn? cran.rstudio.com/web/packages/kknn/kknn.pdf This package looks like it implements exactly what Katz has done. – Liam G May 31 '17 at 10:14
• Seems like what I'm looking for, yes. Thanks a lot! Right now I'm trying to figure out what the different parameters exactly mean - do you know of any tutorial or paper apart from that manual? I will try to post an answer to my own question once I come up with a good solution for my case. – wnstnsmth Jun 1 '17 at 19:02

In the end, I figured out a method with the `kknn` package. If somebody is still interested in this answer, I recommend reading my blog post on the topic.