{"id":126,"date":"2025-06-05T11:09:05","date_gmt":"2025-06-05T02:09:05","guid":{"rendered":"https:\/\/best-biostatistics.com\/toukei-er\/?p=126"},"modified":"2025-06-08T11:12:00","modified_gmt":"2025-06-08T02:12:00","slug":"r-script-for-chi-square-goodness-of-fit-test-sample-size-calculation","status":"publish","type":"post","link":"https:\/\/best-biostatistics.com\/toukei-er\/entry\/r-script-for-chi-square-goodness-of-fit-test-sample-size-calculation\/","title":{"rendered":"R \u3067\u9069\u5408\u5ea6\u306e\u691c\u5b9a\u306b\u5fc5\u8981\u306a\u30b5\u30f3\u30d7\u30eb\u6570\u3092\u8a08\u7b97\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u300c\u3042\u306a\u305f\u306e\u30c7\u30fc\u30bf\u3001\u672c\u5f53\u306b\u305d\u306e\u4eee\u8aac\u306b\u5408\u3063\u3066\u308b\uff1f\u300d&#x1f4c8; \u7d71\u8a08\u5206\u6790\u3067\u3088\u304f\u3042\u308b\u3053\u306e\u7591\u554f\u3002<\/p>\n\n\n\n<p>\u4eca\u56de\u306f\u3001\u89b3\u6e2c\u3055\u308c\u305f\u30c7\u30fc\u30bf\u304c\u3001\u3042\u308b<strong>\u7406\u8ad6\u7684\u306a\u5206\u5e03\u3084\u6bd4\u7387\u306b\u3069\u308c\u304f\u3089\u3044\u300c\u9069\u5408\u3057\u3066\u3044\u308b\u304b\u300d\u3092\u79d1\u5b66\u7684\u306b\u8a55\u4fa1\u3059\u308b<\/strong>\u300c\u9069\u5408\u5ea6\u691c\u5b9a\u300d\u306b\u3064\u3044\u3066\u3001\u57fa\u672c\u304b\u3089\u5177\u4f53\u4f8b\u3001\u5fc5\u8981\u306a\u30b5\u30f3\u30d7\u30eb\u6570\u306e\u8a08\u7b97\u306e\u5b9f\u8df5\u307e\u3067\u3092\u89e3\u8aac\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">\u9069\u5408\u5ea6\u691c\u5b9a\u3068\u306f<\/h2>\n\n\n\n<p>\u9069\u5408\u5ea6\u691c\u5b9a\u306f\u3001\u89b3\u6e2c\u3055\u308c\u305f\u30c7\u30fc\u30bf\u304c\u7279\u5b9a\u306e\u7406\u8ad6\u7684\u5206\u5e03\u3084\u6bd4\u7387\u306b\u3069\u308c\u3060\u3051\u5f53\u3066\u306f\u307e\u308b\u304b\u3092\u7d71\u8a08\u7684\u306b\u8a55\u4fa1\u3059\u308b\u624b\u6cd5\u3060\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u300c\u30b5\u30a4\u30b3\u30ed\u306e\u5404\u76ee\u306e\u51fa\u65b9\u304c\u5747\u7b49\u304b\u300d\u3068\u3044\u3063\u305f\u7591\u554f\u306b\u7b54\u3048\u308b\u969b\u306b\u7528\u3044\u308b\u3002<\/p>\n\n\n\n<p>\u30ab\u30a4\u4e8c\u4e57\u691c\u5b9a\u304c\u4e00\u822c\u7684\u3067\u3001\u89b3\u6e2c\u5ea6\u6570\u3068\u671f\u5f85\u5ea6\u6570\u306e\u30ba\u30ec\u3092\u30ab\u30a4\u4e8c\u4e57\u5024\u3067\u6570\u5024\u5316\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u5024\u3068p\u5024\u306b\u57fa\u3065\u304d\u3001\u30c7\u30fc\u30bf\u304c\u7406\u8ad6\u306b\u9069\u5408\u3059\u308b\u304b\u3092\u5224\u65ad\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u3042\u308b\u30ab\u30c6\u30b4\u30ea\u30ab\u30eb\u5909\u6570\u304c\u7406\u8ad6\u306b\u9069\u5408\u3059\u308b\u304b\u3092\u8abf\u3079\u308b\u3053\u3068\u304c\u76ee\u7684\u3067\u3042\u308a\u3001\u72ec\u7acb\u6027\u306e\u691c\u5b9a\u3068\u306f\u7570\u306a\u308b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u9069\u5408\u5ea6\u691c\u5b9a\u306e\u5177\u4f53\u4f8b<\/h2>\n\n\n\n<p>\u3042\u308b\u88fd\u85ac\u4f1a\u793e\u304c\u65b0\u85ac\u306e\u526f\u4f5c\u7528\u306b\u3064\u3044\u3066\u8abf\u67fb\u3057\u305f\u3068\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u904e\u53bb\u306e\u30c7\u30fc\u30bf\u304b\u3089\u3001\u3053\u306e\u7a2e\u306e\u85ac\u3067\u306f\u300c\u982d\u75db\u300d\u300c\u5410\u304d\u6c17\u300d\u300c\u767a\u75b9\u300d\u306e\u526f\u4f5c\u7528\u304c\u305d\u308c\u305e\u308c20%, 30%, 50%\u306e\u5272\u5408\u3067\u767a\u751f\u3059\u308b\u3053\u3068\u304c\u5206\u304b\u3063\u3066\u3044\u305f\u3002<\/p>\n\n\n\n<p>\u65b0\u85ac\u3092100\u4eba\u306e\u60a3\u8005\u306b\u6295\u4e0e\u3057\u305f\u3068\u3053\u308d\u3001\u982d\u75db\u304c25\u4eba\u3001\u5410\u304d\u6c17\u304c28\u4eba\u3001\u767a\u75b9\u304c47\u4eba\u306b\u767a\u751f\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3053\u3053\u3067\u9069\u5408\u5ea6\u691c\u5b9a\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3001\u300c\u65b0\u85ac\u306e\u526f\u4f5c\u7528\u306e\u767a\u751f\u5272\u5408\u304c\u3001\u3053\u308c\u307e\u3067\u306e\u85ac\u306e\u767a\u751f\u5272\u5408\u3068\u7d71\u8a08\u7684\u306b\u7570\u306a\u3063\u3066\u3044\u308b\u304b\uff1f\u300d\u3092\u5224\u65ad\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<p>\u3082\u3057p\u5024\u304c\u6709\u610f\u6c34\u6e96\uff08\u4f8b\u3048\u30705%\uff09\u3092\u4e0b\u56de\u308c\u3070\u3001\u65b0\u85ac\u306e\u526f\u4f5c\u7528\u306e\u5272\u5408\u306f\u904e\u53bb\u306e\u85ac\u3068\u7570\u306a\u308b\u3068\u7d50\u8ad6\u3067\u304d\u308b\u3060\u308d\u3046\u3002<\/p>\n\n\n\n<p>R \u3067\u8a08\u7b97\u3059\u308b\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. \u89b3\u6e2c\u5ea6\u6570\u306e\u5b9a\u7fa9\n# \u65b0\u85ac\u3092100\u4eba\u306e\u60a3\u8005\u306b\u6295\u4e0e\u3057\u305f\u7d50\u679c\nobserved_counts &lt;- c(\n  \"\u982d\u75db\" = 25,\n  \"\u5410\u304d\u6c17\" = 28,\n  \"\u767a\u75b9\" = 47\n)\n\n# 2. \u671f\u5f85\u3055\u308c\u308b\u6bd4\u7387\uff08\u904e\u53bb\u306e\u30c7\u30fc\u30bf\uff09\u306e\u5b9a\u7fa9\n# \u904e\u53bb\u306e\u30c7\u30fc\u30bf\u304b\u3089\u3001\u526f\u4f5c\u7528\u306e\u767a\u751f\u5272\u5408\u306f\u300c\u982d\u75db: 20%, \u5410\u304d\u6c17: 30%, \u767a\u75b9: 50%\u300d\nexpected_proportions &lt;- c(\n  \"\u982d\u75db\" = 0.20,\n  \"\u5410\u304d\u6c17\" = 0.30,\n  \"\u767a\u75b9\" = 0.50\n)\n\n# 3. \u30ab\u30a4\u4e8c\u4e57\u9069\u5408\u5ea6\u691c\u5b9a\u306e\u5b9f\u884c\n# chisq.test() \u95a2\u6570\u3092\u4f7f\u7528\u3057\u3001\u89b3\u6e2c\u5ea6\u6570 (x) \u3068\u671f\u5f85\u3055\u308c\u308b\u6bd4\u7387 (p) \u3092\u6307\u5b9a\nchi_square_test_result &lt;- chisq.test(x = observed_counts, p = expected_proportions)\n\n# 4. \u691c\u5b9a\u7d50\u679c\u306e\u8868\u793a\ncat(\"--- \u9069\u5408\u5ea6\u691c\u5b9a\u306e\u7d50\u679c ---\\n\")\nprint(chi_square_test_result)\n<\/code><\/pre>\n\n\n\n<p>\u691c\u5b9a\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3001\u6709\u610f\u6c34\u6e965\uff05\u3068\u3059\u308b\u3068\u3001\u904e\u53bb\u306e\u30c7\u30fc\u30bf\u3068\u7570\u306a\u308b\u3068\u306f\u8a00\u3048\u306a\u3044\u3068\u3044\u3046\u7d50\u679c\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> # 4. \u691c\u5b9a\u7d50\u679c\u306e\u8868\u793a\n> cat(\"--- \u9069\u5408\u5ea6\u691c\u5b9a\u306e\u7d50\u679c ---\\n\")\n--- \u9069\u5408\u5ea6\u691c\u5b9a\u306e\u7d50\u679c ---\n> print(chi_square_test_result)\n\n        Chi-squared test for given probabilities\n\ndata:  observed_counts\nX-squared = 1.5633, df = 2, p-value = 0.4576<\/code><\/pre>\n\n\n\n<div id=\"biost-274156977\" 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\">\u9069\u5408\u5ea6\u691c\u5b9a\u306b\u5fc5\u8981\u306a\u30b5\u30f3\u30d7\u30eb\u6570\u306e\u8a08\u7b97<\/h2>\n\n\n\n<p>\u9069\u5408\u5ea6\u691c\u5b9a\u306e\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\u8a08\u7b97\u3092R\u3067\u884c\u3046\u306b\u306f\u3001\u4e3b\u306b<code>pwr<\/code>\u30d1\u30c3\u30b1\u30fc\u30b8\u306e<strong><code>pwr.chisq.test()<\/code><\/strong>\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u95a2\u6570\u3092\u4f7f\u3046\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u60c5\u5831\u304c\u5fc5\u8981<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>w<\/code> (\u52b9\u679c\u91cf Cohen&#8217;s w)<\/strong>: \u691c\u51fa\u3057\u305f\u3044\u52b9\u679c\u306e\u5927\u304d\u3055\u3002\u30ab\u30c6\u30b4\u30ea\u30ab\u30eb\u30c7\u30fc\u30bf\u306e\u5834\u5408\u3001Cohen&#8217;s w\u304c\u7528\u3044\u3089\u308c\u308b\u3002\u5c0f\u3055\u3044\u52b9\u679c(0.1)\u3001\u4e2d\u7a0b\u5ea6\u306e\u52b9\u679c(0.3)\u3001\u5927\u304d\u3044\u52b9\u679c(0.5)\u304c\u76ee\u5b89\u3068\u3055\u308c\u308b\u3002<\/li>\n\n\n\n<li><strong><code>df<\/code> (\u81ea\u7531\u5ea6)<\/strong>: \u30ab\u30c6\u30b4\u30ea\u306e\u6570\u304b\u30891\u3092\u5f15\u3044\u305f\u5024\u3002\u4f8b\u3048\u3070\u30013\u3064\u306e\u30ab\u30c6\u30b4\u30ea\u304c\u3042\u308b\u5834\u5408\u3001df = 3 &#8211; 1 = 2 \u3068\u306a\u308b\u3002<\/li>\n\n\n\n<li><strong><code>sig.level<\/code> (\u6709\u610f\u6c34\u6e96)<\/strong>: \u901a\u5e38\u306f0.05\uff085%\uff09\u304c\u7528\u3044\u3089\u308c\u308b\u3002<\/li>\n\n\n\n<li><strong><code>power<\/code> (\u691c\u51fa\u529b)<\/strong>: \u5e30\u7121\u4eee\u8aac\u304c\u507d\u3067\u3042\u308b\u5834\u5408\u306b\u3001\u6b63\u3057\u304f\u305d\u308c\u3092\u68c4\u5374\u3067\u304d\u308b\u78ba\u7387\u3002\u901a\u5e38\u306f0.8\uff0880%\uff09\u304c\u76ee\u6a19\u3068\u3055\u308c\u308b\u3002<\/li>\n\n\n\n<li><strong><code>N<\/code> (\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba)<\/strong>: \u3053\u308c\u304c\u8a08\u7b97\u3057\u305f\u3044\u5024\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># pwr\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\n# install.packages(\"pwr\")\n\n# pwr\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u8aad\u307f\u8fbc\u3080\nlibrary(pwr)\n\n# \u9069\u5408\u5ea6\u691c\u5b9a\u306e\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\u8a08\u7b97\n# \u30d1\u30e9\u30e1\u30fc\u30bf\u8a2d\u5b9a:\n# w: \u52b9\u679c\u91cf (Cohen's w) - \u4e2d\u7a0b\u5ea6\u306e\u52b9\u679c\u3092\u60f3\u5b9a\n# df: \u81ea\u7531\u5ea6 (\u30ab\u30c6\u30b4\u30ea\u6570 - 1)\u3002\u4f8b: 3\u3064\u306e\u30ab\u30c6\u30b4\u30ea (\u982d\u75db\u3001\u5410\u304d\u6c17\u3001\u767a\u75b9) -&gt; df = 2\n# sig.level: \u6709\u610f\u6c34\u6e96\n# power: \u691c\u51fa\u529b (\u76ee\u6a19\u3068\u3059\u308b\u691c\u51fa\u529b)\nsample_size_result &lt;- pwr.chisq.test(\n  w = 0.3,         # Cohen's w (\u52b9\u679c\u91cf): 0.1(\u5c0f), 0.3(\u4e2d), 0.5(\u5927)\n  df = 2,          # \u81ea\u7531\u5ea6: \u30ab\u30c6\u30b4\u30ea\u6570 - 1\n  sig.level = 0.05, # \u6709\u610f\u6c34\u6e96\n  power = 0.8,     # \u691c\u51fa\u529b\n  N = NULL         # \u8a08\u7b97\u3057\u305f\u3044N\u306fNULL\u306b\u8a2d\u5b9a\n)\n\n# \u7d50\u679c\u306e\u8868\u793a\nprint(sample_size_result)\n\n# \u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\u3092\u3088\u308a\u660e\u78ba\u306b\u8868\u793a\ncat(\"\\n\u5fc5\u8981\u306a\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba (N): \", ceiling(sample_size_result$N), \"\\n\")<\/code><\/pre>\n\n\n\n<p>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3001N = 108 \u3068\u8a08\u7b97\u3055\u308c\u308b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; print(sample_size_result)\n\n     Chi squared power calculation \n\n              w = 0.3\n              N = 107.0521\n             df = 2\n      sig.level = 0.05\n          power = 0.8\n\nNOTE: N is the number of observations\n\n&gt; # \u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\u3092\u3088\u308a\u660e\u78ba\u306b\u8868\u793a\n&gt; cat(\"\\n\u5fc5\u8981\u306a\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba (N): \", ceiling(sample_size_result$N), \"\\n\")\n\n\u5fc5\u8981\u306a\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba (N):  108 <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u52b9\u679c\u91cf w \u306e\u8a08\u7b97\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u3053\u3053\u3067\u3001\u52b9\u679c\u91cf w \u306f\u3069\u306e\u3088\u3046\u306b\u3057\u3066\u8a08\u7b97\u3059\u308b\u304b\u3002<\/p>\n\n\n\n<p>\u9069\u5408\u5ea6\u691c\u5b9a\u306b\u304a\u3051\u308b\u52b9\u679c\u91cf\u3068\u3057\u3066\u3001\u4e00\u822c\u7684\u306b<strong>Cohen&#8217;s w (\u307e\u305f\u306f\u30d5\u30a1\u30a4\u4fc2\u6570 \u03d5)<\/strong> \u304c\u7528\u3044\u3089\u308c\u308b\u3002\u3053\u308c\u306f\u3001\u89b3\u6e2c\u3055\u308c\u305f\u5ea6\u6570\u3068\u671f\u5f85\u3055\u308c\u308b\u5ea6\u6570\u306e\u9593\u306e\u300c\u305a\u308c\u300d\u306e\u5927\u304d\u3055\u3092\u6a19\u6e96\u5316\u3057\u305f\u6307\u6a19\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<p>Cohen&#8217;s w \u306f\u3001\u4ee5\u4e0b\u306e\u8a08\u7b97\u5f0f\u3067\u6c42\u3081\u3089\u308c\u308b\u3002<\/p>\n\n\n\n<p>$$ w=\\sqrt{\\frac{\\chi^2}{N}} $$\u200b<img decoding=\"async\" src=\"\">\u200b<\/p>\n\n\n\n<p>\u3053\u3053\u3067\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u03c72 \u306f\u9069\u5408\u5ea6\u691c\u5b9a\u306b\u3088\u3063\u3066\u5f97\u3089\u308c\u305f<strong>\u30ab\u30a4\u4e8c\u4e57\u5024<\/strong><\/li>\n\n\n\n<li>N \u306f<strong>\u7dcf\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba<\/strong>\uff08\u89b3\u6e2c\u5ea6\u6570\u306e\u5408\u8a08\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u3053\u3067\u306f\u3001\u5148\u306e\u300c\u65b0\u85ac\u306e\u526f\u4f5c\u7528\u300d\u306e\u4f8b\u3092\u4f7f\u3063\u3066\u3001\u30ab\u30a4\u4e8c\u4e57\u691c\u5b9a\u3092\u884c\u3044\u3001\u305d\u306e\u7d50\u679c\u304b\u3089Cohen&#8217;s w\u3092\u8a08\u7b97\u3059\u308bR\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u793a\u3059\u3002<\/p>\n\n\n\n<p><strong>\u4f8b\u984c:<\/strong> \u65b0\u85ac\u3092100\u4eba\u306e\u60a3\u8005\u306b\u6295\u4e0e\u3057\u305f\u3068\u3053\u308d\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u982d\u75db: 25\u4eba<\/li>\n\n\n\n<li>\u5410\u304d\u6c17: 28\u4eba<\/li>\n\n\n\n<li>\u767a\u75b9: 47\u4eba \u304c\u767a\u751f\u3057\u305f\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u904e\u53bb\u306e\u30c7\u30fc\u30bf\u304b\u3089\u3001\u526f\u4f5c\u7528\u306e\u767a\u751f\u5272\u5408\u306f\u300c\u982d\u75db: 20%, \u5410\u304d\u6c17: 30%, \u767a\u75b9: 50%\u300d\u3068\u671f\u5f85\u3055\u308c\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. \u89b3\u6e2c\u5ea6\u6570\u3092\u5b9a\u7fa9\nobserved_counts &lt;- c(25, 28, 47)\nnames(observed_counts) &lt;- c(\"\u982d\u75db\", \"\u5410\u304d\u6c17\", \"\u767a\u75b9\")\n\n# 2. \u671f\u5f85\u3055\u308c\u308b\u6bd4\u7387\u3092\u5b9a\u7fa9 (\u5408\u8a08\u304c1\u306b\u306a\u308b\u3088\u3046\u306b)\nexpected_proportions &lt;- c(0.20, 0.30, 0.50)\n\n# 3. \u30ab\u30a4\u4e8c\u4e57\u9069\u5408\u5ea6\u691c\u5b9a\u3092\u5b9f\u884c\n# chisq.test() \u95a2\u6570\u306f\u3001\u5f15\u6570 p \u306b\u671f\u5f85\u3055\u308c\u308b\u6bd4\u7387\u3092\u6e21\u3059\u3053\u3068\u3067\u9069\u5408\u5ea6\u691c\u5b9a\u3092\u884c\u3046\nchi_square_test_result &lt;- chisq.test(x = observed_counts, p = expected_proportions)\n\n# \u7d50\u679c\u3092\u8868\u793a\nprint(chi_square_test_result)\n\n# 4. \u30ab\u30a4\u4e8c\u4e57\u5024\u3068\u7dcf\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\u3092\u53d6\u5f97\nchi_square_value &lt;- chi_square_test_result$statistic\ntotal_sample_size &lt;- sum(observed_counts)\n\n# 5. Cohen's w \u3092\u8a08\u7b97\ncohens_w &lt;- sqrt(chi_square_value \/ total_sample_size)\n\n# \u7d50\u679c\u3092\u8868\u793a\ncat(\"\\n\u9069\u5408\u5ea6\u691c\u5b9a\u306e\u7d50\u679c:\\n\")\ncat(\"\u30ab\u30a4\u4e8c\u4e57\u5024 (Chi-squared value):\", chi_square_value, \"\\n\")\ncat(\"\u81ea\u7531\u5ea6 (df):\", chi_square_test_result$parameter, \"\\n\")\ncat(\"p\u5024 (p-value):\", chi_square_test_result$p.value, \"\\n\")\ncat(\"\u7dcf\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba (Total N):\", total_sample_size, \"\\n\")\ncat(\"Cohen's w (\u52b9\u679c\u91cf):\", cohens_w, \"\\n\")\n\n# \u52b9\u679c\u91cf\u306e\u89e3\u91c8\u306e\u76ee\u5b89 (Cohen, 1988)\n# w = 0.1: \u5c0f\u3055\u3044\u52b9\u679c\n# w = 0.3: \u4e2d\u7a0b\u5ea6\u306e\u52b9\u679c\n# w = 0.5: \u5927\u304d\u3044\u52b9\u679c<\/code><\/pre>\n\n\n\n<p>\u305d\u306e\u7d50\u679c\u3001\u52b9\u679c\u91cf w \u306f \u7d04 0.125 \u3068\u8a08\u7b97\u3055\u308c\u305f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u9069\u5408\u5ea6\u691c\u5b9a\u306e\u7d50\u679c:\n&gt; cat(\"\u30ab\u30a4\u4e8c\u4e57\u5024 (Chi-squared value):\", chi_square_value, \"\\n\")\n\u30ab\u30a4\u4e8c\u4e57\u5024 (Chi-squared value): 1.563333 \n&gt; cat(\"\u81ea\u7531\u5ea6 (df):\", chi_square_test_result$parameter, \"\\n\")\n\u81ea\u7531\u5ea6 (df): 2 \n&gt; cat(\"p\u5024 (p-value):\", chi_square_test_result$p.value, \"\\n\")\np\u5024 (p-value): 0.4576426 \n&gt; cat(\"\u7dcf\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba (Total N):\", total_sample_size, \"\\n\")\n\u7dcf\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba (Total N): 100 \n&gt; cat(\"Cohen's w (\u52b9\u679c\u91cf):\", cohens_w, \"\\n\")\nCohen's w (\u52b9\u679c\u91cf): 0.1250333 <\/code><\/pre>\n\n\n\n<p>w = 0.125 \u3067\u518d\u8a08\u7b97\u3059\u308b\u3068\u3001617 \u4f8b\u5fc5\u8981\u3068\u8a08\u7b97\u3055\u308c\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> # w = 0.125 \u3067\u518d\u8a08\u7b97\n> sample_size_result &lt;- pwr.chisq.test(\n+     w = 0.125, # Cohen's w (\u52b9\u679c\u91cf): 0.1(\u5c0f), 0.3(\u4e2d), 0.5(\u5927)\n+     df = 2, # \u81ea\u7531\u5ea6: \u30ab\u30c6\u30b4\u30ea\u6570 - 1\n+     sig.level = 0.05, # \u6709\u610f\u6c34\u6e96\n+     power = 0.8, # \u691c\u51fa\u529b\n+     N = NULL # \u8a08\u7b97\u3057\u305f\u3044N\u306fNULL\u306b\u8a2d\u5b9a\n+ )\n> # \u7d50\u679c\u306e\u8868\u793a\n> print(sample_size_result)\n\n     Chi squared power calculation \n\n              w = 0.125\n              N = 616.6201\n             df = 2\n      sig.level = 0.05\n          power = 0.8\n\nNOTE: N is the number of observations\n\n> # \u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\u3092\u3088\u308a\u660e\u78ba\u306b\u8868\u793a\n> cat(\"\\n\u5fc5\u8981\u306a\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba (N): \", ceiling(sample_size_result$N), \"\\n\")\n\n\u5fc5\u8981\u306a\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba (N):  617 \n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u9069\u5408\u5ea6\u691c\u5b9a\u306f\u3001\u89b3\u6e2c\u30c7\u30fc\u30bf\u304c\u3042\u308b\u7406\u8ad6\u7684\u306a\u5206\u5e03\u3084\u6bd4\u7387\u306b\u3069\u308c\u307b\u3069\u300c\u9069\u5408\u3057\u3066\u3044\u308b\u304b\u300d\u3092\u8a55\u4fa1\u3059\u308b\u7d71\u8a08\u624b\u6cd5\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<p>\u30b5\u30a4\u30b3\u30ed\u306e\u76ee\u306e\u51fa\u65b9\u3084\u65b0\u85ac\u306e\u526f\u4f5c\u7528\u6bd4\u7387\u306a\u3069\u3001\u624b\u5143\u306e\u30c7\u30fc\u30bf\u304c\u671f\u5f85\u3055\u308c\u308b\u5272\u5408\u3068\u4e00\u81f4\u3059\u308b\u304b\u3092\u5224\u65ad\u3059\u308b\u969b\u306b\u6d3b\u7528\u3055\u308c\u308b\u3002<\/p>\n\n\n\n<p>\u4e3b\u306b\u30ab\u30a4\u4e8c\u4e57\u691c\u5b9a\u3092\u7528\u3044\u3001\u89b3\u6e2c\u5ea6\u6570\u3068\u671f\u5f85\u5ea6\u6570\u306e\u30ba\u30ec\u304b\u3089\u7d71\u8a08\u7684\u6709\u610f\u6027\u3092\u8a55\u4fa1\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u7814\u7a76\u8a08\u753b\u6642\u306b\u306f\u3001<strong>Cohen&#8217;s w<\/strong>\u306a\u3069\u306e<strong>\u52b9\u679c\u91cf<\/strong>\u3092\u8003\u616e\u3057\u305f<strong>\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\u8a08\u7b97<\/strong>\u304c\u91cd\u8981\u3068\u306a\u308b\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u306b\u3088\u308a\u3001\u52b9\u7387\u7684\u304b\u3064\u4fe1\u983c\u6027\u306e\u9ad8\u3044\u30c7\u30fc\u30bf\u5206\u6790\u304c\u53ef\u80fd\u3068\u306a\u308a\u3001\u30af\u30ea\u30cb\u30ab\u30eb\u30af\u30a8\u30b9\u30c1\u30e7\u30f3\u306b\u79d1\u5b66\u7684\u306a\u6839\u62e0\u3092\u4e0e\u3048\u3066\u304f\u308c\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300c\u3042\u306a\u305f\u306e\u30c7\u30fc\u30bf\u3001\u672c\u5f53\u306b\u305d\u306e\u4eee\u8aac\u306b\u5408\u3063\u3066\u308b\uff1f\u300d&#x1f4c8; \u7d71\u8a08\u5206\u6790\u3067\u3088\u304f\u3042\u308b\u3053\u306e\u7591\u554f\u3002 \u4eca\u56de\u306f\u3001\u89b3\u6e2c\u3055\u308c\u305f\u30c7\u30fc\u30bf\u304c\u3001\u3042\u308b\u7406\u8ad6\u7684\u306a\u5206\u5e03\u3084\u6bd4\u7387\u306b\u3069\u308c\u304f\u3089\u3044\u300c\u9069\u5408\u3057\u3066\u3044\u308b\u304b\u300d\u3092\u79d1\u5b66\u7684\u306b\u8a55\u4fa1\u3059\u308b\u300c\u9069\u5408\u5ea6\u691c\u5b9a\u300d\u306b\u3064\u3044\u3066\u3001\u57fa [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"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,16,51],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-r","category-16","category-51"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/126","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=126"}],"version-history":[{"count":9,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":3917,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/126\/revisions\/3917"}],"wp:attachment":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}