This function is the key function to do the rules based classification.

resolve_data(grouped_data, window_size = 487, threshold_year = 365,
  parallel = FALSE, n_core = 2, include_error_columns = FALSE,
  mc.cleanup = FALSE)

Arguments

grouped_data

A list of data frame objects.

window_size

The maximum length of the scanning period. Can be an integer giving the number of days, the result of a call to function difftime, or an object of class Duration.

threshold_year

The length of the yearly test period. Can be an integer giving the number of days, the result of a call to function difftime, or an object of class Duration.

parallel

Optional, if it is TRUE, run on parallel.

n_core

if parallel set to TRUE, this will specify the number of computer cores required.

include_error_columns

Optional, if it is TRUE, the returned result of error_data will contain two extra columns error_code and error_message.

mc.cleanup

if set to TRUE then all children that have been forked by this function will be killed (by sending SIGTERM) before this function returns. Under normal circumstances mclapply waits for the children to deliver results, so this option usually has only effect when mclapply is interrupted. If set to FALSE then child processes are collected, but not forcefully terminated. As a special case this argument can be set to the number of the signal that should be used to kill the children instead of SIGTERM.

Value

A list type of object that contains a classified journey dataframe object and a error dataframe object.

Examples

## to suppresse log messages to the console migrbc::initialize_logger(log_level = 1)
#> logger 'migrbc' has log_level=1 and writes to the console
number_of_people = 10 person_data <- migrbc::setup_random_test_data(number_of_people, initial_date = '2001-01-01', numJourneys = 5, min = 0, max = 10) crossings <- migrbc::pre_process(person_data, n_groups = 10) crossings
#> $`1` #> $`1`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 1 1 1 1 2001-01-01 1 #> 2 2 1 0 2001-01-03 2 #> 3 3 1 1 2001-01-05 3 #> 4 4 1 0 2001-01-07 4 #> 5 5 1 1 2001-01-11 5 #> res_status_before res_status_after journeyId_prev #> 1 0 0 0 #> 2 0 0 0 #> 3 0 0 0 #> 4 0 0 0 #> 5 0 0 0 #> #> $`1`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> $`2` #> $`2`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 6 1 2 1 2001-01-01 1 #> 7 2 2 0 2001-01-02 2 #> 8 3 2 1 2001-01-09 3 #> 9 4 2 0 2001-01-17 4 #> 10 5 2 1 2001-01-26 5 #> res_status_before res_status_after journeyId_prev #> 6 0 0 0 #> 7 0 0 0 #> 8 0 0 0 #> 9 0 0 0 #> 10 0 0 0 #> #> $`2`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> $`3` #> $`3`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 11 1 3 1 2001-01-01 1 #> 12 2 3 0 2001-01-02 2 #> 13 3 3 1 2001-01-07 3 #> 14 4 3 0 2001-01-14 4 #> 15 5 3 1 2001-01-22 5 #> res_status_before res_status_after journeyId_prev #> 11 0 0 0 #> 12 0 0 0 #> 13 0 0 0 #> 14 0 0 0 #> 15 0 0 0 #> #> $`3`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> $`4` #> $`4`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 16 1 4 1 2001-01-01 1 #> 17 2 4 0 2001-01-03 2 #> 18 3 4 1 2001-01-08 3 #> 19 4 4 0 2001-01-15 4 #> 20 5 4 1 2001-01-23 5 #> res_status_before res_status_after journeyId_prev #> 16 0 0 0 #> 17 0 0 0 #> 18 0 0 0 #> 19 0 0 0 #> 20 0 0 0 #> #> $`4`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> $`5` #> $`5`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 21 1 5 1 2001-01-01 1 #> 22 2 5 0 2001-01-02 2 #> 23 3 5 1 2001-01-05 3 #> 24 4 5 0 2001-01-14 4 #> 25 5 5 1 2001-01-23 5 #> res_status_before res_status_after journeyId_prev #> 21 0 0 0 #> 22 0 0 0 #> 23 0 0 0 #> 24 0 0 0 #> 25 0 0 0 #> #> $`5`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> $`6` #> $`6`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 26 1 6 1 2001-01-01 1 #> 27 2 6 0 2001-01-01 2 #> 28 3 6 1 2001-01-06 3 #> 29 4 6 0 2001-01-13 4 #> 30 5 6 1 2001-01-22 5 #> res_status_before res_status_after journeyId_prev #> 26 0 0 0 #> 27 0 0 0 #> 28 0 0 0 #> 29 0 0 0 #> 30 0 0 0 #> #> $`6`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> $`7` #> $`7`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 31 1 7 1 2001-01-01 1 #> 32 2 7 0 2001-01-03 2 #> 33 3 7 1 2001-01-07 3 #> 34 4 7 0 2001-01-12 4 #> 35 5 7 1 2001-01-18 5 #> res_status_before res_status_after journeyId_prev #> 31 0 0 0 #> 32 0 0 0 #> 33 0 0 0 #> 34 0 0 0 #> 35 0 0 0 #> #> $`7`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> $`8` #> $`8`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 36 1 8 1 2001-01-01 1 #> 37 2 8 0 2001-01-01 2 #> 38 3 8 1 2001-01-02 3 #> 39 4 8 0 2001-01-05 4 #> 40 5 8 1 2001-01-12 5 #> res_status_before res_status_after journeyId_prev #> 36 0 0 0 #> 37 0 0 0 #> 38 0 0 0 #> 39 0 0 0 #> 40 0 0 0 #> #> $`8`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> $`9` #> $`9`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 41 1 9 1 2001-01-01 1 #> 42 2 9 0 2001-01-01 2 #> 43 3 9 1 2001-01-03 3 #> 44 4 9 0 2001-01-07 4 #> 45 5 9 1 2001-01-11 5 #> res_status_before res_status_after journeyId_prev #> 41 0 0 0 #> 42 0 0 0 #> 43 0 0 0 #> 44 0 0 0 #> 45 0 0 0 #> #> $`9`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> $`10` #> $`10`$group_data #> journeyId personId is_arrival date_crossing journey_sequence #> 46 1 10 1 2001-01-01 1 #> 47 2 10 0 2001-01-04 2 #> 48 3 10 1 2001-01-09 3 #> 49 4 10 0 2001-01-14 4 #> 50 5 10 1 2001-01-22 5 #> res_status_before res_status_after journeyId_prev #> 46 0 0 0 #> 47 0 0 0 #> 48 0 0 0 #> 49 0 0 0 #> 50 0 0 0 #> #> $`10`$initial_status_group #> [1] res_status_initial personId date_finalised #> <0 rows> (or 0-length row.names) #> #> #> attr(,"class") #> [1] "migrbc_preprocess" "list"
cross_spaces <- migrbc::resolve_data(crossings) cross_spaces
#> $journeys #> journeyId journeyId_prev personId date_crossing journey_sequence #> 1 1 0 1 2001-01-01 1 #> 2 2 1 1 2001-01-03 2 #> 3 3 2 1 2001-01-05 3 #> 4 4 3 1 2001-01-07 4 #> 5 5 4 1 2001-01-11 5 #> 6 1 0 2 2001-01-01 1 #> 7 2 1 2 2001-01-02 2 #> 8 3 2 2 2001-01-09 3 #> 9 4 3 2 2001-01-17 4 #> 10 5 4 2 2001-01-26 5 #> 11 1 0 3 2001-01-01 1 #> 12 2 1 3 2001-01-02 2 #> 13 3 2 3 2001-01-07 3 #> 14 4 3 3 2001-01-14 4 #> 15 5 4 3 2001-01-22 5 #> 16 1 0 4 2001-01-01 1 #> 17 2 1 4 2001-01-03 2 #> 18 3 2 4 2001-01-08 3 #> 19 4 3 4 2001-01-15 4 #> 20 5 4 4 2001-01-23 5 #> 21 1 0 5 2001-01-01 1 #> 22 2 1 5 2001-01-02 2 #> 23 3 2 5 2001-01-05 3 #> 24 4 3 5 2001-01-14 4 #> 25 5 4 5 2001-01-23 5 #> 26 1 0 6 2001-01-01 1 #> 27 2 1 6 2001-01-01 2 #> 28 3 2 6 2001-01-06 3 #> 29 4 3 6 2001-01-13 4 #> 30 5 4 6 2001-01-22 5 #> 31 1 0 7 2001-01-01 1 #> 32 2 1 7 2001-01-03 2 #> 33 3 2 7 2001-01-07 3 #> 34 4 3 7 2001-01-12 4 #> 35 5 4 7 2001-01-18 5 #> 36 1 0 8 2001-01-01 1 #> 37 2 1 8 2001-01-01 2 #> 38 3 2 8 2001-01-02 3 #> 39 4 3 8 2001-01-05 4 #> 40 5 4 8 2001-01-12 5 #> 41 1 0 9 2001-01-01 1 #> 42 2 1 9 2001-01-01 2 #> 43 3 2 9 2001-01-03 3 #> 44 4 3 9 2001-01-07 4 #> 45 5 4 9 2001-01-11 5 #> 46 1 0 10 2001-01-01 1 #> 47 2 1 10 2001-01-04 2 #> 48 3 2 10 2001-01-09 3 #> 49 4 3 10 2001-01-14 4 #> 50 5 4 10 2001-01-22 5 #> days_to_next_crossing is_arrival res_status_before res_status_after #> 1 2 1 0 1 #> 2 2 0 1 1 #> 3 2 1 1 1 #> 4 4 0 1 1 #> 5 487 1 1 1 #> 6 1 1 0 1 #> 7 7 0 1 1 #> 8 8 1 1 1 #> 9 9 0 1 1 #> 10 487 1 1 1 #> 11 1 1 0 1 #> 12 5 0 1 1 #> 13 7 1 1 1 #> 14 8 0 1 1 #> 15 487 1 1 1 #> 16 2 1 0 1 #> 17 5 0 1 1 #> 18 7 1 1 1 #> 19 8 0 1 1 #> 20 487 1 1 1 #> 21 1 1 0 1 #> 22 3 0 1 1 #> 23 9 1 1 1 #> 24 9 0 1 1 #> 25 487 1 1 1 #> 26 0 1 0 1 #> 27 5 0 1 1 #> 28 7 1 1 1 #> 29 9 0 1 1 #> 30 487 1 1 1 #> 31 2 1 0 1 #> 32 4 0 1 1 #> 33 5 1 1 1 #> 34 6 0 1 1 #> 35 487 1 1 1 #> 36 0 1 0 1 #> 37 1 0 1 1 #> 38 3 1 1 1 #> 39 7 0 1 1 #> 40 487 1 1 1 #> 41 0 1 0 1 #> 42 2 0 1 1 #> 43 4 1 1 1 #> 44 4 0 1 1 #> 45 487 1 1 1 #> 46 3 1 0 1 #> 47 5 0 1 1 #> 48 5 1 1 1 #> 49 8 0 1 1 #> 50 487 1 1 1 #> is_long_term_mig date_finalised_res_before date_finalised_res_after #> 1 1 2001-01-01 2002-01-07 #> 2 0 2002-01-07 2002-01-07 #> 3 0 2002-01-07 2002-01-07 #> 4 0 2002-01-07 2002-01-07 #> 5 0 2002-01-07 2002-01-07 #> 6 1 2001-01-01 2002-01-17 #> 7 0 2002-01-17 2002-01-17 #> 8 0 2002-01-17 2002-01-17 #> 9 0 2002-01-17 2002-01-17 #> 10 0 2002-01-17 2002-01-17 #> 11 1 2001-01-01 2002-01-14 #> 12 0 2002-01-14 2002-01-14 #> 13 0 2002-01-14 2002-01-14 #> 14 0 2002-01-14 2002-01-14 #> 15 0 2002-01-14 2002-01-14 #> 16 1 2001-01-01 2002-01-14 #> 17 0 2002-01-14 2002-01-14 #> 18 0 2002-01-14 2002-01-14 #> 19 0 2002-01-14 2002-01-14 #> 20 0 2002-01-14 2002-01-14 #> 21 1 2001-01-01 2002-01-13 #> 22 0 2002-01-13 2002-01-13 #> 23 0 2002-01-13 2002-01-13 #> 24 0 2002-01-13 2002-01-13 #> 25 0 2002-01-13 2002-01-13 #> 26 1 2001-01-01 2002-01-15 #> 27 0 2002-01-15 2002-01-15 #> 28 0 2002-01-15 2002-01-15 #> 29 0 2002-01-15 2002-01-15 #> 30 0 2002-01-15 2002-01-15 #> 31 1 2001-01-01 2002-01-11 #> 32 0 2002-01-11 2002-01-11 #> 33 0 2002-01-11 2002-01-11 #> 34 0 2002-01-11 2002-01-11 #> 35 0 2002-01-11 2002-01-11 #> 36 1 2001-01-01 2002-01-09 #> 37 0 2002-01-09 2002-01-09 #> 38 0 2002-01-09 2002-01-09 #> 39 0 2002-01-09 2002-01-09 #> 40 0 2002-01-09 2002-01-09 #> 41 1 2001-01-01 2002-01-07 #> 42 0 2002-01-07 2002-01-07 #> 43 0 2002-01-07 2002-01-07 #> 44 0 2002-01-07 2002-01-07 #> 45 0 2002-01-07 2002-01-07 #> 46 1 2001-01-01 2002-01-14 #> 47 0 2002-01-14 2002-01-14 #> 48 0 2002-01-14 2002-01-14 #> 49 0 2002-01-14 2002-01-14 #> 50 0 2002-01-14 2002-01-14 #> date_finalised_LTM #> 1 2002-01-07 #> 2 2001-01-03 #> 3 2002-01-07 #> 4 2001-01-07 #> 5 2002-01-07 #> 6 2002-01-17 #> 7 2001-01-02 #> 8 2002-01-17 #> 9 2001-01-17 #> 10 2002-01-17 #> 11 2002-01-14 #> 12 2001-01-02 #> 13 2002-01-14 #> 14 2001-01-14 #> 15 2002-01-14 #> 16 2002-01-14 #> 17 2001-01-03 #> 18 2002-01-14 #> 19 2001-01-15 #> 20 2002-01-14 #> 21 2002-01-13 #> 22 2001-01-02 #> 23 2002-01-13 #> 24 2001-01-14 #> 25 2002-01-13 #> 26 2002-01-15 #> 27 2001-01-01 #> 28 2002-01-15 #> 29 2001-01-13 #> 30 2002-01-15 #> 31 2002-01-11 #> 32 2001-01-03 #> 33 2002-01-11 #> 34 2001-01-12 #> 35 2002-01-11 #> 36 2002-01-09 #> 37 2001-01-01 #> 38 2002-01-09 #> 39 2001-01-05 #> 40 2002-01-09 #> 41 2002-01-07 #> 42 2001-01-01 #> 43 2002-01-07 #> 44 2001-01-07 #> 45 2002-01-07 #> 46 2002-01-14 #> 47 2001-01-04 #> 48 2002-01-14 #> 49 2001-01-14 #> 50 2002-01-14 #> #> $error_data #> [1] journeyId journeyId_prev #> [3] personId date_crossing #> [5] journey_sequence days_to_next_crossing #> [7] is_arrival res_status_before #> [9] res_status_after is_long_term_mig #> [11] date_finalised_res_before date_finalised_res_after #> [13] date_finalised_LTM #> <0 rows> (or 0-length row.names) #>