Compare food insecurity data with previous data
Compare food insecurity items with data used for the paper. The previous dataset contains only the urban area of Ipixuna, while our corrent dataset includes four cities. We subset the curent dataset to compare the data of Ipixuna’s urban area with the previous dataset.
Load required libraries and data
rm(list = ls())
library(day2day)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
path_main <- git_path()
path_data <- file.path(path_main, "data")
path_raw <- file.path(path_data, "raw")
path_processed <- file.path(path_data, "processed")
path_fi <- file.path(path_raw, "Food-Security-Amazonia")
path_old <- file.path(path_raw, "ipixuna")
# load previous data
(load(file.path(path_old, "01_items_with_na.RData")))
#> [1] "fidata" "fidata_ques" "fidata_only" "fi_varname"
# load current data
fi_items <- st_read(file.path(path_processed, "fi-items.gpkg"), as_tibble = TRUE)
#> Reading layer `fi-items' from data source
#> `/home/rstudio/documents/projects/food-insecurity-mapping/data/processed/fi-items.gpkg'
#> using driver `GPKG'
#> Simple feature collection with 1109 features and 36 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -72.05338 ymin: -7.56604 xmax: -57.40498 ymax: -2.44214
#> Geodetic CRS: WGS 84
Compare current and previous data
Compare items answers
items_current <- fi_items |>
st_set_geometry(NULL) |>
filter(municipality == "Ipixuna", !is_rural) |>
arrange(registro) |>
dplyr::select(matches("^item_[0-9]+_"))
items_old <- as_tibble(fidata_ques) |>
arrange(registro) |>
dplyr::select(matches("^[0-9]+: "))
all.equal(dim(items_current), dim(items_old))
#> [1] TRUE
sum(items_current != items_old, na.rm = TRUE)
#> [1] 0
Compare coordinates
coords_current <- fi_items |>
filter(municipality == "Ipixuna", !is_rural) |>
arrange(registro) |>
st_coordinates()
coords_old <- fidata_ques |>
arrange(registro) |>
dplyr::select(c("gps_longitude", "gps_latitude"))
all.equal(dim(coords_current), dim(coords_old))
#> [1] TRUE
sum(coords_current != coords_old)
#> [1] 0
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 1.350 0.378 1.409