R Under development (unstable) (2024-09-09 r87107 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) > # Neccessary to silence sf startup messages > suppressMessages(library(sf)) > 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 nuts borders, used for extracting smaller data set > 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 == "DK01",] > fsg$dkb = st_join(fsg, dkb)$NUTS_ID > fsg = fsg[!is.na(fsg$dkb) & fsg$dkb == "DK01",] > > s2 = Sys.time() > #' > # 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: 118 ; removed: 1192 ; added: 108 ; confidential: 10" [1] "ires 3 10000 #himg-cells: 78 ; removed: 60 ; added: 20 ; confidential: 5" [1] "ires 4 20000 #himg-cells: 63 ; removed: 18 ; added: 3 ; confidential: 2" [1] "ires 5 40000 #himg-cells: 51 ; removed: 13 ; added: 1 ; confidential: 1" > > # 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: 118 ; removed: 1192 ; added: 108 ; confidential: 10" [1] "ires 3 10000 #himg-cells: 78 ; removed: 60 ; added: 20 ; confidential: 5" [1] "ires 4 20000 #himg-cells: 63 ; removed: 18 ; added: 3 ; confidential: 2" [1] "ires 5 40000 #himg-cells: 51 ; removed: 13 ; added: 1 ; confidential: 1" > > > # 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: 118 ; removed: 1192 ; added: 108 ; confidential: 10" [1] "ires 3 10000 #himg-cells: 40 ; removed: 111 ; added: 33 ; confidential: 6" [1] "ires 4 20000 #himg-cells: 18 ; removed: 33 ; added: 11 ; confidential: 6" [1] "ires 5 40000 #himg-cells: 9 ; removed: 14 ; added: 5 ; confidential: 3" > > > # 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: 118 ; removed: 1192 ; added: 108 ; confidential: 10" [1] "ires 3 10000 #himg-cells: 40 ; removed: 111 ; added: 33 ; confidential: 6" [1] "ires 4 20000 #himg-cells: 18 ; removed: 33 ; added: 11 ; confidential: 6" [1] "ires 5 40000 #himg-cells: 9 ; removed: 14 ; added: 5 ; confidential: 3" > > s3 = Sys.time() > > > # Create multi-resolution grid of UAA and organic UAA, based on survey data, > # also applying reliability check > himg5 <- multiResGrid(fsl, vars = c("UAA"), weights = "EXT_MODULE", ifg = fsg, + strat = "STRA_ID_CORE", checkReliability = TRUE, reliabilitySplit = 5) [1] "ires 2 5000 #himg-cells: 116 ; removed: 1058 ; added: 108 ; confidential: 8" [1] "ires 3 10000 #himg-cells: 75 ; removed: 61 ; added: 20 ; confidential: 3" [1] "ires 4 20000 #himg-cells: 68 ; removed: 10 ; added: 3 ; confidential: 2" [1] "ires 5 40000 #himg-cells: 48 ; removed: 21 ; added: 1 ; confidential: 1" > summary(himg0, digits = 5) count countw weight1 res Min. : 10.0 Min. : 10.0 Min. : 6.000 Min. : 5000 1st Qu.: 20.0 1st Qu.: 20.0 1st Qu.: 16.000 1st Qu.: 5000 Median : 20.0 Median : 20.0 Median : 23.000 Median : 5000 Mean : 37.2 Mean : 37.2 Mean : 36.373 Mean : 7549 3rd Qu.: 30.0 3rd Qu.: 30.0 3rd Qu.: 30.000 3rd Qu.:10000 Max. :490.0 Max. :490.0 Max. :491.000 Max. :40000 NA's :1 NA's :1 ID geometry Min. : 1.0 POLYGON :51 1st Qu.:13.5 epsg:3035 : 0 Median :26.0 +proj=laea...: 0 Mean :26.0 3rd Qu.:38.5 Max. :51.0 > summary(himg1, digits = 5) count countw UAA weight1 Min. : 10.0 Min. : 10.0 Min. : 110.0 Min. : 10.0 1st Qu.: 20.0 1st Qu.: 20.0 1st Qu.: 445.0 1st Qu.: 20.0 Median : 20.0 Median : 20.0 Median : 875.0 Median : 20.0 Mean : 37.2 Mean : 37.2 Mean : 1747.6 Mean : 36.6 3rd Qu.: 30.0 3rd Qu.: 30.0 3rd Qu.: 1760.0 3rd Qu.: 30.0 Max. :490.0 Max. :490.0 Max. :17960.0 Max. :490.0 NA's :1 NA's :1 NA's :1 NA's :1 res ID geometry Min. : 5000 Min. : 1.0 POLYGON :51 1st Qu.: 5000 1st Qu.:13.5 epsg:3035 : 0 Median : 5000 Median :26.0 +proj=laea...: 0 Mean : 7549 Mean :26.0 3rd Qu.:10000 3rd Qu.:38.5 Max. :40000 Max. :51.0 > # To avoid FAQ 7.31 problem in summary - mean(himg3$UAA) = 19182.5 is not consistently rounded to 19182 or 19183 > himg3$UAA = himg3$UAA + 0.001 > summary(himg3, digits = 5) count countw UAA UAAXK0000_ORG Min. : 20.0 Min. : 20.0 Min. : 940 Min. : 0.0 1st Qu.:200.0 1st Qu.:200.0 1st Qu.:13705 1st Qu.:1485.0 Median :375.0 Median :375.0 Median :22750 Median :2255.0 Mean :417.5 Mean :417.5 Mean :19183 Mean :2132.5 3rd Qu.:592.5 3rd Qu.:592.5 3rd Qu.:28228 3rd Qu.:2902.5 Max. :900.0 Max. :900.0 Max. :30290 Max. :4020.0 NA's :5 NA's :5 NA's :5 NA's :5 weight1 weight2 res ID geometry Min. : 20.0 Min. : 0.0 Min. : 5000 Min. :1 POLYGON :9 1st Qu.:200.0 1st Qu.:22.5 1st Qu.:10000 1st Qu.:3 epsg:3035 :0 Median :375.0 Median :40.0 Median :40000 Median :5 +proj=laea...:0 Mean :417.5 Mean :42.5 Mean :26667 Mean :5 3rd Qu.:592.5 3rd Qu.:60.0 3rd Qu.:40000 3rd Qu.:7 Max. :900.0 Max. :90.0 Max. :40000 Max. :9 NA's :5 NA's :5 > himg4$UAA = himg4$UAA + 0.001 > summary(himg4, digits = 5) count countw UAA UAAXK0000_ORG Min. : 20.0 Min. : 20.0 Min. : 940 Min. : 0.0 1st Qu.:200.0 1st Qu.:200.0 1st Qu.:13705 1st Qu.:1485.0 Median :375.0 Median :375.0 Median :22750 Median :2255.0 Mean :417.5 Mean :417.5 Mean :19183 Mean :2132.5 3rd Qu.:592.5 3rd Qu.:592.5 3rd Qu.:28228 3rd Qu.:2902.5 Max. :900.0 Max. :900.0 Max. :30290 Max. :4020.0 NA's :5 NA's :5 NA's :5 NA's :5 weight1 weight2 res ID geometry Min. : 20.0 Min. : 0.0 Min. : 5000 Min. :1 POLYGON :9 1st Qu.:200.0 1st Qu.:22.5 1st Qu.:10000 1st Qu.:3 epsg:3035 :0 Median :375.0 Median :40.0 Median :40000 Median :5 +proj=laea...:0 Mean :417.5 Mean :42.5 Mean :26667 Mean :5 3rd Qu.:592.5 3rd Qu.:60.0 3rd Qu.:40000 3rd Qu.:7 Max. :900.0 Max. :90.0 Max. :40000 Max. :9 NA's :5 NA's :5 > summary(himg5, digits = 5) count countw UAA weight1 Min. : 10.000 Min. : 10.000 Min. : 110.0 Min. : 10.000 1st Qu.: 15.000 1st Qu.: 20.000 1st Qu.: 400.0 1st Qu.: 20.000 Median : 20.000 Median : 20.000 Median : 830.0 Median : 20.000 Mean : 32.766 Mean : 39.787 Mean : 1857.9 Mean : 39.787 3rd Qu.: 20.000 3rd Qu.: 30.000 3rd Qu.: 1660.0 3rd Qu.: 30.000 Max. :420.000 Max. :520.000 Max. :18160.0 Max. :520.000 NA's :1 NA's :1 NA's :1 NA's :1 res ID geometry Min. : 5000.0 Min. : 1.00 POLYGON :48 1st Qu.: 5000.0 1st Qu.:12.75 epsg:3035 : 0 Median : 5000.0 Median :24.50 +proj=laea...: 0 Mean : 7604.2 Mean :24.50 3rd Qu.:10000.0 3rd Qu.:36.25 Max. :40000.0 Max. :48.00 > s4 = Sys.time() > > MRGobject = createMRGobject(ifg = ifg, ress = ress, var = "UAA") > himg1 = multiResGrid(MRGobject) [1] "ires 2 5000 #himg-cells: 118 ; removed: 1192 ; added: 108 ; confidential: 10" [1] "ires 3 10000 #himg-cells: 78 ; removed: 60 ; added: 20 ; confidential: 5" [1] "ires 4 20000 #himg-cells: 63 ; removed: 18 ; added: 3 ; confidential: 2" [1] "ires 5 40000 #himg-cells: 51 ; removed: 13 ; added: 1 ; confidential: 1" > # 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: 118 ; removed: 1192 ; added: 108 ; confidential: 10" [1] "ires 3 10000 #himg-cells: 87 ; removed: 48 ; added: 17 ; confidential: 9" [1] "ires 4 20000 #himg-cells: 77 ; removed: 12 ; added: 2 ; confidential: 7" > himg3 = multiResGrid(MRGobject, suppresslim = 0.05) [1] "ires 2 5000 #himg-cells: 118 ; removed: 1192 ; added: 108 ; confidential: 10" [1] "ires 3 10000 #himg-cells: 92 ; removed: 40 ; added: 14 ; confidential: 13" [1] "ires 4 20000 #himg-cells: 82 ; removed: 12 ; added: 2 ; confidential: 11" > summary(himg1,digits = 5) count countw UAA weight1 Min. : 10.0 Min. : 10.0 Min. : 110.0 Min. : 10.0 1st Qu.: 20.0 1st Qu.: 20.0 1st Qu.: 445.0 1st Qu.: 20.0 Median : 20.0 Median : 20.0 Median : 875.0 Median : 20.0 Mean : 37.2 Mean : 37.2 Mean : 1747.6 Mean : 36.6 3rd Qu.: 30.0 3rd Qu.: 30.0 3rd Qu.: 1760.0 3rd Qu.: 30.0 Max. :490.0 Max. :490.0 Max. :17960.0 Max. :490.0 NA's :1 NA's :1 NA's :1 NA's :1 res ID geometry Min. : 5000 Min. : 1.0 POLYGON :51 1st Qu.: 5000 1st Qu.:13.5 epsg:3035 : 0 Median : 5000 Median :26.0 +proj=laea...: 0 Mean : 7549 Mean :26.0 3rd Qu.:10000 3rd Qu.:38.5 Max. :40000 Max. :51.0 > summary(himg2, digits = 5) count countw UAA weight1 Min. : 10.000 Min. : 10.000 Min. : 110.0 Min. : 10.000 1st Qu.: 20.000 1st Qu.: 20.000 1st Qu.: 475.0 1st Qu.: 20.000 Median : 20.000 Median : 20.000 Median : 800.0 Median : 20.000 Mean : 26.714 Mean : 26.714 Mean :1245.4 Mean : 26.286 3rd Qu.: 30.000 3rd Qu.: 30.000 3rd Qu.:1452.5 3rd Qu.: 30.000 Max. :190.000 Max. :190.000 Max. :7310.0 Max. :190.000 NA's :7 NA's :7 NA's :7 NA's :7 res ID geometry Min. : 1000.0 Min. : 1 POLYGON :77 1st Qu.: 5000.0 1st Qu.:20 epsg:3035 : 0 Median : 5000.0 Median :39 +proj=laea...: 0 Mean : 6155.8 Mean :39 3rd Qu.: 5000.0 3rd Qu.:58 Max. :20000.0 Max. :77 > summary(himg3, digits = 5) count countw UAA weight1 Min. : 10.000 Min. : 10.000 Min. : 110.0 Min. : 10.000 1st Qu.: 20.000 1st Qu.: 20.000 1st Qu.: 465.0 1st Qu.: 20.000 Median : 20.000 Median : 20.000 Median : 780.0 Median : 20.000 Mean : 26.197 Mean : 26.197 Mean :1226.8 Mean : 25.775 3rd Qu.: 30.000 3rd Qu.: 30.000 3rd Qu.:1365.0 3rd Qu.: 30.000 Max. :190.000 Max. :190.000 Max. :7310.0 Max. :190.000 NA's :11 NA's :11 NA's :11 NA's :11 res ID geometry Min. : 1000.0 Min. : 1.00 POLYGON :82 1st Qu.: 5000.0 1st Qu.:21.25 epsg:3035 : 0 Median : 5000.0 Median :41.50 +proj=laea...: 0 Mean : 5804.9 Mean :41.50 3rd Qu.: 5000.0 3rd Qu.:61.75 Max. :20000.0 Max. :82.00 > > s5 = Sys.time() > ## IGNORE_RDIFF_BEGIN > s5-s4 Time difference of 4.551075 secs > s4-s3 Time difference of 8.776483 secs > s3-s2 Time difference of 9.991004 secs > s2-s1 Time difference of 6.218579 secs > > s5-s1 Time difference of 29.53714 secs > s4-s1 Time difference of 24.98607 secs > s3-s1 Time difference of 16.20958 secs > s2-s1 Time difference of 6.218579 secs > ## IGNORE_RDIFF_END > > proc.time() user system elapsed 28.90 0.70 29.67