BlasBenito/spatialRF

Spatial model is not working

IngridFarnell opened this issue · 3 comments

Hi Blas,
I am unable to get your rf_spatial function to work.
I am using your package to run a random forest framework on the attached data. My attached data is set up as such:

dependent.variable.name <- "dNBR"
predictor.variable.names <- colnames(G41607dat270)[2:29]
xy <- G41607dat270[, c("x", "y")]

dist_G41607dat270 <- pointDistance(G41607dat270[, c("x", "y")], lonlat = FALSE)
distance.matrix <- dist_G41607dat270
distance.thresholds <- c(0, 270, 381, 540, 810, 1080, 1350)
random.seed <- 1

The non-spatial model is as such:
model.non.spatial <- spatialRF::rf(
data = G41607dat270,
dependent.variable.name = dependent.variable.name,
predictor.variable.names = predictor.variable.names,
distance.matrix = distance.matrix,
distance.thresholds = distance.thresholds,
xy = xy,
seed = random.seed,
verbose = FALSE
)

I run the spatial model as such:
model.spatial <- spatialRF::rf_spatial(
model = model.non.spatial,
method = "mem.moran.sequential", #default method
verbose = FALSE,
)

I then run the get_spatial_predictors and it errors "Error in spatialRF::get_spatial_predictors(model.spatial) :
This function only works on models fitted with 'rf_spatial'"

It seems as though the spatial model function is not working. There is no difference between the non-spatial and spatial model.
G41607dat270.csv

Thanks for your help!

Dear Ingrid,
I come to this repo quite frequently, but your message went under the radar somehow. I am sorry for that.
I am going to check your code and write you ASAP.
Blas

Ok, I now see what happened here.

If you run your spatial model with "verbose = TRUE" you will see the message "The model residuals are not spatially correlated, there is no need to fit a spatial model", meaning that you don't need a spatial model for your data because the residuals are not spatially autocorrelated.

You can check this in the "model.non.spatial" by plotting the Moran's I of the residuals using "plot_moran(model.non.spatial)".

Please, let me know when you have read this message so I can close this non-issue.

I appreciate your interest in the package!

Blas