From a031082947e5c2babb0b5217f5b8100227505f4b Mon Sep 17 00:00:00 2001 From: Hillary Topazian <80535782+htopazian@users.noreply.github.com> Date: Wed, 27 Jul 2022 09:55:38 +0100 Subject: [PATCH 1/5] modifying mixing matrix warnings - replacing round() with approx_sum() - keeping row sums == 1 error - changing col sums error to a warning about asymmetrical aspects of matrix --- R/model.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/model.R b/R/model.R index 86262e49..82b3a118 100644 --- a/R/model.R +++ b/R/model.R @@ -130,7 +130,8 @@ run_simulation <- function( #' @param correlations a list of correlation parameters for each population #' (default: NULL) #' @param mixing matrix of mixing coefficients for infectivity towards -#' mosquitoes. Each element must be between 0 and 1 and all rows and columns must sum to 1. +#' mosquitoes. Rows = origin sites, columns = destinations. Each element must +#' be between 0 and 1 and all rows must sum to 1. #' @return a list of dataframe of results #' @export run_metapop_simulation <- function( @@ -146,11 +147,11 @@ run_metapop_simulation <- function( if (nrow(mixing) != length(parameters)) { stop('mixing matrix rows must match length of parameters') } - if (!all(round(rowSums(mixing), 1) == 1)) { + if (!all(lapply(1:length(parameters), function(x){approx_sum(mixing[x,], 1)}) == T)) { stop('all mixing matrix rows must sum to 1') } - if (!all(round(colSums(mixing), 1) == 1)) { - stop('all mixing matrix columns must sum to 1') + if (!all(lapply(1:length(parameters), function(x){approx_sum(mixing[,x], 1)}) == T)) { + print('warning: mixing matrix is asymmetrical') } if (is.null(correlations)) { correlations <- lapply(parameters, get_correlation_parameters) From e1dd9f88bf227c22399833f5b8fc6f9ed53609b8 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 1 Aug 2022 15:31:09 +0100 Subject: [PATCH 2/5] Update R/model.R --- R/model.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/model.R b/R/model.R index 82b3a118..b422f696 100644 --- a/R/model.R +++ b/R/model.R @@ -147,7 +147,7 @@ run_metapop_simulation <- function( if (nrow(mixing) != length(parameters)) { stop('mixing matrix rows must match length of parameters') } - if (!all(lapply(1:length(parameters), function(x){approx_sum(mixing[x,], 1)}) == T)) { + if (!all(vlapply(seq_along(parameters), function(x) approx_sum(mixing[x,], 1)))) { stop('all mixing matrix rows must sum to 1') } if (!all(lapply(1:length(parameters), function(x){approx_sum(mixing[,x], 1)}) == T)) { From 0c6e2ccd6b1b950d947cc96138155a1c5e8544a7 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 1 Aug 2022 15:31:17 +0100 Subject: [PATCH 3/5] Update R/model.R --- R/model.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/model.R b/R/model.R index b422f696..d0c61636 100644 --- a/R/model.R +++ b/R/model.R @@ -151,7 +151,7 @@ run_metapop_simulation <- function( stop('all mixing matrix rows must sum to 1') } if (!all(lapply(1:length(parameters), function(x){approx_sum(mixing[,x], 1)}) == T)) { - print('warning: mixing matrix is asymmetrical') + warning('mixing matrix is asymmetrical') } if (is.null(correlations)) { correlations <- lapply(parameters, get_correlation_parameters) From d1866af92852be086235dec58f0e5fc3e18b36f7 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 1 Aug 2022 15:31:24 +0100 Subject: [PATCH 4/5] Update R/model.R --- R/model.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/model.R b/R/model.R index d0c61636..2fb528c7 100644 --- a/R/model.R +++ b/R/model.R @@ -150,7 +150,7 @@ run_metapop_simulation <- function( if (!all(vlapply(seq_along(parameters), function(x) approx_sum(mixing[x,], 1)))) { stop('all mixing matrix rows must sum to 1') } - if (!all(lapply(1:length(parameters), function(x){approx_sum(mixing[,x], 1)}) == T)) { + if (!all(vlapply(seq_along(parameters), function(x) approx_sum(mixing[,x], 1)))) { warning('mixing matrix is asymmetrical') } if (is.null(correlations)) { From c3bc8f2635daa789f963bd05ee9e624a134bd375 Mon Sep 17 00:00:00 2001 From: Hillary Topazian <80535782+htopazian@users.noreply.github.com> Date: Mon, 1 Aug 2022 16:25:11 +0100 Subject: [PATCH 5/5] change vignette 0.33 to 1/3 to avoid errors --- vignettes/Metapopulation.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/Metapopulation.Rmd b/vignettes/Metapopulation.Rmd index c3674a90..1cbb433d 100644 --- a/vignettes/Metapopulation.Rmd +++ b/vignettes/Metapopulation.Rmd @@ -70,7 +70,7 @@ mix_2 <- matrix(c(0.8, 0.1, 0.1, nrow = 3, ncol = 3) # perfectly-mixed -mix_3 <- matrix(rep(.33, 9), nrow = 3, ncol = 3) +mix_3 <- matrix(rep(1/3, 9), nrow = 3, ncol = 3) # run model set.seed(123)