- R: code to assess spatial independence of residuals of a model
This code is useful to check if the assumption of (spatial) independence between residuals of a model is met.
Useful because it can be applied to the residuals of any model we run
It generates a plot of bubbles located according to the X-Y coordinates of the corresponding residuals. The size of the bubbles represents the magnitude of the residuals, while the color indicates if they are positive or negative. If there is spatial independence of the residuals, no pattern should be observed in the disposition of the bubbles. NOTE: requires “sp” package
library(sp) #Load the sp package
Residuals<-resid(model) #Generates a vector with the residuals from the model
mydata <- data.frame(Residuals, RawData$XCooords, RawData$YCoords) # Generate a data frame with the residuals and corresponding coordinates (obtained from the dataset in which the model was ran)
colnames(mydata)<-c(“Residuals”,”X”, “Y”) #Assign names to the columns
coordinates(mydata) <- c(“X”,”Y”) #Identify which columns correspond to the coordinates
bubble (data, “Residuals“, col = c(“black”,”grey”), xlab = “X-coordinates”, ylab = “Y-coordinates”) #Plot the bubbles
- ArcGIS: Iterator option in Model Builder
This option allows to run the same function over all the files contained inside a folder, freeing the user from doing repetitive tasks.
Noelia,
Thank you so much for posting this code! Very helpful. Is bubble a default command in R or do you need to install a particular package?
Yes, it does require a package called “sp”. I’ll add that information to the post. Also, I just realized that the code of line needed more context for it to make sense. I will add some extra lines so it will be easier to understand how it works.
Thanks for pointing it out!
Noelia,
I thought it was helpful you shared the information about the iteration model because it is a little tricky to create a loop operation with python (at least for me)! This will expedite things in the future.
Thanks!