Title: | Event History Procedures and Models |
---|---|
Description: | Functions for setting up and analyzing event history data. |
Authors: | Bruce Swihart [cre, aut], Jim Lindsey [aut] (Jim created this package, Bruce is maintaining the CRAN version) |
Maintainer: | Bruce Swihart <[email protected]> |
License: | GPL-2 |
Version: | 1.1.0 |
Built: | 2025-01-10 04:16:00 UTC |
Source: | https://github.com/swihart/event |
autointensity
plots the autointensity function of a point
process, including a solid horizontal line indicating the constant
intensity of a Poisson process.
autointensity(times, window=NULL, maxlag=max(times), ylab="Conditional probability", xlab="Lag", main="Autointensity function", xlim=c(0,max(times)), ylim=c(0,if(plotse)max(se1)else max(z$density)), lty=1, plot=TRUE, plotse=TRUE, add=FALSE, ...)
autointensity(times, window=NULL, maxlag=max(times), ylab="Conditional probability", xlab="Lag", main="Autointensity function", xlim=c(0,max(times)), ylim=c(0,if(plotse)max(se1)else max(z$density)), lty=1, plot=TRUE, plotse=TRUE, add=FALSE, ...)
times |
Vector of times between events. |
window |
Width of grouping interval. |
maxlag |
Maximum lag to be calculated, by default the maximum interevent time. |
plot |
If FALSE, values are returned but the function is not plotted. |
plotse |
If TRUE, plots pointwise two-standard error bands around the curve. |
add |
If TRUE, add curve to an existing plot. |
ylab |
Plotting control options. |
xlab |
Plotting control options. |
main |
Plotting control options. |
xlim |
Plotting control options. |
ylim |
Plotting control options. |
lty |
Plotting control options. |
... |
Plotting control options. |
A list containing the coordinates of the plotted function and the standard error bands.
J.K. Lindsey
Guttorp, P. (1995) Stochastic Modeling of Scientific Data. Chapman & Hall, pp. 229, 238-240.
times <- rgamma(100,2,scale=4) autointensity(times, window=3)
times <- rgamma(100,2,scale=4) autointensity(times, window=3)
bp
creates a vector of length sum(y)
of cumulative
numbers of previous events for each individual for use in fitting
birth processes with ehr
. Add one if the process starts
at an event.
bp(y, id, censor=1)
bp(y, id, censor=1)
y |
Vector of times. |
id |
Vector of corresponding individual identifiers for who had which sequence of times. |
censor |
Vector of censoring indicators. |
bp
creates a vector of length sum(y)
of cumulative
numbers of previous events for each individual for use in fitting
birth processes with ehr
. Add one if the process starts
at an event.
J.K. Lindsey
ehr
, ident
, pp
, tccov
,
tpast
, ttime
, tvcov
.
y <- c(5,3,2,4) i <- c(1,1,2,2) birth <- bp(y, i) birth
y <- c(5,3,2,4) i <- c(1,1,2,2) birth <- bp(y, i) birth
coxre
fits a Cox proportional hazards model to event history
data using a gamma distribution random effect. The parameter, gamma,
is the variance of this mixing distribution.
If a matrix of response times is supplied, the model can be stratified by columns, i.e. a different intensity function is fitted for each column. To fit identical intensity functions to all response types, give the times as a vector.
coxre(response, censor, nest=NULL, cov=NULL, stratified=FALSE, cumul=FALSE,estimate=1, iter=10, print.level=0, ndigit=10, gradtol=0.00001, steptol=0.00001, iterlim=100, fscale=1, typsize=abs(estimate), stepmax=estimate)
coxre(response, censor, nest=NULL, cov=NULL, stratified=FALSE, cumul=FALSE,estimate=1, iter=10, print.level=0, ndigit=10, gradtol=0.00001, steptol=0.00001, iterlim=100, fscale=1, typsize=abs(estimate), stepmax=estimate)
response |
Vector or matrix of times to events, with one column per type of response (or subunit). |
censor |
Corresponding vector or matrix of censoring indicators. If NULL all values are set to one. |
nest |
Vector indicating to which unit each observation belongs. |
cov |
One covariate |
stratified |
If TRUE, a model stratified on type of response (the columns of response) is fitted instead of proportional intensities. |
cumul |
Set to TRUE if response times are from a common origin instead of times to (or between) events. |
estimate |
Initial estimate of the frailty parameter. |
iter |
Maximum number of iterations allowed for the inner EM loop. |
print.level |
|
ndigit |
|
gradtol |
|
steptol |
|
iterlim |
|
fscale |
|
typsize |
|
stepmax |
|
D.G. Clayton and J.K. Lindsey
Clayton, D. (1987) The analysis of event history data: a review of progress and outstanding problems. Statistics in Medicine 7: 819-841
# 11 individuals, each with 5 responses y <- matrix(c(51,36,50,35,42, 27,20,26,17,27, 37,22,41,37,30, 42,36,32,34,27, 27,18,33,14,29, 43,32,43,35,40, 41,22,36,25,38, 38,21,31,20,16, 36,23,27,25,28, 26,31,31,32,36, 29,20,25,26,25),ncol=5,byrow=TRUE) # Different intensity functions coxre(response=y, censor=matrix(rep(1,55),ncol=5), nest=1:11, est=0.7, stratified=TRUE) # Proportional intensity functions for the five responses coxre(response=y, censor=matrix(rep(1,55),ncol=5), nest=1:11, est=0.7, stratified=FALSE) # Identical intensity functions coxre(response=as.vector(t(y)), censor=rep(1,55), nest=rep(1:11,rep(5,11)), est=0.7)
# 11 individuals, each with 5 responses y <- matrix(c(51,36,50,35,42, 27,20,26,17,27, 37,22,41,37,30, 42,36,32,34,27, 27,18,33,14,29, 43,32,43,35,40, 41,22,36,25,38, 38,21,31,20,16, 36,23,27,25,28, 26,31,31,32,36, 29,20,25,26,25),ncol=5,byrow=TRUE) # Different intensity functions coxre(response=y, censor=matrix(rep(1,55),ncol=5), nest=1:11, est=0.7, stratified=TRUE) # Proportional intensity functions for the five responses coxre(response=y, censor=matrix(rep(1,55),ncol=5), nest=1:11, est=0.7, stratified=FALSE) # Identical intensity functions coxre(response=as.vector(t(y)), censor=rep(1,55), nest=rep(1:11,rep(5,11)), est=0.7)
cprocess
plots the cumulative number of events (the counting
process) over time for each vector in the list. One or both of
times
and events
can be supplied.
cprocess(times=NULL, events=NULL, number=FALSE, lty=NULL, xlim=NULL, ylim=NULL, xlab="Time", ylab="Counts", ...)
cprocess(times=NULL, events=NULL, number=FALSE, lty=NULL, xlim=NULL, ylim=NULL, xlab="Time", ylab="Counts", ...)
times |
Vector of times between events, a list of such
vectors, or a |
events |
Vector of counts of events, a list of such vectors, or a
|
number |
If TRUE, the counting processes are numbered consecutively on the graph. |
ylab |
Plotting control options. |
xlab |
Plotting control options. |
xlim |
Plotting control options. |
ylim |
Plotting control options. |
lty |
Plotting control options. |
... |
Plotting control options. |
J.K. Lindsey
times <- rgamma(20,2,scale=4) cprocess(times)
times <- rgamma(20,2,scale=4) cprocess(times)
ehr
fits an intensity function to event histories, where point is
produced by point <- pp(y)
and lambda
is the user-defined
log intensity function.
Nonlinear regression models for lambda
can be supplied as
formulae where parameters are unknowns. Factor variables cannot be
used and parameters must be scalars. (See finterp
.)
ehr(point, lambda=NULL, linear=NULL, plambda=NULL, delta=1, envir=parent.frame(), print.level=0, typsize=rep(1,length(plambda)), ndigit=10, gradtol=0.00001, iterlim=100, fscale=1, stepmax=max(10*sqrt(plambda%*%plambda),10), steptol=0.0004)
ehr(point, lambda=NULL, linear=NULL, plambda=NULL, delta=1, envir=parent.frame(), print.level=0, typsize=rep(1,length(plambda)), ndigit=10, gradtol=0.00001, iterlim=100, fscale=1, stepmax=max(10*sqrt(plambda%*%plambda),10), steptol=0.0004)
point |
A point process vector produced by |
lambda |
User-specified function of |
linear |
A formula beginning with ~ specifying the linear part of the regression function. |
plambda |
Vector of initial parameter estimates. If |
delta |
If any time intervals are different from unity, a vector of time intervals. |
envir |
Environment in which model formulae are to be
interpreted or a data object of class, repeated, tccov, or tvcov.
If |
print.level |
|
ndigit |
|
gradtol |
|
steptol |
|
iterlim |
|
fscale |
|
typsize |
|
stepmax |
|
J.K. Lindsey
Lindsey, J.K. (1995) Fitting parametric counting processes by using log linear models. Journal of the Royal Statistical Society C44, 201-212.
bp
, finterp
,
ident
, pp
,
tccov
, tpast
,
ttime
, tvcov
.
y <- c(5,3,2,4) # event indicator py <- pp(y) # time since previous event ptime <- tpast(y) # individual ID i <- c(1,1,2,2) id <- ident(y, i) # times and corresponding covariate values tx <- c(2,3,1,2,2,2,2) x <- c(1,2,2,1,2,2,1) zcov <- tvcov(y, x, tx) # Poisson process ehr(py, plambda=1) # Weibull process lambda1 <- function(p) p[1]+p[2]*log(ptime) ehr(py, lambda=lambda1, plambda=c(1,1)) # or ehr(py, lambda=~log(ptime), plambda=c(1,1)) # or ehr(py, lambda=~b0+b1*log(ptime), plambda=list(b0=1,b1=1)) # Poisson process with time-varying covariate lambda2 <- function(p) p[1]+p[2]*zcov ehr(py, lambda=lambda2, plambda=c(1,1)) # or ehr(py, lambda=~zcov, plambda=c(1,1)) # or ehr(py, lambda=~c0+c1*zcov, plambda=list(c0=1,c1=1)) # Weibull process with time-varying covariate lambda3 <- function(p) p[1]+p[2]*log(ptime)+p[3]*zcov ehr(py, lambda=lambda3, plambda=c(1,1,1)) # or ehr(py, lambda=~log(ptime)+zcov, plambda=c(1,1,1)) # or ehr(py, lambda=~c0+b1*log(ptime)+c1*zcov, plambda=list(c0=1,c1=1,b1=1)) # gamma process with time-varying covariate lambda4 <- function(p) hgamma(ptime, p[1], exp(p[2]+p[3]*zcov)) ehr(py, lambda=lambda4, plambda=c(1,1,1)) # or ehr(py, lambda=~hgamma(ptime, b1, exp(c0+c1*zcov)), plambda=list(c0=1,c1=1,b1=1)) # or lambda5 <- function(p, linear) hgamma(ptime, p[1], exp(linear)) ehr(py, lambda=lambda5, linear=~zcov, plambda=c(1,1,1))
y <- c(5,3,2,4) # event indicator py <- pp(y) # time since previous event ptime <- tpast(y) # individual ID i <- c(1,1,2,2) id <- ident(y, i) # times and corresponding covariate values tx <- c(2,3,1,2,2,2,2) x <- c(1,2,2,1,2,2,1) zcov <- tvcov(y, x, tx) # Poisson process ehr(py, plambda=1) # Weibull process lambda1 <- function(p) p[1]+p[2]*log(ptime) ehr(py, lambda=lambda1, plambda=c(1,1)) # or ehr(py, lambda=~log(ptime), plambda=c(1,1)) # or ehr(py, lambda=~b0+b1*log(ptime), plambda=list(b0=1,b1=1)) # Poisson process with time-varying covariate lambda2 <- function(p) p[1]+p[2]*zcov ehr(py, lambda=lambda2, plambda=c(1,1)) # or ehr(py, lambda=~zcov, plambda=c(1,1)) # or ehr(py, lambda=~c0+c1*zcov, plambda=list(c0=1,c1=1)) # Weibull process with time-varying covariate lambda3 <- function(p) p[1]+p[2]*log(ptime)+p[3]*zcov ehr(py, lambda=lambda3, plambda=c(1,1,1)) # or ehr(py, lambda=~log(ptime)+zcov, plambda=c(1,1,1)) # or ehr(py, lambda=~c0+b1*log(ptime)+c1*zcov, plambda=list(c0=1,c1=1,b1=1)) # gamma process with time-varying covariate lambda4 <- function(p) hgamma(ptime, p[1], exp(p[2]+p[3]*zcov)) ehr(py, lambda=lambda4, plambda=c(1,1,1)) # or ehr(py, lambda=~hgamma(ptime, b1, exp(c0+c1*zcov)), plambda=list(c0=1,c1=1,b1=1)) # or lambda5 <- function(p, linear) hgamma(ptime, p[1], exp(linear)) ehr(py, lambda=lambda5, linear=~zcov, plambda=c(1,1,1))
autointensity
Plot Autointensity Function of a Point Process
bp
Create a Vector of Cumulative Numbers of Previous Events for a Point Process
coxre
Cox Proportional Hazards Model with Random Effect
cprocess
Counting Process Plot
ehr
Fit an Intensity Function to Event Histories
hboxcox
Log Hazard Function for a Box-Cox Process
hburr
Log Hazard Function for a Burr Process
hcauchy
Log Hazard Function for a Cauchy Process
hexp
Log Hazard Function for an Exponential (Poisson) Process
hgamma
Log Hazard Function for a Gamma Process
hgextval
Log Hazard Function for an Extreme Value Process
hggamma
Log Hazard Function for a Generalized Gamma Process
hglogis
Log Hazard Function for a Generalized Logistic Process
hgweibull
Log Hazard Function for a Generalized Weibull Process
hhjorth
Log Hazard Function for a Hjorth Process
hinvgauss
Log Hazard Function for a Inverse Gauss Process
hlaplace
Log Hazard Function for a Laplace Process
hlnorm
Log Hazard Function for a Log Normal Process
hlogis
Log Hazard Function for a Logistic Process
hnorm
Log Hazard Function for a Normal Process
hpareto
Log Hazard Function for a Pareto Process
hskewlaplace
Log Hazard Function for a Skew Laplace Process
hstudent
Log Hazard Function for a Student Process
hweibull
Log Hazard Function for a Weibull Process
ident
Create an Individual Identification Vector for a Point Process
kalsurv
Generalized Repeated Measurements Models for Event Histories
km
Kaplan-Meier Survival Curves
pbirth
Fit Overdispersed Count Data as a Birth Process
pp
Create a Point Process Vector from Times between Events
read.list
Read a List of Matrices of Unbalanced Repeated Measurements from a File
read.surv
Read a List of Vectors of Event Histories from a File
survkit
Weibull and Cox Models with Random Effects
tccov
Create a Vector of Time-constant Covariates for a Point Process
tpast
Create a Vector of Times Past since Previous Events for a Point Process
ttime
Create a Vector of Total Time Elapsed for each Individual for a Point Process
tvcov
Create a Vector of Time-varying Covariates for a Point Process
This function provides information about the Box-Cox
distribution with location parameter equal to m
, dispersion
equal to s
, and power transformation equal to f
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The Box-Cox distribution has density
where is the location parameter of the distribution,
is the dispersion,
is the family
parameter,
is the indicator function, and
.
gives a truncated normal distribution.
hboxcox(y, m, s, f)
hboxcox(y, m, s, f)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
f |
vector of power parameters. |
J.K. Lindsey
dnorm
for the normal or Gaussian distribution.
hboxcox(2, 5, 5, 2)
hboxcox(2, 5, 5, 2)
These functions provide information about the Burr distribution with
location parameter equal to m
, dispersion equal to
s
, and family parameter equal to f
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The Burr distribution has density
where is the location parameter of the distribution,
is the dispersion, and
is the family
parameter.
hburr(y, m, s, f)
hburr(y, m, s, f)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
f |
vector of family parameters. |
J.K. Lindsey
hburr(2, 5, 1, 2)
hburr(2, 5, 1, 2)
Log Hazard Function for a Cauchy Process
hcauchy(y, m, s)
hcauchy(y, m, s)
y |
Vector of times. |
m |
Location parameter. |
s |
Dispersion parameter. |
hcauchy
returns the log hazard function for a Cauchy process with
the given parameter values.
J.K. Lindsey
hboxcox
, hburr
,
hexp
, hgextval
,
hgamma
, hggamma
,
hhjorth
, hinvgauss
,
hlaplace
, hlnorm
,
hlogis
, hglogis
,
hnorm
, hstudent
,
hweibull
, hgweibull
.
hcauchy(1:10, 3, 2)
hcauchy(1:10, 3, 2)
Log Hazard Function for a Poisson Process
hexp(y, rate)
hexp(y, rate)
y |
Vector of times. |
rate |
Vector of rates. |
hexp
returns the log hazard function for a Poisson process with
the given parameter value.
J.K. Lindsey
hboxcox
, hburr
,
hexp
, hgextval
,
hgamma
, hggamma
,
hhjorth
, hinvgauss
,
hlaplace
, hlnorm
,
hlogis
, hglogis
,
hnorm
, hstudent
,
hweibull
, hgweibull
.
hexp(1:10, 3)
hexp(1:10, 3)
Log Hazard Function for a Gamma Process
hgamma(y, shape, rate=1, scale=1/rate)
hgamma(y, shape, rate=1, scale=1/rate)
y |
Vector of times. |
shape |
Shape parameter. |
rate |
Rate parameter. |
scale |
Scale parameter. |
hgamma
returns the log hazard function for a gamma process with
the given parameter values.
J.K. Lindsey
hboxcox
, hburr
,
hexp
, hgextval
,
hcauchy
, hggamma
,
hhjorth
, hinvgauss
,
hlaplace
, hlnorm
,
hlogis
, hglogis
,
hnorm
, hstudent
,
hweibull
, hgweibull
.
hgamma(1:10, 3, 2)
hgamma(1:10, 3, 2)
These functions provide information about the generalized extreme
value distribution with location parameter equal to m
, dispersion
equal to s
, and family parameter equal to f
:log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The generalized extreme value distribution has density
where is the location parameter of the distribution,
is the dispersion,
is the family
parameter,
is the indicator function, and
.
a truncated extreme value distribution.
hgextval(y, s, m, f)
hgextval(y, s, m, f)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
f |
vector of family parameters. |
J.K. Lindsey
dweibull
for the Weibull distribution.
hgextval(1, 2, 1, 2)
hgextval(1, 2, 1, 2)
These functions provide information about the generalized gamma
distribution with scale parameter equal to m
, shape equal
to s
, and family parameter equal to f
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The generalized gamma distribution has density
where is the scale parameter of the distribution,
is the shape, and
is the family
parameter.
yields a gamma distribution,
a
Weibull distribution, and
a
log normal distribution.
hggamma(y, s, m, f)
hggamma(y, s, m, f)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
f |
vector of family parameters. |
J.K. Lindsey
dgamma
for the gamma distribution,
dweibull
for the Weibull distribution, dlnorm
for the log normal distribution.
hggamma(2, 5, 4, 2)
hggamma(2, 5, 4, 2)
These functions provide information about the generalized logistic
distribution with location parameter equal to m
, dispersion equal
to s
, and family parameter equal to f
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The generalized logistic distribution has density
where is the location parameter of the distribution,
is the dispersion, and
is the family
parameter.
gives a logistic distribution.
hglogis(y, m, s, f)
hglogis(y, m, s, f)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
f |
vector of family parameters. |
J.K. Lindsey
dlogis
for the logistic distribution.
hglogis(5, 5, 1, 2)
hglogis(5, 5, 1, 2)
These functions provide information about the generalized Weibull
distribution, also called the exponentiated Weibull, with scale
parameter equal to m
, shape equal to s
, and family
parameter equal to f
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The generalized Weibull distribution has density
where is the scale parameter of the distribution,
is the shape, and
is the family
parameter.
gives a Weibull distribution, for
,
a generalized F distribution,
and for
,
a Burr type XII distribution.
hgweibull(y, s, m, f)
hgweibull(y, s, m, f)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
f |
vector of family parameters. |
J.K. Lindsey
dweibull
for the Weibull distribution,
df
for the F distribution,
dburr
for the Burr distribution.
hgweibull(5, 1, 3, 2)
hgweibull(5, 1, 3, 2)
These functions provide information about the Hjorth
distribution with location parameter equal to m
, dispersion equal
to s
, and family parameter equal to f
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The Hjorth distribution has density
where is the location parameter of the distribution,
is the dispersion, and
is the family
parameter.
hhjorth(y, m, s, f)
hhjorth(y, m, s, f)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
f |
vector of family parameters. |
J.K. Lindsey
hhjorth(5, 5, 5, 2)
hhjorth(5, 5, 5, 2)
These functions provide information about the inverse Gaussian
distribution with mean equal to m
and dispersion equal to
s
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The inverse Gaussian distribution has density
where is the mean of the distribution and
is the dispersion.
hinvgauss(y, m, s)
hinvgauss(y, m, s)
y |
vector of responses. |
m |
vector of means. |
s |
vector of dispersion parameters. |
J.K. Lindsey
dnorm
for the normal distribution and
dlnorm
for the Lognormal distribution.
hinvgauss(5, 5, 1)
hinvgauss(5, 5, 1)
These functions provide information about the Laplace distribution
with location parameter equal to m
and dispersion equal to
s
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The Laplace distribution has density
where is the location parameter of the distribution and
is the dispersion.
hlaplace(y, m=0, s=1)
hlaplace(y, m=0, s=1)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
J.K. Lindsey
dexp
for the exponential distribution and
dcauchy
for the Cauchy distribution.
hlaplace(5, 2, 1)
hlaplace(5, 2, 1)
Log Hazard Function for a Log Normal Process
hlnorm(y, m, s)
hlnorm(y, m, s)
y |
Vector of times. |
m |
Mean parameter. |
s |
Variance parameter. |
hlnorm
returns the log hazard function for a log normal
process with the given parameter values.
J.K. Lindsey
hboxcox
, hburr
,
hexp
, hgextval
,
hcauchy
, hgamma
,
hggamma
, hhjorth
,
hinvgauss
, hlaplace
,
hlogis
, hglogis
,
hnorm
, hstudent
,
hweibull
, hgweibull
.
hlnorm(1:10, 3, 2)
hlnorm(1:10, 3, 2)
Log Hazard Function for a Logistic Process
hlogis(y, m, s)
hlogis(y, m, s)
y |
Vector of times. |
m |
Location parameter. |
s |
Scale parameter. |
hlogis
returns the log hazard function for a logistic
process with the given parameter values.
J.K. Lindsey
hboxcox
, hburr
, hexp
,
hgextval
, hcauchy
, hgamma
,
hggamma
, hhjorth
, hinvgauss
,
hlaplace
, hlnorm
, hglogis
,
hnorm
, hstudent
, hweibull
,
hgweibull
.
hlogis(1:10, 3, 2)
hlogis(1:10, 3, 2)
Log Hazard Function for a Normal Process
hnorm(y, m, s)
hnorm(y, m, s)
y |
Vector of times. |
m |
Mean parameter. |
s |
Variance parameter. |
hnorm
returns the log hazard function for a normal
process with the given parameter values.
J.K. Lindsey
hboxcox
, hburr
,
hexp
, hgextval
,
hcauchy
, hgamma
,
hggamma
, hhjorth
,
hinvgauss
, hlaplace
,
hlogis
, hglogis
,
hlnorm
, hstudent
,
hweibull
, hgweibull
.
hnorm(1:10, 3, 2)
hnorm(1:10, 3, 2)
These functions provide information about the Pareto distribution
with location parameter equal to m
and dispersion equal to
s
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
The Pareto distribution has density
where is the mean parameter of the distribution and
is the dispersion.
This distribution can be obtained as a mixture distribution from the exponential distribution using a gamma mixing distribution.
hpareto(y, m, s)
hpareto(y, m, s)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
J.K. Lindsey
dexp
for the exponential distribution.
hpareto(5, 2, 2)
hpareto(5, 2, 2)
These functions provide information about the skew Laplace distribution
with location parameter equal to m
, dispersion equal to
s
, and skew equal to f
: log hazard.
(See 'rmutil' for the d/p/q/r boxcox functions density,
cumulative distribution, quantiles, and random generation).
For f=1
, this is an ordinary (symmetric) Laplace distribution.
The skew Laplace distribution has density
if and else
where is the location parameter of the distribution,
is the dispersion, and
is the skew.
The mean is given by
and the variance by
.
Note that this parametrization of the skew (family) parameter is different than that used for the multivariate skew Laplace distribution in 'growth::elliptic'.
hskewlaplace(y, m=0, s=1, f=1)
hskewlaplace(y, m=0, s=1, f=1)
y |
vector of responses. |
m |
vector of location parameters. |
s |
vector of dispersion parameters. |
f |
vector of skew parameters. |
J.K. Lindsey
dexp
for the exponential distribution,
dcauchy
for the Cauchy distribution, and
dlaplace
for the Laplace distribution.
hskewlaplace(5, 2, 1, 0.5)
hskewlaplace(5, 2, 1, 0.5)
Log Hazard Function for a Student t Process
hstudent(y, m, s, f)
hstudent(y, m, s, f)
y |
Vector of times. |
m |
Location parameter. |
s |
Scale parameter. |
f |
Degrees of freedom. |
hstudent
returns the log hazard function for a Student t
process with the given parameter values.
J.K. Lindsey
hboxcox
, hburr
,
hexp
, hgextval
,
hcauchy
, hgamma
,
hggamma
, hhjorth
,
hinvgauss
, hlaplace
,
hlogis
, hglogis
,
hnorm
, hnorm
,
hweibull
, hgweibull
.
hstudent(1:10, 3, 2, 5)
hstudent(1:10, 3, 2, 5)
Log Hazard Function for a Weibull Process
hweibull(y, s, m)
hweibull(y, s, m)
y |
Vector of times. |
s |
Shape parameter. |
m |
Scale parameter. |
hweibull
returns the log hazard function for a Weibull
process with the given parameter values.
J.K. Lindsey
hboxcox
, hburr
,
hexp
, hgextval
,
hcauchy
, hgamma
,
hggamma
, hhjorth
,
hinvgauss
, hlaplace
,
hlogis
, hglogis
,
hlnorm
, hnorm
,
hstudent
, hgweibull
.
hweibull(1:10, 1.5, 2)
hweibull(1:10, 1.5, 2)
ident
creates a vector of length sum(y)
by repeating the
values of individual identifiers for the times for use with
ehr
.
ident(y, id)
ident(y, id)
y |
Vector of times. |
id |
Vector of corresponding individual identifiers for who had which sequence of times. |
ident
creates a vector of length sum(y)
by repeating the
values of individual identifiers for the times for use with
ehr
.
J.K. Lindsey
bp
, ehr
,
pp
, tccov
,
tpast
, ttime
,
tvcov
.
y <- c(5,3,2,4) i <- c(1,1,2,2) id <- ident(y, i) id
y <- c(5,3,2,4) i <- c(1,1,2,2) id <- ident(y, i) id
kalsurv
is designed to handle event history models with
time-varying covariates. The distributions have two extra parameters
as compared to the functions specified by intensity
and are
generally longer tailed than those distributions. Dependence of
inter-event times can be through gamma frailties (a type of random
effect), with or without autoregression, or several kinds of serial
dependence by updating, as in Kalman filtering.
By default, a gamma mixture of the distribution specified in
intensity
is used, as the conditional distribution in the
serial
dependence models, and as a symmetric multivariate
(random effect) model for frailty
dependence. For example, with
a Weibull intensity
and frailty
dependence, this yields
a multivariate Burr distribution and with Markov
or
serial
dependence, univariate Burr conditional distributions.
If a value for pfamily
is used, the gamma mixture is replaced
by a power variance family mixture.
Nonlinear regression models can be supplied as formulae where
parameters are unknowns in which case factor variables cannot be used and
parameters must be scalars. (See finterp
.)
Marginal and individual profiles can be plotted using
mprofile
and iprofile
and
residuals with plot.residuals
.
kalsurv(response, intensity="exponential", distribution="Pareto", depend="independence", update="Markov", mu=NULL, shape=NULL, renewal=TRUE, density=FALSE, censor=NULL, delta=NULL, ccov=NULL, tvcov=NULL, preg=NULL, ptvc=NULL, pbirth=NULL, pintercept=NULL, pshape=NULL, pinitial=1, pdepend=NULL, pfamily=NULL, envir=parent.frame(), print.level=0, ndigit=10, gradtol=0.00001, steptol=0.00001, iterlim=100, fscale=1, typsize=abs(p), stepmax=10*sqrt(p%*%p))
kalsurv(response, intensity="exponential", distribution="Pareto", depend="independence", update="Markov", mu=NULL, shape=NULL, renewal=TRUE, density=FALSE, censor=NULL, delta=NULL, ccov=NULL, tvcov=NULL, preg=NULL, ptvc=NULL, pbirth=NULL, pintercept=NULL, pshape=NULL, pinitial=1, pdepend=NULL, pfamily=NULL, envir=parent.frame(), print.level=0, ndigit=10, gradtol=0.00001, steptol=0.00001, iterlim=100, fscale=1, typsize=abs(p), stepmax=10*sqrt(p%*%p))
response |
A list of vectors with times between events for
each individual, one matrix or dataframe of such times if all
individuals have the same number of events, or an object of class,
|
intensity |
The form of intensity function to be put in the distribution given by dist. Choices are exponential, Weibull, gamma, log normal, log logistic, log Cauchy, log Student, and gen(eralized) logistic. |
distribution |
The outer distribution. Choices are Pareto, gamma, and Weibull. |
depend |
Type of dependence. Choices are |
update |
Type of update for serial dependence. Choices are
|
mu |
A regression function for the location parameter or a
formula beginning with ~, specifying either a linear regression
function in the Wilkinson and Rogers notation or a general function
with named unknown parameters. Give the initial estimates in
|
shape |
A regression function for the shape parameter or a formula beginning with ~, specifying either a linear regression function in the Wilkinson and Rogers notation or a general function with named unknown parameters. It must yield one value per observation. |
renewal |
IF TRUE, a renewal process is modelled, with time reinitialized after each event. Otherwise, time is cumulated from the origin of observations. |
density |
If TRUE, the density of the function specified in
|
censor |
A vector of the same length as the number of individuals
containing a binary indicator, with a one indicating that the last
time period in the series terminated with an event and zero that it
was censored. For independence and frailty models, where response is
matrix, censor may also be a matrix of the same size. Ignored if
response has class, |
delta |
Scalar or vector giving the unit of measurement for each
response value, set to unity by default. For example, if a response is
measured to two decimals, delta=0.01. If the response has been
pretransformed, this must be multiplied by the Jacobian. This
transformation cannot contain unknown parameters. For example, with a
log transformation, |
ccov |
A vector or matrix containing time-constant baseline
covariates with one entry per individual, a model formula using
vectors of the same size, or an object of class, |
tvcov |
A list of matrices with time-varying covariate values,
observed at the event times in |
preg |
Initial parameter estimates for the regression model:
intercept plus one for each covariate in |
ptvc |
Initial parameter estimates for the coefficients of the
time-varying covariates, as many as in |
pbirth |
If supplied, this is the initial estimate for the coefficient of the birth model. |
pintercept |
The initial estimate of the intercept for the generalized logistic intensity. |
pshape |
An initial estimate for the shape parameter of the
intensity (except exponential intensity). If |
pinitial |
An initial estimate for the initial parameter. In
|
pdepend |
An initial estimate for the serial dependence
parameter. For |
pfamily |
An optional initial estimate for the second parameter
of a two-parameter power variance family mixture instead of the
default gamma mixture. This yields a gamma mixture as |
envir |
Environment in which model formulae are to be
interpreted or a data object of class, |
print.level |
|
ndigit |
|
gradtol |
|
steptol |
|
iterlim |
|
fscale |
|
typsize |
|
stepmax |
|
A list of classes kalsurv
and recursive
is returned.
J.K. Lindsey
coxre
,
finterp
,
gettvc
,
iprofile
,
mprofile
,
read.list
,
restovec
,
rmna
, tcctomat
,
tvctomat
.
treat <- c(0,0,1,1) tr <- tcctomat(treat) cens <- matrix(rbinom(20,1,0.9),ncol=5) times <- # matrix(rweibull(20,2,1+3*rep(treat,5)),ncol=5) matrix(c(1.36,0.18,0.84,0.65,1.44,1.79,1.04,0.43,1.35,1.63,2.15,1.15, 1.21,5.46,1.58,3.44,4.40,2.75,4.78,2.44),ncol=5,byrow=TRUE) times <- restovec(times, censor=cens) reps <- rmna(times, ccov=tr) # exponential intensity model with independence kalsurv(times, pinitial=0.5, preg=1, dep="independence", intensity="exponential") # Weibull intensity model with independence kalsurv(times, pinitial=0.5, preg=1, pshape=1, dep="independence", intensity="Weibull") # same model with serial update kalsurv(times, pinitial=0.5, pdep=0.1, preg=1, pshape=1, dep="serial", intensity="Weibull") # try power variance family instead of gamma distribution for mixture kalsurv(times, pinitial=0.5, pdep=0.1, preg=1, pshape=1, dep="serial", intensity="Weibull", pfamily=0.1) # treatment effect with log link kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, intensity="Weibull", ccov=treat) # or equivalently kalsurv(times, mu=~exp(a+b*treat), pinitial=0.1, preg=c(1,0), pshape=1, intensity="Weibull", envir=reps) # with identity link instead kalsurv(times, mu=~treat, pinitial=0.5, preg=c(1,0), pshape=1, intensity="Weibull") # or equivalently kalsurv(times, mu=~a+b*treat, pinitial=0.5, preg=c(1,0), pshape=1, intensity="Weibull", envir=reps) # add the birth model kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, intensity="Weibull", ccov=treat, pbirth=0) # try frailty dependence kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, dep="frailty", intensity="Weibull", ccov=treat) # add autoregression kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, dep="frailty", pdep=0.1, intensity="Weibull", ccov=treat) # switch to gamma intensity model kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, intensity="gamma", ccov=treat)
treat <- c(0,0,1,1) tr <- tcctomat(treat) cens <- matrix(rbinom(20,1,0.9),ncol=5) times <- # matrix(rweibull(20,2,1+3*rep(treat,5)),ncol=5) matrix(c(1.36,0.18,0.84,0.65,1.44,1.79,1.04,0.43,1.35,1.63,2.15,1.15, 1.21,5.46,1.58,3.44,4.40,2.75,4.78,2.44),ncol=5,byrow=TRUE) times <- restovec(times, censor=cens) reps <- rmna(times, ccov=tr) # exponential intensity model with independence kalsurv(times, pinitial=0.5, preg=1, dep="independence", intensity="exponential") # Weibull intensity model with independence kalsurv(times, pinitial=0.5, preg=1, pshape=1, dep="independence", intensity="Weibull") # same model with serial update kalsurv(times, pinitial=0.5, pdep=0.1, preg=1, pshape=1, dep="serial", intensity="Weibull") # try power variance family instead of gamma distribution for mixture kalsurv(times, pinitial=0.5, pdep=0.1, preg=1, pshape=1, dep="serial", intensity="Weibull", pfamily=0.1) # treatment effect with log link kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, intensity="Weibull", ccov=treat) # or equivalently kalsurv(times, mu=~exp(a+b*treat), pinitial=0.1, preg=c(1,0), pshape=1, intensity="Weibull", envir=reps) # with identity link instead kalsurv(times, mu=~treat, pinitial=0.5, preg=c(1,0), pshape=1, intensity="Weibull") # or equivalently kalsurv(times, mu=~a+b*treat, pinitial=0.5, preg=c(1,0), pshape=1, intensity="Weibull", envir=reps) # add the birth model kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, intensity="Weibull", ccov=treat, pbirth=0) # try frailty dependence kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, dep="frailty", intensity="Weibull", ccov=treat) # add autoregression kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, dep="frailty", pdep=0.1, intensity="Weibull", ccov=treat) # switch to gamma intensity model kalsurv(times, pinitial=0.5, preg=c(1,0), pshape=1, intensity="gamma", ccov=treat)
km
calculates the Kaplan-Meier estimates for survival.
To plot the survivor curve, use plot()
; for the empirical
intensity curve, use plot.intensity()
; for diagnostic curves to
choose a distribution to which the data might belong, use plot.dist()
.
km(times, censor, group=1, freq=1, cdf=FALSE) ## S3 method for class 'km' plot(x, add=FALSE, xlim=NULL, ylim=c(0,1), main=NULL, xlab="Time", ylab=NULL, lty=NULL, ...) ## S3 method for class 'km' plot.intensity(x, add=FALSE, xlab="Time", ylab="Hazard", type="l", lty=NULL, ...) ## S3 method for class 'km' plot.dist(x, ...)
km(times, censor, group=1, freq=1, cdf=FALSE) ## S3 method for class 'km' plot(x, add=FALSE, xlim=NULL, ylim=c(0,1), main=NULL, xlab="Time", ylab=NULL, lty=NULL, ...) ## S3 method for class 'km' plot.intensity(x, add=FALSE, xlab="Time", ylab="Hazard", type="l", lty=NULL, ...) ## S3 method for class 'km' plot.dist(x, ...)
times |
Vector of times to events or a list of vectors of such times for different individuals. |
censor |
Vector of censoring indicators corresponding to the vector of times or to the last time in each vector of a list. |
group |
Vector indicating to which group each individual belongs. |
freq |
Vector of frequencies for grouped data. |
cdf |
If TRUE, calculate the cdf instead of the survivor curve. |
x |
An object produced by |
add |
Plotting control options. |
main |
Plotting control options. |
type |
Plotting control options. |
ylab |
Plotting control options. |
xlab |
Plotting control options. |
xlim |
Plotting control options. |
ylim |
Plotting control options. |
lty |
Plotting control options. |
... |
Plotting control options. |
A matrix with class, km
, containing the Kaplan-Meier estimates
is returned.
J.K. Lindsey
surv <- rgamma(40,2,scale=5) cens <- rbinom(40,1,0.9) treat <- gl(2,20) plot(km(surv, cens, group=treat), main="",xlab="Months", ylab="Probability of deterioration") plot.dist(km(surv, cens, group=treat)) plot.intensity(km(surv, cens, group=treat),ylab="Risk of deterioration")
surv <- rgamma(40,2,scale=5) cens <- rbinom(40,1,0.9) treat <- gl(2,20) plot(km(surv, cens, group=treat), main="",xlab="Months", ylab="Probability of deterioration") plot.dist(km(surv, cens, group=treat)) plot.intensity(km(surv, cens, group=treat),ylab="Risk of deterioration")
pbirth
fits binomial, binomial exponential, binomial logistic,
binomial total, Poisson, Poisson exponential, negative binomial,
gen(eralized) negative binomial, and generalized negative binomial
processes as a birth process.
pbirth(frequencies, p, intensity="negative binomial", type="spectral decomposition", print.level=0, ndigit=10, gradtol=0.00001, steptol=0.00001, fscale=1, iterlim=100, typsize=abs(p), stepmax=10*sqrt(p%*%p))
pbirth(frequencies, p, intensity="negative binomial", type="spectral decomposition", print.level=0, ndigit=10, gradtol=0.00001, steptol=0.00001, fscale=1, iterlim=100, typsize=abs(p), stepmax=10*sqrt(p%*%p))
frequencies |
Vector of frequencies or a matrix with each row a different series of frequencies. |
p |
Vector of initial estimates. |
intensity |
The intensity function of the process: binomial, binomial exdponential, binomial logistic, binomial total, Poisson, Poisson exponential, negative binomial, or gen(eralized) negative binomial. |
type |
Algorithm used for matrix exponentiation: spectral decomposition or series approximation. |
print.level |
|
ndigit |
|
gradtol |
|
steptol |
|
iterlim |
|
fscale |
|
typsize |
|
stepmax |
|
J.K. Lindsey
Faddy, M.J. and Fenlon, J.S. (1999) Stochastic modelling of the invasion process of nematodes in fly larvae. Applied Statistics 48: 31-37.
y <- rnbinom(100,2,0.6) fr <- tabulate(y) pbirth(fr, p=log(-log(0.7)), intensity="Poisson", type="series") pbirth(fr, p=c(log(-log(0.7)),log(5)), intensity="negative binomial", type="series") pbirth(fr, p=c(log(-log(0.7)),log(5),-1), intensity="gen negative binomial", type="series")
y <- rnbinom(100,2,0.6) fr <- tabulate(y) pbirth(fr, p=log(-log(0.7)), intensity="Poisson", type="series") pbirth(fr, p=c(log(-log(0.7)),log(5)), intensity="negative binomial", type="series") pbirth(fr, p=c(log(-log(0.7)),log(5),-1), intensity="gen negative binomial", type="series")
Plot the empirical intensity curve for given times between events.
## S3 method for class 'intensity' plot(x, ...) ## Default S3 method: plot.intensity(x, censor=1, group=1, colour=TRUE, mix=1, ylim=c(0,1), ylab="p", xlab="Time", main="Empirical Hazard Function(s)", ...)
## S3 method for class 'intensity' plot(x, ...) ## Default S3 method: plot.intensity(x, censor=1, group=1, colour=TRUE, mix=1, ylim=c(0,1), ylab="p", xlab="Time", main="Empirical Hazard Function(s)", ...)
censor |
Vector of censoring indicators corresponding to the vector of times or to the last time in each vector of a list. |
group |
Vector indicating to which group each individual belongs. |
colour |
Use a different colour for each curve. |
x |
An object produced by |
mix |
... |
main |
Plotting control options. |
ylab |
Plotting control options. |
xlab |
Plotting control options. |
ylim |
Plotting control options. |
... |
Plotting control options. |
J.K. Lindsey
surv <- rgamma(40,2,scale=5) cens <- rbinom(40,1,0.9) treat <- gl(2,20) plot(km(surv, cens, group=treat), main="",xlab="Months", ylab="Probability of deterioration") plot.dist(km(surv, cens, group=treat)) plot.intensity(km(surv, cens, group=treat),ylab="Risk of deterioration")
surv <- rgamma(40,2,scale=5) cens <- rbinom(40,1,0.9) treat <- gl(2,20) plot(km(surv, cens, group=treat), main="",xlab="Months", ylab="Probability of deterioration") plot.dist(km(surv, cens, group=treat)) plot.intensity(km(surv, cens, group=treat),ylab="Risk of deterioration")
pp
creates a vector of length sum(y)
of zeroes with a one
at the end of each uncensored time interval for use with
ehr
.
pp(y, censor=1)
pp(y, censor=1)
y |
Vector of times. |
censor |
Vector of censoring indicators. |
pp
creates a vector of length sum(y)
of zeroes with a one
at the end of each uncensored time interval for use with
ehr
.
J.K. Lindsey
bp
, ehr
,
ident
, tccov
,
tpast
, ttime
,
tvcov
.
y <- c(5,3,2,4) py <- pp(y) py
y <- c(5,3,2,4) py <- pp(y) py
survfit
was written in Fortran by Dr. V. Ducrocq (INRA, France:
[email protected]) and Dr. J. Soelkner (Vienna:
[email protected]) 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.
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)
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)
times |
Vector of times (events, right-censoring, change in time-varying covariate, left-truncation). |
censor |
Corresponding vector of censoring indicators. 1: event; 0: censored; -1: change of time-varying covariate; -2: left-truncation time. |
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. |
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. |
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. |
id |
A variable giving individual identification numbers (starting at one). If not supplied, all times are assumed to refer to different individuals. |
model |
Weibull or Cox model, or Kaplan-Meier estimates. |
baseline |
If TRUE, the baseline values are calculated for the Cox model. |
residuals |
If TRUE, calculate residuals (only for Cox model). |
survival |
Calculate values of the survival function at
|
svalues |
A vector of quantile values (between 0 and 100),
spacing and maximum for equally-spaced, or specific times for
|
valrho |
A fixed value of the Weibull power parameter if it is not to be estimated. |
constraints |
By default, the category of each factor variable
with the |
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. |
dist |
The distribution of the random effect: loggamma, normal, or multivariate (normal). |
random |
A factor variable specifying the random effect. |
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. |
moments |
Estimate the first three moments of the random effect as well as the mode. |
rule |
For the multivariate normal random effect, the genetic
relationships: |
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. |
integrate |
A factor variable to integrate out as the log-gamma random effect in a Weibull model. (Not available for the Cox model.) |
jointmode |
If TRUE, the log-gamma variance parameter is
estimated simultaneously with the other parameters using the
information in |
within |
A second factor variable (within the |
converge |
The convergence criterion, by default 1.e-8. |
iterlim |
Maximum number of iterations. |
V. Ducrocq, J. Soelkner, and J.K. Lindsey
# 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 ## Not run: 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) ## End(Not run) # # 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))
# 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 ## Not run: 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) ## End(Not run) # # 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))
tccov
creates a vector of length sum(y)
of time-constant
covariates for use with ehr
. id
must be numbered
consecutively. x
must have one value for each distinct id
,
tccov(y, x, id)
tccov(y, x, id)
y |
Vector of times. |
x |
Vector covariate. |
id |
Vector of corresponding individual identifiers for who had which sequence of times. |
tccov
creates a vector of length sum(y)
of time-constant
covariates for use with ehr
. id
must be numbered
consecutively. x
must have one value for each distinct id
,
J.K. Lindsey
bp
, ehr
,
ident
, pp
,
tpast
, ttime
,
tvcov
.
y <- c(5,3,2,4) id <- c(1,1,2,2) x <- c(5.2,3.1) xcov <- tccov(y, x, id) xcov
y <- c(5,3,2,4) id <- c(1,1,2,2) x <- c(5.2,3.1) xcov <- tccov(y, x, id) xcov
tpast
creates a vector of length sum(y)
of times since the
immediately preceding event occurred for use with ehr
.
tpast(y)
tpast(y)
y |
Vector of times. |
tpast
creates a vector of length sum(y)
of times since the
immediately preceding event occurred for use with ehr
.
J.K. Lindsey
bp
, ehr
,
ident
, pp
,
tccov
, ttime
,
tvcov
.
y <- c(5,3,2,4) ptime <- tpast(y) ptime
y <- c(5,3,2,4) ptime <- tpast(y) ptime
ttime
creates a vector of length sum(y)
of times since
each individual began for use with ehr
.
ttime(y, id)
ttime(y, id)
y |
Vector of times. |
id |
Vector of corresponding individual identifiers for who had which sequence of times. |
ttime
creates a vector of length sum(y)
of times since
each individual began for use with ehr
.
J.K. Lindsey
bp
, ehr
,
ident
, pp
,
tccov
, tpast
,
tvcov
.
y <- c(5,3,2,4) id <- c(1,1,2,2) itime <- ttime(y, id) itime
y <- c(5,3,2,4) id <- c(1,1,2,2) itime <- ttime(y, id) itime
tvcov
creates a vector of length sum(y)
of time-varying
covariates for use with ehr
. It may also be used to create
weight vectors.
tvcov(y, x, tx)
tvcov(y, x, tx)
y |
Vector of times. |
x |
Vector covariate. |
tx |
Vector of times at which x changes. |
tvcov
creates a vector of length sum(y)
of time-varying
covariates for use with ehr
. It may also be used to create
weight vectors.
J.K. Lindsey
bp
, ehr
,
ident
, pp
,
tccov
, tpast
,
ttime
.
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
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