Skip to content

Commit

Permalink
Separate quick residency analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardlavender committed Oct 23, 2024
1 parent 7658370 commit 7bce331
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions analyses/patter_04_qresidency.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
###########################
###########################
#### patter-qresidency.R

#### Aims
# 1) Quick residency analysis

#### Prerequisites
# 1) patter-algorithms.R


###########################
###########################
#### Set up

#### Wipe workspace
rm(list = ls())
# try(pacman::p_unload("all"), silent = TRUE)
dv::clear()

#### Essential packages
library(data.table)
library(dtplyr)
library(dplyr, warn.conflicts = FALSE)
library(tictoc)
dv::src()

#### Load data
paths <- qs::qread(here_input("paths.qs"))


###########################
###########################
#### Quick residency analysis

#### TO DO
# * Iterate over indidividuals
# * Compute true & estimated residency

#### True residency in each region
path_res <-
path |>
group_by(region) |>
summarise(n = n()) |>
mutate(residency = (n / sum(n)) * 100,
estimate = "path",
sim_id = id) |>
as.data.table()

#### Particle residency estimates
part_res <-
out_smo |>
mutate(region = terra::extract(map, cbind(x, y))) |>
group_by(region) |>
mutate(residency = (n / sum(n)) * 100,
estimate = "smoother",
sim_id = id) |>
as.data.table()

#### Collect data
res <- rbind(path_res, part_res)
qs::qsave(res, "data/patter/output/residency/qresidency/", paste0(id, ".qs"))


###########################
###########################
#### Synthesis

# Read residency data for each individual
residency <-
lapply(unique(paths$sim_id), function(id) {
qs::qread("data/patter/qresidency.qs")
}) |> rbindlist()

# Visualise residency ~ individual, coloured by truth/algorithm
#
# > TO DO


#### End of code.
###########################
###########################

0 comments on commit 7bce331

Please sign in to comment.