R: Describe the joint likelihood surface of ancestry and...
HIsurf
R Documentation
Describe the joint likelihood surface of ancestry and heterozygosity for a hybrid genotype.
Description
HIsurf calculates the log likelihood of points on a bivariate grid to describe the joint likelihood surface of ancestry and interclass heterozygosity for a genotype given parental allele frequencies.
Usage
HIsurf(G, P, type, size)
Arguments
G
An individual diploid genotype as matrix G. If type == "codominant", G must be a two-row matrix with one column for each locus, as in STRUCTURE
(http://pritch.bsd.uchicago.edu/structure.html). If type == "dominant", G is a vector of 0,1 for absence,presence of the dominant allele. If type == "allele.count", G must be a vector of genotypes coded as 0,1,2 for the number of "j" alleles. That is, genotype 2 is homozygous for allele j, genotype 1 is heterozygous, and genotype 0 has no j alleles.
P
Parental allele frequencies. A matrix or data frame with the following columns (order is important!): Locus name, Allele name, P1 allele frequency, P2 allele frequency. For type="dominant" or type="allele.count", there should be one row per locus, giving the frequencies of the dominant or "1" allele. For type="codominant" there should be a separate row for each allele AND the Allele names should match the data in G.
type
A string representing the data type. The options are "codominant", "dominant", and "allele.count".
size
An integer giving the desired number of gridlines in each direction. The function will calculate the likelihood for all (size^2)/2 combinations of S and H that fall within the triangular sample space.
Details
Given two ancestral species or parental populations (P1 and P2), the ancestry index (S) is the proportion of an individual's alleles descending from alleles in the P1 population and the interclass heterozygosity (H) is the proportion of an individual's loci that have one allele from each ancestral population (Lynch 1991). The likelihood functions are described in Fitzpatrick (2012).
Value
A size x size matrix of log likelihoods for all combinations of ancestry (S) and interclass heterozygosity (H). Rows correspond to the size values of S, and columns the size values of H. For impossible combinations (H > min(2*S,2-2*S)), NA's are returned.
Author(s)
Ben Fitzpatrick
References
Fitzpatrick, B. M. 2008. Hybrid dysfunction: Population genetic and quantitative genetic perspectives. American Naturalist 171:491-198.
Fitzpatrick, B. M. 2012. Estimating ancestry and heterozygosity of hybrids using molecular markers. BMC Evolutionary Biology 12:131. http://www.biomedcentral.com/1471-2148/12/131
Lynch, M. 1991. The genetic interpretation of inbreeding depression and outbreeding depression. Evolution 45:622-629.
See Also
HIest for maximum likelihood estimation of S and H, HIclass for likelihoods of early generation hybrid classes, HItest to compare the classification to the maximum likelihood, HILL for the basic likelihood function.
Examples
data(Bluestone)
Bluestone <- replace(Bluestone,is.na(Bluestone),-9)
# parental allele frequencies (assumed diagnostic)
BS.P <- data.frame(Locus=names(Bluestone),Allele="BTS",P1=1,P2=0)
# a small surface to view in the console
BS.surf.5 <- HIsurf(Bluestone[21,],BS.P,type="allele.count",size=5)
BS.surf.5 # the maximum likelihood is very near the center (S ~ H ~ 0.5)
# # a more finely sampled surface to visualize with image
# BS.surf <- HIsurf(Bluestone[21,],BS.P,type="allele.count",size=99)
# image(-BS.surf,col=gray(seq(from=0,to=1,length.out=6)),
# breaks=seq(from=min(-BS.surf,na.rm=TRUE),by=2,length.out=7),
# cex.axis=1.5,bty="n",xaxs="r",yaxs="r")
# # the breaks option is set so that each level of shading corresponds to 2 log-likelihood
# # units (for one unit increments, set by=1).
# # now make it pretty:
# image(is.na(BS.surf),col="light blue",breaks=c(.5,1),add=TRUE)
# axis(1,labels=FALSE,lwd=2); axis(2,labels=FALSE,lwd=2)
# title(xlab=expression(italic(S)),ylab=expression(italic(H[I])),cex.lab=1.5)
# lines(c(0,.5,1,0),c(0,1,0,0),lty=2,lwd=2)
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(HIest)
Loading required package: nnet
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/HIest/HIsurf.Rd_%03d_medium.png", width=480, height=480)
> ### Name: HIsurf
> ### Title: Describe the joint likelihood surface of ancestry and
> ### heterozygosity for a hybrid genotype.
> ### Aliases: HIsurf
> ### Keywords: ~kwd1 ~kwd2
>
> ### ** Examples
>
> data(Bluestone)
> Bluestone <- replace(Bluestone,is.na(Bluestone),-9)
> # parental allele frequencies (assumed diagnostic)
> BS.P <- data.frame(Locus=names(Bluestone),Allele="BTS",P1=1,P2=0)
>
> # a small surface to view in the console
> BS.surf.5 <- HIsurf(Bluestone[21,],BS.P,type="allele.count",size=5)
> BS.surf.5 # the maximum likelihood is very near the center (S ~ H ~ 0.5)
[,1] [,2] [,3] [,4] [,5]
[1,] -9823.204 NA NA NA NA
[2,] -7139.927 -73.41647 -2741.03304 NA NA
[3,] -7147.694 -72.56990 -65.84898 -76.96435 -8122.803
[4,] -7166.826 -91.12029 -5448.01120 NA NA
[5,] -12565.207 NA NA NA NA
>
> # # a more finely sampled surface to visualize with image
> # BS.surf <- HIsurf(Bluestone[21,],BS.P,type="allele.count",size=99)
>
> # image(-BS.surf,col=gray(seq(from=0,to=1,length.out=6)),
> # breaks=seq(from=min(-BS.surf,na.rm=TRUE),by=2,length.out=7),
> # cex.axis=1.5,bty="n",xaxs="r",yaxs="r")
> # # the breaks option is set so that each level of shading corresponds to 2 log-likelihood
> # # units (for one unit increments, set by=1).
> # # now make it pretty:
> # image(is.na(BS.surf),col="light blue",breaks=c(.5,1),add=TRUE)
> # axis(1,labels=FALSE,lwd=2); axis(2,labels=FALSE,lwd=2)
> # title(xlab=expression(italic(S)),ylab=expression(italic(H[I])),cex.lab=1.5)
> # lines(c(0,.5,1,0),c(0,1,0,0),lty=2,lwd=2)
>
>
>
>
>
>
> dev.off()
null device
1
>