diff --git "a/test.jsonl" "b/test.jsonl" new file mode 100644--- /dev/null +++ "b/test.jsonl" @@ -0,0 +1,11 @@ +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I'm having a hard time finding primary references on semiparametric bootstrapping (i.e. residual bootstrapping) for multilevel/mixed models. This CV question (https://stats.stackexchange.com/questions/29500/parametric-semiparametric-and-nonparametric-bootstrapping-for-mixed-models) refers to Shang and Cavanaugh (2008), but that paper doesn't provide anything going further back. I can't find anything in Chernick (2011) or Efron and Tibshirani (1994) (I haven't looked at Davis and Hinckley, but I would be surprised if there was anything there ...) The other references listed below are interesting, but not useful as far as I can tell.\n\n\n\n\nThe basic question is how one should do residual-based bootstrapping for linear mixed models; do you resample both BLUPs/latent variables and residuals based on cluster-level residuals $\\mathbf y - \\mathbf X \\hat{\\boldsymbol \\beta} - \\mathbf Z \\hat{\\mathbf b}$ (Morris 2002 says this doesn't work)? Simulate $\\mathbf b$ from the unconditional MVN distribution of latent variables (i.e., using the estimated random effects covariance matrices) and add those values to resampled cluster-level residuals and population-level predictions? Use resampled population-level residuals $\\mathbf y - \\mathbf X \\hat{\\boldsymbol \\beta}$ added back to the population-level predictions?\n\n\n\n\nThe last option seems to be what's recommended, but I would really like to see the original discussion/theoretical justification for this ...\n\n\n\n\n\n\n\nChernick, Michael R. Bootstrap Methods: A Guide for Practitioners and Researchers. John Wiley & Sons, 2011.\n\n\n\n\nEfron, Bradley, and R. J. Tibshirani. An Introduction to the Bootstrap. CRC Press, 1994.\n\n\n\n\nMorris, Jeffrey S. “The BLUPs Are Not ‘Best’ When It Comes to Bootstrapping.” Statistics & Probability Letters 56, no. 4 (2002): 425–30. https://doi.org/10.1016/S0167-7152(02)00041-X (https://doi.org/10.1016/S0167-7152(02)00041-X).\n\n\n\n\nShang, Junfeng, and Joseph E. Cavanaugh. “An Assumption for the Development of Bootstrap Variants of the Akaike Information Criterion in Mixed Models.” Statistics & Probability Letters 78, no. 12 (2008): 1422–29. https://doi.org/10.1016/j.spl.2007.12.015 (https://doi.org/10.1016/j.spl.2007.12.015).\n\n\n\n\nThai, Hoai-Thu, France Mentré, Nicholas H. G. Holford, Christine Veyrat-Follet, and Emmanuelle Comets. “A Comparison of Bootstrap Approaches for Estimating Uncertainty of Parameters in Linear Mixed-Effects Models.” Pharmaceutical Statistics 12, no. 3 (2013): 129–40. https://doi.org/10.1002/pst.1561 (https://doi.org/10.1002/pst.1561).", "record_id": "Scientific-Statistics-QA:stats:676832", "selected_answer": {"answer_html": "
I am aware of some discussion of how to bootstrap residuals in (non-linear, but that's more coincidental) mixed effects models in Das and Krishen 1999. This is, again, from the pharmacometrics field like the 2013 paper you found (perhaps where they go their ideas from?).
\nA search additionally let me find Meijer, van der Leeden and Busing 1995, which refers to a user manual for a software called MLA (I've never heard of) from 1994.
\nThat's still 15 years after the start of the bootstrap literature in 1979 and something like 38 to 45 from the beginnings of the jackknife (and mixed models have been around for about that long, too, I think). So there's definitely scope that someone did/published stuff before then. However, older stuff I found like
\nis about resampling cases (i.e. hierachical units) rather than residuals, or
\nwhere it's parametric bootstrapping of residuals.
\n", "answer_id": 676840, "answer_text": "I am aware of some discussion of how to bootstrap residuals in (non-linear, but that's more coincidental) mixed effects models in Das and Krishen 1999 (https://doi.org/10.1016/S0378-3758(98)00145-1). This is, again, from the pharmacometrics field like the 2013 paper you found (perhaps where they go their ideas from?).\n\n\n\n\nA search additionally let me find Meijer, van der Leeden and Busing 1995 (https://www.bristol.ac.uk/media-library/sites/cmm/migrated/documents/new7-2.pdf), which refers to a user manual for a software called MLA (I've never heard of) from 1994.\n\n\n\n\nThat's still 15 years after the start of the bootstrap literature (https://doi.org/10.1214%2Faos%2F1176344552) in 1979 and something like 38 to 45 from the beginnings of the jackknife (and mixed models have been around for about that long, too, I think). So there's definitely scope that someone did/published stuff before then. However, older stuff I found like\n\n\n\n\n\nJ. G. Bagaka. Two Level Nested Hierarchical Linear Model with Random\nIntercepts via the Bootstrap. PhD thesis, Michigan State University, East Lansing, MI, 1992. (Available from University Microfilms International, publication number AAT 9302972, http://www.umi.com (http://www.umi.com))\n\n\n\n\n\nis about resampling cases (i.e. hierachical units) rather than residuals, or\n\n\n\n\n\nBellmann, L., Breitung, J. and Wagner, J., 1989. Bias correction and bootstrapping of error component models for panel data: Theory and applications. Empirical Economics, 14(4), pp.329-342.\n\n\n\n\n\nwhere it's parametric bootstrapping of residuals.", "answer_url": "https://stats.stackexchange.com/a/676840", "author": "Björn", "author_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-11T07:33:29+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676832, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Björn", "profile_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "user_type": "registered"}, "created_at": "2026-08-11T07:33:29+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "32215905-FEAC-4501-8B2E-F8D1D6B1C236", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/32215905-FEAC-4501-8B2E-F8D1D6B1C236/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Björn", "profile_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "user_type": "registered"}, "created_at": "2026-08-11T07:43:14+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "3E76600E-590B-459B-BAD0-E785E7ABDDA0", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3E76600E-590B-459B-BAD0-E785E7ABDDA0/view-source"}], "score": 4, "updated_at": "2026-08-11T07:43:14+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "test", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "I am aware of some discussion of how to bootstrap residuals in (non-linear, but that's more coincidental) mixed effects models in Das and Krishen 1999. This is, again, from the pharmacometrics field like the 2013 paper you found (perhaps where they go their ideas from?).
\nA search additionally let me find Meijer, van der Leeden and Busing 1995, which refers to a user manual for a software called MLA (I've never heard of) from 1994.
\nThat's still 15 years after the start of the bootstrap literature in 1979 and something like 38 to 45 from the beginnings of the jackknife (and mixed models have been around for about that long, too, I think). So there's definitely scope that someone did/published stuff before then. However, older stuff I found like
\nis about resampling cases (i.e. hierachical units) rather than residuals, or
\nwhere it's parametric bootstrapping of residuals.
\n", "answer_id": 676840, "answer_text": "I am aware of some discussion of how to bootstrap residuals in (non-linear, but that's more coincidental) mixed effects models in Das and Krishen 1999 (https://doi.org/10.1016/S0378-3758(98)00145-1). This is, again, from the pharmacometrics field like the 2013 paper you found (perhaps where they go their ideas from?).\n\n\n\n\nA search additionally let me find Meijer, van der Leeden and Busing 1995 (https://www.bristol.ac.uk/media-library/sites/cmm/migrated/documents/new7-2.pdf), which refers to a user manual for a software called MLA (I've never heard of) from 1994.\n\n\n\n\nThat's still 15 years after the start of the bootstrap literature (https://doi.org/10.1214%2Faos%2F1176344552) in 1979 and something like 38 to 45 from the beginnings of the jackknife (and mixed models have been around for about that long, too, I think). So there's definitely scope that someone did/published stuff before then. However, older stuff I found like\n\n\n\n\n\nJ. G. Bagaka. Two Level Nested Hierarchical Linear Model with Random\nIntercepts via the Bootstrap. PhD thesis, Michigan State University, East Lansing, MI, 1992. (Available from University Microfilms International, publication number AAT 9302972, http://www.umi.com (http://www.umi.com))\n\n\n\n\n\nis about resampling cases (i.e. hierachical units) rather than residuals, or\n\n\n\n\n\nBellmann, L., Breitung, J. and Wagner, J., 1989. Bias correction and bootstrapping of error component models for panel data: Theory and applications. Empirical Economics, 14(4), pp.329-342.\n\n\n\n\n\nwhere it's parametric bootstrapping of residuals.", "answer_url": "https://stats.stackexchange.com/a/676840", "author": "Björn", "author_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-11T07:33:29+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676832, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Björn", "profile_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "user_type": "registered"}, "created_at": "2026-08-11T07:33:29+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "32215905-FEAC-4501-8B2E-F8D1D6B1C236", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/32215905-FEAC-4501-8B2E-F8D1D6B1C236/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Björn", "profile_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "user_type": "registered"}, "created_at": "2026-08-11T07:43:14+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "3E76600E-590B-459B-BAD0-E785E7ABDDA0", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3E76600E-590B-459B-BAD0-E785E7ABDDA0/view-source"}], "score": 4, "updated_at": "2026-08-11T07:43:14+00:00"}], "domain": "statistics", "external_links": ["http://www.umi.com", "https://doi.org/10.1002/pst.1561", "https://doi.org/10.1016/S0167-7152(02)00041-X", "https://doi.org/10.1016/S0378-3758(98)00145-1", "https://doi.org/10.1016/j.spl.2007.12.015", "https://doi.org/10.1214%2Faos%2F1176344552", "https://www.bristol.ac.uk/media-library/sites/cmm/migrated/documents/new7-2.pdf"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Ben Bolker", "question_author_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "question_author_user_type": "registered", "question_created_at": "2026-08-10T18:14:05+00:00", "question_html": "I'm having a hard time finding primary references on semiparametric bootstrapping (i.e. residual bootstrapping) for multilevel/mixed models. This CV question refers to Shang and Cavanaugh (2008), but that paper doesn't provide anything going further back. I can't find anything in Chernick (2011) or Efron and Tibshirani (1994) (I haven't looked at Davis and Hinckley, but I would be surprised if there was anything there ...) The other references listed below are interesting, but not useful as far as I can tell.
\nThe basic question is how one should do residual-based bootstrapping for linear mixed models; do you resample both BLUPs/latent variables and residuals based on cluster-level residuals $\\mathbf y - \\mathbf X \\hat{\\boldsymbol \\beta} - \\mathbf Z \\hat{\\mathbf b}$ (Morris 2002 says this doesn't work)? Simulate $\\mathbf b$ from the unconditional MVN distribution of latent variables (i.e., using the estimated random effects covariance matrices) and add those values to resampled cluster-level residuals and population-level predictions? Use resampled population-level residuals $\\mathbf y - \\mathbf X \\hat{\\boldsymbol \\beta}$ added back to the population-level predictions?
\nThe last option seems to be what's recommended, but I would really like to see the original discussion/theoretical justification for this ...
\nChernick, Michael R. Bootstrap Methods: A Guide for Practitioners and Researchers. John Wiley & Sons, 2011.
\nEfron, Bradley, and R. J. Tibshirani. An Introduction to the Bootstrap. CRC Press, 1994.
\nMorris, Jeffrey S. “The BLUPs Are Not ‘Best’ When It Comes to Bootstrapping.” Statistics & Probability Letters 56, no. 4 (2002): 425–30. https://doi.org/10.1016/S0167-7152(02)00041-X.
\nShang, Junfeng, and Joseph E. Cavanaugh. “An Assumption for the Development of Bootstrap Variants of the Akaike Information Criterion in Mixed Models.” Statistics & Probability Letters 78, no. 12 (2008): 1422–29. https://doi.org/10.1016/j.spl.2007.12.015.
\nThai, Hoai-Thu, France Mentré, Nicholas H. G. Holford, Christine Veyrat-Follet, and Emmanuelle Comets. “A Comparison of Bootstrap Approaches for Estimating Uncertainty of Parameters in Linear Mixed-Effects Models.” Pharmaceutical Statistics 12, no. 3 (2013): 129–40. https://doi.org/10.1002/pst.1561.
\n", "question_id": 676832, "question_license": "CC BY-SA 4.0", "question_score": 7, "question_text": "I'm having a hard time finding primary references on semiparametric bootstrapping (i.e. residual bootstrapping) for multilevel/mixed models. This CV question (https://stats.stackexchange.com/questions/29500/parametric-semiparametric-and-nonparametric-bootstrapping-for-mixed-models) refers to Shang and Cavanaugh (2008), but that paper doesn't provide anything going further back. I can't find anything in Chernick (2011) or Efron and Tibshirani (1994) (I haven't looked at Davis and Hinckley, but I would be surprised if there was anything there ...) The other references listed below are interesting, but not useful as far as I can tell.\n\n\n\n\nThe basic question is how one should do residual-based bootstrapping for linear mixed models; do you resample both BLUPs/latent variables and residuals based on cluster-level residuals $\\mathbf y - \\mathbf X \\hat{\\boldsymbol \\beta} - \\mathbf Z \\hat{\\mathbf b}$ (Morris 2002 says this doesn't work)? Simulate $\\mathbf b$ from the unconditional MVN distribution of latent variables (i.e., using the estimated random effects covariance matrices) and add those values to resampled cluster-level residuals and population-level predictions? Use resampled population-level residuals $\\mathbf y - \\mathbf X \\hat{\\boldsymbol \\beta}$ added back to the population-level predictions?\n\n\n\n\nThe last option seems to be what's recommended, but I would really like to see the original discussion/theoretical justification for this ...\n\n\n\n\n\n\n\nChernick, Michael R. Bootstrap Methods: A Guide for Practitioners and Researchers. John Wiley & Sons, 2011.\n\n\n\n\nEfron, Bradley, and R. J. Tibshirani. An Introduction to the Bootstrap. CRC Press, 1994.\n\n\n\n\nMorris, Jeffrey S. “The BLUPs Are Not ‘Best’ When It Comes to Bootstrapping.” Statistics & Probability Letters 56, no. 4 (2002): 425–30. https://doi.org/10.1016/S0167-7152(02)00041-X (https://doi.org/10.1016/S0167-7152(02)00041-X).\n\n\n\n\nShang, Junfeng, and Joseph E. Cavanaugh. “An Assumption for the Development of Bootstrap Variants of the Akaike Information Criterion in Mixed Models.” Statistics & Probability Letters 78, no. 12 (2008): 1422–29. https://doi.org/10.1016/j.spl.2007.12.015 (https://doi.org/10.1016/j.spl.2007.12.015).\n\n\n\n\nThai, Hoai-Thu, France Mentré, Nicholas H. G. Holford, Christine Veyrat-Follet, and Emmanuelle Comets. “A Comparison of Bootstrap Approaches for Estimating Uncertainty of Parameters in Linear Mixed-Effects Models.” Pharmaceutical Statistics 12, no. 3 (2013): 129–40. https://doi.org/10.1002/pst.1561 (https://doi.org/10.1002/pst.1561).", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-08-10T18:14:05+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "D42FF201-3D9E-41EE-AD38-D701B246BD21", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D42FF201-3D9E-41EE-AD38-D701B246BD21/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-08-10T18:34:39+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "30821CFD-69CB-49E7-8636-CD19053C6EFF", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/30821CFD-69CB-49E7-8636-CD19053C6EFF/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-11T09:36:33+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "4D25C7FB-5C99-4487-BCBA-B001C9D9782A", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4D25C7FB-5C99-4487-BCBA-B001C9D9782A/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676832/references-on-semiparametric-bootstrapping-in-mixed-multilevel-models", "split": "test", "split_group": "f66badcf3bceb0e03ae228ad9fa4fe002bfb6ea62c52876caa0f2adeb9118dde", "tags": ["mixed-model", "bootstrap"], "thread_id": "stats:676832", "title": "references on semiparametric bootstrapping in mixed/multilevel models"}} +{"accepted_answer": {"answer_html": "I would suggest you look at a changing a couple of things:
\nThe distribution of Age is quite skewed, with some data squished up around 0 age. I would suggest trying to spread these values by out transforming Age, say via a square root transformation.
If you look at the smooth of Age, most of the smooth is supported by by a few unique time points - the whole right hand side of the plot. Those unique ages are having a potentially bigger influence on the shape of the function than the ages that are all squished up at the left of the x axis. Spreading out the ages allows all the data to influence the smooth more evenly. You can still present the results on the Age scale, What we want to avoid is unnecessary wiggles because the smooth adapted to widely spaced values on the original scale.
\nThe fs smooths by Taxon aren't really doing much because they are very restricted in terms of basis functions.
There is potential for an identifiability issue as you include a Taxon random intercept through the fs smooths, and then again through the ranef structure.
Identifiability refers to the model's ability to unique identify (estimate a value for) each parameter in the model. You are including a random intercept for taxon through the random argument and the fs basis also includes a random intercept term for taxon. As you have included the same variable in the model twice, the model has no way of knowing how to apportion variance in the response between these terms. This will often cause estimation problems and even if the models fit OK, you will likely have larger standard errors than if you didn't have the identifiability problem.
You will have to explain what you are trying or aiming to do rather than show what you did and ask if it is OK; it is not clear what the aim of the analysis, what model you are trying to fit, or how the data are structured, etc. (what is To Fa for example?).
Unless you think the mean of Asfc for individual taxa changes over time smoothly, then there is no reason to use the taxon specific fs smooths. The random effect structure you propose seems reasonable, except I'm unclear from your description if you have multiple observations of Asfc per Facet? Or is facet informative in some way (inside vs top surface for example). If you don't have multiple observations per facet, you don't need the lowermost level in your ranef structure I believe. If individual taxa have different mean values of complexity (which I understand to be true broadly, but perhaps not in your specific group of taxa) then I think you do need Taxon at the highest level of the random effect structure.
Finally, your model assume that the response Acsf values are conditional distributed Gaussian, meaning any value, negative or positive, is possible. If it is measuring complexity, that implies to me that negative values of the response are not observable, which would suggest the Gaussian is not appropriate. But perhaps this is not the case; the partial residuals don't look too bad, but proper model diagnostics would be need to confirm this. You also might need to consider the problem of temporal autocorrelation, although the Age smooth will help with that to some extent.
\n\nAs an aside, how do I only plot the first plot?
\n
Use the select argument to gratia' draw() function. This is a generic function so you need to look at the help for the gam method.
I would suggest you look at a changing a couple of things:
\nThe distribution of Age is quite skewed, with some data squished up around 0 age. I would suggest trying to spread these values by out transforming Age, say via a square root transformation.
If you look at the smooth of Age, most of the smooth is supported by by a few unique time points - the whole right hand side of the plot. Those unique ages are having a potentially bigger influence on the shape of the function than the ages that are all squished up at the left of the x axis. Spreading out the ages allows all the data to influence the smooth more evenly. You can still present the results on the Age scale, What we want to avoid is unnecessary wiggles because the smooth adapted to widely spaced values on the original scale.
\nThe fs smooths by Taxon aren't really doing much because they are very restricted in terms of basis functions.
There is potential for an identifiability issue as you include a Taxon random intercept through the fs smooths, and then again through the ranef structure.
Identifiability refers to the model's ability to unique identify (estimate a value for) each parameter in the model. You are including a random intercept for taxon through the random argument and the fs basis also includes a random intercept term for taxon. As you have included the same variable in the model twice, the model has no way of knowing how to apportion variance in the response between these terms. This will often cause estimation problems and even if the models fit OK, you will likely have larger standard errors than if you didn't have the identifiability problem.
You will have to explain what you are trying or aiming to do rather than show what you did and ask if it is OK; it is not clear what the aim of the analysis, what model you are trying to fit, or how the data are structured, etc. (what is To Fa for example?).
Unless you think the mean of Asfc for individual taxa changes over time smoothly, then there is no reason to use the taxon specific fs smooths. The random effect structure you propose seems reasonable, except I'm unclear from your description if you have multiple observations of Asfc per Facet? Or is facet informative in some way (inside vs top surface for example). If you don't have multiple observations per facet, you don't need the lowermost level in your ranef structure I believe. If individual taxa have different mean values of complexity (which I understand to be true broadly, but perhaps not in your specific group of taxa) then I think you do need Taxon at the highest level of the random effect structure.
Finally, your model assume that the response Acsf values are conditional distributed Gaussian, meaning any value, negative or positive, is possible. If it is measuring complexity, that implies to me that negative values of the response are not observable, which would suggest the Gaussian is not appropriate. But perhaps this is not the case; the partial residuals don't look too bad, but proper model diagnostics would be need to confirm this. You also might need to consider the problem of temporal autocorrelation, although the Age smooth will help with that to some extent.
\n\nAs an aside, how do I only plot the first plot?
\n
Use the select argument to gratia' draw() function. This is a generic function so you need to look at the help for the gam method.
I would suggest you look at a changing a couple of things:
\nThe distribution of Age is quite skewed, with some data squished up around 0 age. I would suggest trying to spread these values by out transforming Age, say via a square root transformation.
If you look at the smooth of Age, most of the smooth is supported by by a few unique time points - the whole right hand side of the plot. Those unique ages are having a potentially bigger influence on the shape of the function than the ages that are all squished up at the left of the x axis. Spreading out the ages allows all the data to influence the smooth more evenly. You can still present the results on the Age scale, What we want to avoid is unnecessary wiggles because the smooth adapted to widely spaced values on the original scale.
\nThe fs smooths by Taxon aren't really doing much because they are very restricted in terms of basis functions.
There is potential for an identifiability issue as you include a Taxon random intercept through the fs smooths, and then again through the ranef structure.
Identifiability refers to the model's ability to unique identify (estimate a value for) each parameter in the model. You are including a random intercept for taxon through the random argument and the fs basis also includes a random intercept term for taxon. As you have included the same variable in the model twice, the model has no way of knowing how to apportion variance in the response between these terms. This will often cause estimation problems and even if the models fit OK, you will likely have larger standard errors than if you didn't have the identifiability problem.
You will have to explain what you are trying or aiming to do rather than show what you did and ask if it is OK; it is not clear what the aim of the analysis, what model you are trying to fit, or how the data are structured, etc. (what is To Fa for example?).
Unless you think the mean of Asfc for individual taxa changes over time smoothly, then there is no reason to use the taxon specific fs smooths. The random effect structure you propose seems reasonable, except I'm unclear from your description if you have multiple observations of Asfc per Facet? Or is facet informative in some way (inside vs top surface for example). If you don't have multiple observations per facet, you don't need the lowermost level in your ranef structure I believe. If individual taxa have different mean values of complexity (which I understand to be true broadly, but perhaps not in your specific group of taxa) then I think you do need Taxon at the highest level of the random effect structure.
Finally, your model assume that the response Acsf values are conditional distributed Gaussian, meaning any value, negative or positive, is possible. If it is measuring complexity, that implies to me that negative values of the response are not observable, which would suggest the Gaussian is not appropriate. But perhaps this is not the case; the partial residuals don't look too bad, but proper model diagnostics would be need to confirm this. You also might need to consider the problem of temporal autocorrelation, although the Age smooth will help with that to some extent.
\n\nAs an aside, how do I only plot the first plot?
\n
Use the select argument to gratia' draw() function. This is a generic function so you need to look at the help for the gam method.
I have ~1400 measurements of teeth from ~40 species (taxon) that go back in time ~35mya (Age).\nThe data is noisy, so there is repetition in measurements from specimens that requires nesting as a random effect.
\nI wish to see if there are trends in this data through time. I can see the trends as individual taxon boxplots if I roughly order them by time, but I would highly prefer Age as a continuous variable and the repetition accounted for.
\nThe problem is that taxa (i.e. species) generally exist for 1my or less, and there are large gaps, so if I understand gamms properly (not a given here lol) then the smoothing splines will be (in my simple terms) trying to extrapolate/estimate the curves for a species across the entire dataset where they don't really exist. I have tried to compensate for this using factor smoothing for taxon.
\nTo cut to the point after much testing and fiddling, I came up with this:
\ntemp3 <- gamm4(Asfc ~ s(Age, k = 8, bs = "tp") + s(Age, taxon, bs = "fs", k = 3), data = df, random = ~(1|taxon/Specimen/To/Fa))\ntemp4 <- gamm4(Asfc ~ s(Age, k = 8, bs = "tp") + s(Age, taxon, bs = "fs", k = 3), data = df, random = ~(1|Specimen/To/Fa))\ndraw(temp3$gam, residuals = TRUE)\n\nAnd I get something like this:\n
For this data am I "gamm-ing" correctly? The second plot suggests errr no, or is that just the intercept and slope for taxon influence?
\nShould taxon be in the random effect structure? There are many specimens of each taxon.
\nAs an aside, how do I only plot the first plot?
\n------ Edit for clarification from questions (and comments) below ------
\nEach measurement is in this example a "complexity" value of a single facet (Fa has four levels), from a tooth (To has 8 levels). There are 1 to 8 measurements per Specimen requiring it to be a random effect. Each Specimen does belong to a species, though Species may or may not require nesting, or inclusion in the model per se, since most species have a single value for age, or are spread over 0.5 million years at most, it is highly correlated to Age and may be superfluous. Asfc is continuous, well normalised, and is considered gaussian.
\nThis is an updated model with model check based on comments : gamm4(Asfc ~ s(sqrtAge, k = 8, bs ="tp"), data = df, random = ~(1|Specimen/ToothNoLR/Facet))\n
RE check_model() I'm doing this to look for verifiable trends, not for prediction. I realise the large gaps would make the latter difficult, so this is more exploratory to see if a signal is present.
$mer\nLinear mixed model fit by REML ['lmerMod']\nREML criterion at convergence: 3606.394\nRandom effects:\n Groups Name Std.Dev.\n Facet:ToothNoLR:Specimen (Intercept) 0.4767 \n ToothNoLR:Specimen (Intercept) 0.3814 \n Specimen (Intercept) 0.6024 \n Xr s(sqrt(Age)) 7.7972 \n Residual 0.4563 \nNumber of obs: 1442, groups: Facet:ToothNoLR:Specimen, 1430; ToothNoLR:Specimen, 542; Specimen, 421; Xr, 6\nFixed Effects:\n X(Intercept) Xs(sqrt(Age))Fx1 \n 0.008243 -0.872465 \n\n$gam\n\nFamily: gaussian \nLink function: identity \n\nFormula:\nAsfc ~ s(sqrt(Age), k = 8, bs = "tp")\n\nEstimated degrees of freedom:\n5.56 total = 6.56 \n\nlmer.REML score: 3606.394 \n\nattr(,"class")\n[1] "gamm4" "list" \n\n------ 2nd edit updating random effect structure ------\nHere is the model with taxon added. The CI's are worse, but I suspect it is a "truer" model. gamm4(Asfc ~ s(sqrt(Age), k = 8, bs ="tp"), data = df, random = ~(1|taxon/Specimen/ToothNoLR/Facet))
The check shows a more even spread of residuals.
\n\nThese are the new results.
\n> temp3 <- gamm4(Asfc ~ s(sqrt(Age), k = 8, bs ="tp"), data = df, random = ~(1|taxon/Specimen/ToothNoLR/Facet))\n> temp3\n$mer\nLinear mixed model fit by REML ['lmerMod']\nREML criterion at convergence: 3566.052\nRandom effects:\n Groups Name Std.Dev.\n Facet:ToothNoLR:Specimen:taxon (Intercept) 0.4786 \n ToothNoLR:Specimen:taxon (Intercept) 0.3614 \n Specimen:taxon (Intercept) 0.5246 \n taxon (Intercept) 0.4379 \n Xr s(sqrt(Age)) 4.5753 \n Residual 0.4561 \nNumber of obs: 1442, groups: Facet:ToothNoLR:Specimen:taxon, 1430; ToothNoLR:Specimen:taxon, 542; Specimen:taxon, 423; taxon, 46; Xr, 6\nFixed Effects:\n X(Intercept) Xs(sqrt(Age))Fx1 \n -0.04013 -0.01014 \n\n$gam\n\nFamily: gaussian \nLink function: identity \n\nFormula:\nAsfc ~ s(sqrt(Age), k = 8, bs = "tp")\n\nEstimated degrees of freedom:\n4.3 total = 5.3 \n\nlmer.REML score: 3566.053\n\nCompare them to the results where Age is not sqrt()'ed
> temp3 <- gamm4(Asfc ~ s(Age, k = 8, bs ="tp"), data = df, random = ~(1|taxon/Specimen/ToothNoLR/Facet))\n> temp3\n$mer\nLinear mixed model fit by REML ['lmerMod']\nREML criterion at convergence: 3566.762\nRandom effects:\n Groups Name Std.Dev.\n Facet:ToothNoLR:Specimen:taxon (Intercept) 0.4651 \n ToothNoLR:Specimen:taxon (Intercept) 0.3611 \n Specimen:taxon (Intercept) 0.5317 \n taxon (Intercept) 0.3790 \n Xr s(Age) 7.4438 \n Residual 0.4692 \nNumber of obs: 1442, groups: Facet:ToothNoLR:Specimen:taxon, 1430; ToothNoLR:Specimen:taxon, 542; Specimen:taxon, 423; taxon, 46; Xr, 6\nFixed Effects:\nX(Intercept) Xs(Age)Fx1 \n -0.04286 -0.98535 \n\n$gam\n\nFamily: gaussian \nLink function: identity \n\nFormula:\nAsfc ~ s(Age, k = 8, bs = "tp")\n\nEstimated degrees of freedom:\n4.77 total = 5.77 \n\nlmer.REML score: 3566.762 \n\nI would appreciate any help in interpreting all this.
\n------ Edit ------\nIn reply to the posterior predictive check. Removal of Facet.\n
\ntemp3 without Facet in nesting, temp4 with Facet in nesting.
> compare_performance(temp3, temp4)\n# Comparison of Model Performance Indices\n\nName | Model | AIC (weights) | BIC (weights) | R2 | RMSE | Sigma\n-----------------------------------------------------------------------\ntemp3 | gamm4 | 4031.8 (0.475) | 4065.0 (0.484) | 0.049 | 0.572 | 0.573\ntemp4 | gamm4 | 4031.6 (0.525) | 4064.8 (0.516) | 0.049 | 0.274 | 0.275\n\n------ quick edit ------\nSo, yes, when I check $mer I get these results, and it appears to be(?), the missing "components" to complete the response?:
> model_performance(temp3$mer)\n# Indices of model performance\n\nAIC | AICc | BIC | R2 (cond.) | R2 (marg.) | ICC | RMSE | Sigma\n--------------------------------------------------------------------------\n3581.9 | 3582.0 | 3618.9 | 0.579 | 1.298e-04 | 0.579 | 0.572 | 0.660\n\n> icc(temp3$mer, by_group = TRUE)\n\nGroup | ICC\n--------------------------------\nToothNoLR:Specimen:taxon | 0.127\nSpecimen:taxon | 0.267\ntaxon | 0.185\n> check_model(temp3$mer)\n\nJust the lmer component predictive curve.\n
> check_model(temp3) Throws an error, so it seems it is incapable of incorporating both $mer and $gam into the check.
If entity name is mostly determined by VIN prefix, then use Felligi-Sunter on only VIN prefix + incident month and estimate likelihood ratios and confidence based on only those two fields. You can separately filter on entity name match as well, but it should not increase your confidence score.
\nBased on what you've said, you don't have enough information to reliably match records from the information provided here. No amount of fancy statistics will solve that problem: if there isn't enough information, there isn't enough information.
\nYou can gain greater confidence for that conclusion by manually trying to match a small subset of records and comparing to what these methods provide. In statistics, "look at the data" is often a good heuristic to help strengthen your intuition, before you dive into fancy mathematics.
\n", "answer_id": 676906, "answer_text": "If entity name is mostly determined by VIN prefix, then use Felligi-Sunter on only VIN prefix + incident month and estimate likelihood ratios and confidence based on only those two fields. You can separately filter on entity name match as well, but it should not increase your confidence score.\n\n\n\n\nBased on what you've said, you don't have enough information to reliably match records from the information provided here. No amount of fancy statistics will solve that problem: if there isn't enough information, there isn't enough information.\n\n\n\n\nYou can gain greater confidence for that conclusion by manually trying to match a small subset of records and comparing to what these methods provide. In statistics, \"look at the data\" is often a good heuristic to help strengthen your intuition, before you dive into fancy mathematics.", "answer_url": "https://stats.stackexchange.com/a/676906", "author": "D.W.", "author_url": "https://stats.stackexchange.com/users/2921/d-w", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-18T17:17:26+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676898, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "D.W.", "profile_url": "https://stats.stackexchange.com/users/2921/d-w", "user_type": "registered"}, "created_at": "2026-08-18T17:17:26+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "948374FD-DEEA-4B62-AC73-93864CE78B36", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/948374FD-DEEA-4B62-AC73-93864CE78B36/view-source"}], "score": 1, "updated_at": "2026-08-18T17:17:26+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "test", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "If entity name is mostly determined by VIN prefix, then use Felligi-Sunter on only VIN prefix + incident month and estimate likelihood ratios and confidence based on only those two fields. You can separately filter on entity name match as well, but it should not increase your confidence score.
\nBased on what you've said, you don't have enough information to reliably match records from the information provided here. No amount of fancy statistics will solve that problem: if there isn't enough information, there isn't enough information.
\nYou can gain greater confidence for that conclusion by manually trying to match a small subset of records and comparing to what these methods provide. In statistics, "look at the data" is often a good heuristic to help strengthen your intuition, before you dive into fancy mathematics.
\n", "answer_id": 676906, "answer_text": "If entity name is mostly determined by VIN prefix, then use Felligi-Sunter on only VIN prefix + incident month and estimate likelihood ratios and confidence based on only those two fields. You can separately filter on entity name match as well, but it should not increase your confidence score.\n\n\n\n\nBased on what you've said, you don't have enough information to reliably match records from the information provided here. No amount of fancy statistics will solve that problem: if there isn't enough information, there isn't enough information.\n\n\n\n\nYou can gain greater confidence for that conclusion by manually trying to match a small subset of records and comparing to what these methods provide. In statistics, \"look at the data\" is often a good heuristic to help strengthen your intuition, before you dive into fancy mathematics.", "answer_url": "https://stats.stackexchange.com/a/676906", "author": "D.W.", "author_url": "https://stats.stackexchange.com/users/2921/d-w", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-18T17:17:26+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676898, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "D.W.", "profile_url": "https://stats.stackexchange.com/users/2921/d-w", "user_type": "registered"}, "created_at": "2026-08-18T17:17:26+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "948374FD-DEEA-4B62-AC73-93864CE78B36", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/948374FD-DEEA-4B62-AC73-93864CE78B36/view-source"}], "score": 1, "updated_at": "2026-08-18T17:17:26+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Jak Potvin", "question_author_url": "https://stats.stackexchange.com/users/515560/jak-potvin", "question_author_user_type": "registered", "question_created_at": "2026-08-18T01:33:20+00:00", "question_html": "This is the parameter estimation half of a linkage problem I described separately in this question, which asks whether a deterministic gate is the defensible alternative. Here I want to ask only about the estimation side.
\nThe setting in brief: two public datasets of vehicle incidents published by the same regulator (NHTSA) but collected through separate channels, with no labelled data and no external record establishing which pairs are true matches.
\nThe comparison vector is three fields
\nTwo properties concern me
\nThe fields are strongly dependent, not conditionally independent given match status. Entity name effectively determines the VIN prefix range, since prefixes are manufacturer specific. Agreement on prefix implies agreement on name almost by construction. The standard conditional independence assumption in Fellegi-Sunter looks straightforwardly violated here, and not in a subtle way.
\nThe population is severely concentrated. In my snapshot, a single vehicle configuration accounts for roughly 950 filings, against 18 consumer complaints for that same configuration in total. Frequencies are dominated by a few very large strata. Against 1,181 independent records, a conservative deterministic gate yields 44 links in one subpopulation and 0 in the other, so the match class is somewhere between very small and empty.
\nQuestions
\nI am asking about method only. The code built on this linkage computes no match rate as a claim about anyone's behaviour, produces no conduct claims, and names no organization as having done anything. It reports differences between two cited documents and stops. I would rather be told this approach does not hold up than be reassured that it does.
\n", "question_id": 676898, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "This is the parameter estimation half of a linkage problem I described separately in this question (https://stats.stackexchange.com/questions/676889/is-a-deterministic-linkage-gate-the-honest-choice-when-no-labelled-data-exists), which asks whether a deterministic gate is the defensible alternative. Here I want to ask only about the estimation side.\n\n\n\n\nThe setting in brief: two public datasets of vehicle incidents published by the same regulator (NHTSA) but collected through separate channels, with no labelled data and no external record establishing which pairs are true matches.\n\n\n\n\nThe comparison vector is three fields\n\n\n\n\n\nReporting entity name, free text, fuzzy compared after normalization.\n\n\n\n\nAn 11 character VIN prefix, which identifies a configuration, model year and plant, shared by thousands of vehicles, not an individual vehicle.\n\n\n\n\nIncident month, because one source publishes month precision only.\n\n\n\n\n\nTwo properties concern me\n\n\n\n\nThe fields are strongly dependent, not conditionally independent given match status. Entity name effectively determines the VIN prefix range, since prefixes are manufacturer specific. Agreement on prefix implies agreement on name almost by construction. The standard conditional independence assumption in Fellegi-Sunter looks straightforwardly violated here, and not in a subtle way.\n\n\n\n\nThe population is severely concentrated. In my snapshot, a single vehicle configuration accounts for roughly 950 filings, against 18 consumer complaints for that same configuration in total. Frequencies are dominated by a few very large strata. Against 1,181 independent records, a conservative deterministic gate yields 44 links in one subpopulation and 0 in the other, so the match class is somewhere between very small and empty.\n\n\n\n\nQuestions\n\n\n\n\n\nDoes Fellegi-Sunter buy anything when m and u can only come from EM over a comparison vector this thin and this correlated? My concern is that the model converges, reports parameters, and produces match weights that look principled, while those parameters are determined by my choice of comparison functions rather than by evidence in the data.\n\n\n\n\nWhat is the appropriate null model for chance agreement under this much concentration? Independent marginals seem clearly wrong when one stratum holds roughly 950 of the records. Is there a standard treatment of u probabilities under heavy stratum concentration, or is the usual answer to estimate u within blocks?\n\n\n\n\nIs there a diagnostic that would tell me EM has fit noise here rather than structure, given that I cannot check its output against any labelled pairs?\n\n\n\n\n\nI am asking about method only. The code built on this linkage computes no match rate as a claim about anyone's behaviour, produces no conduct claims, and names no organization as having done anything. It reports differences between two cited documents and stops. I would rather be told this approach does not hold up than be reassured that it does.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Jak Potvin", "profile_url": "https://stats.stackexchange.com/users/515560/jak-potvin", "user_type": "registered"}, "created_at": "2026-08-18T01:33:20+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "8FD5C245-A5FE-4051-A466-B659BDBC86B8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8FD5C245-A5FE-4051-A466-B659BDBC86B8/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676898/estimating-m-and-u-by-em-when-the-comparison-vector-is-thin-and-highly-correlate", "split": "test", "split_group": "e27f34572979f0cf8fec5d1776b21a0e55eff099c1e3ee4d9486c0fe792d25a7", "tags": ["unsupervised-learning", "expectation-maximization", "mixture-distribution", "record-linkage"], "thread_id": "stats:676898", "title": "Estimating m and u by EM when the comparison vector is thin and highly correlated: what null model for chance agreement under extreme concentration?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I'm working on a medical image segmentation problem. I have the source images, automated annotations, and manual annotations from two human raters. The annotations have two formats: predefined regions, and per-pixel annotation.\n\n\n\n\nFor the predefined regions, each rater overlaid a map of 44 semantically meaningful regions onto the source image and annotated each region as True/False. For a given example, there are therefore 44 binary variables that each rater can agree or disagree on.\n\n\n\n\nFor the per-pixel annotation, each rater created a pixel mask to identify the region of interest. For a given example, each rater could therefore agree or disagree on each individual pixel in the image.\n\n\n\n\nThe \"ground truth\" is the human annotations. The humans don't perfectly agree on their annotations. The nature of the task means that for the per-pixel annotation there's a fair amount of possible disagreement without one rater being \"wrong\".\n\n\n\n\nI want to assess the reliability of my automated annotations. I have calculated some metrics between each pair of raters (rater a to automated, rater b to automated, rater a to rater b). For the predefined regions I calculated the Jaccard index on a per-region basis, and for the per-pixel annotations I calculated the Jaccard index on a per-pixel basis, plus the Normalised Surface Distance.\n\n\n\n\nAs far as I know, there aren't established conventions on what is \"good\" for these metrics on this task. One of my coauthors is strongly advocating to use ICC thresholds from this paper (https://pmc.ncbi.nlm.nih.gov/articles/PMC4913118/#bb0090) to interpret those metrics (<0.5 is poor, 0.5 to 0.75 is moderate, 0.75 to 0.9 is good, >0.9 is excellent). I'm unhappy about this because I think ICC is fundamentally different from the metrics we've used.\n\n\n\n\nMy coauthor is happy to use different thresholds if I can find more relevant ones, but does want a specific cutoff that we call good, excellent etc. I can't find any resources for more relevant thresholds.\n\n\n\n\nIs it reasonable to use these thresholds to interpret Jaccard index and Normalised Surface Distance on an image segmentation task? Is there an established way to decide what \"good\" agreement is for these metrics?", "record_id": "Scientific-Statistics-QA:stats:676924", "selected_answer": {"answer_html": "A few thoughts:
\n\n\nMy coauthor ... does want a specific cutoff that we call good, excellent etc.
\n
This probably isn't a useful goal. What presumably matters is whether the differences in annotation will matter in clinical practice. For example, minor disagreements about which individual pixels belong in a region of interest (ROI) wouldn't be expected to have much practical effect. Differences in overall annotations of ROI (e.g., tumor versus normal) would matter a lot. It's not clear that any choice of arbitrary "cutoffs" would capture the practical importance of the differences. The practical difference is what presumably will matter most to your audience.
\n\n\n... I calculated the Jaccard index...
\n
Think carefully about whether that's the appropriate measure for inter-rater reliability. That won't take into account the agreement that would be expected just by chance. The Wikipedia entry explains:
\n\n\nWhen the number of categories being used is small (e.g. 2 or 3), the likelihood for 2 raters to agree by pure chance increases dramatically.
\n
You only have 2 categories. The Wikipedia entry describes several measures that adjust for chance agreement. Kappa statistics would probably be better choices.
\n\n\nThe "ground truth" is the human annotations...
\n
As the 2 humans don't always agree, you don't really have a "ground truth." You might get closer to a "ground truth" if you had 3 human raters and used the majority vote for each assessment.
\n", "answer_id": 676929, "answer_text": "A few thoughts:\n\n\n\n\n\n\n\nMy coauthor ... does want a specific cutoff that we call good, excellent etc.\n\n\n\n\n\n\n\nThis probably isn't a useful goal. What presumably matters is whether the differences in annotation will matter in clinical practice. For example, minor disagreements about which individual pixels belong in a region of interest (ROI) wouldn't be expected to have much practical effect. Differences in overall annotations of ROI (e.g., tumor versus normal) would matter a lot. It's not clear that any choice of arbitrary \"cutoffs\" would capture the practical importance of the differences. The practical difference is what presumably will matter most to your audience.\n\n\n\n\n\n\n\n... I calculated the Jaccard index...\n\n\n\n\n\n\n\nThink carefully about whether that's the appropriate measure for inter-rater reliability. That won't take into account the agreement that would be expected just by chance. The Wikipedia entry (https://en.wikipedia.org/wiki/Inter-rater_reliability) explains:\n\n\n\n\n\n\n\nWhen the number of categories being used is small (e.g. 2 or 3), the likelihood for 2 raters to agree by pure chance increases dramatically.\n\n\n\n\n\n\n\nYou only have 2 categories. The Wikipedia entry describes several measures that adjust for chance agreement. Kappa statistics (https://en.wikipedia.org/wiki/Inter-rater_reliability#Kappa_statistics) would probably be better choices.\n\n\n\n\n\n\n\nThe \"ground truth\" is the human annotations...\n\n\n\n\n\n\n\nAs the 2 humans don't always agree, you don't really have a \"ground truth.\" You might get closer to a \"ground truth\" if you had 3 human raters and used the majority vote for each assessment.", "answer_url": "https://stats.stackexchange.com/a/676929", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-21T16:56:04+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676924, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-21T16:56:04+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "00FF675D-4690-4BD3-BC52-6349CAAC7745", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/00FF675D-4690-4BD3-BC52-6349CAAC7745/view-source"}], "score": 2, "updated_at": "2026-08-21T16:56:04+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "test", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "A few thoughts:
\n\n\nMy coauthor ... does want a specific cutoff that we call good, excellent etc.
\n
This probably isn't a useful goal. What presumably matters is whether the differences in annotation will matter in clinical practice. For example, minor disagreements about which individual pixels belong in a region of interest (ROI) wouldn't be expected to have much practical effect. Differences in overall annotations of ROI (e.g., tumor versus normal) would matter a lot. It's not clear that any choice of arbitrary "cutoffs" would capture the practical importance of the differences. The practical difference is what presumably will matter most to your audience.
\n\n\n... I calculated the Jaccard index...
\n
Think carefully about whether that's the appropriate measure for inter-rater reliability. That won't take into account the agreement that would be expected just by chance. The Wikipedia entry explains:
\n\n\nWhen the number of categories being used is small (e.g. 2 or 3), the likelihood for 2 raters to agree by pure chance increases dramatically.
\n
You only have 2 categories. The Wikipedia entry describes several measures that adjust for chance agreement. Kappa statistics would probably be better choices.
\n\n\nThe "ground truth" is the human annotations...
\n
As the 2 humans don't always agree, you don't really have a "ground truth." You might get closer to a "ground truth" if you had 3 human raters and used the majority vote for each assessment.
\n", "answer_id": 676929, "answer_text": "A few thoughts:\n\n\n\n\n\n\n\nMy coauthor ... does want a specific cutoff that we call good, excellent etc.\n\n\n\n\n\n\n\nThis probably isn't a useful goal. What presumably matters is whether the differences in annotation will matter in clinical practice. For example, minor disagreements about which individual pixels belong in a region of interest (ROI) wouldn't be expected to have much practical effect. Differences in overall annotations of ROI (e.g., tumor versus normal) would matter a lot. It's not clear that any choice of arbitrary \"cutoffs\" would capture the practical importance of the differences. The practical difference is what presumably will matter most to your audience.\n\n\n\n\n\n\n\n... I calculated the Jaccard index...\n\n\n\n\n\n\n\nThink carefully about whether that's the appropriate measure for inter-rater reliability. That won't take into account the agreement that would be expected just by chance. The Wikipedia entry (https://en.wikipedia.org/wiki/Inter-rater_reliability) explains:\n\n\n\n\n\n\n\nWhen the number of categories being used is small (e.g. 2 or 3), the likelihood for 2 raters to agree by pure chance increases dramatically.\n\n\n\n\n\n\n\nYou only have 2 categories. The Wikipedia entry describes several measures that adjust for chance agreement. Kappa statistics (https://en.wikipedia.org/wiki/Inter-rater_reliability#Kappa_statistics) would probably be better choices.\n\n\n\n\n\n\n\nThe \"ground truth\" is the human annotations...\n\n\n\n\n\n\n\nAs the 2 humans don't always agree, you don't really have a \"ground truth.\" You might get closer to a \"ground truth\" if you had 3 human raters and used the majority vote for each assessment.", "answer_url": "https://stats.stackexchange.com/a/676929", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-21T16:56:04+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676924, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-21T16:56:04+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "00FF675D-4690-4BD3-BC52-6349CAAC7745", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/00FF675D-4690-4BD3-BC52-6349CAAC7745/view-source"}], "score": 2, "updated_at": "2026-08-21T16:56:04+00:00"}], "domain": "statistics", "external_links": ["https://en.wikipedia.org/wiki/Inter-rater_reliability", "https://en.wikipedia.org/wiki/Inter-rater_reliability#Kappa_statistics", "https://pmc.ncbi.nlm.nih.gov/articles/PMC4913118/#bb0090"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "deee", "question_author_url": "https://stats.stackexchange.com/users/492702/deee", "question_author_user_type": "registered", "question_created_at": "2026-08-20T15:23:03+00:00", "question_html": "I'm working on a medical image segmentation problem. I have the source images, automated annotations, and manual annotations from two human raters. The annotations have two formats: predefined regions, and per-pixel annotation.
\nFor the predefined regions, each rater overlaid a map of 44 semantically meaningful regions onto the source image and annotated each region as True/False. For a given example, there are therefore 44 binary variables that each rater can agree or disagree on.
\nFor the per-pixel annotation, each rater created a pixel mask to identify the region of interest. For a given example, each rater could therefore agree or disagree on each individual pixel in the image.
\nThe "ground truth" is the human annotations. The humans don't perfectly agree on their annotations. The nature of the task means that for the per-pixel annotation there's a fair amount of possible disagreement without one rater being "wrong".
\nI want to assess the reliability of my automated annotations. I have calculated some metrics between each pair of raters (rater a to automated, rater b to automated, rater a to rater b). For the predefined regions I calculated the Jaccard index on a per-region basis, and for the per-pixel annotations I calculated the Jaccard index on a per-pixel basis, plus the Normalised Surface Distance.
\nAs far as I know, there aren't established conventions on what is "good" for these metrics on this task. One of my coauthors is strongly advocating to use ICC thresholds from this paper to interpret those metrics (<0.5 is poor, 0.5 to 0.75 is moderate, 0.75 to 0.9 is good, >0.9 is excellent). I'm unhappy about this because I think ICC is fundamentally different from the metrics we've used.
\nMy coauthor is happy to use different thresholds if I can find more relevant ones, but does want a specific cutoff that we call good, excellent etc. I can't find any resources for more relevant thresholds.
\nIs it reasonable to use these thresholds to interpret Jaccard index and Normalised Surface Distance on an image segmentation task? Is there an established way to decide what "good" agreement is for these metrics?
\n", "question_id": 676924, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I'm working on a medical image segmentation problem. I have the source images, automated annotations, and manual annotations from two human raters. The annotations have two formats: predefined regions, and per-pixel annotation.\n\n\n\n\nFor the predefined regions, each rater overlaid a map of 44 semantically meaningful regions onto the source image and annotated each region as True/False. For a given example, there are therefore 44 binary variables that each rater can agree or disagree on.\n\n\n\n\nFor the per-pixel annotation, each rater created a pixel mask to identify the region of interest. For a given example, each rater could therefore agree or disagree on each individual pixel in the image.\n\n\n\n\nThe \"ground truth\" is the human annotations. The humans don't perfectly agree on their annotations. The nature of the task means that for the per-pixel annotation there's a fair amount of possible disagreement without one rater being \"wrong\".\n\n\n\n\nI want to assess the reliability of my automated annotations. I have calculated some metrics between each pair of raters (rater a to automated, rater b to automated, rater a to rater b). For the predefined regions I calculated the Jaccard index on a per-region basis, and for the per-pixel annotations I calculated the Jaccard index on a per-pixel basis, plus the Normalised Surface Distance.\n\n\n\n\nAs far as I know, there aren't established conventions on what is \"good\" for these metrics on this task. One of my coauthors is strongly advocating to use ICC thresholds from this paper (https://pmc.ncbi.nlm.nih.gov/articles/PMC4913118/#bb0090) to interpret those metrics (<0.5 is poor, 0.5 to 0.75 is moderate, 0.75 to 0.9 is good, >0.9 is excellent). I'm unhappy about this because I think ICC is fundamentally different from the metrics we've used.\n\n\n\n\nMy coauthor is happy to use different thresholds if I can find more relevant ones, but does want a specific cutoff that we call good, excellent etc. I can't find any resources for more relevant thresholds.\n\n\n\n\nIs it reasonable to use these thresholds to interpret Jaccard index and Normalised Surface Distance on an image segmentation task? Is there an established way to decide what \"good\" agreement is for these metrics?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "deee", "profile_url": "https://stats.stackexchange.com/users/492702/deee", "user_type": "registered"}, "created_at": "2026-08-20T15:23:03+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "F3431DE0-82AE-4630-A45E-E672DDBF5F5A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F3431DE0-82AE-4630-A45E-E672DDBF5F5A/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-21T22:30:56+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "62C64EA4-AD43-4820-A545-BC23853CCAD6", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/62C64EA4-AD43-4820-A545-BC23853CCAD6/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676924/interpretation-of-interrater-reliability-metrics", "split": "test", "split_group": "3a527218b1c4490fdc463d61353fb9bbbeaa42d0e07302db9e210419fe3df06d", "tags": ["interpretation", "intraclass-correlation", "jaccard-similarity"], "thread_id": "stats:676924", "title": "Interpretation of interrater reliability metrics"}} +{"accepted_answer": {"answer_html": "As it turns out there is a mistake in Grogger and Carson's second derivatives of the zero-truncated negative binomial loglikelihood function wrt the regression parameters: blink and you'll miss it (the sign in one of the exponents should have been outside the parenthesis, probably a typo in the original)
\n\\begin{align}\n\t\\frac{\\partial^2}{\\partial \\boldsymbol{\\beta}\\partial \\boldsymbol{\\beta}^T}\\ell_\\mathrm{ZTNB}{\\left(\\boldsymbol{\\beta},\\alpha\\right)} &= -\\sum_{i=1}^n{\\frac{1+\\alpha^{-1} y_i}{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^2}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T} - \\sum_{i=1}^n\\left\\{\\frac{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\left(1+\\alpha\\right)}-e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(\\alpha^{-1}+1\\right)\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^\\color{blue}{-\\left(2+\\alpha\\right)}}{1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}} +\\right. \\nonumber \\\\ \n\t& \\quad \\left. -\\frac{e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-2(1+\\alpha)}}{\\left[1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}\\right]^2}\\right\\}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T \n\\end{align}
\nI guess I must have been so eager to verify the original results that I conditioned myself to "see" the original notation as correct - even when going through my own derivations over and over again. Few days away from this problem must have broken this perverse loop.
\n", "answer_id": 676993, "answer_text": "As it turns out there is a mistake in Grogger and Carson's second derivatives of the zero-truncated negative binomial loglikelihood function wrt the regression parameters: blink and you'll miss it (the sign in one of the exponents should have been outside the parenthesis, probably a typo in the original)\n\n\n\n\n\\begin{align}\n\t\\frac{\\partial^2}{\\partial \\boldsymbol{\\beta}\\partial \\boldsymbol{\\beta}^T}\\ell_\\mathrm{ZTNB}{\\left(\\boldsymbol{\\beta},\\alpha\\right)} &= -\\sum_{i=1}^n{\\frac{1+\\alpha^{-1} y_i}{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^2}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T} - \\sum_{i=1}^n\\left\\{\\frac{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\left(1+\\alpha\\right)}-e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(\\alpha^{-1}+1\\right)\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^\\color{blue}{-\\left(2+\\alpha\\right)}}{1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}} +\\right. \\nonumber \\\\ \n\t& \\quad \\left. -\\frac{e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-2(1+\\alpha)}}{\\left[1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}\\right]^2}\\right\\}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T \n\\end{align}\n\n\n\n\nI guess I must have been so eager to verify the original results that I conditioned myself to \"see\" the original notation as correct - even when going through my own derivations over and over again. Few days away from this problem must have broken this perverse loop.", "answer_url": "https://stats.stackexchange.com/a/676993", "author": "Ettore S", "author_url": "https://stats.stackexchange.com/users/513606/ettore-s", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:08:55+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676952, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ettore S", "profile_url": "https://stats.stackexchange.com/users/513606/ettore-s", "user_type": "registered"}, "created_at": "2026-08-28T23:08:55+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E33B0B4F-D54D-46E9-8E25-81C77E90B942", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E33B0B4F-D54D-46E9-8E25-81C77E90B942/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ettore S", "profile_url": "https://stats.stackexchange.com/users/513606/ettore-s", "user_type": "registered"}, "created_at": "2026-08-28T23:15:33+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "71D393BD-A8FB-4799-92AF-8FD04BFA27AE", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/71D393BD-A8FB-4799-92AF-8FD04BFA27AE/view-source"}], "score": 0, "updated_at": "2026-08-28T23:15:33+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "In the context of zero-truncated negative binomial regression (see this other post (https://stats.stackexchange.com/q/676385/513606)) , twice-differentiating the loglikelihood yields a well-known result (see e.g., footnote 5 in this paper (https://www.jstor.org/stable/2096628)):\n\n\n\n\n$$\n\\begin{aligned}\n\t\\frac{\\partial^2}{\\partial \\boldsymbol{\\beta}\\partial \\boldsymbol{\\beta}^T}\\ell_\\mathrm{ZTNB}{\\left(\\boldsymbol{\\beta},\\alpha\\right)} &= -\\sum_{i=1}^n{\\frac{1+\\alpha^{-1} y_i}{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^2}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T} -\\sum_{i=1}^n\\left\\{\\frac{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\left(1+\\alpha\\right)}-e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(\\alpha^{-1}+1\\right)\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{\\left(-2+\\alpha\\right)}}{1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}} +\\right. \\nonumber \\\\ \n\t& \\quad \\left. -\\frac{e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-2(1+\\alpha)}}{\\left[1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}\\right]^2}\\right\\}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T\n\\end{aligned}\n$$\n\n\n\n\nwhere:\n\n\n\n\n\n$y_i > 0 \\quad (i=1,2,\\dots,n)$ denotes the observed realisations (observations enter a zero-truncated sample only after the first count occurs);\n\n\n\n\n$\\mathbf{x}^T_i$ is the $i$-th row of the regression data matrix;\n\n\n\n\n$\\boldsymbol{\\beta}$ is the unknown vector of regression coefficients (to be estimated);\n\n\n\n\n$\\alpha$ is another unknown parameter to be estimated, namely the reciprocal of the so-called dispersion parameter ($\\alpha$ is inherited from the Poisson-Gamma mixture that brings about the unconstrained Negative Binomial see e.g., p.745, in this book (https://archive.org/details/econometricanaly0000gree_f4x3/econometricanaly0000gree_f4x3)).\n\n\n\n\nAlso notice that the first summation is just the Hessian of the \"parent\" specification: that one works fine i.e., its elements are negative as expected.\n\n\n\n\n\nThe above equation is correct as far as I can tell. Yet when I implement it in practice, it seems to invariably yield an Hessian with positive elements.\n\n\n\n\nMaybe this is a silly question, and it all depends on initialisation strategies etc.: but is it possible to ascertain whether the above-mentioned Hessian is, somehow, \"bound to\" have positive elements?\n\n\n\n\nI thought this should be a no brainer and I confess I didn't expect struggling on its implementation. Having re-checked the equations and code multiple times now, and tried different numerical examples, I begin to worry about being unable to get an Hessian with negative elements - which is what I need to implement the method of maximum likelihood using, say, textbook Newton-Raphson iterations.\n\n\n\n\nI appreciate any pointer to help me understand what I might be getting wrong - a simple illustrative example below.\n\n\n\n\nExample\n\n\n\n\nFor the sake of illustration, consider data(medpar) available from the R package COUNT. The data subset data_medpar <- medpar[,c(\"los\", \"died\", \"hmo\", \"type2\", \"type3\")] corresponds to the example reported in this STATA documentation for tnbreg (https://www.stata.com/manuals13/rtnbreg.pdf).\n\n\n\n\n\n\n\nInitialising the regression coefficients with a zero-truncated Poisson model gives me (intercept: 2.265; died: -0.248; hmo: -0.075; type2: 0.250; type3: 0.750) -- call this vector beta_iter;\n\n\n\n\n\n\n\n\n\nFollowing the alternating method of glm.nb from package MASS I also obtain an initial guess for $\\alpha$, call this scalar p_alpha <- 1.903 (what STATA calls alpha in the document is the recirpocal $\\theta=\\alpha^{-1}=0.525$ i.e. the so-called dispersion parameter).\n\n\n\n\n\n\n\n\n\nWith X the data matrix (including the intercept) and y the response variable vector corresponding to los I plug p_lambda = exp(X %*% beta_iter) and p_alpha in my R implementation below - which I believe should correspond to the second derivatives in question:\n\n\n\n\n n_regressors <- ncol(X)\n n_observ <- nrow(X)\n phi_sub <- (1 + p_theta*p_lambda)\n H_parent <- ((1 + p_theta*y) / phi_sub^2)*p_lambda\n if(zerotrunc){\n phi_sub_1a <- (1 / (phi_sub)^(1+p_alpha))\n phi <- (1/(1 + p_theta*p_lambda)^p_alpha) \n H_zt_A <- ( p_lambda*phi_sub_1a / (1 - phi) )^2\n H_zt_B <- ( p_lambda*phi_sub_1a - (p_lambda^2 * (p_theta + 1) * phi_sub^(-2+p_alpha)) ) / (1 - phi)\n }\n\n Hessian_iter <- matrix(0L,nrow = n_regressors, ncol = n_regressors)\n for(i in 1:n_observ){\n x <- X[i,]\n x <- as.numeric(x)\n outprod_X <- (x %o% x) \n A <- H_parent[i]\n if(zerotrunc){\n B <- H_zt_A[i]\n C <- H_zt_B[i]\n } else {\n B <- C <- 0\n }\n Hessian_iter <- Hessian_iter - ( A - B + C )*outprod_X \n }\n\n\n\n\n\n\n\n\n\nAnd I get a positive Hessian - as I always do\n\n\n\n\n> Hessian_iter\n [,1] [,2] [,3] [,4] [,5]\n[1,] 200849.45 53431.282 24465.222 43243.069 39578.773\n[2,] 53431.28 53431.282 6036.786 12451.468 14079.196\n[3,] 24465.22 6036.786 24465.222 4528.242 1145.349\n[4,] 43243.07 12451.468 4528.242 43243.069 0.000\n[5,] 39578.77 14079.196 1145.349 0.000 39578.773\n\n\n\n\n\nAny thoughts? Am I missing anything trivial here? Thanks in advance.", "record_id": "Scientific-Statistics-QA:stats:676952", "selected_answer": {"answer_html": "As it turns out there is a mistake in Grogger and Carson's second derivatives of the zero-truncated negative binomial loglikelihood function wrt the regression parameters: blink and you'll miss it (the sign in one of the exponents should have been outside the parenthesis, probably a typo in the original)
\n\\begin{align}\n\t\\frac{\\partial^2}{\\partial \\boldsymbol{\\beta}\\partial \\boldsymbol{\\beta}^T}\\ell_\\mathrm{ZTNB}{\\left(\\boldsymbol{\\beta},\\alpha\\right)} &= -\\sum_{i=1}^n{\\frac{1+\\alpha^{-1} y_i}{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^2}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T} - \\sum_{i=1}^n\\left\\{\\frac{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\left(1+\\alpha\\right)}-e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(\\alpha^{-1}+1\\right)\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^\\color{blue}{-\\left(2+\\alpha\\right)}}{1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}} +\\right. \\nonumber \\\\ \n\t& \\quad \\left. -\\frac{e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-2(1+\\alpha)}}{\\left[1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}\\right]^2}\\right\\}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T \n\\end{align}
\nI guess I must have been so eager to verify the original results that I conditioned myself to "see" the original notation as correct - even when going through my own derivations over and over again. Few days away from this problem must have broken this perverse loop.
\n", "answer_id": 676993, "answer_text": "As it turns out there is a mistake in Grogger and Carson's second derivatives of the zero-truncated negative binomial loglikelihood function wrt the regression parameters: blink and you'll miss it (the sign in one of the exponents should have been outside the parenthesis, probably a typo in the original)\n\n\n\n\n\\begin{align}\n\t\\frac{\\partial^2}{\\partial \\boldsymbol{\\beta}\\partial \\boldsymbol{\\beta}^T}\\ell_\\mathrm{ZTNB}{\\left(\\boldsymbol{\\beta},\\alpha\\right)} &= -\\sum_{i=1}^n{\\frac{1+\\alpha^{-1} y_i}{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^2}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T} - \\sum_{i=1}^n\\left\\{\\frac{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\left(1+\\alpha\\right)}-e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(\\alpha^{-1}+1\\right)\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^\\color{blue}{-\\left(2+\\alpha\\right)}}{1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}} +\\right. \\nonumber \\\\ \n\t& \\quad \\left. -\\frac{e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-2(1+\\alpha)}}{\\left[1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}\\right]^2}\\right\\}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T \n\\end{align}\n\n\n\n\nI guess I must have been so eager to verify the original results that I conditioned myself to \"see\" the original notation as correct - even when going through my own derivations over and over again. Few days away from this problem must have broken this perverse loop.", "answer_url": "https://stats.stackexchange.com/a/676993", "author": "Ettore S", "author_url": "https://stats.stackexchange.com/users/513606/ettore-s", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:08:55+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676952, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ettore S", "profile_url": "https://stats.stackexchange.com/users/513606/ettore-s", "user_type": "registered"}, "created_at": "2026-08-28T23:08:55+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E33B0B4F-D54D-46E9-8E25-81C77E90B942", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E33B0B4F-D54D-46E9-8E25-81C77E90B942/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ettore S", "profile_url": "https://stats.stackexchange.com/users/513606/ettore-s", "user_type": "registered"}, "created_at": "2026-08-28T23:15:33+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "71D393BD-A8FB-4799-92AF-8FD04BFA27AE", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/71D393BD-A8FB-4799-92AF-8FD04BFA27AE/view-source"}], "score": 0, "updated_at": "2026-08-28T23:15:33+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "test", "thread": {"accepted_answer_id": 676993, "answers": [{"answer_html": "As it turns out there is a mistake in Grogger and Carson's second derivatives of the zero-truncated negative binomial loglikelihood function wrt the regression parameters: blink and you'll miss it (the sign in one of the exponents should have been outside the parenthesis, probably a typo in the original)
\n\\begin{align}\n\t\\frac{\\partial^2}{\\partial \\boldsymbol{\\beta}\\partial \\boldsymbol{\\beta}^T}\\ell_\\mathrm{ZTNB}{\\left(\\boldsymbol{\\beta},\\alpha\\right)} &= -\\sum_{i=1}^n{\\frac{1+\\alpha^{-1} y_i}{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^2}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T} - \\sum_{i=1}^n\\left\\{\\frac{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\left(1+\\alpha\\right)}-e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(\\alpha^{-1}+1\\right)\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^\\color{blue}{-\\left(2+\\alpha\\right)}}{1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}} +\\right. \\nonumber \\\\ \n\t& \\quad \\left. -\\frac{e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-2(1+\\alpha)}}{\\left[1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}\\right]^2}\\right\\}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T \n\\end{align}
\nI guess I must have been so eager to verify the original results that I conditioned myself to "see" the original notation as correct - even when going through my own derivations over and over again. Few days away from this problem must have broken this perverse loop.
\n", "answer_id": 676993, "answer_text": "As it turns out there is a mistake in Grogger and Carson's second derivatives of the zero-truncated negative binomial loglikelihood function wrt the regression parameters: blink and you'll miss it (the sign in one of the exponents should have been outside the parenthesis, probably a typo in the original)\n\n\n\n\n\\begin{align}\n\t\\frac{\\partial^2}{\\partial \\boldsymbol{\\beta}\\partial \\boldsymbol{\\beta}^T}\\ell_\\mathrm{ZTNB}{\\left(\\boldsymbol{\\beta},\\alpha\\right)} &= -\\sum_{i=1}^n{\\frac{1+\\alpha^{-1} y_i}{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^2}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T} - \\sum_{i=1}^n\\left\\{\\frac{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\left(1+\\alpha\\right)}-e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(\\alpha^{-1}+1\\right)\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^\\color{blue}{-\\left(2+\\alpha\\right)}}{1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}} +\\right. \\nonumber \\\\ \n\t& \\quad \\left. -\\frac{e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-2(1+\\alpha)}}{\\left[1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}\\right]^2}\\right\\}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T \n\\end{align}\n\n\n\n\nI guess I must have been so eager to verify the original results that I conditioned myself to \"see\" the original notation as correct - even when going through my own derivations over and over again. Few days away from this problem must have broken this perverse loop.", "answer_url": "https://stats.stackexchange.com/a/676993", "author": "Ettore S", "author_url": "https://stats.stackexchange.com/users/513606/ettore-s", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:08:55+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676952, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ettore S", "profile_url": "https://stats.stackexchange.com/users/513606/ettore-s", "user_type": "registered"}, "created_at": "2026-08-28T23:08:55+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E33B0B4F-D54D-46E9-8E25-81C77E90B942", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E33B0B4F-D54D-46E9-8E25-81C77E90B942/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ettore S", "profile_url": "https://stats.stackexchange.com/users/513606/ettore-s", "user_type": "registered"}, "created_at": "2026-08-28T23:15:33+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "71D393BD-A8FB-4799-92AF-8FD04BFA27AE", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/71D393BD-A8FB-4799-92AF-8FD04BFA27AE/view-source"}], "score": 0, "updated_at": "2026-08-28T23:15:33+00:00"}], "domain": "statistics", "external_links": ["https://archive.org/details/econometricanaly0000gree_f4x3/econometricanaly0000gree_f4x3", "https://www.jstor.org/stable/2096628", "https://www.stata.com/manuals13/rtnbreg.pdf"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Ettore S", "question_author_url": "https://stats.stackexchange.com/users/513606/ettore-s", "question_author_user_type": "registered", "question_created_at": "2026-08-24T16:36:39+00:00", "question_html": "In the context of zero-truncated negative binomial regression (see this other post) , twice-differentiating the loglikelihood yields a well-known result (see e.g., footnote 5 in this paper):
\n$$\n\\begin{aligned}\n\t\\frac{\\partial^2}{\\partial \\boldsymbol{\\beta}\\partial \\boldsymbol{\\beta}^T}\\ell_\\mathrm{ZTNB}{\\left(\\boldsymbol{\\beta},\\alpha\\right)} &= -\\sum_{i=1}^n{\\frac{1+\\alpha^{-1} y_i}{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^2}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T} -\\sum_{i=1}^n\\left\\{\\frac{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\left(1+\\alpha\\right)}-e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(\\alpha^{-1}+1\\right)\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{\\left(-2+\\alpha\\right)}}{1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}} +\\right. \\nonumber \\\\ \n\t& \\quad \\left. -\\frac{e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-2(1+\\alpha)}}{\\left[1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}\\right]^2}\\right\\}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T\n\\end{aligned}\n$$
\nwhere:
\nThe above equation is correct as far as I can tell. Yet when I implement it in practice, it seems to invariably yield an Hessian with positive elements.
\nMaybe this is a silly question, and it all depends on initialisation strategies etc.: but is it possible to ascertain whether the above-mentioned Hessian is, somehow, "bound to" have positive elements?
\nI thought this should be a no brainer and I confess I didn't expect struggling on its implementation. Having re-checked the equations and code multiple times now, and tried different numerical examples, I begin to worry about being unable to get an Hessian with negative elements - which is what I need to implement the method of maximum likelihood using, say, textbook Newton-Raphson iterations.
\nI appreciate any pointer to help me understand what I might be getting wrong - a simple illustrative example below.
\nFor the sake of illustration, consider data(medpar) available from the R package COUNT. The data subset data_medpar <- medpar[,c("los", "died", "hmo", "type2", "type3")] corresponds to the example reported in this STATA documentation for tnbreg.
Initialising the regression coefficients with a zero-truncated Poisson model gives me (intercept: 2.265; died: -0.248; hmo: -0.075; type2: 0.250; type3: 0.750) -- call this vector beta_iter;
Following the alternating method of glm.nb from package MASS I also obtain an initial guess for $\\alpha$, call this scalar p_alpha <- 1.903 (what STATA calls alpha in the document is the recirpocal $\\theta=\\alpha^{-1}=0.525$ i.e. the so-called dispersion parameter).
With X the data matrix (including the intercept) and y the response variable vector corresponding to los I plug p_lambda = exp(X %*% beta_iter) and p_alpha in my R implementation below - which I believe should correspond to the second derivatives in question:
n_regressors <- ncol(X)\n n_observ <- nrow(X)\n phi_sub <- (1 + p_theta*p_lambda)\n H_parent <- ((1 + p_theta*y) / phi_sub^2)*p_lambda\n if(zerotrunc){\n phi_sub_1a <- (1 / (phi_sub)^(1+p_alpha))\n phi <- (1/(1 + p_theta*p_lambda)^p_alpha) \n H_zt_A <- ( p_lambda*phi_sub_1a / (1 - phi) )^2\n H_zt_B <- ( p_lambda*phi_sub_1a - (p_lambda^2 * (p_theta + 1) * phi_sub^(-2+p_alpha)) ) / (1 - phi)\n }\n\n Hessian_iter <- matrix(0L,nrow = n_regressors, ncol = n_regressors)\n for(i in 1:n_observ){\n x <- X[i,]\n x <- as.numeric(x)\n outprod_X <- (x %o% x) \n A <- H_parent[i]\n if(zerotrunc){\n B <- H_zt_A[i]\n C <- H_zt_B[i]\n } else {\n B <- C <- 0\n }\n Hessian_iter <- Hessian_iter - ( A - B + C )*outprod_X \n }\n\nAnd I get a positive Hessian - as I always do
\n> Hessian_iter\n [,1] [,2] [,3] [,4] [,5]\n[1,] 200849.45 53431.282 24465.222 43243.069 39578.773\n[2,] 53431.28 53431.282 6036.786 12451.468 14079.196\n[3,] 24465.22 6036.786 24465.222 4528.242 1145.349\n[4,] 43243.07 12451.468 4528.242 43243.069 0.000\n[5,] 39578.77 14079.196 1145.349 0.000 39578.773\n\nAny thoughts? Am I missing anything trivial here? Thanks in advance.
\n", "question_id": 676952, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "In the context of zero-truncated negative binomial regression (see this other post (https://stats.stackexchange.com/q/676385/513606)) , twice-differentiating the loglikelihood yields a well-known result (see e.g., footnote 5 in this paper (https://www.jstor.org/stable/2096628)):\n\n\n\n\n$$\n\\begin{aligned}\n\t\\frac{\\partial^2}{\\partial \\boldsymbol{\\beta}\\partial \\boldsymbol{\\beta}^T}\\ell_\\mathrm{ZTNB}{\\left(\\boldsymbol{\\beta},\\alpha\\right)} &= -\\sum_{i=1}^n{\\frac{1+\\alpha^{-1} y_i}{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^2}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T} -\\sum_{i=1}^n\\left\\{\\frac{\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\left(1+\\alpha\\right)}-e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(\\alpha^{-1}+1\\right)\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{\\left(-2+\\alpha\\right)}}{1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}} +\\right. \\nonumber \\\\ \n\t& \\quad \\left. -\\frac{e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-2(1+\\alpha)}}{\\left[1-\\left(1+\\alpha^{-1} e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\right)^{-\\alpha}\\right]^2}\\right\\}e^{\\mathbf{x}_i^T\\boldsymbol{\\beta}}\\mathbf{x}_i\\mathbf{x}_i^T\n\\end{aligned}\n$$\n\n\n\n\nwhere:\n\n\n\n\n\n$y_i > 0 \\quad (i=1,2,\\dots,n)$ denotes the observed realisations (observations enter a zero-truncated sample only after the first count occurs);\n\n\n\n\n$\\mathbf{x}^T_i$ is the $i$-th row of the regression data matrix;\n\n\n\n\n$\\boldsymbol{\\beta}$ is the unknown vector of regression coefficients (to be estimated);\n\n\n\n\n$\\alpha$ is another unknown parameter to be estimated, namely the reciprocal of the so-called dispersion parameter ($\\alpha$ is inherited from the Poisson-Gamma mixture that brings about the unconstrained Negative Binomial see e.g., p.745, in this book (https://archive.org/details/econometricanaly0000gree_f4x3/econometricanaly0000gree_f4x3)).\n\n\n\n\nAlso notice that the first summation is just the Hessian of the \"parent\" specification: that one works fine i.e., its elements are negative as expected.\n\n\n\n\n\nThe above equation is correct as far as I can tell. Yet when I implement it in practice, it seems to invariably yield an Hessian with positive elements.\n\n\n\n\nMaybe this is a silly question, and it all depends on initialisation strategies etc.: but is it possible to ascertain whether the above-mentioned Hessian is, somehow, \"bound to\" have positive elements?\n\n\n\n\nI thought this should be a no brainer and I confess I didn't expect struggling on its implementation. Having re-checked the equations and code multiple times now, and tried different numerical examples, I begin to worry about being unable to get an Hessian with negative elements - which is what I need to implement the method of maximum likelihood using, say, textbook Newton-Raphson iterations.\n\n\n\n\nI appreciate any pointer to help me understand what I might be getting wrong - a simple illustrative example below.\n\n\n\n\nExample\n\n\n\n\nFor the sake of illustration, consider data(medpar) available from the R package COUNT. The data subset data_medpar <- medpar[,c(\"los\", \"died\", \"hmo\", \"type2\", \"type3\")] corresponds to the example reported in this STATA documentation for tnbreg (https://www.stata.com/manuals13/rtnbreg.pdf).\n\n\n\n\n\n\n\nInitialising the regression coefficients with a zero-truncated Poisson model gives me (intercept: 2.265; died: -0.248; hmo: -0.075; type2: 0.250; type3: 0.750) -- call this vector beta_iter;\n\n\n\n\n\n\n\n\n\nFollowing the alternating method of glm.nb from package MASS I also obtain an initial guess for $\\alpha$, call this scalar p_alpha <- 1.903 (what STATA calls alpha in the document is the recirpocal $\\theta=\\alpha^{-1}=0.525$ i.e. the so-called dispersion parameter).\n\n\n\n\n\n\n\n\n\nWith X the data matrix (including the intercept) and y the response variable vector corresponding to los I plug p_lambda = exp(X %*% beta_iter) and p_alpha in my R implementation below - which I believe should correspond to the second derivatives in question:\n\n\n\n\n n_regressors <- ncol(X)\n n_observ <- nrow(X)\n phi_sub <- (1 + p_theta*p_lambda)\n H_parent <- ((1 + p_theta*y) / phi_sub^2)*p_lambda\n if(zerotrunc){\n phi_sub_1a <- (1 / (phi_sub)^(1+p_alpha))\n phi <- (1/(1 + p_theta*p_lambda)^p_alpha) \n H_zt_A <- ( p_lambda*phi_sub_1a / (1 - phi) )^2\n H_zt_B <- ( p_lambda*phi_sub_1a - (p_lambda^2 * (p_theta + 1) * phi_sub^(-2+p_alpha)) ) / (1 - phi)\n }\n\n Hessian_iter <- matrix(0L,nrow = n_regressors, ncol = n_regressors)\n for(i in 1:n_observ){\n x <- X[i,]\n x <- as.numeric(x)\n outprod_X <- (x %o% x) \n A <- H_parent[i]\n if(zerotrunc){\n B <- H_zt_A[i]\n C <- H_zt_B[i]\n } else {\n B <- C <- 0\n }\n Hessian_iter <- Hessian_iter - ( A - B + C )*outprod_X \n }\n\n\n\n\n\n\n\n\n\nAnd I get a positive Hessian - as I always do\n\n\n\n\n> Hessian_iter\n [,1] [,2] [,3] [,4] [,5]\n[1,] 200849.45 53431.282 24465.222 43243.069 39578.773\n[2,] 53431.28 53431.282 6036.786 12451.468 14079.196\n[3,] 24465.22 6036.786 24465.222 4528.242 1145.349\n[4,] 43243.07 12451.468 4528.242 43243.069 0.000\n[5,] 39578.77 14079.196 1145.349 0.000 39578.773\n\n\n\n\n\nAny thoughts? Am I missing anything trivial here? Thanks in advance.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ettore S", "profile_url": "https://stats.stackexchange.com/users/513606/ettore-s", "user_type": "registered"}, "created_at": "2026-08-24T16:36:39+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "07E45709-2DC4-449E-9EF1-F194BCC37017", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/07E45709-2DC4-449E-9EF1-F194BCC37017/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ettore S", "profile_url": "https://stats.stackexchange.com/users/513606/ettore-s", "user_type": "registered"}, "created_at": "2026-08-24T16:44:54+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "62966E35-E17B-49AB-8C07-589F8E1C8272", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/62966E35-E17B-49AB-8C07-589F8E1C8272/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676952/hessian-with-invariably-positive-elements-for-zero-truncated-negative-binomial-r", "split": "test", "split_group": "7b59a2f46aa3d8cb6ef7b86f03502a2ea8a90a231427a0a51d2360f8ed2dd472", "tags": ["nonlinear-regression", "count-data", "negative-binomial-distribution", "hessian", "truncated-distributions"], "thread_id": "stats:676952", "title": "Hessian with invariably positive elements for zero-truncated negative binomial regression"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I've worked with tree-based models before, but I'm new to survival analysis. I have a very large dataset of highly censored data, and multiple imputations (let's say 5). I wish to train a survival forest on this data and evaluate it. More than this, I also wish to evaluate a survival forest using all but one special variable on this same data, and compare the results with those of the model using all variables.\n\n\n\n\nWhat I am confused about is the evaluation. The way I was planning to do it is the following:\n\n\n\n\n\nFirst, I split the samples into training/testing (stratified by events, 80-20 split).\n\n\n\n\nThen for every imputation, I train a survival forest using all variables on the imputed training samples.\n\n\n\n\nAfter training, I get the out of bag concordance index calculated on the training data and I can compute the concordance index on the using test samples also.\n\n\n\n\n\nAt this point I'm wondering, is the training OOB concordance index a better evaluation metrics of a model than the concordance index on the unseen portion of the data?\nAnd, assuming I have the concordance index on the unseen data for all imputations computed, what is a reasonable way to join and report them - should I just average the scores?\n\n\n\n\n\nNext I do the same (training a model for every imputation on the training samples) using all but one variable of interest. I get OOB c-index and the c-index on the unseen data for each model/imputation.\n\n\n\n\n\nAnd here I wonder, how to compare the two? Do I just test the average concordance indexes of the models being significantly different? Or is there a better way of comparison?\n\n\n\n\nAnd as a last, more general question - at what point (in terms of size of data and censoring/nr of events) would you consider that evaluating through cross-validation is preferable over a simple training/test split?", "record_id": "Scientific-Statistics-QA:stats:676956", "selected_answer": {"answer_html": "\n\nI .. wish to evaluate a survival forest using all but one special variable on this same data, and compare the results with those of the model using all variables.
\n
Frank Harrell has a superb summary of how to evaluate the value of additional predictors in modeling. That's straightforward with nested regression models, which can be compared in a likelihood-ratio test. If you need to use random survival forests, some measure of explained variation in outcomes would be appropriate.
\n\n\nI can compute the concordance index...
\n
Frank Harrell introduced the concordance/c-index to survival analysis. Although it is a useful measure of a single model's discriminative ability, he doesn't think that it's a good way to compare models; see the link above. It only evaluates how well the model gets the order of events correct, not how well the model matches the event probability over time as a function of covariates. Furthermore, the usual c-index can have bias depending on censoring patterns. There are ways to deal with that, but you are still left with a measure of discrimination only.
\nA recent arXiv paper by Lillelund et al., "Stop Chasing the C-index: This Is How We Should Evaluate Our Survival Models," goes into more detail and explains better evaluation methods. The "Review of Statistical Methods for Evaluating the Performance of Survival or Other Time-to-Event Prediction Models (from Conventional to Deep Learning Approaches)" by Park et al., Korean J Radiol. 22:1697-1707 (2021) is also on-topic.
\nYour choice of evaluation method might best depend on your intended use of model, which isn't clear from this question.
\n\n\n... at what point (in terms of size of data and censoring/nr of events) would you consider that evaluating through cross-validation is preferable over a simple training/test split?
\n
A problem with a training/test split is that you limit both the amount of information used to train the model and the power to test the model reliably. Frank Harrell estimates that you need on the order of 20,000 subjects before a train/test split is as stable as resampling from the data with cross-validation or bootstrapping. With the power of survival models essentially determined by the number of subjects with events, you are thus unlikely to have clinical survival data with the necessary tens of thousands of events.
\nAs cross-validation involves train/test splits, it also has the problem of a small test sample in each fold. Combining all 10 test sets in 10-fold cross-validation only uses the number of cases in the original data set for testing. Repeated cross-validation helps, both in reducing reliance on a single set of splits and in increasing the effective number of test cases. Bootstrapping uses the number of cases in the original data set in each bootstrap sample, and one might use 50-100 bootstrap samples. Frank Harrell thus estimates that "To be as good as the bootstrap, about 100 repeats of 10-fold cross-validation are required."
\nWith resampling you are validating the modeling process rather than the model itself. Under the bootstrap principle, drawing samples with replacement from the available data represents the process of drawing the available data from the underlying population. Modeling each of repeated bootstrap samples and evaluating performance of each model on the full data set thus represents how well your modeling process captures the properties of the population. Comparing performance of each (possibly overfit) bootstrap-sample model on its own sample against its performance on the entire data set is the "optimism bootstrap" that evaluates overfitting. Once you accept that you are validating the process, objections to including training data in testing become much less compelling.
\n\n\nI get the out of bag [OOB] concordance index calculated on the training data...
\n
This raises an issue for whatever measure of model performance you choose. Using OOB data for testing does mean that, within each tree, the test data don't overlap with the training data. As noted above, however, that isn't necessarily required and it limits you to about 1/3 of the data in each test set. Alternatively, you could use performance within each tree's model on the entire data set as an optimism bootstrap to validate the modeling process. Frank Harrell notes that distinction in this answer.
\n\n\n... assuming I have the concordance index on the unseen data for all imputations computed, what is a reasonable way to join and report them - should I just average the scores?
\n
See this question and its answer on how to use Rubin's rules to combine random forest models on multiply imputed data sets. If your score of model performance is close enough to normally distributed, then you do average scores for the point estimate. Comparisons between models require estimating the variances of the point estimates, again following Rubin's rules that combine within-imputation and between-imputation variances.
\nA few suggestions
\nSurvival analysis, similarly to binomial regression, can suffer from omitted-variable bias if any outcome-associated variable is omitted from the model. If you are studying clinical survival data, don't fall into the trap of omitting standard clinical outcome-related variables from the model. Models of outcome with predictors like gene-expression levels that don't include standard clinical variables run a serious risk of that bias and might just find proxies for clinical variables in a way that makes clinical application of the models pretty useless.
\nConsider whether your goals might better be met with standard regression models. Their results are typically much easier to interpret heuristically than those of a random forest. Evaluating the added value of a single predictor is simple with regression models.
\nYes, random forests can incorporate unexpected interactions among predictors in ways that regression model's can't, at least with large numbers of predictors. Identifying what those interactions involve isn't so straightforward.
\n", "answer_id": 677008, "answer_text": "I .. wish to evaluate a survival forest using all but one special variable on this same data, and compare the results with those of the model using all variables.\n\n\n\n\n\n\n\nFrank Harrell has a superb summary of how to evaluate the value of additional predictors (https://www.fharrell.com/post/addvalue/) in modeling. That's straightforward with nested regression models, which can be compared in a likelihood-ratio test. If you need to use random survival forests, some measure of explained variation in outcomes would be appropriate.\n\n\n\n\n\n\n\nI can compute the concordance index...\n\n\n\n\n\n\n\nFrank Harrell introduced the concordance/c-index to survival analysis. Although it is a useful measure of a single model's discriminative ability, he doesn't think that it's a good way to compare models; see the link (https://www.fharrell.com/post/addvalue/) above. It only evaluates how well the model gets the order of events correct, not how well the model matches the event probability over time as a function of covariates. Furthermore, the usual c-index can have bias depending on censoring patterns. There are ways to deal with that, but you are still left with a measure of discrimination only.\n\n\n\n\nA recent arXiv paper by Lillelund et al., \"Stop Chasing the C-index: This Is How We Should Evaluate Our Survival Models (https://arxiv.org/html/2506.02075v1),\" goes into more detail and explains better evaluation methods. The \"Review of Statistical Methods for Evaluating the Performance of Survival or Other Time-to-Event Prediction Models (from Conventional to Deep Learning Approaches) (https://doi.org/10.3348/kjr.2021.0223)\" by Park et al., Korean J Radiol. 22:1697-1707 (2021) is also on-topic.\n\n\n\n\nYour choice of evaluation method might best depend on your intended use of model, which isn't clear from this question.\n\n\n\n\n\n\n\n... at what point (in terms of size of data and censoring/nr of events) would you consider that evaluating through cross-validation is preferable over a simple training/test split?\n\n\n\n\n\n\n\nA problem with a training/test split is that you limit both the amount of information used to train the model and the power to test the model reliably. Frank Harrell estimates that you need on the order of 20,000 subjects (https://www.fharrell.com/post/split-val/) before a train/test split is as stable as resampling from the data with cross-validation or bootstrapping. With the power of survival models essentially determined by the number of subjects with events, you are thus unlikely to have clinical survival data with the necessary tens of thousands of events.\n\n\n\n\nAs cross-validation involves train/test splits, it also has the problem of a small test sample in each fold. Combining all 10 test sets in 10-fold cross-validation only uses the number of cases in the original data set for testing. Repeated cross-validation helps, both in reducing reliance on a single set of splits and in increasing the effective number of test cases. Bootstrapping uses the number of cases in the original data set in each bootstrap sample, and one might use 50-100 bootstrap samples. Frank Harrell thus estimates that \"To be as good as the bootstrap, about 100 repeats of 10-fold cross-validation are required (https://www.fharrell.com/post/split-val/).\"\n\n\n\n\nWith resampling you are validating the modeling process rather than the model itself. Under the bootstrap principle, drawing samples with replacement from the available data represents the process of drawing the available data from the underlying population. Modeling each of repeated bootstrap samples and evaluating performance of each model on the full data set thus represents how well your modeling process captures the properties of the population. Comparing performance of each (possibly overfit) bootstrap-sample model on its own sample against its performance on the entire data set is the \"optimism bootstrap\" that evaluates overfitting. Once you accept that you are validating the process, objections to including training data in testing become much less compelling.\n\n\n\n\n\n\n\nI get the out of bag [OOB] concordance index calculated on the training data...\n\n\n\n\n\n\n\nThis raises an issue for whatever measure of model performance you choose. Using OOB data for testing does mean that, within each tree, the test data don't overlap with the training data. As noted above, however, that isn't necessarily required and it limits you to about 1/3 of the data in each test set. Alternatively, you could use performance within each tree's model on the entire data set as an optimism bootstrap to validate the modeling process. Frank Harrell notes that distinction in this answer (https://stats.stackexchange.com/a/656190/28500).\n\n\n\n\n\n\n\n... assuming I have the concordance index on the unseen data for all imputations computed, what is a reasonable way to join and report them - should I just average the scores?\n\n\n\n\n\n\n\nSee this question (https://stats.stackexchange.com/q/476829/28500) and its answer (https://stats.stackexchange.com/a/476849/28500) on how to use Rubin's rules to combine random forest models on multiply imputed data sets. If your score of model performance is close enough to normally distributed, then you do average scores for the point estimate. Comparisons between models require estimating the variances of the point estimates, again following Rubin's rules that combine within-imputation and between-imputation variances.\n\n\n\n\nA few suggestions\n\n\n\n\nSurvival analysis, similarly to binomial regression, can suffer from omitted-variable bias (https://stats.stackexchange.com/q/113766/28500) if any outcome-associated variable is omitted from the model. If you are studying clinical survival data, don't fall into the trap of omitting standard clinical outcome-related variables from the model. Models of outcome with predictors like gene-expression levels that don't include standard clinical variables run a serious risk of that bias and might just find proxies for clinical variables in a way that makes clinical application of the models pretty useless.\n\n\n\n\nConsider whether your goals might better be met with standard regression models. Their results are typically much easier to interpret heuristically than those of a random forest. Evaluating the added value of a single predictor is simple with regression models.\n\n\n\n\nYes, random forests can incorporate unexpected interactions among predictors in ways that regression model's can't, at least with large numbers of predictors. Identifying what those interactions involve isn't so straightforward.", "answer_url": "https://stats.stackexchange.com/a/677008", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-30T15:43:41+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676956, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-30T15:43:41+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "65108C55-42C2-445B-B21B-0B094DADB7B2", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/65108C55-42C2-445B-B21B-0B094DADB7B2/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-30T15:54:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "34531043-A9BE-4349-88AF-6D5B08F325DD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/34531043-A9BE-4349-88AF-6D5B08F325DD/view-source"}], "score": 1, "updated_at": "2026-08-30T15:54:06+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "test", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "\n\nI .. wish to evaluate a survival forest using all but one special variable on this same data, and compare the results with those of the model using all variables.
\n
Frank Harrell has a superb summary of how to evaluate the value of additional predictors in modeling. That's straightforward with nested regression models, which can be compared in a likelihood-ratio test. If you need to use random survival forests, some measure of explained variation in outcomes would be appropriate.
\n\n\nI can compute the concordance index...
\n
Frank Harrell introduced the concordance/c-index to survival analysis. Although it is a useful measure of a single model's discriminative ability, he doesn't think that it's a good way to compare models; see the link above. It only evaluates how well the model gets the order of events correct, not how well the model matches the event probability over time as a function of covariates. Furthermore, the usual c-index can have bias depending on censoring patterns. There are ways to deal with that, but you are still left with a measure of discrimination only.
\nA recent arXiv paper by Lillelund et al., "Stop Chasing the C-index: This Is How We Should Evaluate Our Survival Models," goes into more detail and explains better evaluation methods. The "Review of Statistical Methods for Evaluating the Performance of Survival or Other Time-to-Event Prediction Models (from Conventional to Deep Learning Approaches)" by Park et al., Korean J Radiol. 22:1697-1707 (2021) is also on-topic.
\nYour choice of evaluation method might best depend on your intended use of model, which isn't clear from this question.
\n\n\n... at what point (in terms of size of data and censoring/nr of events) would you consider that evaluating through cross-validation is preferable over a simple training/test split?
\n
A problem with a training/test split is that you limit both the amount of information used to train the model and the power to test the model reliably. Frank Harrell estimates that you need on the order of 20,000 subjects before a train/test split is as stable as resampling from the data with cross-validation or bootstrapping. With the power of survival models essentially determined by the number of subjects with events, you are thus unlikely to have clinical survival data with the necessary tens of thousands of events.
\nAs cross-validation involves train/test splits, it also has the problem of a small test sample in each fold. Combining all 10 test sets in 10-fold cross-validation only uses the number of cases in the original data set for testing. Repeated cross-validation helps, both in reducing reliance on a single set of splits and in increasing the effective number of test cases. Bootstrapping uses the number of cases in the original data set in each bootstrap sample, and one might use 50-100 bootstrap samples. Frank Harrell thus estimates that "To be as good as the bootstrap, about 100 repeats of 10-fold cross-validation are required."
\nWith resampling you are validating the modeling process rather than the model itself. Under the bootstrap principle, drawing samples with replacement from the available data represents the process of drawing the available data from the underlying population. Modeling each of repeated bootstrap samples and evaluating performance of each model on the full data set thus represents how well your modeling process captures the properties of the population. Comparing performance of each (possibly overfit) bootstrap-sample model on its own sample against its performance on the entire data set is the "optimism bootstrap" that evaluates overfitting. Once you accept that you are validating the process, objections to including training data in testing become much less compelling.
\n\n\nI get the out of bag [OOB] concordance index calculated on the training data...
\n
This raises an issue for whatever measure of model performance you choose. Using OOB data for testing does mean that, within each tree, the test data don't overlap with the training data. As noted above, however, that isn't necessarily required and it limits you to about 1/3 of the data in each test set. Alternatively, you could use performance within each tree's model on the entire data set as an optimism bootstrap to validate the modeling process. Frank Harrell notes that distinction in this answer.
\n\n\n... assuming I have the concordance index on the unseen data for all imputations computed, what is a reasonable way to join and report them - should I just average the scores?
\n
See this question and its answer on how to use Rubin's rules to combine random forest models on multiply imputed data sets. If your score of model performance is close enough to normally distributed, then you do average scores for the point estimate. Comparisons between models require estimating the variances of the point estimates, again following Rubin's rules that combine within-imputation and between-imputation variances.
\nA few suggestions
\nSurvival analysis, similarly to binomial regression, can suffer from omitted-variable bias if any outcome-associated variable is omitted from the model. If you are studying clinical survival data, don't fall into the trap of omitting standard clinical outcome-related variables from the model. Models of outcome with predictors like gene-expression levels that don't include standard clinical variables run a serious risk of that bias and might just find proxies for clinical variables in a way that makes clinical application of the models pretty useless.
\nConsider whether your goals might better be met with standard regression models. Their results are typically much easier to interpret heuristically than those of a random forest. Evaluating the added value of a single predictor is simple with regression models.
\nYes, random forests can incorporate unexpected interactions among predictors in ways that regression model's can't, at least with large numbers of predictors. Identifying what those interactions involve isn't so straightforward.
\n", "answer_id": 677008, "answer_text": "I .. wish to evaluate a survival forest using all but one special variable on this same data, and compare the results with those of the model using all variables.\n\n\n\n\n\n\n\nFrank Harrell has a superb summary of how to evaluate the value of additional predictors (https://www.fharrell.com/post/addvalue/) in modeling. That's straightforward with nested regression models, which can be compared in a likelihood-ratio test. If you need to use random survival forests, some measure of explained variation in outcomes would be appropriate.\n\n\n\n\n\n\n\nI can compute the concordance index...\n\n\n\n\n\n\n\nFrank Harrell introduced the concordance/c-index to survival analysis. Although it is a useful measure of a single model's discriminative ability, he doesn't think that it's a good way to compare models; see the link (https://www.fharrell.com/post/addvalue/) above. It only evaluates how well the model gets the order of events correct, not how well the model matches the event probability over time as a function of covariates. Furthermore, the usual c-index can have bias depending on censoring patterns. There are ways to deal with that, but you are still left with a measure of discrimination only.\n\n\n\n\nA recent arXiv paper by Lillelund et al., \"Stop Chasing the C-index: This Is How We Should Evaluate Our Survival Models (https://arxiv.org/html/2506.02075v1),\" goes into more detail and explains better evaluation methods. The \"Review of Statistical Methods for Evaluating the Performance of Survival or Other Time-to-Event Prediction Models (from Conventional to Deep Learning Approaches) (https://doi.org/10.3348/kjr.2021.0223)\" by Park et al., Korean J Radiol. 22:1697-1707 (2021) is also on-topic.\n\n\n\n\nYour choice of evaluation method might best depend on your intended use of model, which isn't clear from this question.\n\n\n\n\n\n\n\n... at what point (in terms of size of data and censoring/nr of events) would you consider that evaluating through cross-validation is preferable over a simple training/test split?\n\n\n\n\n\n\n\nA problem with a training/test split is that you limit both the amount of information used to train the model and the power to test the model reliably. Frank Harrell estimates that you need on the order of 20,000 subjects (https://www.fharrell.com/post/split-val/) before a train/test split is as stable as resampling from the data with cross-validation or bootstrapping. With the power of survival models essentially determined by the number of subjects with events, you are thus unlikely to have clinical survival data with the necessary tens of thousands of events.\n\n\n\n\nAs cross-validation involves train/test splits, it also has the problem of a small test sample in each fold. Combining all 10 test sets in 10-fold cross-validation only uses the number of cases in the original data set for testing. Repeated cross-validation helps, both in reducing reliance on a single set of splits and in increasing the effective number of test cases. Bootstrapping uses the number of cases in the original data set in each bootstrap sample, and one might use 50-100 bootstrap samples. Frank Harrell thus estimates that \"To be as good as the bootstrap, about 100 repeats of 10-fold cross-validation are required (https://www.fharrell.com/post/split-val/).\"\n\n\n\n\nWith resampling you are validating the modeling process rather than the model itself. Under the bootstrap principle, drawing samples with replacement from the available data represents the process of drawing the available data from the underlying population. Modeling each of repeated bootstrap samples and evaluating performance of each model on the full data set thus represents how well your modeling process captures the properties of the population. Comparing performance of each (possibly overfit) bootstrap-sample model on its own sample against its performance on the entire data set is the \"optimism bootstrap\" that evaluates overfitting. Once you accept that you are validating the process, objections to including training data in testing become much less compelling.\n\n\n\n\n\n\n\nI get the out of bag [OOB] concordance index calculated on the training data...\n\n\n\n\n\n\n\nThis raises an issue for whatever measure of model performance you choose. Using OOB data for testing does mean that, within each tree, the test data don't overlap with the training data. As noted above, however, that isn't necessarily required and it limits you to about 1/3 of the data in each test set. Alternatively, you could use performance within each tree's model on the entire data set as an optimism bootstrap to validate the modeling process. Frank Harrell notes that distinction in this answer (https://stats.stackexchange.com/a/656190/28500).\n\n\n\n\n\n\n\n... assuming I have the concordance index on the unseen data for all imputations computed, what is a reasonable way to join and report them - should I just average the scores?\n\n\n\n\n\n\n\nSee this question (https://stats.stackexchange.com/q/476829/28500) and its answer (https://stats.stackexchange.com/a/476849/28500) on how to use Rubin's rules to combine random forest models on multiply imputed data sets. If your score of model performance is close enough to normally distributed, then you do average scores for the point estimate. Comparisons between models require estimating the variances of the point estimates, again following Rubin's rules that combine within-imputation and between-imputation variances.\n\n\n\n\nA few suggestions\n\n\n\n\nSurvival analysis, similarly to binomial regression, can suffer from omitted-variable bias (https://stats.stackexchange.com/q/113766/28500) if any outcome-associated variable is omitted from the model. If you are studying clinical survival data, don't fall into the trap of omitting standard clinical outcome-related variables from the model. Models of outcome with predictors like gene-expression levels that don't include standard clinical variables run a serious risk of that bias and might just find proxies for clinical variables in a way that makes clinical application of the models pretty useless.\n\n\n\n\nConsider whether your goals might better be met with standard regression models. Their results are typically much easier to interpret heuristically than those of a random forest. Evaluating the added value of a single predictor is simple with regression models.\n\n\n\n\nYes, random forests can incorporate unexpected interactions among predictors in ways that regression model's can't, at least with large numbers of predictors. Identifying what those interactions involve isn't so straightforward.", "answer_url": "https://stats.stackexchange.com/a/677008", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-30T15:43:41+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676956, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-30T15:43:41+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "65108C55-42C2-445B-B21B-0B094DADB7B2", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/65108C55-42C2-445B-B21B-0B094DADB7B2/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-30T15:54:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "34531043-A9BE-4349-88AF-6D5B08F325DD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/34531043-A9BE-4349-88AF-6D5B08F325DD/view-source"}], "score": 1, "updated_at": "2026-08-30T15:54:06+00:00"}], "domain": "statistics", "external_links": ["https://arxiv.org/html/2506.02075v1", "https://doi.org/10.3348/kjr.2021.0223", "https://www.fharrell.com/post/addvalue/", "https://www.fharrell.com/post/split-val/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Polhek", "question_author_url": "https://stats.stackexchange.com/users/128159/polhek", "question_author_user_type": "registered", "question_created_at": "2026-08-25T13:00:28+00:00", "question_html": "I've worked with tree-based models before, but I'm new to survival analysis. I have a very large dataset of highly censored data, and multiple imputations (let's say 5). I wish to train a survival forest on this data and evaluate it. More than this, I also wish to evaluate a survival forest using all but one special variable on this same data, and compare the results with those of the model using all variables.
\nWhat I am confused about is the evaluation. The way I was planning to do it is the following:
\nAt this point I'm wondering, is the training OOB concordance index a better evaluation metrics of a model than the concordance index on the unseen portion of the data?\nAnd, assuming I have the concordance index on the unseen data for all imputations computed, what is a reasonable way to join and report them - should I just average the scores?
\nAnd here I wonder, how to compare the two? Do I just test the average concordance indexes of the models being significantly different? Or is there a better way of comparison?
\nAnd as a last, more general question - at what point (in terms of size of data and censoring/nr of events) would you consider that evaluating through cross-validation is preferable over a simple training/test split?
\n", "question_id": 676956, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "I've worked with tree-based models before, but I'm new to survival analysis. I have a very large dataset of highly censored data, and multiple imputations (let's say 5). I wish to train a survival forest on this data and evaluate it. More than this, I also wish to evaluate a survival forest using all but one special variable on this same data, and compare the results with those of the model using all variables.\n\n\n\n\nWhat I am confused about is the evaluation. The way I was planning to do it is the following:\n\n\n\n\n\nFirst, I split the samples into training/testing (stratified by events, 80-20 split).\n\n\n\n\nThen for every imputation, I train a survival forest using all variables on the imputed training samples.\n\n\n\n\nAfter training, I get the out of bag concordance index calculated on the training data and I can compute the concordance index on the using test samples also.\n\n\n\n\n\nAt this point I'm wondering, is the training OOB concordance index a better evaluation metrics of a model than the concordance index on the unseen portion of the data?\nAnd, assuming I have the concordance index on the unseen data for all imputations computed, what is a reasonable way to join and report them - should I just average the scores?\n\n\n\n\n\nNext I do the same (training a model for every imputation on the training samples) using all but one variable of interest. I get OOB c-index and the c-index on the unseen data for each model/imputation.\n\n\n\n\n\nAnd here I wonder, how to compare the two? Do I just test the average concordance indexes of the models being significantly different? Or is there a better way of comparison?\n\n\n\n\nAnd as a last, more general question - at what point (in terms of size of data and censoring/nr of events) would you consider that evaluating through cross-validation is preferable over a simple training/test split?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Polhek", "profile_url": "https://stats.stackexchange.com/users/128159/polhek", "user_type": "registered"}, "created_at": "2026-08-25T13:00:28+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "C4B771B4-ADC3-4FD6-AE5D-16BE2127FFCA", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C4B771B4-ADC3-4FD6-AE5D-16BE2127FFCA/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676956/evaluating-survival-forest-models-on-multiple-imputation-data", "split": "test", "split_group": "8636b1b5f40d7aa127b413ad0a54ccb1823c8f472ffcec2eef386149ce3eef6d", "tags": ["survival", "random-forest", "multiple-imputation", "concordance"], "thread_id": "stats:676956", "title": "Evaluating survival forest models on multiple imputation data"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I understand their fundamental differences and that they are measuring different things. There are quite a few threads already comparing the two methods to each other.\nHowever, none really answer how to \"best\" compare a standard deviation value to an RMSE value.\n\n\n\n\nFor example, lets look at the Bosch BMM150 (https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmm150-ds001.pdf) sensor. It's a magnetic field sensor and measures its heading/azimuth. The datasheet claims an accuary of $\\pm2.5°$ regarding $\\pm3\\sigma$. That means the standard deviation is $\\sigma=0.83°$ and that $99.7\\%$ of its measured values are within $2.5°$ of the actual heading.\n\n\n\n\nNow lets say I have another sensor that claims to have an RMSE of $2.5°$. Is it more or less accuate than the Bosch sensor?", "record_id": "Scientific-Statistics-QA:stats:676975", "selected_answer": {"answer_html": "It would appear that the Bosch BMM150 sensor is implicitly declared/accepted as an unbiased measuring instrument. This I infer by the summary way that the pamflet informs on what the min-max values are ("$\\pm 3\\sigma$", pointing to a zero-mean Normal distribution), and also by the way the OP builds on this information to obtain the implied standard deviation, invoking silently the Normal.
\nWith zero bias, we have\n$${\\rm RMSE }\\;(BMM150) = \\sigma = 0.833$$
\nto be compared to the other sensor with RMSE = 2.5.
\nFor some informal intuition, the information on the Bosch sensor says that "$2.5$" is an extreme value of the error (half-length of a Confidence Interval on the error, with very high statistical confidence), while for the RMSE of the other sensor "$2.5$" is its average value. If this is an average, it is logical to expect from the 2nd sensor to have with some frequency even higher error-values, and so that it ends up inferior in RMSE terms.
\n", "answer_id": 677000, "answer_text": "It would appear that the Bosch BMM150 sensor is implicitly declared/accepted as an unbiased measuring instrument. This I infer by the summary way that the pamflet informs on what the min-max values are (\"$\\pm 3\\sigma$\", pointing to a zero-mean Normal distribution), and also by the way the OP builds on this information to obtain the implied standard deviation, invoking silently the Normal.\n\n\n\n\nWith zero bias, we have\n$${\\rm RMSE }\\;(BMM150) = \\sigma = 0.833$$\n\n\n\n\nto be compared to the other sensor with RMSE = 2.5.\n\n\n\n\nFor some informal intuition, the information on the Bosch sensor says that \"$2.5$\" is an extreme value of the error (half-length of a Confidence Interval on the error, with very high statistical confidence), while for the RMSE of the other sensor \"$2.5$\" is its average value. If this is an average, it is logical to expect from the 2nd sensor to have with some frequency even higher error-values, and so that it ends up inferior in RMSE terms.", "answer_url": "https://stats.stackexchange.com/a/677000", "author": "Alecos Papadopoulos", "author_url": "https://stats.stackexchange.com/users/28746/alecos-papadopoulos", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T17:24:38+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676975, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alecos Papadopoulos", "profile_url": "https://stats.stackexchange.com/users/28746/alecos-papadopoulos", "user_type": "registered"}, "created_at": "2026-08-29T17:24:38+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "08B127CA-03A0-4A61-8D0D-8F3FF0F9CBF1", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/08B127CA-03A0-4A61-8D0D-8F3FF0F9CBF1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alecos Papadopoulos", "profile_url": "https://stats.stackexchange.com/users/28746/alecos-papadopoulos", "user_type": "registered"}, "created_at": "2026-08-30T17:48:55+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "79E36E85-896B-4E05-B1B2-D421C8680DF1", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/79E36E85-896B-4E05-B1B2-D421C8680DF1/view-source"}], "score": 2, "updated_at": "2026-08-30T17:48:55+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "test", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "It would appear that the Bosch BMM150 sensor is implicitly declared/accepted as an unbiased measuring instrument. This I infer by the summary way that the pamflet informs on what the min-max values are ("$\\pm 3\\sigma$", pointing to a zero-mean Normal distribution), and also by the way the OP builds on this information to obtain the implied standard deviation, invoking silently the Normal.
\nWith zero bias, we have\n$${\\rm RMSE }\\;(BMM150) = \\sigma = 0.833$$
\nto be compared to the other sensor with RMSE = 2.5.
\nFor some informal intuition, the information on the Bosch sensor says that "$2.5$" is an extreme value of the error (half-length of a Confidence Interval on the error, with very high statistical confidence), while for the RMSE of the other sensor "$2.5$" is its average value. If this is an average, it is logical to expect from the 2nd sensor to have with some frequency even higher error-values, and so that it ends up inferior in RMSE terms.
\n", "answer_id": 677000, "answer_text": "It would appear that the Bosch BMM150 sensor is implicitly declared/accepted as an unbiased measuring instrument. This I infer by the summary way that the pamflet informs on what the min-max values are (\"$\\pm 3\\sigma$\", pointing to a zero-mean Normal distribution), and also by the way the OP builds on this information to obtain the implied standard deviation, invoking silently the Normal.\n\n\n\n\nWith zero bias, we have\n$${\\rm RMSE }\\;(BMM150) = \\sigma = 0.833$$\n\n\n\n\nto be compared to the other sensor with RMSE = 2.5.\n\n\n\n\nFor some informal intuition, the information on the Bosch sensor says that \"$2.5$\" is an extreme value of the error (half-length of a Confidence Interval on the error, with very high statistical confidence), while for the RMSE of the other sensor \"$2.5$\" is its average value. If this is an average, it is logical to expect from the 2nd sensor to have with some frequency even higher error-values, and so that it ends up inferior in RMSE terms.", "answer_url": "https://stats.stackexchange.com/a/677000", "author": "Alecos Papadopoulos", "author_url": "https://stats.stackexchange.com/users/28746/alecos-papadopoulos", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T17:24:38+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676975, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alecos Papadopoulos", "profile_url": "https://stats.stackexchange.com/users/28746/alecos-papadopoulos", "user_type": "registered"}, "created_at": "2026-08-29T17:24:38+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "08B127CA-03A0-4A61-8D0D-8F3FF0F9CBF1", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/08B127CA-03A0-4A61-8D0D-8F3FF0F9CBF1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alecos Papadopoulos", "profile_url": "https://stats.stackexchange.com/users/28746/alecos-papadopoulos", "user_type": "registered"}, "created_at": "2026-08-30T17:48:55+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "79E36E85-896B-4E05-B1B2-D421C8680DF1", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/79E36E85-896B-4E05-B1B2-D421C8680DF1/view-source"}], "score": 2, "updated_at": "2026-08-30T17:48:55+00:00"}], "domain": "statistics", "external_links": ["https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmm150-ds001.pdf"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "M.X", "question_author_url": "https://stats.stackexchange.com/users/515989/m-x", "question_author_user_type": "registered", "question_created_at": "2026-08-27T12:58:22+00:00", "question_html": "I understand their fundamental differences and that they are measuring different things. There are quite a few threads already comparing the two methods to each other.\nHowever, none really answer how to "best" compare a standard deviation value to an RMSE value.
\nFor example, lets look at the Bosch BMM150 sensor. It's a magnetic field sensor and measures its heading/azimuth. The datasheet claims an accuary of $\\pm2.5°$ regarding $\\pm3\\sigma$. That means the standard deviation is $\\sigma=0.83°$ and that $99.7\\%$ of its measured values are within $2.5°$ of the actual heading.
\nNow lets say I have another sensor that claims to have an RMSE of $2.5°$. Is it more or less accuate than the Bosch sensor?
\n", "question_id": 676975, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I understand their fundamental differences and that they are measuring different things. There are quite a few threads already comparing the two methods to each other.\nHowever, none really answer how to \"best\" compare a standard deviation value to an RMSE value.\n\n\n\n\nFor example, lets look at the Bosch BMM150 (https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmm150-ds001.pdf) sensor. It's a magnetic field sensor and measures its heading/azimuth. The datasheet claims an accuary of $\\pm2.5°$ regarding $\\pm3\\sigma$. That means the standard deviation is $\\sigma=0.83°$ and that $99.7\\%$ of its measured values are within $2.5°$ of the actual heading.\n\n\n\n\nNow lets say I have another sensor that claims to have an RMSE of $2.5°$. Is it more or less accuate than the Bosch sensor?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M.X", "profile_url": "https://stats.stackexchange.com/users/515989/m-x", "user_type": "registered"}, "created_at": "2026-08-27T12:58:22+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "90A46F66-D397-415D-B481-592C45F29D24", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/90A46F66-D397-415D-B481-592C45F29D24/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676975/how-to-compare-a-standard-deviation-to-a-root-mean-square-error", "split": "test", "split_group": "cd99f41c0a42d92d6e8aa8fd37dea2f75901b57bc32e8ea30cf079304b90a422", "tags": ["standard-deviation", "mse", "rms"], "thread_id": "stats:676975", "title": "How to compare a standard deviation to a root mean square error?"}} +{"accepted_answer": {"answer_html": "\n\nIt seems that the rationale here is to see whether the explanation models recover the same input features than the original...
\n
The idea is instead to come close enough to the same outcome predictions of the model. This isn't just a problem with "machine learning" models. For example, Section 5.5.2 of Frank Harrell's Regression Modeling Strategies outlines approaches to the same problem with potentially complex, difficult-to-interpret, multiple regression models. One approach is to use a (more interpretable) subset of the features to fit an OLS model of the predictor values from the full model.
\n\n\nI think the selection of features (through K-LASSO) is an important yet under-explained part of the paper.
\n
In principle, the above simplification of a multiple regression model is not much different from LIME. For a continuous outcome, LIME similarly uses a subset of the features to fit model predictions near a region of interest. K-LASSO selects which K of the features to use.
\n\n\nSo the aim is to test whether LIME selects the same features of all available ones as compared to the original model.
\n
A full machine learning model often involves all of the candidate features in some way, so LIME can't typically "select the same features." LASSO is an exception. In LASSO for linear regression, you start with a loss form similar to what you show.
\n$$L = \\sum_{i} (y_i - g(z_i))^2 + \\lambda \\sum_k{|\\beta_k|},$$
\nwhere the $\\beta_k$ are the coefficient estimates for the predictors. The $\\lambda \\sum_k{|\\beta_k|}$ term is called an L1 penalty, which sets increasing numbers of coefficients exactly to 0 as $\\lambda$ increases. See this page and its links.
\nLASSO usually involves choosing $\\lambda$ to minimize that loss. The K-LASSO evidently finds instead a value of $\\lambda$ that retains only K non-zero coefficients (perhaps using a different loss function).
\n\n\nI could read LASSO in detail but my bandwidth right now is just about enough for LIME/SP-LIME...
\n
I'd recommend devoting more bandwidth to multiple regression, including LASSO and other penalization methods (e.g., ridge regression and elastic net) that minimize overfitting of the data. An Introduction to Statistical Learning is a useful reference on those and other major modeling methods.
\n", "answer_id": 677040, "answer_text": "It seems that the rationale here is to see whether the explanation models recover the same input features than the original...\n\n\n\n\n\n\n\nThe idea is instead to come close enough to the same outcome predictions of the model. This isn't just a problem with \"machine learning\" models. For example, Section 5.5.2 of Frank Harrell's Regression Modeling Strategies (https://hbiostat.org/rmsc/validate#approximating-the-full-model) outlines approaches to the same problem with potentially complex, difficult-to-interpret, multiple regression models. One approach is to use a (more interpretable) subset of the features to fit an OLS model of the predictor values from the full model.\n\n\n\n\n\n\n\nI think the selection of features (through K-LASSO) is an important yet under-explained part of the paper.\n\n\n\n\n\n\n\nIn principle, the above simplification of a multiple regression model is not much different from LIME. For a continuous outcome, LIME similarly uses a subset of the features to fit model predictions near a region of interest. K-LASSO selects which K of the features to use.\n\n\n\n\n\n\n\nSo the aim is to test whether LIME selects the same features of all available ones as compared to the original model.\n\n\n\n\n\n\n\nA full machine learning model often involves all of the candidate features in some way, so LIME can't typically \"select the same features.\" LASSO is an exception. In LASSO for linear regression, you start with a loss form similar to what you show.\n\n\n\n\n$$L = \\sum_{i} (y_i - g(z_i))^2 + \\lambda \\sum_k{|\\beta_k|},$$\n\n\n\n\nwhere the $\\beta_k$ are the coefficient estimates for the predictors. The $\\lambda \\sum_k{|\\beta_k|}$ term is called an L1 penalty, which sets increasing numbers of coefficients exactly to 0 as $\\lambda$ increases. See this page (https://stats.stackexchange.com/q/74542/28500) and its links.\n\n\n\n\nLASSO usually involves choosing $\\lambda$ to minimize that loss. The K-LASSO evidently finds instead a value of $\\lambda$ that retains only K non-zero coefficients (perhaps using a different loss function).\n\n\n\n\n\n\n\nI could read LASSO in detail but my bandwidth right now is just about enough for LIME/SP-LIME...\n\n\n\n\n\n\n\nI'd recommend devoting more bandwidth to multiple regression, including LASSO and other penalization methods (e.g., ridge regression and elastic net) that minimize overfitting of the data. An Introduction to Statistical Learning (https://www.statlearning.com/) is a useful reference on those and other major modeling methods.", "answer_url": "https://stats.stackexchange.com/a/677040", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T19:10:48+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677035, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-01T19:10:48+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B0F5F5-4922-40E3-B683-A890D9DA3239", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B0F5F5-4922-40E3-B683-A890D9DA3239/view-source"}], "score": 2, "updated_at": "2026-09-01T19:10:48+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "Context\n\n\n\n\nSection 5.2 of the 2016 paper \"Why Should I Trust You?\": Explaining the Predictions of Any Classifier (https://dl.acm.org/doi/10.1145/2939672.2939778) tests the Recall of different XAI methods comparing them to interpretable methods.\n\n\n\n\nMy question is about interpreting this section, and the role played by K-LASSO.\n\n\n\n\nIt seems that the rationale here is to see whether the explanation models recover the same input features than the original, since in this case the original model is interpretable (also its input, a bag of words).\n\n\n\n\nSelecting Features\n\n\n\n\nSo the aim is to test whether LIME selects the same features of all available ones as compared to the original model.\n\n\n\n\nI think the selection of features (through K-LASSO) is an important yet under-explained part of the paper.\n\n\n\n\nThe algorithm that applies here, for their model, is LIME (not SP-LIME), which uses K-LASSO to select $K$ features:\n\n\n\n\n\n\n\n(...) selecting $K$ features with Lasso (using the regularization path [9]) and then learning the weights via least squares (a procedure we call K-LASSO in Algorithm 1).\n\n\n\n\n\n\n\nFrom talking to a chatbot, my intuition is that $K$-LASSO usually yields a sparse model, given that some coefficients will be 0, and those features will be the ones we retain or discard from all the ones available.\n\n\n\n\nI am aware I could read LASSO in detail but my bandwidth right now is just about enough for LIME/SP-LIME, so I am using my knowledge of Least-Squares to get an intuition of what is happening.\n\n\n\n\nQuestions\n\n\n\n\n\nIs the overall idea is correct, or what corrections you'd make?\n\n\n\n\nIn the paper LIME shows a loss $\\xi (x) = \\mathrm{argmin_g} L (f,g,\\pi_x (z)) + \\Omega(g)$, and I am assuming LASSO can be performed with such loss as well, otherwise there are two optimisations and the pieces don't fit well in my head.\n\n\n\n\n\nFor completeness, the paper uses $g$ explanation model, $f$ original model, $\\pi_x (z)$ is used as a distance-weight multiplying the loss-L-component $L = \\sum_{z,z'} \\pi_x (f(z)-g(z'))^2$ and $\\Omega$ a model-complexity measure.\n\n\n\n\nComment\n\n\n\n\nThe chatbot says LASSO is done to select features (0 coefficients are features we then discard), but the coeffients arent the best to fit the original model (since there is the extra penalty in the Loss).\n\n\n\n\nSo then Least Squares to re-fit or just fit the coefficients. I'd appreciate corrections if this is wrong, but it does make sense to me", "record_id": "Scientific-Statistics-QA:stats:677035", "selected_answer": {"answer_html": "\n\nIt seems that the rationale here is to see whether the explanation models recover the same input features than the original...
\n
The idea is instead to come close enough to the same outcome predictions of the model. This isn't just a problem with "machine learning" models. For example, Section 5.5.2 of Frank Harrell's Regression Modeling Strategies outlines approaches to the same problem with potentially complex, difficult-to-interpret, multiple regression models. One approach is to use a (more interpretable) subset of the features to fit an OLS model of the predictor values from the full model.
\n\n\nI think the selection of features (through K-LASSO) is an important yet under-explained part of the paper.
\n
In principle, the above simplification of a multiple regression model is not much different from LIME. For a continuous outcome, LIME similarly uses a subset of the features to fit model predictions near a region of interest. K-LASSO selects which K of the features to use.
\n\n\nSo the aim is to test whether LIME selects the same features of all available ones as compared to the original model.
\n
A full machine learning model often involves all of the candidate features in some way, so LIME can't typically "select the same features." LASSO is an exception. In LASSO for linear regression, you start with a loss form similar to what you show.
\n$$L = \\sum_{i} (y_i - g(z_i))^2 + \\lambda \\sum_k{|\\beta_k|},$$
\nwhere the $\\beta_k$ are the coefficient estimates for the predictors. The $\\lambda \\sum_k{|\\beta_k|}$ term is called an L1 penalty, which sets increasing numbers of coefficients exactly to 0 as $\\lambda$ increases. See this page and its links.
\nLASSO usually involves choosing $\\lambda$ to minimize that loss. The K-LASSO evidently finds instead a value of $\\lambda$ that retains only K non-zero coefficients (perhaps using a different loss function).
\n\n\nI could read LASSO in detail but my bandwidth right now is just about enough for LIME/SP-LIME...
\n
I'd recommend devoting more bandwidth to multiple regression, including LASSO and other penalization methods (e.g., ridge regression and elastic net) that minimize overfitting of the data. An Introduction to Statistical Learning is a useful reference on those and other major modeling methods.
\n", "answer_id": 677040, "answer_text": "It seems that the rationale here is to see whether the explanation models recover the same input features than the original...\n\n\n\n\n\n\n\nThe idea is instead to come close enough to the same outcome predictions of the model. This isn't just a problem with \"machine learning\" models. For example, Section 5.5.2 of Frank Harrell's Regression Modeling Strategies (https://hbiostat.org/rmsc/validate#approximating-the-full-model) outlines approaches to the same problem with potentially complex, difficult-to-interpret, multiple regression models. One approach is to use a (more interpretable) subset of the features to fit an OLS model of the predictor values from the full model.\n\n\n\n\n\n\n\nI think the selection of features (through K-LASSO) is an important yet under-explained part of the paper.\n\n\n\n\n\n\n\nIn principle, the above simplification of a multiple regression model is not much different from LIME. For a continuous outcome, LIME similarly uses a subset of the features to fit model predictions near a region of interest. K-LASSO selects which K of the features to use.\n\n\n\n\n\n\n\nSo the aim is to test whether LIME selects the same features of all available ones as compared to the original model.\n\n\n\n\n\n\n\nA full machine learning model often involves all of the candidate features in some way, so LIME can't typically \"select the same features.\" LASSO is an exception. In LASSO for linear regression, you start with a loss form similar to what you show.\n\n\n\n\n$$L = \\sum_{i} (y_i - g(z_i))^2 + \\lambda \\sum_k{|\\beta_k|},$$\n\n\n\n\nwhere the $\\beta_k$ are the coefficient estimates for the predictors. The $\\lambda \\sum_k{|\\beta_k|}$ term is called an L1 penalty, which sets increasing numbers of coefficients exactly to 0 as $\\lambda$ increases. See this page (https://stats.stackexchange.com/q/74542/28500) and its links.\n\n\n\n\nLASSO usually involves choosing $\\lambda$ to minimize that loss. The K-LASSO evidently finds instead a value of $\\lambda$ that retains only K non-zero coefficients (perhaps using a different loss function).\n\n\n\n\n\n\n\nI could read LASSO in detail but my bandwidth right now is just about enough for LIME/SP-LIME...\n\n\n\n\n\n\n\nI'd recommend devoting more bandwidth to multiple regression, including LASSO and other penalization methods (e.g., ridge regression and elastic net) that minimize overfitting of the data. An Introduction to Statistical Learning (https://www.statlearning.com/) is a useful reference on those and other major modeling methods.", "answer_url": "https://stats.stackexchange.com/a/677040", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T19:10:48+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677035, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-01T19:10:48+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B0F5F5-4922-40E3-B683-A890D9DA3239", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B0F5F5-4922-40E3-B683-A890D9DA3239/view-source"}], "score": 2, "updated_at": "2026-09-01T19:10:48+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "test", "thread": {"accepted_answer_id": 677040, "answers": [{"answer_html": "\n\nIt seems that the rationale here is to see whether the explanation models recover the same input features than the original...
\n
The idea is instead to come close enough to the same outcome predictions of the model. This isn't just a problem with "machine learning" models. For example, Section 5.5.2 of Frank Harrell's Regression Modeling Strategies outlines approaches to the same problem with potentially complex, difficult-to-interpret, multiple regression models. One approach is to use a (more interpretable) subset of the features to fit an OLS model of the predictor values from the full model.
\n\n\nI think the selection of features (through K-LASSO) is an important yet under-explained part of the paper.
\n
In principle, the above simplification of a multiple regression model is not much different from LIME. For a continuous outcome, LIME similarly uses a subset of the features to fit model predictions near a region of interest. K-LASSO selects which K of the features to use.
\n\n\nSo the aim is to test whether LIME selects the same features of all available ones as compared to the original model.
\n
A full machine learning model often involves all of the candidate features in some way, so LIME can't typically "select the same features." LASSO is an exception. In LASSO for linear regression, you start with a loss form similar to what you show.
\n$$L = \\sum_{i} (y_i - g(z_i))^2 + \\lambda \\sum_k{|\\beta_k|},$$
\nwhere the $\\beta_k$ are the coefficient estimates for the predictors. The $\\lambda \\sum_k{|\\beta_k|}$ term is called an L1 penalty, which sets increasing numbers of coefficients exactly to 0 as $\\lambda$ increases. See this page and its links.
\nLASSO usually involves choosing $\\lambda$ to minimize that loss. The K-LASSO evidently finds instead a value of $\\lambda$ that retains only K non-zero coefficients (perhaps using a different loss function).
\n\n\nI could read LASSO in detail but my bandwidth right now is just about enough for LIME/SP-LIME...
\n
I'd recommend devoting more bandwidth to multiple regression, including LASSO and other penalization methods (e.g., ridge regression and elastic net) that minimize overfitting of the data. An Introduction to Statistical Learning is a useful reference on those and other major modeling methods.
\n", "answer_id": 677040, "answer_text": "It seems that the rationale here is to see whether the explanation models recover the same input features than the original...\n\n\n\n\n\n\n\nThe idea is instead to come close enough to the same outcome predictions of the model. This isn't just a problem with \"machine learning\" models. For example, Section 5.5.2 of Frank Harrell's Regression Modeling Strategies (https://hbiostat.org/rmsc/validate#approximating-the-full-model) outlines approaches to the same problem with potentially complex, difficult-to-interpret, multiple regression models. One approach is to use a (more interpretable) subset of the features to fit an OLS model of the predictor values from the full model.\n\n\n\n\n\n\n\nI think the selection of features (through K-LASSO) is an important yet under-explained part of the paper.\n\n\n\n\n\n\n\nIn principle, the above simplification of a multiple regression model is not much different from LIME. For a continuous outcome, LIME similarly uses a subset of the features to fit model predictions near a region of interest. K-LASSO selects which K of the features to use.\n\n\n\n\n\n\n\nSo the aim is to test whether LIME selects the same features of all available ones as compared to the original model.\n\n\n\n\n\n\n\nA full machine learning model often involves all of the candidate features in some way, so LIME can't typically \"select the same features.\" LASSO is an exception. In LASSO for linear regression, you start with a loss form similar to what you show.\n\n\n\n\n$$L = \\sum_{i} (y_i - g(z_i))^2 + \\lambda \\sum_k{|\\beta_k|},$$\n\n\n\n\nwhere the $\\beta_k$ are the coefficient estimates for the predictors. The $\\lambda \\sum_k{|\\beta_k|}$ term is called an L1 penalty, which sets increasing numbers of coefficients exactly to 0 as $\\lambda$ increases. See this page (https://stats.stackexchange.com/q/74542/28500) and its links.\n\n\n\n\nLASSO usually involves choosing $\\lambda$ to minimize that loss. The K-LASSO evidently finds instead a value of $\\lambda$ that retains only K non-zero coefficients (perhaps using a different loss function).\n\n\n\n\n\n\n\nI could read LASSO in detail but my bandwidth right now is just about enough for LIME/SP-LIME...\n\n\n\n\n\n\n\nI'd recommend devoting more bandwidth to multiple regression, including LASSO and other penalization methods (e.g., ridge regression and elastic net) that minimize overfitting of the data. An Introduction to Statistical Learning (https://www.statlearning.com/) is a useful reference on those and other major modeling methods.", "answer_url": "https://stats.stackexchange.com/a/677040", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T19:10:48+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677035, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-01T19:10:48+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B0F5F5-4922-40E3-B683-A890D9DA3239", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B0F5F5-4922-40E3-B683-A890D9DA3239/view-source"}], "score": 2, "updated_at": "2026-09-01T19:10:48+00:00"}], "domain": "statistics", "external_links": ["https://dl.acm.org/doi/10.1145/2939672.2939778", "https://hbiostat.org/rmsc/validate#approximating-the-full-model", "https://www.statlearning.com/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "kindleman", "question_author_url": "https://stats.stackexchange.com/users/510622/kindleman", "question_author_user_type": "registered", "question_created_at": "2026-09-01T13:58:20+00:00", "question_html": "Section 5.2 of the 2016 paper "Why Should I Trust You?": Explaining the Predictions of Any Classifier tests the Recall of different XAI methods comparing them to interpretable methods.
\nMy question is about interpreting this section, and the role played by K-LASSO.
\nIt seems that the rationale here is to see whether the explanation models recover the same input features than the original, since in this case the original model is interpretable (also its input, a bag of words).
\nSo the aim is to test whether LIME selects the same features of all available ones as compared to the original model.
\nI think the selection of features (through K-LASSO) is an important yet under-explained part of the paper.
\nThe algorithm that applies here, for their model, is LIME (not SP-LIME), which uses K-LASSO to select $K$ features:
\n\n\n(...) selecting $K$ features with Lasso (using the regularization path [9]) and then learning the weights via least squares (a procedure we call K-LASSO in Algorithm 1).
\n
From talking to a chatbot, my intuition is that $K$-LASSO usually yields a sparse model, given that some coefficients will be 0, and those features will be the ones we retain or discard from all the ones available.
\nI am aware I could read LASSO in detail but my bandwidth right now is just about enough for LIME/SP-LIME, so I am using my knowledge of Least-Squares to get an intuition of what is happening.
\nFor completeness, the paper uses $g$ explanation model, $f$ original model, $\\pi_x (z)$ is used as a distance-weight multiplying the loss-L-component $L = \\sum_{z,z'} \\pi_x (f(z)-g(z'))^2$ and $\\Omega$ a model-complexity measure.
\nThe chatbot says LASSO is done to select features (0 coefficients are features we then discard), but the coeffients arent the best to fit the original model (since there is the extra penalty in the Loss).
\nSo then Least Squares to re-fit or just fit the coefficients. I'd appreciate corrections if this is wrong, but it does make sense to me
\n", "question_id": 677035, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "Context\n\n\n\n\nSection 5.2 of the 2016 paper \"Why Should I Trust You?\": Explaining the Predictions of Any Classifier (https://dl.acm.org/doi/10.1145/2939672.2939778) tests the Recall of different XAI methods comparing them to interpretable methods.\n\n\n\n\nMy question is about interpreting this section, and the role played by K-LASSO.\n\n\n\n\nIt seems that the rationale here is to see whether the explanation models recover the same input features than the original, since in this case the original model is interpretable (also its input, a bag of words).\n\n\n\n\nSelecting Features\n\n\n\n\nSo the aim is to test whether LIME selects the same features of all available ones as compared to the original model.\n\n\n\n\nI think the selection of features (through K-LASSO) is an important yet under-explained part of the paper.\n\n\n\n\nThe algorithm that applies here, for their model, is LIME (not SP-LIME), which uses K-LASSO to select $K$ features:\n\n\n\n\n\n\n\n(...) selecting $K$ features with Lasso (using the regularization path [9]) and then learning the weights via least squares (a procedure we call K-LASSO in Algorithm 1).\n\n\n\n\n\n\n\nFrom talking to a chatbot, my intuition is that $K$-LASSO usually yields a sparse model, given that some coefficients will be 0, and those features will be the ones we retain or discard from all the ones available.\n\n\n\n\nI am aware I could read LASSO in detail but my bandwidth right now is just about enough for LIME/SP-LIME, so I am using my knowledge of Least-Squares to get an intuition of what is happening.\n\n\n\n\nQuestions\n\n\n\n\n\nIs the overall idea is correct, or what corrections you'd make?\n\n\n\n\nIn the paper LIME shows a loss $\\xi (x) = \\mathrm{argmin_g} L (f,g,\\pi_x (z)) + \\Omega(g)$, and I am assuming LASSO can be performed with such loss as well, otherwise there are two optimisations and the pieces don't fit well in my head.\n\n\n\n\n\nFor completeness, the paper uses $g$ explanation model, $f$ original model, $\\pi_x (z)$ is used as a distance-weight multiplying the loss-L-component $L = \\sum_{z,z'} \\pi_x (f(z)-g(z'))^2$ and $\\Omega$ a model-complexity measure.\n\n\n\n\nComment\n\n\n\n\nThe chatbot says LASSO is done to select features (0 coefficients are features we then discard), but the coeffients arent the best to fit the original model (since there is the extra penalty in the Loss).\n\n\n\n\nSo then Least Squares to re-fit or just fit the coefficients. I'd appreciate corrections if this is wrong, but it does make sense to me", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "kindleman", "profile_url": "https://stats.stackexchange.com/users/510622/kindleman", "user_type": "registered"}, "created_at": "2026-09-01T13:58:20+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "1ECA98F4-6DB3-4398-B85E-C435796E45DF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1ECA98F4-6DB3-4398-B85E-C435796E45DF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-01T14:21:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AAF72B85-DA54-49C6-8BEA-FF155201085C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AAF72B85-DA54-49C6-8BEA-FF155201085C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "kindleman", "profile_url": "https://stats.stackexchange.com/users/510622/kindleman", "user_type": "registered"}, "created_at": "2026-09-01T15:22:05+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "588BA2AD-F204-4473-8EB5-7D8AC4DB30CD", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/588BA2AD-F204-4473-8EB5-7D8AC4DB30CD/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-02T02:40:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FD4B782E-B4DA-469C-805C-494937FC4942", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/FD4B782E-B4DA-469C-805C-494937FC4942/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677035/k-lasso-and-recall-in-lime-simulated-experiments", "split": "test", "split_group": "9f7b02658ea7a661e8290f49805b5687b2ff03f604d83ced4faa2c5d53587ee2", "tags": ["linear-model", "lasso", "lime", "explainable-ai"], "thread_id": "stats:677035", "title": "K-LASSO and Recall in LIME (simulated experiments)"}} +{"accepted_answer": {"answer_html": "The 2019 Technical Perspective by Daniel, Thomas and Katherine Pollard, "Empowering statistical methods for cellular and molecular biologists" Molecular Biology of the Cell 30: 1359-1368 is a good practical introduction to study design and statistical analysis for studies like yours. I have quibbles with some details of their recommendations, but you should find it very helpful particularly as you design and analyze future experiments.
\nSubject-matter preliminaries
\nSubject-matter knowledge is important before you design or analyze experiments. You don't say much about the biological hypothesis per se, but I've run enough Western blots at least to know that quantifying them isn't trivial. The issues are covered, for example, by Pillai-Kastoori et al., "A systematic approach to quantitative Western blot analysis," Analytical Biochemistry 593: article 1136082020 (2020).
\nThis answer points out that differences between gels and blots sometimes overwhelm the differences due to treatments. Your results will be most believable if you run samples that you want to compare on the same gel and blot, even if your quantitation is OK. Current best practice expects you to provide annotated images of the entire blots anyway, at least in supplemental data.
\nTechnical versus biological replicates
\nWith all cells obtained from only 1 organ, the best you can do is test whether the protein level was associated with the treatment for the 1 organ you dissociated. The 3 samples at each combination of time and treatment are technical replicates. Differences among the 3 samples at any such combination represent technical differences in culturing the cells, extracting proteins, running the gels, exposing the Western blots, quantifying the bands, and (perhaps) normalizing against a "housekeeping" protein not expected to be affected by treatment.
\nYou need to have multiple biological replicates to support any more general hypothesis about the results. In your situation, that would at least involve organs from multiple animals from different litters, possibly of different sexes, maybe also of different ages or even different species, depending on how general you want the results to be. The Technical Perspective by the Pollards explains the difference between technical and biological replicates.
\nStatistical analysis
\nAlthough you can only examine differences for this 1 organ, the following general principles also apply to experiments with biological replicates.
\nYou have a continuous outcome (protein level via Western blot) with treatment/control and time-point (4 values) as factors. Following Figure 2 of the Technical Report by the Pollards, you could do ANOVA (analysis of variance) or a linear regression model. (ANOVA is simply a specific form of a linear regression model, so that distinction isn't very important.)
\nIf "the effect of treatment on protein levels changes with incubation time," there isn't a single "effect of treatment on protein levels (regardless of time)" or a single "effect of time on protein levels (regardless of treatment)." A 2-way ANOVA, with treatment/control in one direction and time-point in the other direction, can test whether "the effect of treatment on protein levels changes with incubation time." If it doesn't, then you can estimate the "effect of treatment on protein levels (regardless of time)" and the "effect of time on protein levels (regardless of treatment)." If it does, you can use associated "post-hoc" tests to evaluate the difference between any treatment/time-point combinations.
\nIn response to comment
\nWith treatment/control and 4 time points, you presumably have 3 interaction coefficients. When you say "2 Way ANOVA resulted in (mostly) not significant results for treatment * time interactions," I suspect that means you only found one of those coefficients to be "statistically significantly" different from 0. What that means depends on how the software codes the predictors, which can vary among software implementations and how you call their functios. You can get an overall estimate of the interaction by comparing models with and without the interaction term, for example via a likelihood-ratio test. Some implementations of 2-way ANOVA will do that automatically.
\nFor t-tests between treatment and control at each time point, it's best to start with a 2-way ANOVA. A t-test is based on the estimate of the variance of observed values around the model's predictions. If you perform a t-test at each time point, ignoring all the other time points, each test only uses the number of observations at that time point. You thus get imprecise variance estimates that can differ substantially among time points. A 2-way ANOVA instead uses all the observations/predictions to get a pooled variance estimate, which you use for all the time points.* In R, packages like emmeans can help with that.
That said, I've seen lots of plots with separate analyses for each time point. In cell biology, you typically need visually compelling differences to convince your audience. If the differences are very visually compelling, they are likely to be "statistically significant" even if the statistical tests aren't optimal.
\nYou also should be aware of the multiple comparisons problem. The more tests you run, the more likely you are to find a "significant" result just by chance. There are two things you can control to minimize that problem: the "family-wise error rate" (FWER), the probability that none of the comparisons is falsely positive, or the "false-discovery rate" (FDR), the fraction of apparent positive results likely to be false positives. In large-scale experiments in genomics and proteomics, FDR control is the usual choice.
\n*Using pooled variance estimates becomes very important in large-scale experiments like gene-expression studies on 20,000 or so genes, in which single-gene variance estimates can vary widely. The Bioconductor limma package uses an "empirical Bayes" variance estimate for each gene, which starts with individual variance estimates but then "squeezes" the estimates toward a common value. The package's author outlines that method here, with references.
The 2019 Technical Perspective by Daniel, Thomas and Katherine Pollard, "Empowering statistical methods for cellular and molecular biologists" Molecular Biology of the Cell 30: 1359-1368 is a good practical introduction to study design and statistical analysis for studies like yours. I have quibbles with some details of their recommendations, but you should find it very helpful particularly as you design and analyze future experiments.
\nSubject-matter preliminaries
\nSubject-matter knowledge is important before you design or analyze experiments. You don't say much about the biological hypothesis per se, but I've run enough Western blots at least to know that quantifying them isn't trivial. The issues are covered, for example, by Pillai-Kastoori et al., "A systematic approach to quantitative Western blot analysis," Analytical Biochemistry 593: article 1136082020 (2020).
\nThis answer points out that differences between gels and blots sometimes overwhelm the differences due to treatments. Your results will be most believable if you run samples that you want to compare on the same gel and blot, even if your quantitation is OK. Current best practice expects you to provide annotated images of the entire blots anyway, at least in supplemental data.
\nTechnical versus biological replicates
\nWith all cells obtained from only 1 organ, the best you can do is test whether the protein level was associated with the treatment for the 1 organ you dissociated. The 3 samples at each combination of time and treatment are technical replicates. Differences among the 3 samples at any such combination represent technical differences in culturing the cells, extracting proteins, running the gels, exposing the Western blots, quantifying the bands, and (perhaps) normalizing against a "housekeeping" protein not expected to be affected by treatment.
\nYou need to have multiple biological replicates to support any more general hypothesis about the results. In your situation, that would at least involve organs from multiple animals from different litters, possibly of different sexes, maybe also of different ages or even different species, depending on how general you want the results to be. The Technical Perspective by the Pollards explains the difference between technical and biological replicates.
\nStatistical analysis
\nAlthough you can only examine differences for this 1 organ, the following general principles also apply to experiments with biological replicates.
\nYou have a continuous outcome (protein level via Western blot) with treatment/control and time-point (4 values) as factors. Following Figure 2 of the Technical Report by the Pollards, you could do ANOVA (analysis of variance) or a linear regression model. (ANOVA is simply a specific form of a linear regression model, so that distinction isn't very important.)
\nIf "the effect of treatment on protein levels changes with incubation time," there isn't a single "effect of treatment on protein levels (regardless of time)" or a single "effect of time on protein levels (regardless of treatment)." A 2-way ANOVA, with treatment/control in one direction and time-point in the other direction, can test whether "the effect of treatment on protein levels changes with incubation time." If it doesn't, then you can estimate the "effect of treatment on protein levels (regardless of time)" and the "effect of time on protein levels (regardless of treatment)." If it does, you can use associated "post-hoc" tests to evaluate the difference between any treatment/time-point combinations.
\nIn response to comment
\nWith treatment/control and 4 time points, you presumably have 3 interaction coefficients. When you say "2 Way ANOVA resulted in (mostly) not significant results for treatment * time interactions," I suspect that means you only found one of those coefficients to be "statistically significantly" different from 0. What that means depends on how the software codes the predictors, which can vary among software implementations and how you call their functios. You can get an overall estimate of the interaction by comparing models with and without the interaction term, for example via a likelihood-ratio test. Some implementations of 2-way ANOVA will do that automatically.
\nFor t-tests between treatment and control at each time point, it's best to start with a 2-way ANOVA. A t-test is based on the estimate of the variance of observed values around the model's predictions. If you perform a t-test at each time point, ignoring all the other time points, each test only uses the number of observations at that time point. You thus get imprecise variance estimates that can differ substantially among time points. A 2-way ANOVA instead uses all the observations/predictions to get a pooled variance estimate, which you use for all the time points.* In R, packages like emmeans can help with that.
That said, I've seen lots of plots with separate analyses for each time point. In cell biology, you typically need visually compelling differences to convince your audience. If the differences are very visually compelling, they are likely to be "statistically significant" even if the statistical tests aren't optimal.
\nYou also should be aware of the multiple comparisons problem. The more tests you run, the more likely you are to find a "significant" result just by chance. There are two things you can control to minimize that problem: the "family-wise error rate" (FWER), the probability that none of the comparisons is falsely positive, or the "false-discovery rate" (FDR), the fraction of apparent positive results likely to be false positives. In large-scale experiments in genomics and proteomics, FDR control is the usual choice.
\n*Using pooled variance estimates becomes very important in large-scale experiments like gene-expression studies on 20,000 or so genes, in which single-gene variance estimates can vary widely. The Bioconductor limma package uses an "empirical Bayes" variance estimate for each gene, which starts with individual variance estimates but then "squeezes" the estimates toward a common value. The package's author outlines that method here, with references.
The 2019 Technical Perspective by Daniel, Thomas and Katherine Pollard, "Empowering statistical methods for cellular and molecular biologists" Molecular Biology of the Cell 30: 1359-1368 is a good practical introduction to study design and statistical analysis for studies like yours. I have quibbles with some details of their recommendations, but you should find it very helpful particularly as you design and analyze future experiments.
\nSubject-matter preliminaries
\nSubject-matter knowledge is important before you design or analyze experiments. You don't say much about the biological hypothesis per se, but I've run enough Western blots at least to know that quantifying them isn't trivial. The issues are covered, for example, by Pillai-Kastoori et al., "A systematic approach to quantitative Western blot analysis," Analytical Biochemistry 593: article 1136082020 (2020).
\nThis answer points out that differences between gels and blots sometimes overwhelm the differences due to treatments. Your results will be most believable if you run samples that you want to compare on the same gel and blot, even if your quantitation is OK. Current best practice expects you to provide annotated images of the entire blots anyway, at least in supplemental data.
\nTechnical versus biological replicates
\nWith all cells obtained from only 1 organ, the best you can do is test whether the protein level was associated with the treatment for the 1 organ you dissociated. The 3 samples at each combination of time and treatment are technical replicates. Differences among the 3 samples at any such combination represent technical differences in culturing the cells, extracting proteins, running the gels, exposing the Western blots, quantifying the bands, and (perhaps) normalizing against a "housekeeping" protein not expected to be affected by treatment.
\nYou need to have multiple biological replicates to support any more general hypothesis about the results. In your situation, that would at least involve organs from multiple animals from different litters, possibly of different sexes, maybe also of different ages or even different species, depending on how general you want the results to be. The Technical Perspective by the Pollards explains the difference between technical and biological replicates.
\nStatistical analysis
\nAlthough you can only examine differences for this 1 organ, the following general principles also apply to experiments with biological replicates.
\nYou have a continuous outcome (protein level via Western blot) with treatment/control and time-point (4 values) as factors. Following Figure 2 of the Technical Report by the Pollards, you could do ANOVA (analysis of variance) or a linear regression model. (ANOVA is simply a specific form of a linear regression model, so that distinction isn't very important.)
\nIf "the effect of treatment on protein levels changes with incubation time," there isn't a single "effect of treatment on protein levels (regardless of time)" or a single "effect of time on protein levels (regardless of treatment)." A 2-way ANOVA, with treatment/control in one direction and time-point in the other direction, can test whether "the effect of treatment on protein levels changes with incubation time." If it doesn't, then you can estimate the "effect of treatment on protein levels (regardless of time)" and the "effect of time on protein levels (regardless of treatment)." If it does, you can use associated "post-hoc" tests to evaluate the difference between any treatment/time-point combinations.
\nIn response to comment
\nWith treatment/control and 4 time points, you presumably have 3 interaction coefficients. When you say "2 Way ANOVA resulted in (mostly) not significant results for treatment * time interactions," I suspect that means you only found one of those coefficients to be "statistically significantly" different from 0. What that means depends on how the software codes the predictors, which can vary among software implementations and how you call their functios. You can get an overall estimate of the interaction by comparing models with and without the interaction term, for example via a likelihood-ratio test. Some implementations of 2-way ANOVA will do that automatically.
\nFor t-tests between treatment and control at each time point, it's best to start with a 2-way ANOVA. A t-test is based on the estimate of the variance of observed values around the model's predictions. If you perform a t-test at each time point, ignoring all the other time points, each test only uses the number of observations at that time point. You thus get imprecise variance estimates that can differ substantially among time points. A 2-way ANOVA instead uses all the observations/predictions to get a pooled variance estimate, which you use for all the time points.* In R, packages like emmeans can help with that.
That said, I've seen lots of plots with separate analyses for each time point. In cell biology, you typically need visually compelling differences to convince your audience. If the differences are very visually compelling, they are likely to be "statistically significant" even if the statistical tests aren't optimal.
\nYou also should be aware of the multiple comparisons problem. The more tests you run, the more likely you are to find a "significant" result just by chance. There are two things you can control to minimize that problem: the "family-wise error rate" (FWER), the probability that none of the comparisons is falsely positive, or the "false-discovery rate" (FDR), the fraction of apparent positive results likely to be false positives. In large-scale experiments in genomics and proteomics, FDR control is the usual choice.
\n*Using pooled variance estimates becomes very important in large-scale experiments like gene-expression studies on 20,000 or so genes, in which single-gene variance estimates can vary widely. The Bioconductor limma package uses an "empirical Bayes" variance estimate for each gene, which starts with individual variance estimates but then "squeezes" the estimates toward a common value. The package's author outlines that method here, with references.
A few FYI to start:
\nI had cells extracted from an organ (1 organ). Cells were separated into different wells and plates. My end goal is to check for changes in protein "X" levels using western blot.\nTwo factors are included: Control vs Treatment and Incubation Time (how long cells have been incubated with or without the treatment).
\nWells were divided as so:\n30 minutes incubation: 3 controls + 3 medications.\n1 hour: 3 controls + 3 medications.\n2 hours: 3 + 3\n3 hours: 3 + 3.
\nAll samples originate from the same organ lysate (organ was lysed and cells collected -> samples from lysate tube were plated in different wells) 6 wells (3 control + 3 treatment) were the "30m" group, 6 were "1hour" group, and so on...
\nI could extrapolate several points of data: 1) effects of treatment on protein levels (regardless of time); 2) effects of time on protein levels (Regardless of treatment) and 3) Does the effect of treatment on protein levels changes with incubation time?
\nWould really appreciate some recommendations for tests (+some theory about the test you think would fit best).
\n", "question_id": 677078, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "A few FYI to start:\n\n\n\n\n\nI am doing a research project to finish my bachelors in life sciences.\n\n\n\n\nI studied Probability for scientists (intro level).\n\n\n\n\nI didn't study statistical inference. Instead I chose Calculus 1.\nI need to statistically analyze my results but I don't know how. I also have no time to read full introductions to statistical analysis.\n\n\n\n\n\nI had cells extracted from an organ (1 organ). Cells were separated into different wells and plates. My end goal is to check for changes in protein \"X\" levels using western blot.\nTwo factors are included: Control vs Treatment and Incubation Time (how long cells have been incubated with or without the treatment).\n\n\n\n\nWells were divided as so:\n30 minutes incubation: 3 controls + 3 medications.\n1 hour: 3 controls + 3 medications.\n2 hours: 3 + 3\n3 hours: 3 + 3.\n\n\n\n\nAll samples originate from the same organ lysate (organ was lysed and cells collected -> samples from lysate tube were plated in different wells) 6 wells (3 control + 3 treatment) were the \"30m\" group, 6 were \"1hour\" group, and so on...\n\n\n\n\nI could extrapolate several points of data: 1) effects of treatment on protein levels (regardless of time); 2) effects of time on protein levels (Regardless of treatment) and 3) Does the effect of treatment on protein levels changes with incubation time?\n\n\n\n\nWould really appreciate some recommendations for tests (+some theory about the test you think would fit best).", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "user503965", "profile_url": "https://stats.stackexchange.com/users/516304/user503965", "user_type": "registered"}, "created_at": "2026-09-05T09:13:22+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "28593582-B344-42B2-A1B1-A0C00CBD588F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/28593582-B344-42B2-A1B1-A0C00CBD588F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "user503965", "profile_url": "https://stats.stackexchange.com/users/516304/user503965", "user_type": "registered"}, "created_at": "2026-09-05T09:19:27+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "691E0983-9880-4E86-92A1-95DEDF3C24AB", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/691E0983-9880-4E86-92A1-95DEDF3C24AB/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-05T17:00:39+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "BC5FAF19-81E4-4449-9AB1-A58BE937A472", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/BC5FAF19-81E4-4449-9AB1-A58BE937A472/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-05T23:14:16+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "4D24D3DB-1EB5-48B8-8CFC-DD98AA684452", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4D24D3DB-1EB5-48B8-8CFC-DD98AA684452/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677078/time-course-experiment-which-statistical-analysis-fits-best", "split": "test", "split_group": "cbb822688bb3d1bc11e31ae26d9e8a7ea2167dad6d35dc44f96db014cfd3c90f", "tags": ["inference", "experiment-design"], "thread_id": "stats:677078", "title": "Time course experiment - which statistical analysis fits best?"}} +{"accepted_answer": {"answer_html": "The suspicion expressed in the comments is well-founded: your MLE function tends to not arrive at the true MLE. Since it is performing a search, I would expect a good MLE function to use the moment estimators as the starting point. Using the function below, the behavior you observed disappears, as shown by the equivalent plots.
\nMy fit_mle function is inspired by Rfast::betabinom.mle, adapted to handle edge cases.
fit_mle <- function(x, k) {\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n\n\nFull code:
\nlibrary(MASS)\n\nz <- qnorm(0.975)\n\n## Simulate \nmu_true <- 0.5\nv_true <- 0.249\nn_vals <- c(5, 10, 15, 20, 25, 50, 100, 200, 500,1000)\nk_vals <- c(1, 2, 3, 4, 5, 6,7,8,9)\nR <- 1000\n\n\nsim_data <- function(n, k, mu, v) {\n nu <- mu * (1 - mu) / v - 1\n rbinom(n, k, rbeta(n, mu * nu, (1 - mu) * nu))\n}\n\n## MLE \nfit_mle <- function(x, k) {\n xx <<- x\n kk <<- k\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n## Moments\nfit_mom <- function(x, k) {\n p <- x / k\n c(mean(p), var(p) / length(p))\n}\n\nscore <- function(m, V, mu) {\n s <- sqrt(V); ok <- is.finite(m)\n data.frame(mean_estimate = mean(m[ok]),\n bias = mean(m[ok]) - mu,\n mc_se = sd(m[ok]) / sqrt(sum(ok)),\n sd_estimate = sd(m[ok]),\n variance_estimate = mean(V, na.rm = TRUE),\n length_of_interval = mean(2 * z * s, na.rm = TRUE),\n coverage = mean(abs(m - mu) <= z * s, na.rm = TRUE))\n}\n\nrun_cell <- function(mu, v, n, k, R, i, tot, t0) {\n cat(sprintf("[%2d/%2d] n = %3d, k = %d ... ", i, tot, n, k))\n e <- replicate(R, { x <- sim_data(n, k, mu, v)\n rbind(fit_mom(x, k), fit_mle(x, k)) })\n cat(sprintf("done (%.1fs elapsed)\\n",\n as.numeric(difftime(Sys.time(), t0, units = "secs"))))\n cbind(true_mean = mu, true_variance = v, n = n, k = k,\n true_var_of_mean = (v + (mu * (1 - mu) - v) / k) / n,\n method = c("moments", "mle"),\n rbind(score(e[1, 1, ], e[1, 2, ], mu),\n score(e[2, 1, ], e[2, 2, ], mu)))\n}\n\n#Estimation\nset.seed(1)\nt0 <- Sys.time()\ng <- expand.grid(n = n_vals, k = k_vals)\nres <- do.call(rbind, Map(run_cell, mu_true, v_true, g$n, g$k,\n MoreArgs = list(R = R), i = seq_len(nrow(g)),\n tot = nrow(g), t0 = t0))\n\nlibrary(ggplot2)\nlibrary(patchwork)\n\nres_df <- as.data.frame(res, stringsAsFactors = FALSE)\nnum_cols <- c("true_mean", "true_variance", "n", "k", "true_var_of_mean", \n "mean_estimate", "bias", "mc_se", "sd_estimate", \n "variance_estimate", "length_of_interval", "coverage")\nres_df[num_cols] <- lapply(res_df[num_cols], as.numeric)\nres_df$k_factor <- as.factor(res_df$k)\n\ndf_mom <- subset(res_df, method == "moments")\ndf_mle <- subset(res_df, method == "mle")\n\n# Helper function to generate the panels\nmake_panel <- function(data, metric_col, title, subtitle, y_label, hline = NULL) {\n p <- ggplot(data, aes(x = n, y = .data[[metric_col]], color = k_factor)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n labs(title = title, subtitle = subtitle, x = "n", y = y_label, color = "k") +\n theme_bw() +\n theme(legend.position = "bottom",\n plot.title = element_text(hjust = 0),\n plot.subtitle = element_text(hjust = 0))\n \n if (!is.null(hline)) {\n p <- p + geom_hline(yintercept = hline, linetype = "dashed", linewidth = 0.5)\n }\n return(p)\n}\n\np1 <- make_panel(df_mom, "bias", "Moments: bias of the estimated mean", \n "Average estimate minus the truth. Dashed line at 0.", "bias", 0)\np2 <- make_panel(df_mle, "bias", "MLE: bias of the estimated mean", \n "Average estimate minus the truth. Dashed line at 0.", "bias", 0)\np3 <- make_panel(df_mom, "sd_estimate", "Moments: SD of the estimated mean", \n "Spread of the estimate across studies.", "SD")\np4 <- make_panel(df_mle, "sd_estimate", "MLE: SD of the estimated mean", \n "Spread of the estimate across studies.", "SD")\n\n# Combine using patchwork\ncombined_grid <- (p1 + p2) / (p3 + p4)\nprint(combined_grid)\n\np_cov <- ggplot(res_df, aes(x = n, y = coverage, color = method)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n geom_hline(yintercept = 0.95, linetype = "dashed") +\n facet_grid(~ k, labeller = label_both) +\n labs(title = "Coverage of the nominal 95% interval",\n subtitle = "Share of 1000 intervals containing the true mean. Dashed line at 0.95.",\n x = "n",\n y = "coverage",\n color = "method") +\n theme_bw() +\n theme(legend.position = "bottom",\n strip.background = element_rect(fill = "grey90"))\n\nprint(p_cov)\n\n", "answer_id": 677117, "answer_text": "The suspicion expressed in the comments is well-founded: your MLE function tends to not arrive at the true MLE. Since it is performing a search, I would expect a good MLE function to use the moment estimators as the starting point. Using the function below, the behavior you observed disappears, as shown by the equivalent plots.\n\n\n\n\nMy fit_mle function is inspired by Rfast::betabinom.mle, adapted to handle edge cases.\n\n\n\n\nfit_mle <- function(x, k) {\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/yrEHvkk0.png] (https://i.sstatic.net/yrEHvkk0.png)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/9nEiiFBK.png] (https://i.sstatic.net/9nEiiFBK.png)\n\n\n\n\nFull code:\n\n\n\n\nlibrary(MASS)\n\nz <- qnorm(0.975)\n\n## Simulate \nmu_true <- 0.5\nv_true <- 0.249\nn_vals <- c(5, 10, 15, 20, 25, 50, 100, 200, 500,1000)\nk_vals <- c(1, 2, 3, 4, 5, 6,7,8,9)\nR <- 1000\n\n\nsim_data <- function(n, k, mu, v) {\n nu <- mu * (1 - mu) / v - 1\n rbinom(n, k, rbeta(n, mu * nu, (1 - mu) * nu))\n}\n\n## MLE \nfit_mle <- function(x, k) {\n xx <<- x\n kk <<- k\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n## Moments\nfit_mom <- function(x, k) {\n p <- x / k\n c(mean(p), var(p) / length(p))\n}\n\nscore <- function(m, V, mu) {\n s <- sqrt(V); ok <- is.finite(m)\n data.frame(mean_estimate = mean(m[ok]),\n bias = mean(m[ok]) - mu,\n mc_se = sd(m[ok]) / sqrt(sum(ok)),\n sd_estimate = sd(m[ok]),\n variance_estimate = mean(V, na.rm = TRUE),\n length_of_interval = mean(2 * z * s, na.rm = TRUE),\n coverage = mean(abs(m - mu) <= z * s, na.rm = TRUE))\n}\n\nrun_cell <- function(mu, v, n, k, R, i, tot, t0) {\n cat(sprintf(\"[%2d/%2d] n = %3d, k = %d ... \", i, tot, n, k))\n e <- replicate(R, { x <- sim_data(n, k, mu, v)\n rbind(fit_mom(x, k), fit_mle(x, k)) })\n cat(sprintf(\"done (%.1fs elapsed)\\n\",\n as.numeric(difftime(Sys.time(), t0, units = \"secs\"))))\n cbind(true_mean = mu, true_variance = v, n = n, k = k,\n true_var_of_mean = (v + (mu * (1 - mu) - v) / k) / n,\n method = c(\"moments\", \"mle\"),\n rbind(score(e[1, 1, ], e[1, 2, ], mu),\n score(e[2, 1, ], e[2, 2, ], mu)))\n}\n\n#Estimation\nset.seed(1)\nt0 <- Sys.time()\ng <- expand.grid(n = n_vals, k = k_vals)\nres <- do.call(rbind, Map(run_cell, mu_true, v_true, g$n, g$k,\n MoreArgs = list(R = R), i = seq_len(nrow(g)),\n tot = nrow(g), t0 = t0))\n\nlibrary(ggplot2)\nlibrary(patchwork)\n\nres_df <- as.data.frame(res, stringsAsFactors = FALSE)\nnum_cols <- c(\"true_mean\", \"true_variance\", \"n\", \"k\", \"true_var_of_mean\", \n \"mean_estimate\", \"bias\", \"mc_se\", \"sd_estimate\", \n \"variance_estimate\", \"length_of_interval\", \"coverage\")\nres_df[num_cols] <- lapply(res_df[num_cols], as.numeric)\nres_df$k_factor <- as.factor(res_df$k)\n\ndf_mom <- subset(res_df, method == \"moments\")\ndf_mle <- subset(res_df, method == \"mle\")\n\n# Helper function to generate the panels\nmake_panel <- function(data, metric_col, title, subtitle, y_label, hline = NULL) {\n p <- ggplot(data, aes(x = n, y = .data[[metric_col]], color = k_factor)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n labs(title = title, subtitle = subtitle, x = \"n\", y = y_label, color = \"k\") +\n theme_bw() +\n theme(legend.position = \"bottom\",\n plot.title = element_text(hjust = 0),\n plot.subtitle = element_text(hjust = 0))\n \n if (!is.null(hline)) {\n p <- p + geom_hline(yintercept = hline, linetype = \"dashed\", linewidth = 0.5)\n }\n return(p)\n}\n\np1 <- make_panel(df_mom, \"bias\", \"Moments: bias of the estimated mean\", \n \"Average estimate minus the truth. Dashed line at 0.\", \"bias\", 0)\np2 <- make_panel(df_mle, \"bias\", \"MLE: bias of the estimated mean\", \n \"Average estimate minus the truth. Dashed line at 0.\", \"bias\", 0)\np3 <- make_panel(df_mom, \"sd_estimate\", \"Moments: SD of the estimated mean\", \n \"Spread of the estimate across studies.\", \"SD\")\np4 <- make_panel(df_mle, \"sd_estimate\", \"MLE: SD of the estimated mean\", \n \"Spread of the estimate across studies.\", \"SD\")\n\n# Combine using patchwork\ncombined_grid <- (p1 + p2) / (p3 + p4)\nprint(combined_grid)\n\np_cov <- ggplot(res_df, aes(x = n, y = coverage, color = method)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n geom_hline(yintercept = 0.95, linetype = \"dashed\") +\n facet_grid(~ k, labeller = label_both) +\n labs(title = \"Coverage of the nominal 95% interval\",\n subtitle = \"Share of 1000 intervals containing the true mean. Dashed line at 0.95.\",\n x = \"n\",\n y = \"coverage\",\n color = \"method\") +\n theme_bw() +\n theme(legend.position = \"bottom\",\n strip.background = element_rect(fill = \"grey90\"))\n\nprint(p_cov)", "answer_url": "https://stats.stackexchange.com/a/677117", "author": "jblood94", "author_url": "https://stats.stackexchange.com/users/214015/jblood94", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T13:02:57+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677094, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "jblood94", "profile_url": "https://stats.stackexchange.com/users/214015/jblood94", "user_type": "registered"}, "created_at": "2026-09-09T13:02:57+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "09E52470-6B69-4568-A8B3-D52476EA341B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/09E52470-6B69-4568-A8B3-D52476EA341B/view-source"}, {"content_license": null, "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-16T13:07:32+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "20C3E36B-1564-462F-9257-5BBE5B9B70EF", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/20C3E36B-1564-462F-9257-5BBE5B9B70EF/view-source"}], "score": 3, "updated_at": "2026-09-09T13:02:57+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "Here is a beta-binomial model (treated like repeated measures - $i$ is an index for each individual, $n$ total individuals, and exactly $k$ measurements per individual):\n\n\n\n\n$$\\theta_i \\stackrel{\\text{iid}}{\\sim} \\mathrm{Beta}(a,b), \\qquad x_i \\mid \\theta_i \\sim \\mathrm{Binomial}(k,\\theta_i), \\qquad \\hat p_i = \\frac{x_i}{k}, \\qquad i = 1,\\dots,n$$\n\n\n\n\n$$\\mu = E[\\theta_i] = \\frac{a}{a+b}$$\n\n\n\n\n$$\\sigma^2 = \\operatorname{Var}(\\theta_i) = \\frac{ab}{(a+b)^2(a+b+1)}$$\n\n\n\n\n$$\\tau^2 = E[\\theta_i(1-\\theta_i)] = \\mu(1-\\mu) - \\sigma^2$$\n\n\n\n\nFor a single unit,\n\n\n\n\n$$E[\\hat p_i] = \\mu, \\qquad \\operatorname{Var}(\\hat p_i) = \\sigma^2 + \\frac{\\tau^2}{k}$$\n\n\n\n\nand\n\n\n\n\n$$\\operatorname{Var}(\\hat\\mu) = \\frac{1}{n}\\left(\\sigma^2 + \\frac{\\tau^2}{k}\\right)$$\n\n\n\n\nThere are two ways to estimate parameters I am interested in (I am interested in mean estimate and the variance of the mean estimate).\n\n\n\n\nThe first way is with moments (I can show the manipulations if needed):\n\n\n\n\n$$\\hat\\mu = \\frac{1}{n}\\sum_{i=1}^{n}\\hat p_i \\qquad \\text{estimates } \\mu$$\n\n\n\n\n$$S^2 = \\frac{1}{n-1}\\sum_{i=1}^{n}(\\hat p_i - \\hat\\mu)^2 \\qquad \\text{estimates } \\sigma^2 + \\frac{\\tau^2}{k}$$\n\n\n\n\n$$\\widehat{\\operatorname{Var}}(\\hat\\mu) = \\frac{S^2}{n} \\qquad \\text{estimates } \\operatorname{Var}(\\hat\\mu)$$\n\n\n\n\nAnd the second way is using MLE (delta method for variances and log/exp constraint for optimization).\n\n\n\n\nHere is an R script that simulates data, and compares estimates, precision and coverage for both methods. I made it so that mean and variance can be specified in the simulation (instead of a and b from the Beta distribution) at different values of $n,k$ for some fixed true mean and variance. I discard MLE fits with invalid Hessians/variance and I specifically chose the case where there is a large true variance):\n\n\n\n\nlibrary(MASS)\n\nz <- qnorm(0.975)\n\n## Simulate \nmu_true <- 0.5\nv_true <- 0.249\nn_vals <- c(5, 10, 15, 20, 25, 50, 100, 200, 500,1000)\nk_vals <- c(1, 2, 3, 4, 5, 6,7,8,9)\nR <- 1000\n\n\nsim_data <- function(n, k, mu, v) {\n nu <- mu * (1 - mu) / v - 1\n rbinom(n, k, rbeta(n, mu * nu, (1 - mu) * nu))\n}\n\n## MLE \nbb_nll <- function(q, x, k)\n length(x) * lbeta(exp(q[1]), exp(q[2])) -\n sum(lbeta(exp(q[1]) + x, exp(q[2]) + k - x))\n\nfit_mle <- function(x, k) {\n n <- length(x)\n o <- try(optim(c(0, 0), bb_nll, x = x, k = k, method = \"BFGS\",\n hessian = TRUE), silent = TRUE)\n if (inherits(o, \"try-error\")) return(c(NA, NA))\n a <- exp(o$par[1]); b <- exp(o$par[2])\n g <- a * b / (a + b)^2 * c(1, -1)\n V <- try(drop(crossprod(g, ginv(o$hessian) %*% g)), silent = TRUE)\n ok <- !inherits(V, \"try-error\") && is.finite(V) && V > 0 &&\n V < 1 / (4 * n) && rcond(o$hessian) > 1e-10\n c(a / (a + b), if (ok) V else NA)\n}\n\n## Moments\nfit_mom <- function(x, k) {\n p <- x / k\n c(mean(p), var(p) / length(p))\n}\n\nscore <- function(m, V, mu) {\n s <- sqrt(V); ok <- is.finite(m)\n data.frame(mean_estimate = mean(m[ok]),\n bias = mean(m[ok]) - mu,\n mc_se = sd(m[ok]) / sqrt(sum(ok)),\n sd_estimate = sd(m[ok]),\n variance_estimate = mean(V, na.rm = TRUE),\n length_of_interval = mean(2 * z * s, na.rm = TRUE),\n coverage = mean(abs(m - mu) <= z * s, na.rm = TRUE))\n}\n\nrun_cell <- function(mu, v, n, k, R, i, tot, t0) {\n cat(sprintf(\"[%2d/%2d] n = %3d, k = %d ... \", i, tot, n, k))\n e <- replicate(R, { x <- sim_data(n, k, mu, v)\n rbind(fit_mom(x, k), fit_mle(x, k)) })\n cat(sprintf(\"done (%.1fs elapsed)\\n\",\n as.numeric(difftime(Sys.time(), t0, units = \"secs\"))))\n cbind(true_mean = mu, true_variance = v, n = n, k = k,\n true_var_of_mean = (v + (mu * (1 - mu) - v) / k) / n,\n method = c(\"moments\", \"mle\"),\n rbind(score(e[1, 1, ], e[1, 2, ], mu),\n score(e[2, 1, ], e[2, 2, ], mu)))\n}\n\n#Estimation\nset.seed(1)\ng <- expand.grid(n = n_vals, k = k_vals)\nres <- do.call(rbind, Map(run_cell, mu_true, v_true, g$n, g$k,\n MoreArgs = list(R = R), i = seq_len(nrow(g)),\n tot = nrow(g), t0 = t0))\n\n\n\n\n\nHere are the results:\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/kEDelnub.png] (https://i.sstatic.net/kEDelnub.png)\n[image: enter image description here; source: https://i.sstatic.net/H3ywscwO.png] (https://i.sstatic.net/H3ywscwO.png)\n\n\n\n\nPrior to running this script, I would have thought that larger $n,k$ combinations would produce less bias, tighter variances and better coverage rates. But for the MLE, it looks like this is not true. And for both Moments and MLE, it seems that sometimes coverage can sometimes decrease as $n$ increases (jagged pattern).\n\n\n\n\nWhy is this happening?", "record_id": "Scientific-Statistics-QA:stats:677094", "selected_answer": {"answer_html": "The suspicion expressed in the comments is well-founded: your MLE function tends to not arrive at the true MLE. Since it is performing a search, I would expect a good MLE function to use the moment estimators as the starting point. Using the function below, the behavior you observed disappears, as shown by the equivalent plots.
\nMy fit_mle function is inspired by Rfast::betabinom.mle, adapted to handle edge cases.
fit_mle <- function(x, k) {\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n\n\nFull code:
\nlibrary(MASS)\n\nz <- qnorm(0.975)\n\n## Simulate \nmu_true <- 0.5\nv_true <- 0.249\nn_vals <- c(5, 10, 15, 20, 25, 50, 100, 200, 500,1000)\nk_vals <- c(1, 2, 3, 4, 5, 6,7,8,9)\nR <- 1000\n\n\nsim_data <- function(n, k, mu, v) {\n nu <- mu * (1 - mu) / v - 1\n rbinom(n, k, rbeta(n, mu * nu, (1 - mu) * nu))\n}\n\n## MLE \nfit_mle <- function(x, k) {\n xx <<- x\n kk <<- k\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n## Moments\nfit_mom <- function(x, k) {\n p <- x / k\n c(mean(p), var(p) / length(p))\n}\n\nscore <- function(m, V, mu) {\n s <- sqrt(V); ok <- is.finite(m)\n data.frame(mean_estimate = mean(m[ok]),\n bias = mean(m[ok]) - mu,\n mc_se = sd(m[ok]) / sqrt(sum(ok)),\n sd_estimate = sd(m[ok]),\n variance_estimate = mean(V, na.rm = TRUE),\n length_of_interval = mean(2 * z * s, na.rm = TRUE),\n coverage = mean(abs(m - mu) <= z * s, na.rm = TRUE))\n}\n\nrun_cell <- function(mu, v, n, k, R, i, tot, t0) {\n cat(sprintf("[%2d/%2d] n = %3d, k = %d ... ", i, tot, n, k))\n e <- replicate(R, { x <- sim_data(n, k, mu, v)\n rbind(fit_mom(x, k), fit_mle(x, k)) })\n cat(sprintf("done (%.1fs elapsed)\\n",\n as.numeric(difftime(Sys.time(), t0, units = "secs"))))\n cbind(true_mean = mu, true_variance = v, n = n, k = k,\n true_var_of_mean = (v + (mu * (1 - mu) - v) / k) / n,\n method = c("moments", "mle"),\n rbind(score(e[1, 1, ], e[1, 2, ], mu),\n score(e[2, 1, ], e[2, 2, ], mu)))\n}\n\n#Estimation\nset.seed(1)\nt0 <- Sys.time()\ng <- expand.grid(n = n_vals, k = k_vals)\nres <- do.call(rbind, Map(run_cell, mu_true, v_true, g$n, g$k,\n MoreArgs = list(R = R), i = seq_len(nrow(g)),\n tot = nrow(g), t0 = t0))\n\nlibrary(ggplot2)\nlibrary(patchwork)\n\nres_df <- as.data.frame(res, stringsAsFactors = FALSE)\nnum_cols <- c("true_mean", "true_variance", "n", "k", "true_var_of_mean", \n "mean_estimate", "bias", "mc_se", "sd_estimate", \n "variance_estimate", "length_of_interval", "coverage")\nres_df[num_cols] <- lapply(res_df[num_cols], as.numeric)\nres_df$k_factor <- as.factor(res_df$k)\n\ndf_mom <- subset(res_df, method == "moments")\ndf_mle <- subset(res_df, method == "mle")\n\n# Helper function to generate the panels\nmake_panel <- function(data, metric_col, title, subtitle, y_label, hline = NULL) {\n p <- ggplot(data, aes(x = n, y = .data[[metric_col]], color = k_factor)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n labs(title = title, subtitle = subtitle, x = "n", y = y_label, color = "k") +\n theme_bw() +\n theme(legend.position = "bottom",\n plot.title = element_text(hjust = 0),\n plot.subtitle = element_text(hjust = 0))\n \n if (!is.null(hline)) {\n p <- p + geom_hline(yintercept = hline, linetype = "dashed", linewidth = 0.5)\n }\n return(p)\n}\n\np1 <- make_panel(df_mom, "bias", "Moments: bias of the estimated mean", \n "Average estimate minus the truth. Dashed line at 0.", "bias", 0)\np2 <- make_panel(df_mle, "bias", "MLE: bias of the estimated mean", \n "Average estimate minus the truth. Dashed line at 0.", "bias", 0)\np3 <- make_panel(df_mom, "sd_estimate", "Moments: SD of the estimated mean", \n "Spread of the estimate across studies.", "SD")\np4 <- make_panel(df_mle, "sd_estimate", "MLE: SD of the estimated mean", \n "Spread of the estimate across studies.", "SD")\n\n# Combine using patchwork\ncombined_grid <- (p1 + p2) / (p3 + p4)\nprint(combined_grid)\n\np_cov <- ggplot(res_df, aes(x = n, y = coverage, color = method)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n geom_hline(yintercept = 0.95, linetype = "dashed") +\n facet_grid(~ k, labeller = label_both) +\n labs(title = "Coverage of the nominal 95% interval",\n subtitle = "Share of 1000 intervals containing the true mean. Dashed line at 0.95.",\n x = "n",\n y = "coverage",\n color = "method") +\n theme_bw() +\n theme(legend.position = "bottom",\n strip.background = element_rect(fill = "grey90"))\n\nprint(p_cov)\n\n", "answer_id": 677117, "answer_text": "The suspicion expressed in the comments is well-founded: your MLE function tends to not arrive at the true MLE. Since it is performing a search, I would expect a good MLE function to use the moment estimators as the starting point. Using the function below, the behavior you observed disappears, as shown by the equivalent plots.\n\n\n\n\nMy fit_mle function is inspired by Rfast::betabinom.mle, adapted to handle edge cases.\n\n\n\n\nfit_mle <- function(x, k) {\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/yrEHvkk0.png] (https://i.sstatic.net/yrEHvkk0.png)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/9nEiiFBK.png] (https://i.sstatic.net/9nEiiFBK.png)\n\n\n\n\nFull code:\n\n\n\n\nlibrary(MASS)\n\nz <- qnorm(0.975)\n\n## Simulate \nmu_true <- 0.5\nv_true <- 0.249\nn_vals <- c(5, 10, 15, 20, 25, 50, 100, 200, 500,1000)\nk_vals <- c(1, 2, 3, 4, 5, 6,7,8,9)\nR <- 1000\n\n\nsim_data <- function(n, k, mu, v) {\n nu <- mu * (1 - mu) / v - 1\n rbinom(n, k, rbeta(n, mu * nu, (1 - mu) * nu))\n}\n\n## MLE \nfit_mle <- function(x, k) {\n xx <<- x\n kk <<- k\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n## Moments\nfit_mom <- function(x, k) {\n p <- x / k\n c(mean(p), var(p) / length(p))\n}\n\nscore <- function(m, V, mu) {\n s <- sqrt(V); ok <- is.finite(m)\n data.frame(mean_estimate = mean(m[ok]),\n bias = mean(m[ok]) - mu,\n mc_se = sd(m[ok]) / sqrt(sum(ok)),\n sd_estimate = sd(m[ok]),\n variance_estimate = mean(V, na.rm = TRUE),\n length_of_interval = mean(2 * z * s, na.rm = TRUE),\n coverage = mean(abs(m - mu) <= z * s, na.rm = TRUE))\n}\n\nrun_cell <- function(mu, v, n, k, R, i, tot, t0) {\n cat(sprintf(\"[%2d/%2d] n = %3d, k = %d ... \", i, tot, n, k))\n e <- replicate(R, { x <- sim_data(n, k, mu, v)\n rbind(fit_mom(x, k), fit_mle(x, k)) })\n cat(sprintf(\"done (%.1fs elapsed)\\n\",\n as.numeric(difftime(Sys.time(), t0, units = \"secs\"))))\n cbind(true_mean = mu, true_variance = v, n = n, k = k,\n true_var_of_mean = (v + (mu * (1 - mu) - v) / k) / n,\n method = c(\"moments\", \"mle\"),\n rbind(score(e[1, 1, ], e[1, 2, ], mu),\n score(e[2, 1, ], e[2, 2, ], mu)))\n}\n\n#Estimation\nset.seed(1)\nt0 <- Sys.time()\ng <- expand.grid(n = n_vals, k = k_vals)\nres <- do.call(rbind, Map(run_cell, mu_true, v_true, g$n, g$k,\n MoreArgs = list(R = R), i = seq_len(nrow(g)),\n tot = nrow(g), t0 = t0))\n\nlibrary(ggplot2)\nlibrary(patchwork)\n\nres_df <- as.data.frame(res, stringsAsFactors = FALSE)\nnum_cols <- c(\"true_mean\", \"true_variance\", \"n\", \"k\", \"true_var_of_mean\", \n \"mean_estimate\", \"bias\", \"mc_se\", \"sd_estimate\", \n \"variance_estimate\", \"length_of_interval\", \"coverage\")\nres_df[num_cols] <- lapply(res_df[num_cols], as.numeric)\nres_df$k_factor <- as.factor(res_df$k)\n\ndf_mom <- subset(res_df, method == \"moments\")\ndf_mle <- subset(res_df, method == \"mle\")\n\n# Helper function to generate the panels\nmake_panel <- function(data, metric_col, title, subtitle, y_label, hline = NULL) {\n p <- ggplot(data, aes(x = n, y = .data[[metric_col]], color = k_factor)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n labs(title = title, subtitle = subtitle, x = \"n\", y = y_label, color = \"k\") +\n theme_bw() +\n theme(legend.position = \"bottom\",\n plot.title = element_text(hjust = 0),\n plot.subtitle = element_text(hjust = 0))\n \n if (!is.null(hline)) {\n p <- p + geom_hline(yintercept = hline, linetype = \"dashed\", linewidth = 0.5)\n }\n return(p)\n}\n\np1 <- make_panel(df_mom, \"bias\", \"Moments: bias of the estimated mean\", \n \"Average estimate minus the truth. Dashed line at 0.\", \"bias\", 0)\np2 <- make_panel(df_mle, \"bias\", \"MLE: bias of the estimated mean\", \n \"Average estimate minus the truth. Dashed line at 0.\", \"bias\", 0)\np3 <- make_panel(df_mom, \"sd_estimate\", \"Moments: SD of the estimated mean\", \n \"Spread of the estimate across studies.\", \"SD\")\np4 <- make_panel(df_mle, \"sd_estimate\", \"MLE: SD of the estimated mean\", \n \"Spread of the estimate across studies.\", \"SD\")\n\n# Combine using patchwork\ncombined_grid <- (p1 + p2) / (p3 + p4)\nprint(combined_grid)\n\np_cov <- ggplot(res_df, aes(x = n, y = coverage, color = method)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n geom_hline(yintercept = 0.95, linetype = \"dashed\") +\n facet_grid(~ k, labeller = label_both) +\n labs(title = \"Coverage of the nominal 95% interval\",\n subtitle = \"Share of 1000 intervals containing the true mean. Dashed line at 0.95.\",\n x = \"n\",\n y = \"coverage\",\n color = \"method\") +\n theme_bw() +\n theme(legend.position = \"bottom\",\n strip.background = element_rect(fill = \"grey90\"))\n\nprint(p_cov)", "answer_url": "https://stats.stackexchange.com/a/677117", "author": "jblood94", "author_url": "https://stats.stackexchange.com/users/214015/jblood94", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T13:02:57+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677094, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "jblood94", "profile_url": "https://stats.stackexchange.com/users/214015/jblood94", "user_type": "registered"}, "created_at": "2026-09-09T13:02:57+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "09E52470-6B69-4568-A8B3-D52476EA341B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/09E52470-6B69-4568-A8B3-D52476EA341B/view-source"}, {"content_license": null, "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-16T13:07:32+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "20C3E36B-1564-462F-9257-5BBE5B9B70EF", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/20C3E36B-1564-462F-9257-5BBE5B9B70EF/view-source"}], "score": 3, "updated_at": "2026-09-09T13:02:57+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "test", "thread": {"accepted_answer_id": 677117, "answers": [{"answer_html": "The suspicion expressed in the comments is well-founded: your MLE function tends to not arrive at the true MLE. Since it is performing a search, I would expect a good MLE function to use the moment estimators as the starting point. Using the function below, the behavior you observed disappears, as shown by the equivalent plots.
\nMy fit_mle function is inspired by Rfast::betabinom.mle, adapted to handle edge cases.
fit_mle <- function(x, k) {\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n\n\nFull code:
\nlibrary(MASS)\n\nz <- qnorm(0.975)\n\n## Simulate \nmu_true <- 0.5\nv_true <- 0.249\nn_vals <- c(5, 10, 15, 20, 25, 50, 100, 200, 500,1000)\nk_vals <- c(1, 2, 3, 4, 5, 6,7,8,9)\nR <- 1000\n\n\nsim_data <- function(n, k, mu, v) {\n nu <- mu * (1 - mu) / v - 1\n rbinom(n, k, rbeta(n, mu * nu, (1 - mu) * nu))\n}\n\n## MLE \nfit_mle <- function(x, k) {\n xx <<- x\n kk <<- k\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n## Moments\nfit_mom <- function(x, k) {\n p <- x / k\n c(mean(p), var(p) / length(p))\n}\n\nscore <- function(m, V, mu) {\n s <- sqrt(V); ok <- is.finite(m)\n data.frame(mean_estimate = mean(m[ok]),\n bias = mean(m[ok]) - mu,\n mc_se = sd(m[ok]) / sqrt(sum(ok)),\n sd_estimate = sd(m[ok]),\n variance_estimate = mean(V, na.rm = TRUE),\n length_of_interval = mean(2 * z * s, na.rm = TRUE),\n coverage = mean(abs(m - mu) <= z * s, na.rm = TRUE))\n}\n\nrun_cell <- function(mu, v, n, k, R, i, tot, t0) {\n cat(sprintf("[%2d/%2d] n = %3d, k = %d ... ", i, tot, n, k))\n e <- replicate(R, { x <- sim_data(n, k, mu, v)\n rbind(fit_mom(x, k), fit_mle(x, k)) })\n cat(sprintf("done (%.1fs elapsed)\\n",\n as.numeric(difftime(Sys.time(), t0, units = "secs"))))\n cbind(true_mean = mu, true_variance = v, n = n, k = k,\n true_var_of_mean = (v + (mu * (1 - mu) - v) / k) / n,\n method = c("moments", "mle"),\n rbind(score(e[1, 1, ], e[1, 2, ], mu),\n score(e[2, 1, ], e[2, 2, ], mu)))\n}\n\n#Estimation\nset.seed(1)\nt0 <- Sys.time()\ng <- expand.grid(n = n_vals, k = k_vals)\nres <- do.call(rbind, Map(run_cell, mu_true, v_true, g$n, g$k,\n MoreArgs = list(R = R), i = seq_len(nrow(g)),\n tot = nrow(g), t0 = t0))\n\nlibrary(ggplot2)\nlibrary(patchwork)\n\nres_df <- as.data.frame(res, stringsAsFactors = FALSE)\nnum_cols <- c("true_mean", "true_variance", "n", "k", "true_var_of_mean", \n "mean_estimate", "bias", "mc_se", "sd_estimate", \n "variance_estimate", "length_of_interval", "coverage")\nres_df[num_cols] <- lapply(res_df[num_cols], as.numeric)\nres_df$k_factor <- as.factor(res_df$k)\n\ndf_mom <- subset(res_df, method == "moments")\ndf_mle <- subset(res_df, method == "mle")\n\n# Helper function to generate the panels\nmake_panel <- function(data, metric_col, title, subtitle, y_label, hline = NULL) {\n p <- ggplot(data, aes(x = n, y = .data[[metric_col]], color = k_factor)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n labs(title = title, subtitle = subtitle, x = "n", y = y_label, color = "k") +\n theme_bw() +\n theme(legend.position = "bottom",\n plot.title = element_text(hjust = 0),\n plot.subtitle = element_text(hjust = 0))\n \n if (!is.null(hline)) {\n p <- p + geom_hline(yintercept = hline, linetype = "dashed", linewidth = 0.5)\n }\n return(p)\n}\n\np1 <- make_panel(df_mom, "bias", "Moments: bias of the estimated mean", \n "Average estimate minus the truth. Dashed line at 0.", "bias", 0)\np2 <- make_panel(df_mle, "bias", "MLE: bias of the estimated mean", \n "Average estimate minus the truth. Dashed line at 0.", "bias", 0)\np3 <- make_panel(df_mom, "sd_estimate", "Moments: SD of the estimated mean", \n "Spread of the estimate across studies.", "SD")\np4 <- make_panel(df_mle, "sd_estimate", "MLE: SD of the estimated mean", \n "Spread of the estimate across studies.", "SD")\n\n# Combine using patchwork\ncombined_grid <- (p1 + p2) / (p3 + p4)\nprint(combined_grid)\n\np_cov <- ggplot(res_df, aes(x = n, y = coverage, color = method)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n geom_hline(yintercept = 0.95, linetype = "dashed") +\n facet_grid(~ k, labeller = label_both) +\n labs(title = "Coverage of the nominal 95% interval",\n subtitle = "Share of 1000 intervals containing the true mean. Dashed line at 0.95.",\n x = "n",\n y = "coverage",\n color = "method") +\n theme_bw() +\n theme(legend.position = "bottom",\n strip.background = element_rect(fill = "grey90"))\n\nprint(p_cov)\n\n", "answer_id": 677117, "answer_text": "The suspicion expressed in the comments is well-founded: your MLE function tends to not arrive at the true MLE. Since it is performing a search, I would expect a good MLE function to use the moment estimators as the starting point. Using the function below, the behavior you observed disappears, as shown by the equivalent plots.\n\n\n\n\nMy fit_mle function is inspired by Rfast::betabinom.mle, adapted to handle edge cases.\n\n\n\n\nfit_mle <- function(x, k) {\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/yrEHvkk0.png] (https://i.sstatic.net/yrEHvkk0.png)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/9nEiiFBK.png] (https://i.sstatic.net/9nEiiFBK.png)\n\n\n\n\nFull code:\n\n\n\n\nlibrary(MASS)\n\nz <- qnorm(0.975)\n\n## Simulate \nmu_true <- 0.5\nv_true <- 0.249\nn_vals <- c(5, 10, 15, 20, 25, 50, 100, 200, 500,1000)\nk_vals <- c(1, 2, 3, 4, 5, 6,7,8,9)\nR <- 1000\n\n\nsim_data <- function(n, k, mu, v) {\n nu <- mu * (1 - mu) / v - 1\n rbinom(n, k, rbeta(n, mu * nu, (1 - mu) * nu))\n}\n\n## MLE \nfit_mle <- function(x, k) {\n xx <<- x\n kk <<- k\n m1 <- mean(x)\n \n if (k == 1 || all(x == 0) || all(x == k)) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n V <- NA\n } else {\n n <- length(x)\n z1 <- sort(unique(x))\n n1 <- tabulate(match(x, z1))\n z2 <- sort(unique(k - x))\n n2 <- tabulate(match(k - x, z2))\n m2 <- mean(x^2)\n d <- 1/(k*(m2/m1 - m1) - k + m1)\n a <- (k*m1 - m2)*d\n b <- (k - m1)*(k - m2/m1)*d\n \n if (!is.finite(a) || d < 0) {\n a <- max(m1*100/k, 1e-5)\n b <- max(100 - a, 1e-5)\n } else if (a <= 0 || b <= 0) {\n a <- max(m1*0.1/k, 1e-5)\n b <- max(0.1 - a, 1e-5)\n }\n \n for (i in 1:100) {\n ab <- a + b\n t1 <- digamma(ab) - digamma(k + ab)\n S1 <- a*(sum(digamma(z1 + a)*n1) + n*(t1 - digamma(a)))\n S2 <- b*(sum(digamma(z2 + b)*n2) + n*(t1 - digamma(b)))\n t2 <- trigamma(ab) - trigamma(k + ab)\n J11 <- a^2*(sum(trigamma(z1 + a)*n1) + n*(t2 - trigamma(a))) + S1\n J22 <- b^2*(sum(trigamma(z2 + b)*n2) + n*(t2 - trigamma(b))) + S2\n J12 <- a*b*t2*n\n if (abs(detJ <- J11*J22 - J12^2) < 1e-12) break\n step1 <- (J22*S1 - J12*S2)/detJ\n step2 <- (J11*S2 - J12*S1)/detJ\n if (abs(step1) + abs(step2) < 1e-8) break\n step_norm <- 2/sqrt(step1^2 + step2^2)\n \n if (step_norm < 1) {\n step1 <- step1*step_norm\n step2 <- step2*step_norm\n }\n \n a <- a*exp(-step1)\n b <- b*exp(-step2)\n }\n \n g <- a*b/(a + b)^2\n V <- -(J11 + J22 + 2*J12)*g^2/detJ\n }\n \n c(a/(a + b), if (is.finite(V) && V > 0 && V < 1 / (4 * n)) V else NA)\n}\n\n## Moments\nfit_mom <- function(x, k) {\n p <- x / k\n c(mean(p), var(p) / length(p))\n}\n\nscore <- function(m, V, mu) {\n s <- sqrt(V); ok <- is.finite(m)\n data.frame(mean_estimate = mean(m[ok]),\n bias = mean(m[ok]) - mu,\n mc_se = sd(m[ok]) / sqrt(sum(ok)),\n sd_estimate = sd(m[ok]),\n variance_estimate = mean(V, na.rm = TRUE),\n length_of_interval = mean(2 * z * s, na.rm = TRUE),\n coverage = mean(abs(m - mu) <= z * s, na.rm = TRUE))\n}\n\nrun_cell <- function(mu, v, n, k, R, i, tot, t0) {\n cat(sprintf(\"[%2d/%2d] n = %3d, k = %d ... \", i, tot, n, k))\n e <- replicate(R, { x <- sim_data(n, k, mu, v)\n rbind(fit_mom(x, k), fit_mle(x, k)) })\n cat(sprintf(\"done (%.1fs elapsed)\\n\",\n as.numeric(difftime(Sys.time(), t0, units = \"secs\"))))\n cbind(true_mean = mu, true_variance = v, n = n, k = k,\n true_var_of_mean = (v + (mu * (1 - mu) - v) / k) / n,\n method = c(\"moments\", \"mle\"),\n rbind(score(e[1, 1, ], e[1, 2, ], mu),\n score(e[2, 1, ], e[2, 2, ], mu)))\n}\n\n#Estimation\nset.seed(1)\nt0 <- Sys.time()\ng <- expand.grid(n = n_vals, k = k_vals)\nres <- do.call(rbind, Map(run_cell, mu_true, v_true, g$n, g$k,\n MoreArgs = list(R = R), i = seq_len(nrow(g)),\n tot = nrow(g), t0 = t0))\n\nlibrary(ggplot2)\nlibrary(patchwork)\n\nres_df <- as.data.frame(res, stringsAsFactors = FALSE)\nnum_cols <- c(\"true_mean\", \"true_variance\", \"n\", \"k\", \"true_var_of_mean\", \n \"mean_estimate\", \"bias\", \"mc_se\", \"sd_estimate\", \n \"variance_estimate\", \"length_of_interval\", \"coverage\")\nres_df[num_cols] <- lapply(res_df[num_cols], as.numeric)\nres_df$k_factor <- as.factor(res_df$k)\n\ndf_mom <- subset(res_df, method == \"moments\")\ndf_mle <- subset(res_df, method == \"mle\")\n\n# Helper function to generate the panels\nmake_panel <- function(data, metric_col, title, subtitle, y_label, hline = NULL) {\n p <- ggplot(data, aes(x = n, y = .data[[metric_col]], color = k_factor)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n labs(title = title, subtitle = subtitle, x = \"n\", y = y_label, color = \"k\") +\n theme_bw() +\n theme(legend.position = \"bottom\",\n plot.title = element_text(hjust = 0),\n plot.subtitle = element_text(hjust = 0))\n \n if (!is.null(hline)) {\n p <- p + geom_hline(yintercept = hline, linetype = \"dashed\", linewidth = 0.5)\n }\n return(p)\n}\n\np1 <- make_panel(df_mom, \"bias\", \"Moments: bias of the estimated mean\", \n \"Average estimate minus the truth. Dashed line at 0.\", \"bias\", 0)\np2 <- make_panel(df_mle, \"bias\", \"MLE: bias of the estimated mean\", \n \"Average estimate minus the truth. Dashed line at 0.\", \"bias\", 0)\np3 <- make_panel(df_mom, \"sd_estimate\", \"Moments: SD of the estimated mean\", \n \"Spread of the estimate across studies.\", \"SD\")\np4 <- make_panel(df_mle, \"sd_estimate\", \"MLE: SD of the estimated mean\", \n \"Spread of the estimate across studies.\", \"SD\")\n\n# Combine using patchwork\ncombined_grid <- (p1 + p2) / (p3 + p4)\nprint(combined_grid)\n\np_cov <- ggplot(res_df, aes(x = n, y = coverage, color = method)) +\n geom_line(linewidth = 0.5) +\n geom_point(size = 1.5) +\n geom_hline(yintercept = 0.95, linetype = \"dashed\") +\n facet_grid(~ k, labeller = label_both) +\n labs(title = \"Coverage of the nominal 95% interval\",\n subtitle = \"Share of 1000 intervals containing the true mean. Dashed line at 0.95.\",\n x = \"n\",\n y = \"coverage\",\n color = \"method\") +\n theme_bw() +\n theme(legend.position = \"bottom\",\n strip.background = element_rect(fill = \"grey90\"))\n\nprint(p_cov)", "answer_url": "https://stats.stackexchange.com/a/677117", "author": "jblood94", "author_url": "https://stats.stackexchange.com/users/214015/jblood94", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T13:02:57+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677094, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "jblood94", "profile_url": "https://stats.stackexchange.com/users/214015/jblood94", "user_type": "registered"}, "created_at": "2026-09-09T13:02:57+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "09E52470-6B69-4568-A8B3-D52476EA341B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/09E52470-6B69-4568-A8B3-D52476EA341B/view-source"}, {"content_license": null, "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-16T13:07:32+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "20C3E36B-1564-462F-9257-5BBE5B9B70EF", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/20C3E36B-1564-462F-9257-5BBE5B9B70EF/view-source"}], "score": 3, "updated_at": "2026-09-09T13:02:57+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/9nEiiFBK.png", "https://i.sstatic.net/H3ywscwO.png", "https://i.sstatic.net/kEDelnub.png", "https://i.sstatic.net/yrEHvkk0.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "adamkostanov", "question_author_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "question_author_user_type": "registered", "question_created_at": "2026-09-07T06:07:31+00:00", "question_html": "Here is a beta-binomial model (treated like repeated measures - $i$ is an index for each individual, $n$ total individuals, and exactly $k$ measurements per individual):
\n$$\\theta_i \\stackrel{\\text{iid}}{\\sim} \\mathrm{Beta}(a,b), \\qquad x_i \\mid \\theta_i \\sim \\mathrm{Binomial}(k,\\theta_i), \\qquad \\hat p_i = \\frac{x_i}{k}, \\qquad i = 1,\\dots,n$$
\n$$\\mu = E[\\theta_i] = \\frac{a}{a+b}$$
\n$$\\sigma^2 = \\operatorname{Var}(\\theta_i) = \\frac{ab}{(a+b)^2(a+b+1)}$$
\n$$\\tau^2 = E[\\theta_i(1-\\theta_i)] = \\mu(1-\\mu) - \\sigma^2$$
\nFor a single unit,
\n$$E[\\hat p_i] = \\mu, \\qquad \\operatorname{Var}(\\hat p_i) = \\sigma^2 + \\frac{\\tau^2}{k}$$
\nand
\n$$\\operatorname{Var}(\\hat\\mu) = \\frac{1}{n}\\left(\\sigma^2 + \\frac{\\tau^2}{k}\\right)$$
\nThere are two ways to estimate parameters I am interested in (I am interested in mean estimate and the variance of the mean estimate).
\nThe first way is with moments (I can show the manipulations if needed):
\n$$\\hat\\mu = \\frac{1}{n}\\sum_{i=1}^{n}\\hat p_i \\qquad \\text{estimates } \\mu$$
\n$$S^2 = \\frac{1}{n-1}\\sum_{i=1}^{n}(\\hat p_i - \\hat\\mu)^2 \\qquad \\text{estimates } \\sigma^2 + \\frac{\\tau^2}{k}$$
\n$$\\widehat{\\operatorname{Var}}(\\hat\\mu) = \\frac{S^2}{n} \\qquad \\text{estimates } \\operatorname{Var}(\\hat\\mu)$$
\nAnd the second way is using MLE (delta method for variances and log/exp constraint for optimization).
\nHere is an R script that simulates data, and compares estimates, precision and coverage for both methods. I made it so that mean and variance can be specified in the simulation (instead of a and b from the Beta distribution) at different values of $n,k$ for some fixed true mean and variance. I discard MLE fits with invalid Hessians/variance and I specifically chose the case where there is a large true variance):
\nlibrary(MASS)\n\nz <- qnorm(0.975)\n\n## Simulate \nmu_true <- 0.5\nv_true <- 0.249\nn_vals <- c(5, 10, 15, 20, 25, 50, 100, 200, 500,1000)\nk_vals <- c(1, 2, 3, 4, 5, 6,7,8,9)\nR <- 1000\n\n\nsim_data <- function(n, k, mu, v) {\n nu <- mu * (1 - mu) / v - 1\n rbinom(n, k, rbeta(n, mu * nu, (1 - mu) * nu))\n}\n\n## MLE \nbb_nll <- function(q, x, k)\n length(x) * lbeta(exp(q[1]), exp(q[2])) -\n sum(lbeta(exp(q[1]) + x, exp(q[2]) + k - x))\n\nfit_mle <- function(x, k) {\n n <- length(x)\n o <- try(optim(c(0, 0), bb_nll, x = x, k = k, method = "BFGS",\n hessian = TRUE), silent = TRUE)\n if (inherits(o, "try-error")) return(c(NA, NA))\n a <- exp(o$par[1]); b <- exp(o$par[2])\n g <- a * b / (a + b)^2 * c(1, -1)\n V <- try(drop(crossprod(g, ginv(o$hessian) %*% g)), silent = TRUE)\n ok <- !inherits(V, \"try-error\") && is.finite(V) && V > 0 &&\n V < 1 / (4 * n) && rcond(o$hessian) > 1e-10\n c(a / (a + b), if (ok) V else NA)\n}\n\n## Moments\nfit_mom <- function(x, k) {\n p <- x / k\n c(mean(p), var(p) / length(p))\n}\n\nscore <- function(m, V, mu) {\n s <- sqrt(V); ok <- is.finite(m)\n data.frame(mean_estimate = mean(m[ok]),\n bias = mean(m[ok]) - mu,\n mc_se = sd(m[ok]) / sqrt(sum(ok)),\n sd_estimate = sd(m[ok]),\n variance_estimate = mean(V, na.rm = TRUE),\n length_of_interval = mean(2 * z * s, na.rm = TRUE),\n coverage = mean(abs(m - mu) <= z * s, na.rm = TRUE))\n}\n\nrun_cell <- function(mu, v, n, k, R, i, tot, t0) {\n cat(sprintf("[%2d/%2d] n = %3d, k = %d ... ", i, tot, n, k))\n e <- replicate(R, { x <- sim_data(n, k, mu, v)\n rbind(fit_mom(x, k), fit_mle(x, k)) })\n cat(sprintf("done (%.1fs elapsed)\\n",\n as.numeric(difftime(Sys.time(), t0, units = "secs"))))\n cbind(true_mean = mu, true_variance = v, n = n, k = k,\n true_var_of_mean = (v + (mu * (1 - mu) - v) / k) / n,\n method = c("moments", "mle"),\n rbind(score(e[1, 1, ], e[1, 2, ], mu),\n score(e[2, 1, ], e[2, 2, ], mu)))\n}\n\n#Estimation\nset.seed(1)\ng <- expand.grid(n = n_vals, k = k_vals)\nres <- do.call(rbind, Map(run_cell, mu_true, v_true, g$n, g$k,\n MoreArgs = list(R = R), i = seq_len(nrow(g)),\n tot = nrow(g), t0 = t0))\n\nHere are the results:
\n\nPrior to running this script, I would have thought that larger $n,k$ combinations would produce less bias, tighter variances and better coverage rates. But for the MLE, it looks like this is not true. And for both Moments and MLE, it seems that sometimes coverage can sometimes decrease as $n$ increases (jagged pattern).
\nWhy is this happening?
\n", "question_id": 677094, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "Here is a beta-binomial model (treated like repeated measures - $i$ is an index for each individual, $n$ total individuals, and exactly $k$ measurements per individual):\n\n\n\n\n$$\\theta_i \\stackrel{\\text{iid}}{\\sim} \\mathrm{Beta}(a,b), \\qquad x_i \\mid \\theta_i \\sim \\mathrm{Binomial}(k,\\theta_i), \\qquad \\hat p_i = \\frac{x_i}{k}, \\qquad i = 1,\\dots,n$$\n\n\n\n\n$$\\mu = E[\\theta_i] = \\frac{a}{a+b}$$\n\n\n\n\n$$\\sigma^2 = \\operatorname{Var}(\\theta_i) = \\frac{ab}{(a+b)^2(a+b+1)}$$\n\n\n\n\n$$\\tau^2 = E[\\theta_i(1-\\theta_i)] = \\mu(1-\\mu) - \\sigma^2$$\n\n\n\n\nFor a single unit,\n\n\n\n\n$$E[\\hat p_i] = \\mu, \\qquad \\operatorname{Var}(\\hat p_i) = \\sigma^2 + \\frac{\\tau^2}{k}$$\n\n\n\n\nand\n\n\n\n\n$$\\operatorname{Var}(\\hat\\mu) = \\frac{1}{n}\\left(\\sigma^2 + \\frac{\\tau^2}{k}\\right)$$\n\n\n\n\nThere are two ways to estimate parameters I am interested in (I am interested in mean estimate and the variance of the mean estimate).\n\n\n\n\nThe first way is with moments (I can show the manipulations if needed):\n\n\n\n\n$$\\hat\\mu = \\frac{1}{n}\\sum_{i=1}^{n}\\hat p_i \\qquad \\text{estimates } \\mu$$\n\n\n\n\n$$S^2 = \\frac{1}{n-1}\\sum_{i=1}^{n}(\\hat p_i - \\hat\\mu)^2 \\qquad \\text{estimates } \\sigma^2 + \\frac{\\tau^2}{k}$$\n\n\n\n\n$$\\widehat{\\operatorname{Var}}(\\hat\\mu) = \\frac{S^2}{n} \\qquad \\text{estimates } \\operatorname{Var}(\\hat\\mu)$$\n\n\n\n\nAnd the second way is using MLE (delta method for variances and log/exp constraint for optimization).\n\n\n\n\nHere is an R script that simulates data, and compares estimates, precision and coverage for both methods. I made it so that mean and variance can be specified in the simulation (instead of a and b from the Beta distribution) at different values of $n,k$ for some fixed true mean and variance. I discard MLE fits with invalid Hessians/variance and I specifically chose the case where there is a large true variance):\n\n\n\n\nlibrary(MASS)\n\nz <- qnorm(0.975)\n\n## Simulate \nmu_true <- 0.5\nv_true <- 0.249\nn_vals <- c(5, 10, 15, 20, 25, 50, 100, 200, 500,1000)\nk_vals <- c(1, 2, 3, 4, 5, 6,7,8,9)\nR <- 1000\n\n\nsim_data <- function(n, k, mu, v) {\n nu <- mu * (1 - mu) / v - 1\n rbinom(n, k, rbeta(n, mu * nu, (1 - mu) * nu))\n}\n\n## MLE \nbb_nll <- function(q, x, k)\n length(x) * lbeta(exp(q[1]), exp(q[2])) -\n sum(lbeta(exp(q[1]) + x, exp(q[2]) + k - x))\n\nfit_mle <- function(x, k) {\n n <- length(x)\n o <- try(optim(c(0, 0), bb_nll, x = x, k = k, method = \"BFGS\",\n hessian = TRUE), silent = TRUE)\n if (inherits(o, \"try-error\")) return(c(NA, NA))\n a <- exp(o$par[1]); b <- exp(o$par[2])\n g <- a * b / (a + b)^2 * c(1, -1)\n V <- try(drop(crossprod(g, ginv(o$hessian) %*% g)), silent = TRUE)\n ok <- !inherits(V, \"try-error\") && is.finite(V) && V > 0 &&\n V < 1 / (4 * n) && rcond(o$hessian) > 1e-10\n c(a / (a + b), if (ok) V else NA)\n}\n\n## Moments\nfit_mom <- function(x, k) {\n p <- x / k\n c(mean(p), var(p) / length(p))\n}\n\nscore <- function(m, V, mu) {\n s <- sqrt(V); ok <- is.finite(m)\n data.frame(mean_estimate = mean(m[ok]),\n bias = mean(m[ok]) - mu,\n mc_se = sd(m[ok]) / sqrt(sum(ok)),\n sd_estimate = sd(m[ok]),\n variance_estimate = mean(V, na.rm = TRUE),\n length_of_interval = mean(2 * z * s, na.rm = TRUE),\n coverage = mean(abs(m - mu) <= z * s, na.rm = TRUE))\n}\n\nrun_cell <- function(mu, v, n, k, R, i, tot, t0) {\n cat(sprintf(\"[%2d/%2d] n = %3d, k = %d ... \", i, tot, n, k))\n e <- replicate(R, { x <- sim_data(n, k, mu, v)\n rbind(fit_mom(x, k), fit_mle(x, k)) })\n cat(sprintf(\"done (%.1fs elapsed)\\n\",\n as.numeric(difftime(Sys.time(), t0, units = \"secs\"))))\n cbind(true_mean = mu, true_variance = v, n = n, k = k,\n true_var_of_mean = (v + (mu * (1 - mu) - v) / k) / n,\n method = c(\"moments\", \"mle\"),\n rbind(score(e[1, 1, ], e[1, 2, ], mu),\n score(e[2, 1, ], e[2, 2, ], mu)))\n}\n\n#Estimation\nset.seed(1)\ng <- expand.grid(n = n_vals, k = k_vals)\nres <- do.call(rbind, Map(run_cell, mu_true, v_true, g$n, g$k,\n MoreArgs = list(R = R), i = seq_len(nrow(g)),\n tot = nrow(g), t0 = t0))\n\n\n\n\n\nHere are the results:\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/kEDelnub.png] (https://i.sstatic.net/kEDelnub.png)\n[image: enter image description here; source: https://i.sstatic.net/H3ywscwO.png] (https://i.sstatic.net/H3ywscwO.png)\n\n\n\n\nPrior to running this script, I would have thought that larger $n,k$ combinations would produce less bias, tighter variances and better coverage rates. But for the MLE, it looks like this is not true. And for both Moments and MLE, it seems that sometimes coverage can sometimes decrease as $n$ increases (jagged pattern).\n\n\n\n\nWhy is this happening?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-07T06:07:31+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "BE06C153-8C52-4CC0-883B-294D30B035A1", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/BE06C153-8C52-4CC0-883B-294D30B035A1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-07T06:17:50+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "E476317C-DD27-4C9B-AE2F-6BCDF9875E56", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E476317C-DD27-4C9B-AE2F-6BCDF9875E56/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-07T06:25:11+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "30B3CCCA-ABFC-44BA-A8AA-62F762C98FC8", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/30B3CCCA-ABFC-44BA-A8AA-62F762C98FC8/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-07T06:33:19+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "2E412836-177B-410E-B0A8-2FD925F88199", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2E412836-177B-410E-B0A8-2FD925F88199/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-07T06:41:52+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "246BB9D4-0913-4A5D-BA26-19A883E71D2E", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/246BB9D4-0913-4A5D-BA26-19A883E71D2E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-07T08:45:32+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "06091D8C-4AF4-44C7-A257-DDB59EE43D39", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/06091D8C-4AF4-44C7-A257-DDB59EE43D39/view-source"}, {"content_license": null, "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-09T06:13:57+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "4B6B337A-AB66-48A4-9852-835642560D4F", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4B6B337A-AB66-48A4-9852-835642560D4F/view-source"}, {"content_license": null, "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-09T06:13:57+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "FF6141BB-F0C5-4F25-80CC-121B75A68FE8", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/FF6141BB-F0C5-4F25-80CC-121B75A68FE8/view-source"}, {"content_license": null, "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-16T13:07:32+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "398480DB-D18F-4C34-B57A-2901985CD8FF", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/398480DB-D18F-4C34-B57A-2901985CD8FF/view-source"}, {"content_license": null, "contributor": {"display_name": "adamkostanov", "profile_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "user_type": "registered"}, "created_at": "2026-09-16T13:07:32+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "E442CC1D-1B8D-4B82-A247-1B52D8C54699", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/E442CC1D-1B8D-4B82-A247-1B52D8C54699/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677094/can-coverage-probability-decrease-as-sample-size-increases", "split": "test", "split_group": "9708b014da60835c67095344e417c92716420d5056f8162fcbb5adcca7853c04", "tags": ["r", "maximum-likelihood"], "thread_id": "stats:677094", "title": "Can coverage probability decrease as sample size increases?"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "You can take a sample to get a decent estimate.
\n", "answer_id": 677259, "answer_text": "You can take a sample to get a decent estimate.", "answer_url": "https://stats.stackexchange.com/a/677259", "author": "Yossi Levy", "author_url": "https://stats.stackexchange.com/users/183735/yossi-levy", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-25T07:06:59+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:08.569053+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/ba8a114171cbec551f0a7f4b9f04e95c559131a62357d51e159434d4acc7183d_1790825228829630100_0.json", "raw_sha256": "a03822ca860dd0b0fb0cc402754ae4cdbaad51d18873dfd19aed56ffe1cf7ec8", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=2&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677201, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Yossi Levy", "profile_url": "https://stats.stackexchange.com/users/183735/yossi-levy", "user_type": "registered"}, "created_at": "2026-09-25T07:06:59+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "BC514043-68C0-45FC-8E73-43A04AE28F35", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/BC514043-68C0-45FC-8E73-43A04AE28F35/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-25T13:33:38+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "F88E62B3-141E-44BE-B4C2-8A7F08D22261", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/F88E62B3-141E-44BE-B4C2-8A7F08D22261/view-source"}], "score": 0, "updated_at": "2026-09-25T07:06:59+00:00"}], "product": "statistics_qa", "question": "I've a database that stores multiple values of performance stats for thousands and millions of players in a certain game, over 10s of millions of matches, the game follows a system of episodes/acts, and players have ranks.\n\n\n\n\nI want to be able to answer questions like for a certain stat of the player in a match, how does it compare to others of the same rank (or in general sometimes) in the same episode/act, and sometimes I want to compare the average of said stat over the player's entire matches, to the averages of others over their entire matches, and so on.\n\n\n\n\nfor that one of the best ways to present it is percentile, for example let's say we have a stat called damage per round, saying top 1% percentile would give the player a clear indicator that their damage per round is top notch, and so on.\n\n\n\n\nThe problem is that I don't know of a cheap way to calculate that, since I'm not good at mathematics, but I'd imagine that maybe there's a way while importing players' matches into our database, to some what calculate & update some statistical data that could answer that cheaply? instead of having to go over a lot of player's data to answer that? I imagine if the stats follow a normal distribution it might be easy, but what if it doesn't for one reason or another, and how do I even verify if it does? and is there a way to incrementally calculate/update them incrementally\n\n\n\n\nps: sorry if the phrasing of the question is messed up, Idk how else to phrase it", "record_id": "Scientific-Statistics-QA:stats:677201", "selected_answer": {"answer_html": "Depending on how accurate you want the result to be. At least there are two straight approaches. Both the following are per stat incremental over all samples - say, damage as you mentioned.
\nThis is the simplest and most straightforward way: store all values, sort them once, and then percentile retrieval is essentially an array-index lookup. For $N$ values, storage is $O(N)$, building time is $O(N \\log N)$ because of sorting, and percentile retrieval is $O(1)$ if you use the sorted array directly. The important downside is that when new values are continuously added, you need to re-sort periodically ($O(N \\log N)$), or to maintain an ordered data structure (binary search tree), which makes each insertion roughly $O(\\log N)$.
\nA histogram avoids storing every individual value: divide the possible value range into $B$ bins and only store the count in each bin. Storage is $O(B)$, building/updating time is $O(N)$ for $N$ incoming values (actually $O(1)$ per value), and percentile retrieval is $O(B)$ with a simple cumulative scan, or $O(\\log B)$ if you maintain cumulative counts appropriately (e.g., a fixed binary search tree). The tradeoff is that the result is approximate, and accuracy depends on how the bins are chosen. But here you are not assuming a normal distribution; the histogram approach makes no distribution shape assumption. It's a non-parametric approach.
\n", "answer_id": 677203, "answer_text": "Depending on how accurate you want the result to be. At least there are two straight approaches. Both the following are per stat incremental over all samples - say, damage as you mentioned.\n\n\n\n\n\nExact sort\n\n\n\n\n\nThis is the simplest and most straightforward way: store all values, sort them once, and then percentile retrieval is essentially an array-index lookup. For $N$ values, storage is $O(N)$, building time is $O(N \\log N)$ because of sorting, and percentile retrieval is $O(1)$ if you use the sorted array directly. The important downside is that when new values are continuously added, you need to re-sort periodically ($O(N \\log N)$), or to maintain an ordered data structure (binary search tree), which makes each insertion roughly $O(\\log N)$.\n\n\n\n\n\nHistogram\n\n\n\n\n\nA histogram avoids storing every individual value: divide the possible value range into $B$ bins and only store the count in each bin. Storage is $O(B)$, building/updating time is $O(N)$ for $N$ incoming values (actually $O(1)$ per value), and percentile retrieval is $O(B)$ with a simple cumulative scan, or $O(\\log B)$ if you maintain cumulative counts appropriately (e.g., a fixed binary search tree). The tradeoff is that the result is approximate, and accuracy depends on how the bins are chosen. But here you are not assuming a normal distribution; the histogram approach makes no distribution shape assumption. It's a non-parametric approach.", "answer_url": "https://stats.stackexchange.com/a/677203", "author": "J. Doe", "author_url": "https://stats.stackexchange.com/users/289647/j-doe", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-18T04:59:04+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:08.569053+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/ba8a114171cbec551f0a7f4b9f04e95c559131a62357d51e159434d4acc7183d_1790825228829630100_0.json", "raw_sha256": "a03822ca860dd0b0fb0cc402754ae4cdbaad51d18873dfd19aed56ffe1cf7ec8", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=2&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677201, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J. Doe", "profile_url": "https://stats.stackexchange.com/users/289647/j-doe", "user_type": "registered"}, "created_at": "2026-09-18T04:59:04+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "6D94553A-9020-42A1-B486-1E43A3AE556B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6D94553A-9020-42A1-B486-1E43A3AE556B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J. Doe", "profile_url": "https://stats.stackexchange.com/users/289647/j-doe", "user_type": "registered"}, "created_at": "2026-09-18T05:04:10+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "420CE9DF-3FEB-4529-BED4-B15BFCCC362F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/420CE9DF-3FEB-4529-BED4-B15BFCCC362F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-25T07:21:46+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "DE49DAB7-B2D2-4D9B-B972-BF216D135688", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DE49DAB7-B2D2-4D9B-B972-BF216D135688/view-source"}], "score": 4, "updated_at": "2026-09-25T07:21:46+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "test", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Depending on how accurate you want the result to be. At least there are two straight approaches. Both the following are per stat incremental over all samples - say, damage as you mentioned.
\nThis is the simplest and most straightforward way: store all values, sort them once, and then percentile retrieval is essentially an array-index lookup. For $N$ values, storage is $O(N)$, building time is $O(N \\log N)$ because of sorting, and percentile retrieval is $O(1)$ if you use the sorted array directly. The important downside is that when new values are continuously added, you need to re-sort periodically ($O(N \\log N)$), or to maintain an ordered data structure (binary search tree), which makes each insertion roughly $O(\\log N)$.
\nA histogram avoids storing every individual value: divide the possible value range into $B$ bins and only store the count in each bin. Storage is $O(B)$, building/updating time is $O(N)$ for $N$ incoming values (actually $O(1)$ per value), and percentile retrieval is $O(B)$ with a simple cumulative scan, or $O(\\log B)$ if you maintain cumulative counts appropriately (e.g., a fixed binary search tree). The tradeoff is that the result is approximate, and accuracy depends on how the bins are chosen. But here you are not assuming a normal distribution; the histogram approach makes no distribution shape assumption. It's a non-parametric approach.
\n", "answer_id": 677203, "answer_text": "Depending on how accurate you want the result to be. At least there are two straight approaches. Both the following are per stat incremental over all samples - say, damage as you mentioned.\n\n\n\n\n\nExact sort\n\n\n\n\n\nThis is the simplest and most straightforward way: store all values, sort them once, and then percentile retrieval is essentially an array-index lookup. For $N$ values, storage is $O(N)$, building time is $O(N \\log N)$ because of sorting, and percentile retrieval is $O(1)$ if you use the sorted array directly. The important downside is that when new values are continuously added, you need to re-sort periodically ($O(N \\log N)$), or to maintain an ordered data structure (binary search tree), which makes each insertion roughly $O(\\log N)$.\n\n\n\n\n\nHistogram\n\n\n\n\n\nA histogram avoids storing every individual value: divide the possible value range into $B$ bins and only store the count in each bin. Storage is $O(B)$, building/updating time is $O(N)$ for $N$ incoming values (actually $O(1)$ per value), and percentile retrieval is $O(B)$ with a simple cumulative scan, or $O(\\log B)$ if you maintain cumulative counts appropriately (e.g., a fixed binary search tree). The tradeoff is that the result is approximate, and accuracy depends on how the bins are chosen. But here you are not assuming a normal distribution; the histogram approach makes no distribution shape assumption. It's a non-parametric approach.", "answer_url": "https://stats.stackexchange.com/a/677203", "author": "J. Doe", "author_url": "https://stats.stackexchange.com/users/289647/j-doe", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-18T04:59:04+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:08.569053+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/ba8a114171cbec551f0a7f4b9f04e95c559131a62357d51e159434d4acc7183d_1790825228829630100_0.json", "raw_sha256": "a03822ca860dd0b0fb0cc402754ae4cdbaad51d18873dfd19aed56ffe1cf7ec8", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=2&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677201, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J. Doe", "profile_url": "https://stats.stackexchange.com/users/289647/j-doe", "user_type": "registered"}, "created_at": "2026-09-18T04:59:04+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "6D94553A-9020-42A1-B486-1E43A3AE556B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6D94553A-9020-42A1-B486-1E43A3AE556B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J. Doe", "profile_url": "https://stats.stackexchange.com/users/289647/j-doe", "user_type": "registered"}, "created_at": "2026-09-18T05:04:10+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "420CE9DF-3FEB-4529-BED4-B15BFCCC362F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/420CE9DF-3FEB-4529-BED4-B15BFCCC362F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-25T07:21:46+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "DE49DAB7-B2D2-4D9B-B972-BF216D135688", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DE49DAB7-B2D2-4D9B-B972-BF216D135688/view-source"}], "score": 4, "updated_at": "2026-09-25T07:21:46+00:00"}, {"answer_html": "You can take a sample to get a decent estimate.
\n", "answer_id": 677259, "answer_text": "You can take a sample to get a decent estimate.", "answer_url": "https://stats.stackexchange.com/a/677259", "author": "Yossi Levy", "author_url": "https://stats.stackexchange.com/users/183735/yossi-levy", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-25T07:06:59+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:08.569053+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/ba8a114171cbec551f0a7f4b9f04e95c559131a62357d51e159434d4acc7183d_1790825228829630100_0.json", "raw_sha256": "a03822ca860dd0b0fb0cc402754ae4cdbaad51d18873dfd19aed56ffe1cf7ec8", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=2&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677201, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Yossi Levy", "profile_url": "https://stats.stackexchange.com/users/183735/yossi-levy", "user_type": "registered"}, "created_at": "2026-09-25T07:06:59+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "BC514043-68C0-45FC-8E73-43A04AE28F35", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/BC514043-68C0-45FC-8E73-43A04AE28F35/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-25T13:33:38+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "F88E62B3-141E-44BE-B4C2-8A7F08D22261", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/F88E62B3-141E-44BE-B4C2-8A7F08D22261/view-source"}], "score": 0, "updated_at": "2026-09-25T07:06:59+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "HauntedMansion", "question_author_url": "https://stats.stackexchange.com/users/516799/hauntedmansion", "question_author_user_type": "unregistered", "question_created_at": "2026-09-18T02:53:20+00:00", "question_html": "I've a database that stores multiple values of performance stats for thousands and millions of players in a certain game, over 10s of millions of matches, the game follows a system of episodes/acts, and players have ranks.
\nI want to be able to answer questions like for a certain stat of the player in a match, how does it compare to others of the same rank (or in general sometimes) in the same episode/act, and sometimes I want to compare the average of said stat over the player's entire matches, to the averages of others over their entire matches, and so on.
\nfor that one of the best ways to present it is percentile, for example let's say we have a stat called damage per round, saying top 1% percentile would give the player a clear indicator that their damage per round is top notch, and so on.
\nThe problem is that I don't know of a cheap way to calculate that, since I'm not good at mathematics, but I'd imagine that maybe there's a way while importing players' matches into our database, to some what calculate & update some statistical data that could answer that cheaply? instead of having to go over a lot of player's data to answer that? I imagine if the stats follow a normal distribution it might be easy, but what if it doesn't for one reason or another, and how do I even verify if it does? and is there a way to incrementally calculate/update them incrementally
\nps: sorry if the phrasing of the question is messed up, Idk how else to phrase it
\n", "question_id": 677201, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I've a database that stores multiple values of performance stats for thousands and millions of players in a certain game, over 10s of millions of matches, the game follows a system of episodes/acts, and players have ranks.\n\n\n\n\nI want to be able to answer questions like for a certain stat of the player in a match, how does it compare to others of the same rank (or in general sometimes) in the same episode/act, and sometimes I want to compare the average of said stat over the player's entire matches, to the averages of others over their entire matches, and so on.\n\n\n\n\nfor that one of the best ways to present it is percentile, for example let's say we have a stat called damage per round, saying top 1% percentile would give the player a clear indicator that their damage per round is top notch, and so on.\n\n\n\n\nThe problem is that I don't know of a cheap way to calculate that, since I'm not good at mathematics, but I'd imagine that maybe there's a way while importing players' matches into our database, to some what calculate & update some statistical data that could answer that cheaply? instead of having to go over a lot of player's data to answer that? I imagine if the stats follow a normal distribution it might be easy, but what if it doesn't for one reason or another, and how do I even verify if it does? and is there a way to incrementally calculate/update them incrementally\n\n\n\n\nps: sorry if the phrasing of the question is messed up, Idk how else to phrase it", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "HauntedMansion", "profile_url": "https://stats.stackexchange.com/users/516799/hauntedmansion", "user_type": "unregistered"}, "created_at": "2026-09-18T02:53:20+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "0BFF647A-80FA-4820-B7A7-E1A9456A7D2B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0BFF647A-80FA-4820-B7A7-E1A9456A7D2B/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-18T10:54:55+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "87F84BB2-7808-4DE2-B278-EADB7B565808", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/87F84BB2-7808-4DE2-B278-EADB7B565808/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677201/is-there-a-way-to-calculate-the-percentiles-cheaply-without-enumeratine-values-o", "split": "test", "split_group": "8c3c53e9665c565323785a03f1fb4ba9ffaf6c9ecb63d8cea543d3897fd51d0a", "tags": ["distributions", "normal-distribution", "standard-deviation", "percentage"], "thread_id": "stats:677201", "title": "is there a way to calculate the percentiles cheaply without enumeratine values of the entire population (check body for details)"}}