# open an example dataset (HapMap)
genofile <- snpgdsOpen(snpgdsExampleFileName())
# CEU population
samp.id <- read.gdsn(index.gdsn(genofile, "sample.id"))
CEU.id <- samp.id[
read.gdsn(index.gdsn(genofile, "sample.annot/pop.group"))=="CEU"]
#### KING-robust:
#### relationship inference in the presence of population stratification
#### robust relationship inference across family
ibd.robust <- snpgdsIBDKING(genofile, sample.id=CEU.id, family.id=NULL)
names(ibd.robust)
# [1] "sample.id" "snp.id" "afreq" "IBS0" "kinship"
# select a set of pairs of individuals
dat <- snpgdsIBDSelection(ibd.robust, 1/32)
head(dat)
plot(dat$IBS0, dat$kinship, xlab="Proportion of Zero IBS",
ylab="Estimated Kinship Coefficient (KING-robust)")
#### KING-robust:
#### relationship inference in the presence of population stratification
#### within- and between-family relationship inference
# incorporate with pedigree information
family.id <- read.gdsn(index.gdsn(genofile, "sample.annot/family.id"))
family.id <- family.id[match(CEU.id, samp.id)]
ibd.robust2 <- snpgdsIBDKING(genofile, sample.id=CEU.id, family.id=family.id)
names(ibd.robust2)
# select a set of pairs of individuals
dat <- snpgdsIBDSelection(ibd.robust2, 1/32)
head(dat)
plot(dat$IBS0, dat$kinship, xlab="Proportion of Zero IBS",
ylab="Estimated Kinship Coefficient (KING-robust)")
#### KING-homo: relationship inference in a homogeneous population
ibd.homo <- snpgdsIBDKING(genofile, sample.id=CEU.id, type="KING-homo")
names(ibd.homo)
# "sample.id" "snp.id" "afreq" "k0" "k1"
# select a subset of pairs of individuals
dat <- snpgdsIBDSelection(ibd.homo, 1/32)
head(dat)
plot(dat$k0, dat$kinship, xlab="Pr(IBD=0)",
ylab="Estimated Kinship Coefficient (KING-homo)")
# close the genotype file
snpgdsClose(genofile)
Run the code above in your browser using DataLab