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

Contact likelihood affected by contact directionality #89

Open
CyGei opened this issue Jul 22, 2024 · 1 comment
Open

Contact likelihood affected by contact directionality #89

CyGei opened this issue Jul 22, 2024 · 1 comment

Comments

@CyGei
Copy link
Contributor

CyGei commented Jul 22, 2024

Description:

The contact likelihood function does not consider directed contacts (link to code & article) despite the outbreaker_config() function allowing specification of whether contacts are directed. If the user specifies that ctd_directed = TRUE in outbreaker_config(), the resulting contact matrix will not be pairwise.

Proposed Solution:

Simplify the internal handling of the contact matrix to always make it pairwise, regardless of user input. Alternatively, remove the option for directed contacts.

Illustration Code:

n = 10
ids = LETTERS[1:n]
i = LETTERS[1:(n / 2)]
j = LETTERS[(n / 2 + 1):n]
ctd_dup <- data.frame("i" = c(i, j), "j" = c(j, i))
ctd <- data.frame("i" = i, "j" = j)

data <- lapply(list(ctd_dup = ctd_dup, ctd = ctd), function(x) {
  data <- outbreaker_data(
    ids = ids,
    dates = sample(1:40, n, replace = TRUE),
    ctd = x,
    w_dens = fake_outbreak$w
  )
  data$contacts
})
data
all.equal(data$ctd, data$ctd_dup)

#/// from internals.R line 291
make_ctd_pairwise <- function(contacts) {
  contacts[] <- as.integer(contacts == 1 | t(contacts) == 1)
  return(contacts)
}
all.equal(make_ctd_pairwise(data$ctd), make_ctd_pairwise(data$ctd_dup))
@finlaycampbell
Copy link
Collaborator

Hi Cy! Thanks for raising the issue :)

It's true that the original paper states we use only non-directed contacts, but we made a later addition to the package itself to accommodate directed contacts too. As far as I can tell, when ctd_directed=TRUE and the matrix is not symmetrical, cpp_ll_contact will only count a "true positive" (i.e. a transmission pair aligns with a reported contact) if the directionality is also aligned (i.e. A contacted B and A infected B). The likelihood code refers to a pairwise matrix but by that I don't mean symmetrical, I just mean it contains information on all infector-infectee pairs.

Not sure if that makes sense, let me know. It shouldn't be too difficult to run some tests to check whether the implementation actually works, I am on leave for all of August though and so don't have capacity to do that now.

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

No branches or pull requests

2 participants