| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
| <title>MADlib: Cox-Proportional Hazards Regression</title> |
| |
| <link href="tabs.css" rel="stylesheet" type="text/css"/> |
| <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| <link href="navtree.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="jquery.js"></script> |
| <script type="text/javascript" src="resize.js"></script> |
| <script type="text/javascript" src="navtree.js"></script> |
| <script type="text/javascript"> |
| $(document).ready(initResizable); |
| </script> |
| <link href="search/search.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="search/search.js"></script> |
| <script type="text/javascript"> |
| $(document).ready(function() { searchBox.OnSelectItem(0); }); |
| </script> |
| <script src="../mathjax/MathJax.js"> |
| MathJax.Hub.Config({ |
| extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"], |
| jax: ["input/TeX","output/HTML-CSS"], |
| }); |
| </script> |
| </head> |
| <body> |
| <div id="top"><!-- do not remove this div! --> |
| |
| |
| <div id="titlearea"> |
| <table cellspacing="0" cellpadding="0"> |
| <tbody> |
| <tr style="height: 56px;"> |
| |
| |
| <td style="padding-left: 0.5em;"> |
| <div id="projectname">MADlib |
|  <span id="projectnumber">0.6</span> <span style="font-size:10pt; font-style:italic"><a href="../latest/./group__grp__cox__prop__hazards.html"> A newer version is available</a></span> |
| </div> |
| <div id="projectbrief">User Documentation</div> |
| </td> |
| |
| |
| |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| |
| <!-- Generated by Doxygen 1.7.5.1 --> |
| <script type="text/javascript"> |
| var searchBox = new SearchBox("searchBox", "search",false,'Search'); |
| </script> |
| <script type="text/javascript" src="dynsections.js"></script> |
| <div id="navrow1" class="tabs"> |
| <ul class="tablist"> |
| <li><a href="index.html"><span>Main Page</span></a></li> |
| <li><a href="modules.html"><span>Modules</span></a></li> |
| <li><a href="files.html"><span>Files</span></a></li> |
| <li> |
| <div id="MSearchBox" class="MSearchBoxInactive"> |
| <span class="left"> |
| <img id="MSearchSelect" src="search/mag_sel.png" |
| onmouseover="return searchBox.OnSearchSelectShow()" |
| onmouseout="return searchBox.OnSearchSelectHide()" |
| alt=""/> |
| <input type="text" id="MSearchField" value="Search" accesskey="S" |
| onfocus="searchBox.OnSearchFieldFocus(true)" |
| onblur="searchBox.OnSearchFieldFocus(false)" |
| onkeyup="searchBox.OnSearchFieldChange(event)"/> |
| </span><span class="right"> |
| <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> |
| </span> |
| </div> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <div id="side-nav" class="ui-resizable side-nav-resizable"> |
| <div id="nav-tree"> |
| <div id="nav-tree-contents"> |
| </div> |
| </div> |
| <div id="splitbar" style="-moz-user-select:none;" |
| class="ui-resizable-handle"> |
| </div> |
| </div> |
| <script type="text/javascript"> |
| initNavTree('group__grp__cox__prop__hazards.html',''); |
| </script> |
| <div id="doc-content"> |
| <div class="header"> |
| <div class="headertitle"> |
| <div class="title">Cox-Proportional Hazards Regression</div> </div> |
| <div class="ingroups"><a class="el" href="group__grp__suplearn.html">Supervised Learning</a></div></div> |
| <div class="contents"> |
| <div id="dynsection-0" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;"> |
| <img id="dynsection-0-trigger" src="closed.png" alt="+"/> Collaboration diagram for Cox-Proportional Hazards Regression:</div> |
| <div id="dynsection-0-summary" class="dynsummary" style="display:block;"> |
| </div> |
| <div id="dynsection-0-content" class="dyncontent" style="display:none;"> |
| <center><table><tr><td><div class="center"><iframe scrolling="no" frameborder="0" src="group__grp__cox__prop__hazards.svg" width="472" height="40"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe> |
| </div> |
| </td></tr></table></center> |
| </div> |
| <dl class="user"><dt><b>About:</b></dt><dd>Proportional-Hazard models enable the comparison of various survival models. These survival models are functions describing the probability of an one-item event (prototypically, this event is death) with respect to time. The interval of time before death occurs is the survival time. Let T be a random variable representing the survival time, with a cumulative probability function P(t). Informally, P(t) is the probability that death has happened before time t.</dd></dl> |
| <p>Generally, applications start with a list of \( \boldsymbol n \) observations, each with \( \boldsymbol m \) covariates and a time of death. From this \( \boldsymbol n \times m \) matrix, we would like to derive the correlation between the covariates and the hazard function. This amounts to finding the parameters \( \boldsymbol \beta \) that best fit the model described below.</p> |
| <p>Let us define:</p> |
| <ul> |
| <li>\( \boldsymbol t \in \mathbf R^{m} \) denote the vector of observed dependent variables, with \( n \) rows.</li> |
| <li>\( X \in \mathbf R^{m} \) denote the design matrix with \( m \) columns and \( n \) rows, containing all observed vectors of independent variables \( \boldsymbol x_i \) as rows.</li> |
| <li>\( R(t_i) \) denote the set of observations still alive at time \( t_i \)</li> |
| </ul> |
| <p>Note that this model <b>does not</b> include a <b>constant term</b>, and the data cannot contain a column of 1s.</p> |
| <p>By definition, </p> |
| <p class="formulaDsp"> |
| \[ P[T_k = t_i | \boldsymbol R(t_i)] = \frac{e^{\beta^T x_k} }{ \sum_{j \in R(t_i)} e^{\beta^T x_j}}. \,. \] |
| </p> |
| <p>The <b>partial likelihood </b>function can now be generated as the product of conditional probabilities: </p> |
| <p class="formulaDsp"> |
| \[ \mathcal L = \prod_{i = 1}^n \left( \frac{e^{\beta^T x_i}}{ \sum_{j \in R(t_i)} e^{\beta^T x_j}} \right). \] |
| </p> |
| <p>The log-likelihood form of this equation is </p> |
| <p class="formulaDsp"> |
| \[ L = \sum_{i = 1}^n \left[ \beta^T x_i - \log\left(\sum_{j \in R(t_i)} e^{\beta^T x_j }\right) \right]. \] |
| </p> |
| <p>Using this score function and Hessian matrix, the partial likelihood can be maximized using the <b> Newton-Raphson algorithm </b>.<b> Breslow's method </b> is used to resolved tied times of deaths. The time of death for two records are considered "equal" if they differ by less than 1.0e-6</p> |
| <p>The inverse of the Hessian matrix, evaluated at the estimate of \( \boldsymbol \beta \), can be used as an <b>approximate variance-covariance matrix </b> for the estimate, and used to produce approximate <b>standard errors</b> for the regression coefficients.</p> |
| <p class="formulaDsp"> |
| \[ \mathit{se}(c_i) = \left( (H)^{-1} \right)_{ii} \,. \] |
| </p> |
| <p> The Wald z-statistic is </p> |
| <p class="formulaDsp"> |
| \[ z_i = \frac{c_i}{\mathit{se}(c_i)} \,. \] |
| </p> |
| <p>The Wald \( p \)-value for coefficient \( i \) gives the probability (under the assumptions inherent in the Wald test) of seeing a value at least as extreme as the one observed, provided that the null hypothesis ( \( c_i = 0 \)) is true. Letting \( F \) denote the cumulative density function of a standard normal distribution, the Wald \( p \)-value for coefficient \( i \) is therefore </p> |
| <p class="formulaDsp"> |
| \[ p_i = \Pr(|Z| \geq |z_i|) = 2 \cdot (1 - F( |z_i| )) \] |
| </p> |
| <p> where \( Z \) is a standard normally distributed random variable.</p> |
| <p>The condition number is computed as \( \kappa(H) \) during the iteration immediately <em>preceding</em> convergence (i.e., \( A \) is computed using the coefficients of the previous iteration). A large condition number (say, more than 1000) indicates the presence of significant multicollinearity.</p> |
| <dl class="user"><dt><b>Input:</b></dt><dd></dd></dl> |
| <p>The training data is expected to be of the following form:<br/> |
| </p> |
| <pre>{TABLE|VIEW} <em>sourceName</em> ( |
| ... |
| <em>dependentVariable</em> FLOAT8, |
| <em>independentVariables</em> FLOAT8[], |
| ... |
| )</pre><p> Note: Dependent Variables refer to the time of death. There is no need to pre-sort the data. Additionally, all the data is assumed</p> |
| <dl class="user"><dt><b>Usage:</b></dt><dd><ul> |
| <li>Get vector of coefficients \( \boldsymbol \beta \) and all diagnostic statistics:<br/> |
| <pre>SELECT * FROM <a class="el" href="cox__prop__hazards_8sql__in.html#a9c04e1fd1353bb3cfb942b6251851179">cox_prop_hazards</a>( |
| '<em>sourceName</em>', '<em>dependentVariable</em>', '<em>independentVariables</em>' |
| [, <em>numberOfIterations</em> [, '<em>optimizer</em>' [, <em>precision</em> ] ] ] |
| );</pre> Output: Output: <pre>coef | log_likelihood | std_err | z_stats | p_values | condition_no | num_iterations |
| ... |
| </pre></li> |
| <li>Get vector of coefficients \( \boldsymbol \beta \):<br/> |
| <pre>SELECT (<a class="el" href="cox__prop__hazards_8sql__in.html#a9c04e1fd1353bb3cfb942b6251851179">cox_prop_hazards</a>('<em>sourceName</em>', '<em>dependentVariable</em>', '<em>independentVariables</em>')).coef;</pre></li> |
| <li>Get a subset of the output columns, e.g., only the array of coefficients \( \boldsymbol \beta \), the log-likelihood of determination: <pre>SELECT coef, log_likelihood |
| FROM <a class="el" href="cox__prop__hazards_8sql__in.html#a9c04e1fd1353bb3cfb942b6251851179">cox_prop_hazards</a>('<em>sourceName</em>', '<em>dependentVariable</em>', '<em>independentVariables</em>');</pre></li> |
| </ul> |
| </dd></dl> |
| <dl class="user"><dt><b>Examples:</b></dt><dd></dd></dl> |
| <ol type="1"> |
| <li>Create the sample data set: <div class="fragment"><pre class="fragment"> |
| sql> SELECT * FROM data; |
| val | time |
| ------------|-------------- |
| {0,1.95} | 35 |
| {0,2.20} | 28 |
| {1,1.45} | 32 |
| {1,5.25} | 31 |
| {1,0.38} | 21 |
| ... |
| </pre></div></li> |
| <li>Run the cox regression function: <div class="fragment"><pre class="fragment"> |
| sql> SELECT * FROM cox_prop_hazards('data', 'val', 'time', 100, 'newto', 0.001); |
| ---------------|-------------------------------------------------------------- |
| coef | {0.881089349817059,-0.0756817768938055} |
| log_likelihood | -4.46535157957394 |
| std_err | {1.16954914708414,0.338426252282655} |
| z_stats | {0.753356711368689,-0.223628410729811} |
| p_values | {0.451235588326831,0.823046454908087} |
| condition_no | 12.1135391339082 |
| num_iterations | 4 |
| |
| </pre></div></li> |
| </ol> |
| <dl class="user"><dt><b>Literature:</b></dt><dd></dd></dl> |
| <p>A somewhat random selection of nice write-ups, with valuable pointers into further literature:</p> |
| <p>[1] John Fox: Cox Proportional-Hazards Regression for Survival Data, Appendix to An R and S-PLUS companion to Applied Regression Feb 2012, <a href="http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf">http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf</a></p> |
| <p>[2] Stephen J Walters: What is a Cox model? <a href="http://www.medicine.ox.ac.uk/bandolier/painres/download/whatis/cox_model.pdf">http://www.medicine.ox.ac.uk/bandolier/painres/download/whatis/cox_model.pdf</a></p> |
| <dl class="note"><dt><b>Note:</b></dt><dd>Source and column names have to be passed as strings (due to limitations of the SQL syntax).</dd></dl> |
| <dl class="see"><dt><b>See also:</b></dt><dd>File <a class="el" href="cox__prop__hazards_8sql__in.html" title="SQL functions for cox proportional hazards.">cox_prop_hazards.sql_in</a> (documenting the SQL functions) </dd></dl> |
| </div> |
| </div> |
| <div id="nav-path" class="navpath"> |
| <ul> |
| <!-- window showing the filter options --> |
| <div id="MSearchSelectWindow" |
| onmouseover="return searchBox.OnSearchSelectShow()" |
| onmouseout="return searchBox.OnSearchSelectHide()" |
| onkeydown="return searchBox.OnSearchSelectKey(event)"> |
| <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Functions</a></div> |
| |
| <!-- iframe showing the search results (closed by default) --> |
| <div id="MSearchResultsWindow"> |
| <iframe src="javascript:void(0)" frameborder="0" |
| name="MSearchResults" id="MSearchResults"> |
| </iframe> |
| </div> |
| |
| |
| <li class="footer">Generated on Tue Apr 2 2013 14:57:03 for MADlib by |
| <a href="http://www.doxygen.org/index.html"> |
| <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li> |
| </ul> |
| </div> |
| |
| |
| </body> |
| </html> |