Learn R Programming

sequoia (version 2.0.7)

GetRelCat: Pairwise relationship

Description

Determine the relationship between individual X and all other individuals in the pedigree, going up to 1 or 2 generations back.

Usage

GetRelCat(x, Pedigree, GenBack = 2, patmat = TRUE)

Arguments

x

The focal individual, either its rownumber in the pedigree or ID.

Pedigree

dataframe columns id - dam - sire.

GenBack

Number of generations back to consider; 1 returns parent-offspring and sibling relationships, 2 also returns grandparental, avuncular and first cousins.

patmat

logical, distinguish between paternal versus maternal relative pairs?

Value

A named vector of length equal to the number of rows in Ped, with for each ID its relationship to the focal individual:

S

Self

M

Mother

P

Father

O

Offspring

FS

Full sibling

MHS

Maternal half-sibling

PHS

Paternal half-sibling

MGM

Maternal grandmother

MGF

Maternal grandfather

PGM

Paternal grandmother

PGF

Paternal grandfather

GO

Grand-offspring

FA

Full avuncular; maternal or paternal aunt or uncle

HA

Half avuncular

FN

Full nephew/niece

HN

Half nephew/niece

FC1

Full first cousin

DFC1

Double full first cousin

U

Unrelated (or otherwise related)

See Also

ComparePairs to compare pairwise relationships between 2 pedigrees.

Examples

Run this code
# NOT RUN {
data(Ped_griffin)
# find all relatives of a specific individual
Rel42 <- GetRelCat("i042_2003_F", Ped_griffin)
Rel42[Rel42 != "U"]

# make NxN matrix with relationship categories:
Ped_griffin_sub <- Ped_griffin[Ped_griffin$birthyear<2003,]  # quicker
RCM <- sapply(seq_along(Ped_griffin_sub$id), GetRelCat, Ped_griffin_sub)
table(RCM)
#   M  MHS    O    P    S    U
#  10    6   16    6   40 1522
# note that sibling & cousin pairs are counted twice!
# Parent-offspring pairs are counted directionally:
# once as offspring (O), once as mother (M) or father (P)

# for large pedigrees, table(factor()) is much faster:
table(factor(RCM, levels=c("M","P","FS","MHS","PHS","U")))

# list the maternal half-siblings:
these <- which(RCM=="MHS", arr.ind=TRUE)
data.frame(id1 = Ped_griffin_sub$id[these[,1]],
           id2 = Ped_griffin_sub$id[these[,2]])


# Get Colony-style lists of full sibs & half sibs dyads:
# }
# NOT RUN {
RCM <- sapply(seq_along(MyPedigree$id), GetRelCat, Pedigree = MyPedigree,
              GenBack = 1, patmat = FALSE)
# rownumbers of pairs of FS & HS
FullSibDyads <- which(RCM == "FS", arr.ind=TRUE)
HalfSibDyads <- which(RCM == "HS", arr.ind=TRUE)

# each pair is listed 2x - fix:
FullSibDyads <- FullSibDyads[FullSibDyads[,1] < FullSibDyads[,2], ]
HalfSibDyads <- HalfSibDyads[HalfSibDyads[,1] < HalfSibDyads[,2], ]

# translate rownumbers into IDs
MyPedigree$id <- as.character(MyPedigree$id)
FullSibDyads <- cbind(MyPedigree$id[FullSibDyads[,1]],
                      MyPedigree$id[FullSibDyads[,2]])
HalfSibDyads <- cbind(MyPedigree$id[HalfSibDyads[,1]],
                      MyPedigree$id[HalfSibDyads[,2]])
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab