\name{ap.ttest}
\alias{ap.ttest}
\title{ adaptive permutation t-test }
\description{
  adaptive permutation t-test
}
\usage{
ap.ttest(me, mm, np.max = 5e+05, np = c(100, 1000, 5000, 10000, 50000, 1e+05),
  aim.p = c(0.1, 0.05, 0.02, 0.01, 0.002, 0.001), confidence.p = 1e-04, 
  var.equal = FALSE, min.obs=10)
}
\arguments{
  \item{me}{ matrix of gene expression, each row corresponds to one gene }
  \item{mm}{ matrix of marker genotype, each row corresponds to one marker}
  \item{np.max}{ the maximum number of permutations }
  \item{np}{ number of permutations, a vector in ascending order }
  \item{aim.p}{ the permutation p-values to estimate, corresponding to the number of permutations in \code{np} }
  \item{confidence.p}{ given np[i], aim.p[i], confidence p-value is a binomial p-value determining   
    whether more permutations are needed for one gene expression trait }
  \item{var.equal}{ a logical variable indicating whether to treat the two variances as being equal. 
  If TRUE then the pooled variance is used to estimate the variance otherwise the Welch 
  (or Satterthwaite) approximation to the degrees of freedom is used. }
  \item{min.obs}{ minimum number of observations in each group for ttest }
}
\details{
  Given, np[i], aim.p[i], confidence.p, the cutoff c = qbinom(1-confidence.p, np[i], aim.p[i]). 
  If for one gene, there are more than c permutations where more extreme p-values are observed, 
  we do not perform more permutaions for this gene.  
}
\value{
  a list
  \item{nominal.p }{nominal p-value for each gene expression trait}
  \item{permute.p }{ permutation p-value for each gene expresison trait}
  \item{n.permute.p }{ number of permutations performed for each gene expression trait}
}
\author{ Wei Sun wsun@bios.unc.edu }
\keyword{ methods }
