Pixelwise correlation between of two time series rasters

1,154 views
Skip to first unread message

Jaber B

unread,
Feb 1, 2016, 4:52:51 PM2/1/16
to Maxent
Any know a package that could do a Spearman correlation between two rasters? I have looked online and I think I didn't find any that worked.
thanks,
J

Ahmed El-Gabbas

unread,
Feb 1, 2016, 7:52:58 PM2/1/16
to Maxent
Some code like this may be useful:

require(raster)
require(dismo)
# Loading some rasters
fnames <- list.files(path=paste(system.file(package="dismo"), '/ex', sep=''),  pattern='grd', full.names=TRUE )
predictors <- stack(fnames[1:4])

#### 1. pearson correlation ####
cor(as.data.frame(predictors, na.rm=T), method = "pearson")
# bio1 bio12 bio16 bio17
# bio1 1.0000000 0.5240536 0.6210404 0.1225208
# bio12 0.5240536 1.0000000 0.9314960 0.7346015
# bio16 0.6210404 0.9314960 1.0000000 0.4670012
# bio17 0.1225208 0.7346015 0.4670012 1.0000000

### the same as ###
layerStats(predictors, 'pearson', na.rm=T)$pearson
# bio1 bio12 bio16 bio17
# bio1 1.0000000 0.5240802 0.6210652 0.1225174
# bio12 0.5240802 1.0000000 0.9314799 0.7345565
# bio16 0.6210652 0.9314799 1.0000000 0.4668995
# bio17 0.1225174 0.7345565 0.4668995 1.0000000

# spearman correlation
cor(as.data.frame(predictors, na.rm=T), method = "spearman")
# bio1 bio12 bio16 bio17
# bio1 1.0000000 0.6264554 0.7016923 0.1846605
# bio12 0.6264554 1.0000000 0.9448034 0.6918693
# bio16 0.7016923 0.9448034 1.0000000 0.4669103
# bio17 0.1846605 0.6918693 0.4669103 1.0000000

Hope this helps,
Ahmed

Jaber B

unread,
Feb 1, 2016, 8:24:29 PM2/1/16
to Maxent
Thank you Ahmed,
I was looking for something that compares two rasters pixel by pixel and creates a third raster showing the correlation.
Something like this  but adapted to two rasters only
http://www.hakimabdi.com/20150101/an-r-function-to-test-pixelwise-correlation-between-two-time-series-of-raster-data/
 
Best,

Jesús Muñoz

unread,
Feb 2, 2016, 3:02:23 AM2/2/16
to max...@googlegroups.com

Spearman or Pearson correlation between two rasters is inappropriate, as the spatial component is lost. Use instead Lee’s statistic, now implemented in the R package ‘spdep’ (lee, lee.mc and lee.test functions):

 

Bivand, R., Altman, M., Anselin, L., Assunção, R., Berke, O., Bernat, A., Blanchet, G., Blankmeyer, E., Carvalho, M., Christensen, B., Chun, Y., Dormann, C., Dray, S., Halbersma, R., Krainski, E., Legendre, P., Lewin-Koh, N., Li, H., Ma, J., Millo, G., Mueller, W., Ono, H., Peres-Neto, P., Piras, G., Reder, M., Tiefelsdorf, M. & Yu, D. (2014) spdep: Spatial dependence: weighting schemes, statistics and models version 0.5-77. Available at:  http://cran.r-project.org/web/packages/spdep/index.html (accessed Oct 10th.).

 

Jesús Muñoz

Director

Real Jardín Botánico (CSIC)

C/ Claudio Moyano 1

E-28014 Madrid

ESPAÑA (Spain)

tlf. +34 914203017

 

 

--
You received this message because you are subscribed to the Google Groups "Maxent" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maxent+un...@googlegroups.com.
To post to this group, send email to max...@googlegroups.com.
Visit this group at https://groups.google.com/group/maxent.
For more options, visit https://groups.google.com/d/optout.


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7357 / Virus Database: 4522/11529 - Release Date: 01/31/16

Lee 2001_bivariate spatial association measure.pdf
Bivand 2014_spdep Spatial dependencies.pdf

Jaber B

unread,
Feb 2, 2016, 1:00:49 PM2/2/16
to Maxent
Hi Jesus,
I tried to use the "lee.test" from the package spdep. It seems that it works with numeric vectors and not directly with rasters.  Have you ever used it with rasters
If so can you please guide me a bit.
Thanks,
J

Jaber B

unread,
Feb 2, 2016, 1:10:17 PM2/2/16
to Maxent
Also, Lee test looks more used for spatial Auto correlation and not to look for correlation between two different rasters

Alaa Eldeen

unread,
Feb 3, 2016, 5:49:55 AM2/3/16
to max...@googlegroups.com
You can use function corLocal in raster package
But I don't think the output will be helpful 
--
Alaaeldin Soultan
PhD researcher
MaxPlanck Institute for Ornithology
Am Obstberg 1
78315 Radolfzell, Germany
Tel: +49 (0)7732 1501 911
Mob.+4915757474779



Ps:  It takes 24 trees to produce 1 ton of office paper! Think… is it really necessary to print this email?

Reply all
Reply to author
Forward
0 new messages