EVOLUTION-MANAGER
Edit File: predict.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: Predictions for a Cox 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 predict.coxph {survival}"><tr><td>predict.coxph {survival}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Predictions for a Cox model </h2> <h3>Description</h3> <p>Compute fitted values and regression terms for a model fitted by <code><a href="coxph.html">coxph</a></code> </p> <h3>Usage</h3> <pre> ## S3 method for class 'coxph' predict(object, newdata, type=c("lp", "risk", "expected", "terms", "survival"), se.fit=FALSE, na.action=na.pass, terms=names(object$assign), collapse, reference=c("strata", "sample"), ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>object</code></td> <td> <p>the results of a coxph fit. </p> </td></tr> <tr valign="top"><td><code>newdata</code></td> <td> <p>Optional new data at which to do predictions. If absent predictions are for the data frame used in the original fit. When coxph has been called with a formula argument created in another context, i.e., coxph has been called within another function and the formula was passed as an argument to that function, there can be problems finding the data set. See the note below. </p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>the type of predicted value. Choices are the linear predictor (<code>"lp"</code>), the risk score exp(lp) (<code>"risk"</code>), the expected number of events given the covariates and follow-up time (<code>"expected"</code>), and the terms of the linear predictor (<code>"terms"</code>). The survival probability for a subject is equal to exp(-expected). </p> </td></tr> <tr valign="top"><td><code>se.fit</code></td> <td> <p>if TRUE, pointwise standard errors are produced for the predictions. </p> </td></tr> <tr valign="top"><td><code>na.action</code></td> <td> <p>applies only when the <code>newdata</code> argument is present, and defines the missing value action for the new data. The default is to include all observations. When there is no newdata, then the behavior of missing is dictated by the na.action option of the original fit.</p> </td></tr> <tr valign="top"><td><code>terms</code></td> <td> <p>if type="terms", this argument can be used to specify which terms should be included; the default is all. </p> </td></tr> <tr valign="top"><td><code>collapse</code></td> <td> <p>optional vector of subject identifiers. If specified, the output will contain one entry per subject rather than one entry per observation. </p> </td></tr> <tr valign="top"><td><code>reference</code></td> <td> <p>reference for centering predictions, see details below</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>For future methods</p> </td></tr> </table> <h3>Details</h3> <p>The Cox model is a <em>relative</em> risk model; predictions of type "linear predictor", "risk", and "terms" are all relative to the sample from which they came. By default, the reference value for each of these is the mean covariate within strata. The primary underlying reason is statistical: a Cox model only predicts relative risks between pairs of subjects within the same strata, and hence the addition of a constant to any covariate, either overall or only within a particular stratum, has no effect on the fitted results. Using the <code>reference="strata"</code> option causes this to be true for predictions as well. (There have been occasional requests for reference="zero", i.e., a hypothetical subject with all covariates equal to zero, in order to match certain other packages' results. The issue is that the results are often silly, e.g., risk relative to a subject with height, weight, or blood pressure of zero.) </p> <p>When the results of <code>predict</code> are used in further calculations it may be desirable to use a fixed reference level. Use of <code>reference="sample"</code> will use the overall means, and agrees with the <code>linear.predictors</code> component of the coxph object (which uses the overall mean for backwards compatability with older code). Predictions of <code>type="terms"</code> are almost invariably passed forward to further calculation, so for these we default to using the sample as the reference. </p> <p>Predictions of type "expected" incorporate the baseline hazard and are thus absolute instead of relative; the <code>reference</code> option has no effect on these. These values depend on the follow-up time for the future subjects as well as covariates so the <code>newdata</code> argument needs to include both the right and <em>left</em> hand side variables from the formula. (The status variable will not be used, but is required since the underlying code needs to reconstruct the entire formula.) </p> <p>Models that contain a <code>frailty</code> term are a special case: due to the technical difficulty, when there is a <code>newdata</code> argument the predictions will always be for a random effect of zero. </p> <h3>Value</h3> <p>a vector or matrix of predictions, or a list containing the predictions (element "fit") and their standard errors (element "se.fit") if the se.fit option is TRUE. </p> <h3>Note</h3> <p>Some predictions can be obtained directly from the coxph object, and for others it is necessary for the routine to have the entirety of the original data set, e.g., for type = <code>terms</code> or if standard errors are requested. This extra information is saved in the coxph object if <code>model=TRUE</code>, if not the original data is reconstructed. If it is known that such residuals will be required overall execution will be slightly faster if the model information is saved. </p> <p>In some cases the reconstruction can fail. The most common is when coxph has been called inside another function and the formula was passed as one of the arguments to that enclosing function. Another is when the data set has changed between the original call and the time of the prediction call. In each of these the simple solution is to add <code>model=TRUE</code> to the original coxph call. </p> <h3>See Also</h3> <p><code><a href="../../stats/html/predict.html">predict</a></code>,<code><a href="coxph.html">coxph</a></code>,<code><a href="../../stats/html/termplot.html">termplot</a></code> </p> <h3>Examples</h3> <pre> options(na.action=na.exclude) # retain NA in predictions fit <- coxph(Surv(time, status) ~ age + ph.ecog + strata(inst), lung) #lung data set has status coded as 1/2 mresid <- (lung$status-1) - predict(fit, type='expected') #Martingale resid predict(fit,type="lp") predict(fit,type="expected") predict(fit,type="risk",se.fit=TRUE) predict(fit,type="terms",se.fit=TRUE) # For someone who demands reference='zero' pzero <- function(fit) predict(fit, reference="sample") + sum(coef(fit) * fit$means, na.rm=TRUE) </pre> <hr /><div style="text-align: center;">[Package <em>survival</em> version 2.44-1.1 <a href="00Index.html">Index</a>]</div> </body></html>