Thursday, 23 April 2015

Raster correlation: Error (arg6) in raster.modified.ttest (R)


I am performing pairwise spatial correlation of 6 rasters using the raster.modified.ttest() function in R, as per this very useful post.


I have consistently had the following error with my data;


Error in SpatialPack::modified.ttest(x.var, y.var, sp::coordinates(x[nb[[i]],  : 
NA/NaN/Inf in foreign function call (arg 6)

and yet no errors with any dummy data. The following will yield a result;


s.pix1 <- as(raster(xmn=0,xmx=10,ymn=0,ymx=10,res=1,vals=sample(1:5,100,replace=T)), "SpatialGridDataFrame")
s.pix1[sample(1:100,25)]<-NA
s.pix2 <- as(raster(xmn=0,xmx=10,ymn=0,ymx=10,res=1,vals=sample(1:5,100,replace=T)), "SpatialGridDataFrame")

s.pix2[sample(1:100,25)]<-NA

corr <- raster.modifed.ttest(x=s.pix1, y=s.pix2)

plot(raster(corr), main="spatially adjusted raster correlation")

Very small sample areas of my data would also yield results. However forcing larger contiguous areas of NA data into the dummy data recreated the error;


s.pix1 <- as(raster(xmn=0,xmx=10,ymn=0,ymx=10,res=1,vals=sample(1:5,100,replace=T)), "SpatialGridDataFrame")
s.pix1[c(1:5,11:15,21:25,31:35,41:45)]<-NA
s.pix2 <- as(raster(xmn=0,xmx=10,ymn=0,ymx=10,res=1,vals=sample(1:5,100,replace=T)), "SpatialGridDataFrame")

s.pix2[c(1:5,11:15,21:25,31:35,41:45)]<-NA

corr <- raster.modifed.ttest(x=s.pix1, y=s.pix2)

Error in SpatialPack::modified.ttest(x.var, y.var, sp::coordinates(x[nb[[i]], :
NA/NaN/Inf in foreign function call (arg 6)

Could be a bug? @JeffreyEvans provided the excellent answer in the linked post




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...