EVOLUTION-MANAGER
Edit File: coxph.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Additive Cox Proportional Hazard Model</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for cox.ph {mgcv}"><tr><td>cox.ph {mgcv}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Additive Cox Proportional Hazard Model</h2> <h3>Description</h3> <p>The <code>cox.ph</code> family implements the Cox Proportional Hazards model with Peto's correction for ties, optional stratification, and estimation by penalized partial likelihood maximization, for use with <code><a href="gam.html">gam</a></code>. In the model formula, event time is the response. Under stratification the response has two columns: time and a numeric index for stratum. The <code>weights</code> vector provides the censoring information (0 for censoring, 1 for event). <code>cox.ph</code> deals with the case in which each subject has one event/censoring time and one row of covariate values. When each subject has several time dependent covariates see <code><a href="coxpht.html">cox.pht</a></code>. </p> <p>See example below for conditional logistic regression. </p> <h3>Usage</h3> <pre> cox.ph(link="identity") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>link</code></td> <td> <p>currently (and possibly for ever) only <code>"identity"</code> supported.</p> </td></tr> </table> <h3>Details</h3> <p>Used with <code><a href="gam.html">gam</a></code> to fit Cox Proportional Hazards models to survival data. The model formula will have event/censoring times on the left hand side and the linear predictor specification on the right hand side. Censoring information is provided by the <code>weights</code> argument to <code>gam</code>, with 1 indicating an event and 0 indicating censoring. </p> <p>Stratification is possible, allowing for different baseline hazards in different strata. In that case the response has two columns: the first is event/censoring time and the second is a numeric stratum index. See below for an example. </p> <p>Prediction from the fitted model object (using the <code>predict</code> method) with <code>type="response"</code> will predict on the survivor function scale. This requires evaluation times to be provided as well as covariates (see example). Also see example code below for extracting the cumulative baseline hazard/survival directly. Martingale or deviance residuals can be extracted. The <code>fitted.values</code> stored in the model object are survival function estimates for each subject at their event/censoring time. </p> <p>Estimation of model coefficients is by maximising the log-partial likelihood penalized by the smoothing penalties. See e.g. Hastie and Tibshirani, 1990, section 8.3. for the partial likelihood used (with Peto's approximation for ties), but note that optimization of the partial likelihood does not follow Hastie and Tibshirani. See Klein amd Moeschberger (2003) for estimation of residuals, the cumulative baseline hazard, survival function and associated standard errors (the survival standard error expression has a typo). </p> <p>The percentage deviance explained reported for Cox PH models is based on the sum of squares of the deviance residuals, as the model deviance, and the sum of squares of the deviance residuals when the covariate effects are set to zero, as the null deviance. The same baseline hazard estimate is used for both. </p> <p>This family deals efficiently with the case in which each subject has one event/censoring time and one row of covariate values. For studies in which there are multiple time varying covariate measures for each subject then the equivalent Poisson model should be fitted to suitable pseudodata using <code>bam(...,discrete=TRUE)</code>. See <code><a href="coxpht.html">cox.pht</a></code>. </p> <h3>Value</h3> <p>An object inheriting from class <code>general.family</code>. </p> <h3>References</h3> <p>Hastie and Tibshirani (1990) Generalized Additive Models, Chapman and Hall. </p> <p>Klein, J.P and Moeschberger, M.L. (2003) Survival Analysis: Techniques for Censored and Truncated Data (2nd ed.) Springer. </p> <p>Wood, S.N., N. Pya and B. Saefken (2016), Smoothing parameter and model selection for general smooth models. Journal of the American Statistical Association 111, 1548-1575 <a href="http://dx.doi.org/10.1080/01621459.2016.1180986">http://dx.doi.org/10.1080/01621459.2016.1180986</a> </p> <h3>See Also</h3> <p><code><a href="coxpht.html">cox.pht</a></code></p> <h3>Examples</h3> <pre> library(mgcv) library(survival) ## for data col1 <- colon[colon$etype==1,] ## concentrate on single event col1$differ <- as.factor(col1$differ) col1$sex <- as.factor(col1$sex) b <- gam(time~s(age,by=sex)+sex+s(nodes)+perfor+rx+obstruct+adhere, family=cox.ph(),data=col1,weights=status) summary(b) plot(b,pages=1,all.terms=TRUE) ## plot effects plot(b$linear.predictors,residuals(b)) ## plot survival function for patient j... np <- 300;j <- 6 newd <- data.frame(time=seq(0,3000,length=np)) dname <- names(col1) for (n in dname) newd[[n]] <- rep(col1[[n]][j],np) newd$time <- seq(0,3000,length=np) fv <- predict(b,newdata=newd,type="response",se=TRUE) plot(newd$time,fv$fit,type="l",ylim=c(0,1),xlab="time",ylab="survival") lines(newd$time,fv$fit+2*fv$se.fit,col=2) lines(newd$time,fv$fit-2*fv$se.fit,col=2) ## crude plot of baseline survival... plot(b$family$data$tr,exp(-b$family$data$h),type="l",ylim=c(0,1), xlab="time",ylab="survival") lines(b$family$data$tr,exp(-b$family$data$h + 2*b$family$data$q^.5),col=2) lines(b$family$data$tr,exp(-b$family$data$h - 2*b$family$data$q^.5),col=2) lines(b$family$data$tr,exp(-b$family$data$km),lty=2) ## Kaplan Meier ## stratification example, with 2 randomly allocated strata ## so that results should be similar to previous.... col1$strata <- sample(1:2,nrow(col1),replace=TRUE) bs <- gam(cbind(time,strata)~s(age,by=sex)+sex+s(nodes)+perfor+rx+obstruct+adhere, family=cox.ph(),data=col1,weights=status) plot(bs,pages=1,all.terms=TRUE) ## plot effects ## baseline survival plots by strata... for (i in 1:2) { ## loop over strata ## create index picking out elements of stored hazard info for this stratum... ind <- which(bs$family$data$tr.strat == i) if (i==1) plot(bs$family$data$tr[ind],exp(-bs$family$data$h[ind]),type="l",ylim=c(0,1), xlab="time",ylab="survival",lwd=2,col=i) else lines(bs$family$data$tr[ind],exp(-bs$family$data$h[ind]),lwd=2,col=i) lines(bs$family$data$tr[ind],exp(-bs$family$data$h[ind] + 2*bs$family$data$q[ind]^.5),lty=2,col=i) ## upper ci lines(bs$family$data$tr[ind],exp(-bs$family$data$h[ind] - 2*bs$family$data$q[ind]^.5),lty=2,col=i) ## lower ci lines(bs$family$data$tr[ind],exp(-bs$family$data$km[ind]),col=i) ## KM } ## Simple simulated known truth example... ph.weibull.sim <- function(eta,gamma=1,h0=.01,t1=100) { lambda <- h0*exp(eta) n <- length(eta) U <- runif(n) t <- (-log(U)/lambda)^(1/gamma) d <- as.numeric(t <= t1) t[!d] <- t1 list(t=t,d=d) } n <- 500;set.seed(2) x0 <- runif(n, 0, 1);x1 <- runif(n, 0, 1) x2 <- runif(n, 0, 1);x3 <- runif(n, 0, 1) f0 <- function(x) 2 * sin(pi * x) f1 <- function(x) exp(2 * x) f2 <- function(x) 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10 f3 <- function(x) 0*x f <- f0(x0) + f1(x1) + f2(x2) g <- (f-mean(f))/5 surv <- ph.weibull.sim(g) surv$x0 <- x0;surv$x1 <- x1;surv$x2 <- x2;surv$x3 <- x3 b <- gam(t~s(x0)+s(x1)+s(x2,k=15)+s(x3),family=cox.ph,weights=d,data=surv) plot(b,pages=1) ## conditional logistic regression models are often estimated using the ## cox proportional hazards partial likelihood with a strata for each ## case-control group. A dummy vector of times is created (all equal). ## The following compares to 'clogit' for a simple case. Note that ## the gam log likelihood is not exact if there is more than one case ## per stratum, corresponding to clogit's approximate method. library(survival);library(mgcv) infert$dumt <- rep(1,nrow(infert)) mg <- gam(cbind(dumt,stratum) ~ spontaneous + induced, data=infert, family=cox.ph,weights=case) ms <- clogit(case ~ spontaneous + induced + strata(stratum), data=infert, method="approximate") summary(mg)$p.table[1:2,]; ms </pre> <hr /><div style="text-align: center;">[Package <em>mgcv</em> version 1.8-28 <a href="00Index.html">Index</a>]</div> </body></html>