I have a data points of presence-absence records and I want to perform joint-count test as it was suggested in the post https://gis.stackexchange.com/a/388939/178392 by calculating it on a grid (raster). The raster have to contain no-NA values only in the records cells I used for this rasterFromXYZ function from raster package. At this point sometimes I get NA for the p_values of the test. Is it correct what I did?

cells_data <- cellFromXY(Raster_[[1]], xy =xy ) # Raster_[[1]] is the raster of reference and xy are UTM locations of my presence-absence data
xy_cells <- xyFromCell(Raster_[[1]], cell=cells_data)
data_cells <- as.data.frame(cbind(xy_cells, data$P_A))
colnames(data_cells) <- c('x', 'y', 'P_A') 
coordinates(data_cells) <- ~ x + y
proj4string(data_cells)=crs(Raster_[[1]]) # 
Raster_PA <- rasterFromXYZ(data_cells, res= res(Raster_[[1]]), crs= crs(Raster_[[1]]))
Raster_PA_ <- extend(Raster_PA, y=extent(Raster_[[1]]))
Raster_PA_ <- mask(Raster_PA_, Raster_[[1]] )
pA <- rasterToPolygons(Raster_PA_, dissolve=FALSE)
nb <- poly2nb(pA, queen = T)
W <- nb2listw(nb, style='B', zero.policy=TRUE)
JCT <- joincount.test(as.factor(pA$layer), W , zero.policy=TRUE) 

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.