R Under development (unstable) (2024-10-01 r87205 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## Copyright 2013-2020 Stefan Widgren and Maria Noremark, > ## National Veterinary Institute, Sweden > ## > ## Licensed under the EUPL, Version 1.1 or - as soon they > ## will be approved by the European Commission - subsequent > ## versions of the EUPL (the "Licence"); > ## You may not use this work except in compliance with the > ## Licence. > ## You may obtain a copy of the Licence at: > ## > ## http://ec.europa.eu/idabc/eupl > ## > ## Unless required by applicable law or agreed to in > ## writing, software distributed under the Licence is > ## distributed on an "AS IS" basis, > ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either > ## express or implied. > ## See the Licence for the specific language governing > ## permissions and limitations under the Licence. > > library(EpiContactTrace) > > ## > ## Check in- and outgoing contact chain methods > ## > > ## > ## Case 1 > ## > > movements <- data.frame( + source = 1:7, + destination = c(4L, 5L, 5L, 6L, 8L, 8L, 8L), + t = structure(c(14849, 14846, 14847, 14850, 14848, 14851, 14852), + class = "Date")) > ct <- Trace(movements, + root = 8L, + inBegin = as.Date("2010-08-22"), + inEnd = as.Date("2010-10-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) > ct Root: 8 <<< In contacts <<< In begin date: 2010-08-22 In end date: 2010-10-01 In days: 40 In degree: 3 Ingoing contact chain: 7 8 <-- 5 5 <-- 2 5 <-- 3 8 <-- 6 6 <-- 4 4 <-- 1 8 <-- 7 >>> Out contacts >>> Out begin date: 2010-08-01 Out end date: 2010-08-31 Out days: 30 Out degree: 0 Outgoing contact chain: 0 No outgoing contacts during the search period. > stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 7L)) > stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 0L)) > > ## > ## Case 2 > ## > > movements <- data.frame( + source = c(1L, 2L, 3L, 3L), + destination = c(3L, 3L, 4L, 4L), + t = structure(c(14834, 14838, 14836, 14841), class = "Date"), + individual = c(NA_character_, NA_character_, NA_character_, NA_character_), + n = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_)) > ct <- Trace(movements, + root = 4L, + inBegin = as.Date("2010-07-22"), + inEnd = as.Date("2010-08-21"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) > ct Root: 4 <<< In contacts <<< In begin date: 2010-07-22 In end date: 2010-08-21 In days: 30 In degree: 1 Ingoing contact chain: 3 4 <-- 3 3 <-- 1 3 <-- 2 >>> Out contacts >>> Out begin date: 2010-08-01 Out end date: 2010-08-31 Out days: 30 Out degree: 0 Outgoing contact chain: 0 No outgoing contacts during the search period. > stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 3L)) > stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 0L)) > > ## > ## Case 3 > ## > > movements <- data.frame( + source = 1:2, + destination = c(2L, 1L), + t = structure(c(14834, 14834), class = "Date"), + individual = c(NA_character_, NA_character_), + n = c(NA_integer_, NA_integer_)) > ct <- Trace(movements, + root = 1L, + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-09-01"), + outEnd = as.Date("2010-10-01")) > ct Root: 1 <<< In contacts <<< In begin date: 2010-08-02 In end date: 2010-09-01 In days: 30 In degree: 1 Ingoing contact chain: 1 1 <-- 2 >>> Out contacts >>> Out begin date: 2010-09-01 Out end date: 2010-10-01 Out days: 30 Out degree: 0 Outgoing contact chain: 0 No outgoing contacts during the search period. > stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 1L)) > stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 0L)) > > ## > ## Case 4 > ## > > movements <- data.frame( + source = c(1L, 2L, 2L, 1L, 3L, 7L, 1L), + destination = c(2L, 5L, 6L, 3L, 7L, 8L, 4L), + t = structure(c(14834, 14838, 14836, 14857, 14860, 14862, 14884), + class = "Date"), + individual = c(NA_character_, NA_character_, NA_character_, + NA_character_, NA_character_, NA_character_, + NA_character_), + n = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, + NA_integer_, NA_integer_, NA_integer_)) > ct <- Trace(movements, + root = 1L, + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-11-09")) > ct Root: 1 <<< In contacts <<< In begin date: 2010-08-02 In end date: 2010-09-01 In days: 30 In degree: 0 Ingoing contact chain: 0 No ingoing contacts during the search period. >>> Out contacts >>> Out begin date: 2010-08-01 Out end date: 2010-11-09 Out days: 100 Out degree: 3 Outgoing contact chain: 7 1 --> 2 2 --> 5 2 --> 6 1 --> 3 3 --> 7 7 --> 8 1 --> 4 > stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 0L)) > stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 7L)) > > ## > ## Case 5 > ## > > movements <- data.frame( + source = 1:2, + destination = c(2L, 1L), + t = structure(c(14834, 14834), class = "Date"), + individual = c(NA_character_, NA_character_), + n = c(NA_integer_, NA_integer_)) > ct <- Trace(movements, + root = 1L, + inBegin = as.Date("2010-07-02"), + inEnd = as.Date("2010-08-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) > ct Root: 1 <<< In contacts <<< In begin date: 2010-07-02 In end date: 2010-08-01 In days: 30 In degree: 0 Ingoing contact chain: 0 No ingoing contacts during the search period. >>> Out contacts >>> Out begin date: 2010-08-01 Out end date: 2010-08-31 Out days: 30 Out degree: 1 Outgoing contact chain: 1 1 --> 2 > stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 0L)) > stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 1L)) > > ## > ## Case 6 > ## > > movements <- data.frame( + source = c(1L, 2L, 1L, 2L, 1L, 3L, 1L), + destination = c(2L, 3L, 2L, 3L, 2L, 4L, 2L), + t = structure(c(1L, 2L, 3L, 4L, 7L, 6L, 5L), + .Label = c("2010-10-01", "2010-10-05", "2010-10-10", + "2010-10-15", "2010-10-20", "2010-10-25", + "2010-10-30"), + class = "factor")) > ct <- Trace(movements, + root = 1L, + inBegin = as.Date("2010-10-10"), + inEnd = as.Date("2010-10-20"), + outBegin = as.Date("2010-10-10"), + outEnd = as.Date("2010-10-20")) > ct Root: 1 <<< In contacts <<< In begin date: 2010-10-10 In end date: 2010-10-20 In days: 10 In degree: 0 Ingoing contact chain: 0 No ingoing contacts during the search period. >>> Out contacts >>> Out begin date: 2010-10-10 Out end date: 2010-10-20 Out days: 10 Out degree: 1 Outgoing contact chain: 2 1 --> 2 2 --> 3 > stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 0L)) > stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 2L)) > > ## > ## Case 7 > ## > > movements <- data.frame( + source = c(1L, 2L, 1L, 2L, 1L, 3L, 1L), + destination = c(2L, 3L, 2L, 3L, 2L, 4L, 2L), + t = structure(c(1L, 2L, 3L, 4L, 7L, 6L, 5L), + .Label = c("2010-10-01", "2010-10-05", "2010-10-10", + "2010-10-15", "2010-10-20", "2010-10-25", + "2010-10-30"), + class = "factor")) > > ns <- NetworkSummary(movements, root = 1, tEnd = "2010-10-20", days = 10) > > df <- data.frame(root = "1", + inBegin = structure(14892, class = "Date"), + inEnd = structure(14902, class = "Date"), + inDays = 10L, + outBegin = structure(14892, class = "Date"), + outEnd = structure(14902, class = "Date"), + outDays = 10L, + inDegree = 0L, + outDegree = 1L, + ingoingContactChain = 0L, + outgoingContactChain = 2L, + stringsAsFactors = FALSE) > ns root inBegin inEnd inDays outBegin outEnd outDays inDegree 1 1 2010-10-10 2010-10-20 10 2010-10-10 2010-10-20 10 0 outDegree ingoingContactChain outgoingContactChain 1 1 0 2 > stopifnot(identical(ns, df)) > > proc.time() user system elapsed 0.21 0.12 0.32