I have run my data in R, and created a distribution mapof my data (Clay Soil Property).

I want to detect in a way the spatial outliers that i can see from the map, and remove them in order to execute kriging NOT in all the set, but in the remaining data (except the outliers).

Do you have any idea with the code i should write?

Until now, i wrote the following code for the creation of the distribution map:

#Next steps for Kriging Methods

boundary <- st_read("Aoi.shp")
mycrs <- st_crs(boundary)

mydata <- read.csv("Attributesfixed.csv", sep = ";")
mydata2 <- mydata %>% select("X","Y","PH","CACO3","SAND","SILT", "CLAY" ,"OM","CEC")

mydata2 <- st_as_sf(mydata2, coords=c("X","Y"), crs=mycrs)
ggplot() + 
  geom_sf(data=boundary, color="black", size=1) +
  geom_sf(data=mydata2, aes(color=CLAY), size=3) +

And i plotted the map you can see:enter image description here

This is the code i wrote for the ordinary kriging BUT in the whole set.

#Mask for ordinary kriging

mask <- read_stars("AoiGrid")
st_crs(mask) <- mycrs

# ordinary kriging
mydata2.krig <- krige(CLAY~1, mydata2, 
                      newdata=mask, vgm)

names(mydata2.krig)[1] <- "CLAY.pred"

min(mydata2.krig$CLAY.pred, na.rm=T); max(mydata2.krig$CLAY.pred, na.rm=T)

ggplot() +
  geom_stars(data=mydata2.krig["CLAY.pred"]) +
  scale_fill_gradient(low="yellow", high="dark blue", limits=c(18,60)) +
  geom_sf(data=mydata2, shape=1, aes(size=CLAY))

I want to run it in the set without the outliers, that i will previously remove in some way!

  • How are you defining 'outliers'? Spatial data isn't like numeric, where you can rank and exclude things with a high deviance.
    – Mox
    Jan 6 at 21:43
  • @Mox Thank you verymuch for your kind response! I mean, that for example,in the right down area (southeast) i have clay values: 15, 15.6, 16, 16.5 and one value that is 35. The latter, is the spatial outlier represented as the yellow dot. How can i remove it?
    – Dimitris K
    Jan 6 at 22:02
  • @Mox Do I helped with the attempof this expanation?
    – Dimitris K
    Jan 6 at 22:11
  • I've removed the RStudio tag since this isn't an RStudio problem. Added the R tag.
    – Spacedman
    Jan 13 at 17:19
  • You need a mathematical definition of an "outlier", not just "oh, that 35 near to the 16s is an outlier because I can see a yellow dot next to some blue dots".
    – Spacedman
    Jan 13 at 17:22


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.