Skip to content

Kindepth for double marriage #33

@LouisLeNezet

Description

@LouisLeNezet

Hi @sinnweja,

I'm nearly done for the new package.
I've recently discovered a subtle use case where the kindepth is not nicely computed:

Here is the code:

df <- data.frame(
    id = 1:12,
    dadid = c(0, 0, 1, 0, 0, 0, 3, 3, 5, 5, 7, 10),
    momid = c(0, 0, 2, 0, 0, 0, 4, 4, 6, 6, 9, 8),
    sex = c(1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 1, 2)
)
pedi <- with(df, pedigree(id, dadid, momid, sex))
kindepth(pedi, align = TRUE)
# 0 0 1 1 0 0 2 2 1 1 3 3

We get
image

What would be better is to to have a kindepth of

kindepth(pedi, align = TRUE)
# 0 0 1 1 1 1 2 2 2 2 3 3

plot

The problem seems to come in the loop that update the agood ancestors.
In the case of a double marriage like in the previous pedigree, the loop will iterate and will add the individuals as follow:

# Initial depth
0 0 1 0 0 0 2 2 1 1 3 3

# id 4 single marryin corrected
0 0 1 1 0 0 2 2 1 1 3 3

# Selected pairs is 9, 7
# abad is
9 5 6
# agood is
7 1 2 3 4

# Then by iteration agood become
# + spouse
7 1 2 3 4
# + ancestors
7 1 2 3 4
# + kids
7 1 2 3 4 8
# + spouse
7  1  2  3  4  8 10
# + ancestors
7  1  2  3  4  8 10  5  6
# + kids
7  1  2  3  4  8 10  5  6  9

The individuals 10, 5, 6 and 9 should not be added to be able to modify them.
What would be the best way to control for this case ?

Best,
Louis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions