Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check/fix subset_clusters_by_id #100

Closed
thibautjombart opened this issue May 13, 2019 · 2 comments
Closed

check/fix subset_clusters_by_id #100

thibautjombart opened this issue May 13, 2019 · 2 comments
Assignees

Comments

@thibautjombart
Copy link
Contributor

From the example in the doc, I am not sure if the function is working, or I misunderstand it's use. In the example below, the number of cases in the linelist changes, but contacts remains unchanged.

if (require(outbreaks)) {
+      ## build data
+      x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts,
+                             id="case_id", to="case_id", from="infector",
+                             directed=TRUE)
+      
+      
+      id <- "cac51e" ## it can be a vector of id as well
+      
+      
+      ## subset based on cluster to which "cac51e" belongs
+      x_subset <- subset_clusters_by_id(x, id)
+      
+      }
Loading required package: outbreaks
>      
> x

/// Epidemiological Contacts //

  // class: epicontacts
  // 5,888 cases in linelist; 3,800 contacts;  directed 

  // linelist

# A tibble: 5,888 x 11
   id    generation date_of_infecti… date_of_onset date_of_hospita…
   <chr>      <int> <date>           <date>        <date>          
 1 d1fa…          0 NA               2014-04-07    2014-04-17      
 2 5337…          1 2014-04-09       2014-04-15    2014-04-20      
 3 f5c3…          1 2014-04-18       2014-04-21    2014-04-25      
 4 6c28…          2 NA               2014-04-27    2014-04-27      
 5 0f58…          2 2014-04-22       2014-04-26    2014-04-29      
 6 4973…          0 2014-03-19       2014-04-25    2014-05-02      
 7 f914…          3 NA               2014-05-03    2014-05-04      
 8 881b…          3 2014-04-26       2014-05-01    2014-05-05      
 9 e66f…          2 NA               2014-04-21    2014-05-06      
10 20b6…          3 NA               2014-05-05    2014-05-06      
# … with 5,878 more rows, and 6 more variables: date_of_outcome <date>,
#   outcome <fct>, gender <fct>, hospital <fct>, lon <dbl>, lat <dbl>

  // contacts

# A tibble: 3,800 x 3
   from   to     source 
   <chr>  <chr>  <fct>  
 1 d1fafd 53371b other  
 2 cac51e f5c3d8 funeral
 3 f5c3d8 0f58c4 other  
 4 0f58c4 881bd4 other  
 5 8508df 40ae5f other  
 6 127d83 f547d6 funeral
 7 f5c3d8 d58402 other  
 8 20b688 d8a13d other  
 9 2ae019 a3c8b8 other  
10 20b688 974bc1 other  
# … with 3,790 more rows

> x_subset

/// Epidemiological Contacts //

  // class: epicontacts
  // 5 cases in linelist; 3,800 contacts;  directed 

  // linelist

# A tibble: 5 x 11
  id    generation date_of_infecti… date_of_onset date_of_hospita…
  <chr>      <int> <date>           <date>        <date>          
1 f5c3…          1 2014-04-18       2014-04-21    2014-04-25      
2 0f58…          2 2014-04-22       2014-04-26    2014-04-29      
3 881b…          3 2014-04-26       2014-05-01    2014-05-05      
4 d584…          2 2014-04-23       2014-05-01    2014-05-10      
5 9000…          3 2014-05-09       2014-05-14    2014-05-17      
# … with 6 more variables: date_of_outcome <date>, outcome <fct>, gender <fct>,
#   hospital <fct>, lon <dbl>, lat <dbl>

  // contacts

# A tibble: 3,800 x 3
   from   to     source 
   <chr>  <chr>  <fct>  
 1 d1fafd 53371b other  
 2 cac51e f5c3d8 funeral
 3 f5c3d8 0f58c4 other  
 4 0f58c4 881bd4 other  
 5 8508df 40ae5f other  
 6 127d83 f547d6 funeral
 7 f5c3d8 d58402 other  
 8 20b688 d8a13d other  
 9 2ae019 a3c8b8 other  
10 20b688 974bc1 other  
# … with 3,790 more rows

>      

@nistara
Copy link
Member

nistara commented May 14, 2019

Fixed with 4492006

The error was in the last line of the function, which incorrectly subsetted the epicontacts object. It now uses igraph to subset and then rebuild the epicontacts object.

@zkamvar zkamvar mentioned this issue Jun 6, 2019
@finlaycampbell
Copy link
Collaborator

Fixed as of f3463b6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants