Search code examples
rgeospatialcorrelationrasterspatialpack

Correlation between 2 rasters accounting for spatial autocorrelation


I want to test the correlation in the values between 2 spatial raster data sets (that perfectly overlap).

I could just do:

correlation(getValues(raster1), getValues(raster2))

but both raster datasets are spatial autocorrelated.

Instead, I am using:

modified.ttest(getValues(raster1), getValues(raster2), coordinates) 

from the SpatialPack library. This is based on Dutilleul's test that modifies that effective sample size based on the degree of autocorrelation.

However, the modified test does not change the estimated correlation coefficient, only the p-value.

How do I also correct the estimated correlation coefficient for the extent of autocorrelation?


Solution

  • This is more a stats than a programming question.

    I do not think you can "correct the correlation coefficient for autocorrelation". The correlation coefficient is what it is. It is not affected by "oversampling".

    a <- 1:10
    b <- c(1:5,1:5)
    cor(a,b)
    #[1] 0.492366
    

    No "inflation" when using the same values twice

    cor(c(a,a),c(b,b))
    #[1] 0.492366
    

    The p-value is affected

    t.test(a,b)$p.value
    #[1] 0.03554967
    t.test(c(a,a), c(b,b))$p.value
    #[1] 0.002042504
    

    You can adjust the p-value for oversampling. However, a question with raster data is whether you should indeed consider these as a sample. That depends on context, but raster data often represent the entire population (with some local averaging given that cells are discreet). If there is no uncertainty due to (a small) sample size, presenting a p-value is not meaningful.