{"id":1802,"date":"2025-05-07T20:12:43","date_gmt":"2025-05-07T12:12:43","guid":{"rendered":"https:\/\/www.ddosidc.com\/wp\/?p=1802"},"modified":"2025-05-07T20:12:43","modified_gmt":"2025-05-07T12:12:43","slug":"r%e8%af%ad%e8%a8%80%e4%b8%ad%e7%9a%84cox%e5%9b%9e%e5%bd%92%e5%88%86%e6%9e%90%e8%83%bd%e8%a7%a3%e5%86%b3%e5%93%aa%e4%ba%9b%e7%94%9f%e5%ad%98%e6%97%b6%e9%97%b4%e7%9b%b8%e5%85%b3%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.ddosidc.com\/wp\/1802.html","title":{"rendered":"R\u8bed\u8a00\u4e2d\u7684Cox\u56de\u5f52\u5206\u6790\u80fd\u89e3\u51b3\u54ea\u4e9b\u751f\u5b58\u65f6\u95f4\u76f8\u5173\u95ee\u9898"},"content":{"rendered":"<p><p>\u5728\u751f\u5b58\u5206\u6790\u4e2d\uff0cCox\u56de\u5f52\u6a21\u578b\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5e38\u7528\u4e8e\u63a2\u7d22\u5f71\u54cd\u751f\u5b58\u65f6\u95f4\u7684\u53d8\u91cf\u3002\u672c\u6587\u65e8\u5728\u901a\u8fc7R\u8bed\u8a00\u8bb2\u89e3\u5982\u4f55\u8fdb\u884cCox\u56de\u5f52\u5206\u6790\uff0c\u4ee5\u89e3\u51b3\u751f\u5b58\u5206\u6790\u4e2d\u7684\u5177\u4f53\u95ee\u9898\uff0c\u5982\u5982\u4f55\u8bc4\u4f30\u4e0d\u540c\u56e0\u7d20\u5bf9\u751f\u5b58\u65f6\u95f4\u7684\u5f71\u54cd\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.ddosidc.com\/wp\/wp-content\/uploads\/2025\/05\/zsKSU93Lg3.jpg\" alt=\"R\u8bed\u8a00\u4e2d\u7684Cox\u56de\u5f52\u5206\u6790\u80fd\u89e3\u51b3\u54ea\u4e9b\u751f\u5b58\u65f6\u95f4\u76f8\u5173\u95ee\u9898\" title=\"R\u8bed\u8a00\u4e2d\u7684Cox\u56de\u5f52\u5206\u6790\u80fd\u89e3\u51b3\u54ea\u4e9b\u751f\u5b58\u65f6\u95f4\u76f8\u5173\u95ee\u9898\"><\/p>\n<\/p>\n<p><h2>\u64cd\u4f5c\u524d\u7684\u51c6\u5907<\/h2>\n<\/p>\n<p><p>\u5728\u8fdb\u884cCox\u56de\u5f52\u5206\u6790\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86\u5fc5\u8981\u7684R\u5305\u3002\u6700\u5e38\u7528\u7684\u5305\u662f<strong>survival<\/strong>\uff0c\u5b83\u63d0\u4f9b\u4e86\u8fdb\u884c\u751f\u5b58\u5206\u6790\u7684\u57fa\u7840\u529f\u80fd\u3002\u6b64\u5916\uff0c\u6570\u636e\u96c6\u8981\u5305\u542b\u751f\u5b58\u65f6\u95f4\u3001\u4e8b\u4ef6\u53d1\u751f\u6307\u793a\u7b26\uff08\u5982\u6b7b\u4ea1\u6216\u5931\u8e2a\uff09\u53ca\u5176\u4ed6\u76f8\u5173\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><h2>\u5b89\u88c5\u548c\u52a0\u8f7d\u5fc5\u8981\u7684R\u5305<\/h2>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86<strong>survival<\/strong>\u5305\u3002\u5982\u679c\u672a\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code>install.packages(\"survival\")<\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u52a0\u8f7d\u8be5\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code>library(survival)<\/code><\/pre>\n<\/p>\n<p><h2>\u6570\u636e\u96c6\u7684\u51c6\u5907<\/h2>\n<\/p>\n<p><p>\u6211\u4eec\u5047\u8bbe\u6709\u4e00\u4e2a\u751f\u5b58\u6570\u636e\u96c6\uff0c\u5305\u542b\u4ee5\u4e0b\u5217\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>time<\/strong>: \u751f\u5b58\u65f6\u95f4\uff08\u4f8b\u5982\uff0c\u5728\u5929\u6570\u6216\u6708\u6570\u4e2d\uff09<\/li>\n<li><strong>status<\/strong>: \u4e8b\u4ef6\u53d1\u751f\u72b6\u6001\uff08\u901a\u5e380\u8868\u793a\u751f\u5b58\uff0c1\u8868\u793a\u4e8b\u4ef6\u53d1\u751f\uff09<\/li>\n<li><strong>age<\/strong>: \u53c2\u4e0e\u8005\u5e74\u9f84<\/li>\n<li><strong>treatment<\/strong>: \u6cbb\u7597\u7ec4\uff08\u5982&#8221;\u836f\u7269A&#8221;\u6216&#8221;\u836f\u7269B&#8221;\uff09<\/li>\n<\/ul>\n<p><h2>\u6570\u636e\u5bfc\u5165<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528<strong>read.csv<\/strong>\u547d\u4ee4\u5bfc\u5165\u6570\u636e\u96c6\uff1a<\/p>\n<\/p>\n<p><pre><code>data <- read.csv(\"path\/to\/your\/data.csv\")<\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6b64\u547d\u4ee4\u4e2d\uff0c\u5c06\u201cpath\/to\/your\/data.csv\u201d\u66ff\u6362\u4e3a\u5b9e\u9645\u6587\u4ef6\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><h2>\u67e5\u770b\u548c\u51c6\u5907\u6570\u636e<\/h2>\n<\/p>\n<p><p>\u5bfc\u5165\u6570\u636e\u540e\uff0c\u4f7f\u7528<strong>head<\/strong>\u51fd\u6570\u67e5\u770b\u6570\u636e\u7684\u524d\u51e0\u884c\uff0c\u4ee5\u786e\u8ba4\u6570\u636e\u5df2\u6b63\u786e\u52a0\u8f7d\uff1a<\/p>\n<\/p>\n<p><pre><code>head(data)<\/code><\/pre>\n<\/p>\n<p><p>\u786e\u4fdd\u6570\u636e\u4e2d\u6ca1\u6709\u7f3a\u5931\u503c\uff0c\u7f3a\u5931\u503c\u4f1a\u5f71\u54cd\u6a21\u578b\u7ed3\u679c\u3002\u5982\u679c\u6709\u7f3a\u5931\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u548c\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code>sum(is.na(data))<\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u53d1\u73b0\u7f3a\u5931\u503c\uff0c\u53ef\u4ee5\u9009\u62e9\u5220\u9664\u5e26\u6709\u7f3a\u5931\u503c\u7684\u8bb0\u5f55\u6216\u586b\u8865\u7f3a\u5931\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code>data <- na.omit(data)<\/code><\/pre>\n<\/p>\n<p><h2>\u6784\u5efaCox\u56de\u5f52\u6a21\u578b<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528<strong>coxph<\/strong>\u51fd\u6570\u6784\u5efaCox\u56de\u5f52\u6a21\u578b\u3002\u5047\u8bbe\u6211\u4eec\u8981\u7814\u7a76<strong>age<\/strong>\u548c<strong>treatment<\/strong>\u5bf9\u751f\u5b58\u65f6\u95f4\u7684\u5f71\u54cd\uff1a<\/p>\n<\/p>\n<p><pre><code>cox_model <- coxph(Surv(time, status) ~ age + treatment, data = data)<\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u91cc\uff0c<strong>Surv(time, status)<\/strong>\u521b\u5efa\u4e86\u4e00\u4e2a\u751f\u5b58\u5bf9\u8c61\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u5c06\u88ab\u7528\u4e8e\u6a21\u578b\u3002<strong>age + treatment<\/strong>\u8868\u793a\u6211\u4eec\u5efa\u6a21\u7684\u81ea\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><h2>\u6a21\u578b\u8bca\u65ad<\/h2>\n<\/p>\n<p><p>\u5728\u5f97\u5230Cox\u56de\u5f52\u6a21\u578b\u540e\uff0c\u4f7f\u7528<strong>summary<\/strong>\u51fd\u6570\u6765\u8f93\u51fa\u6a21\u578b\u6458\u8981\uff0c\u4ee5\u68c0\u67e5\u7cfb\u6570\u3001p\u503c\u7b49\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code>summary(cox_model)<\/code><\/pre>\n<\/p>\n<p><p>\u4f60\u5c06\u770b\u5230\u6bcf\u4e2a\u53d8\u91cf\u7684\u4f30\u8ba1\u7cfb\u6570\u3001\u6807\u51c6\u8bef\u3001z\u503c\u53cap\u503c\u3002\u6ce8\u610fp\u503c\u5c0f\u4e8e0.05\u901a\u5e38\u8868\u660e\u8be5\u53d8\u91cf\u5728\u751f\u5b58\u65f6\u95f4\u4e2d\u5177\u6709\u7edf\u8ba1\u5b66\u663e\u8457\u6027\u3002<\/p>\n<\/p>\n<p><h2>\u6a21\u578b\u5047\u8bbe\u68c0\u9a8c<\/h2>\n<\/p>\n<p><p>Cox\u56de\u5f52\u6a21\u578b\u6709\u4e00\u4e2a\u91cd\u8981\u5047\u8bbe\uff0c\u5373\u6bd4\u4f8b\u98ce\u9669\u5047\u8bbe\u3002\u4f7f\u7528<strong>cox.zph<\/strong>\u51fd\u6570\u5bf9\u8be5\u5047\u8bbe\u8fdb\u884c\u68c0\u9a8c\uff1a<\/p>\n<\/p>\n<p><pre><code>zph_test <- cox.zph(cox_model)<\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u53ef\u4ee5\u4f7f\u7528<strong>plot<\/strong>\u51fd\u6570\u7ed8\u5236\u7ed3\u679c\uff0c\u4ee5\u5e2e\u52a9\u53ef\u89c6\u5316\u68c0\u9a8c\u7ed3\u679c\uff1a<\/p>\n<\/p>\n<p><pre><code>plot(zph_test)<\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6d4b\u8bd5\u7ed3\u679c\u663e\u793a\u4e0d\u6ee1\u8db3\u6bd4\u4f8b\u98ce\u9669\u5047\u8bbe\uff0c\u53ef\u80fd\u9700\u8981\u8003\u8651\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\uff0c\u4f8b\u5982\u5206\u5c42Cox\u56de\u5f52\u6a21\u578b\u6216\u65f6\u95f4\u4f9d\u8d56\u6027\u534f\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><h2>\u7ed3\u679c\u89e3\u91ca\u548c\u53ef\u89c6\u5316<\/h2>\n<\/p>\n<p><p>\u6a21\u578b\u8bad\u7ec3\u5b8c\u6210\u540e\uff0c\u53ef\u80fd\u9700\u8981\u5c06\u7ed3\u679c\u53ef\u89c6\u5316\u3002\u53ef\u4ee5\u4f7f\u7528<strong>ggsurvplot<\/strong>\u51fd\u6570\u6765\u7ed8\u5236\u751f\u5b58\u66f2\u7ebf\u3002\u8fd9\u9700\u8981\u5148\u5b89\u88c5\u5e76\u52a0\u8f7d<strong>survminer<\/strong>\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code>install.packages(\"survminer\")<\/p>\r\n<p>library(survminer)<\/p>\r\n<p>ggsurvplot(survfit(cox_model), data = data)<\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u56fe\u5c06\u663e\u793a\u4e0d\u540c\u7ec4\u522b\u7684\u751f\u5b58\u66f2\u7ebf\uff0c\u5e2e\u52a9\u8fdb\u4e00\u6b65\u7406\u89e3\u751f\u5b58\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h2>\n<\/p>\n<p><p>\u5728\u8fdb\u884cCox\u56de\u5f52\u5206\u6790\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u7f3a\u5931\u503c\u5904\u7406<\/strong>: \u5728\u6570\u636e\u96c6\u4e2d\u6709\u7f3a\u5931\u503c\u65f6\uff0c\u9700\u8c28\u614e\u5904\u7406\uff0c\u907f\u514d\u5bf9\u7ed3\u679c\u9020\u6210\u504f\u5dee\u3002<\/li>\n<li><strong>\u6bd4\u4f8b\u98ce\u9669\u5047\u8bbe<\/strong>: \u4e0d\u6ee1\u8db3\u6bd4\u4f8b\u98ce\u9669\u5047\u8bbe\u5c06\u5f71\u54cd\u6a21\u578b\u7684\u53ef\u9760\u6027\u3002<\/li>\n<li><strong>\u53d8\u91cf\u9009\u62e9<\/strong>: \u9009\u62e9\u5408\u9002\u7684\u81ea\u53d8\u91cf\u975e\u5e38\u91cd\u8981\uff0c\u76f8\u5173\u6027\u5206\u6790\u53ef\u4ee5\u5e2e\u52a9\u8bc6\u522b\u5173\u952e\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p><p>\u6b64\u5916\uff0c\u53ef\u4ee5\u901a\u8fc7<strong>stepAIC<\/strong>\u51fd\u6570\u8fdb\u884c\u9010\u6b65\u56de\u5f52\uff0c\u4ee5\u9009\u62e9\u9002\u5408\u7684\u53d8\u91cf\u7ec4\u5408\u3002<\/p>\n<\/p>\n<p><h2>\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728R\u8bed\u8a00\u4e2d\u8fdb\u884cCox\u56de\u5f52\u5206\u6790\uff0c\u4ece\u6a21\u578b\u7684\u6784\u5efa\u5230\u7ed3\u679c\u7684\u89e3\u91ca\u4e0e\u53ef\u89c6\u5316\uff0c\u63d0\u4f9b\u4e86\u8be6\u7ec6\u7684\u6b65\u9aa4\u548c\u4ee3\u7801\u793a\u4f8b\u3002\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u8bfb\u8005\u80fd\u591f\u72ec\u7acb\u8fdb\u884cCox\u56de\u5f52\u5206\u6790\uff0c\u89e3\u51b3\u751f\u5b58\u5206\u6790\u4e2d\u7684\u76f8\u5173\u95ee\u9898\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u751f\u5b58\u5206\u6790\u4e2d\uff0cCox\u56de\u5f52\u6a21\u578b\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5e38\u7528\u4e8e\u63a2\u7d22\u5f71\u54cd\u751f\u5b58\u65f6\u95f4\u7684\u53d8\u91cf\u3002\u672c\u6587\u65e8\u5728\u901a\u8fc7R\u8bed\u8a00\u8bb2\u89e3\u5982\u4f55\u8fdb\u884cCox\u56de\u5f52\u5206\u6790\uff0c\u4ee5\u89e3\u51b3\u751f\u5b58\u5206\u6790\u4e2d\u7684\u5177\u4f53\u95ee\u9898\uff0c\u5982\u5982\u4f55\u8bc4\u4f30\u4e0d\u540c\u56e0\u7d20\u5bf9\u751f\u5b58\u65f6\u95f4\u7684\u5f71\u54cd\u3002 \u64cd\u4f5c\u524d\u7684\u51c6\u5907 \u5728\u8fdb\u884cCox\u56de\u5f52\u5206\u6790\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u7ecf&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1803,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-1802","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-baike"],"_links":{"self":[{"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/posts\/1802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/comments?post=1802"}],"version-history":[{"count":1,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/posts\/1802\/revisions"}],"predecessor-version":[{"id":1805,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/posts\/1802\/revisions\/1805"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/media\/1803"}],"wp:attachment":[{"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/media?parent=1802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/categories?post=1802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/tags?post=1802"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/topic?post=1802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}