{"id":87,"date":"2023-11-29T20:08:56","date_gmt":"2023-11-29T20:08:56","guid":{"rendered":"https:\/\/projectfena.com\/?page_id=87"},"modified":"2023-11-29T20:08:57","modified_gmt":"2023-11-29T20:08:57","slug":"multivariable-survival-analysis","status":"publish","type":"page","link":"https:\/\/projectfena.com\/index.php\/multivariable-survival-analysis\/","title":{"rendered":"Multivariable Survival Analysis"},"content":{"rendered":"\n<p>Step 1: Importing the Data and Initial Setup<\/p>\n\n\n\n<p>This block of code imports the required data and sets up some preliminary parameters for analysis.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use \"https:\/\/github.com\/muzaale\/ikesa\/raw\/main\/nhanes.dta\", clear\ndi \"obs: `c(N)', vars: `c(k)'\"\nglobal subgroup ridreth3\nglobal subgroupvar: var lab ridreth3\ncls\ngen years = permth_exm \/ 12\nstset years, fail(mortstat)<\/code><\/pre>\n\n\n\n<p>Step 2: Generating the Survival Graph<\/p>\n\n\n\n<p>Here, we generate the survival graph for the various subgroups defined by the variable\u00a0<code>ridreth3<\/code>.<\/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<\/code><\/pre>\n\n\n\n<p>Step 3: Cox Proportional Hazard Model<\/p>\n\n\n\n<p>Next, we run the Cox proportional hazards model using the defined subgroups and a set of confounding variables.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \"~\/dropbox\/1f.\u1f21\u1f14\u03c1\u03b9\u03c2,\u03ba\/1.ontology\/alpha\"\nglobal confounders ridageyr diq010 bmxbmi smq020 lbdscrsi lbxgh\nstcox i.$subgroup $confounders if inlist(${subgroup}, 1, 2, 3, 4, 6, 7), basesurv(s0) \/\/best when centered<\/code><\/pre>\n\n\n\n<p>Step 4: Matrices Definition<\/p>\n\n\n\n<p>We define three matrices\u00a0<code><span class=\"katex-eq\" data-katex-display=\"false\">m<\/span><\/code>, <code><span class=\"katex-eq\" data-katex-display=\"false\">b<\/span><\/code>, and\u00a0<code><span class=\"katex-eq\" data-katex-display=\"false\">V<\/span><\/code>, to store the table of results, coefficients, and variance-covariance matrix, respectively.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>matrix define m = r(table)\nmatrix b = e(b)\nmatrix V = e(V)<\/code><\/pre>\n\n\n\n<p>Step 5: Scenario Vector (SV)<\/p>\n\n\n\n<p>The Scenario Vector defines specific values for a given scenario. For instance, this can represent a 60-year-old black individual with certain medical conditions. Note that the first six positions in the vector are for the subgroups of race, and the last six are for the confounding variables.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/SV: black, 60yo, diabetic, BMI=36, h\/o smoking, SCr=1.5, HbA1c=7.1\nmatrix SV = (0, 0, 0, 1, 0, 0, 60, 1, 36, 1, 1.5, 7.1)<\/code><\/pre>\n\n\n\n<p>Step 6: Calculating the Risk Score<\/p>\n\n\n\n<p>The risk score (<code><span class=\"katex-eq\" data-katex-display=\"false\">\\rho<\/span><\/code>) is calculated by multiplying the scenario vector with the transpose of the coefficients:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>matrix risk_score = SV * b'<\/code><\/pre>\n\n\n\n<p>Step 7: Log Hazard Ratio<\/p>\n\n\n\n<p>The log hazard ratio for the specified scenario is displayed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/log HR for scenario vector above\nmatrix list risk_score <\/code><\/pre>\n\n\n\n<p>Step 8: Hazard Ratio for Scenario<\/p>\n\n\n\n<p>This calculates the hazard ratio (HR) by taking the exponential of the log hazard ratio:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/HR for scenario described compared with \"base-case\"\ndi exp(risk_score&#091;1,1])<\/code><\/pre>\n\n\n\n<p>Step 9: Variance and Standard Error of Prediction<\/p>\n\n\n\n<p>Here, we calculate the variance (<code><span class=\"katex-eq\" data-katex-display=\"false\">\\sigma^2<\/span><\/code>) and standard error (SE) of the prediction for the scenario.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>matrix var_prediction = SV * V * SV'\nmatrix se_prediction = sqrt(var_prediction&#091;1,1])<\/code><\/pre>\n\n\n\n<p>Step 10: 10-Year Mortality for Scenario<\/p>\n\n\n\n<p>Finally, the 10-year mortality for the specified scenario is plotted.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/10-year mortality for scenario \ngen f0 = (1 - s0) * 100\ngen f1 = f0 * exp(risk_score&#091;1,1])\ndrop if _t > 10\nline f1 _t, sort connect(step step) ylab(0(5)20) xlab(0(2)10)\ngraph export nhanes_scenario.png, replace  <\/code><\/pre>\n\n\n\n<p>&lt;nhanes_scenario.png><\/p>\n\n\n\n<p>This series of steps takes the reader through the process of estimating the risk score and the associated 10-year mortality for a given scenario. It uses a semi-parametric model to create the underlying hazard function and uses specific scenario vectors to estimate the individualized risk for different populations or conditions.<\/p>\n\n\n\n<p><strong>Comment About Base-Case:<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Interpretation would be more intuitive if centering were used. Without centering, the base-case is for a specific reference group (e.g., Mexican, 0 years old, non-diabetic, BMI=0, etc.) which is not very useful.<\/p>\n<\/blockquote>\n\n\n\n<p>To adapt this portion of the code for another project or scenario, the analyst would need to redefine the scenario vector (<code>SV<\/code>) with the appropriate values for the new context. They would also need to ensure that the model\u2019s coefficients and variance-covariance matrix are correctly extracted, and that the calculations are aligned with the new scenario\u2019s specifications.<\/p>\n\n\n\n \n","protected":false},"excerpt":{"rendered":"<p>Step 1: Importing the Data and Initial Setup This block of code imports the required data and sets up some preliminary parameters for analysis. Step 2: Generating the Survival Graph Here, we generate the survival graph for the various subgroups defined by the variable\u00a0ridreth3. Step 3: Cox Proportional Hazard Model Next, we run the Cox [&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-87","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/pages\/87","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=87"}],"version-history":[{"count":1,"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/pages\/87\/revisions"}],"predecessor-version":[{"id":89,"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/pages\/87\/revisions\/89"}],"wp:attachment":[{"href":"https:\/\/projectfena.com\/index.php\/wp-json\/wp\/v2\/media?parent=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}