make_relation_df: Simplify data frame to pedigree information

Description Usage Arguments Details Value Examples

View source: R/ego network functions.R

Description

Simple function to prepare a data frame of population.data data frame to be used in the make_kinship_network function.

Usage

1
make_relation_df(population.data, parents.to.use = "all.avaliable")

Arguments

population.data

Data frame containing columns named id and one or both of 'mother' and 'father'.

parents.to.use

Either "all.avaliable", "mother.only" or father.only. This defines the type of network that will be created and ultimately the type of relatedness calculated made either biparental, maternal only or paternal only. Option "all.avaliable" will use both mother and father if both columns are avalaible, otherwise will only use one or the other as are present in the population.data.

Details

The function checks column names and trims a data frame to only include the necessary columns. If population.data already only has the necessary columns named correctly then this function is unnecessary, but will not do any harm.

Value

Returns a dataframe with one column named id, and columns mother, father or both as appropriate.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#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

make_relation_df(test1, parents.to.use = "all.avaliable")
make_relation_df(test1, parents.to.use = "mother.only")
make_relation_df(test1, parents.to.use = "father.only")

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