Error in kinship2 creating of pedigree object

梦想与她 提交于 2020-06-01 05:04:13

问题


I am trying to plot very simple pedigrees with kinship2. I only have one generations but lots of different families.

id <- sample(1:100, 50, replace=F)
dadid <- sample(100:110, 50, replace=T)
momid <- sample(111:121, 50, replace=T)
sex <- sample(1:3, 50, replace=T)

df <- data.frame(cbind(dadid, momid, id, sex))

df<- df %>% mutate(famid = group_indices(., momid, dadid))

When I try and convert my data into a pedigree() object:

pedAll <- pedigree(
  id = id, 
  dadid = dadid, 
  momid = momid,
  sex = sex, 
  famid = famid)

I get the following error:

Error in pedigree(id = id, dadid = dadid, momid = momid, sex = sex, famid = famid) : 
  Value of 'dadid' not found in the id list 1/101 5/100 5/103 11/103 11/107

Any ideas why? I have been doing round in circles for ages and there is not much out there using this package.


回答1:


I just started to learn how to use this library some days ago. In your dataframe you need to have a row for each individual present (mother and father included) with either both parents specified or none. You can either adding them by hand or use the function fixParent() of kinship2. This function will add the missing parents, fix genders problems and add second parents for children for whom only one parent id is given.

df_fixed <- with(df,fixParents(
  id = id, 
  dadid = dadid, 
  momid = momid,
  sex = sex))

This new dataframe can then be use to create your pedigree.

pedAll <- with(df_fixed,pedigree(
  id = id, 
  dadid = dadid, 
  momid = momid,
  sex = sex))
plot(pedAll)

However I don't quite understand what you want to do with the 'mutate' function. If you subdivide your dataframe in family, be sure that every individual inside each family has its own row (that doesn't seems to be the case with your code).



来源:https://stackoverflow.com/questions/61900004/error-in-kinship2-creating-of-pedigree-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!