\HeaderA{survreg.distributions}{Parametric Survival Distributions}{survreg.distributions}
\keyword{survival}{survreg.distributions}
\begin{Description}\relax
List of distributions for accelerated failure models. These are
location-scale families for some transformation of time. The entry
describes  the cdf \eqn{F}{} and density \eqn{f}{} of a canonical member of
the family.
\end{Description}
\begin{Usage}
\begin{verbatim}
survreg.distributions
\end{verbatim}
\end{Usage}
\begin{Format}\relax
There are two basic formats, the first defines a distribution de novo,
the second defines a new distribution in terms of an old one.
\Tabular{ll}{
name:& name of distribution\\
variance:& function(parms) returning the variance (currently unused)\\
init(x,weights,...):& Function returning an initial\\
& estimate of the mean and variance \\
& (used for initial values in the iteration)\\
density(x,parms):& Function returning a matrix with columns \eqn{F}{},\\
& \eqn{1-F}{},\eqn{f}{},\eqn{f'/f}{},\eqn{f''/f}{}\\
quantile(p,parms):& Quantile function\\
scale:& Optional fixed value for the scale parameter\\
parms:& Vector of default values and names for any additional parameters\\
deviance(y,scale,parms):& Function returning the deviance for a\\
& saturated model; used only for deviance residuals.
}
and to define one distribution in terms of another
\Tabular{ll}{
name:& name of distribution\\
dist:& name of parent distribution\\
trans:& transformation (eg log)\\
dtrans:& derivative of transformation\\
itrans:& inverse of transformation\\
scale:& Optional fixed value for scale parameter\\
}
\end{Format}
\begin{Details}\relax
There are four basic distributions:\code{extreme}, \code{gaussian},
\code{logistic} and \code{t}. The last three
are parametrised in the same way as the distributions already present in
\R. The extreme value cdf is
\deqn{F=1-e^{-e^t}.}{}

When the logarithm of survival time has one of the first three distributions
we obtain respectively \code{weibull}, \code{lognormal}, and
\code{loglogistic}. The location-scale parameterizaion of a Weibull
distribution found in \code{survreg} is not the same as the parameterization
of \code{\LinkA{rweibull}{rweibull}}.

The other predefined distributions are defined in terms of these. The
\code{exponential} and \code{rayleigh} distributions are Weibull
distributions with fixed \code{scale} of 1 and 0.5 respectively, and
\code{loggaussian} is a synonym for \code{lognormal}.

For speed parts of the three most commonly used distributions
are hardcoded in C; for this reason the elements of \code{survreg.distributions}
with names of "Extreme value", "Logisitic" and "Gaussian" should not be
modified.  (The order of these in the list is not important, recognition
is by name.)
As an alternative to modifying \code{survreg.distributions}
a new distribution can be specified as a separate list.
This is the preferred method of addition and is illustrated below.
\end{Details}
\begin{SeeAlso}\relax
\code{\LinkA{survreg}{survreg}}, \code{\LinkA{pweibull}{pweibull}},
\code{\LinkA{pnorm}{pnorm}},\code{\LinkA{plogis}{plogis}}, \code{\LinkA{pt}{pt}},
\code{\LinkA{survregDtest}{survregDtest}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
# time transformation
survreg(Surv(time, status) ~ ph.ecog + sex, dist='weibull', data=lung)
# change the transformation to work in years
# intercept changes by log(365), everything else stays the same
my.weibull <- survreg.distributions$weibull
my.weibull$trans <- function(y) log(y/365)
my.weibull$itrans <- function(y) 365*exp(y)
survreg(Surv(time, status) ~ ph.ecog + sex, lung, dist=my.weibull)

# Weibull parametrisation
y<-rweibull(1000, shape=2, scale=5)
survreg(Surv(y)~1, dist="weibull")
# survreg parameters are scale=1/shape, intercept=log(scale)

# Cauchy fit
mycauchy <- list(name='Cauchy',
                 init= function(x, weights, ...) 
                      c(median(x), mad(x)),
                 density= function(x, parms) {
                      temp <- 1/(1 + x^2)
                      cbind(.5 + atan(temp)/pi, .5+ atan(-temp)/pi,
                            temp/pi, -2 *x*temp, 2*temp^2*(4*x^2*temp -1))
                      },
                 quantile= function(p, parms) tan((p-.5)*pi),
                 deviance= function(...) stop('deviance residuals not defined')
                 )
survreg(Surv(log(time), status) ~ ph.ecog + sex, lung, dist=mycauchy)
\end{ExampleCode}
\end{Examples}

