\HeaderA{LD}{Pairwise linkage disequilibrium between genetic markers.}{LD}
\aliasA{LDband}{LD}{LDband}
\methaliasA{LDband.geneSet}{LD}{LDband.geneSet}
\aliasA{LDdist}{LD}{LDdist}
\methaliasA{LDdist.geneSet}{LD}{LDdist.geneSet}
\aliasA{summary.LD}{LD}{summary.LD}
\keyword{misc}{LD}
\begin{Description}\relax
Compute pairwise linkage disequilibrium between genetic markers
\end{Description}
\begin{Usage}
\begin{verbatim}
LD(object, pooling.threshold = 0.1, founderOnly = FALSE, quiet = TRUE )
LDband(object, width=31,pooling.threshold=0.1, founderOnly=FALSE, quiet=TRUE)
LDband.geneSet(object,width=31,pooling.threshold=0.1, founderOnly=FALSE, quiet=TRUE)
LDdist.geneSet(object,posVec, maxDist, pooling.threshold=0.1, founderOnly=FALSE, quiet=TRUE)

summary.LD(object, 
           which = c("D", "D'", "r", "R^2", "X^2", "P-value", "LOD", "n"), 
           rowsep, 
           digits = 3, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{object}] geneSet object 
\item[\code{width}] window width 
\item[\code{posVec}] marker position
\item[\code{maxDist}] size of the window based on distance
\item[\code{pooling.threshold}] Threshold for LD calculation
\item[\code{which}] character string indicates which LD statistic should be print out 
\item[\code{rowsep}] separator for rows 
\item[\code{digits}] the desired number of digits after the decimal point  
\item[\code{founderOnly}] Indicates if only founders are used to do the test.
\item[\code{quiet}] Indicates if intermediate results should be output
\item[\code{...}] additional optional arguments
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Linkage disequilibrium (LD) is the non-random association of
marker alleles and can arise from marker proximity or from selection
bias.

\code{LD} estimates the extent of LD for all pairs of
genotypes contained in a \code{object}.  \code{LDband} computes the
extent of LD of markers within a window containing
\code{width} markers centered around each marker in \code{object}.

The current (temporary) code only computes LD for markers with exactly
2 variants.  For other markers, \code{NA} is returned. 

Three estimators of LD are computed:
\Itemize{

\item[D] raw difference in frequency between the
observed number of AB pairs and the expected number:

\deqn{
D = p_{AB} - p_A p_B 
}{D = p(AB) - p(A)*p(B) 
}


\item[D'] scaled D spanning the range [-1,1] 


\deqn{D' = \frac{D}{D_{max} } }{D' = D / Dmax}

where, if D > 0:
\deqn{
D_{max} = \min( p_A p_b, p_a p_B )  
}{Dmax = min( p(A)p(b), p(a)p(B) )   
} 
or if D < 0:
\deqn{
D_{max} = \max{ -p_A p_B, -p_a p_b }  
}{Dmax = max( -p(A)p(B), -p(a)p(b) )  
}


\item[r] correlation coefficient between the markers

\deqn{
r = \frac{-D}{\sqrt( p_A * p_a * p_B * p_b  )} 
}{r = -D / sqrt( p(A) * p(a) * p(B) * p(b) ) 
}

}

where
\Itemize{
\item[-] \eqn{p_A}{p(A)} is defined as the observed probability of
allele 'A' for marker 1, 
\item[-] \eqn{p_a=1-p_A}{p(a) = 1-p(A)} is defined as the observed probability of
allele 'a' for marker 1, 
\item[-] \eqn{p_B}{p(B)} is defined as the observed probability of
allele 'B' for marker 2, and 
\item[-] \eqn{p_b=1-p_B}{p(b) = 1- p(B)} is defined as the observed probability of
allele 'b' for marker 2, and 
\item[-] \eqn{p_{AB}}{p(AB)} is defined as the probability of
the marker allele pair 'AB'. 
}

For genotype data, AB/ab cannot be distinguished from
aB/Ab. Consequently, we estimate \eqn{p_{AB}}{p(AB)} using maximum
likelihood and use this value in the computations.
\end{Details}
\begin{Value}
\code{LD} returns an object of class \code{LD}, while \code{LDband}
and \code{LDdist} return objects of classes \code{LDband} and \code{LDdist}, 
respectively.  All classes contain these
slots:

\begin{ldescription}
\item[\code{call}] the matched call
\item[\code{D}] Linkage disequilibrium estimate
\item[\code{Dprime }] Scaled linkage disequilibrium estimate
\item[\code{corr}] Correlation coefficient
\item[\code{nobs}] Number of observations
\item[\code{chisq}] Chi-square statistic for linkage
equilibrium (i.e., D=D'=corr=0)
\item[\code{p.value}] Chi-square p-value for marker independence
\item[\code{LOD}] LOD scores
\item[\code{tab}] Description of 'tab'
\item[\code{statlist}] Description of 'statlist'
\item[\code{which}] Description of 'which'
\item[\code{object}] Description of 'object'
\end{ldescription}
\end{Value}
\begin{Author}\relax
Gregory R. Warnes \email{warnes@bst.rochester.edu}
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{geneSet-class}{geneSet.Rdash.class}}, \code{\LinkA{diseq}{diseq}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

data(CAMP)

ld <- LD(CAMP)
print(ld)

ldb <- LDband(CAMP)
print(ldb)

ldd <- LDdist(CAMP, posVec=1:8, maxDist=3)
print(ldd)

\end{ExampleCode}
\end{Examples}

