{"id":4379,"date":"2025-08-04T23:27:24","date_gmt":"2025-08-04T14:27:24","guid":{"rendered":"https:\/\/best-biostatistics.com\/toukei-er\/?p=4379"},"modified":"2025-08-05T22:20:55","modified_gmt":"2025-08-05T13:20:55","slug":"creating-iptw-baseline-summary-tables-in-r-mastering-tableone-and-other-functions","status":"publish","type":"post","link":"https:\/\/best-biostatistics.com\/toukei-er\/entry\/creating-iptw-baseline-summary-tables-in-r-mastering-tableone-and-other-functions\/","title":{"rendered":"R\u3067\u4f5c\u6210\u3059\u308bIPTW\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868\uff1atableone \u3068\u305d\u306e\u4ed6\u95a2\u6570\u3092\u4f7f\u3044\u3053\u306a\u3059"},"content":{"rendered":"\n<p>\u75ab\u5b66\u7814\u7a76\u3084\u81e8\u5e8a\u7814\u7a76\u306b\u304a\u3044\u3066\u3001\u89b3\u5bdf\u7814\u7a76\u3067\u56e0\u679c\u63a8\u8ad6\u3092\u884c\u3046\u969b\u306b\u306f\u3001\u6cbb\u7642\u7fa4\u9593\u306e\u5171\u5909\u91cf\u30d0\u30e9\u30f3\u30b9\u304c\u53d6\u308c\u3066\u3044\u306a\u3044\u3053\u3068\u304c\u5927\u304d\u306a\u8ab2\u984c\u3068\u306a\u308b\u3002\u3053\u306e\u8ab2\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u624b\u6cd5\u306e\u4e00\u3064\u304c\u3001IPTW (Inverse Probability of Treatment Weighting) \u3067\u3042\u308b\u3002IPTW\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3001\u3042\u305f\u304b\u3082\u30e9\u30f3\u30c0\u30e0\u5316\u6bd4\u8f03\u8a66\u9a13\u306e\u3088\u3046\u306a\u72b6\u6cc1\u3092\u7d71\u8a08\u7684\u306b\u4f5c\u308a\u51fa\u3057\u3001\u6cbb\u7642\u52b9\u679c\u306e\u3088\u308a\u6b63\u78ba\u306a\u63a8\u5b9a\u3092\u76ee\u6307\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<p>IPTW\u3092\u9069\u7528\u3057\u305f\u5f8c\u3001\u91cd\u8981\u306a\u306e\u306f\u3001\u30a6\u30a7\u30a4\u30c8\u304c\u9069\u5207\u306b\u6a5f\u80fd\u3057\u3001\u5171\u5909\u91cf\u306e\u30d0\u30e9\u30f3\u30b9\u304c\u6539\u5584\u3055\u308c\u305f\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3067\u3042\u308b\u3002\u3053\u306e\u78ba\u8a8d\u306b\u4e0d\u53ef\u6b20\u306a\u306e\u304c\u3001IPTW\u3092\u9069\u7528\u3057\u305f\u5f8c\u306e\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868\u3067\u3042\u308b\u3002\u672c\u8a18\u4e8b\u3067\u306f\u3001R\u306e tableone\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4e2d\u5fc3\u306b\u3001\u4ed6\u306e\u4fbf\u5229\u306a\u95a2\u6570\u3082\u7d44\u307f\u5408\u308f\u305b\u306a\u304c\u3089\u3001IPTW\u5f8c\u306e\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3092\u8a73\u3057\u304f\u89e3\u8aac\u3059\u308b\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">IPTW\u306e\u57fa\u672c\u7684\u306a\u6d41\u308c\uff08\u518d\u78ba\u8a8d\uff09<\/h2>\n\n\n\n<p>IPTW\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868\u306e\u4f5c\u6210\u306b\u5165\u308b\u524d\u306b\u3001IPTW\u306e\u57fa\u672c\u7684\u306a\u6d41\u308c\u3092\u7c21\u5358\u306b\u304a\u3055\u3089\u3044\u3059\u308b\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u50be\u5411\u30b9\u30b3\u30a2\u306e\u63a8\u5b9a:<\/strong> \u5404\u53c2\u52a0\u8005\u304c\u7279\u5b9a\u306e\u6cbb\u7642\u3092\u53d7\u3051\u308b\u78ba\u7387\uff08\u50be\u5411\u30b9\u30b3\u30a2\u3001\u3053\u3053\u3067\u306f PS \u3068\u8868\u8a18\u3059\u308b\uff09\u3092\u3001\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u5171\u5909\u91cf\u3092\u7528\u3044\u3066\u30ed\u30b8\u30b9\u30c6\u30a3\u30c3\u30af\u56de\u5e30\u306a\u3069\u3067\u63a8\u5b9a\u3059\u308b\u3002<\/li>\n\n\n\n<li><strong>\u30a6\u30a7\u30a4\u30c8\u306e\u8a08\u7b97:<\/strong> \u63a8\u5b9a\u3055\u308c\u305f\u50be\u5411\u30b9\u30b3\u30a2\u306b\u57fa\u3065\u3044\u3066\u3001\u5404\u53c2\u52a0\u8005\u306e\u30a6\u30a7\u30a4\u30c8\u3092\u8a08\u7b97\u3059\u308b\u3002\u4e00\u822c\u7684\u306a\u306e\u306f\u3001ATT (Average Treatment effect on the Treated) \u307e\u305f\u306f ATE (Average Treatment effect) \u306e\u30a6\u30a7\u30a4\u30c8\u3067\u3042\u308b\u3002\n<ul class=\"wp-block-list\">\n<li>ATT\u306e\u5834\u5408\uff1a\n<ul class=\"wp-block-list\">\n<li>\u6cbb\u7642\u7fa4: $w_i = 1$<\/li>\n\n\n\n<li>\u5bfe\u7167\u7fa4: $w_i = \\frac{\\text{PS}_i}{1 &#8211; \\text{PS}_i}$<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>ATE\u306e\u5834\u5408\uff1a\n<ul class=\"wp-block-list\">\n<li>\u6cbb\u7642\u7fa4: $w_i = \\frac{1}{\\text{PS}_i}$<\/li>\n\n\n\n<li>\u5bfe\u7167\u7fa4: $w_i = \\frac{1}{1 &#8211; \\text{PS}_i}$<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u30a6\u30a7\u30a4\u30c8\u306e\u9069\u7528:<\/strong> \u8a08\u7b97\u3055\u308c\u305f\u30a6\u30a7\u30a4\u30c8\u3092\u30c7\u30fc\u30bf\u306b\u9069\u7528\u3057\u3001\u30a6\u30a7\u30a4\u30c8\u4ed8\u304d\u306e\u7d71\u8a08\u89e3\u6790\u3092\u884c\u3046\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001\u65e2\u306b\u30a6\u30a7\u30a4\u30c8\u304c\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306b\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u524d\u63d0\u306b\u9032\u3081\u308b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528\u3059\u308bR\u30d1\u30c3\u30b1\u30fc\u30b8<\/h2>\n\n\n\n<p>\u4eca\u56de\u4f7f\u7528\u3059\u308b\u4e3b\u306aR\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3042\u308b\u3002\u4e8b\u524d\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u3053\u3068\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#install.packages(c(\"dplyr\", \"tableone\", \"survey\", \"ggplot2\", \"cobalt\"))\nlibrary(dplyr)\nlibrary(tableone)\nlibrary(survey)\nlibrary(ggplot2)\nlibrary(cobalt) # \u30d0\u30e9\u30f3\u30b9\u30c1\u30a7\u30c3\u30af\u306e\u305f\u3081\u306b\u975e\u5e38\u306b\u4fbf\u5229<\/code><\/pre>\n\n\n\n<div id=\"biost-1667732621\" 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\">\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u306e\u6e96\u5099<\/h2>\n\n\n\n<p>\u67b6\u7a7a\u306e\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f5c\u6210\u3057\u3001IPTW\u306e\u30a6\u30a7\u30a4\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4e71\u6570\u30b7\u30fc\u30c9\u306e\u8a2d\u5b9a\nset.seed(123)\n\n# \u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u306e\u4f5c\u6210\nn &lt;- 500 # \u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\ndata_df &lt;- tibble(\n  id = 1:n,\n  treatment = sample(c(0, 1), n, replace = TRUE, prob = c(0.6, 0.4)), # \u6cbb\u7642\u7fa4 (0:\u5bfe\u7167, 1:\u6cbb\u7642)\n  age = round(rnorm(n, 50, 10)), # \u5e74\u9f62\n  sex = sample(c(\"Male\", \"Female\"), n, replace = TRUE, prob = c(0.5, 0.5)), # \u6027\u5225\n  bmi = round(rnorm(n, 25, 5),1), # BMI\n  comorbidity = rbinom(n, 1, 0.3) # \u4f75\u5b58\u75be\u60a3 (0:\u306a\u3057, 1:\u3042\u308a)\n)\n\n# \u50be\u5411\u30b9\u30b3\u30a2\u306e\u63a8\u5b9a (\u3053\u3053\u3067\u306f\u7c21\u6613\u7684\u306a\u30ed\u30b8\u30b9\u30c6\u30a3\u30c3\u30af\u56de\u5e30)\nps_model &lt;- glm(treatment ~ age + sex + bmi + comorbidity, data = data_df, family = binomial())\ndata_df$prop_score &lt;- predict(ps_model, type = \"response\")\n\n# ATE\u30a6\u30a7\u30a4\u30c8\u306e\u8a08\u7b97\ndata_df &lt;- data_df %&gt;%\n  mutate(\n    iptw_weight = ifelse(treatment == 1, 1 \/ prop_score, 1 \/ (1 - prop_score))\n  )\n\n# \u30a6\u30a7\u30a4\u30c8\u306e\u30c8\u30ea\u30df\u30f3\u30b0 (\u30aa\u30d7\u30b7\u30e7\u30f3\u3060\u304c\u63a8\u5968)\n# \u6975\u7aef\u306a\u30a6\u30a7\u30a4\u30c8\u306f\u4e0d\u5b89\u5b9a\u6027\u3092\u3082\u305f\u3089\u3059\u305f\u3081\u3001\u30c8\u30ea\u30df\u30f3\u30b0\u306f\u91cd\u8981\u3067\u3042\u308b\u3002\n# \u4f8b\u3048\u3070\u3001\u4e0a\u4f4d\u30fb\u4e0b\u4f4d1%\u3092\u30c8\u30ea\u30df\u30f3\u30b0\nquantile_trim_lower &lt;- quantile(data_df$iptw_weight, 0.01)\nquantile_trim_upper &lt;- quantile(data_df$iptw_weight, 0.99)\n\ndata_df &lt;- data_df %&gt;%\n  mutate(\n    iptw_weight_trimmed = pmin(pmax(iptw_weight, quantile_trim_lower), quantile_trim_upper)\n  )\n\n# \u4ee5\u964d\u3001iptw_weight_trimmed \u3092\u4f7f\u7528<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">tableone \u3092\u4f7f\u3063\u305f\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868\u306e\u4f5c\u6210<\/h2>\n\n\n\n<p>tableone \u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001\u975e\u5e38\u306b\u7c21\u5358\u306b\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u306e\u60a3\u8005\u7279\u6027\u8868\uff08Table 1\uff09\u3092\u4f5c\u6210\u3067\u304d\u308b\u3053\u3068\u3067\u77e5\u3089\u308c\u3066\u3044\u308b\u3002\u30a6\u30a7\u30a4\u30c8\u3092\u8003\u616e\u3057\u305f\u8868\u3092\u4f5c\u6210\u3059\u308b\u306b\u306f\u3001<code>svyglm<\/code>\u306a\u3069\u3068\u540c\u3058\u3088\u3046\u306b<code>survey<\/code>\u30d1\u30c3\u30b1\u30fc\u30b8\u306e<code>svydesign<\/code>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30a6\u30a7\u30a4\u30c8\u306a\u3057\u306e\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868\uff08\u6bd4\u8f03\u7528\uff09<\/h3>\n\n\n\n<p>\u307e\u305a\u3001\u30a6\u30a7\u30a4\u30c8\u3092\u8003\u616e\u3057\u306a\u3044\u901a\u5e38\u306e\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868\u3092\u4f5c\u6210\u3057\u3001\u30a6\u30a7\u30a4\u30c8\u9069\u7528\u5f8c\u306e\u8868\u3068\u6bd4\u8f03\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u5171\u5909\u91cf\u306e\u30ea\u30b9\u30c8\nmyVars &lt;- c(\"age\", \"sex\", \"bmi\", \"comorbidity\")\n# \u30ab\u30c6\u30b4\u30ea\u30ab\u30eb\u5909\u6570\u306e\u30ea\u30b9\u30c8\ncatVars &lt;- c(\"sex\", \"comorbidity\")\n\n# \u30a6\u30a7\u30a4\u30c8\u306a\u3057\u306eTableOne\ntable1_unweighted &lt;- CreateTableOne(\n  vars = myVars,\n  strata = \"treatment\",\n  data = data_df,\n  factorVars = catVars\n)\n\n# \u8868\u306e\u8868\u793a\nprint(table1_unweighted, smd = TRUE) # SMD (Standardized Mean Difference) \u3082\u8868\u793a<\/code><\/pre>\n\n\n\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; # \u8868\u306e\u8868\u793a\n&gt; print(table1_unweighted, smd = TRUE) # SMD (Standardized Mean Difference) \u3082\u8868\u793a\n                     Stratified by treatment\n                      0             1             p      test SMD   \n  n                     305           195                           \n  age (mean (SD))     49.65 (10.13) 51.09 (9.91)   0.118       0.144\n  sex = Male (%)        152 (49.8)     96 (49.2)   0.968       0.012\n  bmi (mean (SD))     25.06 (4.87)  25.25 (5.11)   0.676       0.038\n  comorbidity = 1 (%)    91 (29.8)     56 (28.7)   0.867       0.025<\/code><\/pre>\n\n\n\n<p>\u3053\u3053\u3067<code>smd = TRUE<\/code>\u3068\u3059\u308b\u3053\u3068\u3067\u3001\u6a19\u6e96\u5316\u5e73\u5747\u5dee (Standardized Mean Difference; <strong>SMD<\/strong>) \u304c\u8868\u793a\u3055\u308c\u308b\u3002SMD\u306f\u3001\u5404\u5171\u5909\u91cf\u304c\u6cbb\u7642\u7fa4\u3068\u5bfe\u7167\u7fa4\u3067\u3069\u308c\u3060\u3051\u30d0\u30e9\u30f3\u30b9\u304c\u53d6\u308c\u3066\u3044\u308b\u304b\u3092\u793a\u3059\u6307\u6a19\u3067\u3042\u308a\u3001\u4e00\u822c\u7684\u306b<strong>0.1\u4ee5\u4e0b\u3067\u3042\u308c\u3070\u826f\u597d\u306a\u30d0\u30e9\u30f3\u30b9<\/strong>\u3068\u5224\u65ad\u3055\u308c\u308b\u3002\u3053\u3061\u3089\u306e\u30a6\u30a7\u30a4\u30c8\u306a\u3057\u306e\u8868\u3067\u306f\u3001age \u304c SMD 0.1 \u4ee5\u4e0a\u3067\u30d0\u30e9\u30f3\u30b9\u4e0d\u826f\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">IPTW\u30a6\u30a7\u30a4\u30c8\u3092\u8003\u616e\u3057\u305f\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868<\/h3>\n\n\n\n<p>\u6b21\u306b\u3001IPTW\u30a6\u30a7\u30a4\u30c8\u3092\u8003\u616e\u3057\u305f\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868\u3092\u4f5c\u6210\u3059\u308b\u3002\u3053\u308c\u306b\u306f\u3001<code>survey<\/code>\u30d1\u30c3\u30b1\u30fc\u30b8\u306e<code>svydesign<\/code>\u95a2\u6570\u3067\u30c7\u30b6\u30a4\u30f3\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3001\u305d\u308c\u3092<code>CreateTableOne<\/code>\u306b\u6e21\u3059\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># survey\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30c7\u30b6\u30a4\u30f3\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\n# id = ~1 \u306f\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u304c\u306a\u3044\u3053\u3068\u3092\u793a\u3059\n# weights = ~iptw_weight_trimmed \u3067\u30a6\u30a7\u30a4\u30c8\u3092\u6307\u5b9a\nsvy_design &lt;- svydesign(\n  id = ~1,\n  weights = ~iptw_weight_trimmed,\n  data = data_df\n)\n\n# survey\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30c7\u30b6\u30a4\u30f3\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304b\u3089TableOne\u3092\u4f5c\u6210\n# svyCreateTableOne\u95a2\u6570\u3092\u4f7f\u7528\ntable1_weighted &lt;- svyCreateTableOne(\n  vars = myVars,\n  strata = \"treatment\",\n  data = svy_design, # svydesign\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092data\u5f15\u6570\u3068\u3057\u3066\u6e21\u3059\n  factorVars = catVars\n)\n\n# \u8868\u306e\u8868\u793a\nprint(table1_weighted, smd = TRUE)<\/code><\/pre>\n\n\n\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; # \u8868\u306e\u8868\u793a\n&gt; print(table1_weighted, smd = TRUE)\n                     Stratified by treatment\n                      0              1              p      test SMD   \n  n                   500.13         499.93                           \n  age (mean (SD))      50.21 (10.15)  50.21 (10.08)  1.000      &lt;0.001\n  sex = Male (%)       249.5 (49.9)   251.6 (50.3)   0.924       0.009\n  bmi (mean (SD))      25.12 (4.87)   25.12 (5.12)   0.996      &lt;0.001\n  comorbidity = 1 (%)  147.6 (29.5)   148.1 (29.6)   0.979       0.002\n&gt; <\/code><\/pre>\n\n\n\n<p>\u3053\u306e\u30a6\u30a7\u30a4\u30c8\u4ed8\u304d\u306e\u8868\u3067\u306f\u3001age \u3092\u542b\u3080\u5168\u5171\u5909\u91cf\u306eSMD\u304c\u30a6\u30a7\u30a4\u30c8\u306a\u3057\u306e\u8868\u3068\u6bd4\u8f03\u3057\u3066\u5927\u5e45\u306b\u6e1b\u5c11\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3067\u304d\u308b\u3002\u3053\u308c\u306f\u3001IPTW\u304c\u5171\u5909\u91cf\u306e\u30d0\u30e9\u30f3\u30b9\u3092\u6539\u5584\u3059\u308b\u4e0a\u3067\u52b9\u679c\u7684\u306b\u6a5f\u80fd\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u793a\u3057\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u305d\u306e\u4ed6\u306e\u30d0\u30e9\u30f3\u30b9\u30c1\u30a7\u30c3\u30af\u95a2\u6570 (<code>cobalt<\/code>\u30d1\u30c3\u30b1\u30fc\u30b8)<\/h2>\n\n\n\n<p>tableone \u306f\u7d20\u6674\u3089\u3057\u3044\u304c\u3001\u8996\u899a\u7684\u306a\u30d0\u30e9\u30f3\u30b9\u30c1\u30a7\u30c3\u30af\u306b\u306f<code>cobalt<\/code>\u30d1\u30c3\u30b1\u30fc\u30b8\u306e<code>bal.plot<\/code>\u3084<code>love.plot<\/code>\u304c\u975e\u5e38\u306b\u4fbf\u5229\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">SMD\u306eLove Plot<\/h3>\n\n\n\n<p>SMD\u306eLove Plot\u306f\u3001\u5404\u5171\u5909\u91cf\u306eSMD\u3092\u8996\u899a\u7684\u306b\u6bd4\u8f03\u3059\u308b\u306e\u306b\u5f79\u7acb\u3064\u3002\u30a6\u30a7\u30a4\u30c8\u9069\u7528\u524d\u3068\u9069\u7528\u5f8c\u306e\u4e21\u65b9\u3092\u30d7\u30ed\u30c3\u30c8\u3059\u308b\u3053\u3068\u3067\u3001\u30d0\u30e9\u30f3\u30b9\u6539\u5584\u306e\u52b9\u679c\u304c\u4e00\u76ee\u3067\u308f\u304b\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u30a6\u30a7\u30a4\u30c8\u9069\u7528\u524d\u5f8c\u306e\u30d0\u30e9\u30f3\u30b9\u3092\u8a08\u7b97\n# treat: \u6cbb\u7642\u7fa4\u5909\u6570, covs: \u5171\u5909\u91cf\u30ea\u30b9\u30c8\n# weights: \u30a6\u30a7\u30a4\u30c8\u5909\u6570 (\u306a\u3057\u306e\u5834\u5408\u306funweighted)\nbal_results &lt;- bal.tab(\n  treatment ~ age + sex + bmi + comorbidity,\n  data = data_df,\n  estimand = \"ATE\", # ATE\u30a6\u30a7\u30a4\u30c8\u306e\u5834\u5408\n  weights = \"iptw_weight_trimmed\",\n  method = \"weighting\",\n  un = TRUE,\n  disp.means = TRUE,\n  disp.v.ratio = TRUE # SMD\u3092\u8868\u793a\n)\n\n# Love Plot\u3092PNG\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\npng(\"IPTW_summary_table_love_plot.png\", width = 1000, height = 800, res = 120)\nlove.plot(\n  bal_results,\n  stats = \"mean.diffs\", # SMD\u3092\u8868\u793a\n  threshold = 0.1, # \u95be\u5024\u3092\u8a2d\u5b9a\n  var.order = \"alphabetical\", # \u5909\u6570\u3092\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u9806\u306b\u4e26\u3079\u66ff\u3048\n  stars = \"raw\",\n  title = \"Love Plot of Covariate Balance Before and After IPTW\"\n)\ndev.off()<\/code><\/pre>\n\n\n\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1000\" height=\"800\" src=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_love_plot.png\" alt=\"\" class=\"wp-image-4392\" srcset=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_love_plot.png 1000w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_love_plot-300x240.png 300w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_love_plot-768x614.png 768w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p>\u3053\u306e\u30d7\u30ed\u30c3\u30c8\u3067\u306f\u3001\u5404\u5171\u5909\u91cf\u306eSMD\u304c\u30a6\u30a7\u30a4\u30c8\u9069\u7528\u524d\uff08&#8221;Unadjusted&#8221;\uff09\u3068\u9069\u7528\u5f8c\uff08&#8221;Adjusted&#8221;\uff09\u3067\u3069\u306e\u3088\u3046\u306b\u5909\u5316\u3057\u305f\u304b\u304c\u793a\u3055\u308c\u308b\u3002\u7406\u60f3\u7684\u306b\u306f\u3001Adjusted \u306e\u5168\u3066\u306e\u70b9\u306eSMD\u304c\u95be\u5024\uff08\u4f8b\u3048\u30700.1\uff09\u4ee5\u4e0b\u306b\u53ce\u307e\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u671b\u307e\u3057\u3044\u3002\u3053\u306e\u30b0\u30e9\u30d5\u306f\u3001\u6c34\u8272\u306e\u70b9\u304c\u3001-0.1 \u304b\u3089 +0.1 \u306b\u53ce\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u7406\u60f3\u7684\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u50be\u5411\u30b9\u30b3\u30a2\u306e\u5206\u5e03<\/h3>\n\n\n\n<p>\u50be\u5411\u30b9\u30b3\u30a2\u306e\u5206\u5e03\u3092\u6cbb\u7642\u7fa4\u3054\u3068\u306b\u53ef\u8996\u5316\u3059\u308b\u3053\u3068\u3082\u91cd\u8981\u3067\u3042\u308b\u3002\u30a6\u30a7\u30a4\u30c8\u9069\u7528\u5f8c\u3001\u50be\u5411\u30b9\u30b3\u30a2\u306e\u5206\u5e03\u304c\u3088\u308a\u91cd\u306a\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u50be\u5411\u30b9\u30b3\u30a2\u306e\u5206\u5e03\uff08\u30a6\u30a7\u30a4\u30c8\u306a\u3057\uff09\nggplot(data_df, aes(x = prop_score, fill = factor(treatment))) +\n  geom_density(alpha = 0.6) +\n  labs(title = \"Propensity Score Distribution (Unweighted)\",\n       x = \"Propensity Score\",\n       y = \"Density\",\n       fill = \"Treatment\") +\n  theme_minimal()\nggsave(\"IPTW_summary_table_propensity_score_distribution_unweighted.png\", width = 8, height = 6)\n\n# \u50be\u5411\u30b9\u30b3\u30a2\u306e\u5206\u5e03\uff08\u30a6\u30a7\u30a4\u30c8\u4ed8\u304d\uff09\n# survey\u30d1\u30c3\u30b1\u30fc\u30b8\u306esvyhist\u306a\u3069\u3092\u4f7f\u3046\u304b\u3001\u624b\u52d5\u3067\u30a6\u30a7\u30a4\u30c8\u3092\u9069\u7528\u3057\u305f\u30d2\u30b9\u30c8\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\n# ggplot2\u306eaes\u306bweight\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30a6\u30a7\u30a4\u30c8\u4ed8\u304d\u306e\u30d7\u30ed\u30c3\u30c8\u304c\u53ef\u80fd\nggplot(data_df, aes(x = prop_score, fill = factor(treatment), weight = iptw_weight_trimmed)) +\n  geom_density(alpha = 0.6) +\n  labs(title = \"Propensity Score Distribution (IPTW Weighted)\",\n       x = \"Propensity Score\",\n       y = \"Weighted Density\",\n       fill = \"Treatment\") +\n  theme_minimal()\nggsave(\"IPTW_summary_table_propensity_score_distribution_weighted.png\", width = 8, height = 6)\n<\/code><\/pre>\n\n\n\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"768\" data-id=\"4390\" src=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_unweighted-2-1024x768.png\" alt=\"\" class=\"wp-image-4390\" srcset=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_unweighted-2-1024x768.png 1024w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_unweighted-2-300x225.png 300w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_unweighted-2-768x576.png 768w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_unweighted-2-1536x1152.png 1536w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_unweighted-2-2048x1536.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"768\" data-id=\"4387\" src=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_weighted-1-1024x768.png\" alt=\"\" class=\"wp-image-4387\" srcset=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_weighted-1-1024x768.png 1024w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_weighted-1-300x225.png 300w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_weighted-1-768x576.png 768w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_weighted-1-1536x1152.png 1536w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_weighted-1-2048x1536.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>\u30a6\u30a7\u30a4\u30c8\u9069\u7528\u5f8c\uff08IPTW Weighted\uff09\u306e\u30d7\u30ed\u30c3\u30c8\u3067\u306f\u3001\u6cbb\u7642\u7fa4\u3068\u5bfe\u7167\u7fa4\u306e\u50be\u5411\u30b9\u30b3\u30a2\u306e\u5206\u5e03\u304c\u3001\u30a6\u30a7\u30a4\u30c8\u306a\u3057\u306e\u5834\u5408\u3088\u308a\u3082\u985e\u4f3c\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3067\u304d\u308b\u3002\u3053\u308c\u306f\u3001IPTW\u304c\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3092\u6539\u5584\u3057\u3001\u30d0\u30e9\u30f3\u30b9\u3092\u8abf\u6574\u3057\u3066\u3044\u308b\u8a3c\u62e0\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001R\u306e tableone \u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4e2d\u5fc3\u306b\u3001IPTW\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30b5\u30de\u30ea\u30fc\u8868\u306e\u4f5c\u6210\u65b9\u6cd5\u3092\u89e3\u8aac\u3057\u305f\u3002<code>survey<\/code>\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u7c21\u5358\u306b\u30a6\u30a7\u30a4\u30c8\u3092\u8003\u616e\u3057\u305f\u8868\u3092\u4f5c\u6210\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001<code>cobalt<\/code>\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u7528\u3044\u305fLove Plot\u3084\u50be\u5411\u30b9\u30b3\u30a2\u306e\u5206\u5e03\u306e\u53ef\u8996\u5316\u306f\u3001IPTW\u306b\u3088\u308b\u30d0\u30e9\u30f3\u30b9\u6539\u5584\u306e\u52b9\u679c\u3092\u8996\u899a\u7684\u306b\u78ba\u8a8d\u3059\u308b\u4e0a\u3067\u975e\u5e38\u306b\u6709\u7528\u3067\u3042\u308b\u3002\u3053\u308c\u3089\u306e\u30c4\u30fc\u30eb\u3092\u4f7f\u3044\u3053\u306a\u3059\u3053\u3068\u3067\u3001\u3088\u308a\u4fe1\u983c\u6027\u306e\u9ad8\u3044\u56e0\u679c\u63a8\u8ad6\u306b\u7e4b\u304c\u308b\u3067\u3042\u308d\u3046\u3002<\/p>\n\n\n\n<p>IPTW\u306f\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3042\u308b\u304c\u3001\u9069\u5207\u306a\u30a6\u30a7\u30a4\u30c8\u306e\u8a08\u7b97\u3001\u30c8\u30ea\u30df\u30f3\u30b0\u3001\u305d\u3057\u3066\u30d0\u30e9\u30f3\u30b9\u30c1\u30a7\u30c3\u30af\u304c\u4e0d\u53ef\u6b20\u3067\u3042\u308b\u3002\u3053\u308c\u3089\u306e\u624b\u9806\u3092\u4e01\u5be7\u306b\u884c\u3044\u3001\u7814\u7a76\u306e\u8cea\u3092\u9ad8\u3081\u3066\u3044\u304f\u3053\u3068\u3092\u63a8\u5968\u3059\u308b\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>\u75ab\u5b66\u7814\u7a76\u3084\u81e8\u5e8a\u7814\u7a76\u306b\u304a\u3044\u3066\u3001\u89b3\u5bdf\u7814\u7a76\u3067\u56e0\u679c\u63a8\u8ad6\u3092\u884c\u3046\u969b\u306b\u306f\u3001\u6cbb\u7642\u7fa4\u9593\u306e\u5171\u5909\u91cf\u30d0\u30e9\u30f3\u30b9\u304c\u53d6\u308c\u3066\u3044\u306a\u3044\u3053\u3068\u304c\u5927\u304d\u306a\u8ab2\u984c\u3068\u306a\u308b\u3002\u3053\u306e\u8ab2\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u624b\u6cd5\u306e\u4e00\u3064\u304c\u3001IPTW (Inverse Probability o [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":4383,"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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[],"class_list":["post-4379","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-iptw-"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2025\/08\/IPTW_summary_table_propensity_score_distribution_weighted.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/4379","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=4379"}],"version-history":[{"count":9,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/4379\/revisions"}],"predecessor-version":[{"id":4396,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/4379\/revisions\/4396"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/media\/4383"}],"wp:attachment":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/media?parent=4379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/categories?post=4379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/tags?post=4379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}