diff --git a/R/contact_matrix.R b/R/contact_matrix.R index def4bc9..eecf8ec 100644 --- a/R/contact_matrix.R +++ b/R/contact_matrix.R @@ -197,8 +197,8 @@ contact_matrix <- function(survey, countries = NULL, survey.pop, age.limits, fil # remove contact ages below the age limit, before dealing with missing contact ages survey$contacts <- survey$contacts[is.na(cnt_age) | - cnt_age >= min(age.limits), ] - + cnt_age >= min(age.limits), ] + if (missing.contact.age == "remove" && nrow(survey$contacts[is.na(cnt_age)]) > 0) { if (!missing.contact.age.set) { diff --git a/tests/testthat/test-matrix.r b/tests/testthat/test-matrix.r index 4fb7da6..a28bd74 100644 --- a/tests/testthat/test-matrix.r +++ b/tests/testthat/test-matrix.r @@ -557,12 +557,8 @@ test_that("Symmetric contact matrices with large normalisation weights throw a w }) test_that("Contacts with an age below the age limits are excluded regardless of the missing.contact.age setting", { - expect_equal(ncol(contact_matrix(polymod,age.limits = c(10,50), missing.contact.age = 'remove')$matrix), 2) - expect_equal(ncol(contact_matrix(polymod,age.limits = c(10,50), missing.contact.age = 'sample')$matrix), 2) - expect_equal(ncol(contact_matrix(polymod,age.limits = c(10,50), missing.contact.age = 'keep')$matrix), 3) # extra column for ages outside age limits (= NA) - expect_equal(ncol(contact_matrix(polymod,age.limits = c(10,50), missing.contact.age = 'ignore')$matrix), 2) + expect_equal(ncol(contact_matrix(polymod, age.limits = c(10, 50), missing.contact.age = "remove")$matrix), 2) + expect_equal(ncol(contact_matrix(polymod, age.limits = c(10, 50), missing.contact.age = "sample")$matrix), 2) + expect_equal(ncol(contact_matrix(polymod, age.limits = c(10, 50), missing.contact.age = "keep")$matrix), 3) # extra column for ages outside age limits (= NA) + expect_equal(ncol(contact_matrix(polymod, age.limits = c(10, 50), missing.contact.age = "ignore")$matrix), 2) }) - - - -