BlasBenito / spatialRF

R package to fit spatial models with Random Forest
https://blasbenito.github.io/spatialRF/
109 stars 16 forks source link

Spatial model is not working #8

Closed IngridFarnell closed 2 years ago

IngridFarnell commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Thanks so much for getting back to me Blas. Great news!

Cheers, Ingrid

On Tue, Mar 1, 2022 at 6:38 AM Blas Benito @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/BlasBenito/spatialRF/issues/8#issuecomment-1055511589, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHP6VSADEUZ4MFYSYE3YP5LU5YTW7ANCNFSM5OPYFWVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>