Estimate spatial kernel density from raster and output kernel values in a grid

I would like to use a raster map (find below) to estimate or create a kernel density distribution. The objective is to extrapolate the kernel density function and re-use it in order to distribute a traits in space according to such kernel density function.

Do yo have any suggestion?

I tried using the sp.kde function in SpatialEco R package. However, it estimates a kernel density in continuos terms, while I would like to distribute the kernel density values in a 23 x 23 grid (space). In other words, I would write in each cell of the picture below the corresponding kernel value. • I don't think your question as written makes any sense. You have a grid of values ranging from -60 to +60. A kernel density function is a strictly positive density function derived from a set of discrete point events. How are you trying to connect these two? You could add 60 to your raster and get something that is positive and use it as a density, but it wouldn't be a kernel density function. You could sample points from that density and then use those points to compute a kernel density function. But I don't see what that gets you... – Spacedman Nov 15 '18 at 17:06
• @Spacedman, first, thank you for your comment. Indeed, I do not have very clear ideas. I'm new to spatial statistics. My objective is to distribute a certain trait across the landscape according to the kernel density value in each cell. For instance, I want to distribute the amount of air polluted across the landscape according to a kernel density estimated by this raster, knowing that the total amount of air polluted across the whole landscape is 30000 (it is a fake example). A bit more clear what I would like to do? – CafféSospeso Nov 15 '18 at 17:18
• You want to generate a grid of values such that sum(grid) = 30000 and grid[i,j] = f(this[i,j]) where this is the pattern above and f is some function? – Spacedman Nov 15 '18 at 19:08
• Shall I use a Geographically weighted model? – CafféSospeso Nov 16 '18 at 10:41
• I don't see any reason to do that. If you add a constant of about 60 to the grid, then divide all cells by the sum of the grid, the multiply each cell by 30,000 you'll get a grid such that sum(grid) = 30000 and it looks like the grid in your question. – Spacedman Nov 16 '18 at 11:56