Interpolacion IDW

1.1 Instalacion librerias y paquetes

library(sf)
library(stars)
library(leaflet)
library(gstat)
library(automap)
library(raster)
library(RColorBrewer)

1.2 Verificacion y lugar de guardado

getwd()
[1] "/Users/carlitos/Documents/University/Geomatica/drive-download-20250223T004732Z-001"
    setwd("/Users/carlitos/Documents/University/Geomatica/drive-download-20250223T004732Z-001")

1.3 Declarar las variables

ruta_aoi="./municipios_muestreo.shp"
ruta_puntos="./puntos_muestreo.shp" 
ruta_raster="./dem_srtm_9377.tif"

1.4 Visualizar los archivos de datos (shp y tif) (tablas atributos)

 raster_dem=read_stars(ruta_raster, RasterIO = list(bands = 1))
    raster_dem
stars object with 2 dimensions and 1 attribute
attribute(s), summary of first 1e+05 cells:
                   Min. 1st Qu. Median    Mean 3rd Qu. Max.
dem_srtm_9377.tif  -247       0      0 131.274       0 1673
dimension(s):
    plot(raster_dem)
downsample set to 2

puntos = st_read(ruta_puntos)
Reading layer `puntos_muestreo' from data source `/Users/carlitos/Documents/University/Geomatica/drive-download-20250223T004732Z-001/puntos_muestreo.shp' using driver `ESRI Shapefile'
Simple feature collection with 67 features and 16 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 4968206 ymin: 2257635 xmax: 5005157 ymax: 2292361
Projected CRS: MAGNA-SIRGAS_Origen-Nacional
    gs_crs = st_crs(raster_dem)
    puntos = st_transform(puntos, crs = gs_crs)
    (puntos)
Simple feature collection with 67 features and 16 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 4968206 ymin: 2257635 xmax: 5005157 ymax: 2292361
Projected CRS: MAGNA-SIRGAS 2018 / Origen-Nacional
First 10 features:
   Department Municipali Latitude.D Longitude. Altitude.m  pH EC.dSm NH4.ppm NO3.ppm K2O.ppm P2O5.ppm SOC.pct Sand.pct Silt.pct Clay.pct Slope.pct                geometry
1   Santander   Confines   6.331580  -73.25827       1533 4.8   0.08    10.3     8.4   173.5     10.1    2.46     40.7     32.6     26.6      10.5 POINT (4971447 2257635)
2   Santander   Confines   6.345463  -73.28759       1489 4.9   0.07    10.3     5.4   122.9      8.9    1.62     51.2     26.1     22.6       9.2 POINT (4968206 2259171)
3   Santander   Confines   6.357339  -73.28138       1482 4.8   0.08    18.2     0.9   119.3      6.2    2.95     51.9     35.4     12.7       7.4 POINT (4968893 2260483)
4   Santander   Confines   6.360368  -73.24903       1581 4.7   0.07     6.7     2.3   181.9     12.1    1.02     37.3     36.1     26.5      12.6 POINT (4972470 2260816)
5   Santander   Confines   6.340922  -73.20868       1878 4.8   0.15    24.0    12.3   130.1      7.3    2.48     65.6     30.3      4.1       8.5 POINT (4976930 2258665)
6   Santander   Confines   6.357226  -73.23005       1742 4.8   0.09    11.7     1.2   131.3      4.8    1.60     40.8     46.5     12.6       7.5 POINT (4974568 2260467)
7   Santander   Confines   6.339062  -73.23301       1752 4.9   0.09     9.4     2.0    73.5     11.5    3.65     55.0     42.5      2.5       5.6 POINT (4974240 2258460)
8   Santander   Confines   6.402768  -73.22524       1715 4.8   0.08     9.4     5.9   194.0      6.6    2.12     33.7     45.4     20.9      13.7 POINT (4975101 2265500)
9   Santander   Confines   6.365608  -73.21098       1878 4.8   0.10    19.3     0.3   273.5      3.4    3.81     64.4     24.9     10.6       1.5 POINT (4976677 2261393)
10  Santander     Paramo   6.384360  -73.19552       1912 4.9   0.12    19.1     0.1   128.9     18.8    3.14     39.1     50.7     10.3      15.8 POINT (4978386 2263464)

1.5 Verificacion sistema de coordenadas y reproyeccion de puntos

st_crs(puntos)
Coordinate Reference System:
  User input: MAGNA-SIRGAS 2018 / Origen-Nacional 
  wkt:
PROJCRS["MAGNA-SIRGAS 2018 / Origen-Nacional",
    BASEGEOGCRS["MAGNA-SIRGAS 2018",
        DATUM["Marco Geocentrico Nacional de Referencia 2018",
            ELLIPSOID["GRS 1980",6378137,298.257222101,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",20046]],
    CONVERSION["Colombia Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",4,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",-73,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",0.9992,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",5000000,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",2000000,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, topographic mapping."],
        AREA["Colombia - onshore and offshore. Includes San Andres y Providencia, Malpelo Islands, Roncador Bank, Serrana Bank and Serranilla Bank."],
        BBOX[-4.23,-84.77,15.51,-66.87]],
    ID["EPSG",9377]]
    st_crs(raster_dem)
Coordinate Reference System:
  User input: MAGNA-SIRGAS 2018 / Origen-Nacional 
  wkt:
PROJCRS["MAGNA-SIRGAS 2018 / Origen-Nacional",
    BASEGEOGCRS["MAGNA-SIRGAS 2018",
        DATUM["Marco Geocentrico Nacional de Referencia 2018",
            ELLIPSOID["GRS 1980",6378137,298.257222101,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",20046]],
    CONVERSION["Colombia Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",4,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",-73,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",0.9992,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",5000000,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",2000000,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, topographic mapping."],
        AREA["Colombia - onshore and offshore. Includes San Andres y Providencia, Malpelo Islands, Roncador Bank, Serrana Bank and Serranilla Bank."],
        BBOX[-4.23,-84.77,15.51,-66.87]],
    ID["EPSG",9377]]
    if (identical(crs_raster, crs_puntos)) {
      cat("El sistema de referencia de coordenadas del raster y de los puntos es el mismo:\n")
      print(crs_raster)
    } else {
      cat("Los sistemas de referencia de coordenadas son diferentes.\n")
      cat("Raster:\n")
      print(crs_raster)
      cat("Puntos:\n")
      print(crs_puntos)
    }
El sistema de referencia de coordenadas del raster y de los puntos es el mismo:
Coordinate Reference System:
  User input: MAGNA-SIRGAS / Origen-Nacional 
  wkt:
PROJCRS["MAGNA-SIRGAS / Origen-Nacional",
    BASEGEOGCRS["MAGNA-SIRGAS",
        DATUM["Marco Geocentrico Nacional de Referencia",
            ELLIPSOID["GRS 1980",6378137,298.257222101,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4686]],
    CONVERSION["Colombia Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",4,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",-73,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",0.9992,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",5000000,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",2000000,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre."],
        AREA["Colombia - onshore and offshore. Includes San Andres y Providencia, Malpelo Islands, Roncador Bank, Serrana Bank and Serranilla Bank."],
        BBOX[-4.23,-84.77,15.51,-66.87]],
    ID["EPSG",9377]]
    puntos_reproj <- st_transform(puntos, crs_raster)
    
    (puntos_reproj)
Simple feature collection with 67 features and 16 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 4968206 ymin: 2257635 xmax: 5005157 ymax: 2292361
Projected CRS: MAGNA-SIRGAS / Origen-Nacional
First 10 features:
   Department Municipali Latitude.D Longitude. Altitude.m  pH EC.dSm NH4.ppm NO3.ppm K2O.ppm P2O5.ppm SOC.pct Sand.pct Silt.pct Clay.pct Slope.pct                geometry
1   Santander   Confines   6.331580  -73.25827       1533 4.8   0.08    10.3     8.4   173.5     10.1    2.46     40.7     32.6     26.6      10.5 POINT (4971447 2257635)
2   Santander   Confines   6.345463  -73.28759       1489 4.9   0.07    10.3     5.4   122.9      8.9    1.62     51.2     26.1     22.6       9.2 POINT (4968206 2259171)
3   Santander   Confines   6.357339  -73.28138       1482 4.8   0.08    18.2     0.9   119.3      6.2    2.95     51.9     35.4     12.7       7.4 POINT (4968893 2260483)
4   Santander   Confines   6.360368  -73.24903       1581 4.7   0.07     6.7     2.3   181.9     12.1    1.02     37.3     36.1     26.5      12.6 POINT (4972470 2260816)
5   Santander   Confines   6.340922  -73.20868       1878 4.8   0.15    24.0    12.3   130.1      7.3    2.48     65.6     30.3      4.1       8.5 POINT (4976930 2258665)
6   Santander   Confines   6.357226  -73.23005       1742 4.8   0.09    11.7     1.2   131.3      4.8    1.60     40.8     46.5     12.6       7.5 POINT (4974568 2260467)
7   Santander   Confines   6.339062  -73.23301       1752 4.9   0.09     9.4     2.0    73.5     11.5    3.65     55.0     42.5      2.5       5.6 POINT (4974240 2258460)
8   Santander   Confines   6.402768  -73.22524       1715 4.8   0.08     9.4     5.9   194.0      6.6    2.12     33.7     45.4     20.9      13.7 POINT (4975101 2265500)
9   Santander   Confines   6.365608  -73.21098       1878 4.8   0.10    19.3     0.3   273.5      3.4    3.81     64.4     24.9     10.6       1.5 POINT (4976677 2261393)
10  Santander     Paramo   6.384360  -73.19552       1912 4.9   0.12    19.1     0.1   128.9     18.8    3.14     39.1     50.7     10.3      15.8 POINT (4978386 2263464)

1.6 Interpolacion por metodo IDW

var="pH"
    puntos[var]
Simple feature collection with 67 features and 1 field
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 4968206 ymin: 2257635 xmax: 5005157 ymax: 2292361
Projected CRS: MAGNA-SIRGAS 2018 / Origen-Nacional
First 10 features:
    pH                geometry
1  4.8 POINT (4971447 2257635)
2  4.9 POINT (4968206 2259171)
3  4.8 POINT (4968893 2260483)
4  4.7 POINT (4972470 2260816)
5  4.8 POINT (4976930 2258665)
6  4.8 POINT (4974568 2260467)
7  4.9 POINT (4974240 2258460)
8  4.8 POINT (4975101 2265500)
9  4.8 POINT (4976677 2261393)
10 4.9 POINT (4978386 2263464)
  
    st_crs(puntos_reproj) 
Coordinate Reference System:
  User input: MAGNA-SIRGAS / Origen-Nacional 
  wkt:
PROJCRS["MAGNA-SIRGAS / Origen-Nacional",
    BASEGEOGCRS["MAGNA-SIRGAS",
        DATUM["Marco Geocentrico Nacional de Referencia",
            ELLIPSOID["GRS 1980",6378137,298.257222101,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4686]],
    CONVERSION["Colombia Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",4,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",-73,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",0.9992,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",5000000,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",2000000,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre."],
        AREA["Colombia - onshore and offshore. Includes San Andres y Providencia, Malpelo Islands, Roncador Bank, Serrana Bank and Serranilla Bank."],
        BBOX[-4.23,-84.77,15.51,-66.87]],
    ID["EPSG",9377]]
    crs(raster_dem)
[1] NA
  
    g = gstat(formula = pH ~ 1, data = puntos_reproj,set=list(idp=2))
    z = predict(g, raster_dem)
[inverse distance weighted interpolation]
    print(z)
stars object with 2 dimensions and 2 attributes
attribute(s), summary of first 1e+05 cells:
              Min.  1st Qu.   Median     Mean  3rd Qu.     Max.  NA's
var1.pred  5.04681 5.130046 5.162891 5.174822 5.238671 5.283381 0e+00
var1.var        NA       NA       NA      NaN       NA       NA 1e+05
dimension(s):

1.7 Formula establecida interpolacion

g = gstat(formula = pH ~ 1, data = puntos_reproj,set=list(idp=2))

1.8 Definicion parametros

z = predict(g, raster_dem)
[inverse distance weighted interpolation]
print(z)
stars object with 2 dimensions and 2 attributes
attribute(s), summary of first 1e+05 cells:
              Min.  1st Qu.   Median     Mean  3rd Qu.     Max.  NA's
var1.pred  5.04681 5.130046 5.162891 5.174822 5.238671 5.283381 0e+00
var1.var        NA       NA       NA      NaN       NA       NA 1e+05
dimension(s):
z = z["var1.pred",,]

1.9 Visualizacion resultados interpolacion

names(z) = "pH"
  b = seq(4, 7.5, 0.1)
plot(z, breaks = b, col = hcl.colors(length(b)-1, "Spectral"), reset = FALSE)
downsample set to 2
       plot(st_geometry(puntos_reproj), pch = 3, add = TRUE) 
        contour(z, breaks = b, add = TRUE)

1.10 Asignacion variable

interpolacion_idw="./ph_idw.tif"

1.11 Almacenar raster en archivo geotiff

write_stars(z, dsn = interpolacion_idw)

1.12 Zonas optimas jitomate

 zona_optima = prediccion
    zona_optima[zona_optima < 6.0 | zona_optima > 6.8] <- NA
    plot(zona_optima, col = hcl.colors(10, "blues"), main = "Zonas óptimas para jitomate")
downsample set to 2

Interpolacion por kriging

2.1 Creacion variograma empirico

   v_emp_ok = variogram(pH ~ 1, puntos_reproj)
plot(v_emp_ok)

2.2 Ajuste variograma a funcion

v_mod_ok = autofitVariogram(pH ~ 1, as(puntos_reproj, "Spatial"))
plot(v_mod_ok)

2.3 Formula interpolacion

g2 = gstat(formula = pH ~ 1, model = v_mod_ok$var_model, data = puntos_reproj)

2.4 Prediccion kriging

z = predict(g2, raster_dem)
[using ordinary kriging]
 print(z)
stars object with 2 dimensions and 2 attributes
attribute(s), summary of first 1e+05 cells:
               Min.   1st Qu.    Median      Mean 3rd Qu.     Max.
var1.pred  4.973535 5.0923192 5.1475910 5.1348409 5.18763 5.238132
var1.var   0.604284 0.7349258 0.8883815 0.9006311 1.04760 1.302663
dimension(s):

2.5 Visualizacion kriging

prediccion = z["var1.pred",,]
  names(prediccion) = "pH"
  b_predict = seq(4, 7, 0.1) 
  plot(prediccion, breaks = b_predict, col = hcl.colors(length(b_predict)-1, "Spectral"), reset = FALSE)
downsample set to 2

2.6 Visual varianza

varianza = z["var1.var",,]
  names(varianza) = "varianza pH"
  b_var = seq(0.1, 1.4, 0.1)

2.7 Distribucion varianza

plot(varianza, breaks = b_var, col = hcl.colors(length(b_var)-1, "Spectral"), reset = FALSE)
downsample set to 2
  plot(st_geometry(puntos_reproj), pch = 3, add = TRUE)

2.8 Asignacion formulas IDW y Kriging (g, g2) y grafico de burbujas

 cv2 = gstat.cv(g2)

  |                                                                                                                                                                                        
  |                                                                                                                                                                                  |   0%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===                                                                                                                                                                               |   2%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=====                                                                                                                                                                             |   3%[using ordinary kriging]

  |                                                                                                                                                                                        
  |========                                                                                                                                                                          |   5%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===========                                                                                                                                                                       |   6%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=============                                                                                                                                                                     |   8%[using ordinary kriging]

  |                                                                                                                                                                                        
  |================                                                                                                                                                                  |   9%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===================                                                                                                                                                               |  11%[using ordinary kriging]

  |                                                                                                                                                                                        
  |======================                                                                                                                                                            |  12%[using ordinary kriging]

  |                                                                                                                                                                                        
  |========================                                                                                                                                                          |  14%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===========================                                                                                                                                                       |  15%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==============================                                                                                                                                                    |  17%[using ordinary kriging]

  |                                                                                                                                                                                        
  |================================                                                                                                                                                  |  18%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===================================                                                                                                                                               |  20%[using ordinary kriging]

  |                                                                                                                                                                                        
  |======================================                                                                                                                                            |  21%[using ordinary kriging]

  |                                                                                                                                                                                        
  |========================================                                                                                                                                          |  23%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===========================================                                                                                                                                       |  24%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==============================================                                                                                                                                    |  26%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=================================================                                                                                                                                 |  27%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===================================================                                                                                                                               |  29%[using ordinary kriging]

  |                                                                                                                                                                                        
  |======================================================                                                                                                                            |  30%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=========================================================                                                                                                                         |  32%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===========================================================                                                                                                                       |  33%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==============================================================                                                                                                                    |  35%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=================================================================                                                                                                                 |  36%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===================================================================                                                                                                               |  38%[using ordinary kriging]

  |                                                                                                                                                                                        
  |======================================================================                                                                                                            |  39%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=========================================================================                                                                                                         |  41%[using ordinary kriging]

  |                                                                                                                                                                                        
  |============================================================================                                                                                                      |  42%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==============================================================================                                                                                                    |  44%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=================================================================================                                                                                                 |  45%[using ordinary kriging]

  |                                                                                                                                                                                        
  |====================================================================================                                                                                              |  47%[using ordinary kriging]

  |                                                                                                                                                                                        
  |======================================================================================                                                                                            |  48%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=========================================================================================                                                                                         |  50%[using ordinary kriging]

  |                                                                                                                                                                                        
  |============================================================================================                                                                                      |  52%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==============================================================================================                                                                                    |  53%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=================================================================================================                                                                                 |  55%[using ordinary kriging]

  |                                                                                                                                                                                        
  |====================================================================================================                                                                              |  56%[using ordinary kriging]

  |                                                                                                                                                                                        
  |======================================================================================================                                                                            |  58%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=========================================================================================================                                                                         |  59%[using ordinary kriging]

  |                                                                                                                                                                                        
  |============================================================================================================                                                                      |  61%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===============================================================================================================                                                                   |  62%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=================================================================================================================                                                                 |  64%[using ordinary kriging]

  |                                                                                                                                                                                        
  |====================================================================================================================                                                              |  65%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=======================================================================================================================                                                           |  67%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=========================================================================================================================                                                         |  68%[using ordinary kriging]

  |                                                                                                                                                                                        
  |============================================================================================================================                                                      |  70%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===============================================================================================================================                                                   |  71%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=================================================================================================================================                                                 |  73%[using ordinary kriging]

  |                                                                                                                                                                                        
  |====================================================================================================================================                                              |  74%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=======================================================================================================================================                                           |  76%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==========================================================================================================================================                                        |  77%[using ordinary kriging]

  |                                                                                                                                                                                        
  |============================================================================================================================================                                      |  79%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===============================================================================================================================================                                   |  80%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==================================================================================================================================================                                |  82%[using ordinary kriging]

  |                                                                                                                                                                                        
  |====================================================================================================================================================                              |  83%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=======================================================================================================================================================                           |  85%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==========================================================================================================================================================                        |  86%[using ordinary kriging]

  |                                                                                                                                                                                        
  |============================================================================================================================================================                      |  88%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===============================================================================================================================================================                   |  89%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==================================================================================================================================================================                |  91%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=====================================================================================================================================================================             |  92%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=======================================================================================================================================================================           |  94%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==========================================================================================================================================================================        |  95%[using ordinary kriging]

  |                                                                                                                                                                                        
  |=============================================================================================================================================================================     |  97%[using ordinary kriging]

  |                                                                                                                                                                                        
  |===============================================================================================================================================================================   |  98%[using ordinary kriging]

  |                                                                                                                                                                                        
  |==================================================================================================================================================================================| 100%[using ordinary kriging]
  cv2 = st_as_sf(cv2)
  
  sp::bubble(as(cv2[, "residual"], "Spatial"))

 
  
  cv3 = gstat.cv(g)

  |                                                                                                                                                                                        
  |                                                                                                                                                                                  |   0%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===                                                                                                                                                                               |   2%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=====                                                                                                                                                                             |   3%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |========                                                                                                                                                                          |   5%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===========                                                                                                                                                                       |   6%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=============                                                                                                                                                                     |   8%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |================                                                                                                                                                                  |   9%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===================                                                                                                                                                               |  11%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |======================                                                                                                                                                            |  12%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |========================                                                                                                                                                          |  14%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===========================                                                                                                                                                       |  15%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==============================                                                                                                                                                    |  17%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |================================                                                                                                                                                  |  18%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===================================                                                                                                                                               |  20%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |======================================                                                                                                                                            |  21%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |========================================                                                                                                                                          |  23%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===========================================                                                                                                                                       |  24%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==============================================                                                                                                                                    |  26%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=================================================                                                                                                                                 |  27%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===================================================                                                                                                                               |  29%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |======================================================                                                                                                                            |  30%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=========================================================                                                                                                                         |  32%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===========================================================                                                                                                                       |  33%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==============================================================                                                                                                                    |  35%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=================================================================                                                                                                                 |  36%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===================================================================                                                                                                               |  38%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |======================================================================                                                                                                            |  39%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=========================================================================                                                                                                         |  41%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |============================================================================                                                                                                      |  42%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==============================================================================                                                                                                    |  44%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=================================================================================                                                                                                 |  45%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |====================================================================================                                                                                              |  47%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |======================================================================================                                                                                            |  48%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=========================================================================================                                                                                         |  50%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |============================================================================================                                                                                      |  52%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==============================================================================================                                                                                    |  53%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=================================================================================================                                                                                 |  55%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |====================================================================================================                                                                              |  56%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |======================================================================================================                                                                            |  58%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=========================================================================================================                                                                         |  59%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |============================================================================================================                                                                      |  61%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===============================================================================================================                                                                   |  62%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=================================================================================================================                                                                 |  64%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |====================================================================================================================                                                              |  65%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=======================================================================================================================                                                           |  67%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=========================================================================================================================                                                         |  68%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |============================================================================================================================                                                      |  70%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===============================================================================================================================                                                   |  71%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=================================================================================================================================                                                 |  73%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |====================================================================================================================================                                              |  74%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=======================================================================================================================================                                           |  76%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==========================================================================================================================================                                        |  77%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |============================================================================================================================================                                      |  79%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===============================================================================================================================================                                   |  80%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==================================================================================================================================================                                |  82%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |====================================================================================================================================================                              |  83%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=======================================================================================================================================================                           |  85%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==========================================================================================================================================================                        |  86%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |============================================================================================================================================================                      |  88%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===============================================================================================================================================================                   |  89%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==================================================================================================================================================================                |  91%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=====================================================================================================================================================================             |  92%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=======================================================================================================================================================================           |  94%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==========================================================================================================================================================================        |  95%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |=============================================================================================================================================================================     |  97%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |===============================================================================================================================================================================   |  98%[inverse distance weighted interpolation]

  |                                                                                                                                                                                        
  |==================================================================================================================================================================================| 100%[inverse distance weighted interpolation]
  cv3 = st_as_sf(cv3)
  
  sp::bubble(as(cv3[, "residual"], "Spatial"))

NA

2.9 Calculo RMSE

sqrt(sum((cv2$var1.pred - cv2$observed)^2) / nrow(cv2))
[1] 0.7066087
sqrt(sum((cv3$var1.pred - cv3$observed)^2) / nrow(cv3))
[1] 0.7196336

FIN

LS0tCnRpdGxlOiAiVGFsbGVyIGludGVycG9sYWNpb24gQ2FybG9zIEdlcm1hbiBTYW5jaGV6IFJpdmVyYSIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQoKIyAqKkludGVycG9sYWNpb24gSURXKioKCiMjIDEuMSBJbnN0YWxhY2lvbiBsaWJyZXJpYXMgeSBwYXF1ZXRlcyAKCmBgYHtyfQpsaWJyYXJ5KHNmKQpsaWJyYXJ5KHN0YXJzKQpsaWJyYXJ5KGxlYWZsZXQpCmxpYnJhcnkoZ3N0YXQpCmxpYnJhcnkoYXV0b21hcCkKbGlicmFyeShyYXN0ZXIpCmxpYnJhcnkoUkNvbG9yQnJld2VyKQpgYGAKCiMjIDEuMiBWZXJpZmljYWNpb24geSBsdWdhciBkZSBndWFyZGFkbyAKCmBgYHtyfQpnZXR3ZCgpCiAgICBzZXR3ZCgiL1VzZXJzL2NhcmxpdG9zL0RvY3VtZW50cy9Vbml2ZXJzaXR5L0dlb21hdGljYS9kcml2ZS1kb3dubG9hZC0yMDI1MDIyM1QwMDQ3MzJaLTAwMSIpCmBgYAoKIyMgMS4zIERlY2xhcmFyIGxhcyB2YXJpYWJsZXMKCmBgYHtyIG1lc3NhZ2U9VFJVRX0KcnV0YV9hb2k9Ii4vbXVuaWNpcGlvc19tdWVzdHJlby5zaHAiCnJ1dGFfcHVudG9zPSIuL3B1bnRvc19tdWVzdHJlby5za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