{"id":72,"date":"2023-11-28T20:04:20","date_gmt":"2023-11-28T20:04:20","guid":{"rendered":"https:\/\/projectfena.com\/?page_id=72"},"modified":"2023-11-29T19:58:04","modified_gmt":"2023-11-29T19:58:04","slug":"univariable-survival-analysis","status":"publish","type":"page","link":"https:\/\/projectfena.com\/index.php\/univariable-survival-analysis\/","title":{"rendered":"Univariable Survival Analysis"},"content":{"rendered":"\n<ol class=\"wp-block-list\">\n<li><strong>Individualized Risk Prediction<\/strong>: The code calculates individualized risk predictions using survival analysis, specifically the Cox proportional hazards model.<\/li>\n\n\n\n<li><strong>Semi-Parametric Approach<\/strong>: The Cox model is considered a semi-parametric model. This is because it makes no assumptions about the form of the baseline hazard function (hence \u201cnon-parametric\u201d for the baseline hazard) but does assume a parametric form for the effect of predictors. In mathematical terms, the hazard function is given by: <code><span class=\"katex-eq\" data-katex-display=\"false\">h(t | X) = h_0(t) \\exp(\\beta X)<\/span><\/code> where <code><span class=\"katex-eq\" data-katex-display=\"false\">h_0(t)<\/span><\/code> is the baseline hazard function,&nbsp;<code><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/projectfena.com\/wp-content\/ql-cache\/quicklatex.com-b6a7605b1bcca8f1b416eaf733f34e08_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#98;&#101;&#116;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"17\" width=\"11\" style=\"vertical-align: -4px;\"\/><\/code>&nbsp;is the vector of coefficients, and&nbsp;<code><span class=\"katex-eq\" data-katex-display=\"false\">X<\/span><\/code> is the vector of covariates.<\/li>\n\n\n\n<li><strong>Subgroups Considered<\/strong>: The survival analysis is performed for specific subgroups, identified by the variable&nbsp;<a href=\"https:\/\/wwwn.cdc.gov\/Nchs\/Nhanes\/2011-2012\/DEMO_G.htm#RIDRETH3\">ridreth3<\/a>. These include Mexican, Hispanic, White, Black, Asian, and Other.<\/li>\n\n\n\n<li><strong>Matrices Explanation<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>b<\/code>: Contains the coefficients&nbsp;<code><span class=\"katex-eq\" data-katex-display=\"false\">\\beta<\/span><\/code>&nbsp;of the model.<\/li>\n\n\n\n<li><code>V<\/code>: Contains the variance-covariance matrix, used for calculating standard errors.<\/li>\n\n\n\n<li><code>SV<\/code>: A scenario vector, used to calculate the risk score for a specific scenario.<\/li>\n\n\n\n<li><code>risk_score<\/code>: The risk score calculated as&nbsp;SV\u00d7<code><span class=\"katex-eq\" data-katex-display=\"false\">\\beta<\/span><\/code>.<\/li>\n\n\n\n<li><code>var_prediction<\/code>: Variance of the risk score prediction.<\/li>\n\n\n\n<li><code>se_prediction<\/code>: Standard error of the risk score prediction.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Graphs<\/strong>:\n<ul class=\"wp-block-list\">\n<li>The first graph illustrates the survival rates for different subgroups.<\/li>\n\n\n\n<li>The second graph depicts survival rates for a specific scenario defined in the matrix&nbsp;<code>SV<\/code>. For the mathematical details, look&nbsp;here.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>global data https:\/\/github.com\/muzaale\/ikesa\/raw\/main\/nhanes.dta\nglobal subgroup ridreth3\nglobal subgroupvar: var lab ridreth3\ncls\nuse $data, clear\ndi \"obs: `c(N)', vars: `c(k)'\"\ngen years = permth_exm \/ 12\nstset years, fail(mortstat)<\/code><\/pre>\n\n\n\n<p>Am I not understood?\u2014Have I not been understood?\u2014\u201cCertainly not, sir?\u201d\u2014Well, let us go back to the beginning!<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Preparing the Environment and Loading the Data<\/li>\n<\/ol>\n\n\n\n<p>The first part of the code defines global macros and loads the necessary data for analysis.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>global data https:\/\/github.com\/muzaale\/ikesa\/raw\/main\/nhanes.dta\nglobal subgroup ridreth3\nglobal subgroupvar: var lab ridreth3\ncls\nuse $data, clear\ndi \"obs: `c(N)', vars: `c(k)'\"\ngen years = permth_exm \/ 12\nstset years, fail(mortstat)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Line 1-3<\/strong>: Definition of global variables for data URL, subgroup identifier (ridreth3), and subgroup variable label.<\/li>\n\n\n\n<li><strong>Line 4<\/strong>: Clears the screen (<code>cls<\/code>).<\/li>\n\n\n\n<li><strong>Line 5<\/strong>: Loads the dataset (<code>use&nbsp;$data,&nbsp;clear<\/code>).<\/li>\n\n\n\n<li><strong>Line 6<\/strong>: Displays the number of observations and variables in the dataset.<\/li>\n\n\n\n<li><strong>Line 7<\/strong>: Generates a variable for years by dividing a given variable by 12.<\/li>\n\n\n\n<li><strong>Line 8<\/strong>: Sets the data as survival-time data with&nbsp;<code>years<\/code>&nbsp;as the time variable and&nbsp;<code>mortstat<\/code>&nbsp;as the failure indicator.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li>Plotting the Survival Graph by Subgroup<\/li>\n<\/ol>\n\n\n\n<p>This section visualizes the survival rates for different subgroups by plotting the Kaplan-Meier survival estimates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#delimit ;\nsts graph if inlist($subgroup,1,2,3,4,6,7),\n    by($subgroup)\n    fail\n    ti(\"Mortality in NHANES III\",pos(11))\n    subti(\"by self report: ${subgroupvar}\",pos(11))\n    yti(\"\n    xti(\"Years\")\n    per(100)\n    ylab(0(5)20,\n        format(\n        angle(360)\n    )\n    legend(on\n        lab(1 \"Mexican\")\n        lab(2 \"Hispanic\")\n        lab(3 \"White\")\n        lab(4 \"Black\")\n        lab(5 \"Asian\")\n        lab(6 \"Other\")\n        ring(0)\n        pos(11)\n        col(1)\n        order(3 4 1 2 5)\n    )\n    note(\"Source: RDC\/NCHS\/CDC\/DHHS\")  \n;\n#delimit cr\ncd \"~\/dropbox\/1f.\u1f21\u1f14\u03c1\u03b9\u03c2,\u03ba\/1.ontology\/alpha\"\ngraph export nhanes.png, replace<\/code><\/pre>\n\n\n\n<p>nonparametric mortality risk:<\/p>\n\n\n\n<p>&lt;nhanes.png&gt;<\/p>\n\n\n\n<p>Here, a mortality graph (i.e., 1 &#8211; survival-time graph;&nbsp;<code>sts&nbsp;graph,&nbsp;failure<\/code>) is drawn for specific subgroups and the legend ordered so that the highest-risk group (3 &#8211; white) appears first, the second highest-risk (4 &#8211; black) appears second, etc. Various formatting options are applied to enhance readability, and the graph is exported as an image.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li>Fitting the Cox Proportional Hazards Model<\/li>\n<\/ol>\n\n\n\n<p>This part fits the Cox proportional hazards model to the data for the selected subgroups (which one?) and extracts important matrices such as coefficients and the variance-covariance matrix.<\/p>\n\n\n\n<p><abbr class='c2c-text-hover' title='Subgroups Considered: The survival analysis is performed for specific subgroups, identified by the variable ridreth3. These include Mexican, Hispanic, White, Black, Asian, and Other.'>Hint<\/abbr> <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>stcox i.$subgroup if inlist(${subgroup}, 1, 2, 3, 4, 6, 7), basesurv(s0)\nmatrix define m = r(table)\nmatrix b = e(b)\nmatrix V = e(V)\nmatrix SV = (0, 0, 0, 0, 1, 0)\nmatrix risk_score = SV * b'\ndi exp(risk_score&#091;1,1])\nmatrix var_prediction = SV * V * SV'\nmatrix se_prediction = sqrt(var_prediction&#091;1,1])<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>stcox<\/code>: Fitting the Cox model.<\/li>\n\n\n\n<li><code>matrix&nbsp;define<\/code>: Defining matrices for coefficients (<code>b<\/code>), variance-covariance (<code>V<\/code>), and others.<\/li>\n\n\n\n<li><code>di&nbsp;exp(risk_score[1,1])<\/code>: Displays the exponential of the risk score for interpretation.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li>Calculating and Plotting Specific Scenario<\/li>\n<\/ol>\n\n\n\n<p>This section calculates the risk for a specific scenario defined in the matrix&nbsp;<code>SV<\/code>, and plots the survival rates.<\/p>\n\n\n\n<p>semiparametric mortality risk:<\/p>\n\n\n\n<p>&lt;nhanes_5.png&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gen f0 = (1 - s0) * 100\ngen f1 = f0 * exp(risk_score&#091;1,1])\ndrop if _t &gt; 10\nline f1 _t, sort connect(step step) ylab(0(5)20) xlab(0(2)10)\ngraph export nhanes_5.png, replace<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>gen<\/code>: Generates new variables for the survival function.<\/li>\n\n\n\n<li><code>s0<\/code>: Nonparametric (like Kaplan-Meier) baseline survival function (the base-case scenario in which all covariates are 0). Ideally this scenario should be of the typical of \u201caverage\u201d person in the population and is achieved by centering the covariates at their means (binary variables take the value greater than 0.5)<\/li>\n\n\n\n<li><code>drop&nbsp;if&nbsp;_t&nbsp;&gt;&nbsp;10<\/code>: Excludes observations where time exceeds 10 since the race variable was only collected in the last 12 years.<\/li>\n\n\n\n<li><code>line<\/code>: Plots the survival rates. The&nbsp;<code>sort<\/code>&nbsp;option sorts the data by time, and the&nbsp;<code>connect<\/code>&nbsp;option connects the data points with a step function (Kaplan-Meier function).<\/li>\n\n\n\n<li><code>graph&nbsp;export<\/code>: Exports the plotted graph seen above as an image.<\/li>\n<\/ul>\n\n\n\n<p>Final Remarks<\/p>\n\n\n\n<p>The entire code process takes a semi-parametric approach to calculate and visualize individualized risk predictions using survival analysis. Subgroup analysis is also performed based on the variable ridreth3, considering different ethnicities. Two different graphs illustrate the survival rates both generally and for a specific scenario.<\/p>\n\n\n\n<p>Images depicting nonparametric and semiparametric mortality risk are also included in the documentation.<\/p>\n\n\n\n<p>By following the steps detailed above, the code achieves the goal of analyzing 10-year risk with potential adaptability to assess 30-year risk in the future. For more practice in a multivariable survival analysis setting, see&nbsp;<a href=\"https:\/\/jhutrc.github.io\/beta\/act_0\/act_0_0\/act_0_0_7\/act_0_0_7_7.html\">here<\/a>.<\/p>\n\n\n\n \n","protected":false},"excerpt":{"rendered":"<p>Am I not understood?\u2014Have I not been understood?\u2014\u201cCertainly not, sir?\u201d\u2014Well, let us go back to the beginning! The first part of the code defines global macros and loads the necessary data for analysis. This section visualizes the survival rates for different subgroups by plotting the Kaplan-Meier survival estimates. nonparametric mortality risk: &lt;nhanes.png&gt; Here, a mortality [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"class_list":["post-72","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/pages\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":10,"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/pages\/72\/revisions"}],"predecessor-version":[{"id":86,"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/pages\/72\/revisions\/86"}],"wp:attachment":[{"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/media?parent=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}