Skip to content

Allow same-sex relationship in the demography module #3

@asiripanich

Description

@asiripanich

If there is any same-sex couple getting married via the cohabitation route then the following checkmate command will raise a 'unique integer' error since the ids of those individuals will appear twice in both vector ids.

https://github.com/dymium-org/dymiumModules/blob/d53fdb47680efc9a05e56f0c420c85907e73794e/modules/demography/marriage.R#L75-L80

One way to fix this would be to call unique on the id vectors, only if the duplicated ids belong to individuals in a same-sex partnership.

#' Check to make sure that the duplicated ids come from same-sex cohabiting
    #' individuals to get married.
    if (length(unique(cohabiting_person_to_marry_ids)) !=
        length(cohabiting_person_to_marry_ids)) {
      tab <- table(cohabiting_person_to_marry_ids)
      if (any(tab > 2)) {
        stop("There are some ids that appear more than twice. Please debug or report this.")
      }
      potential_same_sex_ind_ids <- as.integer(names(tab[tab != 1]))
      #' pssind = potential_same_sex_ind
      pssind_sex <- Ind$get_attr("sex", ids = potential_same_sex_ind_ids)
      pssind_partner_ids <- Ind$get_attr("partner_id", ids = potential_same_sex_ind_ids)
      pssind_partner_sex <- Ind$get_attr("sex", ids = pssind_partner_ids)
      if (all(pssind_sex == pssind_partner_sex)) {
        stop("There are duplicated ids of opposite couples in the marriage from cohabitation process.")
      } else {
        cohabiting_person_to_marry_ids <- unique(cohabiting_person_to_marry_ids)
      }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions