Description Usage Arguments Value Examples
View source: R/ego network functions.R
get_nth_degree_relatives
derives the ids of all relatives within the
nth degree for a given individual from a population kinship-network.
1 | get_nth_degree_relatives(network, from.id, r.degree)
|
network |
A kinship-network derived from the
|
from.id |
Character. The id of the individual for whom nth degree relatives will be found |
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). |
Returns a character vector of the ids of all relatives up to the
r.degree
degree of the from.id
. For example, where
r.degree = 2
this will return a vector of all 1st and 2nd degree
maternal and paternal relatives (if they are both present in the network).
Vector also includes from.id
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #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
population.network = make_kinship_network(make_relation_df(test1))
plot(population.network)
get_nth_degree_relatives(network = population.network, from.id = test1$id[5],
r.degree = 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.