{"id":89,"date":"2023-07-24T19:40:33","date_gmt":"2023-07-24T10:40:33","guid":{"rendered":"https:\/\/best-biostatistics.com\/toukei-er\/?p=89"},"modified":"2025-02-11T21:16:52","modified_gmt":"2025-02-11T12:16:52","slug":"how-to-draw-a-penalized-spline-curve-using-cox-regression-in-r","status":"publish","type":"post","link":"https:\/\/best-biostatistics.com\/toukei-er\/entry\/how-to-draw-a-penalized-spline-curve-using-cox-regression-in-r\/","title":{"rendered":"R \u3067 Cox \u56de\u5e30\u3092\u7528\u3044\u3066 Penalized Spline \u66f2\u7dda\u3092\u66f8\u304f\u65b9\u6cd5"},"content":{"rendered":"\n<p>R \u3067 \u751f\u5b58\u6642\u9593\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u3001Penalized Spline\uff08\u7f70\u5247\u4ed8\u304d\u30b9\u30d7\u30e9\u30a4\u30f3\uff09\u66f2\u7dda\u3092\u66f8\u304f\u65b9\u6cd5\u306e\u89e3\u8aac<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Penalized Spline \u3068\u306f<\/h2>\n\n\n\n<p>Penalized Spline\uff08\u7f70\u5247\u4ed8\u304d\u30b9\u30d7\u30e9\u30a4\u30f3\u3001P \u30b9\u30d7\u30e9\u30a4\u30f3\uff09\u306f\u3001\u30c7\u30fc\u30bf\u306b\u5408\u308f\u305b\u305f\u6ed1\u3089\u304b\u306a\u66f2\u7dda\u3092\u6c42\u3081\u308b\u305f\u3081\u306b\u4f7f\u308f\u308c\u308b\u65b9\u6cd5\u306e\u4e00\u3064\u3060\u304c\u3001\u904e\u5270\u9069\u5408\uff08\u30aa\u30fc\u30d0\u30fc\u30d5\u30a3\u30c3\u30c6\u30a3\u30f3\u30b0\uff09\u3092\u9632\u3050\u305f\u3081\u306b\u30da\u30ca\u30eb\u30c6\u30a3\uff08\u7f70\u5247\uff09\u3092\u52a0\u3048\u308b\u624b\u6cd5<\/p>\n\n\n\n<p>\u66f2\u7dda\u306e 2 \u968e\u5fae\u5206\uff08\u66f2\u304c\u308a\u5177\u5408\uff09\u306b\u5bfe\u3057\u3066\u30da\u30ca\u30eb\u30c6\u30a3\u3092\u8ab2\u3059\u3053\u3068\u3067\u3001\u904e\u5ea6\u306b\u8907\u96d1\u306a\u5f62\u72b6\u3092\u907f\u3051\u3066\u3001\u6ed1\u3089\u304b\u306a\u63a8\u5b9a\u3092\u884c\u3046<\/p>\n\n\n\n<p>\u81ea\u7531\u5ea6\u306e 2 \uff5e 3 \u500d\u306e\u30ce\u30c3\u30c8\u3092\u914d\u7f6e\u3059\u308b\u3068\u9069\u5207\u306a\u30b9\u30e0\u30fc\u30b8\u30f3\u30b0\u304c\u884c\u3048\u308b\uff08\u9023\u7d9a\u30c7\u30fc\u30bf\u3067\u81ea\u7531\u5ea6 1 \u3067\u3042\u308c\u3070\u30012 \uff5e 3 \u500b\u306e\u30ce\u30c3\u30c8\u3068\u3044\u3046\u610f\u5473\uff09<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">B \u30b9\u30d7\u30e9\u30a4\u30f3\u3068\u306e\u9055\u3044<\/h2>\n\n\n\n<p>\u30b9\u30d7\u30e9\u30a4\u30f3\u66f2\u7dda\u3067\u306f\u3001B \u30b9\u30d7\u30e9\u30a4\u30f3\u304c\u77e5\u3089\u308c\u3066\u3044\u308b<\/p>\n\n\n\n<p>B \u30b9\u30d7\u30e9\u30a4\u30f3\u3082\u30c7\u30fc\u30bf\u3092\u6ed1\u3089\u304b\u306a\u66f2\u7dda\u306b\u30d5\u30a3\u30c3\u30c8\u3055\u305b\u308b\u65b9\u6cd5\u3060\u304c\u3001\u904e\u5270\u9069\u5408\u3092\u9632\u3050\u4ed5\u7d44\u307f\u304c\u306a\u3044<\/p>\n\n\n\n<p>Penalized Spline \u306f\u3001\u30c7\u30fc\u30bf\u306b\u30d5\u30a3\u30c3\u30c8\u3057\u3064\u3064\u3082\u3001\u904e\u5270\u9069\u5408\u3092\u9632\u304e\u3001\u904e\u5ea6\u306b\u66f2\u304c\u308a\u3059\u304e\u306a\u3044\u66f2\u7dda\u3092\u63cf\u753b\u3059\u308b<\/p>\n\n\n\n<div id=\"biost-2181984319\" class=\"biost- biost-entity-placement\"><p style=\"text-align: center;\"><span style=\"font-size: 20px;\"><strong><a href=\"https:\/\/best-biostatistics.com\/kmhl\">\uff1e\uff1e\u3082\u3046\u7d71\u8a08\u3067\u60a9\u3080\u306e\u306f\u7d42\u308f\u308a\u306b\u3057\u307e\u305b\u3093\u304b\uff1f\u00a0<\/a><\/strong><\/span><\/p>\r\n<a href=\"https:\/\/best-biostatistics.com\/kmhl\"><img class=\"aligncenter wp-image-2794 size-full\" src=\"https:\/\/best-biostatistics.com\/wp\/wp-content\/uploads\/2023\/11\/bn_r_03.png\" alt=\"\" width=\"500\" height=\"327\" \/><\/a>\r\n<p style=\"text-align: center;\"><span style=\"color: #ff0000; font-size: 20px;\"><strong><span class=\"marker2\">\u21911\u4e07\u4eba\u4ee5\u4e0a\u306e\u533b\u7642\u5f93\u4e8b\u8005\u304c\u8cfc\u8aad\u4e2d<\/span><\/strong><\/span><\/p><\/div><h2 class=\"wp-block-heading\">Penalized Spline \u3092 R \u3067\u66f8\u3044\u3066\u307f\u308b<\/h2>\n\n\n\n<p>suvival \u30d1\u30c3\u30b1\u30fc\u30b8\u306e lung \u3068\u3044\u3046\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u7528\u3044\u3066\u3001\u5e74\u9f62\u306b\u5bfe\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30af\u3092 Penalized Spline \u66f2\u7dda\u3068\u3057\u3066\u66f8\u3044\u3066\u307f\u308b<\/p>\n\n\n\n<p>\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span class=\"synComment\"># penalized spline curve<\/span>\n<span class=\"synPreProc\">library<\/span><span class=\"synSpecial\">(<\/span>survival<span class=\"synSpecial\">)<\/span>\n\nfit <span class=\"synStatement\">&lt;-<\/span> <span class=\"synIdentifier\">coxph<\/span><span class=\"synSpecial\">(<\/span><span class=\"synIdentifier\">Surv<\/span><span class=\"synSpecial\">(<\/span>time<span class=\"synSpecial\">,<\/span> status<span class=\"synSpecial\">)<\/span><span class=\"synStatement\">~<\/span><span class=\"synIdentifier\">pspline<\/span><span class=\"synSpecial\">(<\/span>age<span class=\"synSpecial\">),<\/span> data<span class=\"synStatement\">=<\/span>lung<span class=\"synSpecial\">)<\/span>\n<span class=\"synIdentifier\">termplot<\/span><span class=\"synSpecial\">(<\/span>fit<span class=\"synSpecial\">,<\/span> se<span class=\"synStatement\">=<\/span><span class=\"synConstant\">TRUE<\/span><span class=\"synSpecial\">)<\/span>\n<span class=\"synIdentifier\">abline<\/span><span class=\"synSpecial\">(<\/span>h<span class=\"synStatement\">=<\/span><span class=\"synConstant\">0<\/span><span class=\"synSpecial\">)<\/span>\n\n<span class=\"synIdentifier\">summary<\/span><span class=\"synSpecial\">(<\/span>fit<span class=\"synSpecial\">)<\/span>\n<\/code><\/pre>\n\n\n\n<p>coxph \u95a2\u6570\u5185\u306e pspline \u304c Penalized Spline \u9805\u3067\u3042\u308b<\/p>\n\n\n\n<p>termplot \u3067\u4ee5\u4e0b\u306e\u30b0\u30e9\u30d5\u304c\u66f8\u3051\u308b<\/p>\n\n\n\n<p>se = TRUE \u304c\u3001\u4fe1\u983c\u533a\u9593\u3092\u8868\u793a\u3059\u308b\u5f15\u6570\u3067\u3042\u308b<\/p>\n\n\n\n<p>\u8d64\u3044\u7dda\u304c\u70b9\u63a8\u5b9a\u5024\u3067\u3001\u30aa\u30ec\u30f3\u30b8\u306e\u7834\u7dda\u304c 95 \uff05 \u4fe1\u983c\u533a\u9593\u3067\u3042\u308b<\/p>\n\n\n\n<p>Y \u8ef8\u306f\u5bfe\u6570\u30cf\u30b6\u30fc\u30c9\u6bd4\u3067\u3042\u308b<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"672\" height=\"672\" src=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/07\/20240129211309.png\" alt=\"\" class=\"wp-image-1689\" title=\"\" srcset=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/07\/20240129211309.png 672w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/07\/20240129211309-300x300.png 300w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/07\/20240129211309-150x150.png 150w\" sizes=\"(max-width: 672px) 100vw, 672px\" \/><\/figure>\n\n\n\n<p>\u8a08\u7b97\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> summary(fit)\nCall:\ncoxph(formula = Surv(time, status) ~ pspline(age), data = lung)\n\n  n= 228, number of events= 165 \n\n                     coef    se(coef) se2      Chisq DF   p    \npspline(age), linear 0.01879 0.009014 0.009014 4.34  1.00 0.037\npspline(age), nonlin                           2.91  3.09 0.420\n\n          exp(coef) exp(-coef) lower .95 upper .95\nps(age)3      1.458    0.68597    0.3474     6.117\nps(age)4      2.126    0.47029    0.2097    21.564\nps(age)5      3.089    0.32375    0.2128    44.842\nps(age)6      3.713    0.26930    0.2498    55.195\nps(age)7      3.575    0.27969    0.2562    49.897\nps(age)8      3.336    0.29972    0.2454    45.359\nps(age)9      3.371    0.29668    0.2478    45.848\nps(age)10     3.804    0.26289    0.2788    51.900\nps(age)11     4.525    0.22098    0.3298    62.094\nps(age)12     6.031    0.16582    0.4257    85.423\nps(age)13    10.027    0.09973    0.5887   170.793\nps(age)14    17.508    0.05712    0.5730   534.903\n\nIterations: 4 outer, 11 Newton-Raphson\n     Theta= 0.8062094 \nDegrees of freedom for terms= 4.1 \nConcordance= 0.535  (se = 0.027 )\nLikelihood ratio test= 7.74  on 4.09 df,   p=0.1<\/code><\/pre>\n\n\n\n<p>linear \u306e\u90e8\u5206\u304c \u81ea\u7531\u5ea6 1 \u3067\u3001nonlinear \u306e\u90e8\u5206\u304c\u81ea\u7531\u5ea6 3.09 \u3068\u308f\u304b\u308b<\/p>\n\n\n\n<p>\u5408\u308f\u305b\u3066\u3001Degrees of freedom for terms = 4.1 \u3068\u7406\u89e3\u3067\u304d\u308b\uff08\u4e0b\u304b\u3089 3 \u884c\u76ee\uff09<\/p>\n\n\n\n<p>\u52a0\u3048\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001\u4ea4\u7d61\u56e0\u5b50\u3092\u52a0\u3048\u305f\u308a\u3001\u81ea\u7531\u5ea6\u3092\u5236\u5fa1\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># ph.ecog \u3092\u4ea4\u7d61\u56e0\u5b50\u3068\u3057\u3066\u6295\u5165\nfit1 <span class=\"synStatement\">&lt;-<\/span> <span class=\"synIdentifier\">coxph(Surv(<\/span>time<span class=\"synSpecial\">,<\/span> status<span class=\"synSpecial\">) ~ <\/span>ph.ecog<span class=\"synStatement\"> + pspline(<\/span>age<span class=\"synSpecial\">),<\/span> lung<span class=\"synSpecial\">)<\/span>\n# df (degree of freedom) \u3092 8 \u306b\u5909\u66f4\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306f 4\uff09\nfit2 <span class=\"synStatement\">&lt;-<\/span> <span class=\"synIdentifier\">coxph(Surv(<\/span>time<span class=\"synSpecial\">,<\/span> status<span class=\"synSpecial\">) ~ <\/span>ph.ecog <span class=\"synStatement\">+ pspline(<\/span>age<span class=\"synSpecial\">,<\/span> <span class=\"synConstant\">8),<\/span> lung<span class=\"synSpecial\">)<\/span>\n<\/code><\/pre>\n\n\n\n<p>\u81ea\u7531\u5ea6\u306f\u591a\u304f\u3057\u904e\u304e\u305a\u3001\u8907\u96d1\u306b\u3057\u306a\u3044\u307b\u3046\u304c\u3088\u304f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u307e\u307e\u3067\u3088\u3044\u3088\u3046\u306b\u601d\u3046<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u4ee5\u4e0a\u3001R \u3067 \u751f\u5b58\u6642\u9593\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066 Penalized Spline \u66f2\u7dda\u3092\u66f8\u304f\u65b9\u6cd5\u3092\u304a\u4f1d\u3048\u3057\u305f<\/p>\n\n\n\n<p>\u9023\u7d9a\u30c7\u30fc\u30bf\u306e\u8aac\u660e\u5909\u6570\u306b\u5bfe\u3057\u3066\u3001\u7dda\u5f62\u306b\u30a4\u30d9\u30f3\u30c8\u306e\u30ea\u30b9\u30af\u304c\u4e0a\u6607\u3057\u306a\u3044\u3068\u60f3\u5b9a\u3055\u308c\u308b\u5834\u5408\u3001\u904e\u5270\u9069\u5408\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u30da\u30ca\u30eb\u30c6\u30a3\u304c\u3064\u3044\u305f Penalized Spline \u66f2\u7dda\u3067\u3001\u8aac\u660e\u5909\u6570\u3068\u30a4\u30d9\u30f3\u30c8\u3068\u306e\u95a2\u4fc2\u6027\u3092\u63cf\u304f\u306e\u304c\u4e00\u3064\u306e\u9078\u629e\u80a2\u3067\u3042\u308b<\/p>\n\n\n\n<p>\u4f55\u3089\u304b\u53c2\u8003\u306b\u306a\u308c\u3070<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>R \u3067 \u751f\u5b58\u6642\u9593\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u3001Penalized Spline\uff08\u7f70\u5247\u4ed8\u304d\u30b9\u30d7\u30e9\u30a4\u30f3\uff09\u66f2\u7dda\u3092\u66f8\u304f\u65b9\u6cd5\u306e\u89e3\u8aac<\/p>\n","protected":false},"author":2,"featured_media":1689,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5,37,21,101],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","category-37","category-21","category-101"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/07\/20240129211309.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":5,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":3488,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/89\/revisions\/3488"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/media\/1689"}],"wp:attachment":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}