\HeaderA{NPBayesT2}{Nonparametric Bayes estimate of CDF from left truncated, right censored data}{NPBayesT2}
\keyword{nonparametric}{NPBayesT2}
\keyword{survival}{NPBayesT2}
\begin{Description}\relax
This function will compute the nonparametric Bayes estimator of
survival/distribution function from left truncated, right
censored data with square error loss. 
The prior is a Dirichlet process. 

The data must be nonnegative. We assume \eqn{F(0)=0}{}.
\end{Description}
\begin{Usage}
\begin{verbatim}
NPBayesT2(B, theta, u, y = numeric(0), x = numeric(0), status = numeric(0))
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{B}] a positive number. The parameter for Dirichlet process prior. 
The weight of prior information. If B is very small, then the resulting
prior is "non-informative".

\item[\code{theta}] a positive number. Another parameter for Dirichlet process prior. 
The measure/parameter is \eqn{ \alpha [t, \infty ) = B \exp( - \theta t)}{} .

\item[\code{u}] a non-negative number, where the estimator of
\eqn{ 1- \hat F(u)}{} is to be computed.

\item[\code{y}] optional vector holding the (non-negative) truncation times.

\item[\code{x}] optional vector holding the (possibly) right censored observations.

\item[\code{status}] optional vector holding the censoring status of the x vector.
1--uncensor, 0--censor.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The observations must all be non-negative. Due to left truncation,
data must also satisfy \eqn{y_i < x_i}{}. The 3 data vectors, x, y, status
must be of the same length. This function is standalone.
\end{Details}
\begin{Value}
a single value that is 
the Bayes nonparametric estimator \eqn{ 1- \hat F(u) }{}.
\end{Value}
\begin{Author}\relax
Mai Zhou.
\end{Author}
\begin{References}\relax
Susarla and Van Ryzin (1976)
Nonparametric Bayesian estimation of survival curves from
incomplete observations.
\emph{ J. Amer. Statist. Assoc.} \bold{71}, 
897-902.

Zhou, M. (2000). Nonparametric Bayes estimator of survival functions
for doubly/interval censored data. Tech Report, Univ. of Kentucky.  

See also Zhou, M. (2004). Statistica Sinica. 

Luan, J, and Zhou, M. (2004). 
Nonparametric Bayes estimator of survival functions for
censored data that are also subject to left truncation.
Tech Report. Univ. Kentucky.
\end{References}
\begin{Examples}
\begin{ExampleCode}
trunc <- c(2,4,10)
xtime <- c(9,13,15)
d <- c(1,0,0) 
NPBayesT(B=8, theta=0.12, u=3.2, y=trunc, x=xtime, status=d)

ui <- seq(0.1, 20, 0.1)
fui <- ui
for(i in 1:200) 
   fui[i] <- NPBayesT(B=8, theta=0.12, u=ui[i],y=trunc, x=xtime, status=d)
#plot(ui, fui)

ypsy <- c(51, 58, 55, 28, 25, 48, 47, 25, 31, 30, 33, 43, 45, 35, 36)
xpsy <- c(52, 59, 57, 50, 57, 59, 61, 61, 62, 67, 68, 69, 69, 65, 76)
dpsy <- c(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1 ) 
NPBayesT(B=8,theta=0.02,u=56,y=ypsy,x=xpsy,status=dpsy)
\end{ExampleCode}
\end{Examples}

