R Under development (unstable) (2024-08-27 r87062 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > s1 = Sys.time() > library(MRG) > library(sf) Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE > library(giscoR) > #' > # These are SYNTHETIC agricultural FSS data > data(ifs_dk) # Census data > ifs_weight = ifs_dk %>% dplyr::filter(Sample == 1) # Extract weighted subsample > > # Create spatial data > ifg = fssgeo(ifs_dk, locAdj = "LL") > fsg = fssgeo(ifs_weight, locAdj = "LL") > # Read country borders, only used for plotting > borders = gisco_get_nuts(nuts_level = 0) > > borders = gisco_get_nuts(nuts_level = 2) > > dkb = borders[borders$CNTR_CODE == "DK",] %>% st_transform(crs = 3035) > ifg$dkb = st_join(ifg, dkb)$NUTS_ID > ifg = ifg[!is.na(ifg$dkb) & ifg$dkb == "DK05",] > fsg$dkb = st_join(fsg, dkb)$NUTS_ID > fsg = fsg[!is.na(fsg$dkb) & fsg$dkb == "DK05",] > > #' > # Set the base resolutions, and create a hierarchical list with gridded data > ress = c(1,5,10,20,40)*1000 > # Gridding Utilized agricultural area (UAA) > ifl = gridData(ifg, "UAA", res = ress) > > # Gridding UAA and organic UAA together > ifl3 = gridData(ifg, vars = c("UAA", "UAAXK0000_ORG"), res = ress) > > # Gridding the UAA from the survey - the survey weights are in the column EXT_MODULE > fsl = gridData(fsg, vars = c("UAA"), weights = "EXT_MODULE", res = ress) > > # Create a multi-resolution grid only with farm number as confidentiality rule, then plot results > himg0 = multiResGrid(ifl, checkReliability = FALSE, suppresslim = 0) [1] "ires 2 5000 #himg-cells: 372 ; removed: 4205 ; added: 358 ; confidential: 14" [1] "ires 3 10000 #himg-cells: 297 ; removed: 111 ; added: 36 ; confidential: 11" [1] "ires 4 20000 #himg-cells: 286 ; removed: 18 ; added: 7 ; confidential: 3" [1] "ires 5 40000 #himg-cells: 271 ; removed: 17 ; added: 2 ; confidential: 2" > > # Create a multi-resolution grid of UAA, also based on the dominance rule (default) > himg1 = multiResGrid(ifl, vars = "UAA", ifg = ifg) [1] "ires 2 5000 #himg-cells: 372 ; removed: 4205 ; added: 358 ; confidential: 14" [1] "ires 3 10000 #himg-cells: 290 ; removed: 121 ; added: 39 ; confidential: 11" [1] "ires 4 20000 #himg-cells: 279 ; removed: 18 ; added: 7 ; confidential: 3" [1] "ires 5 40000 #himg-cells: 264 ; removed: 17 ; added: 2 ; confidential: 2" > > > # Create joint multi-resolution grid of organic UAA and total UAA > himg3 = multiResGrid(ifl3, vars = c("UAA", "UAAXK0000_ORG"), ifg = ifg, + checkReliability = FALSE, suppresslim = 0) [1] "ires 2 5000 #himg-cells: 372 ; removed: 4205 ; added: 358 ; confidential: 14" [1] "ires 3 10000 #himg-cells: 111 ; removed: 361 ; added: 100 ; confidential: 11" [1] "ires 4 20000 #himg-cells: 39 ; removed: 104 ; added: 32 ; confidential: 7" [1] "ires 5 40000 #himg-cells: 21 ; removed: 26 ; added: 8 ; confidential: 2" > > > # Create joint multi-resolution grid of organic UAA and total UAA > himg4 = multiResGrid(ifl3, vars = c("UAA", "UAAXK0000_ORG"), ifg = ifg, + checkReliability = FALSE, suppresslim = 0.1) [1] "ires 2 5000 #himg-cells: 372 ; removed: 4205 ; added: 358 ; confidential: 14" [1] "ires 3 10000 #himg-cells: 111 ; removed: 361 ; added: 100 ; confidential: 11" [1] "ires 4 20000 #himg-cells: 39 ; removed: 104 ; added: 32 ; confidential: 7" [1] "ires 5 40000 #himg-cells: 21 ; removed: 26 ; added: 8 ; confidential: 2" > > # Create multi-resolution grid of UAA and organic UAA, based on survey data, > # also applying reliability check > system.time(himg5 <- multiResGrid(fsl, vars = c("UAA"), weights = "EXT_MODULE", ifg = fsg, + strat = "STRA_ID_CORE", checkReliability = TRUE, reliabilitySplit = 15)) Joining with `by = join_by(himgid)` [1] "df 121 107" [1] "df 122 107" [1] "df 121 107" [1] "df 124 107" [1] "df 113 107" [1] "df 121 107" [1] "df 117 107" [1] "df 122 107" [1] "df 123 107" [1] "df 124 107" [1] "df 124 107" [1] "df 125 107" [1] "df 113 107" [1] "df 121 107" [1] "df 120 107" [1] "ires 2 5000 #himg-cells: 357 ; removed: 1576 ; added: 328 ; confidential: 29" Joining with `by = join_by(himgid)` [1] "df 25 24" [1] "df 106 24" [1] "df 114 24" [1] "df 115 23" [1] "df 144 24" [1] "df 97 24" [1] "df 121 24" [1] "df 125 23" [1] "df 145 24" [1] "df 127 24" [1] "df 163 24" [1] "df 133 23" [1] "df 138 24" [1] "df 125 24" [1] "df 133 24" [1] "ires 3 10000 #himg-cells: 107 ; removed: 346 ; added: 96 ; confidential: 11" Joining with `by = join_by(himgid)` [1] "df 18 8" [1] "df 76 7" [1] "df 124 7" [1] "df 123 7" [1] "df 145 7" [1] "df 67 7" [1] "df 111 7" [1] "df 162 7" [1] "df 107 7" [1] "df 134 7" [1] "df 167 7" [1] "df 152 7" [1] "df 155 7" [1] "df 119 7" [1] "df 151 8" [1] "ires 4 20000 #himg-cells: 68 ; removed: 56 ; added: 17 ; confidential: 8" Joining with `by = join_by(himgid)` [1] "df 28 5" [1] "df 82 4" [1] "df 88 5" [1] "df 62 4" [1] "df 99 5" [1] "df 68 4" [1] "df 128 5" [1] "df 125 4" [1] "df 103 5" [1] "df 96 4" [1] "df 69 5" [1] "df 203 4" [1] "df 122 5" [1] "df 261 4" [1] "df 277 5" [1] "ires 5 40000 #himg-cells: 48 ; removed: 26 ; added: 6 ; confidential: 2" Joining with `by = join_by(himgid)` [1] "df 53 4" [1] "df 69 3" [1] "df 48 3" [1] "df 52 3" [1] "df 91 3" [1] "df 83 3" [1] "df 89 3" [1] "df 82 4" [1] "df 70 3" [1] "df 46 3" [1] "df 147 3" [1] "df 184 3" [1] "df 180 3" [1] "df 128 3" [1] "df 489 4" user system elapsed 15.82 0.44 16.32 There were 50 or more warnings (use warnings() to see the first 50) > > summary(himg0) count countw weight1 res Min. : 10.00 Min. : 10.00 Min. : 5.00 Min. : 5000 1st Qu.: 16.00 1st Qu.: 16.00 1st Qu.: 16.00 1st Qu.: 5000 Median : 21.00 Median : 21.00 Median : 20.00 Median : 5000 Mean : 24.21 Mean : 24.21 Mean : 23.24 Mean : 6070 3rd Qu.: 25.00 3rd Qu.: 25.00 3rd Qu.: 24.00 3rd Qu.: 5000 Max. :332.00 Max. :332.00 Max. :326.00 Max. :40000 NA's :2 NA's :2 ID geometry Min. : 1.0 POLYGON :271 1st Qu.: 68.5 epsg:3035 : 0 Median :136.0 +proj=laea...: 0 Mean :136.0 3rd Qu.:203.5 Max. :271.0 > summary(himg1) count countw UAA weight1 Min. : 10.00 Min. : 10.00 Min. : 50.0 Min. : 10.00 1st Qu.: 17.00 1st Qu.: 17.00 1st Qu.: 762.5 1st Qu.: 20.00 Median : 21.00 Median : 21.00 Median : 1380.0 Median : 20.00 Mean : 24.86 Mean : 24.86 Mean : 1684.8 Mean : 24.24 3rd Qu.: 25.00 3rd Qu.: 25.00 3rd Qu.: 2095.0 3rd Qu.: 20.00 Max. :332.00 Max. :332.00 Max. :27900.0 Max. :330.00 NA's :2 NA's :2 NA's :2 NA's :2 res ID geometry Min. : 5000 Min. : 1.00 POLYGON :264 1st Qu.: 5000 1st Qu.: 66.75 epsg:3035 : 0 Median : 5000 Median :132.50 +proj=laea...: 0 Mean : 6155 Mean :132.50 3rd Qu.: 5000 3rd Qu.:198.25 Max. :40000 Max. :264.00 > summary(himg3) count countw UAA UAAXK0000_ORG weight1 Min. :137.0 Min. :137.0 Min. : 6100 Min. : 630 Min. :130.0 1st Qu.:277.0 1st Qu.:277.0 1st Qu.:16460 1st Qu.:1580 1st Qu.:280.0 Median :345.0 Median :345.0 Median :27100 Median :2340 Median :340.0 Mean :378.1 Mean :378.1 Mean :25680 Mean :2831 Mean :365.9 3rd Qu.:387.0 3rd Qu.:387.0 3rd Qu.:29060 3rd Qu.:3730 3rd Qu.:370.0 Max. :819.0 Max. :819.0 Max. :47720 Max. :6000 Max. :780.0 NA's :4 NA's :4 NA's :4 NA's :4 NA's :4 weight2 res ID geometry Min. :20.00 Min. : 5000 Min. : 1 POLYGON :21 1st Qu.:30.00 1st Qu.:20000 1st Qu.: 6 epsg:3035 : 0 Median :30.00 Median :20000 Median :11 +proj=laea...: 0 Mean :36.47 Mean :26905 Mean :11 3rd Qu.:40.00 3rd Qu.:40000 3rd Qu.:16 Max. :70.00 Max. :40000 Max. :21 NA's :4 > summary(himg4) count countw UAA UAAXK0000_ORG weight1 Min. :137.0 Min. :137.0 Min. : 6100 Min. : 630 Min. :130.0 1st Qu.:277.0 1st Qu.:277.0 1st Qu.:16460 1st Qu.:1580 1st Qu.:280.0 Median :345.0 Median :345.0 Median :27100 Median :2340 Median :340.0 Mean :378.1 Mean :378.1 Mean :25680 Mean :2831 Mean :365.9 3rd Qu.:387.0 3rd Qu.:387.0 3rd Qu.:29060 3rd Qu.:3730 3rd Qu.:370.0 Max. :819.0 Max. :819.0 Max. :47720 Max. :6000 Max. :780.0 NA's :4 NA's :4 NA's :4 NA's :4 NA's :4 weight2 res ID geometry Min. :20.00 Min. : 5000 Min. : 1 POLYGON :21 1st Qu.:30.00 1st Qu.:20000 1st Qu.: 6 epsg:3035 : 0 Median :30.00 Median :20000 Median :11 +proj=laea...: 0 Mean :36.47 Mean :26905 Mean :11 3rd Qu.:40.00 3rd Qu.:40000 3rd Qu.:16 Max. :70.00 Max. :40000 Max. :21 NA's :4 > summary(himg5) count countw UAA weight1 Min. : 10.00 Min. : 27.62 Min. : 2220 Min. : 30.0 1st Qu.: 17.00 1st Qu.: 63.99 1st Qu.: 3880 1st Qu.: 60.0 Median : 27.00 Median : 93.61 Median : 6260 Median : 90.0 Mean : 40.04 Mean :146.09 Mean : 9306 Mean :141.6 3rd Qu.: 40.00 3rd Qu.:154.53 3rd Qu.: 8960 3rd Qu.:150.0 Max. :187.00 Max. :692.11 Max. :44920 Max. :650.0 NA's :3 NA's :3 NA's :3 NA's :3 res ID geometry Min. : 1000 Min. : 1.00 POLYGON :48 1st Qu.:10000 1st Qu.:12.75 epsg:3035 : 0 Median :10000 Median :24.50 +proj=laea...: 0 Mean :15333 Mean :24.50 3rd Qu.:20000 3rd Qu.:36.25 Max. :40000 Max. :48.00 > > MRGobject = createMRGobject(ifg = ifg, ress = ress, var = "UAA") > himg1 = multiResGrid(MRGobject) [1] "ires 2 5000 #himg-cells: 372 ; removed: 4205 ; added: 358 ; confidential: 14" [1] "ires 3 10000 #himg-cells: 290 ; removed: 121 ; added: 39 ; confidential: 11" [1] "ires 4 20000 #himg-cells: 279 ; removed: 18 ; added: 7 ; confidential: 3" [1] "ires 5 40000 #himg-cells: 264 ; removed: 17 ; added: 2 ; confidential: 2" > # Parameters can be updated in the object or in the call to multiResGrid > MRGobject$suppresslim = 0.02 > himg2 = multiResGrid(MRGobject) [1] "ires 2 5000 #himg-cells: 372 ; removed: 4205 ; added: 358 ; confidential: 14" [1] "ires 3 10000 #himg-cells: 306 ; removed: 99 ; added: 33 ; confidential: 17" [1] "ires 4 20000 #himg-cells: 299 ; removed: 12 ; added: 5 ; confidential: 10" [1] "ires 5 40000 #himg-cells: 283 ; removed: 18 ; added: 2 ; confidential: 8" > himg3 = multiResGrid(MRGobject, suppresslim = 0.05) [1] "ires 2 5000 #himg-cells: 372 ; removed: 4205 ; added: 358 ; confidential: 14" [1] "ires 3 10000 #himg-cells: 308 ; removed: 96 ; added: 32 ; confidential: 18" [1] "ires 4 20000 #himg-cells: 301 ; removed: 12 ; added: 5 ; confidential: 11" [1] "ires 5 40000 #himg-cells: 300 ; removed: 2 ; added: 1 ; confidential: 11" > summary(himg1) count countw UAA weight1 Min. : 10.00 Min. : 10.00 Min. : 50.0 Min. : 10.00 1st Qu.: 17.00 1st Qu.: 17.00 1st Qu.: 762.5 1st Qu.: 20.00 Median : 21.00 Median : 21.00 Median : 1380.0 Median : 20.00 Mean : 24.86 Mean : 24.86 Mean : 1684.8 Mean : 24.24 3rd Qu.: 25.00 3rd Qu.: 25.00 3rd Qu.: 2095.0 3rd Qu.: 20.00 Max. :332.00 Max. :332.00 Max. :27900.0 Max. :330.00 NA's :2 NA's :2 NA's :2 NA's :2 res ID geometry Min. : 5000 Min. : 1.00 POLYGON :264 1st Qu.: 5000 1st Qu.: 66.75 epsg:3035 : 0 Median : 5000 Median :132.50 +proj=laea...: 0 Mean : 6155 Mean :132.50 3rd Qu.: 5000 3rd Qu.:198.25 Max. :40000 Max. :264.00 > summary(himg2) count countw UAA weight1 Min. : 10.00 Min. : 10.00 Min. : 50 Min. : 10.00 1st Qu.: 16.00 1st Qu.: 16.00 1st Qu.: 730 1st Qu.: 20.00 Median : 21.00 Median : 21.00 Median : 1280 Median : 20.00 Mean : 23.64 Mean : 23.64 Mean : 1605 Mean : 23.05 3rd Qu.: 25.00 3rd Qu.: 25.00 3rd Qu.: 2025 3rd Qu.: 20.00 Max. :332.00 Max. :332.00 Max. :27900 Max. :330.00 NA's :8 NA's :8 NA's :8 NA's :8 res ID geometry Min. : 1000 Min. : 1.0 POLYGON :283 1st Qu.: 5000 1st Qu.: 71.5 epsg:3035 : 0 Median : 5000 Median :142.0 +proj=laea...: 0 Mean : 5898 Mean :142.0 3rd Qu.: 5000 3rd Qu.:212.5 Max. :40000 Max. :283.0 > summary(himg3) count countw UAA weight1 res Min. :10.00 Min. :10.00 Min. : 50 Min. :10.0 Min. : 1000 1st Qu.:16.00 1st Qu.:16.00 1st Qu.: 740 1st Qu.:20.0 1st Qu.: 5000 Median :20.00 Median :20.00 Median :1280 Median :20.0 Median : 5000 Mean :22.46 Mean :22.46 Mean :1525 Mean :21.9 Mean : 5720 3rd Qu.:25.00 3rd Qu.:25.00 3rd Qu.:2050 3rd Qu.:20.0 3rd Qu.: 5000 Max. :77.00 Max. :77.00 Max. :9450 Max. :80.0 Max. :40000 NA's :11 NA's :11 NA's :11 NA's :11 ID geometry Min. : 1.00 POLYGON :300 1st Qu.: 75.75 epsg:3035 : 0 Median :150.50 +proj=laea...: 0 Mean :150.50 3rd Qu.:225.25 Max. :300.00 > > s2 = Sys.time() > > proc.time() user system elapsed 51.95 1.42 53.42