# Correlation between rasters using R

In R, anyone know a method for measuring correlation between raster and spatialpixels, or between two rasters?. I read something about Kulldorff but do not understand how to use it, and maybe it's not the solution.

Ok, I will improve the question. I would like to compare a set of points representing where certain people live, and the number of times people have suffered thefts. In some cases it has not been stolen, in other cases once stolen and in other cases, two or three. For each person the exposure period is one year. I would like to compare these data against a raster population density created by european environment agency, also against a raster containing the proximity in meters to a commercial area. how i can measure the correlation between points and rasters?. At the end I have to study the correlation of a set of data (SpatialPointsDataFrame) against various rasters.

i know classical techniques of inference, and it's not geostadistics are in principle but I wonder if there is something more advanced. I do not understand the correlation with population density where exactly is the point, I would like to understand for example the density (mean, maximum, minimum, percentile ... etc) in a circle. If I do this by iterative methods can reach the same conclusion, creating rasters that soften the density of population, with formula. i know the focal methods of r raster package. But what I want to know is if there is a method that estimates the circle. A person does not move just right next to your home, it has a radius of action in which he lives. That's the circle I want to know it's like a cluster

• Have you got two rasters with the same resolution and cell size? Then get the values and run `cor` on them. Where did you 'read something about Kulldorff'? That's not helpful to us. What is it you are trying to do? Please try and improve your question. Commented Jun 23, 2013 at 8:04
• Ok, I will improve the question. Commented Jun 23, 2013 at 12:20

Firstly, what you have is a regression problem - how (if at all) does X depend on Y.

Secondly, you have a Poisson regression problem - X is a count, and fairly small count at that (0,1,2,3).

Thirdly you have two covariates or explanatory variables - population density and distance to commercial area.

Fourthly your data is spatial, so you might not assume that they are independent. This affects the inference from the parameter estimates (generally the standard errors will be smaller than they should be).

So, initially you should plug all those into a generalised linear model using the `glm` function. Then map the residuals at the data points and see if they look spatially correlated.

• +1 And if the residuals do appear correlated, the `geoRglm` package will handle that complication nicely. Commented Jun 24, 2013 at 16:56

How about you do the following steps: 1- Create a buffer for each point, based on your assumption of action area. 2 - Use zonal statistics to calculate de average of the population density for each circle. 3 - Calculate correlation in your new dataframe, where you now have, for each circle, a colum for the number of thefts and another for average density.