{smcl}
{hline}
help for {hi:hapipf}  {right: (TSJ-1: st0003)}
{hline}


{title:Haplotype frequency using an EM algorithm and log-linear modelling}

{p 8 24}
{cmdab:hapipf}
{it:varlist} [{cmd:using} {it:exp}] 
[{cmd:,}
[
{cmd:ldim}{cmd:(}{it:varlist}{cmd:)}
{cmdab:dis:play} 
{cmd:ipf}{cmd:(}{it:string}{cmd:)}
{cmd:start}
{cmd:known} 
{cmd:phase}{cmd:(}{it:varname}{cmd:)} 
{cmd:acc}{cmd:(}{it:#}{cmd:)} 
{cmd:ipfacc}{cmd:(}{it:#}{cmd:)} 
{cmd:nolog}
{cmd:model}{cmd:(}{it:#}{cmd:)}
{cmd:lrtest}{cmd:(}{it:#,#}{cmd:)} 
{cmd:convars}{cmd:(}{it:string}{cmd:)}
{cmd:confile}{cmd:(}{it:string}{cmd:)} 
{cmd:menu}
{cmd:mv} 
{cmd:mvdel} 
]



{title:Description}

{p 0 0}
This function calculates allele/haplotype frequencies using log-linear 
modeling embedded within an EM algorithm. The EM algorithm handles the phase 
uncertainty and the log-linear modeling allows testing for linkage 
disequilibrium and disease association. These tests can be controlled
for confounders using a stratified analysis specified by the log-linear model. 
The log-linear model can also model the relationship between loci, and hence 
can group similar haplotypes.

{p 0 0}
The log-linear model is fitted using iterative proportional fitting which is 
implemented in the STB command {hi:ipf.ado}  (the user will have to install this
function first). This algorithm can handle very large contingency tables and 
converges to maximum likelihood estimates even when the likelihood is badly 
behaved.

{p 0 0}
The {hi:varlist} consists of paired variables representing the alleles at each 
locus. If phase is known then the pairs are the genotypes. When phase is 
unknown the algorithm assumes Hardy Weinberg Equilibrium
so that models are based on chromosomal data and not genotypic data.

{p 0 0}
This algorithm can handle missing alleles at the loci by using the {hi:mv} option.


{title:Options}

{p 0 4}
{cmd:menu} specifies that the syntax is specified using a window interface.

{p 0 4}
{cmd:mv} specifies that the algorithm should replace missing data (".") with a
copy of each of the possible alleles at this locus. This is performed at the
same stage as the handling of the missing phase when the dataset is expanded
into all possible observations. If this option is not specified but some of
the alleles do contain missing data the algorithm sees the symbol "." as
another allele.

{p 0 4}
{cmd:mvdel} specifies that people with missing alleles are deleted.

{p 0 4}
{cmd:ldim(}{it:varlist}{cmd:)} specifies the variables that determine the
dimension of the contingency table. By default the variables contained in the
{hi:ipf()} option define the dimension.

{p 0 4}
{cmd:ipf(}{it:string}{cmd:)} specifies the log-linear model. It requires
special syntax of the form {hi:l1*l2+l3}. {hi:l1*l2} allows all the
interactions between the first two loci and locus 3 is independent of them.
This syntax is used in most books on Log-linear modelling.

{p 0 4}
{cmd:start} specifies that the starting posterior weights of the EM algorithm
are chosen at random.

{p 0 4}
{cmd:display} specifies whether the expected and imputed haplotype frequencies
are shown on the screen.

{p 0 4}
{cmd:known} specifies that phase is known.

{p 0 4}
{cmd:phase(}{it:varname}{cmd:)} specifies a variable that contains 1's where
phase is known and 0's where phase is unknown.

{p 0 4}
{cmd:acc(}{it:real}{cmd:)} specifies the convergence threshold of the change
of the full log-likelihood.

{p 0 4}
{cmd:ipfacc(}{it:real}{cmd:)} specifies the convergence theshold of the change
in the log-likelihood of the log-linear model.

{p 0 4}
{cmd:nolog} specifies whether the log-likelihood is displayed at each iteration.

{p 0 4}
{cmd:model(}{it:#}{cmd:)} specifies a label for the log-linear model being
fitted. This label is used in the lrtest() option.

{p 0 4}
{cmdab:lrtest}{cmd:(}{it:#,#}{cmd:)} performs a likelihood ratio test using
two models that have been labelled in the {hi:model()} option.

{p 0 4}
{cmd:convars(}{it:string}{cmd:)} specifies a list of variables in the
constraints file.

{p 0 4}
{cmd:confile(}{it:string}{cmd:)} specifies the name of the constraints file.


{title:Examples}

Take a dataset with 3 loci, the pairs of alleles at locus 1 are the variables
ass1 and ass2, the pairs of alleles at locus 2 are the variables
bss1 and bss2 and the pairs of alleles at locus 3 are the variables
drss1 and drss2. Note the {hi:ipf()} option requires the log-linear model that 
contains lj terms which represent locus j. 

The indicator variable for whether a person
is a case or control is caco. To test whether the haplotypes are associated
with disease is the likelihood ratio test comparing the models 
l1*l2*l3*caco and l1*l2*l3+caco. The following stata commands perform this
test.

{p 4 4}
   {inp:. hapipf ass1 ass2 bss1 bss2 drss1 drss2, ipf(l1*l2*l3*caco) model(0) display}

{p 4 4}
   {inp:. hapipf ass1 ass2 bss1 bss2 drss1 drss2, ipf(l1*l2*l3+caco) model(1) lrtest(0,1) display}


{title:Author}

Adrian Mander, MRC Biostatistics Unit, Forvie Site, Addenbrookes, Cambridge,UK.

Click here to see Adrian Mander's {browse "http://www.mrc-bsu.cam.ac.uk/personal/adrian":web site}
Email {browse "mailto:adrian.mander@mrc-bsu.cam.ac.uk":adrian.mander@mrc-bsu.cam.ac.uk}


{title:Also see}

{p 0 19}
On-line:{space 2}help for {help qhapipf} (if installed), {help profhap} (if installed), {help ipf} (if installed). 
