@@ -1,136 +1,144 @@
\name{survkit}
\title{Weibull and Cox Models with Random Effects}
\alias{survkit}
\usage{
survkit(times, censor=NULL, ccov=NULL, tvcov=NULL,
strata=NULL, id=NULL, model="Weibull", baseline=FALSE,
residuals=FALSE, survival=NULL, svalues=NULL, valrho=NULL,
constraints=NULL, impose=NULL, dist=NULL, random=NULL,
estimate=NULL, moments=FALSE, rule=NULL, pedigree=NULL,
integrate=NULL, jointmode=FALSE, within=NULL, converge=1.e-8,
iterlim=100)
}
\description{
\code{survfit} was written in Fortran by Dr. V. Ducrocq (INRA, France:
vincent.ducrocq@dga.jouy.inra.fr) and Dr. J. Soelkner (Vienna:
soelkner@mail.boku.ac.at) to fit Weibull and Cox proportional hazards
models with random effects for very large data sets. This is a
cut-down version adapted to R. The full Survival Kit, including the
manual, can be obtained from http://www.boku.ac.at/nuwi/popgen.
}
\arguments{
\item{times}{Vector of times (events, right-censoring, change in
time-varying covariate, left-truncation).}
\item{censor}{Corresponding vector of censoring indicators. 1: event;
0: censored; -1: change of time-varying covariate; -2: left-truncation
time.}
\item{ccov}{Model formula for time-constant covariates. These may have
one value per individual or one per time. Because of the way factor
variables are handled, interactions must be coded as new variables.}
\item{tvcov}{Model formula for time-varying covariates with one value
per time. There can only be one change-point per individual. Again,
interactions must be coded as new variables.}
\item{strata}{A factor variable specifying stratification. With the
Weibull model, different intercepts and power parameters are
calculated for each stratum. For the Cox model, a different baseline
curve is fitted.}
\item{id}{A variable giving individual identification numbers
(starting at one). If not supplied, all times are assumed to refer to
different individuals.}
\item{model}{Weibull or Cox model, or Kaplan-Meier estimates.}
\item{baseline}{If TRUE, the baseline values are calculated for the
Cox model.}
\item{residuals}{If TRUE, calculate residuals (only for Cox model).}
\item{survival}{Calculate values of the survival function at
\code{quantiles},or at \code{equal}ly-spaced, \code{specific}, or
\code{all} observed times.}
\item{svalues}{A vector of quantile values (between 0 and 100),
spacing and maximum for equally-spaced, or specific times for
\code{survival}.}
\item{valrho}{A fixed value of the Weibull power parameter if it is
not to be estimated.}
\item{constraints}{By default, the category of each factor variable
with the \code{largest} number of events is taken as baseline. Other
options are \code{none} which gives values around the mean and
\code{find}. See also, \code{impose}.}
\item{impose}{A list of a vector of variable names and a corresponding
vector of their baseline category numbers. Any factor variables not
given will have their first category as baseline.}
\item{dist}{The distribution of the random effect: loggamma, normal,
or multivariate (normal).}
\item{random}{A factor variable specifying the random effect.}
\item{estimate}{One fixed value for the mode of the variance of the
random effect or three values if the mode is to be estimated: lower
and upper bounds, and precision.}
\item{moments}{Estimate the first three moments of the random effect
as well as the mode.}
\item{rule}{For the multivariate normal random effect, the genetic
relationships: \code{usual}, \code{mgs} (sire or father model), or
\code{sire.dam} (father and mother).}
\item{pedigree}{A matrix with four columns required for the
multivariate normal random effect, containing the individual
id, the sex, the father's category, and the mother's category.}
\item{integrate}{A factor variable to integrate out as the log-gamma
random effect in a Weibull model. (Not available for the Cox model.)}
\item{jointmode}{If TRUE, the log-gamma variance parameter is
estimated simultaneously with the other parameters using the
information in \code{estimate}. Otherwise, a fixed value, given in
\code{estimate} is assumed.}
\item{within}{A second factor variable (within the \code{integrate}
variable) to integrate out.}
\item{converge}{The convergence criterion, by default 1.e-8.}
\item{iterlim}{Maximum number of iterations.}
}
\author{V. Ducrocq, J. Soelkner, and J.K. Lindsey}
\seealso{
\code{\link[event]{coxre}}, \code{\link[event]{kalsurv}}.
}
\examples{
# y <- trunc(rweibull(20,2,20))
y <- c(6,22,43,16,7,6,15,35,10,9,18,34,7,13,10,17,14,19,11,13)
# cens <- rbinom(20,1,0.9)
cens <- c(1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1)
id <- gl(2,10)
# x <- rnorm(20)
x <- c(1.82881379,1.06606868,0.70877744,-0.09932880,-0.60626148,-0.75371046,
0.23884069,0.51199483,-0.73060095,-0.93222151,2.27947539,-0.73855454,
-0.36412735,-0.89122114,-0.05025962,-0.10001587,1.11460865,-1.87315971,
-0.11280052,-1.6880509)
# Kaplan-Meier estimates
survkit(y, censor=cens, model="Kaplan")
# null Weibull model
survkit(y, censor=cens)
# one time-constant covariate
survkit(y, censor=cens, ccov=~x)
# stratify
survkit(y, censor=cens, ccov=~x, strata=id)
# estimate a normal random effect
survkit(y, censor=cens, ccov=~x, random=id, dist="normal",
estimate=c(0.1,10,0.01), moments=TRUE)
# try a fixed value for the normal random effect
survkit(y, censor=cens, ccov=~x, random=id, dist="normal",
estimate=1.3)
# estimate a log-gamma random effect
survkit(y, censor=cens, ccov=~x, random=id, dist="loggamma",
estimate=c(0.1,10,0.01))
# estimate a log-gamma random effect by integrating it out
survkit(y, censor=cens, ccov=~x, dist="loggamma", estimate=1.4,
integ=id, jointmode=TRUE)
# try a fixed value of the log-gamma random effect, integrating it out
survkit(y, censor=cens, ccov=~x, dist="loggamma", estimate=1,
integ=id)
#
# Cox model with one time-constant covariate
print(z <- survkit(y, censor=cens, ccov=~x, model="Cox", residuals=TRUE,
baseline=TRUE))
residuals(z)
baseline(z)
# obtain the quantiles
print(z <- survkit(y, censor=cens, ccov=~x, model="Cox",
survival="quantiles", svalues=seq(10,90,by=10)))
survival(z)
# estimate a log-gamma random effect
survkit(y, censor=cens, ccov=~x, model="Cox", random=id,
dist="loggamma", estimate=c(0.1,10,0.01))
}
\keyword{models}
\name{survkit}
\title{Weibull and Cox Models with Random Effects}
\alias{survkit}
\alias{baseline}
\alias{baseline.survivalkit}
\alias{print.survivalkit}
\alias{residuals.survivalkit}
\alias{survival}
\alias{survival.survivalkit}
\usage{
survkit(times, censor=NULL, ccov=NULL, tvcov=NULL,
strata=NULL, id=NULL, model="Weibull", baseline=FALSE,
residuals=FALSE, survival=NULL, svalues=NULL, valrho=NULL,
constraints=NULL, impose=NULL, dist=NULL, random=NULL,
estimate=NULL, moments=FALSE, rule=NULL, pedigree=NULL,
integrate=NULL, jointmode=FALSE, within=NULL, converge=1.e-8,
iterlim=100)
}
\description{
\code{survfit} was written in Fortran by Dr. V. Ducrocq (INRA, France:
vincent.ducrocq@dga.jouy.inra.fr) and Dr. J. Soelkner (Vienna:
soelkner@mail.boku.ac.at) to fit Weibull and Cox proportional hazards
models with random effects for very large data sets. This is a
cut-down version adapted to R. The full Survival Kit, including the
manual, can be obtained from http://www.boku.ac.at/nuwi/popgen.
}
\arguments{
\item{times}{Vector of times (events, right-censoring, change in
time-varying covariate, left-truncation).}
\item{censor}{Corresponding vector of censoring indicators. 1: event;
0: censored; -1: change of time-varying covariate; -2: left-truncation
time.}
\item{ccov}{Model formula for time-constant covariates. These may have
one value per individual or one per time. Because of the way factor
variables are handled, interactions must be coded as new variables.}
\item{tvcov}{Model formula for time-varying covariates with one value
per time. There can only be one change-point per individual. Again,
interactions must be coded as new variables.}
\item{strata}{A factor variable specifying stratification. With the
Weibull model, different intercepts and power parameters are
calculated for each stratum. For the Cox model, a different baseline
curve is fitted.}
\item{id}{A variable giving individual identification numbers
(starting at one). If not supplied, all times are assumed to refer to
different individuals.}
\item{model}{Weibull or Cox model, or Kaplan-Meier estimates.}
\item{baseline}{If TRUE, the baseline values are calculated for the
Cox model.}
\item{residuals}{If TRUE, calculate residuals (only for Cox model).}
\item{survival}{Calculate values of the survival function at
\code{quantiles},or at \code{equal}ly-spaced, \code{specific}, or
\code{all} observed times.}
\item{svalues}{A vector of quantile values (between 0 and 100),
spacing and maximum for equally-spaced, or specific times for
\code{survival}.}
\item{valrho}{A fixed value of the Weibull power parameter if it is
not to be estimated.}
\item{constraints}{By default, the category of each factor variable
with the \code{largest} number of events is taken as baseline. Other
options are \code{none} which gives values around the mean and
\code{find}. See also, \code{impose}.}
\item{impose}{A list of a vector of variable names and a corresponding
vector of their baseline category numbers. Any factor variables not
given will have their first category as baseline.}
\item{dist}{The distribution of the random effect: loggamma, normal,
or multivariate (normal).}
\item{random}{A factor variable specifying the random effect.}
\item{estimate}{One fixed value for the mode of the variance of the
random effect or three values if the mode is to be estimated: lower
and upper bounds, and precision.}
\item{moments}{Estimate the first three moments of the random effect
as well as the mode.}
\item{rule}{For the multivariate normal random effect, the genetic
relationships: \code{usual}, \code{mgs} (sire or father model), or
\code{sire.dam} (father and mother).}
\item{pedigree}{A matrix with four columns required for the
multivariate normal random effect, containing the individual
id, the sex, the father's category, and the mother's category.}
\item{integrate}{A factor variable to integrate out as the log-gamma
random effect in a Weibull model. (Not available for the Cox model.)}
\item{jointmode}{If TRUE, the log-gamma variance parameter is
estimated simultaneously with the other parameters using the
information in \code{estimate}. Otherwise, a fixed value, given in
\code{estimate} is assumed.}
\item{within}{A second factor variable (within the \code{integrate}
variable) to integrate out.}
\item{converge}{The convergence criterion, by default 1.e-8.}
\item{iterlim}{Maximum number of iterations.}
}
\author{V. Ducrocq, J. Soelkner, and J.K. Lindsey}
\seealso{
\code{\link[event]{coxre}}, \code{\link[event]{kalsurv}}.
}
\examples{
# y <- trunc(rweibull(20,2,20))
y <- c(6,22,43,16,7,6,15,35,10,9,18,34,7,13,10,17,14,19,11,13)
# cens <- rbinom(20,1,0.9)
cens <- c(1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1)
id <- gl(2,10)
# x <- rnorm(20)
x <- c(1.82881379,1.06606868,0.70877744,-0.09932880,-0.60626148,-0.75371046,
0.23884069,0.51199483,-0.73060095,-0.93222151,2.27947539,-0.73855454,
-0.36412735,-0.89122114,-0.05025962,-0.10001587,1.11460865,-1.87315971,
-0.11280052,-1.6880509)
# Kaplan-Meier estimates
survkit(y, censor=cens, model="Kaplan")
# null Weibull model
survkit(y, censor=cens)
# one time-constant covariate
survkit(y, censor=cens, ccov=~x)
# stratify
survkit(y, censor=cens, ccov=~x, strata=id)
# estimate a normal random effect
survkit(y, censor=cens, ccov=~x, random=id, dist="normal",
estimate=c(0.1,10,0.01), moments=TRUE)
# try a fixed value for the normal random effect
survkit(y, censor=cens, ccov=~x, random=id, dist="normal",
estimate=1.3)
# estimate a log-gamma random effect
survkit(y, censor=cens, ccov=~x, random=id, dist="loggamma",
estimate=c(0.1,10,0.01))
# estimate a log-gamma random effect by integrating it out
\dontrun{
survkit(y, censor=cens, ccov=~x, dist="loggamma", estimate=1.3,
integ=id, jointmode=TRUE)
# try a fixed value of the log-gamma random effect, integrating it out
survkit(y, censor=cens, ccov=~x, dist="loggamma", estimate=1,
integ=id)
}
#
# Cox model with one time-constant covariate
print(z <- survkit(y, censor=cens, ccov=~x, model="Cox", residuals=TRUE,
baseline=TRUE))
residuals(z)
baseline(z)
# obtain the quantiles
print(z <- survkit(y, censor=cens, ccov=~x, model="Cox",
survival="quantiles", svalues=seq(10,90,by=10)))
survival(z)
# estimate a log-gamma random effect
survkit(y, censor=cens, ccov=~x, model="Cox", random=id,
dist="loggamma", estimate=c(0.1,10,0.01))
}
\keyword{models}
@@ -1,32 +1,37 @@
\name{tccov}
\title{Create a Vector of Time-constant Covariates for a Point Process}
\alias{tccov}
\usage{
tccov(y, x, id)
}
\arguments{
\item{y}{Vector of times.}
\item{x}{Vector covariate.}
\item{id}{Vector of corresponding individual identifiers for who had
which sequence of times.}
}
\value{
\code{tccov} creates a vector of length \code{sum(y)} of time-constant
covariates for use with \code{\link[event]{ehr}}. \code{id} must be numbered
consecutively. \code{x} must have one value for each distinct \code{id},
}
\author{J.K. Lindsey}
\seealso{
\code{\link[event]{bp}}, \code{\link[event]{ehr}},
\code{\link[event]{ident}}, \code{\link[event]{pp}},
\code{\link[event]{tpast}}, \code{\link[event]{ttime}},
\code{\link[event]{tvcov}}.
}
\examples{
y <- c(5,3,2,4)
id <- c(1,1,2,2)
x <- c(5.2,3.1)
xcov <- tccov(y, x, id)
xcov
}
\keyword{manip}
\name{tccov}
\title{Create a Vector of Time-constant Covariates for a Point Process}
\alias{tccov}
\usage{
tccov(y, x, id)
}
\description{
\code{tccov} creates a vector of length \code{sum(y)} of time-constant
covariates for use with \code{\link[event]{ehr}}. \code{id} must be numbered
consecutively. \code{x} must have one value for each distinct \code{id},
}
\arguments{
\item{y}{Vector of times.}
\item{x}{Vector covariate.}
\item{id}{Vector of corresponding individual identifiers for who had
which sequence of times.}
}
\value{
\code{tccov} creates a vector of length \code{sum(y)} of time-constant
covariates for use with \code{\link[event]{ehr}}. \code{id} must be numbered
consecutively. \code{x} must have one value for each distinct \code{id},
}
\author{J.K. Lindsey}
\seealso{
\code{\link[event]{bp}}, \code{\link[event]{ehr}},
\code{\link[event]{ident}}, \code{\link[event]{pp}},
\code{\link[event]{tpast}}, \code{\link[event]{ttime}},
\code{\link[event]{tvcov}}.
}
\examples{
y <- c(5,3,2,4)
id <- c(1,1,2,2)
x <- c(5.2,3.1)
xcov <- tccov(y, x, id)
xcov
}
\keyword{manip}
@@ -1,26 +1,30 @@
\name{tpast}
\title{Create a Vector of Times Past since Previous Events for a Point Process}
\alias{tpast}
\usage{
tpast(y)
}
\arguments{
\item{y}{Vector of times.}
}
\value{
\code{tpast} creates a vector of length \code{sum(y)} of times since the
immediately preceding event occurred for use with \code{\link[event]{ehr}}.
}
\author{J.K. Lindsey}
\seealso{
\code{\link[event]{bp}}, \code{\link[event]{ehr}},
\code{\link[event]{ident}}, \code{\link[event]{pp}},
\code{\link[event]{tccov}}, \code{\link[event]{ttime}},
\code{\link[event]{tvcov}}.
}
\examples{
y <- c(5,3,2,4)
ptime <- tpast(y)
ptime
}
\keyword{manip}
\name{tpast}
\title{Create a Vector of Times Past since Previous Events for a Point Process}
\alias{tpast}
\usage{
tpast(y)
}
\description{
\code{tpast} creates a vector of length \code{sum(y)} of times since the
immediately preceding event occurred for use with \code{\link[event]{ehr}}.
}
\arguments{
\item{y}{Vector of times.}
}
\value{
\code{tpast} creates a vector of length \code{sum(y)} of times since the
immediately preceding event occurred for use with \code{\link[event]{ehr}}.
}
\author{J.K. Lindsey}
\seealso{
\code{\link[event]{bp}}, \code{\link[event]{ehr}},
\code{\link[event]{ident}}, \code{\link[event]{pp}},
\code{\link[event]{tccov}}, \code{\link[event]{ttime}},
\code{\link[event]{tvcov}}.
}
\examples{
y <- c(5,3,2,4)
ptime <- tpast(y)
ptime
}
\keyword{manip}
@@ -1,30 +1,34 @@
\name{ttime}
\title{Create a Vector of Total Time Elapsed for each Individual for a
Point Process}
\alias{ttime}
\usage{
ttime(y, id)
}
\arguments{
\item{y}{Vector of times.}
\item{id}{Vector of corresponding individual identifiers for who had
which sequence of times.}
}
\value{
\code{ttime} creates a vector of length \code{sum(y)} of times since
each individual began for use with \code{\link[event]{ehr}}.
}
\author{J.K. Lindsey}
\seealso{
\code{\link[event]{bp}}, \code{\link[event]{ehr}},
\code{\link[event]{ident}}, \code{\link[event]{pp}},
\code{\link[event]{tccov}}, \code{\link[event]{tpast}},
\code{\link[event]{tvcov}}.
}
\examples{
y <- c(5,3,2,4)
id <- c(1,1,2,2)
itime <- ttime(y, id)
itime
}
\keyword{manip}
\name{ttime}
\title{Create a Vector of Total Time Elapsed for each Individual for a
Point Process}
\alias{ttime}
\usage{
ttime(y, id)
}
\description{
\code{ttime} creates a vector of length \code{sum(y)} of times since
each individual began for use with \code{\link[event]{ehr}}.
}
\arguments{
\item{y}{Vector of times.}
\item{id}{Vector of corresponding individual identifiers for who had
which sequence of times.}
}
\value{
\code{ttime} creates a vector of length \code{sum(y)} of times since
each individual began for use with \code{\link[event]{ehr}}.
}
\author{J.K. Lindsey}
\seealso{
\code{\link[event]{bp}}, \code{\link[event]{ehr}},
\code{\link[event]{ident}}, \code{\link[event]{pp}},
\code{\link[event]{tccov}}, \code{\link[event]{tpast}},
\code{\link[event]{tvcov}}.
}
\examples{
y <- c(5,3,2,4)
id <- c(1,1,2,2)
itime <- ttime(y, id)
itime
}
\keyword{manip}
@@ -1,31 +1,36 @@
\name{tvcov}
\title{Create a Vector of Time-varying Covariates for a Point Process}
\alias{tvcov}
\usage{
tvcov(y, x, tx)
}
\arguments{
\item{y}{Vector of times.}
\item{x}{Vector covariate.}
\item{tx}{Vector of times at which x changes.}
}
\value{
\code{tvcov} creates a vector of length \code{sum(y)} of time-varying
covariates for use with \code{\link[event]{ehr}}. It may also be used to create
weight vectors.
}
\author{J.K. Lindsey}
\seealso{
\code{\link[event]{bp}}, \code{\link[event]{ehr}},
\code{\link[event]{ident}}, \code{\link[event]{pp}},
\code{\link[event]{tccov}}, \code{\link[event]{tpast}},
\code{\link[event]{ttime}}.
}
\examples{
y <- c(5,3,2,4)
x <- c(1,2,2,1,2,2,1)
tx <- c(2,3,1,2,2,2,2)
zcov <- tvcov(y, x, tx)
zcov
}
\keyword{manip}
\name{tvcov}
\title{Create a Vector of Time-varying Covariates for a Point Process}
\alias{tvcov}
\usage{
tvcov(y, x, tx)
}
\description{
\code{tvcov} creates a vector of length \code{sum(y)} of time-varying
covariates for use with \code{\link[event]{ehr}}. It may also be used to create
weight vectors.
}
\arguments{
\item{y}{Vector of times.}
\item{x}{Vector covariate.}
\item{tx}{Vector of times at which x changes.}
}
\value{
\code{tvcov} creates a vector of length \code{sum(y)} of time-varying
covariates for use with \code{\link[event]{ehr}}. It may also be used to create
weight vectors.
}
\author{J.K. Lindsey}
\seealso{
\code{\link[event]{bp}}, \code{\link[event]{ehr}},
\code{\link[event]{ident}}, \code{\link[event]{pp}},
\code{\link[event]{tccov}}, \code{\link[event]{tpast}},
\code{\link[event]{ttime}}.
}
\examples{
y <- c(5,3,2,4)
x <- c(1,2,2,1,2,2,1)
tx <- c(2,3,1,2,2,2,2)
zcov <- tvcov(y, x, tx)
zcov
}
\keyword{manip}

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

13,282 src/survkit.f

Large diffs are not rendered by default.