- 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.