\name{hadamard}
\alias{hadamard}
\alias{fhm}
\alias{h4st}
\alias{h2st}
\title{Hadamard Matrices and Fast Hadamard Multiplication}
\description{
A collection of functions to perform Hadamard conjugation. 
%Hv of a Hadamard matrix H with a vector v using fast Hadamard multiplication.
}
\usage{
hadamard(x)
fhm(v)
h2st(obj, eps=0.001)
h4st(obj, levels = c("a","c","g","t"))
}
\arguments{
  \item{x}{ a vector of length \eqn{2^n}, where n is an integer. }
  \item{v}{ a vector of length \eqn{2^n}, where n is an integer. }
  \item{obj}{ a data.frame or character matrix, typical a sequence alignment.}
  \item{eps}{Threshold value for splits.}
  \item{levels}{ levels of the sequences.}
}

\details{
\code{h2st} and \code{h4st} perform Hadamard conjugation 
for 2-state (binary, RY-coded) or 4-state (DNA/RNA) data.
\code{write.nexus.splits} writes splits returned from  \code{h2st} or  
\code{\link[phangorn]{distanceHadamard}} to a nexus file, which can be processed by 
Spectronet or Splitstree.
}

\value{
\code{hadamard} returns a Hadamard matrix. \code{fhm} returns the 
fast Hadamard multiplication. 
}
\references{Hendy, M.D. (1989). The relationship between simple evolutionary tree
models and observable sequence data. \emph{Systematic Zoology}, \bold{38} 310--321.

Hendy, M. D. and Penny, D. (1993). Spectral Analysis of Phylogenetic
Data. \emph{Journal of Classification}, \bold{10}, 5--24.

Hendy, M. D. (2005). Hadamard conjugation: an analytical tool for phylogenetics.
In O. Gascuel, editor, \emph{Mathematics of evolution and phylogeny}, Oxford University Press, Oxford

Waddell P. J. (1995). Statistical methods of phylogenetic analysis: Including hadamard conjugation, 
LogDet transforms, and maximum likelihood. \emph{PhD thesis}.
}
\author{Klaus Schliep \email{klaus.schliep@gmail.com}}
\seealso{\code{\link{distanceHadamard}}, \code{\link{lento}}, \code{\link{plot.networx}}}

\examples{
H = hadamard(3)
v = 1:8
H%*%v
fhm(v)

data(yeast)
dat = as.character(yeast)
# RY-coding
dat2 = dat
dat2[dat=="a" | dat=="g"] = "r"
dat2[dat=="c" | dat=="t"] = "y"
dat2 = phyDat(dat2, type="USER", levels=c("r","y"), ambiguity=NULL)
fit2 = h2st(dat2)
lento(fit2)

# write.nexus.splits(fit2, file = "test.nxs")
# read this file into Spectronet or Splitstree to show the network
\dontrun{
dat4 = phyDat(dat, type="USER", levels=c("a","c", "g", "t"), ambiguity=NULL)
fit4 = h4st(dat4)

par(mfrow=c(3,1))
lento(fit4[[1]], main="Transversion")
lento(fit4[[2]], main="Transition 1")
lento(fit4[[3]], main="Transition 2")
}
}
\keyword{ cluster }% at least one, from doc/KEYWORDS

