| <!-- HTML header for doxygen 1.8.4--> |
| <!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"/> |
| <meta http-equiv="X-UA-Compatible" content="IE=9"/> |
| <meta name="generator" content="Doxygen 1.8.4"/> |
| <meta name="keywords" content="madlib,postgres,greenplum,machine learning,data mining,deep learning,ensemble methods,data science,market basket analysis,affinity analysis,pca,lda,regression,elastic net,huber white,proportional hazards,k-means,latent dirichlet allocation,bayes,support vector machines,svm"/> |
| <title>MADlib: Cox-Proportional Hazards Regression</title> |
| <link href="tabs.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="jquery.js"></script> |
| <script type="text/javascript" src="dynsections.js"></script> |
| <link href="navtree.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="resize.js"></script> |
| <script type="text/javascript" src="navtree.js"></script> |
| <script type="text/javascript"> |
| $(document).ready(initResizable); |
| $(window).load(resizeHeight); |
| </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 type="text/x-mathjax-config"> |
| MathJax.Hub.Config({ |
| extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"], |
| jax: ["input/TeX","output/HTML-CSS"], |
| }); |
| </script><script src="../mathjax/MathJax.js"></script> |
| <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| <link href="madlib_extra.css" rel="stylesheet" type="text/css"/> |
| <!-- google analytics --> |
| <script> |
| (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
| (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
| m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
| })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); |
| ga('create', 'UA-45382226-1', 'auto'); |
| ga('send', 'pageview'); |
| </script> |
| </head> |
| <body> |
| <div id="top"><!-- do not remove this div, it is closed by doxygen! --> |
| <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">1.2</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> |
| <!--BEGIN VERSIONS LINKS--> |
| <td style="padding-left: 0.5em;"> |
| <div class="versionlist"><ul> |
| <li class="head">More versions:</li> |
| <li><a href="../v1.1/index.html">v1.1</li> |
| <li><a href="../v1.0/index.html">v1.0</li> |
| <li><a href="../v0.7/index.html">v0.7</li> |
| <li><a href="../v0.5/index.html">v0.5</li></ul> |
| </div> |
| </td> |
| <td> <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> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <!-- end header part --> |
| <!-- Generated by Doxygen 1.8.4 --> |
| <script type="text/javascript"> |
| var searchBox = new SearchBox("searchBox", "search",false,'Search'); |
| </script> |
| </div><!-- top --> |
| <div id="side-nav" class="ui-resizable side-nav-resizable"> |
| <div id="nav-tree"> |
| <div id="nav-tree-contents"> |
| <div id="nav-sync" class="sync"></div> |
| </div> |
| </div> |
| <div id="splitbar" style="-moz-user-select:none;" |
| class="ui-resizable-handle"> |
| </div> |
| </div> |
| <script type="text/javascript"> |
| $(document).ready(function(){initNavTree('group__grp__cox__prop__hazards.html','');}); |
| </script> |
| <div id="doc-content"> |
| <!-- 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><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Groups</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> |
| |
| <div class="header"> |
| <div class="headertitle"> |
| <div class="title">Cox-Proportional Hazards Regression<div class="ingroups"><a class="el" href="group__grp__glm.html">Generalized Linear Models</a></div></div> </div> |
| </div><!--header--> |
| <div class="contents"> |
| <div class="toc"> <ul> |
| <li class="level1"> |
| <a href="#about">About</a> </li> |
| <li class="level1"> |
| <a href="#help">Online Help</a> </li> |
| <li class="level1"> |
| <a href="#training">Training Function</a> </li> |
| <li class="level1"> |
| <a href="#output">Output Table</a> </li> |
| <li class="level1"> |
| <a href="#examples">Examples</a> </li> |
| <li class="level1"> |
| <a href="#seealso">See Also</a> </li> |
| <li class="level1"> |
| <a href="#background">Technical Background</a> </li> |
| </ul> |
| </div><p><a class="anchor" id="about"></a></p> |
| <dl class="section user"><dt>About</dt><dd>Proportional-Hazard models enable the comparison of various survival models. These survival models are functions describing the probability of a 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><a class="anchor" id="help"></a></p> |
| <dl class="section user"><dt>Online Help</dt><dd></dd></dl> |
| <p>To display a brief summary of the Cox Proportional Hazards module, call the cox_prop_hazards() function with no argument: </p> |
| <pre class="fragment">SELECT madlib.cox_prop_hazards(); |
| </pre><p><a class="anchor" id="train"></a></p> |
| <dl class="section user"><dt>Training Function</dt><dd></dd></dl> |
| <p>Following is the syntax for the cox_prop_hazards() training function: </p> |
| <pre class="fragment">cox_prop_hazards( |
| source_table, |
| out_table, |
| dependent_variable, |
| independent_variable, |
| right_censoring_status) |
| ) |
| </pre><p> <b>Arguments</b> </p> |
| <dl class="arglist"> |
| <dt>source_table </dt> |
| <dd>TEXT. The name of the table containing input data. </dd> |
| <dt>out_table </dt> |
| <dd>TEXT. The name of the table where the output model is saved. </dd> |
| <dt>dependent_variable </dt> |
| <dd>TEXT. A string containing the name of a column that contains an array of numeric values, or a string expression in the format 'array[1, x1, x2, x3]', where <em>x1</em>, <em>x2</em> and <em>x3</em> are column names. Dependent variables refer to the time of death. There is no need to pre-sort the data. </dd> |
| <dt>independent_variable </dt> |
| <dd>TEXT. The name of the independent variable. </dd> |
| <dt>right_censoring_status (optional) </dt> |
| <dd>TEXT, default: TRUE for all observations. A string containing an expression that evaluates to the right-censoring status for the observation—TRUE if the observation is not censored and FALSE if the observation is censored. The string could contain the name of the column containing the right-censoring status, a fixed Boolean expression (i.e., 'true', 'false', '0', '1') that applies to all observations, or a Boolean expression such as 'column_name < 10' that can be evaluated for each observation. </dd> |
| </dl> |
| <p><a class="anchor" id="notes"></a></p> |
| <dl class="section user"><dt>Notes</dt><dd><ul> |
| <li>All table names can be optionally schema qualified (current_schemas() would be searched if a schema name is not provided) and all table and column names should follow case-sensitivity and quoting rules per the database. (For instance, 'mytable' and 'MyTable' both resolve to the same entity, i.e. 'mytable'. If mixed-case or multi-byte characters are desired for entity names then the string should be double-quoted; in this case the input would be '"MyTable"').</li> |
| <li>The <a class="el" href="cox__prop__hazards_8sql__in.html#a3310cf98478b7c1e400e8fb1b3965d30" title="Compute cox-regression coefficients and diagnostic statistics. ">cox_prop_hazards_regr()</a> function has been deprecated, and cox_prop_hazards() should be used instead.</li> |
| </ul> |
| </dd></dl> |
| <p><a class="anchor" id="output"></a></p> |
| <dl class="section user"><dt>Output Table</dt><dd></dd></dl> |
| <p>The output is saved in the table named by the <em>out_table</em> argument. It has the following columns: </p> |
| <dl class="arglist"> |
| <dt>coef </dt> |
| <dd>FLOAT8[]. Vector of the coefficients. </dd> |
| <dt>std_err </dt> |
| <dd>FLOAT8[]. Vector of the standard error of the coefficients. </dd> |
| <dt>stats </dt> |
| <dd>FLOAT8[]. Vector of the statistics of the coefficients. </dd> |
| <dt>p_values </dt> |
| <dd>FLOAT8[]. Vector of the p-values of the coefficients. </dd> |
| </dl> |
| <p><a class="anchor" id="examples"></a></p> |
| <dl class="section user"><dt>Examples</dt><dd><ol type="1"> |
| <li>Create an input data set: <pre class="fragment">DROP TABLE IF EXISTS sample_data; |
| CREATE TABLE sample_data ( |
| id INTEGER NOT NULL, |
| grp DOUBLE PRECISION, |
| wbc DOUBLE PRECISION, |
| timedeath INTEGER, |
| status BOOLEAN |
| ); |
| COPY sample_data FROM STDIN DELIMITED BY '|'; |
| 0 | 0 | 1.45 | 35 | t |
| 1 | 0 | 1.47 | 34 | t |
| 3 | 0 | 2.2 | 32 | t |
| 4 | 0 | 1.78 | 25 | t |
| 5 | 0 | 2.57 | 23 | t |
| 6 | 0 | 2.32 | 22 | t |
| 7 | 0 | 2.01 | 20 | t |
| 8 | 0 | 2.05 | 19 | t |
| 9 | 0 | 2.16 | 17 | t |
| 10 | 0 | 3.6 | 16 | t |
| 11 | 1 | 2.3 | 15 | t |
| 12 | 0 | 2.88 | 13 | t |
| 13 | 1 | 1.5 | 12 | t |
| 14 | 0 | 2.6 | 11 | t |
| 15 | 0 | 2.7 | 10 | t |
| 16 | 0 | 2.8 | 9 | t |
| 17 | 1 | 2.32 | 8 | t |
| 18 | 0 | 4.43 | 7 | t |
| 19 | 0 | 2.31 | 6 | t |
| 20 | 1 | 3.49 | 5 | t |
| 21 | 1 | 2.42 | 4 | t |
| 22 | 1 | 4.01 | 3 | t |
| 23 | 1 | 4.91 | 2 | t |
| 24 | 1 | 5 | 1 | t |
| \. |
| </pre></li> |
| <li>Run the cox regression function: <pre class="fragment">SELECT * FROM madlib.cox_prop_hazards( |
| 'sample_data', |
| 'sample_cox', |
| 'timedeath', |
| 'ARRAY[grp,wbc]', |
| 'status'); |
| </pre></li> |
| <li>View the results of the regression: <pre class="fragment">\x on |
| SELECT * FROM sample_cox; |
| </pre> Results: <pre class="fragment">-[ RECORD 1 ]----------------------------------------- |
| coef | {2.54449137803027,1.67183255057665} |
| std_err | {0.677308807341768,0.387308633304678} |
| z_stats | {3.75676700265663,4.31653830257251} |
| p_values | {0.000172122613528057,1.58495189046891e-05} |
| </pre></li> |
| </ol> |
| </dd></dl> |
| <p><a class="anchor" id="seealso"></a></p> |
| <dl class="section see"><dt>See Also</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 functions</dd></dl> |
| <p><a class="anchor" id="Literature"></a></p> |
| <dl class="section user"><dt>Literature</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> |
| <p><a class="anchor" id="background"></a></p> |
| <dl class="section user"><dt>Technical Background</dt><dd></dd></dl> |
| <p>Generally, proportional-hazard models 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> |
| </div><!-- contents --> |
| </div><!-- doc-content --> |
| <!-- start footer part --> |
| <div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> |
| <ul> |
| <li class="footer">Generated on Thu Jan 9 2014 20:35:40 for MADlib by |
| <a href="http://www.doxygen.org/index.html"> |
| <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.4 </li> |
| </ul> |
| </div> |
| </body> |
| </html> |