Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spatial model is not working #8

Closed
IngridFarnell opened this issue Feb 15, 2022 · 3 comments
Closed

Spatial model is not working #8

IngridFarnell opened this issue Feb 15, 2022 · 3 comments

Comments

@IngridFarnell
Copy link

IngridFarnell commented Feb 15, 2022

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!

@BlasBenito
Copy link
Owner

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

@BlasBenito
Copy link
Owner

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

@IngridFarnell
Copy link
Author

IngridFarnell commented Mar 1, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants