Last data update: 2014.03.03

R: Joint IBD probabilities for two linked loci
twoLocusIBDR Documentation

Joint IBD probabilities for two linked loci

Description

Estimates by simulation the IBD matrix associated to a pair of non-inbred individuals at two linked loci. The entries of the matrix are the joint IBD probabilities

κ(i,j) = Pr(sharing i alleles IBD at locus 1, and j alleles IBD at locus 2).

The loci can be autosomal (in which case 0 ≤ i,j ≤ 2) or X-linked (in which case 0 ≤ i,j ≤ 2 if both individuals are female; otherwise 0 ≤ i,j ≤ 1).

Usage

twoLocusIBD(x, ind1, ind2, rho=NULL, cM=NULL, Nsim, Xchrom=FALSE, verbose=TRUE, ...)

Arguments

x

A pedigree in the form of a linkdat object.

ind1, ind2

Numeric ID labels of the two individuals.

rho

A number in the interval [0, 0.5]: the recombination fraction between the two loci. Should be NULL if cM is non-NULL.

cM

A non-negative number: the distance in centiMorgan between the two loci. Should be NULL if rho is non-NULL.

Nsim

The number of simulations to be performed.

Xchrom

A logical indicating if the markers are X-linked (if TRUE) or autosomal (FALSE).

verbose

A logical.

...

Further arguments to be passed on to IBDsim.

Details

If the recombination fraction rho is given, it is converted to centiMorgan using Haldanes map function: cM = -50*log(1-2*rho).

Value

A numerical matrix. The entry in row a and column b is the estimate of κ(a-1, b-1) defined above.

Author(s)

Magnus Dehli Vigeland

Examples


#Example 1
x <- nuclearPed(2) 
rho <- 0.1 
cM <- -50*log(1-2*rho)
Nsim <- 100 # Should be increased to at least 1000 
r1 <- twoLocusIBD(x, ind1=3, ind2=4, rho=rho, Nsim=Nsim, seed=17)
r2 <- twoLocusIBD(x, ind1=3, ind2=4, cM=cM, Nsim=Nsim, seed=17)
stopifnot(identical(r1,r2))

# X chromosome
r1 <- twoLocusIBD(x, ind1=3, ind2=4, rho=rho, Nsim=Nsim, seed=17, Xchrom=TRUE)
r2 <- twoLocusIBD(x, ind1=3, ind2=4, cM=cM, Nsim=Nsim, seed=17, Xchrom=TRUE )
stopifnot(identical(r1,r2))

# Example 2
# Autosomal testing, example p. 182-183 Egeland, Kling and Mostad(2016, Book).
# Each simulations followed by exact counterpart.
x <- addSon(addSon(nuclearPed(2,1:2), 4), 5)
plot(x)
rho <- 0.25
Nsim <- 100 # Should be increased to at least 10000
twoLocusIBD(x, 1, 6, rho=rho, Nsim=Nsim, verbose=FALSE)[2,2];.5*(1-rho)
twoLocusIBD(x, 8, 6, rho=rho, Nsim=Nsim, verbose=FALSE)[2,2];.5*(rho^2+(1-rho)^2)
twoLocusIBD(x, 3, 6, rho=rho, Nsim=Nsim, verbose=FALSE)[2,2];.5*((1-rho)*(rho^2+(1-rho)^2) + rho/2)

# Example 3
# X chromosome testing, example granddaughter vs maternal grandfather.
y <- addDaughter(nuclearPed(1, sex=2), 3)
plot(y)
rho <- 0.25
Nsim <-100
twoLocusIBD(y, 1, 5, rho=rho, Nsim=Nsim, Xchrom=TRUE)
matrix(c(1-rho, rho, rho, 1-rho)/2, ncol=2) #exact

# Example 4 
# X chromosomes can help in incest cases: Incest by brother or father?
# Could alternatively consider one marker and use IBDsim:::oneLocusIBD
x <- nuclearPed(2, sex=c(1,2))
x <- addOffspring(x, father=3, mother=4, noff=1, sex=2)
par(mfcol=c(1,2))
plot(x, title="Brother")
Nsim <- 100
r1 <- twoLocusIBD(x, ind1=2, ind2=5, rho=0.2,  Nsim=Nsim, Xchrom=TRUE)
stopifnot(r1[1,1]==0) # grand mother must share IBD 

#  Incest by father
x <- nuclearPed(1,sex=2)
x <- addOffspring(x, father=1, mother=3, noff=1, sex=2)
plot(x, title="Father")
r2 <- twoLocusIBD(x, ind1=2, ind2=4, rho=0.2,  Nsim=Nsim, Xchrom=TRUE)
stopifnot(r2[1,1]>0) # grand mother need not share IBD

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(IBDsim)
Loading required package: paramlink
Loading required package: kinship2
Loading required package: Matrix
Loading required package: quadprog
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/IBDsim/twoLocusIBD.Rd_%03d_medium.png", width=480, height=480)
> ### Name: twoLocusIBD
> ### Title: Joint IBD probabilities for two linked loci
> ### Aliases: twoLocusIBD
> ### Keywords: math
> 
> ### ** Examples
> 
> 
> #Example 1
> x <- nuclearPed(2) 
> rho <- 0.1 
> cM <- -50*log(1-2*rho)
> Nsim <- 100 # Should be increased to at least 1000 
> r1 <- twoLocusIBD(x, ind1=3, ind2=4, rho=rho, Nsim=Nsim, seed=17)
Locus distance: 11.15718 centiMorgan
---------------
Performing unconditional simulation
Mode: autosomal 
Recombination model: haldane (poisson process) 
Number of simulations: 100 
Simulation finished. Time used: 0.024 seconds
---------------
IBD analysis finished. Total time used: 0.026 seconds.
> r2 <- twoLocusIBD(x, ind1=3, ind2=4, cM=cM, Nsim=Nsim, seed=17)
Locus distance: 11.15718 centiMorgan
---------------
Performing unconditional simulation
Mode: autosomal 
Recombination model: haldane (poisson process) 
Number of simulations: 100 
Simulation finished. Time used: 0.021 seconds
---------------
IBD analysis finished. Total time used: 0.022 seconds.
> stopifnot(identical(r1,r2))
> 
> # X chromosome
> r1 <- twoLocusIBD(x, ind1=3, ind2=4, rho=rho, Nsim=Nsim, seed=17, Xchrom=TRUE)
Locus distance: 11.15718 centiMorgan
---------------
Performing unconditional simulation
Mode: X chromosome 
Recombination model: haldane (poisson process) 
Number of simulations: 100 
Simulation finished. Time used: 0.015 seconds
---------------
IBD analysis finished. Total time used: 0.015 seconds.
> r2 <- twoLocusIBD(x, ind1=3, ind2=4, cM=cM, Nsim=Nsim, seed=17, Xchrom=TRUE )
Locus distance: 11.15718 centiMorgan
---------------
Performing unconditional simulation
Mode: X chromosome 
Recombination model: haldane (poisson process) 
Number of simulations: 100 
Simulation finished. Time used: 0.024 seconds
---------------
IBD analysis finished. Total time used: 0.025 seconds.
> stopifnot(identical(r1,r2))
> 
> # Example 2
> # Autosomal testing, example p. 182-183 Egeland, Kling and Mostad(2016, Book).
> # Each simulations followed by exact counterpart.
> x <- addSon(addSon(nuclearPed(2,1:2), 4), 5)
Father: Creating new individual with ID 5 
Mother: Creating new individual with ID 7 
> plot(x)
> rho <- 0.25
> Nsim <- 100 # Should be increased to at least 10000
> twoLocusIBD(x, 1, 6, rho=rho, Nsim=Nsim, verbose=FALSE)[2,2];.5*(1-rho)
[1] 0.46
[1] 0.375
> twoLocusIBD(x, 8, 6, rho=rho, Nsim=Nsim, verbose=FALSE)[2,2];.5*(rho^2+(1-rho)^2)
[1] 0.41
[1] 0.3125
> twoLocusIBD(x, 3, 6, rho=rho, Nsim=Nsim, verbose=FALSE)[2,2];.5*((1-rho)*(rho^2+(1-rho)^2) + rho/2)
[1] 0.35
[1] 0.296875
> 
> # Example 3
> # X chromosome testing, example granddaughter vs maternal grandfather.
> y <- addDaughter(nuclearPed(1, sex=2), 3)
Father: Creating new individual with ID 4 
> plot(y)
> rho <- 0.25
> Nsim <-100
> twoLocusIBD(y, 1, 5, rho=rho, Nsim=Nsim, Xchrom=TRUE)
Locus distance: 34.65736 centiMorgan
---------------
Performing unconditional simulation
Mode: X chromosome 
Recombination model: haldane (poisson process) 
Number of simulations: 100 
Simulation finished. Time used: 0.018 seconds
---------------
IBD analysis finished. Total time used: 0.019 seconds.
     ibd0 ibd1
ibd0 0.34 0.14
ibd1 0.12 0.40
> matrix(c(1-rho, rho, rho, 1-rho)/2, ncol=2) #exact
      [,1]  [,2]
[1,] 0.375 0.125
[2,] 0.125 0.375
> 
> # Example 4 
> # X chromosomes can help in incest cases: Incest by brother or father?
> # Could alternatively consider one marker and use IBDsim:::oneLocusIBD
> x <- nuclearPed(2, sex=c(1,2))
> x <- addOffspring(x, father=3, mother=4, noff=1, sex=2)
> par(mfcol=c(1,2))
> plot(x, title="Brother")
> Nsim <- 100
> r1 <- twoLocusIBD(x, ind1=2, ind2=5, rho=0.2,  Nsim=Nsim, Xchrom=TRUE)
Locus distance: 25.54128 centiMorgan
---------------
Performing unconditional simulation
Mode: X chromosome 
Recombination model: haldane (poisson process) 
Number of simulations: 100 
Simulation finished. Time used: 0.024 seconds
---------------
IBD analysis finished. Total time used: 0.026 seconds.
> stopifnot(r1[1,1]==0) # grand mother must share IBD 
> 
> #  Incest by father
> x <- nuclearPed(1,sex=2)
> x <- addOffspring(x, father=1, mother=3, noff=1, sex=2)
> plot(x, title="Father")
> r2 <- twoLocusIBD(x, ind1=2, ind2=4, rho=0.2,  Nsim=Nsim, Xchrom=TRUE)
Locus distance: 25.54128 centiMorgan
---------------
Performing unconditional simulation
Mode: X chromosome 
Recombination model: haldane (poisson process) 
Number of simulations: 100 
Simulation finished. Time used: 0.016 seconds
---------------
IBD analysis finished. Total time used: 0.019 seconds.
> stopifnot(r2[1,1]>0) # grand mother need not share IBD
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>