get__pairwise_relatednesses_matrix: Calculates a matrix of pairwise relatedness's

Description Usage Arguments Details Value Examples

View source: R/relatedness functions.R

Description

get__pairwise_relatednesses_matrix calculates and returns a matrix of pairwise relatedness's

Usage

1
2
3
4
5
6
7
8
get__pairwise_relatednesses_matrix(
  ids = "ALL",
  population.data,
  parents.to.use = "all.avaliable",
  r.degree = 2,
  kinship.network = NULL,
  r.type = "coef.of.relationship"
)

Arguments

ids

Vector of ids to include in returned matrix. Default is "ALL" which will calculate for all ids in the population.data

population.data

data frame of all known ids in the population (not just ids). Data frame must columns: id [character], mother [character], father [character] & sex [character] . No columns can contains NA. Unknown mother or father, ids should be labeled as UNK. sex must be M, F, male, female or UNK.

parents.to.use

Character of either "all.available" (default), "mother.only" or "father.only", which calculate biparental, maternal or paternal relatedness respectively.

r.degree

degree of relationship to which to calculate relatedness ( https://en.wikipedia.org/wiki/Coefficient_of_relationship. Degree is calculated separately for each lineage i.e. half-sisters are considered equivalent to full-sisters in count (but not in relatedness calculation).

kinship.network

Either NULL [default] or the output from make_kinship_network function. Using the function output will usually be faster, especially with large datasets.

r.type

Either "coef.of.relationship" (default) or "kinship.coef". Defines the type of relatedness returned.

Details

This is a function to calculate a matrix of pairwise relatedness between all ids supplied by the ids term, limited to a pedigree depth of r.degree and returning NA if the pairwise relatedness is unknown.

Value

This function will output a square matrix of length(ids) x length(ids). With row and columns named for ids. When ids is "ALL", ids == population.data$id.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#Example data taken from kinship2::kinship()
test1 <- data.frame(id  =c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14),
                   mom =c(0, 0, 0, 0, 2, 2, 4, 4, 6,  2,  0,  0, 12, 13),
                   dad =c(0, 0, 0, 0, 1, 1, 3, 3, 3,  7,  0,  0, 11, 10),
                   sex =c(0, 1, 0, 1, 0, 1, 0, 1, 0,  0,  0,  1,  1,  1))
#some renaming
names(test1)[2] = "mother"
names(test1)[3] = "father"
test1$sex = ifelse(test1$sex ==1, "F", "M")
test1$id = as.character(test1$id)
test1$mother = ifelse(test1$mother!=0, as.character(test1$mother), "UNK")
test1$father = ifelse(test1$father!=0, as.character(test1$father), "UNK")
test1
r.mat =
 get__pairwise_relatednesses_matrix(
   ids = test1$id ,
   population.data = test1,
   parents.to.use = "all.avaliable",
   r.degree = 2,
   kinship.network = NULL,
   r.type = "coef.of.relationship"
 )
r.mat

samellisq/comparekin documentation built on Dec. 22, 2021, 10:11 p.m.