From 40a5f737824da10c5ca6875e17bca0ec5288efef Mon Sep 17 00:00:00 2001 From: pachka <pachka@hotmail.fr> Date: Tue, 12 Dec 2023 11:40:34 +0100 Subject: [PATCH 1/3] -- --- R/run_arbocartoR.R | 3 ++- tests/testthat/test-runArboRisk.R | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/run_arbocartoR.R b/R/run_arbocartoR.R index b426adb..5dc212f 100644 --- a/R/run_arbocartoR.R +++ b/R/run_arbocartoR.R @@ -250,7 +250,8 @@ run_arbocartoR <- function(parcels, ) # N matrix for the shift process - N <- matrix(rep(0, length(u0 %>% colnames)), nrow = length(u0 %>% colnames), ncol = 2, + N <- matrix(rep(0, length(u0 %>% colnames)), + nrow = length(u0 %>% colnames), ncol = 2, dimnames = list(u0 %>% colnames, c("1", "2"))) diff --git a/tests/testthat/test-runArboRisk.R b/tests/testthat/test-runArboRisk.R index 5c6ca63..ab21888 100644 --- a/tests/testthat/test-runArboRisk.R +++ b/tests/testthat/test-runArboRisk.R @@ -19,8 +19,7 @@ test_that("simulation works with introduction", { introduction_pts <- build_E_random( period_start <- "2022/08/10" %>% as.Date, period_end <- "2022/08/30" %>% as.Date, - n_ind = NULL, - n_events = 5, + n_ind = 155, stage = "Eh", loc = parcels$ID[1]) -- GitLab From cf73eec7b40e1875e0eab77f12b55fb6899f458a Mon Sep 17 00:00:00 2001 From: pachka <pachka@hotmail.fr> Date: Tue, 12 Dec 2023 12:51:00 +0100 Subject: [PATCH 2/3] correct local mosquitoes infection --- R/build_transitions.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/R/build_transitions.R b/R/build_transitions.R index 29c449e..63241a4 100644 --- a/R/build_transitions.R +++ b/R/build_transitions.R @@ -60,9 +60,17 @@ stoch_transitions <- c( #### MOSQUITOS INFECTION #### # 6/ Infection during blood meal of nulliparous female - "@ -> (Sh+Eh+Ih+Rh) > 0 ? (A1hm - (nIm1 - ninfm1)) * gammaAh * ((Ih/(Sh+Eh+Ih+Rh) * pii) + betaHext) * bHM : (A1hm - (nIm1 - ninfm1)) * gammaAh * (betaHext) * bHM -> A1gmE + ninfm1", + # internal + # "@ -> Ih > 0 ? (A1hm - (nIm1 - ninfm1)) * gammaAh * pii * (Ih/(Sh+Eh+Ih+Rh)) * bHM : 0 -> A1gmE + ninfm1", + "@ -> Ih > 0 ?(A1hm - (nIm1 - ninfm1)) * gammaAh * pii * Ih/(Sh+Eh+Ih+Rh) * bHM : 0 -> A1gmE + ninfm1", + # external + "@ -> (A1hm - (nIm1 - ninfm1)) * gammaAh * betaHext * bHM -> A1gmE + ninfm1", + # 7/ Infection during blood meal of parous female - "@ -> (Sh+Eh+Ih+Rh) > 0 ? (A2hm - (nIm2 - ninfm2)) * gammaAh * ((Ih/(Sh+Eh+Ih+Rh) * pii) + betaHext) * bHM : (A2hm - (nIm2 - ninfm2)) * gammaAh * (betaHext) * bHM -> A2gmE + ninfm2", + # internal + "@ -> Ih > 0 ? (A2hm - (nIm2 - ninfm2)) * gammaAh * pii * Ih/(Sh+Eh+Ih+Rh) * bHM : 0 -> A2gmE + ninfm2", + # external + "@ -> (A2hm - (nIm2 - ninfm2)) * gammaAh * betaHext * bHM -> A2gmE + ninfm2", # 8 - 12/ from exposed to infectious "A1gmE -> E2I > 0 ? A1gmE * 1/E2I : 0 -> A1gmI", -- GitLab From ddce4ad21e61e5661bd127e8392a15ab401c4cf6 Mon Sep 17 00:00:00 2001 From: pachka <pachka@hotmail.fr> Date: Tue, 12 Dec 2023 13:43:02 +0100 Subject: [PATCH 3/3] doc + roxygenize --- NAMESPACE | 1 + R/build_mMov.R | 9 +-------- man/build_mMov.Rd | 30 +++++++++++++----------------- vignettes/mobility_test.Rmd | 4 ++-- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 19d99cf..0ee5436 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -37,6 +37,7 @@ importFrom(magrittr,`%<>%`) importFrom(magrittr,`%>%`) importFrom(magrittr,is_greater_than) importFrom(magrittr,is_less_than) +importFrom(magrittr,multiply_by) importFrom(magrittr,subtract) importFrom(pbapply,pbapply) importFrom(pbapply,pblapply) diff --git a/R/build_mMov.R b/R/build_mMov.R index c0b86fd..65126be 100644 --- a/R/build_mMov.R +++ b/R/build_mMov.R @@ -20,14 +20,7 @@ #' @importFrom TDLM calib_param #' @importFrom TDLM run_model #' @importFrom sf st_as_sf -#' -#' @usage build_mMov(SpatVec, -#' law = "NGravExp", -#' param = NULL, -#' p2move = 0.7, -#' outflow = NULL, -#' inflow = NULL, -#' verbose = F) +#' @importFrom magrittr multiply_by #' #' @return List of mobility metrics: #' diff --git a/man/build_mMov.Rd b/man/build_mMov.Rd index f7d65c7..d3460a9 100644 --- a/man/build_mMov.Rd +++ b/man/build_mMov.Rd @@ -4,13 +4,15 @@ \alias{build_mMov} \title{Build matrix of contact probabilities} \usage{ -build_mMov(SpatVec, - law = "NGravExp", - param = NULL, - p2move = 0.7, - outflow = NULL, - inflow = NULL, - verbose = F) +build_mMov( + SpatVec, + law = "NGravExp", + param = NULL, + p2move = NULL, + outflow = NULL, + inflow = NULL, + verbose = F +) } \arguments{ \item{SpatVec}{SpatVector or sf. Spatial vector of polygons representing patches. Polygons must include 'POP' and 'ID' attributes.} @@ -22,7 +24,7 @@ A single value or a vector of several parameter values can be used. Not necessary for the original radiation law or the uniform law. (see TDLM package for more details) Default is NULL. If NULL but required the parameter will be estimated by TDLM package.} -\item{p2move}{numeric. Daily probability to move from the residential patch or daily proportion of residents moving from the residential patch.} +\item{p2move}{numeric. Optional. Daily probability to move from the residential patch or daily proportion of residents moving from the residential patch. p2move is required if outflow is not provided. If the outflow is provided, the p2move probability is not used.} \item{outflow}{numeric. Optional. Average number of person moving out of each patch daily.} @@ -33,17 +35,11 @@ Default is NULL. If NULL but required the parameter will be estimated by TDLM pa \value{ List of mobility metrics: -`total_daily` is a simulated number of persons in each administrative unit daily (residents staying + visitors). +`mi_mixedpop` is the estimated daily number of persons in each administrative unit (staying residents + visitors). -`pii` is the average proportion of residents among the total daily population. +`proba_ij` is a normalized matrix of probabilities for movements of residents from patch i (rows) in patch j in j (columns) (proba_ij). The referent population is the resident population. -`p2move` is the average proportion of residents among the total daily population. - -`p2move` is the daily probability to move from the residential patch or daily proportion of residents moving from the residential patch. - -`proba_ij` is the normalized matrix for probabilities of contact of moving agents from patch i (rows) with agents of patch j in j (columns) (proba_ij) - -`proba_ji` is the normalized matrix for probabilities of contact of moving agents from patch j (rows) with agents of patch i in i (columns) (proba_ji) +`proba_ji` is a normalized matrix of probabilities for origin i (columns) of agents in patch j (rows) (proba_ji). The referent population is the total population during the day including staying residents and visitors. } \description{ This function estimate probability matrices of movements/trips between all the polygons of a SpatVector or sf object and return them along with other mobility metrics. diff --git a/vignettes/mobility_test.Rmd b/vignettes/mobility_test.Rmd index 039f549..fef63e3 100644 --- a/vignettes/mobility_test.Rmd +++ b/vignettes/mobility_test.Rmd @@ -45,7 +45,7 @@ SpatVec <- system.file("shape/SpatVec.shp", # Generate the mobility metrics ```{r} -mobility_metrics <- build_mMov(SpatVec) +mobility_metrics <- build_mMov(SpatVec, p2move = 0.7) # daily probability to move from i (rows) to j (columns) pij <- mobility_metrics$proba_ij * mobility_metrics$p2move @@ -56,6 +56,6 @@ pji <- mobility_metrics$proba_ji * (1 - mobility_metrics$pii) # Documentation -```{r} +```{r eval = F} ? build_mMov ``` -- GitLab