EIFA Urban Ipixuna: fitting
Run exploratory item factor analysis (EIFA) for different number of dimensions for the urban households of Ipixuna.
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(mirt)
#> Loading required package: stats4
#> Loading required package: lattice
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_modelled <- file.path(path_data, "modelled")
fidata <- file.path(path_processed, "fi-items-ipixuna-urban.gpkg") |>
st_read(as_tibble = TRUE)
#> Reading layer `fi-items-ipixuna-urban' from data source
#> `/home/rstudio/documents/projects/food-insecurity-mapping/data/processed/fi-items-ipixuna-urban.gpkg'
#> using driver `GPKG'
#> Simple feature collection with 200 features and 36 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -71.70038 ymin: -7.06058 xmax: -71.68109 ymax: -7.03724
#> Geodetic CRS: WGS 84
Exploratory items factor analysis
First, we filter only the items
items_data <- fidata |>
st_set_geometry(NULL) |>
dplyr::select(matches("^item_[0-9]+_[A-D]"))
Run the exploratory item factor analysis with 1 to 6 dimensions.
eifa_dim <- function(x) {
mirt(items_data, x, method = "MHRM", technical = list(NCYCLES = 20000),
verbose = FALSE)
}
mirt_eifa <- tibble(ndim = 1:6) |>
mutate(model = purrr::map(ndim, eifa_dim))
Save output
Save output as a tibble containing number of dimensions and associated eifa models.
saveRDS(mirt_eifa, file = file.path(path_modelled, "eifa-ipixuna-urban.rds"))
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 462.376 756.077 311.912