\HeaderA{twilight}{Estimation of local false discovery rate}{twilight}
\keyword{nonparametric}{twilight}
\begin{Description}\relax
The function performs the successive exclusion procedure (SEP) as described in Scheid and Spang (2004).
\end{Description}
\begin{Usage}
\begin{verbatim}
twilight(xin, lambda = NULL, B = 0, boot.ci = 0.95, clus = NULL, verbose = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{xin}] Numerical vector of \eqn{p}{}-values or a \code{twilight} object. 
\item[\code{lambda}] Numerical value denoting the penalty factor. If not specified, the function searchs for an appropriate regularization parameter. 
\item[\code{B}] Numerical value specifying the number of bootstrap samples. If not specified, no bootstrap estimates are calculated. 
\item[\code{boot.ci}] Numerical value denoting the probability value for bootstrap confidence intervals of local false discovery rate and prior pi0. 
\item[\code{clus}] A list or numerical value to be passed to \code{makeCluster(clus,...)} in \code{library(snow)}. If specified, bootstrapping is performed in parallel. No checks on \code{clus} are performed. Please make sure that \code{makeCluster(clus)} works properly in your environment. 
\item[\code{verbose}] Logical value for message printing. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
See vignette.
\end{Details}
\begin{Value}
Returns a \code{twilight} object consisting of a \code{data.frame} named \code{result} with variables
\begin{ldescription}
\item[\code{pvalue}] Sorted input vector.
\item[\code{qvalue}] \eqn{q}{}-values computed as described in Storey and Tibshirani (2003) with new estimate \code{pi0}.
\item[\code{index}] Index of the original ordering.
\item[\code{fdr}] Local false discovery rate averaged over 10 runs of SEP.
\item[\code{mean.fdr}] Bootstrap estimate of local false discovery rate.
\item[\code{lower.fdr}] Lower \code{boot.ci}-bootstrap confidence bound.
\item[\code{upper.fdr}] Upper \code{boot.ci}-bootstrap confidence bound.
\end{ldescription}

Values are sorted by \code{pvalue}.
\end{Value}
\begin{Note}\relax
Additional output consists of

\Tabular{ll}{
\code{lambda} & Regularization parameter. \\
\code{pi0} & SEP estimate of prior probability. \\
\code{boot.pi0} & Bootstrap estimate and \code{boot.ci}-bootstrap confidence bounds. \\
\code{boot.ci} & Passes \code{boot.ci} for plotting. \\
\code{effect} & Histogram of effect size distributions averaged over 10 runs of SEP. \\
}

If \code{xin} is of class \code{twilight}, the remaining slots are filled with corresponding input values. If \code{xin} is not of class \code{twilight}, these slots remain free.
\end{Note}
\begin{Author}\relax
Stefanie Scheid \url{http://www.molgen.mpg.de/~scheid}
\end{Author}
\begin{References}\relax
Scheid S and Spang R (2004): A stochastic downhill search algorithm for estimating the local false discovery rate, \emph{IEEE TCBB} \bold{1(3)}, 98--108.

Storey JD and Tibshirani R (2003): Statistical significance for genomewide studies, \emph{PNAS} \bold{100(16)}, 9440--9445.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{twilight.pval}{twilight.pval}}, \code{\LinkA{plot.twilight}{plot.twilight}}, \code{\LinkA{exfdr}{exfdr}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(exfdr) # twilight object created by twilight with B=1000 bootstraps
exfdr
plot(exfdr,which="fdr")
\end{ExampleCode}
\end{Examples}

