Load Environment

# clean
rm(list = ls(all=TRUE))

# load
library(ElstonStewart)

Example using the ElstonStewart R-Packages and “conrad2” data set

  • This family has many generations, inbreeding and loops
    • The Elston-Stewart algorithm does not work well in pedigrees with loops/inbreeding
    • Packages like the ElstonStewart or pedprobr/pedtools R-Package can deal with such complex pedigrees

Load the conrad2 data

## cf Elston-Stewart vignette for more comments on this example
data(conrad2)

Add the genotype information for each family member

# creating an es.pedigree object
conrad.genotypes <-rep(
  list(
    0:2
  ), 22
)
conrad.genotypes[[1]]=2
conrad.genotypes[[22]]=2

We will make a phenotype list

# get phenotypes
conrad.phenotypes=rep(
  0,
  22
)

Make the pedigree object

# make es.pedigree object for Elston-Stewart
X <- es.pedigree( 
  id = conrad2$id,
  father = conrad2$father,
  mother = conrad2$mother, 
  sex = conrad2$sex,
  pheno = conrad.phenotypes,
  geno = conrad.genotypes
)
plot.es.pedigree(X)

Run the Elston-Stewart algorithm using the basic di allelic model provided in the ElstonStewart R-Package

# input theta
theta=list(p=0.9)

# running Elston-Stewart
r <- Elston(
  ped = X,
  modele = modele.di,
  theta = theta
)
r$result
## [1] 0.0002160156

Summary of what we learned

First, we’ll write a function to get founder probabilities

get.founder.probabilities.from.afreq=function(
  g,
  theta
) 
{
  if(g == 0)
    {
        return(theta$p^2)
    } 
  if(g == 1)
    {
      return(2 * theta$p * (1 - theta$p))
    } 
  if(g == 2)
    {
      return((1 - theta$p)^2)
    }
    stop("Unknown Genotype")
}

Make fuction to get the probability of the phenotypes given a genotype

## Make function to get penetrance probabilities based on an exponential function (will use in the future)
get.phenotype.genotype.probabilities=function(
  x,
  g,
  theta
)
{
  # get phenotype information
  phenotype.event=x[1]
  phenotype.time=x[2]
  
  # get probability of phenotype
  if(g==0)
  {
      if(phenotype.event==1)
    {
      p=dexp(
        x=phenotype.time,
        rate = 0.1
      )
    } else if(phenotype.event==0)
    {
      p=pexp(
        q=phenotype.time,
        rate = 0.1,
        lower.tail = FALSE
      )
    } else
      {
        warning('invalid phenotype/genotype')
      }
  } else if(g==1 | g==2)
  {
    # get probability
    if(phenotype.event==1)
    {
      p=dexp(
        x=phenotype.time,
        rate = 0.025
      )
    } else if(phenotype.event==0)
    {
      p=pexp(
        q=phenotype.time,
        rate = 0.025,
        lower.tail = FALSE
      )
    } else
      {
        warning('invalid phenotype/genotype')
      }
  }
  return(p)
}

Make function to get transmission probabilities

get.transmission.probabilities=function(
  of,
  fa,
  mo
) 
{
    if (fa == 0) 
    {
        if (mo == 0 & of == 0) 
            return(1)
        if (mo == 1 & (of == 0 | of == 1)) 
            return(0.5)
        if (mo == 2 & of == 1) 
            return(1)
    }
    if (fa == 1) 
    {
        if (mo == 0 & (of == 0 | of == 1)) 
            return(0.5)
        if (mo == 1 & (of == 0 | of == 2)) 
            return(0.25)
        if (mo == 1 & of == 1) 
            return(0.5)
        if (mo == 2 & (of == 1 | of == 2)) 
            return(0.5)
    }
    if (fa == 2) 
    {
        if (mo == 0 & of == 1) 
            return(1)
        if (mo == 1 & (of == 1 | of == 2)) 
            return(0.5)
        if (mo == 2 & of == 2) 
            return(1)
    }
    return(0)
}

Make a new modele object for ElstonStewart R-Package

new.modele = list(
  'name' = 'CCVR.Modele',
  'proba.g' = get.founder.probabilities.from.afreq,
  'trans' = get.transmission.probabilities,
  'p.pheno' = get.phenotype.genotype.probabilities
)

Make the phenotype information appropriate for our model

# give phenotype with events to many family members
conrad.phenotypes = rep(
  list(c(0,60)), 
  22
)
conrad.phenotypes[[22]]=c(1,35)

Run the Elston-Stewart algorithm using the ElstonStewart R-Package with our custom model

# make es.pedigree object for Elston-Stewart
Our.Pedigree <- es.pedigree( 
  id = conrad2$id,
  father = conrad2$father,
  mother = conrad2$mother, 
  sex = conrad2$sex, 
  pheno = conrad.phenotypes, 
  geno = conrad.genotypes 
)

# running Elston-Stewart
r <- Elston(
  ped = Our.Pedigree,
  modele = new.modele,
  theta = theta
)
r$result
## [1] 7.523996e-25

Make example where many family members have early events

# make most famly members have genotype 1 or 2
conrad.genotypes=rep(
  list(1:2),
  22
)
conrad.genotypes[[22]]=2

# give phenotype with events to many family members
conrad.phenotypes = rep(
  list(c(1,40)), 
  22
)
conrad.phenotypes[[22]]=c(0, 25)

Run our modele again

# make es.pedigree object for Elston-Stewart
Our.Pedigree <- es.pedigree( 
  id = conrad2$id,
  father = conrad2$father,
  mother = conrad2$mother, 
  sex = conrad2$sex, 
  pheno = conrad.phenotypes, 
  geno = conrad.genotypes 
)

# running Elston-Stewart
r <- Elston(
  ped = Our.Pedigree,
  modele = new.modele,
  theta = theta
)
r$result
## [1] 3.422755e-51

Final summary/thoughts