1

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

  • 2
    I am working on "retooling" this function so that it does not require spdep to construct a neighbor matrix but rather takes advantage of some of the base functionality in the raster package. The focal function itself, does not allow for more than one raster however, getValuesFocal will return an array if a stack or brick is passed to it. Using this approach is speeding up multivariate focal operations considerably. Unfortunately, I am swamped but will move this up on my ever-growing to-do list and post it in the GitHub development version of spatialEco. – Jeffrey Evans Apr 18 at 14:19
  • Thanks @JeffreyEvans and good luck! – Sam Apr 23 at 7:00
  • @JeffreyEvans, Thank you for this! Any news about this? I do run on the same issue. – geo_dd Jul 17 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.