R Under development (unstable) (2024-08-21 r87038 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. > 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) > dkb = borders[borders$CNTR_CODE == "DK",] %>% st_transform(crs = 3035) > #' > # Set the base resolutions, and create a hierarchical list with gridded data > ress = c(1,5,10,20,40, 80, 160)*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: 2179 ; removed: 23704 ; added: 2107 ; confidential: 72" [1] "ires 3 10000 #himg-cells: 1642 ; removed: 768 ; added: 231 ; confidential: 41" [1] "ires 4 20000 #himg-cells: 1539 ; removed: 137 ; added: 34 ; confidential: 9" [1] "ires 5 40000 #himg-cells: 1451 ; removed: 96 ; added: 8 ; confidential: 1" [1] "ires 6 80000 #himg-cells: 1366 ; removed: 86 ; added: 1 ; confidential: 0" [1] "ires 7 160000 #himg-cells: 1366 ; removed: 0 ; added: 0 ; confidential: 0" > > # 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: 2179 ; removed: 23704 ; added: 2107 ; confidential: 72" [1] "ires 3 10000 #himg-cells: 1601 ; removed: 824 ; added: 246 ; confidential: 42" [1] "ires 4 20000 #himg-cells: 1493 ; removed: 145 ; added: 37 ; confidential: 9" [1] "ires 5 40000 #himg-cells: 1405 ; removed: 96 ; added: 8 ; confidential: 1" [1] "ires 6 80000 #himg-cells: 1333 ; removed: 73 ; added: 1 ; confidential: 0" [1] "ires 7 160000 #himg-cells: 1333 ; removed: 0 ; added: 0 ; confidential: 0" > > > # 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: 2179 ; removed: 23704 ; added: 2107 ; confidential: 72" [1] "ires 3 10000 #himg-cells: 636 ; removed: 2126 ; added: 583 ; confidential: 48" [1] "ires 4 20000 #himg-cells: 192 ; removed: 613 ; added: 169 ; confidential: 17" [1] "ires 5 40000 #himg-cells: 121 ; removed: 103 ; added: 32 ; confidential: 5" [1] "ires 6 80000 #himg-cells: 103 ; removed: 25 ; added: 7 ; confidential: 3" [1] "ires 7 160000 #himg-cells: 94 ; removed: 11 ; added: 2 ; 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: 2179 ; removed: 23704 ; added: 2107 ; confidential: 72" [1] "ires 3 10000 #himg-cells: 636 ; removed: 2126 ; added: 583 ; confidential: 48" [1] "ires 4 20000 #himg-cells: 196 ; removed: 607 ; added: 167 ; confidential: 19" [1] "ires 5 40000 #himg-cells: 132 ; removed: 92 ; added: 28 ; confidential: 11" [1] "ires 6 80000 #himg-cells: 119 ; removed: 19 ; added: 6 ; confidential: 8" [1] "ires 7 160000 #himg-cells: 108 ; removed: 13 ; added: 2 ; confidential: 6" > > # Create multi-resolution grid of UAA and organic UAA, based on survey data, > # also applying reliability check > # Slow! > 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 634 566" [1] "df 640 565" [1] "df 635 565" [1] "df 633 566" [1] "df 626 565" [1] "df 717 565" [1] "df 743 566" [1] "df 719 565" [1] "df 704 565" [1] "df 665 566" [1] "df 636 565" [1] "df 664 565" [1] "df 684 566" [1] "df 645 565" [1] "df 655 566" [1] "ires 2 5000 #himg-cells: 2033 ; removed: 8187 ; added: 1739 ; confidential: 287" Joining with `by = join_by(himgid)` [1] "df 152 136" [1] "df 157 135" [1] "df 603 136" [1] "df 781 135" [1] "df 706 136" [1] "df 573 135" [1] "df 571 136" [1] "df 945 135" [1] "df 1088 136" [1] "df 907 135" [1] "df 685 136" [1] "df 712 135" [1] "df 764 136" [1] "df 703 135" [1] "df 653 136" [1] "ires 3 10000 #himg-cells: 634 ; removed: 1951 ; added: 552 ; confidential: 50" Joining with `by = join_by(himgid)` [1] "df 204 43" [1] "df 482 42" [1] "df 734 42" [1] "df 861 42" [1] "df 685 42" [1] "df 580 43" [1] "df 606 42" [1] "df 844 42" [1] "df 913 42" [1] "df 821 42" [1] "df 711 43" [1] "df 672 42" [1] "df 716 42" [1] "df 586 42" [1] "df 585 43" [1] "ires 4 20000 #himg-cells: 314 ; removed: 445 ; added: 125 ; confidential: 13" Joining with `by = join_by(himgid)` [1] "df 260 21" [1] "df 372 21" [1] "df 449 21" [1] "df 457 21" [1] "df 609 21" [1] "df 463 21" [1] "df 480 21" [1] "df 427 20" [1] "df 440 21" [1] "df 949 21" [1] "df 1069 21" [1] "df 1101 21" [1] "df 1076 21" [1] "df 956 21" [1] "df 892 21" [1] "ires 5 40000 #himg-cells: 259 ; removed: 76 ; added: 21 ; confidential: 1" Joining with `by = join_by(himgid)` [1] "df 289 18" [1] "df 316 17" [1] "df 401 17" [1] "df 380 17" [1] "df 526 17" [1] "df 440 18" [1] "df 396 17" [1] "df 365 17" [1] "df 387 17" [1] "df 816 17" [1] "df 967 18" [1] "df 1309 17" [1] "df 948 17" [1] "df 879 17" [1] "df 1581 18" [1] "ires 6 80000 #himg-cells: 257 ; removed: 3 ; added: 1 ; confidential: 1" Joining with `by = join_by(himgid)` [1] "df 289 18" [1] "df 316 17" [1] "df 401 17" [1] "df 380 17" [1] "df 526 17" [1] "df 421 17" [1] "df 396 17" [1] "df 370 17" [1] "df 366 17" [1] "df 920 17" [1] "df 918 17" [1] "df 1288 17" [1] "df 893 17" [1] "df 1061 17" [1] "df 1455 18" [1] "ires 7 160000 #himg-cells: 242 ; removed: 16 ; added: 1 ; confidential: 0" Joining with `by = join_by(himgid)` [1] "df 276 17" [1] "df 280 16" [1] "df 382 16" [1] "df 357 16" [1] "df 411 16" [1] "df 483 16" [1] "df 365 16" [1] "df 353 16" [1] "df 403 16" [1] "df 547 16" [1] "df 942 16" [1] "df 1224 16" [1] "df 896 16" [1] "df 745 16" [1] "df 2336 17" user system elapsed 91.68 3.22 95.47 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. : 8.00 Min. : 5000 1st Qu.: 16.25 1st Qu.: 16.25 1st Qu.: 16.00 1st Qu.: 5000 Median : 21.00 Median : 21.00 Median : 20.00 Median : 5000 Mean : 27.15 Mean : 27.15 Mean : 26.42 Mean : 6083 3rd Qu.: 25.00 3rd Qu.: 25.00 3rd Qu.: 25.00 3rd Qu.: 5000 Max. :2078.00 Max. :2078.00 Max. :2008.00 Max. :80000 ID geometry Min. : 1.0 POLYGON :1366 1st Qu.: 342.2 epsg:3035 : 0 Median : 683.5 +proj=laea...: 0 Mean : 683.5 3rd Qu.:1024.8 Max. :1366.0 > summary(himg1) count countw UAA weight1 Min. : 10.00 Min. : 10.00 Min. : 90 Min. : 10.00 1st Qu.: 17.00 1st Qu.: 17.00 1st Qu.: 800 1st Qu.: 20.00 Median : 21.00 Median : 21.00 Median : 1390 Median : 20.00 Mean : 27.82 Mean : 27.82 Mean : 1961 Mean : 27.25 3rd Qu.: 26.00 3rd Qu.: 26.00 3rd Qu.: 2200 3rd Qu.: 20.00 Max. :2078.00 Max. :2078.00 Max. :163660 Max. :2010.00 res ID geometry Min. : 5000 Min. : 1 POLYGON :1333 1st Qu.: 5000 1st Qu.: 334 epsg:3035 : 0 Median : 5000 Median : 667 +proj=laea...: 0 Mean : 6159 Mean : 667 3rd Qu.: 5000 3rd Qu.:1000 Max. :80000 Max. :1333 > summary(himg3) count countw UAA UAAXK0000_ORG Min. : 77.0 Min. : 77.0 Min. : 3480 Min. : 370 1st Qu.: 244.8 1st Qu.: 244.8 1st Qu.: 16670 1st Qu.: 1462 Median : 314.0 Median : 314.0 Median : 23240 Median : 2555 Mean : 401.5 Mean : 401.5 Mean : 28309 Mean : 3152 3rd Qu.: 376.5 3rd Qu.: 376.5 3rd Qu.: 29070 3rd Qu.: 3650 Max. :3981.0 Max. :3981.0 Max. :230640 Max. :27170 NA's :2 NA's :2 NA's :2 NA's :2 weight1 weight2 res ID Min. : 80.0 Min. : 10.00 Min. : 10000 Min. : 1.00 1st Qu.: 230.0 1st Qu.: 20.00 1st Qu.: 20000 1st Qu.:24.25 Median : 310.0 Median : 30.00 Median : 20000 Median :47.50 Mean : 390.7 Mean : 39.24 Mean : 28511 Mean :47.50 3rd Qu.: 370.0 3rd Qu.: 40.00 3rd Qu.: 20000 3rd Qu.:70.75 Max. :3860.0 Max. :380.00 Max. :160000 Max. :94.00 NA's :2 NA's :2 geometry POLYGON :94 epsg:3035 : 0 +proj=laea...: 0 > summary(himg4) count countw UAA UAAXK0000_ORG Min. : 77.0 Min. : 77.0 Min. : 3480 Min. : 370 1st Qu.: 227.5 1st Qu.: 227.5 1st Qu.: 15108 1st Qu.: 1398 Median : 296.0 Median : 296.0 Median : 22190 Median : 2335 Mean : 361.9 Mean : 361.9 Mean : 25513 Mean : 2843 3rd Qu.: 359.8 3rd Qu.: 359.8 3rd Qu.: 28173 3rd Qu.: 3500 Max. :3981.0 Max. :3981.0 Max. :230640 Max. :27170 NA's :6 NA's :6 NA's :6 NA's :6 weight1 weight2 res ID Min. : 80.0 Min. : 10.00 Min. : 5000 Min. : 1.00 1st Qu.: 220.0 1st Qu.: 20.00 1st Qu.: 20000 1st Qu.: 27.75 Median : 285.0 Median : 30.00 Median : 20000 Median : 54.50 Mean : 352.3 Mean : 35.39 Mean : 25972 Mean : 54.50 3rd Qu.: 350.0 3rd Qu.: 40.00 3rd Qu.: 20000 3rd Qu.: 81.25 Max. :3860.0 Max. :380.00 Max. :160000 Max. :108.00 NA's :6 NA's :6 geometry POLYGON :108 epsg:3035 : 0 +proj=laea...: 0 > summary(himg5) count countw UAA weight1 Min. : 3.00 Min. : 10.79 Min. : 100 Min. : 10.0 1st Qu.: 17.00 1st Qu.: 62.31 1st Qu.: 3750 1st Qu.: 60.0 Median : 25.00 Median : 93.52 Median : 6830 Median : 90.0 Mean : 41.44 Mean : 153.56 Mean : 10776 Mean : 149.5 3rd Qu.: 52.00 3rd Qu.: 193.13 3rd Qu.: 13810 3rd Qu.: 190.0 Max. :902.00 Max. :3879.43 Max. :215440 Max. :3730.0 NA's :1 NA's :1 NA's :1 NA's :1 res ID geometry Min. : 5000 Min. : 1.00 POLYGON :242 1st Qu.: 10000 1st Qu.: 61.25 epsg:3035 : 0 Median : 10000 Median :121.50 +proj=laea...: 0 Mean : 15269 Mean :121.50 3rd Qu.: 20000 3rd Qu.:181.75 Max. :160000 Max. :242.00 > > MRGobject = createMRGobject(ifg = ifg, ress = ress, var = "UAA") > himg1 = multiResGrid(MRGobject) [1] "ires 2 5000 #himg-cells: 2179 ; removed: 23704 ; added: 2107 ; confidential: 72" [1] "ires 3 10000 #himg-cells: 1601 ; removed: 824 ; added: 246 ; confidential: 42" [1] "ires 4 20000 #himg-cells: 1493 ; removed: 145 ; added: 37 ; confidential: 9" [1] "ires 5 40000 #himg-cells: 1405 ; removed: 96 ; added: 8 ; confidential: 1" [1] "ires 6 80000 #himg-cells: 1333 ; removed: 73 ; added: 1 ; confidential: 0" [1] "ires 7 160000 #himg-cells: 1333 ; removed: 0 ; added: 0 ; confidential: 0" > # 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: 2179 ; removed: 23704 ; added: 2107 ; confidential: 72" [1] "ires 3 10000 #himg-cells: 1657 ; removed: 746 ; added: 224 ; confidential: 67" [1] "ires 4 20000 #himg-cells: 1603 ; removed: 77 ; added: 23 ; confidential: 48" [1] "ires 5 40000 #himg-cells: 1558 ; removed: 50 ; added: 5 ; confidential: 41" [1] "ires 6 80000 #himg-cells: 1558 ; removed: 0 ; added: 0 ; confidential: 41" [1] "ires 7 160000 #himg-cells: 1558 ; removed: 0 ; added: 0 ; confidential: 41" > himg3 = multiResGrid(MRGobject, suppresslim = 0.05) [1] "ires 2 5000 #himg-cells: 2179 ; removed: 23704 ; added: 2107 ; confidential: 72" [1] "ires 3 10000 #himg-cells: 1724 ; removed: 651 ; added: 196 ; confidential: 100" [1] "ires 4 20000 #himg-cells: 1690 ; removed: 51 ; added: 17 ; confidential: 87" [1] "ires 5 40000 #himg-cells: 1675 ; removed: 17 ; added: 2 ; confidential: 82" [1] "ires 6 80000 #himg-cells: 1675 ; removed: 0 ; added: 0 ; confidential: 82" [1] "ires 7 160000 #himg-cells: 1675 ; removed: 0 ; added: 0 ; confidential: 82" > summary(himg1) count countw UAA weight1 Min. : 10.00 Min. : 10.00 Min. : 90 Min. : 10.00 1st Qu.: 17.00 1st Qu.: 17.00 1st Qu.: 800 1st Qu.: 20.00 Median : 21.00 Median : 21.00 Median : 1390 Median : 20.00 Mean : 27.82 Mean : 27.82 Mean : 1961 Mean : 27.25 3rd Qu.: 26.00 3rd Qu.: 26.00 3rd Qu.: 2200 3rd Qu.: 20.00 Max. :2078.00 Max. :2078.00 Max. :163660 Max. :2010.00 res ID geometry Min. : 5000 Min. : 1 POLYGON :1333 1st Qu.: 5000 1st Qu.: 334 epsg:3035 : 0 Median : 5000 Median : 667 +proj=laea...: 0 Mean : 6159 Mean : 667 3rd Qu.: 5000 3rd Qu.:1000 Max. :80000 Max. :1333 > 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.: 780 1st Qu.: 20.00 Median : 20.00 Median : 20.00 Median : 1350 Median : 20.00 Mean : 24.36 Mean : 24.36 Mean : 1721 Mean : 23.87 3rd Qu.: 25.00 3rd Qu.: 25.00 3rd Qu.: 2140 3rd Qu.: 20.00 Max. :518.00 Max. :518.00 Max. :33040 Max. :510.00 NA's :41 NA's :41 NA's :41 NA's :41 res ID geometry Min. : 1000 Min. : 1.0 POLYGON :1558 1st Qu.: 5000 1st Qu.: 390.2 epsg:3035 : 0 Median : 5000 Median : 779.5 +proj=laea...: 0 Mean : 5806 Mean : 779.5 3rd Qu.: 5000 3rd Qu.:1168.8 Max. :40000 Max. :1558.0 > summary(himg3) 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.: 780 1st Qu.: 20.00 Median : 20.00 Median : 20.00 Median : 1330 Median : 20.00 Mean : 23.05 Mean : 23.05 Mean : 1636 Mean : 22.61 3rd Qu.: 25.00 3rd Qu.: 25.00 3rd Qu.: 2100 3rd Qu.: 20.00 Max. :284.00 Max. :284.00 Max. :18860 Max. :280.00 NA's :82 NA's :82 NA's :82 NA's :82 res ID geometry Min. : 1000 Min. : 1.0 POLYGON :1675 1st Qu.: 5000 1st Qu.: 419.5 epsg:3035 : 0 Median : 5000 Median : 838.0 +proj=laea...: 0 Mean : 5614 Mean : 838.0 3rd Qu.: 5000 3rd Qu.:1256.5 Max. :40000 Max. :1675.0 > > > > proc.time() user system elapsed 238.23 7.82 246.62