{"citation_context": "t be non-negative and integrate to infinity in the limit of infinite time. See the Wikipedia entry (https://en.wikipedia.org/wiki/Survival_analysis#Hazard_function_and_cumulative_hazard_function). What you propose is thus possible, in principle.\n\n\n\n\nThe difficulty is that you would no longer h", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Survival_analysis#Hazard_function_and_cumulative_hazard_function", "kind": "external_url", "post_id": 676869, "post_url": "https://stats.stackexchange.com/a/676869", "product": "citations", "record_id": "Scientific-Citation-Graph:5b8fc369657ee86c5bdc9119", "split": "validation", "thread": {"accepted_answer_id": 676869, "answers": [{"answer_html": "
The only requirement for a hazard as a function of time is that it be non-negative and integrate to infinity in the limit of infinite time. See the Wikipedia entry. What you propose is thus possible, in principle.
\nThe difficulty is that you would no longer have a proportional hazards model. Consider the hazard ratio for individuals $i$ and $j$ at time $t$ in your additive proposal:
\n$$\\frac{h_i}{h_j}=\\frac{\\lambda_1\\gamma_1 t^{\\gamma_1-1} + \\lambda_2\\gamma_2\\, U_i(t)^{\\gamma_2-1}}{\\lambda_1\\gamma_1 t^{\\gamma_1-1} + \\lambda_2\\gamma_2\\, U_j(t)^{\\gamma_2-1}}. $$
\nCompare that to a model with multiplicative hazards:
\n$$\\frac{h_i}{h_j}=\\frac{\\lambda_1\\gamma_1 t^{\\gamma_1-1} \\lambda_2\\gamma_2\\, U_i(t)^{\\gamma_2-1}} {\\lambda_1\\gamma_1 t^{\\gamma_1-1}\\lambda_2\\gamma_2\\, U_j(t)^{\\gamma_2-1}}=\\frac{U_i(t)^{\\gamma_2-1}}{U_j(t)^{\\gamma_2-1}}. $$
\nUnlike your additive suggestion, with the multiplicative hazards the hazard ratio between individuals $i$ and $j$ is constant over time, given their values of $U(t)$.
\nA proportional hazards model has a particular advantage in that it only depends on the covariate values in place at event times. Other types of models, like accelerated-failure-time models other than Weibull, depend on the entire history of time-varying covariate values like $U(t)$. That's one reason for favoring multiplicative hazards.
\n", "answer_id": 676869, "answer_text": "The only requirement for a hazard as a function of time is that it be non-negative and integrate to infinity in the limit of infinite time. See the Wikipedia entry (https://en.wikipedia.org/wiki/Survival_analysis#Hazard_function_and_cumulative_hazard_function). What you propose is thus possible, in principle.\n\n\n\n\nThe difficulty is that you would no longer have a proportional hazards model. Consider the hazard ratio for individuals $i$ and $j$ at time $t$ in your additive proposal:\n\n\n\n\n$$\\frac{h_i}{h_j}=\\frac{\\lambda_1\\gamma_1 t^{\\gamma_1-1} + \\lambda_2\\gamma_2\\, U_i(t)^{\\gamma_2-1}}{\\lambda_1\\gamma_1 t^{\\gamma_1-1} + \\lambda_2\\gamma_2\\, U_j(t)^{\\gamma_2-1}}. $$\n\n\n\n\nCompare that to a model with multiplicative hazards:\n\n\n\n\n$$\\frac{h_i}{h_j}=\\frac{\\lambda_1\\gamma_1 t^{\\gamma_1-1} \\lambda_2\\gamma_2\\, U_i(t)^{\\gamma_2-1}} {\\lambda_1\\gamma_1 t^{\\gamma_1-1}\\lambda_2\\gamma_2\\, U_j(t)^{\\gamma_2-1}}=\\frac{U_i(t)^{\\gamma_2-1}}{U_j(t)^{\\gamma_2-1}}. $$\n\n\n\n\nUnlike your additive suggestion, with the multiplicative hazards the hazard ratio between individuals $i$ and $j$ is constant over time, given their values of $U(t)$.\n\n\n\n\nA proportional hazards model has a particular advantage in that it only depends on the covariate values in place at event times. Other types of models, like accelerated-failure-time models other than Weibull, depend on the entire history of time-varying covariate values like $U(t)$. That's one reason for favoring multiplicative hazards.", "answer_url": "https://stats.stackexchange.com/a/676869", "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-14T15:23:45+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": 676850, "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-14T15:23:45+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "3D1D9A3E-6087-4625-BCEE-EC8203D245D9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3D1D9A3E-6087-4625-BCEE-EC8203D245D9/view-source"}], "score": 4, "updated_at": "2026-08-14T15:23:45+00:00"}], "domain": "statistics", "external_links": ["https://en.wikipedia.org/wiki/Survival_analysis#Hazard_function_and_cumulative_hazard_function"], "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-08-12T05:22:15+00:00", "question_html": "An object is manufactured on some date. There are two things which contribute to the risk of failure: time passed since the date of manufacture and the amount of cumulative usage.
\nAssuming there is data on multiple objects at different time points, a parametric PH model can be used ($t$ = time since manufacture, $U(t)$ = cumulative usage up to time $t$):
\n$$h(t \\mid U) = \\lambda \\gamma t^{\\gamma-1}\\,\\exp\\!\\big(\\beta_1 U(t)\\big)$$
\nIs it possible to define a model where two hazard functions are added for the hazard from time and hazard from cumulative usage?
\n$$h(t) = \\lambda_1\\gamma_1 t^{\\gamma_1-1} + \\lambda_2\\gamma_2\\, U(t)^{\\gamma_2-1}$$
\nTypically, I have seen additive hazard models that are additive in terms of covariates (Aalen additive hazards model):
\n$$\\lambda(t \\mid X) = \\beta_0(t) + \\beta_1(t) X_1 + \\beta_2(t) X_2 + \\cdots + \\beta_p(t) X_p$$
\nBut is it possible to have a model that is additive in the hazard contributions of two time scales?
\n$$h(t) = \\lambda_1\\gamma_1 t^{\\gamma_1-1} + \\lambda_2\\gamma_2\\, U(t)^{\\gamma_2-1}$$
\n", "question_id": 676850, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "An object is manufactured on some date. There are two things which contribute to the risk of failure: time passed since the date of manufacture and the amount of cumulative usage.\n\n\n\n\nAssuming there is data on multiple objects at different time points, a parametric PH model can be used ($t$ = time since manufacture, $U(t)$ = cumulative usage up to time $t$):\n\n\n\n\n$$h(t \\mid U) = \\lambda \\gamma t^{\\gamma-1}\\,\\exp\\!\\big(\\beta_1 U(t)\\big)$$\n\n\n\n\nIs it possible to define a model where two hazard functions are added for the hazard from time and hazard from cumulative usage?\n\n\n\n\n$$h(t) = \\lambda_1\\gamma_1 t^{\\gamma_1-1} + \\lambda_2\\gamma_2\\, U(t)^{\\gamma_2-1}$$\n\n\n\n\nTypically, I have seen additive hazard models that are additive in terms of covariates (Aalen additive hazards model):\n\n\n\n\n$$\\lambda(t \\mid X) = \\beta_0(t) + \\beta_1(t) X_1 + \\beta_2(t) X_2 + \\cdots + \\beta_p(t) X_p$$\n\n\n\n\nBut is it possible to have a model that is additive in the hazard contributions of two time scales?\n\n\n\n\n$$h(t) = \\lambda_1\\gamma_1 t^{\\gamma_1-1} + \\lambda_2\\gamma_2\\, U(t)^{\\gamma_2-1}$$", "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-08-12T05:22:15+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "D26D0E7A-7AF6-4114-984B-40639054B7E2", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D26D0E7A-7AF6-4114-984B-40639054B7E2/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676850/how-to-let-different-factors-influence-survival-hazard-within-a-model", "split": "validation", "split_group": "a5373623168c1c550833ba1b84284085b1884c554ada82546c601a9dd3638f4b", "tags": ["survival"], "thread_id": "stats:676850", "title": "How to let different factors influence survival hazard within a model?"}} {"citation_context": "oth the above references have links to implementations in R. For example, the R elasticnet package (https://cran.r-project.org/package=elasticnet) has one implementation in its spca() function.", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://cran.r-project.org/package=elasticnet", "kind": "external_url", "post_id": 676880, "post_url": "https://stats.stackexchange.com/a/676880", "product": "citations", "record_id": "Scientific-Citation-Graph:b61b2b6622d74ab042f73e1c", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Performing LASSO on standard principal components or following LASSO with PCA might still end up with all retained predictors contributing to each component.
\nAn alternative is sparse principal component analysis (SPCA). It uses a LASSO-type penalty to cut down on the number of original variables contributing to each component. Quoting:
\n\n\nA particular disadvantage of ordinary PCA is that the principal components are usually linear combinations of all input variables. SPCA overcomes this disadvantage by finding components that are linear combinations of just a few input variables (SPCs).
\n
Frank Harrell recommends it as one way to perform "data reduction" on predictors without using the outcome. See Section 8.6.1 of his Regression Modeling Strategies. Both the above references have links to implementations in R. For example, the R elasticnet package has one implementation in its spca() function.
EdM’s answer is very good but a couple of additional points:
\nI understand that PCA is for eliminating collinearity and reducing dimensions while the other is used for feature selection. I was wondering if there is any way to use these two methods together for an example if you wanted do feature selection but also wanted to get rid of collinearity which elastic net/lasso does poorly.
\nIn what cases would you use these two methods together and what cases would you use them separately? What is the general standard of practice is it to do it together or separate?
\n", "question_id": 676873, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "I understand that PCA is for eliminating collinearity and reducing dimensions while the other is used for feature selection. I was wondering if there is any way to use these two methods together for an example if you wanted do feature selection but also wanted to get rid of collinearity which elastic net/lasso does poorly.\n\n\n\n\nIn what cases would you use these two methods together and what cases would you use them separately? What is the general standard of practice is it to do it together or separate?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Karl Suh", "profile_url": "https://stats.stackexchange.com/users/513622/karl-suh", "user_type": "registered"}, "created_at": "2026-08-15T03:42:38+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "C888628D-3C97-4B17-86E4-AF7475A3C710", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C888628D-3C97-4B17-86E4-AF7475A3C710/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-15T13:55:27+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "1513EDD5-94FC-4B55-A64B-81770DFE0CB8", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/1513EDD5-94FC-4B55-A64B-81770DFE0CB8/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676873/can-you-use-pca-and-elastic-net-lasso-together-or-do-you-have-to-use-one-or-the", "split": "validation", "split_group": "b0befa11d334e3ea0cb0f6c32cda5c87da78493a28ed637e497c3e4ae2e250e6", "tags": ["pca", "lasso", "elastic-net"], "thread_id": "stats:676873", "title": "Can you use PCA and Elastic Net/Lasso together or do you have to use one or the other? Are there any use cases for using these two methods together?"}} {"citation_context": "edictors contributing to each component.\n\n\n\n\nAn alternative is sparse principal component analysis (https://en.wikipedia.org/wiki/Sparse_PCA) (SPCA). It uses a LASSO-type penalty to cut down on the number of original variables contributing ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Sparse_PCA", "kind": "external_url", "post_id": 676880, "post_url": "https://stats.stackexchange.com/a/676880", "product": "citations", "record_id": "Scientific-Citation-Graph:bd3563fe3db927b14aea4225", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Performing LASSO on standard principal components or following LASSO with PCA might still end up with all retained predictors contributing to each component.
\nAn alternative is sparse principal component analysis (SPCA). It uses a LASSO-type penalty to cut down on the number of original variables contributing to each component. Quoting:
\n\n\nA particular disadvantage of ordinary PCA is that the principal components are usually linear combinations of all input variables. SPCA overcomes this disadvantage by finding components that are linear combinations of just a few input variables (SPCs).
\n
Frank Harrell recommends it as one way to perform "data reduction" on predictors without using the outcome. See Section 8.6.1 of his Regression Modeling Strategies. Both the above references have links to implementations in R. For example, the R elasticnet package has one implementation in its spca() function.
EdM’s answer is very good but a couple of additional points:
\nI understand that PCA is for eliminating collinearity and reducing dimensions while the other is used for feature selection. I was wondering if there is any way to use these two methods together for an example if you wanted do feature selection but also wanted to get rid of collinearity which elastic net/lasso does poorly.
\nIn what cases would you use these two methods together and what cases would you use them separately? What is the general standard of practice is it to do it together or separate?
\n", "question_id": 676873, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "I understand that PCA is for eliminating collinearity and reducing dimensions while the other is used for feature selection. I was wondering if there is any way to use these two methods together for an example if you wanted do feature selection but also wanted to get rid of collinearity which elastic net/lasso does poorly.\n\n\n\n\nIn what cases would you use these two methods together and what cases would you use them separately? What is the general standard of practice is it to do it together or separate?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Karl Suh", "profile_url": "https://stats.stackexchange.com/users/513622/karl-suh", "user_type": "registered"}, "created_at": "2026-08-15T03:42:38+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "C888628D-3C97-4B17-86E4-AF7475A3C710", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C888628D-3C97-4B17-86E4-AF7475A3C710/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-15T13:55:27+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "1513EDD5-94FC-4B55-A64B-81770DFE0CB8", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/1513EDD5-94FC-4B55-A64B-81770DFE0CB8/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676873/can-you-use-pca-and-elastic-net-lasso-together-or-do-you-have-to-use-one-or-the", "split": "validation", "split_group": "b0befa11d334e3ea0cb0f6c32cda5c87da78493a28ed637e497c3e4ae2e250e6", "tags": ["pca", "lasso", "elastic-net"], "thread_id": "stats:676873", "title": "Can you use PCA and Elastic Net/Lasso together or do you have to use one or the other? Are there any use cases for using these two methods together?"}} {"citation_context": "\" on predictors without using the outcome. See Section 8.6.1 of his Regression Modeling Strategies (https://hbiostat.org/rmsc/impred.html#sec-impred-sparsepc). Both the above references have links to implementations in R. For example, the R elasticnet packa", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://hbiostat.org/rmsc/impred.html#sec-impred-sparsepc", "kind": "external_url", "post_id": 676880, "post_url": "https://stats.stackexchange.com/a/676880", "product": "citations", "record_id": "Scientific-Citation-Graph:e78e1574f242ccb6046a2c66", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Performing LASSO on standard principal components or following LASSO with PCA might still end up with all retained predictors contributing to each component.
\nAn alternative is sparse principal component analysis (SPCA). It uses a LASSO-type penalty to cut down on the number of original variables contributing to each component. Quoting:
\n\n\nA particular disadvantage of ordinary PCA is that the principal components are usually linear combinations of all input variables. SPCA overcomes this disadvantage by finding components that are linear combinations of just a few input variables (SPCs).
\n
Frank Harrell recommends it as one way to perform "data reduction" on predictors without using the outcome. See Section 8.6.1 of his Regression Modeling Strategies. Both the above references have links to implementations in R. For example, the R elasticnet package has one implementation in its spca() function.
EdM’s answer is very good but a couple of additional points:
\nI understand that PCA is for eliminating collinearity and reducing dimensions while the other is used for feature selection. I was wondering if there is any way to use these two methods together for an example if you wanted do feature selection but also wanted to get rid of collinearity which elastic net/lasso does poorly.
\nIn what cases would you use these two methods together and what cases would you use them separately? What is the general standard of practice is it to do it together or separate?
\n", "question_id": 676873, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "I understand that PCA is for eliminating collinearity and reducing dimensions while the other is used for feature selection. I was wondering if there is any way to use these two methods together for an example if you wanted do feature selection but also wanted to get rid of collinearity which elastic net/lasso does poorly.\n\n\n\n\nIn what cases would you use these two methods together and what cases would you use them separately? What is the general standard of practice is it to do it together or separate?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Karl Suh", "profile_url": "https://stats.stackexchange.com/users/513622/karl-suh", "user_type": "registered"}, "created_at": "2026-08-15T03:42:38+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "C888628D-3C97-4B17-86E4-AF7475A3C710", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C888628D-3C97-4B17-86E4-AF7475A3C710/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-15T13:55:27+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "1513EDD5-94FC-4B55-A64B-81770DFE0CB8", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/1513EDD5-94FC-4B55-A64B-81770DFE0CB8/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676873/can-you-use-pca-and-elastic-net-lasso-together-or-do-you-have-to-use-one-or-the", "split": "validation", "split_group": "b0befa11d334e3ea0cb0f6c32cda5c87da78493a28ed637e497c3e4ae2e250e6", "tags": ["pca", "lasso", "elastic-net"], "thread_id": "stats:676873", "title": "Can you use PCA and Elastic Net/Lasso together or do you have to use one or the other? Are there any use cases for using these two methods together?"}} {"citation_context": "ep3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": "10.1093/ije/dyaa148", "external_url": "https://doi.org/10.1093/ije/dyaa148", "kind": "doi_url", "post_id": 676979, "post_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "product": "citations", "record_id": "Scientific-Citation-Graph:6e8575c37a56f8cb84667556", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": "ables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$pr", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": "10.1186/s12874-021-01235-8", "external_url": "https://doi.org/10.1186/s12874-021-01235-8", "kind": "doi_url", "post_id": 676979, "post_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "product": "citations", "record_id": "Scientific-Citation-Graph:3013659a1404a54c2a8f5f25", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": "as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prev", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": "10.1186/s12889-017-4998-9", "external_url": "https://doi.org/10.1186/s12889-017-4998-9", "kind": "doi_url", "post_id": 676979, "post_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "product": "citations", "record_id": "Scientific-Citation-Graph:ff3089bd8e9d287d06438fae", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": " to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n tra", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": "10.3111/13696998.2011.626097", "external_url": "https://doi.org/10.3111/13696998.2011.626097", "kind": "doi_url", "post_id": 676979, "post_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "product": "citations", "record_id": "Scientific-Citation-Graph:aad582b89afbd27245f65c01", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": " type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/4a0pdydL.png", "kind": "external_url", "post_id": 676979, "post_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "product": "citations", "record_id": "Scientific-Citation-Graph:471ca43c46f3b504ff64d66f", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": "\n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/pzs11NTf.png", "kind": "external_url", "post_id": 676979, "post_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "product": "citations", "record_id": "Scientific-Citation-Graph:48214a1089fa9fc6e48cee63", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": "ly, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisf", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html", "kind": "external_url", "post_id": 676979, "post_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "product": "citations", "record_id": "Scientific-Citation-Graph:bb33698342e2b767348f3721", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": "\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/2fnDCjiM.png", "kind": "external_url", "post_id": 676996, "post_url": "https://stats.stackexchange.com/a/676996", "product": "citations", "record_id": "Scientific-Citation-Graph:04f7e860e7d6204dd91b60dd", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": "rring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpr", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://otexts.com/fpp3/dhr.html", "kind": "external_url", "post_id": 676996, "post_url": "https://stats.stackexchange.com/a/676996", "product": "citations", "record_id": "Scientific-Citation-Graph:19ea21785f3cad7fd014464b", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": "8572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://reprex.tidyverse.org", "kind": "external_url", "post_id": 676996, "post_url": "https://stats.stackexchange.com/a/676996", "product": "citations", "record_id": "Scientific-Citation-Graph:6bb92c41b2492e36659eb212", "split": "validation", "thread": {"accepted_answer_id": 676996, "answers": [{"answer_html": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.
age * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.
library(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html).
The reference level is Adults, so coefficients are interpreted as:
\ntime: pre-intervention slope for adults (prevalence per month)ageChildren:time: additional slope for children;The same logic applies for all ramp and step terms.
coef(fit) |>\n (\\(e) data.frame(\n Segment = c("Pre", "Post-1", "Post-2", "Post-3"),\n Adults = round(cumsum(c(e["time"],\n e["ramp1"],\n e["ramp2"],\n e["ramp3"])), 3),\n Children = round(cumsum(c(e["time"] + e["ageChildren:time"],\n e["ramp1"] + e["ageChildren:ramp1"],\n e["ramp2"] + e["ageChildren:ramp2"],\n e["ramp3"] + e["ageChildren:ramp3"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == "Children"], main = "Children")\ndev.off()\n\n
summary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\nCreated on 2026-08-29 with reprex v2.1.1
\n", "answer_id": 676996, "answer_text": "Rather than fitting separate models, you can handle both age groups in a single gls() model with age interactions. This has two advantages over separate auto.arima() models: you get formal tests of whether intervention effects differ between groups via the interaction terms, and you can account for the fact that the two series have very different variances.\n\n\n\n\nage * (time + step1 + ramp1 + ...) gives each group its own intercept, pre-intervention slope, and intervention effects, plus tests of whether they differ. Then, corAR1(form = ~ 1 | age) fits AR(1) autocorrelation within each group and varIdent(form = ~ 1 | age) allows different residual variances per group, which matters here since children's prevalence is an order of magnitude larger.\n\n\n\n\nlibrary(nlme)\nlibrary(dplyr)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nd_its <- d |>\n arrange(age, month) |>\n mutate(.by = age,\n time = row_number() - 1,\n step1 = as.numeric(month >= interventions[1]),\n ramp1 = ifelse(step1 == 1, cumsum(step1) - 1, 0),\n step2 = as.numeric(month >= interventions[2]),\n ramp2 = ifelse(step2 == 1, cumsum(step2) - 1, 0),\n step3 = as.numeric(month >= interventions[3]),\n ramp3 = ifelse(step3 == 1, cumsum(step3) - 1, 0),\n sin12 = sin(2 * pi * time / 12),\n cos12 = cos(2 * pi * time / 12),\n sin6 = sin(2 * pi * time / 6),\n cos6 = cos(2 * pi * time / 6),\n sin4 = sin(2 * pi * time / 4),\n cos4 = cos(2 * pi * time / 4)\n ) |>\n mutate(age = factor(age))\n\nfit <- gls(\n prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 +\n sin12 + cos12 + sin6 + cos6 + sin4 + cos4),\n data = d_its,\n correlation = corAR1(form = ~ 1 | age),\n weights = varIdent(form = ~ 1 | age)\n)\n\n\n\n\n\nThe Fourier terms (sin12, cos12, etc.) handle the recurring seasonal pattern, which is more stable than trying to absorb it through ARMA error terms (see https://otexts.com/fpp3/dhr.html (https://otexts.com/fpp3/dhr.html)).\n\n\n\n\nThe reference level is Adults, so coefficients are interpreted as:\n\n\n\n\n\ntime: pre-intervention slope for adults (prevalence per month)\n\n\n\n\nageChildren:time: additional slope for children;\n\n\n\n\n\nThe same logic applies for all ramp and step terms.\n\n\n\n\ncoef(fit) |>\n (\\(e) data.frame(\n Segment = c(\"Pre\", \"Post-1\", \"Post-2\", \"Post-3\"),\n Adults = round(cumsum(c(e[\"time\"],\n e[\"ramp1\"],\n e[\"ramp2\"],\n e[\"ramp3\"])), 3),\n Children = round(cumsum(c(e[\"time\"] + e[\"ageChildren:time\"],\n e[\"ramp1\"] + e[\"ageChildren:ramp1\"],\n e[\"ramp2\"] + e[\"ageChildren:ramp2\"],\n e[\"ramp3\"] + e[\"ageChildren:ramp3\"])), 3)\n))()\n\n#> Segment Adults Children\n#> time Pre 0.152 1.445\n#> ramp1 Post-1 0.919 9.276\n#> ramp2 Post-2 1.265 6.667\n#> ramp3 Post-3 2.387 8.418\n\n\n\n\n\npar(mfrow = c(1, 2))\nacf(residuals(fit)[d_its$age == \"Adults\"], main = \"Adults\")\nacf(residuals(fit)[d_its$age == \"Children\"], main = \"Children\")\ndev.off()\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/2fnDCjiM.png]\n\n\n\n\nsummary(fit)\n\n#> Generalized least squares fit by REML\n#> Model: prevalence ~ age * (time + step1 + ramp1 + step2 + ramp2 + step3 + ramp3 + sin12 + cos12 + sin6 + cos6 + sin4 + cos4) \n#> Data: d_its \n#> AIC BIC logLik\n#> 1665.172 1769.226 -801.5858\n#> \n#> Correlation Structure: AR(1)\n#> Formula: ~1 | age \n#> Parameter estimate(s):\n#> Phi \n#> 0.1231768 \n#> Variance function:\n#> Structure: Different standard deviations per stratum\n#> Formula: ~1 | age \n#> Parameter estimates:\n#> Adults Children \n#> 1.000000 9.435418 \n#> \n#> Coefficients:\n#> Value Std.Error t-value p-value\n#> (Intercept) 10.25450 0.701853 14.610597 0.0000\n#> ageChildren 177.16318 6.659369 26.603599 0.0000\n#> time 0.15162 0.017799 8.518225 0.0000\n#> step1 1.83019 1.934456 0.946100 0.3452\n#> ramp1 0.76689 0.379858 2.018892 0.0448\n#> step2 -0.98456 2.681497 -0.367167 0.7139\n#> ramp2 0.34620 0.449034 0.770992 0.4416\n#> step3 -4.38832 2.094825 -2.094838 0.0374\n#> ramp3 1.12257 0.257109 4.366133 0.0000\n#> sin12 0.01845 0.399784 0.046145 0.9632\n#> cos12 1.16269 0.380402 3.056467 0.0025\n#> sin6 -0.70555 0.358820 -1.966309 0.0506\n#> cos6 -0.97079 0.355213 -2.732980 0.0068\n#> sin4 0.78337 0.333359 2.349941 0.0197\n#> cos4 0.05479 0.333865 0.164117 0.8698\n#> ageChildren:time 1.29381 0.168883 7.661002 0.0000\n#> ageChildren:step1 -1.02662 18.354630 -0.055933 0.9554\n#> ageChildren:ramp1 7.06407 3.604192 1.959960 0.0513\n#> ageChildren:step2 -35.82645 25.442751 -1.408120 0.1606\n#> ageChildren:ramp2 -2.95530 4.260553 -0.693643 0.4887\n#> ageChildren:step3 -29.49930 19.876247 -1.484148 0.1393\n#> ageChildren:ramp3 0.62770 2.439516 0.257306 0.7972\n#> ageChildren:sin12 4.22521 3.793256 1.113874 0.2666\n#> ageChildren:cos12 36.54005 3.609352 10.123715 0.0000\n#> ageChildren:sin6 -9.76953 3.404578 -2.869528 0.0045\n#> ageChildren:cos6 -25.08251 3.370352 -7.442104 0.0000\n#> ageChildren:sin4 13.68702 3.162997 4.327230 0.0000\n#> ageChildren:cos4 14.66062 3.167797 4.628016 0.0000\n#> \n#> Correlation: \n#> (Intr) agChld time step1 ramp1 step2 ramp2 step3 \n#> ageChildren -0.105 \n#> time -0.862 0.091 \n#> step1 0.173 -0.018 -0.309 \n#> ramp1 0.057 -0.006 -0.063 -0.763 \n#> step2 -0.021 0.002 0.020 0.366 -0.711 \n#> ramp2 -0.004 0.000 0.005 0.655 -0.831 0.306 \n#> step3 -0.015 0.002 0.015 0.007 -0.031 0.300 -0.403 \n#> ramp3 -0.016 0.002 0.016 0.008 -0.023 0.514 -0.520 0.649\n#> sin12 -0.056 0.006 0.043 0.155 -0.247 0.317 0.074 0.209\n#> cos12 -0.050 0.005 0.069 -0.188 0.137 -0.028 -0.155 0.065\n#> sin6 -0.008 0.001 -0.006 0.034 0.018 -0.103 0.052 -0.126\n#> cos6 -0.010 0.001 0.002 0.047 -0.026 -0.035 0.060 -0.071\n#> sin4 -0.024 0.002 0.028 -0.033 -0.004 0.059 -0.040 0.066\n#> cos4 -0.011 0.001 0.002 0.063 -0.078 0.095 0.024 0.069\n#> ageChildren:time 0.091 -0.862 -0.105 0.033 0.007 -0.002 0.000 -0.002\n#> ageChildren:step1 -0.018 0.173 0.033 -0.105 0.080 -0.039 -0.069 -0.001\n#> ageChildren:ramp1 -0.006 0.057 0.007 0.080 -0.105 0.075 0.088 0.003\n#> ageChildren:step2 0.002 -0.021 -0.002 -0.039 0.075 -0.105 -0.032 -0.032\n#> ageChildren:ramp2 0.000 -0.004 0.000 -0.069 0.088 -0.032 -0.105 0.043\n#> ageChildren:step3 0.002 -0.015 -0.002 -0.001 0.003 -0.032 0.043 -0.105\n#> ageChildren:ramp3 0.002 -0.016 -0.002 -0.001 0.002 -0.054 0.055 -0.068\n#> ageChildren:sin12 0.006 -0.056 -0.005 -0.016 0.026 -0.033 -0.008 -0.022\n#> ageChildren:cos12 0.005 -0.050 -0.007 0.020 -0.014 0.003 0.016 -0.007\n#> ageChildren:sin6 0.001 -0.008 0.001 -0.004 -0.002 0.011 -0.005 0.013\n#> ageChildren:cos6 0.001 -0.010 0.000 -0.005 0.003 0.004 -0.006 0.007\n#> ageChildren:sin4 0.002 -0.024 -0.003 0.003 0.000 -0.006 0.004 -0.007\n#> ageChildren:cos4 0.001 -0.011 0.000 -0.007 0.008 -0.010 -0.002 -0.007\n#> ramp3 sin12 cos12 sin6 cos6 sin4 cos4 agChl:\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 0.235 \n#> cos12 0.057 -0.008 \n#> sin6 -0.099 -0.036 -0.015 \n#> cos6 -0.058 -0.011 -0.017 0.017 \n#> sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> cos4 0.073 0.041 -0.007 -0.009 -0.004 0.009 \n#> ageChildren:time -0.002 -0.005 -0.007 0.001 0.000 -0.003 0.000 \n#> ageChildren:step1 -0.001 -0.016 0.020 -0.004 -0.005 0.003 -0.007 -0.309\n#> ageChildren:ramp1 0.002 0.026 -0.014 -0.002 0.003 0.000 0.008 -0.063\n#> ageChildren:step2 -0.054 -0.033 0.003 0.011 0.004 -0.006 -0.010 0.020\n#> ageChildren:ramp2 0.055 -0.008 0.016 -0.005 -0.006 0.004 -0.002 0.005\n#> ageChildren:step3 -0.068 -0.022 -0.007 0.013 0.007 -0.007 -0.007 0.015\n#> ageChildren:ramp3 -0.105 -0.025 -0.006 0.010 0.006 -0.008 -0.008 0.016\n#> ageChildren:sin12 -0.025 -0.105 0.001 0.004 0.001 -0.003 -0.004 0.043\n#> ageChildren:cos12 -0.006 0.001 -0.105 0.002 0.002 -0.002 0.001 0.069\n#> ageChildren:sin6 0.010 0.004 0.002 -0.105 -0.002 0.001 0.001 -0.006\n#> ageChildren:cos6 0.006 0.001 0.002 -0.002 -0.105 0.001 0.000 0.002\n#> ageChildren:sin4 -0.008 -0.003 -0.002 0.001 0.001 -0.105 -0.001 0.028\n#> ageChildren:cos4 -0.008 -0.004 0.001 0.001 0.000 -0.001 -0.105 0.002\n#> agChldrn:s1 agChldrn:r1 agChldrn:s2 agChldrn:r2 agChldrn:s3\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 -0.763 \n#> ageChildren:step2 0.366 -0.711 \n#> ageChildren:ramp2 0.655 -0.831 0.306 \n#> ageChildren:step3 0.007 -0.031 0.300 -0.403 \n#> ageChildren:ramp3 0.008 -0.023 0.514 -0.520 0.649 \n#> ageChildren:sin12 0.155 -0.247 0.317 0.074 0.209 \n#> ageChildren:cos12 -0.188 0.137 -0.028 -0.155 0.065 \n#> ageChildren:sin6 0.034 0.018 -0.103 0.052 -0.126 \n#> ageChildren:cos6 0.047 -0.026 -0.035 0.060 -0.071 \n#> ageChildren:sin4 -0.033 -0.004 0.059 -0.040 0.066 \n#> ageChildren:cos4 0.063 -0.078 0.095 0.024 0.069 \n#> agChldrn:r3 agChldrn:s12 agChldrn:c12 agChldrn:s6 agChldrn:c6\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 0.235 \n#> ageChildren:cos12 0.057 -0.008 \n#> ageChildren:sin6 -0.099 -0.036 -0.015 \n#> ageChildren:cos6 -0.058 -0.011 -0.017 0.017 \n#> ageChildren:sin4 0.074 0.025 0.014 -0.013 -0.006 \n#> ageChildren:cos4 0.073 0.041 -0.007 -0.009 -0.004 \n#> agChldrn:s4\n#> ageChildren \n#> time \n#> step1 \n#> ramp1 \n#> step2 \n#> ramp2 \n#> step3 \n#> ramp3 \n#> sin12 \n#> cos12 \n#> sin6 \n#> cos6 \n#> sin4 \n#> cos4 \n#> ageChildren:time \n#> ageChildren:step1 \n#> ageChildren:ramp1 \n#> ageChildren:step2 \n#> ageChildren:ramp2 \n#> ageChildren:step3 \n#> ageChildren:ramp3 \n#> ageChildren:sin12 \n#> ageChildren:cos12 \n#> ageChildren:sin6 \n#> ageChildren:cos6 \n#> ageChildren:sin4 \n#> ageChildren:cos4 0.009 \n#> \n#> Standardized residuals:\n#> Min Q1 Med Q3 Max \n#> -5.25291094 -0.42240774 0.04331099 0.45224365 3.26323939 \n#> \n#> Residual standard error: 2.608572 \n#> Degrees of freedom: 240 total; 212 residual\n\n\n\n\n\nCreated on 2026-08-29 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676996", "author": "M--", "author_url": "https://stats.stackexchange.com/users/154449/m", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-29T05:35:19+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": 676979, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-08-29T05:35:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F437721-3A00-4B4D-BA06-A2F50516CC59", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F437721-3A00-4B4D-BA06-A2F50516CC59/view-source"}], "score": 3, "updated_at": "2026-08-29T05:35:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1093/ije/dyaa148", "https://doi.org/10.1186/s12874-021-01235-8", "https://doi.org/10.1186/s12889-017-4998-9", "https://doi.org/10.3111/13696998.2011.626097", "https://i.sstatic.net/2fnDCjiM.png", "https://i.sstatic.net/4a0pdydL.png", "https://i.sstatic.net/pzs11NTf.png", "https://otexts.com/fpp3/dhr.html", "https://reprex.tidyverse.org", "https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html"], "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": "Thomas", "question_author_url": "https://stats.stackexchange.com/users/263046/thomas", "question_author_user_type": "registered", "question_created_at": "2026-08-27T20:48:18+00:00", "question_html": "month <- seq(\n from = as.Date("2016-01-01"),\n to = as.Date("2025-12-31"),\n by = "month"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c("Children", "Adults"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = "l", main = "Children", subset = age == "Children")\nplot(prevalence ~ month, d, type = "l", main = "Adults", subset = age == "Adults")\ndev.off()\n\n\nI started with children.
\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. and Xiao et al.
d2 <- subset(d, age == "Children")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c("2021-09-13", "2022-06-02", "2023-06-29"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\nAccording to this thread, I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.
According to Schaffer et al., I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)
\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21, 22].
\n
fit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?
\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).
I have also read about nlme::gls() but I would like guidance/confirmation whether it is more appropriate.
BTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.
\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = "Ljung-Box", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n", "question_id": 676979, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Background\n\n\n\n\n\nData: time series of the monthly prevalence of patients receiving a given medication by age group (children or adults) from January 2016 to December 2026\n\n\n\n\nInterventions: three successive regulatory interventions implemented on September 2021, June 2022, and June 2023 to facilitate prescription of the medication (dotted lines on the figure below)\n\n\n\n\nAim: to estimate pre-intervention slope, post-intervention 1 slope, post-intervention 2 slope, and post-intervention 3 slope depending on age group to assess the impact of the interventions (i.e., interrupted time series analysis, ITS)\n\n\n\n\n\nmonth <- seq(\n from = as.Date(\"2016-01-01\"),\n to = as.Date(\"2025-12-31\"),\n by = \"month\"\n)\nmonth <- rep(month, each = 2)\nage <- rep(c(\"Children\", \"Adults\"), 120)\nprevalence <- c(\n 214.1, 11.3, 194.9, 11.1, 220.3, 11.8, 200.7, 11.7, 213.5, \n 11.7, 197.6, 11.5, 128.2, 10.3, 138.6, 9.9, 215, 12.1, 201.9, \n 11.9, 223.8, 12.2, 204.9, 12.4, 234.1, 12.7, 202, 11.9, 247, \n 13.6, 209.8, 13, 236.7, 13.4, 216.9, 13.1, 145.1, 12, 144.3, \n 11, 235.1, 13.7, 227.5, 13.9, 242.5, 13.9, 229.5, 13.8, 255.3, \n 14.5, 226.3, 13.6, 260.8, 15.2, 229.7, 14.2, 245.5, 14.7, 232.6, \n 14.4, 158.8, 13.4, 165, 12.5, 244.3, 14.8, 249.4, 15.7, 259.4, \n 15.5, 244, 15.3, 275.7, 16.2, 240.7, 14.9, 274.4, 16.2, 256.8, \n 16.3, 274.3, 16.4, 240.3, 15.5, 178.2, 15.5, 180.3, 13.6, 264, \n 16.3, 271.3, 17.4, 277.8, 16.9, 261.5, 16.8, 296.9, 17.8, 265.8, \n 17.2, 270.4, 17.9, 218.8, 16, 214.7, 16, 221.8, 16.7, 183.6, \n 16.8, 185.4, 14.9, 273.6, 18.7, 276.7, 19.3, 285, 19.4, 282.8, \n 19.9, 308.3, 20.2, 279.2, 19.3, 331.1, 22, 289.3, 21.2, 303, \n 20.9, 307.5, 21.8, 221.2, 20.9, 215.4, 18.9, 324, 23.4, 323.3, \n 24.3, 328.3, 24.7, 326.5, 25.8, 349.2, 26.1, 319.1, 25.5, 379.3, \n 29, 341.7, 28.3, 365.1, 28.6, 351.7, 30.1, 253.7, 28.6, 266.9, \n 27, 375, 33.4, 373.5, 34.4, 385.8, 35.5, 368.1, 36, 413.7, 38.8, \n 376, 37.4, 440.1, 42.5, 390.3, 40.8, 409.5, 42.6, 402, 44.9, \n 297.9, 43.4, 297.1, 40.2, 430.9, 49.3, 433.4, 51.2, 454.1, 53.1, \n 441.4, 53.4, 472.9, 57, 455.8, 57, 496.3, 62.6, 475, 63.1, 483.4, \n 63.3, 466, 65.1, 367.3, 66.2, 368.4, 58.6, 499.4, 70.8, 528.3, \n 76.1, 533.8, 76, 525.6, 77.2, 588.3, 84.8, 532.4, 81.1, 599.6, \n 90.9, 580.3, 90.8, 601.5, 93.8, 560.6, 95.1, 455.2, 96.9, 440.6, \n 83.7, 629.2, 107.7, 655.7, 112.8, 653.8, 113.2, 674.9, 118.7\n)\nd <- data.frame(month, age, prevalence)\n\npar(mfrow = c(1, 2))\nplot(prevalence ~ month, d, type = \"l\", main = \"Children\", subset = age == \"Children\")\nplot(prevalence ~ month, d, type = \"l\", main = \"Adults\", subset = age == \"Adults\")\ndev.off()\n\n\n\n\n\n[image: time series; source: https://i.sstatic.net/4a0pdydL.png] (https://i.sstatic.net/4a0pdydL.png)\n\n\n\n\nWhat I did\n\n\n\n\nI started with children.\n\n\n\n\nI constructed the ITS variables for the 3 interventions (step1, ramp1, step2, ramp2, step3, ramp3) following Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8) and Xiao et al. (https://doi.org/10.1093/ije/dyaa148)\n\n\n\n\nd2 <- subset(d, age == \"Children\")\nd2$prevalence <- ts(d2$prevalence, start = 2016, frequency = 12)\n\ninterventions <- as.Date(c(\"2021-09-13\", \"2022-06-02\", \"2023-06-29\"))\n\nstep1 <- as.numeric(d2$month >= interventions[1])\nramp1 <- ifelse(step1 == 1, cumsum(step1) - 1, 0)\n\nstep2 <- as.numeric(d2$month >= interventions[2])\nramp2 <- ifelse(step2 == 1, cumsum(step2) - 1, 0)\n\nstep3 <- as.numeric(d2$month >= interventions[3])\nramp3 <- ifelse(step3 == 1, cumsum(step3) - 1, 0)\n\ntime <- seq(from = 0, along.with = d2$month)\n\nxreg <- cbind(time, step1, ramp1, step2, ramp2, step3, ramp3)\n\ncbind(d2, xreg)\n# month age prevalence time step1 ramp1 step2 ramp2 step3 ramp3\n# 1 2016-01-01 Children 214.1 0 0 0 0 0 0 0\n# 3 2016-02-01 Children 194.9 1 0 0 0 0 0 0\n# 5 2016-03-01 Children 220.3 2 0 0 0 0 0 0\n# 7 2016-04-01 Children 200.7 3 0 0 0 0 0 0\n# 9 2016-05-01 Children 213.5 4 0 0 0 0 0 0\n# 11 2016-06-01 Children 197.6 5 0 0 0 0 0 0\n# 13 2016-07-01 Children 128.2 6 0 0 0 0 0 0\n# 15 2016-08-01 Children 138.6 7 0 0 0 0 0 0\n# 17 2016-09-01 Children 215.0 8 0 0 0 0 0 0\n# 19 2016-10-01 Children 201.9 9 0 0 0 0 0 0\n# 21 2016-11-01 Children 223.8 10 0 0 0 0 0 0\n# 23 2016-12-01 Children 204.9 11 0 0 0 0 0 0\n# 25 2017-01-01 Children 234.1 12 0 0 0 0 0 0\n# 27 2017-02-01 Children 202.0 13 0 0 0 0 0 0\n# 29 2017-03-01 Children 247.0 14 0 0 0 0 0 0\n# 31 2017-04-01 Children 209.8 15 0 0 0 0 0 0\n# 33 2017-05-01 Children 236.7 16 0 0 0 0 0 0\n# 35 2017-06-01 Children 216.9 17 0 0 0 0 0 0\n# 37 2017-07-01 Children 145.1 18 0 0 0 0 0 0\n# 39 2017-08-01 Children 144.3 19 0 0 0 0 0 0\n# 41 2017-09-01 Children 235.1 20 0 0 0 0 0 0\n# 43 2017-10-01 Children 227.5 21 0 0 0 0 0 0\n# 45 2017-11-01 Children 242.5 22 0 0 0 0 0 0\n# 47 2017-12-01 Children 229.5 23 0 0 0 0 0 0\n# 49 2018-01-01 Children 255.3 24 0 0 0 0 0 0\n# 51 2018-02-01 Children 226.3 25 0 0 0 0 0 0\n# 53 2018-03-01 Children 260.8 26 0 0 0 0 0 0\n# 55 2018-04-01 Children 229.7 27 0 0 0 0 0 0\n# 57 2018-05-01 Children 245.5 28 0 0 0 0 0 0\n# 59 2018-06-01 Children 232.6 29 0 0 0 0 0 0\n# 61 2018-07-01 Children 158.8 30 0 0 0 0 0 0\n# 63 2018-08-01 Children 165.0 31 0 0 0 0 0 0\n# 65 2018-09-01 Children 244.3 32 0 0 0 0 0 0\n# 67 2018-10-01 Children 249.4 33 0 0 0 0 0 0\n# 69 2018-11-01 Children 259.4 34 0 0 0 0 0 0\n# 71 2018-12-01 Children 244.0 35 0 0 0 0 0 0\n# 73 2019-01-01 Children 275.7 36 0 0 0 0 0 0\n# 75 2019-02-01 Children 240.7 37 0 0 0 0 0 0\n# 77 2019-03-01 Children 274.4 38 0 0 0 0 0 0\n# 79 2019-04-01 Children 256.8 39 0 0 0 0 0 0\n# 81 2019-05-01 Children 274.3 40 0 0 0 0 0 0\n# 83 2019-06-01 Children 240.3 41 0 0 0 0 0 0\n# 85 2019-07-01 Children 178.2 42 0 0 0 0 0 0\n# 87 2019-08-01 Children 180.3 43 0 0 0 0 0 0\n# 89 2019-09-01 Children 264.0 44 0 0 0 0 0 0\n# 91 2019-10-01 Children 271.3 45 0 0 0 0 0 0\n# 93 2019-11-01 Children 277.8 46 0 0 0 0 0 0\n# 95 2019-12-01 Children 261.5 47 0 0 0 0 0 0\n# 97 2020-01-01 Children 296.9 48 0 0 0 0 0 0\n# 99 2020-02-01 Children 265.8 49 0 0 0 0 0 0\n# 101 2020-03-01 Children 270.4 50 0 0 0 0 0 0\n# 103 2020-04-01 Children 218.8 51 0 0 0 0 0 0\n# 105 2020-05-01 Children 214.7 52 0 0 0 0 0 0\n# 107 2020-06-01 Children 221.8 53 0 0 0 0 0 0\n# 109 2020-07-01 Children 183.6 54 0 0 0 0 0 0\n# 111 2020-08-01 Children 185.4 55 0 0 0 0 0 0\n# 113 2020-09-01 Children 273.6 56 0 0 0 0 0 0\n# 115 2020-10-01 Children 276.7 57 0 0 0 0 0 0\n# 117 2020-11-01 Children 285.0 58 0 0 0 0 0 0\n# 119 2020-12-01 Children 282.8 59 0 0 0 0 0 0\n# 121 2021-01-01 Children 308.3 60 0 0 0 0 0 0\n# 123 2021-02-01 Children 279.2 61 0 0 0 0 0 0\n# 125 2021-03-01 Children 331.1 62 0 0 0 0 0 0\n# 127 2021-04-01 Children 289.3 63 0 0 0 0 0 0\n# 129 2021-05-01 Children 303.0 64 0 0 0 0 0 0\n# 131 2021-06-01 Children 307.5 65 0 0 0 0 0 0\n# 133 2021-07-01 Children 221.2 66 0 0 0 0 0 0\n# 135 2021-08-01 Children 215.4 67 0 0 0 0 0 0\n# 137 2021-09-01 Children 324.0 68 0 0 0 0 0 0\n# 139 2021-10-01 Children 323.3 69 1 0 0 0 0 0\n# 141 2021-11-01 Children 328.3 70 1 1 0 0 0 0\n# 143 2021-12-01 Children 326.5 71 1 2 0 0 0 0\n# 145 2022-01-01 Children 349.2 72 1 3 0 0 0 0\n# 147 2022-02-01 Children 319.1 73 1 4 0 0 0 0\n# 149 2022-03-01 Children 379.3 74 1 5 0 0 0 0\n# 151 2022-04-01 Children 341.7 75 1 6 0 0 0 0\n# 153 2022-05-01 Children 365.1 76 1 7 0 0 0 0\n# 155 2022-06-01 Children 351.7 77 1 8 0 0 0 0\n# 157 2022-07-01 Children 253.7 78 1 9 1 0 0 0\n# 159 2022-08-01 Children 266.9 79 1 10 1 1 0 0\n# 161 2022-09-01 Children 375.0 80 1 11 1 2 0 0\n# 163 2022-10-01 Children 373.5 81 1 12 1 3 0 0\n# 165 2022-11-01 Children 385.8 82 1 13 1 4 0 0\n# 167 2022-12-01 Children 368.1 83 1 14 1 5 0 0\n# 169 2023-01-01 Children 413.7 84 1 15 1 6 0 0\n# 171 2023-02-01 Children 376.0 85 1 16 1 7 0 0\n# 173 2023-03-01 Children 440.1 86 1 17 1 8 0 0\n# 175 2023-04-01 Children 390.3 87 1 18 1 9 0 0\n# 177 2023-05-01 Children 409.5 88 1 19 1 10 0 0\n# 179 2023-06-01 Children 402.0 89 1 20 1 11 0 0\n# 181 2023-07-01 Children 297.9 90 1 21 1 12 1 0\n# 183 2023-08-01 Children 297.1 91 1 22 1 13 1 1\n# 185 2023-09-01 Children 430.9 92 1 23 1 14 1 2\n# 187 2023-10-01 Children 433.4 93 1 24 1 15 1 3\n# 189 2023-11-01 Children 454.1 94 1 25 1 16 1 4\n# 191 2023-12-01 Children 441.4 95 1 26 1 17 1 5\n# 193 2024-01-01 Children 472.9 96 1 27 1 18 1 6\n# 195 2024-02-01 Children 455.8 97 1 28 1 19 1 7\n# 197 2024-03-01 Children 496.3 98 1 29 1 20 1 8\n# 199 2024-04-01 Children 475.0 99 1 30 1 21 1 9\n# 201 2024-05-01 Children 483.4 100 1 31 1 22 1 10\n# 203 2024-06-01 Children 466.0 101 1 32 1 23 1 11\n# 205 2024-07-01 Children 367.3 102 1 33 1 24 1 12\n# 207 2024-08-01 Children 368.4 103 1 34 1 25 1 13\n# 209 2024-09-01 Children 499.4 104 1 35 1 26 1 14\n# 211 2024-10-01 Children 528.3 105 1 36 1 27 1 15\n# 213 2024-11-01 Children 533.8 106 1 37 1 28 1 16\n# 215 2024-12-01 Children 525.6 107 1 38 1 29 1 17\n# 217 2025-01-01 Children 588.3 108 1 39 1 30 1 18\n# 219 2025-02-01 Children 532.4 109 1 40 1 31 1 19\n# 221 2025-03-01 Children 599.6 110 1 41 1 32 1 20\n# 223 2025-04-01 Children 580.3 111 1 42 1 33 1 21\n# 225 2025-05-01 Children 601.5 112 1 43 1 34 1 22\n# 227 2025-06-01 Children 560.6 113 1 44 1 35 1 23\n# 229 2025-07-01 Children 455.2 114 1 45 1 36 1 24\n# 231 2025-08-01 Children 440.6 115 1 46 1 37 1 25\n# 233 2025-09-01 Children 629.2 116 1 47 1 38 1 26\n# 235 2025-10-01 Children 655.7 117 1 48 1 39 1 27\n# 237 2025-11-01 Children 653.8 118 1 49 1 40 1 28\n# 239 2025-12-01 Children 674.9 119 1 50 1 41 1 29\n\n\n\n\n\nAccording to this thread (https://stats.stackexchange.com/q/665216/), I included the ITS variables for the 3 interventions in a single model. I used forecast::auto.arima() to select (p, q) and (P, Q) parameters automatically.\n\n\n\n\nAccording to Schaffer et al. (https://doi.org/10.1186/s12874-021-01235-8), I included a time variable and set $d = 0$ and $D = 0$ (but I am not sure that I need both $d = 0$ and $D = 0$): (emphasis mine)\n\n\n\n\n\n\n\nIn ITS analysis, ARIMA forecasts $Y_t$ in the absence of the intervention (the “counterfactual”) and determines how the observed diverges from this forecast. Unlike segmented regression, including time or seasonal dummy variables in the ARIMA model is not necessary, as ARIMA can eliminate trends and seasonality through differencing. If the trend is eliminated via differencing then the pre- and post-intervention trends cannot be estimated from the model. However, if estimation of the pre- and/or post-intervention slope is desired, this can be accommodated by including time as a covariate and incorporating AR and MA terms to address autocorrelation (e.g. ARMA models) [21 (https://doi.org/10.1186/s12889-017-4998-9), 22 (https://doi.org/10.3111/13696998.2011.626097)].\n\n\n\n\n\n\n\nfit <- forecast::auto.arima(\n d2$prevalence,\n d = 0,\n D = 0,\n stepwise = FALSE,\n trace = TRUE,\n approximation = FALSE,\n xreg = xreg\n)\n# \n# Regression with ARIMA(0,0,0) errors : 1422.701\n# Regression with ARIMA(0,0,0) errors : 1256.821\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,1)[12] errors : 1186.586\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,0)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,1) errors : 1348.712\n# Regression with ARIMA(0,0,1) errors : 1237.018\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,1)[12] errors : 1167.011\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,1)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,1)(2,0,2)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,1)(2,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2) errors : 1304.633\n# Regression with ARIMA(0,0,2) errors : 1235.236\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1226.35\n# Regression with ARIMA(0,0,2)(0,0,1)[12] errors : 1164.06\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,2)(0,0,2)[12] errors : 1122.153\n# ARIMA(0,0,2)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,2)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with zero mean : Inf\n# ARIMA(0,0,2)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,2)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,3) errors : 1301.979\n# Regression with ARIMA(0,0,3) errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,1)[12] errors : 1166.444\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(0,0,3)(0,0,2)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,3)(1,0,0)[12] errors : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with zero mean : Inf\n# ARIMA(0,0,3)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with zero mean : Inf\n# ARIMA(0,0,3)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4) errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(0,0,4)(0,0,1)[12] errors : 1167.795\n# ARIMA(0,0,4)(1,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(0,0,4)(1,0,0)[12] errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(0,0,5) errors : Inf\n# Regression with ARIMA(1,0,0) errors : 1269.039\n# Regression with ARIMA(1,0,0) errors : 1236.551\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1191.463\n# Regression with ARIMA(1,0,0)(0,0,1)[12] errors : 1163.925\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1144.206\n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors : 1122.139\n# ARIMA(1,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,0)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,0)(2,0,2)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,1) errors : 1269.741\n# Regression with ARIMA(1,0,1) errors : 1237.127\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1191.287\n# Regression with ARIMA(1,0,1)(0,0,1)[12] errors : 1165.649\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1145.611\n# Regression with ARIMA(1,0,1)(0,0,2)[12] errors : 1123.56\n# ARIMA(1,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with zero mean : Inf\n# ARIMA(1,0,1)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(1,0,1)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,1)(2,0,0)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,1)(2,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,2) errors : Inf\n# ARIMA(1,0,2) with non-zero mean : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(1,0,2)(0,0,2)[12] errors : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with zero mean : Inf\n# ARIMA(1,0,2)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(1,0,2)(2,0,0)[12] with zero mean : Inf\n# Regression with ARIMA(1,0,2)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3) errors : Inf\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : 1196.785\n# Regression with ARIMA(1,0,3)(0,0,1)[12] errors : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with zero mean : Inf\n# ARIMA(1,0,3)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(1,0,4) errors : Inf\n# Regression with ARIMA(2,0,0) errors : 1270.227\n# Regression with ARIMA(2,0,0) errors : 1235.453\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1191.855\n# Regression with ARIMA(2,0,0)(0,0,1)[12] errors : 1165.096\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1145.887\n# Regression with ARIMA(2,0,0)(0,0,2)[12] errors : 1123.031\n# ARIMA(2,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with zero mean : Inf\n# ARIMA(2,0,0)(1,0,2)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,0)(2,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,0)(2,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,0)(2,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1) errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(0,0,2)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(1,0,1)[12] errors : Inf\n# ARIMA(2,0,1)(1,0,1)[12] with non-zero mean : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,1)(2,0,0)[12] errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# Regression with ARIMA(2,0,2) errors : Inf\n# ARIMA(2,0,2)(0,0,1)[12] with zero mean : Inf\n# Regression with ARIMA(2,0,2)(0,0,1)[12] errors : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with zero mean : Inf\n# ARIMA(2,0,2)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(2,0,3) with zero mean : Inf\n# Regression with ARIMA(2,0,3) errors : Inf\n# Regression with ARIMA(3,0,0) errors : 1271.552\n# Regression with ARIMA(3,0,0) errors : 1234.442\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1193.944\n# Regression with ARIMA(3,0,0)(0,0,1)[12] errors : 1165.004\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1147.337\n# Regression with ARIMA(3,0,0)(0,0,2)[12] errors : 1124.69\n# ARIMA(3,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,0)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with zero mean : Inf\n# ARIMA(3,0,0)(1,0,1)[12] with non-zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,0)(2,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1) errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# Regression with ARIMA(3,0,1)(0,0,1)[12] errors : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with zero mean : Inf\n# ARIMA(3,0,1)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(3,0,2) errors : Inf\n# Regression with ARIMA(4,0,0) errors : 1268.176\n# Regression with ARIMA(4,0,0) errors : 1236.501\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1191.278\n# Regression with ARIMA(4,0,0)(0,0,1)[12] errors : 1167.39\n# ARIMA(4,0,0)(1,0,0)[12] with zero mean : Inf\n# ARIMA(4,0,0)(1,0,0)[12] with non-zero mean : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(4,0,1) errors : Inf\n# Regression with ARIMA(5,0,0) errors : 1270.388\n# Regression with ARIMA(5,0,0) errors : 1226.449\n# \n# \n# \n# Best model: Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n\nsummary(fit)\n# Series: d2$prevalence \n# Regression with ARIMA(1,0,0)(0,0,2)[12] errors \n# \n# Coefficients:\n# ar1 sma1 sma2 intercept time step1 ramp1 step2 ramp2 step3 ramp3\n# 0.5256 1.0413 0.6987 188.8179 1.5717 3.3284 2.1966 -5.6181 0.4640 0.4378 4.6447\n# s.e. 0.0800 0.1536 0.1312 20.6895 0.4724 13.0492 3.5219 23.9955 3.8197 19.1790 2.5724\n# \n# sigma^2 = 494.9: log likelihood = -547.61\n# AIC=1119.22 AICc=1122.14 BIC=1152.67\n# \n# Training set error measures:\n# ME RMSE MAE MPE MAPE MASE ACF1\n# Training set -0.2760281 21.20232 16.21419 -0.9807653 5.578825 0.3604042 0.05861382\n\n\n\n\n\nQuestion\n\n\n\n\nShould I just apply the same strategy to adults? Or can such models handle correlated/stratified time series?\n\n\n\n\nI guess that there is a better strategy than fitting separate models within each subgroup. However, I suspect that I cannot simply stack the time series and include age in xreg. Additionally, I probably need an interaction terms (e.g. time * age).\n\n\n\n\nI have also read about nlme::gls() (https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/gls.html) but I would like guidance/confirmation whether it is more appropriate.\n\n\n\n\n\n\n\nBTW, I am not satisfied with the fit, but I will explore that once I have decided the modelling strategy.\n\n\n\n\nres <- residuals(fit)\nl <- 36\n\npar(mfrow = c(3, 1))\nplot(res)\nacf(res, lag.max = l)\npacf(res, lag.max = l)\ndev.off()\n\nBox.test(res, lag = 24, type = \"Ljung-Box\", fitdf = 3)\n# \n# Box-Ljung test\n# \n# data: res\n# X-squared = 49.814, df = 21, p-value = 0.0003872\n# \n\n\n\n\n\n[image: residuals; source: https://i.sstatic.net/pzs11NTf.png] (https://i.sstatic.net/pzs11NTf.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-27T20:48:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4F68B416-BBB1-4FBC-8F34-014B8106BA46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F68B416-BBB1-4FBC-8F34-014B8106BA46/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:03:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "FB0908B9-A046-40C1-A08B-E6284215F76C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FB0908B9-A046-40C1-A08B-E6284215F76C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T00:11:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E9FBC78-84A9-484D-B830-4D1751368045", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E9FBC78-84A9-484D-B830-4D1751368045/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas", "profile_url": "https://stats.stackexchange.com/users/263046/thomas", "user_type": "registered"}, "created_at": "2026-08-28T09:19:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F52E35E2-A4F3-4D9C-BBE7-6F9246725A84", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F52E35E2-A4F3-4D9C-BBE7-6F9246725A84/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676979/strategy-for-interrupted-time-series-of-correlated-stratified-time-series", "split": "validation", "split_group": "4776dab9c10254abf857639b7a8deff481b81182a68f5330c41a896a7463144f", "tags": ["r", "time-series", "arima", "generalized-least-squares", "intervention-analysis"], "thread_id": "stats:676979", "title": "Strategy for interrupted time series of correlated/stratified time series"}}
{"citation_context": "et/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/03FfH1CY.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:bccbe4ed78fb5cb982805f42", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've c", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/2f1IsCZM.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:f9de31088e75f28feab22118", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/2frGxmzM.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:a654ebfe4629211621b7ca3b", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": " 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/2fs8yraM.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:02db30684d39475cb073a233", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/7o8KKCNe.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:9a5d00c9b21cbed3e7e77cbc", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/Cf66Rzrk.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:461758f194fa115069589ec9", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/JQ7R4P2C.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:848ad86014d04b3e9e4869cd", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/JprOGOJ2.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:621f2f11b6c96d0d0d51614a", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/V0JjVImt.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:7b6dcd4832e144a9c2fbaa78", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/YYELEFx7.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:098d0419cd08f85f269f3b3a", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": " 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/fmBeMY6t.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:9cafba01c27a8fb2267de4d3", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/iOSbUmj8.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:0b058769a9e6e947cd9eccf4", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/vTBK3rAo.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:7fc5263fee8cdcaf71a1590a", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/ykzaI4V0.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:76b40a6dce7b791e06fa1c0f", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "et/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstat", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/zOi948b5.png", "kind": "external_url", "post_id": 676982, "post_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "product": "citations", "record_id": "Scientific-Citation-Graph:09ef519c12d3fd076e9d100b", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.
\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.
\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.
\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.
\n", "answer_id": 676994, "answer_text": "Based on what I see in the interaction plot, there seems to be a strong association between your continuous predictor and the outcome. Consequently, the confidence intervals are narrow (so it's not very noisy). This is likely what primarily contributes to the $R^2$ being high.\n\n\n\n\nIt seems there aren't very large differences between groups wrt the outcome and the interaction isn't very strong. Grayscale is the only standout group. It has the same association but has a lower conditional mean and higher variability. So the group-based effects in the model are driving less of the $R^2$ than the continuous predictor is.\n\n\n\n\nThe model fitness seems fine too, so its not an obvious mis-specification. There is some by-quantile curvature at times and the QQ plot isn't exactly perfect but they're passable for a model. The results would be scarier if the plots were obviously bad.\n\n\n\n\nIt seems one version of your model has an additional categorical variable (based on the DHARMa plots) which isn't included in your R formula. This predictor could also be contributing to the model $R^2$ in some way too, but its not clear how.", "answer_url": "https://stats.stackexchange.com/a/676994", "author": "Shawn Hemelstrand", "author_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T23:57:01+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": 676982, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-28T23:57:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DB57E1BB-14A5-4645-A356-129C789D7022", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DB57E1BB-14A5-4645-A356-129C789D7022/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Shawn Hemelstrand", "profile_url": "https://stats.stackexchange.com/users/345611/shawn-hemelstrand", "user_type": "registered"}, "created_at": "2026-08-29T00:41:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0159009C-9F9A-4524-9B80-EAD167E5975F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0159009C-9F9A-4524-9B80-EAD167E5975F/view-source"}], "score": 6, "updated_at": "2026-08-29T00:41:24+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/03FfH1CY.png", "https://i.sstatic.net/2f1IsCZM.png", "https://i.sstatic.net/2frGxmzM.png", "https://i.sstatic.net/2fs8yraM.png", "https://i.sstatic.net/7o8KKCNe.png", "https://i.sstatic.net/Cf66Rzrk.png", "https://i.sstatic.net/JQ7R4P2C.png", "https://i.sstatic.net/JprOGOJ2.png", "https://i.sstatic.net/V0JjVImt.png", "https://i.sstatic.net/YYELEFx7.png", "https://i.sstatic.net/fmBeMY6t.png", "https://i.sstatic.net/iOSbUmj8.png", "https://i.sstatic.net/vTBK3rAo.png", "https://i.sstatic.net/ykzaI4V0.png", "https://i.sstatic.net/zOi948b5.png"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:58:06+00:00", "question_html": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?
\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.
here's some of the output of the final model, with fixed dispersion:
\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = "logit"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c("R2", "AIC", "BIC", "RMSE")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?
\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)
\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n(can't add more plots, I guess)
\n", "question_id": 676982, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Not sure if someone can help me, but I am trying to fit a model with one fixed continuous predictor (th) to my response variable (Score, continuous proportion without 0 or 1) measured in four different conditions (bd) in the same observers (obs). The data are from a psychological experiment, so I am having a hard time in finding a precedent. The results of the GLMM look too good to be true, so I think something might be very wrong. How can I make sure if the results are okay? Can I have a R^2 over 0.9 for the fixed dispersion model?\n\n\n\n\nI have previously fitted beta regression models separately to each condition, without accounting for repeated measures and random effects, using betareg, and pseudo-R-squared values were also high (ranging from 0.79 to 0.90). Although they are not the same, can they indicate something about this result? And is there a way for me to confirm the appropriateness of this GLMM and its output for my data? Observers' performance is expected to follow this trend, as they can be separated into 2 separate groups by the predictor's test result (a discrimination threshold), but still I have doubts. Maybe the experimental hypothesis is inappropriate, as one group is expected to outperform the other in the threshold, and the response is a hit score based on the control's group performance.\n\n\n\n\nhere's some of the output of the final model, with fixed dispersion:\n\n\n\n\nmod <- glmmTMB(Score ~ th * bd + (1 | obs),\n family = beta_family(link = \"logit\"), data = data_long)\n\n\n AIC BIC logLik -2*log(L) df.resid \n -565.2 -531.6 292.6 -585.2 202 \n\n**Random effects:**\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.03939 0.1985 \nNumber of obs: 212, groups: obs, 53\n\n> model_performance(\n+ mod,\n+ metrics = c(\"R2\", \"AIC\", \"BIC\", \"RMSE\")\n+ )\n# Indices of model performance\n\nAIC | BIC | R2 (cond.) | R2 (marg.) | RMSE\n-------------------------------------------------\n-565.2 | -531.6 | 0.985 | 0.912 | 0.048\n\n\n--- DHARMa diagnostic tests (unconditional simulations, old default) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.060925, p-value = 0.4108\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.0707, p-value = 0.51\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 3, observations = 212, p-value = 0.009158\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.002927826 0.040795871\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.01415094 \n\n\n\n# Intraclass Correlation Coefficient\n\n Adjusted ICC: 0.832\n Unadjusted ICC: 0.073\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/V0JjVImt.png] (https://i.sstatic.net/V0JjVImt.png)\n[image: enter image description here; source: https://i.sstatic.net/vTBK3rAo.png] (https://i.sstatic.net/vTBK3rAo.png)\n[image: enter image description here; source: https://i.sstatic.net/zOi948b5.png] (https://i.sstatic.net/zOi948b5.png)\n[image: enter image description here; source: https://i.sstatic.net/7o8KKCNe.png] (https://i.sstatic.net/7o8KKCNe.png)\n[image: enter image description here; source: https://i.sstatic.net/Cf66Rzrk.png] (https://i.sstatic.net/Cf66Rzrk.png)\n[image: enter image description here; source: https://i.sstatic.net/JQ7R4P2C.png] (https://i.sstatic.net/JQ7R4P2C.png)\n[image: enter image description here; source: https://i.sstatic.net/ykzaI4V0.png] (https://i.sstatic.net/ykzaI4V0.png)\n[image: enter image description here; source: https://i.sstatic.net/JprOGOJ2.png] (https://i.sstatic.net/JprOGOJ2.png)\n[image: enter image description here; source: https://i.sstatic.net/YYELEFx7.png] (https://i.sstatic.net/YYELEFx7.png)\n\n\n\n\nafter updating the software, with the new dharma package version, that uses conditional simulations as default, instead of unconditional, I now have significant distribution KS tests... How does this affect model validation?\n\n\n\n\n--- DHARMa diagnostic tests (new default: conditional simulations) ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.107, p-value = 0.01559\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1412, p-value = 0.138\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res\noutliers at both margin(s) = 2, observations = 212, p-value = 0.06782\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.001144546 0.033661358\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.009433962\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/2fs8yraM.png] (https://i.sstatic.net/2fs8yraM.png)\n[image: enter image description here; source: https://i.sstatic.net/2frGxmzM.png] (https://i.sstatic.net/2frGxmzM.png)\n[image: enter image description here; source: https://i.sstatic.net/iOSbUmj8.png] (https://i.sstatic.net/iOSbUmj8.png)\n[image: enter image description here; source: https://i.sstatic.net/03FfH1CY.png] (https://i.sstatic.net/03FfH1CY.png)\n[image: enter image description here; source: https://i.sstatic.net/2f1IsCZM.png] (https://i.sstatic.net/2f1IsCZM.png)\n\n\n\n\nUpdate: Due to the new conditional DHARMa results, I've compared a model with variable dispersion, which seems to be more adequate. I guess this solves the issue of the R-squared values, as they are now inappropriate to calculate... :)\n\n\n\n\n--- Model comparison (LRT and AIC) ---\nData: data_long\nModels:\nmod_disp_constant: Score ~ th * bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: Score ~ th * bd + (1 | obs), zi=~0,disp=~background\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 10 -565.16 -531.60 292.58 -585.16 \nmod_disp_background 13 -576.10 -532.47 301.05 -602.10 16.937 3 0.0007281 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1**\n df AIC\nmod_disp_constant 10 -565.1642\nmod_disp_background 13 -576.1012\n\n--- DHARMa diagnostics: varying dispersion, conditional simulation ---\n\n Asymptotic one-sample Kolmogorov-Smirnov test\n\ndata: simulationOutput$scaledResiduals\nD = 0.071019, p-value = 0.2353\nalternative hypothesis: two-sided\n\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated\n\ndata: simulationOutput\ndispersion = 1.1215, p-value = 0.192\nalternative hypothesis: two.sided\n\n\n DHARMa outlier test based on exact binomial test with approximate expectations\n\ndata: sim_res_dispbg_conditional\noutliers at both margin(s) = 1, observations = 212, p-value = 0.3456\nalternative hypothesis: true probability of success is not equal to 0.001998002\n95 percent confidence interval:\n 0.0001194165 0.0259997103\nsample estimates:\nfrequency of outliers (expected: 0.001998001998002 ) \n 0.004716981 \n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fmBeMY6t.png] (https://i.sstatic.net/fmBeMY6t.png)\n\n\n\n\n(can't add more plots, I guess)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-27T23:58:06+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "AD9037CD-0DDE-403F-9F6A-53908AE97FCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD9037CD-0DDE-403F-9F6A-53908AE97FCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alex J", "profile_url": "https://stats.stackexchange.com/users/369002/alex-j", "user_type": "registered"}, "created_at": "2026-08-28T01:38:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3EAA59CF-9ACC-4B3D-9AFA-AB5D8ECE34B4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-28T04:20:19+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7E6B4854-2230-4F24-8E0A-5B62915E43E4", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7E6B4854-2230-4F24-8E0A-5B62915E43E4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:01:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F19DD4EF-9466-40CB-B4D0-9CE189FEB3F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T15:09:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "007496D1-0D4A-482B-BAD6-609D5895915F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/007496D1-0D4A-482B-BAD6-609D5895915F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-28T20:29:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "12B957FD-E529-454A-B047-188DDFB56FEC", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12B957FD-E529-454A-B047-188DDFB56FEC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T05:37:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4E87FA39-5CD2-406D-9D24-0B402CCCA345", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E87FA39-5CD2-406D-9D24-0B402CCCA345/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T22:21:59+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E05011F7-55D9-4351-B560-D118A78E2098", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E05011F7-55D9-4351-B560-D118A78E2098/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-29T23:47:46+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2A145D07-0EC6-4F2F-846F-61F813A88425", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A145D07-0EC6-4F2F-846F-61F813A88425/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dodo", "profile_url": "https://stats.stackexchange.com/users/516003/dodo", "user_type": "registered"}, "created_at": "2026-08-30T08:44:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9A297BC1-B323-4435-8926-2848718059A9", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9A297BC1-B323-4435-8926-2848718059A9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "User1865345", "profile_url": "https://stats.stackexchange.com/users/362671/user1865345", "user_type": "registered"}, "created_at": "2026-08-30T09:13:27+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "67969179-E863-4693-B637-9E30F0487804", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67969179-E863-4693-B637-9E30F0487804/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676982/glmmtmb-with-beta-distribution-and-repeated-measures-with-high-r-squared-too-g", "split": "validation", "split_group": "4a3fc879ae3d375972ec508b97fe4ec07ecf984d1615b6ef74597b17b4827d41", "tags": ["mixed-model", "repeated-measures", "glmm", "beta-distribution", "glmmtmb"], "thread_id": "stats:676982", "title": "glmmTMB with beta distribution and repeated measures with high R-squared - too good to be true"}} {"citation_context": "ausch (2003, \"Obtaining power or obtaining precision. Delineating methods of sample-size planning\" (https://pubmed.ncbi.nlm.nih.gov/12971200/).\n\n\n\n\n(Finally, since you ask what's \"typical,\" the most common situation in practice is neither of", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://pubmed.ncbi.nlm.nih.gov/12971200/", "kind": "external_url", "post_id": 677102, "post_url": "https://stats.stackexchange.com/a/677102", "product": "citations", "record_id": "Scientific-Citation-Graph:49283e23cc551fde35c2b204", "split": "validation", "thread": {"accepted_answer_id": 677102, "answers": [{"answer_html": "Confidence interval procedures already account for the sample size. A good 95% CI procedure should cover the parameter 95% of the time, regardless of $n$, by definition. If $n$ is smaller, the CIs will just tend to be wider.
\n(...of course, with the exception of discrete-data situations where at certain $n$ you can get, let's say, 93% or 97% coverage but not exactly 95%, etc.)
So when choosing $n$, you shouldn't need to focus much on your 2nd case. Instead you can focus on your 1st case, which sounds to me like "Accuracy in Parameter Estimation" (AIPE). See for example Kelley, Maxwell, and Rausch (2003, "Obtaining power or obtaining precision. Delineating methods of sample-size planning".
\n(Finally, since you ask what's "typical," the most common situation in practice is neither of your 2 cases. Instead, the most common framework for choosing $n$ is to have adequate statistical power, in a hypothesis testing setting. But that is partly a historical quirk of how statistics was developed and taught. There are good reasons to focus on things like AIPE instead of hypothesis testing.)
\n", "answer_id": 677102, "answer_text": "Confidence interval procedures already account for the sample size. A good 95% CI procedure should cover the parameter 95% of the time, regardless of $n$, by definition. If $n$ is smaller, the CIs will just tend to be wider.\n\n(...of course, with the exception of discrete-data situations where at certain $n$ you can get, let's say, 93% or 97% coverage but not exactly 95%, etc.)\n\n\n\n\nSo when choosing $n$, you shouldn't need to focus much on your 2nd case. Instead you can focus on your 1st case, which sounds to me like \"Accuracy in Parameter Estimation\" (AIPE). See for example Kelley, Maxwell, and Rausch (2003, \"Obtaining power or obtaining precision. Delineating methods of sample-size planning\" (https://pubmed.ncbi.nlm.nih.gov/12971200/).\n\n\n\n\n(Finally, since you ask what's \"typical,\" the most common situation in practice is neither of your 2 cases. Instead, the most common framework for choosing $n$ is to have adequate statistical power, in a hypothesis testing setting. But that is partly a historical quirk of how statistics was developed and taught. There are good reasons to focus on things like AIPE instead of hypothesis testing.)", "answer_url": "https://stats.stackexchange.com/a/677102", "author": "civilstat", "author_url": "https://stats.stackexchange.com/users/17414/civilstat", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-08T13:23:08+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": 677098, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "civilstat", "profile_url": "https://stats.stackexchange.com/users/17414/civilstat", "user_type": "registered"}, "created_at": "2026-09-08T13:23:08+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "30E58C39-F28E-4090-A7B7-0EC9CE56FFCB", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/30E58C39-F28E-4090-A7B7-0EC9CE56FFCB/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "civilstat", "profile_url": "https://stats.stackexchange.com/users/17414/civilstat", "user_type": "registered"}, "created_at": "2026-09-15T01:01:34+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "D313A7E5-AE58-48F9-A18F-C0F2150BB098", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D313A7E5-AE58-48F9-A18F-C0F2150BB098/view-source"}], "score": 5, "updated_at": "2026-09-15T01:01:34+00:00"}], "domain": "statistics", "external_links": ["https://pubmed.ncbi.nlm.nih.gov/12971200/"], "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-08T04:17:59+00:00", "question_html": "Given a statistical model $M(\\theta_1,\\dots,\\theta_p)$.
\nAssuming a true value of each $\\theta_i$ is known, via simulation, I can determine two different sample sizes:
\nParameter Recovery: The $n$ needed so that each estimate $\\hat\\theta_i$ falls within $\\pm k\\%$ of its true value with probability at least $q$ .
\nCoverage: The $n$ needed so that a 95% confidence interval for the estimated mean of $M$ (i.e. $\\mathbb{E}_M[Y]$) contains the true mean a proportion $j$ of the time (coverage of the derived quantity $g(\\theta) = \\mathbb{E}_M[Y]$).
\nWhich of these is typically the more important factor/target when choosing $n$?
\n", "question_id": 677098, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Given a statistical model $M(\\theta_1,\\dots,\\theta_p)$.\n\n\n\n\nAssuming a true value of each $\\theta_i$ is known, via simulation, I can determine two different sample sizes:\n\n\n\n\n\n\n\nParameter Recovery: The $n$ needed so that each estimate $\\hat\\theta_i$ falls within $\\pm k\\%$ of its true value with probability at least $q$ .\n\n\n\n\n\n\n\n\n\nCoverage: The $n$ needed so that a 95% confidence interval for the estimated mean of $M$ (i.e. $\\mathbb{E}_M[Y]$) contains the true mean a proportion $j$ of the time (coverage of the derived quantity $g(\\theta) = \\mathbb{E}_M[Y]$).\n\n\n\n\n\n\n\n\nWhich of these is typically the more important factor/target when choosing $n$?", "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-08T04:17:59+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "15313CED-1404-44EA-A230-82E79875C5B8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/15313CED-1404-44EA-A230-82E79875C5B8/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-08T04:23:48+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "3D41642C-3420-4A9F-843C-F98D90590AF5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3D41642C-3420-4A9F-843C-F98D90590AF5/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-09T16:17:18+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "BF6E51A9-985F-4D9C-AFDE-2ABFDAC7C9D7", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/BF6E51A9-985F-4D9C-AFDE-2ABFDAC7C9D7/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677098/what-factor-is-more-important-in-determining-sample-size", "split": "validation", "split_group": "185fcb021546ad3cd40051f624c4e2d290e2963794c032b8452e062ce2a554d6", "tags": ["sampling"], "thread_id": "stats:677098", "title": "What factor is more important in determining sample size?"}} {"citation_context": "_error coverage \n#> -5.571571e-05 9.514200e-01\n\n\n\n\n\nCreated on 2026-09-15 with reprex v2.1.1 (https://reprex.tidyverse.org)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://reprex.tidyverse.org", "kind": "external_url", "post_id": 677181, "post_url": "https://stats.stackexchange.com/a/677181", "product": "citations", "record_id": "Scientific-Citation-Graph:bcb5aa1c3982fe9293b886d6", "split": "validation", "thread": {"accepted_answer_id": 677181, "answers": [{"answer_html": "Fix treatment arm $d$ and, to keep the notation light, let all sums and expectations below be taken within that arm. Write
\n$$\n\\widehat{\\tau}\n=\n\\frac{\\overline{Y}}{\\overline{M}}\n=\n\\frac{\\sum_i Y_i}{\\sum_i M_i},\n\\qquad\n\\tau\n=\n\\frac{E[Y]}{E[M]}.\n$$
\nA first-order Taylor expansion of $f(y,m)=y/m$ gives
\n$$\n\\begin{aligned}\n\\widehat{\\tau}-\\tau\n&\\approx\n\\frac{\\overline{Y}-E[Y]}{E[M]}\n-\n\\frac{E[Y]}{E[M]^2}\n\\left(\\overline{M}-E[M]\\right) \\\\[4pt]\n&=\n\\frac{1}{E[M]}\n\\left[\n\\left(\\overline{Y}-E[Y]\\right)\n-\n\\tau\\left(\\overline{M}-E[M]\\right)\n\\right] \\\\[4pt]\n&=\n\\frac{1}{nE[M]}\n\\sum_i\\left(Y_i-\\tau M_i\\right).\n\\end{aligned}\n$$
\nThe last equality uses $E[Y]=\\tau E[M]$. Therefore, the influence function is
\n$$\n\\operatorname{IF}_i\n=\n\\frac{Y_i-\\tau M_i}{E[M]}.\n$$
\nReplacing the unknown quantities with their sample estimates gives
\n$$\n\\widehat{\\operatorname{IF}}_i\n=\n\\frac{Y_i-\\widehat{\\tau}M_i}{\\overline{M}}.\n$$
\nThus, apart from the constant scaling factor $1/\\overline{M}$, the linearized outcome is
\n$$\nZ_i=Y_i-\\widehat{\\tau}M_i.\n$$
\nPractically speaking, you can run OLS on the ratios and weight them by the number of trials. I'd use robust covariance in this event too
\nlibrary(sandwich)\n\nset.seed(0)\ncef <- function(x, d) {\n plogis(-2 + 0.8 * x + 0.3 * d)\n}\n\ntau <- integrate(\n f = function(x) (cef(x, 1) - cef(x, 0)) * dnorm(x, 0, 1),\n lower = -Inf,\n upper = Inf\n)$value\n\nn <- 1000\nsims <- replicate(50000, {\n x1 <- rnorm(n)\n d <- rbinom(n, 1, 0.5)\n M <- pmax(1, rpois(n, 10))\n y <- rbinom(n, M, cef(x1, d))\n r <- y / M\n \n fit <- lm(r ~ x1 + d, weights = M)\n \n est <- coef(fit)[["d"]]\n se <- sqrt(sandwich::vcovHC(fit, type = "HC0")[["d", "d"]])\n \n lower <- est - qnorm(0.975) * se\n upper <- est + qnorm(0.975) * se\n \n c(\n estimate = est,\n se = se,\n lower = lower,\n upper = upper,\n error = est - tau\n )\n})\n\nsims <- t(sims)\n\nc(\n mean_error = mean(sims[, "error"]),\n coverage = mean(\n sims[, "lower"] <= tau &\n tau <= sims[, "upper"]\n )\n)\n#> mean_error coverage \n#> -5.571571e-05 9.514200e-01\n\nCreated on 2026-09-15 with reprex v2.1.1
\n", "answer_id": 677181, "answer_text": "Fix treatment arm $d$ and, to keep the notation light, let all sums and expectations below be taken within that arm. Write\n\n\n\n\n$$\n\\widehat{\\tau}\n=\n\\frac{\\overline{Y}}{\\overline{M}}\n=\n\\frac{\\sum_i Y_i}{\\sum_i M_i},\n\\qquad\n\\tau\n=\n\\frac{E[Y]}{E[M]}.\n$$\n\n\n\n\nA first-order Taylor expansion of $f(y,m)=y/m$ gives\n\n\n\n\n$$\n\\begin{aligned}\n\\widehat{\\tau}-\\tau\n&\\approx\n\\frac{\\overline{Y}-E[Y]}{E[M]}\n-\n\\frac{E[Y]}{E[M]^2}\n\\left(\\overline{M}-E[M]\\right) \\\\[4pt]\n&=\n\\frac{1}{E[M]}\n\\left[\n\\left(\\overline{Y}-E[Y]\\right)\n-\n\\tau\\left(\\overline{M}-E[M]\\right)\n\\right] \\\\[4pt]\n&=\n\\frac{1}{nE[M]}\n\\sum_i\\left(Y_i-\\tau M_i\\right).\n\\end{aligned}\n$$\n\n\n\n\nThe last equality uses $E[Y]=\\tau E[M]$. Therefore, the influence function is\n\n\n\n\n$$\n\\operatorname{IF}_i\n=\n\\frac{Y_i-\\tau M_i}{E[M]}.\n$$\n\n\n\n\nReplacing the unknown quantities with their sample estimates gives\n\n\n\n\n$$\n\\widehat{\\operatorname{IF}}_i\n=\n\\frac{Y_i-\\widehat{\\tau}M_i}{\\overline{M}}.\n$$\n\n\n\n\nThus, apart from the constant scaling factor $1/\\overline{M}$, the linearized outcome is\n\n\n\n\n$$\nZ_i=Y_i-\\widehat{\\tau}M_i.\n$$\n\n\n\n\nPractically speaking, you can run OLS on the ratios and weight them by the number of trials. I'd use robust covariance in this event too\n\n\n\n\nlibrary(sandwich)\n\nset.seed(0)\ncef <- function(x, d) {\n plogis(-2 + 0.8 * x + 0.3 * d)\n}\n\ntau <- integrate(\n f = function(x) (cef(x, 1) - cef(x, 0)) * dnorm(x, 0, 1),\n lower = -Inf,\n upper = Inf\n)$value\n\nn <- 1000\nsims <- replicate(50000, {\n x1 <- rnorm(n)\n d <- rbinom(n, 1, 0.5)\n M <- pmax(1, rpois(n, 10))\n y <- rbinom(n, M, cef(x1, d))\n r <- y / M\n \n fit <- lm(r ~ x1 + d, weights = M)\n \n est <- coef(fit)[[\"d\"]]\n se <- sqrt(sandwich::vcovHC(fit, type = \"HC0\")[[\"d\", \"d\"]])\n \n lower <- est - qnorm(0.975) * se\n upper <- est + qnorm(0.975) * se\n \n c(\n estimate = est,\n se = se,\n lower = lower,\n upper = upper,\n error = est - tau\n )\n})\n\nsims <- t(sims)\n\nc(\n mean_error = mean(sims[, \"error\"]),\n coverage = mean(\n sims[, \"lower\"] <= tau &\n tau <= sims[, \"upper\"]\n )\n)\n#> mean_error coverage \n#> -5.571571e-05 9.514200e-01\n\n\n\n\n\nCreated on 2026-09-15 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/677181", "author": "Demetri Pananos", "author_url": "https://stats.stackexchange.com/users/111259/demetri-pananos", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-15T16:27:34+00:00", "is_accepted": true, "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": 677179, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Demetri Pananos", "profile_url": "https://stats.stackexchange.com/users/111259/demetri-pananos", "user_type": "registered"}, "created_at": "2026-09-15T16:27:34+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "AC30AD7E-7B7F-4D55-B05C-76A70A413D78", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AC30AD7E-7B7F-4D55-B05C-76A70A413D78/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Demetri Pananos", "profile_url": "https://stats.stackexchange.com/users/111259/demetri-pananos", "user_type": "registered"}, "created_at": "2026-09-15T16:35:13+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "755739D7-7C88-4D82-AD57-75C2AE33AFBC", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/755739D7-7C88-4D82-AD57-75C2AE33AFBC/view-source"}], "score": 6, "updated_at": "2026-09-15T16:35:13+00:00"}], "domain": "statistics", "external_links": ["https://reprex.tidyverse.org"], "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": "jbuddy_13", "question_author_url": "https://stats.stackexchange.com/users/288172/jbuddy-13", "question_author_user_type": "registered", "question_created_at": "2026-09-15T15:25:50+00:00", "question_html": "In my workplace, I came across an idea that OLS can be retooled to solve ratio metric inference problems.
\nWhen I think of $k_i$ successes out of $m_i$ trials for individual $i$, this seems to be a perfect use case for binomial regression. Where your chief interest is estimating the conditional probability of success. Its strength, natively handling non-linearity, is also its weakness: Extracting the marginal probability of success is a nontrivial operation; marginalization via G-computation would be needed:\n$$logit(K=k|M=m, X=x, d=1) - logit(K=k|M=m, X=x, d=0)$$
\nAnd this is a large computational burden to assume with millions or billions of observations. So, I've been pointed to the OLS solution, which I understand to be based on the "delta method", correcting the linear solution with gradient information to accommodate curvature in the nonlinearity (ratio function), through the Taylor Series Expansion.
\nNaively, we have two options for OLS.
\nFirst, infer in the ratio space directly. But this approach completely mutes the number of trials and biases inference when $corr(K, M)$ exists.
\n$$ \\frac{k_i}{m_i} = \\alpha + \\lambda d_i + \\beta X +\\epsilon $$
\nThe second naive option is to infer the difference of global ratios directly where $D_j$ is the binary design vector for treatment exposure.This is equally problematic due to a sample size of one.
\n$$ \\frac{\\sum_{j=1} K_j D_j}{\\sum_{j=1} M_j D_j} - \\frac{\\sum_{j=1} K_j (1-D_j)}{\\sum_{j=1} M_j (1-D_j)} = \\alpha + \\lambda d_i + \\beta X +\\epsilon $$
\nThe end solution seems to address the bias shortcoming in naive approach 1 and the variance shortcoming in naive solution 2; it has two parts, computing $z_i$ as the difference between the actual successes and expected successes, and regressing $z_i$ via OLS given treatment exposure among other covariates.
\n$$ z_i = k_i - (\\frac{\\sum_{j=1} K_j}{\\sum_{j=1} M_j}) m_i $$
\n$$ z_i = \\alpha + \\lambda d_i + \\beta X_i +\\epsilon $$
\nIf all of the above, is correct, and that's a big if, where I'm lost at is seeing the connection between the $z_i$ form and the Taylor Series Expansion.
\nQuestion: How does the TSE prove $z_i$ to be the correct solution accounting for the nonlinearity in the ratio function?
\n", "question_id": 677179, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "In my workplace, I came across an idea that OLS can be retooled to solve ratio metric inference problems.\n\n\n\n\nWhen I think of $k_i$ successes out of $m_i$ trials for individual $i$, this seems to be a perfect use case for binomial regression. Where your chief interest is estimating the conditional probability of success. Its strength, natively handling non-linearity, is also its weakness: Extracting the marginal probability of success is a nontrivial operation; marginalization via G-computation would be needed:\n$$logit(K=k|M=m, X=x, d=1) - logit(K=k|M=m, X=x, d=0)$$\n\n\n\n\nAnd this is a large computational burden to assume with millions or billions of observations. So, I've been pointed to the OLS solution, which I understand to be based on the \"delta method\", correcting the linear solution with gradient information to accommodate curvature in the nonlinearity (ratio function), through the Taylor Series Expansion.\n\n\n\n\nNaively, we have two options for OLS.\n\n\n\n\nFirst, infer in the ratio space directly. But this approach completely mutes the number of trials and biases inference when $corr(K, M)$ exists.\n\n\n\n\n$$ \\frac{k_i}{m_i} = \\alpha + \\lambda d_i + \\beta X +\\epsilon $$\n\n\n\n\nThe second naive option is to infer the difference of global ratios directly where $D_j$ is the binary design vector for treatment exposure.This is equally problematic due to a sample size of one.\n\n\n\n\n$$ \\frac{\\sum_{j=1} K_j D_j}{\\sum_{j=1} M_j D_j} - \\frac{\\sum_{j=1} K_j (1-D_j)}{\\sum_{j=1} M_j (1-D_j)} = \\alpha + \\lambda d_i + \\beta X +\\epsilon $$\n\n\n\n\nThe end solution seems to address the bias shortcoming in naive approach 1 and the variance shortcoming in naive solution 2; it has two parts, computing $z_i$ as the difference between the actual successes and expected successes, and regressing $z_i$ via OLS given treatment exposure among other covariates.\n\n\n\n\n$$ z_i = k_i - (\\frac{\\sum_{j=1} K_j}{\\sum_{j=1} M_j}) m_i $$\n\n\n\n\n$$ z_i = \\alpha + \\lambda d_i + \\beta X_i +\\epsilon $$\n\n\n\n\nIf all of the above, is correct, and that's a big if, where I'm lost at is seeing the connection between the $z_i$ form and the Taylor Series Expansion.\n\n\n\n\nQuestion: How does the TSE prove $z_i$ to be the correct solution accounting for the nonlinearity in the ratio function?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "jbuddy_13", "profile_url": "https://stats.stackexchange.com/users/288172/jbuddy-13", "user_type": "registered"}, "created_at": "2026-09-15T15:25:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "E477C4E5-8119-4D6D-8EB7-06E7F1147CE1", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E477C4E5-8119-4D6D-8EB7-06E7F1147CE1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "jbuddy_13", "profile_url": "https://stats.stackexchange.com/users/288172/jbuddy-13", "user_type": "registered"}, "created_at": "2026-09-15T15:51:31+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7C5055B2-E916-464C-9092-9B0B51019D05", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7C5055B2-E916-464C-9092-9B0B51019D05/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-15T23:37:38+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "0015EC33-1DEB-456C-8D58-1E9522CF13C1", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/0015EC33-1DEB-456C-8D58-1E9522CF13C1/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677179/delta-method-for-linearizing-success-rate-inference", "split": "validation", "split_group": "bb14fd5ee1c3dd00639ebb6fa31a6ba50a54e417aaf3c07d0873f8be08a6ced7", "tags": ["logistic", "binomial-distribution", "delta-method"], "thread_id": "stats:677179", "title": "Delta method for linearizing success rate inference"}} {"citation_context": "[image: enter image description here; source: https://i.sstatic.net/Lh0AOcud.png] (https://i.sstatic.net/Lh0AOcud.png)\n\n\n\n\nI have two polynomial fits of the same dataset: a second-", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/Lh0AOcud.png", "kind": "external_url", "post_id": 677225, "post_url": "https://stats.stackexchange.com/questions/677225/comparing-extreme-points-of-two-polynomial-fits-of-the-same-dataset", "product": "citations", "record_id": "Scientific-Citation-Graph:ec46c695db832cee8874b245", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "As the 2 posts linked by @whuber in his comments allude to, such a task appears quite challenging. I will provide a possible approach, but I cannot vouch for its validity. I would be cautious in any case, as such extrema can be quite noisy, would be substantially influenced by high-leverage points, may not occur in the range of x-values from your dataset, etc.
\nThis being said, if I had to do what you want to do, (“find a statistical test that would allow me to know whether the x-value of these extrem[a are] significantly different), and assuming that the dataset is sufficiently large (? maybe $n>50$ ?), I would use bootstrapping.
Take a sample from the original dataset, of same size $n$, with replacement. Fit a quadratic and cubic to this resample; derive the 2 extrema of interest (0’s of the 1st derivative) and compute $\\Delta X$, the difference in x-values between them. Repeat the above a large (? 10,000 ?) number of times. Find the desired quantiles of these many $\\Delta X$’s (e.g. 2.5% and 97.5 for the “traditional” 5% significance level, or some other suitable significance). If the observed $\\Delta X_0$ is outside these 2 quantiles, you can reject the null that the difference in x-values was due to pure chance (i.e. that the observed difference would arise simply from the random differences between datasets from your population). The R code to do this bootstrap should not be too hard to write (the functions boot, and boot.ci should help a lot).
\n", "answer_id": 677230, "answer_text": "As the 2 posts linked by @whuber in his comments allude to, such a task appears quite challenging. I will provide a possible approach, but I cannot vouch for its validity. I would be cautious in any case, as such extrema can be quite noisy, would be substantially influenced by high-leverage points, may not occur in the range of x-values from your dataset, etc.\n\nThis being said, if I had to do what you want to do, (“find a statistical test that would allow me to know whether the x-value of these extrem[a are] significantly different), and assuming that the dataset is sufficiently large (? maybe $n>50$ ?), I would use bootstrapping.\n\n\n\n\nTake a sample from the original dataset, of same size $n$, with replacement. Fit a quadratic and cubic to this resample; derive the 2 extrema of interest (0’s of the 1st derivative) and compute $\\Delta X$, the difference in x-values between them. Repeat the above a large (? 10,000 ?) number of times. Find the desired quantiles of these many $\\Delta X$’s (e.g. 2.5% and 97.5 for the “traditional” 5% significance level, or some other suitable significance). If the observed $\\Delta X_0$ is outside these 2 quantiles, you can reject the null that the difference in x-values was due to pure chance (i.e. that the observed difference would arise simply from the random differences between datasets from your population). The R code to do this bootstrap should not be too hard to write (the functions boot, and boot.ci should help a lot).", "answer_url": "https://stats.stackexchange.com/a/677230", "author": "jginestet", "author_url": "https://stats.stackexchange.com/users/380096/jginestet", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-21T20:36:48+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": 677225, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "jginestet", "profile_url": "https://stats.stackexchange.com/users/380096/jginestet", "user_type": "registered"}, "created_at": "2026-09-21T20:36:48+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "4F10EF81-2804-478F-8F37-0E73D3975734", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F10EF81-2804-478F-8F37-0E73D3975734/view-source"}], "score": 3, "updated_at": "2026-09-21T20:36:48+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/Lh0AOcud.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": "Thomas Moore", "question_author_url": "https://stats.stackexchange.com/users/509665/thomas-moore", "question_author_user_type": "registered", "question_created_at": "2026-09-20T20:22:20+00:00", "question_html": "\nI have two polynomial fits of the same dataset: a second-order fit and a third-order fit. The second-order fit has a single extreme point, and the third-order fit has two extreme points.
\nI would like to compare the first local extreme of these two fits. That is: I am trying to find a statistical test that would allow me to know whether the x-value of these extreme points are the same, or significantly different.
\nVisualization above. Remember, these are both fitted to the same set of data.
\n", "question_id": 677225, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "[image: enter image description here; source: https://i.sstatic.net/Lh0AOcud.png] (https://i.sstatic.net/Lh0AOcud.png)\n\n\n\n\nI have two polynomial fits of the same dataset: a second-order fit and a third-order fit. The second-order fit has a single extreme point, and the third-order fit has two extreme points.\n\n\n\n\nI would like to compare the first local extreme of these two fits. That is: I am trying to find a statistical test that would allow me to know whether the x-value of these extreme points are the same, or significantly different.\n\n\n\n\nVisualization above. Remember, these are both fitted to the same set of data.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Moore", "profile_url": "https://stats.stackexchange.com/users/509665/thomas-moore", "user_type": "registered"}, "created_at": "2026-09-20T20:22:20+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "8EE5F099-563F-47E6-943F-16BB2E8525DE", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8EE5F099-563F-47E6-943F-16BB2E8525DE/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Moore", "profile_url": "https://stats.stackexchange.com/users/509665/thomas-moore", "user_type": "registered"}, "created_at": "2026-09-20T20:28:51+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "A0A723AE-391D-40BC-BBEE-69E6A23BE36C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A0A723AE-391D-40BC-BBEE-69E6A23BE36C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Moore", "profile_url": "https://stats.stackexchange.com/users/509665/thomas-moore", "user_type": "registered"}, "created_at": "2026-09-20T20:47:09+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "71E71D94-27AF-4E26-B7C7-6F803EBD415F", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/71E71D94-27AF-4E26-B7C7-6F803EBD415F/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-21T21:12:47+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "FFE6C570-22AB-4B74-895C-BEF572C9421A", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/FFE6C570-22AB-4B74-895C-BEF572C9421A/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677225/comparing-extreme-points-of-two-polynomial-fits-of-the-same-dataset", "split": "validation", "split_group": "28c3e36ae5541869796e6f6aedc890ed37f353f7ffb9886f7ab1d1b570d96777", "tags": ["polynomial"], "thread_id": "stats:677225", "title": "Comparing extreme points of two polynomial fits of the same dataset"}} {"citation_context": "The entropy power inequality (https://en.wikipedia.org/wiki/Entropy_power_inequality) is defined on continuous random variables.\n\n\n\n\n$$N[X+Y] \\geq N[X] + N[Y]$$\n\n\n\n\nwhere\n\n\n\n\n$$N[X] \\t", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Entropy_power_inequality", "kind": "external_url", "post_id": 677275, "post_url": "https://stats.stackexchange.com/questions/677275/is-there-a-discrete-analog-of-the-entropy-power-inequality", "product": "citations", "record_id": "Scientific-Citation-Graph:1449c1cdf10da4f8c12c0fc0", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Yes.
\nThis is shown in Nekouei et al 2019 that a very similar result holds:
\n$$N_d[X]+N_d[Y] \\leq 2 N_d[X+Y]$$
\nwhere
\n$$N_d[X] \\triangleq \\frac{1}{2\\pi e}e^{2H[X]}$$
\n$$H[X] \\triangleq - \\sum_{i} \\Pr[X=x_i]\\log \\Pr[X=x_i]$$
\n", "answer_id": 677276, "answer_text": "Yes.\n\n\n\n\nThis is shown in Nekouei et al 2019 (https://arxiv.org/html/1905.03015v1) that a very similar result holds:\n\n\n\n\n$$N_d[X]+N_d[Y] \\leq 2 N_d[X+Y]$$\n\n\n\n\nwhere\n\n\n\n\n$$N_d[X] \\triangleq \\frac{1}{2\\pi e}e^{2H[X]}$$\n\n\n\n\n$$H[X] \\triangleq - \\sum_{i} \\Pr[X=x_i]\\log \\Pr[X=x_i]$$", "answer_url": "https://stats.stackexchange.com/a/677276", "author": "Galen", "author_url": "https://stats.stackexchange.com/users/69508/galen", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-27T03:19:11+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": 677275, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Galen", "profile_url": "https://stats.stackexchange.com/users/69508/galen", "user_type": "registered"}, "created_at": "2026-09-27T03:19:11+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "88C57361-C89B-4371-BA6D-A50C945B5C2D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/88C57361-C89B-4371-BA6D-A50C945B5C2D/view-source"}], "score": 0, "updated_at": "2026-09-27T03:19:11+00:00"}, {"answer_html": "Yes, but not as a direct analogue of the continuous EPI.
\nSimply replacing differential entropy $h$ by discrete Shannon entropy $H$ does not make
\n$$N(X+Y)\\geq N(X)+N(Y)$$
\nvalid in general.
\nHowever, discrete EPI-type results do exist. For example, for i.i.d. integer-valued random variables $X,X'$, Haghighatshoar, Abbe and Telatar proved that
\n$$H(X+X')-H(X)\\geq g(H(X)),$$
\nwhere $g$ is a universal function, positive whenever $H(X)>0$.
\nSo there is no exact universal discrete counterpart obtained merely by replacing $h$ with $H$, but there are meaningful discrete analogues under appropriate assumptions.
\nReference: S. Haghighatshoar, E. Abbe & E. Telatar, A New Entropy Power Inequality for Integer-Valued Random Variables, IEEE Transactions on Information Theory, 60(7), 2014.
\n", "answer_id": 677277, "answer_text": "Yes, but not as a direct analogue of the continuous EPI.\n\n\n\n\nSimply replacing differential entropy $h$ by discrete Shannon entropy $H$ does not make\n\n\n\n\n$$N(X+Y)\\geq N(X)+N(Y)$$\n\n\n\n\nvalid in general.\n\n\n\n\nHowever, discrete EPI-type results do exist. For example, for i.i.d. integer-valued random variables $X,X'$, Haghighatshoar, Abbe and Telatar proved that\n\n\n\n\n$$H(X+X')-H(X)\\geq g(H(X)),$$\n\n\n\n\nwhere $g$ is a universal function, positive whenever $H(X)>0$.\n\n\n\n\nSo there is no exact universal discrete counterpart obtained merely by replacing $h$ with $H$, but there are meaningful discrete analogues under appropriate assumptions.\n\n\n\n\nReference: S. Haghighatshoar, E. Abbe & E. Telatar, A New Entropy Power Inequality for Integer-Valued Random Variables, IEEE Transactions on Information Theory, 60(7), 2014.", "answer_url": "https://stats.stackexchange.com/a/677277", "author": "Ghislain TSHALWE", "author_url": "https://stats.stackexchange.com/users/517102/ghislain-tshalwe", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-27T07:47:52+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": 677275, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ghislain TSHALWE", "profile_url": "https://stats.stackexchange.com/users/517102/ghislain-tshalwe", "user_type": "registered"}, "created_at": "2026-09-27T07:47:52+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "84D476DD-675E-499A-A6C7-A248DC56C8DA", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/84D476DD-675E-499A-A6C7-A248DC56C8DA/view-source"}], "score": 0, "updated_at": "2026-09-27T07:47:52+00:00"}], "domain": "statistics", "external_links": ["https://arxiv.org/html/1905.03015v1", "https://en.wikipedia.org/wiki/Entropy_power_inequality"], "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": "Galen", "question_author_url": "https://stats.stackexchange.com/users/69508/galen", "question_author_user_type": "registered", "question_created_at": "2026-09-27T03:17:37+00:00", "question_html": "The entropy power inequality is defined on continuous random variables.
\n$$N[X+Y] \\geq N[X] + N[Y]$$
\nwhere
\n$$N[X] \\triangleq \\frac{1}{2\\pi e}e^{\\frac{2}{n}h(X)}$$\n$$h(X) \\triangleq -\\int_{\\mathbb{R}^n}f(x)\\log f(x) dx$$
\nIs there an analogous result for discrete random variables?
\n", "question_id": 677275, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "The entropy power inequality (https://en.wikipedia.org/wiki/Entropy_power_inequality) is defined on continuous random variables.\n\n\n\n\n$$N[X+Y] \\geq N[X] + N[Y]$$\n\n\n\n\nwhere\n\n\n\n\n$$N[X] \\triangleq \\frac{1}{2\\pi e}e^{\\frac{2}{n}h(X)}$$\n$$h(X) \\triangleq -\\int_{\\mathbb{R}^n}f(x)\\log f(x) dx$$\n\n\n\n\nIs there an analogous result for discrete random variables?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Galen", "profile_url": "https://stats.stackexchange.com/users/69508/galen", "user_type": "registered"}, "created_at": "2026-09-27T03:17:37+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "3797B37E-74AE-4A2F-9573-37DD0EEB9DCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3797B37E-74AE-4A2F-9573-37DD0EEB9DCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Galen", "profile_url": "https://stats.stackexchange.com/users/69508/galen", "user_type": "registered"}, "created_at": "2026-09-27T03:19:51+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "9D51A372-C029-4708-A501-704874A2B11C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9D51A372-C029-4708-A501-704874A2B11C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Galen", "profile_url": "https://stats.stackexchange.com/users/69508/galen", "user_type": "registered"}, "created_at": "2026-09-27T03:36:43+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "460F551E-BD45-4EBC-8A2A-5695BDBCFB47", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/460F551E-BD45-4EBC-8A2A-5695BDBCFB47/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677275/is-there-a-discrete-analog-of-the-entropy-power-inequality", "split": "validation", "split_group": "0838d62c0bf3ef8ac843c59ad66d008d2a79de2fb7411d0c3574ed0da8e12bde", "tags": ["information-theory", "inequality", "entropy-power"], "thread_id": "stats:677275", "title": "Is there a discrete analog of the entropy power inequality?"}} {"citation_context": "Yes.\n\n\n\n\nThis is shown in Nekouei et al 2019 (https://arxiv.org/html/1905.03015v1) that a very similar result holds:\n\n\n\n\n$$N_d[X]+N_d[Y] \\leq 2 N_d[X+Y]$$\n\n\n\n\nwhere\n\n\n\n\n$$N_d[X] \\tr", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://arxiv.org/html/1905.03015v1", "kind": "external_url", "post_id": 677276, "post_url": "https://stats.stackexchange.com/a/677276", "product": "citations", "record_id": "Scientific-Citation-Graph:a597423297f0f1fe25faf155", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Yes.
\nThis is shown in Nekouei et al 2019 that a very similar result holds:
\n$$N_d[X]+N_d[Y] \\leq 2 N_d[X+Y]$$
\nwhere
\n$$N_d[X] \\triangleq \\frac{1}{2\\pi e}e^{2H[X]}$$
\n$$H[X] \\triangleq - \\sum_{i} \\Pr[X=x_i]\\log \\Pr[X=x_i]$$
\n", "answer_id": 677276, "answer_text": "Yes.\n\n\n\n\nThis is shown in Nekouei et al 2019 (https://arxiv.org/html/1905.03015v1) that a very similar result holds:\n\n\n\n\n$$N_d[X]+N_d[Y] \\leq 2 N_d[X+Y]$$\n\n\n\n\nwhere\n\n\n\n\n$$N_d[X] \\triangleq \\frac{1}{2\\pi e}e^{2H[X]}$$\n\n\n\n\n$$H[X] \\triangleq - \\sum_{i} \\Pr[X=x_i]\\log \\Pr[X=x_i]$$", "answer_url": "https://stats.stackexchange.com/a/677276", "author": "Galen", "author_url": "https://stats.stackexchange.com/users/69508/galen", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-27T03:19:11+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": 677275, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Galen", "profile_url": "https://stats.stackexchange.com/users/69508/galen", "user_type": "registered"}, "created_at": "2026-09-27T03:19:11+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "88C57361-C89B-4371-BA6D-A50C945B5C2D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/88C57361-C89B-4371-BA6D-A50C945B5C2D/view-source"}], "score": 0, "updated_at": "2026-09-27T03:19:11+00:00"}, {"answer_html": "Yes, but not as a direct analogue of the continuous EPI.
\nSimply replacing differential entropy $h$ by discrete Shannon entropy $H$ does not make
\n$$N(X+Y)\\geq N(X)+N(Y)$$
\nvalid in general.
\nHowever, discrete EPI-type results do exist. For example, for i.i.d. integer-valued random variables $X,X'$, Haghighatshoar, Abbe and Telatar proved that
\n$$H(X+X')-H(X)\\geq g(H(X)),$$
\nwhere $g$ is a universal function, positive whenever $H(X)>0$.
\nSo there is no exact universal discrete counterpart obtained merely by replacing $h$ with $H$, but there are meaningful discrete analogues under appropriate assumptions.
\nReference: S. Haghighatshoar, E. Abbe & E. Telatar, A New Entropy Power Inequality for Integer-Valued Random Variables, IEEE Transactions on Information Theory, 60(7), 2014.
\n", "answer_id": 677277, "answer_text": "Yes, but not as a direct analogue of the continuous EPI.\n\n\n\n\nSimply replacing differential entropy $h$ by discrete Shannon entropy $H$ does not make\n\n\n\n\n$$N(X+Y)\\geq N(X)+N(Y)$$\n\n\n\n\nvalid in general.\n\n\n\n\nHowever, discrete EPI-type results do exist. For example, for i.i.d. integer-valued random variables $X,X'$, Haghighatshoar, Abbe and Telatar proved that\n\n\n\n\n$$H(X+X')-H(X)\\geq g(H(X)),$$\n\n\n\n\nwhere $g$ is a universal function, positive whenever $H(X)>0$.\n\n\n\n\nSo there is no exact universal discrete counterpart obtained merely by replacing $h$ with $H$, but there are meaningful discrete analogues under appropriate assumptions.\n\n\n\n\nReference: S. Haghighatshoar, E. Abbe & E. Telatar, A New Entropy Power Inequality for Integer-Valued Random Variables, IEEE Transactions on Information Theory, 60(7), 2014.", "answer_url": "https://stats.stackexchange.com/a/677277", "author": "Ghislain TSHALWE", "author_url": "https://stats.stackexchange.com/users/517102/ghislain-tshalwe", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-27T07:47:52+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": 677275, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ghislain TSHALWE", "profile_url": "https://stats.stackexchange.com/users/517102/ghislain-tshalwe", "user_type": "registered"}, "created_at": "2026-09-27T07:47:52+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "84D476DD-675E-499A-A6C7-A248DC56C8DA", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/84D476DD-675E-499A-A6C7-A248DC56C8DA/view-source"}], "score": 0, "updated_at": "2026-09-27T07:47:52+00:00"}], "domain": "statistics", "external_links": ["https://arxiv.org/html/1905.03015v1", "https://en.wikipedia.org/wiki/Entropy_power_inequality"], "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": "Galen", "question_author_url": "https://stats.stackexchange.com/users/69508/galen", "question_author_user_type": "registered", "question_created_at": "2026-09-27T03:17:37+00:00", "question_html": "The entropy power inequality is defined on continuous random variables.
\n$$N[X+Y] \\geq N[X] + N[Y]$$
\nwhere
\n$$N[X] \\triangleq \\frac{1}{2\\pi e}e^{\\frac{2}{n}h(X)}$$\n$$h(X) \\triangleq -\\int_{\\mathbb{R}^n}f(x)\\log f(x) dx$$
\nIs there an analogous result for discrete random variables?
\n", "question_id": 677275, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "The entropy power inequality (https://en.wikipedia.org/wiki/Entropy_power_inequality) is defined on continuous random variables.\n\n\n\n\n$$N[X+Y] \\geq N[X] + N[Y]$$\n\n\n\n\nwhere\n\n\n\n\n$$N[X] \\triangleq \\frac{1}{2\\pi e}e^{\\frac{2}{n}h(X)}$$\n$$h(X) \\triangleq -\\int_{\\mathbb{R}^n}f(x)\\log f(x) dx$$\n\n\n\n\nIs there an analogous result for discrete random variables?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Galen", "profile_url": "https://stats.stackexchange.com/users/69508/galen", "user_type": "registered"}, "created_at": "2026-09-27T03:17:37+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "3797B37E-74AE-4A2F-9573-37DD0EEB9DCD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3797B37E-74AE-4A2F-9573-37DD0EEB9DCD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Galen", "profile_url": "https://stats.stackexchange.com/users/69508/galen", "user_type": "registered"}, "created_at": "2026-09-27T03:19:51+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "9D51A372-C029-4708-A501-704874A2B11C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9D51A372-C029-4708-A501-704874A2B11C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Galen", "profile_url": "https://stats.stackexchange.com/users/69508/galen", "user_type": "registered"}, "created_at": "2026-09-27T03:36:43+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "460F551E-BD45-4EBC-8A2A-5695BDBCFB47", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/460F551E-BD45-4EBC-8A2A-5695BDBCFB47/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677275/is-there-a-discrete-analog-of-the-entropy-power-inequality", "split": "validation", "split_group": "0838d62c0bf3ef8ac843c59ad66d008d2a79de2fb7411d0c3574ed0da8e12bde", "tags": ["information-theory", "inequality", "entropy-power"], "thread_id": "stats:677275", "title": "Is there a discrete analog of the entropy power inequality?"}} {"citation_context": "one has any suggestions for improvements, I would be very happy to hear them!\n\n\n\n\nHere is the code: https://github.com/DJopek/chaos/blob/main/double_pendulum.py (https://github.com/DJopek/chaos/blob/main/double_pendulum.py)\n\n\n\n\nimport sys\nimport numpy as np\nim", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://github.com/DJopek/chaos/blob/main/double_pendulum.py", "kind": "external_url", "post_id": 45171, "post_url": "https://scicomp.stackexchange.com/questions/45171/poincar%c3%a9-section-for-double-pendulum-code-improvement", "product": "citations", "record_id": "Scientific-Citation-Graph:75f196e44fef78b3c61e4c63", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "\n\nPoincaré section obtained by conditions in the code
\n
I very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections.
\n\n\nThe code can also be improved, so if anyone has any suggestions
\n
Well... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying "improve your Python". For the numerics:
\ng is both wrong and unnecessary; get the correct value from Scipy insteadmath module; stick to Numpyf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.plt.show() once.import time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n """energy of the system"""\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r"$\\theta_2\\ [rad]$")\n ax.set_ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n """solving the equations of motion"""\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r"$\\theta_1\\ [rad]$")\n ax.set_ylabel(r"$\\theta_2\\ [rad]$")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()\n\n", "answer_id": 45267, "answer_text": "Poincaré section obtained by conditions in the code\n\n\n\n\n\n\n\nI very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections (https://duetosymmetry.com/tool/poincare-section-clicker-toy/).\n\n\n\n\n\n\n\nThe code can also be improved, so if anyone has any suggestions\n\n\n\n\n\n\n\nWell... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying \"improve your Python\". For the numerics:\n\n\n\n\n\nYour g is both wrong and unnecessary; get the correct value from Scipy instead\n\n\n\n\nDon't use the math module; stick to Numpy\n\n\n\n\nf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().\n\n\n\n\nThe current parameters to solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.\n\n\n\n\nFor plotting, only call plt.show() once.\n\n\n\n\n\n[image: poincare; source: https://i.sstatic.net/INKhjIWk.png] (https://i.sstatic.net/INKhjIWk.png)\n\n\n\n\nimport time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n \"\"\"energy of the system\"\"\"\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n \"#2C3E50\", \"#3A3F64\", \"#484078\", \"#56428D\", \"#6B469E\",\n \"#804AAF\", \"#954EBF\", \"#A753C4\", \"#BA58C8\", \"#CE5DCD\",\n \"#E062C9\", \"#E971B4\", \"#F1809F\", \"#F98F8A\", \"#FFA07A\",\n \"#FF9C65\", \"#FF9850\", \"#FF943B\", \"#FF9026\", \"#FF8C11\",\n \"#F97F0D\", \"#F3730A\", \"#ED6606\", \"#E75A03\", \"#E04E00\",\n \"#D4431E\", \"#C8383C\", \"#BC2D5A\", \"#B02178\", \"#A41596\",\n \"#9710A3\", \"#880EA7\", \"#790CAB\", \"#6A0AAF\", \"#5C08B2\",\n \"#4D06B6\", \"#3E04BA\", \"#2F02BD\", \"#2000C1\", \"#1800B8\",\n \"#1000AF\", \"#0800A6\", \"#00009D\", \"#00008F\", \"#000081\",\n \"#0B006C\", \"#160057\", \"#210043\", \"#2C002E\", \"#37001A\"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r\"$\\theta_2\\ [rad]$\")\n ax.set_ylabel(r\"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$\")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n \"\"\"solving the equations of motion\"\"\"\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r\"$\\theta_1\\ [rad]$\")\n ax.set_ylabel(r\"$\\theta_2\\ [rad]$\")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()", "answer_url": "https://scicomp.stackexchange.com/a/45267", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-26T03:59:29+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45171, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-26T03:59:29+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9/view-source"}], "score": 3, "updated_at": "2025-10-26T03:59:29+00:00"}], "domain": "computational_science", "external_links": ["https://duetosymmetry.com/tool/poincare-section-clicker-toy/", "https://github.com/DJopek/chaos/blob/main/double_pendulum.py", "https://i.sstatic.net/INKhjIWk.png", "https://i.sstatic.net/U0nOulED.png", "https://i.sstatic.net/oJaBUfA4.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Dávid Jopek", "question_author_url": "https://scicomp.stackexchange.com/users/54327/d%c3%a1vid-jopek", "question_author_user_type": "registered", "question_created_at": "2025-07-15T18:16:26+00:00", "question_html": "I wanted to try numerical analysis of a chaotic system. So I decided to write my own code for the Poincaré section of a double pendulum in Python. The code works and the Poincaré section should be correct, but I can't get a nice picture of the section, like you see in textbooks or on the internet. I don't know if the problem is in the choice of energies, the (number of) initial conditions, or the integration "time interval" and steps. Can someone more experienced advise me on a good approach to obtaining nice Poincaré sections? The code can also be improved, so if anyone has any suggestions for improvements, I would be very happy to hear them!
\nHere is the code: https://github.com/DJopek/chaos/blob/main/double_pendulum.py
\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp\nfrom math import pi\nimport random\n\n# constants\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\ng = 9.81\n\n# Cauchy problem\n\n# y = [theta_1, theta_2, theta_1_dot, theta_2_dot]\n# y0 = [theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0]\n\n# generating initial conditions for some energy E\n\nnumber_of_initial_conditions = 50\n\ntheta_1_0 = []\n# theta_2_0 = []\ntheta_2_0 = np.linspace(-pi/2, pi/2, number_of_initial_conditions)\ntheta_1_dot_0 = []\ntheta_2_dot_0 = []\n\n# Energy = np.linspace(5,5.6,8) # [0,100] 1.\n# Energy = np.linspace(5.6,6.2,8) # [0,300] 2.\n# Energy = np.linspace(6.2,6.4,8) # [0,500] 3.\n# Energy = np.linspace(6.4,6.8,8) # [0,1000] 4.\n# Energy = np.linspace(5.9,6.3,8) # [0,700] 2-3.\n# Energy = np.linspace(6.3,6.8,12) # [0,1200] 3-4.\n# Energy = np.linspace(5.4,6.8,20) # [0,2000] 0.\n# Energy = np.linspace(5.6, 6.4, 16) # [0,700] 2_3\n# Energy = np.linspace(6.2,6.8,18) # [0,1200] 3_4.\n\n# Energy = [5.865]\nEnergy = [6.09]\n# Energy = [6.075]\n# Energy = [6.095]\n# Energy = [6.079]\n# Energy = [6.12]\n\n# number_of_initial_conditions = 1\n\ntotal_numbers_of_initial_conditions = number_of_initial_conditions*len(Energy)\n\ndef initial_conditions(E, number_of_initial_conditions):\n\n for i in range(number_of_initial_conditions):\n theta_1_0.append(0)\n # theta_2_0.append(np.random.uniform(-pi/4, pi/4))\n theta_2_dot_0.append(0)\n bucket = []\n bucket.append(np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n bucket.append(-np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n theta_1_dot_0.append(bucket[random.randint(0,1)])\n\nfor i in range(len(Energy)):\n initial_conditions(Energy[i], number_of_initial_conditions)\n\ndef f(t,y):\n return [y[2], \n y[3], \n (-g*np.sin(y[0])*(2*m_1+m_2)-g*m_2*np.sin(y[0]-2*y[1])-2*m_2*np.sin(y[0]-y[1])*(y[2]**2*l_1*np.cos(y[0]-y[1])+l_2*y[3]**2))/(l_1*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1]))), \n (2*np.sin(y[0]-y[1])*(np.cos(y[0])*g*(m_1+m_2)+l_1*(m_1+m_2)*y[2]**2+m_2*l_2*y[3]**2*np.cos(y[0]-y[1])))/(l_2*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1])))]\n\n# energy of the system\ndef E(y_1, y_2, y_3, y_4):\n total_energy = 0.5*l_1**2*y_3**2*(m_1+m_2)+0.5*m_2*l_2**2*y_4**2+m_2*l_1*l_2*y_3*y_4*np.cos(y_1-y_2)-l_1*g*np.cos(y_1)*(m_1+m_2)-l_2*m_2*g*np.cos(y_2)+(l_1+l_2)*g*(m_1+m_2)\n return total_energy\n\n# Poincaré section\ndef Poincare_section(total_numbers_of_initial_conditions):\n theta_2 = []\n theta_2_dot = []\n\n colors = []\n\n color = [\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n ]\n\n for i in range(total_numbers_of_initial_conditions):\n # color = ["#"+''.join([random.choice('0123456789ABCDEF') for r in range(6)])\n # for s in range(1)]\n\n number_of_points = len(solutions[i].t)\n\n for j in range(number_of_points-1):\n if solutions[i].y[0][j] <= 0 and solutions[i].y[0][j+1] >= 0:\n colors.append(color[i])\n theta_2.append(solutions[i].y[1][j+1])\n theta_2_dot.append(solutions[i].y[3][j+1])\n\n for m in range(len(theta_2)):\n plt.scatter((theta_2[m]+np.pi)%(2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n plt.xlabel(r"$\\theta_2\\ [rad]$")\n plt.ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n plt.show()\n\n# solving the equations of motion\nsolutions = []\n\nerror = 0.001\n\n# defining time interval\nt_span = [0,750]\n\nfor i in range(total_numbers_of_initial_conditions):\n y0 = [theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i]]\n system_energy = E(y0[0], y0[1], y0[2], y0[3])\n print(y0)\n print(system_energy)\n solutions.append(solve_ivp(f, t_span, y0, dense_output=True, rtol = 1e-12, atol = 1e-14))\n number_of_points = len(solutions[i].t)\n \n for j in range(number_of_points):\n solution_energy = E(solutions[i].y[0][j], solutions[i].y[1][j], solutions[i].y[2][j], solutions[i].y[3][j])\n if np.abs(solution_energy - system_energy) > error:\n sys.exit('Maximum energy drift of {} exceeded.'.format(error))\n\nPoincare_section(total_numbers_of_initial_conditions)\n\nx_1 = []\nx_2 = []\ny_1 = []\ny_2 = []\n\nfor i in range(len(solutions[0].t)):\n x_1.append(l_1*np.sin(solutions[0].y[0][i]))\n x_2.append(x_1[i]+l_2*np.sin(solutions[0].y[1][i]))\n y_1.append(-l_1*np.cos(solutions[0].y[0][i]))\n y_2.append(y_1[i]-l_2*np.cos(solutions[0].y[1][i]))\n\nplt.plot(solutions[0].y[0], solutions[0].y[1])\nplt.xlabel(r"$\\theta_1\\ [rad]$")\nplt.ylabel(r"$\\theta_2\\ [rad]$")\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.show()\nplt.plot(x_2, y_2)\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.plot(x_2, y_2)\nplt.show()\n\nPoincaré section obtained by conditions in the code:\n
EDIT:\nPoincaré section obtained by conditions in the code with labels
\n\nPoincaré section obtained by conditions in the code
\n
I very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections.
\n\n\nThe code can also be improved, so if anyone has any suggestions
\n
Well... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying "improve your Python". For the numerics:
\ng is both wrong and unnecessary; get the correct value from Scipy insteadmath module; stick to Numpyf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.plt.show() once.import time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n """energy of the system"""\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r"$\\theta_2\\ [rad]$")\n ax.set_ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n """solving the equations of motion"""\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r"$\\theta_1\\ [rad]$")\n ax.set_ylabel(r"$\\theta_2\\ [rad]$")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()\n\n", "answer_id": 45267, "answer_text": "Poincaré section obtained by conditions in the code\n\n\n\n\n\n\n\nI very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections (https://duetosymmetry.com/tool/poincare-section-clicker-toy/).\n\n\n\n\n\n\n\nThe code can also be improved, so if anyone has any suggestions\n\n\n\n\n\n\n\nWell... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying \"improve your Python\". For the numerics:\n\n\n\n\n\nYour g is both wrong and unnecessary; get the correct value from Scipy instead\n\n\n\n\nDon't use the math module; stick to Numpy\n\n\n\n\nf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().\n\n\n\n\nThe current parameters to solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.\n\n\n\n\nFor plotting, only call plt.show() once.\n\n\n\n\n\n[image: poincare; source: https://i.sstatic.net/INKhjIWk.png] (https://i.sstatic.net/INKhjIWk.png)\n\n\n\n\nimport time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n \"\"\"energy of the system\"\"\"\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n \"#2C3E50\", \"#3A3F64\", \"#484078\", \"#56428D\", \"#6B469E\",\n \"#804AAF\", \"#954EBF\", \"#A753C4\", \"#BA58C8\", \"#CE5DCD\",\n \"#E062C9\", \"#E971B4\", \"#F1809F\", \"#F98F8A\", \"#FFA07A\",\n \"#FF9C65\", \"#FF9850\", \"#FF943B\", \"#FF9026\", \"#FF8C11\",\n \"#F97F0D\", \"#F3730A\", \"#ED6606\", \"#E75A03\", \"#E04E00\",\n \"#D4431E\", \"#C8383C\", \"#BC2D5A\", \"#B02178\", \"#A41596\",\n \"#9710A3\", \"#880EA7\", \"#790CAB\", \"#6A0AAF\", \"#5C08B2\",\n \"#4D06B6\", \"#3E04BA\", \"#2F02BD\", \"#2000C1\", \"#1800B8\",\n \"#1000AF\", \"#0800A6\", \"#00009D\", \"#00008F\", \"#000081\",\n \"#0B006C\", \"#160057\", \"#210043\", \"#2C002E\", \"#37001A\"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r\"$\\theta_2\\ [rad]$\")\n ax.set_ylabel(r\"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$\")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n \"\"\"solving the equations of motion\"\"\"\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r\"$\\theta_1\\ [rad]$\")\n ax.set_ylabel(r\"$\\theta_2\\ [rad]$\")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()", "answer_url": "https://scicomp.stackexchange.com/a/45267", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-26T03:59:29+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45171, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-26T03:59:29+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9/view-source"}], "score": 3, "updated_at": "2025-10-26T03:59:29+00:00"}], "domain": "computational_science", "external_links": ["https://duetosymmetry.com/tool/poincare-section-clicker-toy/", "https://github.com/DJopek/chaos/blob/main/double_pendulum.py", "https://i.sstatic.net/INKhjIWk.png", "https://i.sstatic.net/U0nOulED.png", "https://i.sstatic.net/oJaBUfA4.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Dávid Jopek", "question_author_url": "https://scicomp.stackexchange.com/users/54327/d%c3%a1vid-jopek", "question_author_user_type": "registered", "question_created_at": "2025-07-15T18:16:26+00:00", "question_html": "I wanted to try numerical analysis of a chaotic system. So I decided to write my own code for the Poincaré section of a double pendulum in Python. The code works and the Poincaré section should be correct, but I can't get a nice picture of the section, like you see in textbooks or on the internet. I don't know if the problem is in the choice of energies, the (number of) initial conditions, or the integration "time interval" and steps. Can someone more experienced advise me on a good approach to obtaining nice Poincaré sections? The code can also be improved, so if anyone has any suggestions for improvements, I would be very happy to hear them!
\nHere is the code: https://github.com/DJopek/chaos/blob/main/double_pendulum.py
\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp\nfrom math import pi\nimport random\n\n# constants\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\ng = 9.81\n\n# Cauchy problem\n\n# y = [theta_1, theta_2, theta_1_dot, theta_2_dot]\n# y0 = [theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0]\n\n# generating initial conditions for some energy E\n\nnumber_of_initial_conditions = 50\n\ntheta_1_0 = []\n# theta_2_0 = []\ntheta_2_0 = np.linspace(-pi/2, pi/2, number_of_initial_conditions)\ntheta_1_dot_0 = []\ntheta_2_dot_0 = []\n\n# Energy = np.linspace(5,5.6,8) # [0,100] 1.\n# Energy = np.linspace(5.6,6.2,8) # [0,300] 2.\n# Energy = np.linspace(6.2,6.4,8) # [0,500] 3.\n# Energy = np.linspace(6.4,6.8,8) # [0,1000] 4.\n# Energy = np.linspace(5.9,6.3,8) # [0,700] 2-3.\n# Energy = np.linspace(6.3,6.8,12) # [0,1200] 3-4.\n# Energy = np.linspace(5.4,6.8,20) # [0,2000] 0.\n# Energy = np.linspace(5.6, 6.4, 16) # [0,700] 2_3\n# Energy = np.linspace(6.2,6.8,18) # [0,1200] 3_4.\n\n# Energy = [5.865]\nEnergy = [6.09]\n# Energy = [6.075]\n# Energy = [6.095]\n# Energy = [6.079]\n# Energy = [6.12]\n\n# number_of_initial_conditions = 1\n\ntotal_numbers_of_initial_conditions = number_of_initial_conditions*len(Energy)\n\ndef initial_conditions(E, number_of_initial_conditions):\n\n for i in range(number_of_initial_conditions):\n theta_1_0.append(0)\n # theta_2_0.append(np.random.uniform(-pi/4, pi/4))\n theta_2_dot_0.append(0)\n bucket = []\n bucket.append(np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n bucket.append(-np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n theta_1_dot_0.append(bucket[random.randint(0,1)])\n\nfor i in range(len(Energy)):\n initial_conditions(Energy[i], number_of_initial_conditions)\n\ndef f(t,y):\n return [y[2], \n y[3], \n (-g*np.sin(y[0])*(2*m_1+m_2)-g*m_2*np.sin(y[0]-2*y[1])-2*m_2*np.sin(y[0]-y[1])*(y[2]**2*l_1*np.cos(y[0]-y[1])+l_2*y[3]**2))/(l_1*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1]))), \n (2*np.sin(y[0]-y[1])*(np.cos(y[0])*g*(m_1+m_2)+l_1*(m_1+m_2)*y[2]**2+m_2*l_2*y[3]**2*np.cos(y[0]-y[1])))/(l_2*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1])))]\n\n# energy of the system\ndef E(y_1, y_2, y_3, y_4):\n total_energy = 0.5*l_1**2*y_3**2*(m_1+m_2)+0.5*m_2*l_2**2*y_4**2+m_2*l_1*l_2*y_3*y_4*np.cos(y_1-y_2)-l_1*g*np.cos(y_1)*(m_1+m_2)-l_2*m_2*g*np.cos(y_2)+(l_1+l_2)*g*(m_1+m_2)\n return total_energy\n\n# Poincaré section\ndef Poincare_section(total_numbers_of_initial_conditions):\n theta_2 = []\n theta_2_dot = []\n\n colors = []\n\n color = [\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n ]\n\n for i in range(total_numbers_of_initial_conditions):\n # color = ["#"+''.join([random.choice('0123456789ABCDEF') for r in range(6)])\n # for s in range(1)]\n\n number_of_points = len(solutions[i].t)\n\n for j in range(number_of_points-1):\n if solutions[i].y[0][j] <= 0 and solutions[i].y[0][j+1] >= 0:\n colors.append(color[i])\n theta_2.append(solutions[i].y[1][j+1])\n theta_2_dot.append(solutions[i].y[3][j+1])\n\n for m in range(len(theta_2)):\n plt.scatter((theta_2[m]+np.pi)%(2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n plt.xlabel(r"$\\theta_2\\ [rad]$")\n plt.ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n plt.show()\n\n# solving the equations of motion\nsolutions = []\n\nerror = 0.001\n\n# defining time interval\nt_span = [0,750]\n\nfor i in range(total_numbers_of_initial_conditions):\n y0 = [theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i]]\n system_energy = E(y0[0], y0[1], y0[2], y0[3])\n print(y0)\n print(system_energy)\n solutions.append(solve_ivp(f, t_span, y0, dense_output=True, rtol = 1e-12, atol = 1e-14))\n number_of_points = len(solutions[i].t)\n \n for j in range(number_of_points):\n solution_energy = E(solutions[i].y[0][j], solutions[i].y[1][j], solutions[i].y[2][j], solutions[i].y[3][j])\n if np.abs(solution_energy - system_energy) > error:\n sys.exit('Maximum energy drift of {} exceeded.'.format(error))\n\nPoincare_section(total_numbers_of_initial_conditions)\n\nx_1 = []\nx_2 = []\ny_1 = []\ny_2 = []\n\nfor i in range(len(solutions[0].t)):\n x_1.append(l_1*np.sin(solutions[0].y[0][i]))\n x_2.append(x_1[i]+l_2*np.sin(solutions[0].y[1][i]))\n y_1.append(-l_1*np.cos(solutions[0].y[0][i]))\n y_2.append(y_1[i]-l_2*np.cos(solutions[0].y[1][i]))\n\nplt.plot(solutions[0].y[0], solutions[0].y[1])\nplt.xlabel(r"$\\theta_1\\ [rad]$")\nplt.ylabel(r"$\\theta_2\\ [rad]$")\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.show()\nplt.plot(x_2, y_2)\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.plot(x_2, y_2)\nplt.show()\n\nPoincaré section obtained by conditions in the code:\n
EDIT:\nPoincaré section obtained by conditions in the code with labels
\n\nPoincaré section obtained by conditions in the code
\n
I very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections.
\n\n\nThe code can also be improved, so if anyone has any suggestions
\n
Well... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying "improve your Python". For the numerics:
\ng is both wrong and unnecessary; get the correct value from Scipy insteadmath module; stick to Numpyf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.plt.show() once.import time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n """energy of the system"""\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r"$\\theta_2\\ [rad]$")\n ax.set_ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n """solving the equations of motion"""\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r"$\\theta_1\\ [rad]$")\n ax.set_ylabel(r"$\\theta_2\\ [rad]$")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()\n\n", "answer_id": 45267, "answer_text": "Poincaré section obtained by conditions in the code\n\n\n\n\n\n\n\nI very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections (https://duetosymmetry.com/tool/poincare-section-clicker-toy/).\n\n\n\n\n\n\n\nThe code can also be improved, so if anyone has any suggestions\n\n\n\n\n\n\n\nWell... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying \"improve your Python\". For the numerics:\n\n\n\n\n\nYour g is both wrong and unnecessary; get the correct value from Scipy instead\n\n\n\n\nDon't use the math module; stick to Numpy\n\n\n\n\nf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().\n\n\n\n\nThe current parameters to solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.\n\n\n\n\nFor plotting, only call plt.show() once.\n\n\n\n\n\n[image: poincare; source: https://i.sstatic.net/INKhjIWk.png] (https://i.sstatic.net/INKhjIWk.png)\n\n\n\n\nimport time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n \"\"\"energy of the system\"\"\"\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n \"#2C3E50\", \"#3A3F64\", \"#484078\", \"#56428D\", \"#6B469E\",\n \"#804AAF\", \"#954EBF\", \"#A753C4\", \"#BA58C8\", \"#CE5DCD\",\n \"#E062C9\", \"#E971B4\", \"#F1809F\", \"#F98F8A\", \"#FFA07A\",\n \"#FF9C65\", \"#FF9850\", \"#FF943B\", \"#FF9026\", \"#FF8C11\",\n \"#F97F0D\", \"#F3730A\", \"#ED6606\", \"#E75A03\", \"#E04E00\",\n \"#D4431E\", \"#C8383C\", \"#BC2D5A\", \"#B02178\", \"#A41596\",\n \"#9710A3\", \"#880EA7\", \"#790CAB\", \"#6A0AAF\", \"#5C08B2\",\n \"#4D06B6\", \"#3E04BA\", \"#2F02BD\", \"#2000C1\", \"#1800B8\",\n \"#1000AF\", \"#0800A6\", \"#00009D\", \"#00008F\", \"#000081\",\n \"#0B006C\", \"#160057\", \"#210043\", \"#2C002E\", \"#37001A\"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r\"$\\theta_2\\ [rad]$\")\n ax.set_ylabel(r\"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$\")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n \"\"\"solving the equations of motion\"\"\"\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r\"$\\theta_1\\ [rad]$\")\n ax.set_ylabel(r\"$\\theta_2\\ [rad]$\")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()", "answer_url": "https://scicomp.stackexchange.com/a/45267", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-26T03:59:29+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45171, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-26T03:59:29+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9/view-source"}], "score": 3, "updated_at": "2025-10-26T03:59:29+00:00"}], "domain": "computational_science", "external_links": ["https://duetosymmetry.com/tool/poincare-section-clicker-toy/", "https://github.com/DJopek/chaos/blob/main/double_pendulum.py", "https://i.sstatic.net/INKhjIWk.png", "https://i.sstatic.net/U0nOulED.png", "https://i.sstatic.net/oJaBUfA4.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Dávid Jopek", "question_author_url": "https://scicomp.stackexchange.com/users/54327/d%c3%a1vid-jopek", "question_author_user_type": "registered", "question_created_at": "2025-07-15T18:16:26+00:00", "question_html": "I wanted to try numerical analysis of a chaotic system. So I decided to write my own code for the Poincaré section of a double pendulum in Python. The code works and the Poincaré section should be correct, but I can't get a nice picture of the section, like you see in textbooks or on the internet. I don't know if the problem is in the choice of energies, the (number of) initial conditions, or the integration "time interval" and steps. Can someone more experienced advise me on a good approach to obtaining nice Poincaré sections? The code can also be improved, so if anyone has any suggestions for improvements, I would be very happy to hear them!
\nHere is the code: https://github.com/DJopek/chaos/blob/main/double_pendulum.py
\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp\nfrom math import pi\nimport random\n\n# constants\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\ng = 9.81\n\n# Cauchy problem\n\n# y = [theta_1, theta_2, theta_1_dot, theta_2_dot]\n# y0 = [theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0]\n\n# generating initial conditions for some energy E\n\nnumber_of_initial_conditions = 50\n\ntheta_1_0 = []\n# theta_2_0 = []\ntheta_2_0 = np.linspace(-pi/2, pi/2, number_of_initial_conditions)\ntheta_1_dot_0 = []\ntheta_2_dot_0 = []\n\n# Energy = np.linspace(5,5.6,8) # [0,100] 1.\n# Energy = np.linspace(5.6,6.2,8) # [0,300] 2.\n# Energy = np.linspace(6.2,6.4,8) # [0,500] 3.\n# Energy = np.linspace(6.4,6.8,8) # [0,1000] 4.\n# Energy = np.linspace(5.9,6.3,8) # [0,700] 2-3.\n# Energy = np.linspace(6.3,6.8,12) # [0,1200] 3-4.\n# Energy = np.linspace(5.4,6.8,20) # [0,2000] 0.\n# Energy = np.linspace(5.6, 6.4, 16) # [0,700] 2_3\n# Energy = np.linspace(6.2,6.8,18) # [0,1200] 3_4.\n\n# Energy = [5.865]\nEnergy = [6.09]\n# Energy = [6.075]\n# Energy = [6.095]\n# Energy = [6.079]\n# Energy = [6.12]\n\n# number_of_initial_conditions = 1\n\ntotal_numbers_of_initial_conditions = number_of_initial_conditions*len(Energy)\n\ndef initial_conditions(E, number_of_initial_conditions):\n\n for i in range(number_of_initial_conditions):\n theta_1_0.append(0)\n # theta_2_0.append(np.random.uniform(-pi/4, pi/4))\n theta_2_dot_0.append(0)\n bucket = []\n bucket.append(np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n bucket.append(-np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n theta_1_dot_0.append(bucket[random.randint(0,1)])\n\nfor i in range(len(Energy)):\n initial_conditions(Energy[i], number_of_initial_conditions)\n\ndef f(t,y):\n return [y[2], \n y[3], \n (-g*np.sin(y[0])*(2*m_1+m_2)-g*m_2*np.sin(y[0]-2*y[1])-2*m_2*np.sin(y[0]-y[1])*(y[2]**2*l_1*np.cos(y[0]-y[1])+l_2*y[3]**2))/(l_1*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1]))), \n (2*np.sin(y[0]-y[1])*(np.cos(y[0])*g*(m_1+m_2)+l_1*(m_1+m_2)*y[2]**2+m_2*l_2*y[3]**2*np.cos(y[0]-y[1])))/(l_2*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1])))]\n\n# energy of the system\ndef E(y_1, y_2, y_3, y_4):\n total_energy = 0.5*l_1**2*y_3**2*(m_1+m_2)+0.5*m_2*l_2**2*y_4**2+m_2*l_1*l_2*y_3*y_4*np.cos(y_1-y_2)-l_1*g*np.cos(y_1)*(m_1+m_2)-l_2*m_2*g*np.cos(y_2)+(l_1+l_2)*g*(m_1+m_2)\n return total_energy\n\n# Poincaré section\ndef Poincare_section(total_numbers_of_initial_conditions):\n theta_2 = []\n theta_2_dot = []\n\n colors = []\n\n color = [\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n ]\n\n for i in range(total_numbers_of_initial_conditions):\n # color = ["#"+''.join([random.choice('0123456789ABCDEF') for r in range(6)])\n # for s in range(1)]\n\n number_of_points = len(solutions[i].t)\n\n for j in range(number_of_points-1):\n if solutions[i].y[0][j] <= 0 and solutions[i].y[0][j+1] >= 0:\n colors.append(color[i])\n theta_2.append(solutions[i].y[1][j+1])\n theta_2_dot.append(solutions[i].y[3][j+1])\n\n for m in range(len(theta_2)):\n plt.scatter((theta_2[m]+np.pi)%(2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n plt.xlabel(r"$\\theta_2\\ [rad]$")\n plt.ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n plt.show()\n\n# solving the equations of motion\nsolutions = []\n\nerror = 0.001\n\n# defining time interval\nt_span = [0,750]\n\nfor i in range(total_numbers_of_initial_conditions):\n y0 = [theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i]]\n system_energy = E(y0[0], y0[1], y0[2], y0[3])\n print(y0)\n print(system_energy)\n solutions.append(solve_ivp(f, t_span, y0, dense_output=True, rtol = 1e-12, atol = 1e-14))\n number_of_points = len(solutions[i].t)\n \n for j in range(number_of_points):\n solution_energy = E(solutions[i].y[0][j], solutions[i].y[1][j], solutions[i].y[2][j], solutions[i].y[3][j])\n if np.abs(solution_energy - system_energy) > error:\n sys.exit('Maximum energy drift of {} exceeded.'.format(error))\n\nPoincare_section(total_numbers_of_initial_conditions)\n\nx_1 = []\nx_2 = []\ny_1 = []\ny_2 = []\n\nfor i in range(len(solutions[0].t)):\n x_1.append(l_1*np.sin(solutions[0].y[0][i]))\n x_2.append(x_1[i]+l_2*np.sin(solutions[0].y[1][i]))\n y_1.append(-l_1*np.cos(solutions[0].y[0][i]))\n y_2.append(y_1[i]-l_2*np.cos(solutions[0].y[1][i]))\n\nplt.plot(solutions[0].y[0], solutions[0].y[1])\nplt.xlabel(r"$\\theta_1\\ [rad]$")\nplt.ylabel(r"$\\theta_2\\ [rad]$")\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.show()\nplt.plot(x_2, y_2)\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.plot(x_2, y_2)\nplt.show()\n\nPoincaré section obtained by conditions in the code:\n
EDIT:\nPoincaré section obtained by conditions in the code with labels
\n\nPoincaré section obtained by conditions in the code
\n
I very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections.
\n\n\nThe code can also be improved, so if anyone has any suggestions
\n
Well... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying "improve your Python". For the numerics:
\ng is both wrong and unnecessary; get the correct value from Scipy insteadmath module; stick to Numpyf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.plt.show() once.import time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n """energy of the system"""\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r"$\\theta_2\\ [rad]$")\n ax.set_ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n """solving the equations of motion"""\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r"$\\theta_1\\ [rad]$")\n ax.set_ylabel(r"$\\theta_2\\ [rad]$")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()\n\n", "answer_id": 45267, "answer_text": "Poincaré section obtained by conditions in the code\n\n\n\n\n\n\n\nI very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections (https://duetosymmetry.com/tool/poincare-section-clicker-toy/).\n\n\n\n\n\n\n\nThe code can also be improved, so if anyone has any suggestions\n\n\n\n\n\n\n\nWell... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying \"improve your Python\". For the numerics:\n\n\n\n\n\nYour g is both wrong and unnecessary; get the correct value from Scipy instead\n\n\n\n\nDon't use the math module; stick to Numpy\n\n\n\n\nf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().\n\n\n\n\nThe current parameters to solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.\n\n\n\n\nFor plotting, only call plt.show() once.\n\n\n\n\n\n[image: poincare; source: https://i.sstatic.net/INKhjIWk.png] (https://i.sstatic.net/INKhjIWk.png)\n\n\n\n\nimport time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n \"\"\"energy of the system\"\"\"\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n \"#2C3E50\", \"#3A3F64\", \"#484078\", \"#56428D\", \"#6B469E\",\n \"#804AAF\", \"#954EBF\", \"#A753C4\", \"#BA58C8\", \"#CE5DCD\",\n \"#E062C9\", \"#E971B4\", \"#F1809F\", \"#F98F8A\", \"#FFA07A\",\n \"#FF9C65\", \"#FF9850\", \"#FF943B\", \"#FF9026\", \"#FF8C11\",\n \"#F97F0D\", \"#F3730A\", \"#ED6606\", \"#E75A03\", \"#E04E00\",\n \"#D4431E\", \"#C8383C\", \"#BC2D5A\", \"#B02178\", \"#A41596\",\n \"#9710A3\", \"#880EA7\", \"#790CAB\", \"#6A0AAF\", \"#5C08B2\",\n \"#4D06B6\", \"#3E04BA\", \"#2F02BD\", \"#2000C1\", \"#1800B8\",\n \"#1000AF\", \"#0800A6\", \"#00009D\", \"#00008F\", \"#000081\",\n \"#0B006C\", \"#160057\", \"#210043\", \"#2C002E\", \"#37001A\"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r\"$\\theta_2\\ [rad]$\")\n ax.set_ylabel(r\"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$\")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n \"\"\"solving the equations of motion\"\"\"\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r\"$\\theta_1\\ [rad]$\")\n ax.set_ylabel(r\"$\\theta_2\\ [rad]$\")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()", "answer_url": "https://scicomp.stackexchange.com/a/45267", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-26T03:59:29+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45171, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-26T03:59:29+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9/view-source"}], "score": 3, "updated_at": "2025-10-26T03:59:29+00:00"}], "domain": "computational_science", "external_links": ["https://duetosymmetry.com/tool/poincare-section-clicker-toy/", "https://github.com/DJopek/chaos/blob/main/double_pendulum.py", "https://i.sstatic.net/INKhjIWk.png", "https://i.sstatic.net/U0nOulED.png", "https://i.sstatic.net/oJaBUfA4.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Dávid Jopek", "question_author_url": "https://scicomp.stackexchange.com/users/54327/d%c3%a1vid-jopek", "question_author_user_type": "registered", "question_created_at": "2025-07-15T18:16:26+00:00", "question_html": "I wanted to try numerical analysis of a chaotic system. So I decided to write my own code for the Poincaré section of a double pendulum in Python. The code works and the Poincaré section should be correct, but I can't get a nice picture of the section, like you see in textbooks or on the internet. I don't know if the problem is in the choice of energies, the (number of) initial conditions, or the integration "time interval" and steps. Can someone more experienced advise me on a good approach to obtaining nice Poincaré sections? The code can also be improved, so if anyone has any suggestions for improvements, I would be very happy to hear them!
\nHere is the code: https://github.com/DJopek/chaos/blob/main/double_pendulum.py
\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp\nfrom math import pi\nimport random\n\n# constants\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\ng = 9.81\n\n# Cauchy problem\n\n# y = [theta_1, theta_2, theta_1_dot, theta_2_dot]\n# y0 = [theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0]\n\n# generating initial conditions for some energy E\n\nnumber_of_initial_conditions = 50\n\ntheta_1_0 = []\n# theta_2_0 = []\ntheta_2_0 = np.linspace(-pi/2, pi/2, number_of_initial_conditions)\ntheta_1_dot_0 = []\ntheta_2_dot_0 = []\n\n# Energy = np.linspace(5,5.6,8) # [0,100] 1.\n# Energy = np.linspace(5.6,6.2,8) # [0,300] 2.\n# Energy = np.linspace(6.2,6.4,8) # [0,500] 3.\n# Energy = np.linspace(6.4,6.8,8) # [0,1000] 4.\n# Energy = np.linspace(5.9,6.3,8) # [0,700] 2-3.\n# Energy = np.linspace(6.3,6.8,12) # [0,1200] 3-4.\n# Energy = np.linspace(5.4,6.8,20) # [0,2000] 0.\n# Energy = np.linspace(5.6, 6.4, 16) # [0,700] 2_3\n# Energy = np.linspace(6.2,6.8,18) # [0,1200] 3_4.\n\n# Energy = [5.865]\nEnergy = [6.09]\n# Energy = [6.075]\n# Energy = [6.095]\n# Energy = [6.079]\n# Energy = [6.12]\n\n# number_of_initial_conditions = 1\n\ntotal_numbers_of_initial_conditions = number_of_initial_conditions*len(Energy)\n\ndef initial_conditions(E, number_of_initial_conditions):\n\n for i in range(number_of_initial_conditions):\n theta_1_0.append(0)\n # theta_2_0.append(np.random.uniform(-pi/4, pi/4))\n theta_2_dot_0.append(0)\n bucket = []\n bucket.append(np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n bucket.append(-np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n theta_1_dot_0.append(bucket[random.randint(0,1)])\n\nfor i in range(len(Energy)):\n initial_conditions(Energy[i], number_of_initial_conditions)\n\ndef f(t,y):\n return [y[2], \n y[3], \n (-g*np.sin(y[0])*(2*m_1+m_2)-g*m_2*np.sin(y[0]-2*y[1])-2*m_2*np.sin(y[0]-y[1])*(y[2]**2*l_1*np.cos(y[0]-y[1])+l_2*y[3]**2))/(l_1*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1]))), \n (2*np.sin(y[0]-y[1])*(np.cos(y[0])*g*(m_1+m_2)+l_1*(m_1+m_2)*y[2]**2+m_2*l_2*y[3]**2*np.cos(y[0]-y[1])))/(l_2*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1])))]\n\n# energy of the system\ndef E(y_1, y_2, y_3, y_4):\n total_energy = 0.5*l_1**2*y_3**2*(m_1+m_2)+0.5*m_2*l_2**2*y_4**2+m_2*l_1*l_2*y_3*y_4*np.cos(y_1-y_2)-l_1*g*np.cos(y_1)*(m_1+m_2)-l_2*m_2*g*np.cos(y_2)+(l_1+l_2)*g*(m_1+m_2)\n return total_energy\n\n# Poincaré section\ndef Poincare_section(total_numbers_of_initial_conditions):\n theta_2 = []\n theta_2_dot = []\n\n colors = []\n\n color = [\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n ]\n\n for i in range(total_numbers_of_initial_conditions):\n # color = ["#"+''.join([random.choice('0123456789ABCDEF') for r in range(6)])\n # for s in range(1)]\n\n number_of_points = len(solutions[i].t)\n\n for j in range(number_of_points-1):\n if solutions[i].y[0][j] <= 0 and solutions[i].y[0][j+1] >= 0:\n colors.append(color[i])\n theta_2.append(solutions[i].y[1][j+1])\n theta_2_dot.append(solutions[i].y[3][j+1])\n\n for m in range(len(theta_2)):\n plt.scatter((theta_2[m]+np.pi)%(2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n plt.xlabel(r"$\\theta_2\\ [rad]$")\n plt.ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n plt.show()\n\n# solving the equations of motion\nsolutions = []\n\nerror = 0.001\n\n# defining time interval\nt_span = [0,750]\n\nfor i in range(total_numbers_of_initial_conditions):\n y0 = [theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i]]\n system_energy = E(y0[0], y0[1], y0[2], y0[3])\n print(y0)\n print(system_energy)\n solutions.append(solve_ivp(f, t_span, y0, dense_output=True, rtol = 1e-12, atol = 1e-14))\n number_of_points = len(solutions[i].t)\n \n for j in range(number_of_points):\n solution_energy = E(solutions[i].y[0][j], solutions[i].y[1][j], solutions[i].y[2][j], solutions[i].y[3][j])\n if np.abs(solution_energy - system_energy) > error:\n sys.exit('Maximum energy drift of {} exceeded.'.format(error))\n\nPoincare_section(total_numbers_of_initial_conditions)\n\nx_1 = []\nx_2 = []\ny_1 = []\ny_2 = []\n\nfor i in range(len(solutions[0].t)):\n x_1.append(l_1*np.sin(solutions[0].y[0][i]))\n x_2.append(x_1[i]+l_2*np.sin(solutions[0].y[1][i]))\n y_1.append(-l_1*np.cos(solutions[0].y[0][i]))\n y_2.append(y_1[i]-l_2*np.cos(solutions[0].y[1][i]))\n\nplt.plot(solutions[0].y[0], solutions[0].y[1])\nplt.xlabel(r"$\\theta_1\\ [rad]$")\nplt.ylabel(r"$\\theta_2\\ [rad]$")\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.show()\nplt.plot(x_2, y_2)\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.plot(x_2, y_2)\nplt.show()\n\nPoincaré section obtained by conditions in the code:\n
EDIT:\nPoincaré section obtained by conditions in the code with labels
\n\nPoincaré section obtained by conditions in the code
\n
I very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections.
\n\n\nThe code can also be improved, so if anyone has any suggestions
\n
Well... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying "improve your Python". For the numerics:
\ng is both wrong and unnecessary; get the correct value from Scipy insteadmath module; stick to Numpyf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.plt.show() once.import time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n """energy of the system"""\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r"$\\theta_2\\ [rad]$")\n ax.set_ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n """solving the equations of motion"""\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r"$\\theta_1\\ [rad]$")\n ax.set_ylabel(r"$\\theta_2\\ [rad]$")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()\n\n", "answer_id": 45267, "answer_text": "Poincaré section obtained by conditions in the code\n\n\n\n\n\n\n\nI very much cannot reproduce what you've generated, after refactoring - I suspect due to moving to the more sophisticated LSODA and its accompanying parameters. I get results more similar to the resonances seen in e.g. Leo Stein's Poincaré sections (https://duetosymmetry.com/tool/poincare-section-clicker-toy/).\n\n\n\n\n\n\n\nThe code can also be improved, so if anyone has any suggestions\n\n\n\n\n\n\n\nWell... There's a lot. Since this is the Computational Science site and not the Code Review site, I will elide much of my feedback by saying \"improve your Python\". For the numerics:\n\n\n\n\n\nYour g is both wrong and unnecessary; get the correct value from Scipy instead\n\n\n\n\nDon't use the math module; stick to Numpy\n\n\n\n\nf() is both pretty slow and wholly illegible. It can be somewhat sped up by identifying common expressions, and should be broken up into many more lines. The same applies to E().\n\n\n\n\nThe current parameters to solve_ivp produce a very slow solution. Switch to LSODA and go easy on those tolerances.\n\n\n\n\nFor plotting, only call plt.show() once.\n\n\n\n\n\n[image: poincare; source: https://i.sstatic.net/INKhjIWk.png] (https://i.sstatic.net/INKhjIWk.png)\n\n\n\n\nimport time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp, OdeSolution\n\nfrom scipy.constants import g\nfrom scipy.integrate._ivp.ivp import OdeResult\n\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\n\n\ndef initial_conditions(\n E: float, n_initial_conditions: int, rand: np.random.Generator,\n) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n theta_1_0 = np.zeros(n_initial_conditions)\n theta_2_0 = np.linspace(-0.5*np.pi, 0.5*np.pi, n_initial_conditions)\n theta_2_dot_0 = np.zeros(n_initial_conditions)\n\n abs_t10 = np.sqrt(\n 2*(\n (\n E + l_2*m_2*g*np.cos(theta_2_0)\n )/(m_1 + m_2)\n - l_2*g\n )\n )/l_1\n\n theta_1_dot_0 = abs_t10*rand.choice((-1, 1), size=n_initial_conditions)\n\n return theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0\n\n\ndef f(t: float, y: np.ndarray) -> tuple[\n float, float, float, float,\n]:\n y0, y1, y2, y3 = y\n sin_y01 = 2*np.sin(y0 - y1)\n cos_y01 = np.cos(y0 - y1)\n m12m2 = 2*m_1 + m_2\n den = m12m2 - m_2*np.cos(2*y0 - 2*y1)\n y22l1 = y2**2*l_1\n y32l2 = l_2*y3**2\n\n res = (\n y2,\n y3,\n (\n -g*np.sin(y0)*m12m2 - m_2*(\n g*np.sin(y0 - 2*y1)\n + sin_y01*(\n y22l1*cos_y01 + y32l2\n )\n )\n ) / (l_1*den),\n (\n sin_y01*(\n (m_1 + m_2)*(\n np.cos(y0)*g + y22l1\n )\n + m_2*y32l2*cos_y01\n )\n ) / (l_2*den),\n )\n return res\n\n\ndef E(y_1: float, y_2: float, y_3: float, y_4: float) -> float:\n \"\"\"energy of the system\"\"\"\n total_energy = (\n 0.5*l_1**2*y_3**2*(m_1 + m_2)\n + 0.5*m_2*l_2**2*y_4**2\n + m_2*l_1*l_2*y_3*y_4*np.cos(y_1 - y_2)\n - l_1*g*np.cos(y_1)*(m_1 + m_2)\n - l_2*m_2*g*np.cos(y_2)\n + (l_1 + l_2)*g*(m_1 + m_2)\n )\n return total_energy\n\n\ndef plot_poincaré_section(solutions: list[OdeSolution]) -> plt.Figure:\n theta_2 = []\n theta_2_dot = []\n colors = []\n\n color = (\n \"#2C3E50\", \"#3A3F64\", \"#484078\", \"#56428D\", \"#6B469E\",\n \"#804AAF\", \"#954EBF\", \"#A753C4\", \"#BA58C8\", \"#CE5DCD\",\n \"#E062C9\", \"#E971B4\", \"#F1809F\", \"#F98F8A\", \"#FFA07A\",\n \"#FF9C65\", \"#FF9850\", \"#FF943B\", \"#FF9026\", \"#FF8C11\",\n \"#F97F0D\", \"#F3730A\", \"#ED6606\", \"#E75A03\", \"#E04E00\",\n \"#D4431E\", \"#C8383C\", \"#BC2D5A\", \"#B02178\", \"#A41596\",\n \"#9710A3\", \"#880EA7\", \"#790CAB\", \"#6A0AAF\", \"#5C08B2\",\n \"#4D06B6\", \"#3E04BA\", \"#2F02BD\", \"#2000C1\", \"#1800B8\",\n \"#1000AF\", \"#0800A6\", \"#00009D\", \"#00008F\", \"#000081\",\n \"#0B006C\", \"#160057\", \"#210043\", \"#2C002E\", \"#37001A\"\n )\n\n for solution, colori in zip(solutions, color):\n n_points = len(solution.t)\n y0, y1, y2, y3 = solution.y\n\n for j in range(n_points - 1):\n if y0[j] <= 0 <= y0[j + 1]:\n colors.append(colori)\n theta_2.append(y1[j + 1])\n theta_2_dot.append(y3[j + 1])\n\n fig, ax = plt.subplots()\n\n for m in range(len(theta_2)):\n ax.scatter((theta_2[m] + np.pi) % (2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n ax.set_xlabel(r\"$\\theta_2\\ [rad]$\")\n ax.set_ylabel(r\"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$\")\n return fig\n\n\ndef solve_motion_equations(\n theta_1_0: np.ndarray,\n theta_2_0: np.ndarray,\n theta_1_dot_0: np.ndarray,\n theta_2_dot_0: np.ndarray,\n strict: bool = True,\n error_max: float = 1e-3,\n rtol: float = 1e-4, atol: float = 1e-6,\n) -> list[OdeResult]:\n \"\"\"solving the equations of motion\"\"\"\n solutions = []\n\n # defining time interval\n t_span = (0, 750)\n jac_sparsity = np.array(( # All methods but LSODA\n (0, 0, 1, 0),\n (0, 0, 0, 1),\n (1, 1, 1, 1),\n (1, 1, 1, 1),\n ))\n # LSODA band parameters only reduce the Jacobian by one element; probably not worth it\n\n for i in range(len(theta_1_0)):\n y0 = (theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i])\n t0 = time.perf_counter()\n solutions.append(solve_ivp(\n fun=f, t_span=t_span, y0=y0, dense_output=True, method='LSODA',\n # jac_sparsity=jac_sparsity,\n rtol=rtol, atol=atol,\n ))\n t1 = time.perf_counter()\n print(t1 - t0)\n\n system_energy = E(*y0)\n for y in solutions[i].y.T:\n solution_energy = E(*y)\n error = np.abs(solution_energy - system_energy)\n if strict and error > error_max:\n message = f'Energy drift of {error_max} exceeds maximum {error_max}'\n raise ValueError(message)\n\n return solutions\n\n\ndef fill_xy(solutions: list[OdeSolution]) -> tuple[\n np.ndarray, np.ndarray, np.ndarray, np.ndarray,\n]:\n x_1 = l_1*np.sin(solutions[0].y[0])\n x_2 = l_2*np.sin(solutions[0].y[1]) + x_1\n y_1 = -l_1*np.cos(solutions[0].y[0])\n y_2 = -l_2*np.cos(solutions[0].y[1]) + y_1\n return x_1, x_2, y_1, y_2\n\n\ndef plot(\n solutions: list[OdeSolution],\n x_1: np.ndarray, x_2: np.ndarray,\n y_1: np.ndarray, y_2: np.ndarray,\n) -> None:\n fig, ax = plt.subplots()\n ax.plot(solutions[0].y[0], solutions[0].y[1])\n ax.set_xlabel(r\"$\\theta_1\\ [rad]$\")\n ax.set_ylabel(r\"$\\theta_2\\ [rad]$\")\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1)\n ax.set_xlabel('x_1')\n ax.set_ylabel('y_1')\n\n fig, ax = plt.subplots()\n ax.plot(x_2, y_2)\n ax.set_xlabel('x_2')\n ax.set_ylabel('y_2')\n\n fig, ax = plt.subplots()\n ax.plot(x_1, y_1, label='y_1')\n ax.plot(x_2, y_2, label='y_2')\n ax.legend()\n\n\ndef main() -> None:\n n_initial_conditions = 3 # 50\n rand = np.random.default_rng(seed=0)\n\n theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0 = initial_conditions(\n E=6.09, n_initial_conditions=n_initial_conditions, rand=rand,\n )\n solutions = solve_motion_equations(\n theta_1_0=theta_1_0, theta_1_dot_0=theta_1_dot_0,\n theta_2_0=theta_2_0, theta_2_dot_0=theta_2_dot_0,\n error_max=0.1,\n )\n plot_poincaré_section(solutions)\n x_1, x_2, y_1, y_2 = fill_xy(solutions)\n plot(solutions, x_1, x_2, y_1, y_2)\n plt.show()\n\n\nif __name__ == '__main__':\n main()", "answer_url": "https://scicomp.stackexchange.com/a/45267", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-26T03:59:29+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45171, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-26T03:59:29+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/1952C7E4-BD5B-442D-86E8-1FF1EBB10DF9/view-source"}], "score": 3, "updated_at": "2025-10-26T03:59:29+00:00"}], "domain": "computational_science", "external_links": ["https://duetosymmetry.com/tool/poincare-section-clicker-toy/", "https://github.com/DJopek/chaos/blob/main/double_pendulum.py", "https://i.sstatic.net/INKhjIWk.png", "https://i.sstatic.net/U0nOulED.png", "https://i.sstatic.net/oJaBUfA4.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Dávid Jopek", "question_author_url": "https://scicomp.stackexchange.com/users/54327/d%c3%a1vid-jopek", "question_author_user_type": "registered", "question_created_at": "2025-07-15T18:16:26+00:00", "question_html": "I wanted to try numerical analysis of a chaotic system. So I decided to write my own code for the Poincaré section of a double pendulum in Python. The code works and the Poincaré section should be correct, but I can't get a nice picture of the section, like you see in textbooks or on the internet. I don't know if the problem is in the choice of energies, the (number of) initial conditions, or the integration "time interval" and steps. Can someone more experienced advise me on a good approach to obtaining nice Poincaré sections? The code can also be improved, so if anyone has any suggestions for improvements, I would be very happy to hear them!
\nHere is the code: https://github.com/DJopek/chaos/blob/main/double_pendulum.py
\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp\nfrom math import pi\nimport random\n\n# constants\nl_1 = 0.1\nl_2 = 0.5\nm_1 = 0.8\nm_2 = 0.3\ng = 9.81\n\n# Cauchy problem\n\n# y = [theta_1, theta_2, theta_1_dot, theta_2_dot]\n# y0 = [theta_1_0, theta_2_0, theta_1_dot_0, theta_2_dot_0]\n\n# generating initial conditions for some energy E\n\nnumber_of_initial_conditions = 50\n\ntheta_1_0 = []\n# theta_2_0 = []\ntheta_2_0 = np.linspace(-pi/2, pi/2, number_of_initial_conditions)\ntheta_1_dot_0 = []\ntheta_2_dot_0 = []\n\n# Energy = np.linspace(5,5.6,8) # [0,100] 1.\n# Energy = np.linspace(5.6,6.2,8) # [0,300] 2.\n# Energy = np.linspace(6.2,6.4,8) # [0,500] 3.\n# Energy = np.linspace(6.4,6.8,8) # [0,1000] 4.\n# Energy = np.linspace(5.9,6.3,8) # [0,700] 2-3.\n# Energy = np.linspace(6.3,6.8,12) # [0,1200] 3-4.\n# Energy = np.linspace(5.4,6.8,20) # [0,2000] 0.\n# Energy = np.linspace(5.6, 6.4, 16) # [0,700] 2_3\n# Energy = np.linspace(6.2,6.8,18) # [0,1200] 3_4.\n\n# Energy = [5.865]\nEnergy = [6.09]\n# Energy = [6.075]\n# Energy = [6.095]\n# Energy = [6.079]\n# Energy = [6.12]\n\n# number_of_initial_conditions = 1\n\ntotal_numbers_of_initial_conditions = number_of_initial_conditions*len(Energy)\n\ndef initial_conditions(E, number_of_initial_conditions):\n\n for i in range(number_of_initial_conditions):\n theta_1_0.append(0)\n # theta_2_0.append(np.random.uniform(-pi/4, pi/4))\n theta_2_dot_0.append(0)\n bucket = []\n bucket.append(np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n bucket.append(-np.sqrt(2*(E+l_1*g*(m_1+m_2)+l_2*m_2*g*np.cos(theta_2_0[i])-(l_1+l_2)*(m_1+m_2)*g)/(l_1**2*(m_1+m_2))))\n theta_1_dot_0.append(bucket[random.randint(0,1)])\n\nfor i in range(len(Energy)):\n initial_conditions(Energy[i], number_of_initial_conditions)\n\ndef f(t,y):\n return [y[2], \n y[3], \n (-g*np.sin(y[0])*(2*m_1+m_2)-g*m_2*np.sin(y[0]-2*y[1])-2*m_2*np.sin(y[0]-y[1])*(y[2]**2*l_1*np.cos(y[0]-y[1])+l_2*y[3]**2))/(l_1*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1]))), \n (2*np.sin(y[0]-y[1])*(np.cos(y[0])*g*(m_1+m_2)+l_1*(m_1+m_2)*y[2]**2+m_2*l_2*y[3]**2*np.cos(y[0]-y[1])))/(l_2*(2*m_1+m_2-m_2*np.cos(2*y[0]-2*y[1])))]\n\n# energy of the system\ndef E(y_1, y_2, y_3, y_4):\n total_energy = 0.5*l_1**2*y_3**2*(m_1+m_2)+0.5*m_2*l_2**2*y_4**2+m_2*l_1*l_2*y_3*y_4*np.cos(y_1-y_2)-l_1*g*np.cos(y_1)*(m_1+m_2)-l_2*m_2*g*np.cos(y_2)+(l_1+l_2)*g*(m_1+m_2)\n return total_energy\n\n# Poincaré section\ndef Poincare_section(total_numbers_of_initial_conditions):\n theta_2 = []\n theta_2_dot = []\n\n colors = []\n\n color = [\n "#2C3E50", "#3A3F64", "#484078", "#56428D", "#6B469E",\n "#804AAF", "#954EBF", "#A753C4", "#BA58C8", "#CE5DCD",\n "#E062C9", "#E971B4", "#F1809F", "#F98F8A", "#FFA07A",\n "#FF9C65", "#FF9850", "#FF943B", "#FF9026", "#FF8C11",\n "#F97F0D", "#F3730A", "#ED6606", "#E75A03", "#E04E00",\n "#D4431E", "#C8383C", "#BC2D5A", "#B02178", "#A41596",\n "#9710A3", "#880EA7", "#790CAB", "#6A0AAF", "#5C08B2",\n "#4D06B6", "#3E04BA", "#2F02BD", "#2000C1", "#1800B8",\n "#1000AF", "#0800A6", "#00009D", "#00008F", "#000081",\n "#0B006C", "#160057", "#210043", "#2C002E", "#37001A"\n ]\n\n for i in range(total_numbers_of_initial_conditions):\n # color = ["#"+''.join([random.choice('0123456789ABCDEF') for r in range(6)])\n # for s in range(1)]\n\n number_of_points = len(solutions[i].t)\n\n for j in range(number_of_points-1):\n if solutions[i].y[0][j] <= 0 and solutions[i].y[0][j+1] >= 0:\n colors.append(color[i])\n theta_2.append(solutions[i].y[1][j+1])\n theta_2_dot.append(solutions[i].y[3][j+1])\n\n for m in range(len(theta_2)):\n plt.scatter((theta_2[m]+np.pi)%(2 * np.pi) - np.pi, theta_2_dot[m], c=colors[m], s=0.1)\n\n plt.xlabel(r"$\\theta_2\\ [rad]$")\n plt.ylabel(r"$\\dot{\\theta_2}\\ [rad \\cdot s^{-1}]$")\n plt.show()\n\n# solving the equations of motion\nsolutions = []\n\nerror = 0.001\n\n# defining time interval\nt_span = [0,750]\n\nfor i in range(total_numbers_of_initial_conditions):\n y0 = [theta_1_0[i], theta_2_0[i], theta_1_dot_0[i], theta_2_dot_0[i]]\n system_energy = E(y0[0], y0[1], y0[2], y0[3])\n print(y0)\n print(system_energy)\n solutions.append(solve_ivp(f, t_span, y0, dense_output=True, rtol = 1e-12, atol = 1e-14))\n number_of_points = len(solutions[i].t)\n \n for j in range(number_of_points):\n solution_energy = E(solutions[i].y[0][j], solutions[i].y[1][j], solutions[i].y[2][j], solutions[i].y[3][j])\n if np.abs(solution_energy - system_energy) > error:\n sys.exit('Maximum energy drift of {} exceeded.'.format(error))\n\nPoincare_section(total_numbers_of_initial_conditions)\n\nx_1 = []\nx_2 = []\ny_1 = []\ny_2 = []\n\nfor i in range(len(solutions[0].t)):\n x_1.append(l_1*np.sin(solutions[0].y[0][i]))\n x_2.append(x_1[i]+l_2*np.sin(solutions[0].y[1][i]))\n y_1.append(-l_1*np.cos(solutions[0].y[0][i]))\n y_2.append(y_1[i]-l_2*np.cos(solutions[0].y[1][i]))\n\nplt.plot(solutions[0].y[0], solutions[0].y[1])\nplt.xlabel(r"$\\theta_1\\ [rad]$")\nplt.ylabel(r"$\\theta_2\\ [rad]$")\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.show()\nplt.plot(x_2, y_2)\nplt.show()\n\nplt.plot(x_1, y_1)\nplt.plot(x_2, y_2)\nplt.show()\n\nPoincaré section obtained by conditions in the code:\n
EDIT:\nPoincaré section obtained by conditions in the code with labels
Both schemes are implementation variants of the Verlet integration scheme and identical in the position components to it.
\nWikipedia editing has some unfortunate moments of inertia. There is a general resistance to restructuring established long blocks of text, especially if several articles would need to be edited in concert. Then there is a somewhat ingrained tunnel vision for some approaches that is resistant to exhibit short-comings of these approaches (or perhaps that is just saying other people have different preferences). Here there is some popularity in using the method as a quick-n-dirty physics engine, and also as a final illustrative example in a numerics-for-ODE course. The complex of the articles "Verlet integration/Velocity V./Leapfrog V./symplectic Euler" is not very coherent, redundant with some contradictory statements. The German versions are less messy, but do miss some points of content.
\n", "answer_id": 45443, "answer_text": "Both schemes are implementation variants of the Verlet integration scheme and identical in the position components to it.\n\n\n\n\n\nThe Velocity Verlet variant is geared towards the structure of a one-step method, but it is not one in the way that Runge-Kutta methods are.\n\n\n\n\nThe Leapfrog variant emphasizes the order-increasing time symmetries in that the parts can be seen as applications of the midpoint formula. The shifted time grids are also a distinctive mark differentiating this method variant from other numerical integration schemes.\n\n\n\n\n\nWikipedia editing has some unfortunate moments of inertia. There is a general resistance to restructuring established long blocks of text, especially if several articles would need to be edited in concert. Then there is a somewhat ingrained tunnel vision for some approaches that is resistant to exhibit short-comings of these approaches (or perhaps that is just saying other people have different preferences). Here there is some popularity in using the method as a quick-n-dirty physics engine, and also as a final illustrative example in a numerics-for-ODE course. The complex of the articles \"Verlet integration/Velocity V./Leapfrog V./symplectic Euler\" is not very coherent, redundant with some contradictory statements. The German versions are less messy, but do miss some points of content.", "answer_url": "https://scicomp.stackexchange.com/a/45443", "author": "Lutz Lehmann", "author_url": "https://scicomp.stackexchange.com/users/6839/lutz-lehmann", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-05-06T12:51:51+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45230, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lutz Lehmann", "profile_url": "https://scicomp.stackexchange.com/users/6839/lutz-lehmann", "user_type": "registered"}, "created_at": "2026-05-06T12:51:51+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "37834AF7-44CA-4D01-AD34-79CAFC058BBD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/37834AF7-44CA-4D01-AD34-79CAFC058BBD/view-source"}], "score": 1, "updated_at": "2026-05-06T12:51:51+00:00"}], "domain": "computational_science", "external_links": ["https://en.wikipedia.org/wiki/Leapfrog_integration#Algorithm", "https://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "bendkok", "question_author_url": "https://scicomp.stackexchange.com/users/54688/bendkok", "question_author_user_type": "registered", "question_created_at": "2025-09-08T15:10:04+00:00", "question_html": "On the Wikipedia-page for for Verlet integration, under the Velocity Verlet heading it says
\n\n\nA related, and more commonly used algorithm is the velocity Verlet algorithm, similar to the leapfrog method, except that the velocity and position are calculated at the same value of the time variable (leapfrog does not, as the name suggests).
\n
They then give the equations\n\\begin{aligned}\n& \\mathbf{x}(t+\\Delta t)=\\mathbf{x}(t)+\\mathbf{v}(t) \\Delta t+\\frac{1}{2} \\mathbf{a}(t) \\Delta t^2, \\\\\n& \\mathbf{v}(t+\\Delta t)=\\mathbf{v}(t)+\\frac{\\mathbf{a}(t)+\\mathbf{a}(t+\\Delta t)}{2} \\Delta t .\n\\end{aligned}
\nHowever, on the Leapfrog page it gives the equations\n\\begin{aligned}\nx_{i+1} & =x_i+v_i \\Delta t+\\frac{1}{2} a_i \\Delta t^2, \\\\\nv_{i+1} & =v_i+\\frac{1}{2}\\left(a_i+a_{i+1}\\right) \\Delta t .\n\\end{aligned}\nThese seem identical to me. Is there a difference here I am missing? If not, why does the Verlet-page say that they are similar when they actually are identical?
\n", "question_id": 45230, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "On the Wikipedia-page for for Verlet integration, under the Velocity Verlet (https://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet) heading it says\n\n\n\n\n\n\n\nA related, and more commonly used algorithm is the velocity Verlet algorithm, similar to the leapfrog method, except that the velocity and position are calculated at the same value of the time variable (leapfrog does not, as the name suggests).\n\n\n\n\n\n\n\nThey then give the equations\n\\begin{aligned}\n& \\mathbf{x}(t+\\Delta t)=\\mathbf{x}(t)+\\mathbf{v}(t) \\Delta t+\\frac{1}{2} \\mathbf{a}(t) \\Delta t^2, \\\\\n& \\mathbf{v}(t+\\Delta t)=\\mathbf{v}(t)+\\frac{\\mathbf{a}(t)+\\mathbf{a}(t+\\Delta t)}{2} \\Delta t .\n\\end{aligned}\n\n\n\n\nHowever, on the Leapfrog (https://en.wikipedia.org/wiki/Leapfrog_integration#Algorithm) page it gives the equations\n\\begin{aligned}\nx_{i+1} & =x_i+v_i \\Delta t+\\frac{1}{2} a_i \\Delta t^2, \\\\\nv_{i+1} & =v_i+\\frac{1}{2}\\left(a_i+a_{i+1}\\right) \\Delta t .\n\\end{aligned}\nThese seem identical to me. Is there a difference here I am missing? If not, why does the Verlet-page say that they are similar when they actually are identical?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bendkok", "profile_url": "https://scicomp.stackexchange.com/users/54688/bendkok", "user_type": "registered"}, "created_at": "2025-09-08T15:10:04+00:00", "raw_file": "raw/codex_api_v1/8b02bbba3a1a1a633af4866e7fea0bd6789190b52c4b8380b0538b5c670e7131_1790825346551636200_0.json", "raw_sha256": "33050439b68e1f78cef06bf4c2ce07c0ec45a5fdf656fa1a9efd04691108f5e0", "revision_guid": "9C11818B-2F9B-4AE3-9E2B-8DE15DB86ADF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/9C11818B-2F9B-4AE3-9E2B-8DE15DB86ADF/view-source"}], "source_site": "scicomp", "source_url": "https://scicomp.stackexchange.com/questions/45230/are-velocity-verlet-and-leapfrog-identical", "split": "validation", "split_group": "aa1a9291de2e8bca42a8b731ea263fccd057b8408c9b92bcc6ca33e6d21d9d3f", "tags": ["ode", "computational-physics", "numerical-modelling", "time-integration"], "thread_id": "scicomp:45230", "title": "Are Velocity Verlet and Leapfrog Identical?"}} {"citation_context": "On the Wikipedia-page for for Verlet integration, under the Velocity Verlet (https://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet) heading it says\n\n\n\n\n\n\n\nA related, and more commonly used algorithm is the velocity Verlet algorith", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet", "kind": "external_url", "post_id": 45230, "post_url": "https://scicomp.stackexchange.com/questions/45230/are-velocity-verlet-and-leapfrog-identical", "product": "citations", "record_id": "Scientific-Citation-Graph:425dedee0a8e6d5daa29984b", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Both schemes are implementation variants of the Verlet integration scheme and identical in the position components to it.
\nWikipedia editing has some unfortunate moments of inertia. There is a general resistance to restructuring established long blocks of text, especially if several articles would need to be edited in concert. Then there is a somewhat ingrained tunnel vision for some approaches that is resistant to exhibit short-comings of these approaches (or perhaps that is just saying other people have different preferences). Here there is some popularity in using the method as a quick-n-dirty physics engine, and also as a final illustrative example in a numerics-for-ODE course. The complex of the articles "Verlet integration/Velocity V./Leapfrog V./symplectic Euler" is not very coherent, redundant with some contradictory statements. The German versions are less messy, but do miss some points of content.
\n", "answer_id": 45443, "answer_text": "Both schemes are implementation variants of the Verlet integration scheme and identical in the position components to it.\n\n\n\n\n\nThe Velocity Verlet variant is geared towards the structure of a one-step method, but it is not one in the way that Runge-Kutta methods are.\n\n\n\n\nThe Leapfrog variant emphasizes the order-increasing time symmetries in that the parts can be seen as applications of the midpoint formula. The shifted time grids are also a distinctive mark differentiating this method variant from other numerical integration schemes.\n\n\n\n\n\nWikipedia editing has some unfortunate moments of inertia. There is a general resistance to restructuring established long blocks of text, especially if several articles would need to be edited in concert. Then there is a somewhat ingrained tunnel vision for some approaches that is resistant to exhibit short-comings of these approaches (or perhaps that is just saying other people have different preferences). Here there is some popularity in using the method as a quick-n-dirty physics engine, and also as a final illustrative example in a numerics-for-ODE course. The complex of the articles \"Verlet integration/Velocity V./Leapfrog V./symplectic Euler\" is not very coherent, redundant with some contradictory statements. The German versions are less messy, but do miss some points of content.", "answer_url": "https://scicomp.stackexchange.com/a/45443", "author": "Lutz Lehmann", "author_url": "https://scicomp.stackexchange.com/users/6839/lutz-lehmann", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-05-06T12:51:51+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45230, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lutz Lehmann", "profile_url": "https://scicomp.stackexchange.com/users/6839/lutz-lehmann", "user_type": "registered"}, "created_at": "2026-05-06T12:51:51+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "37834AF7-44CA-4D01-AD34-79CAFC058BBD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/37834AF7-44CA-4D01-AD34-79CAFC058BBD/view-source"}], "score": 1, "updated_at": "2026-05-06T12:51:51+00:00"}], "domain": "computational_science", "external_links": ["https://en.wikipedia.org/wiki/Leapfrog_integration#Algorithm", "https://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "bendkok", "question_author_url": "https://scicomp.stackexchange.com/users/54688/bendkok", "question_author_user_type": "registered", "question_created_at": "2025-09-08T15:10:04+00:00", "question_html": "On the Wikipedia-page for for Verlet integration, under the Velocity Verlet heading it says
\n\n\nA related, and more commonly used algorithm is the velocity Verlet algorithm, similar to the leapfrog method, except that the velocity and position are calculated at the same value of the time variable (leapfrog does not, as the name suggests).
\n
They then give the equations\n\\begin{aligned}\n& \\mathbf{x}(t+\\Delta t)=\\mathbf{x}(t)+\\mathbf{v}(t) \\Delta t+\\frac{1}{2} \\mathbf{a}(t) \\Delta t^2, \\\\\n& \\mathbf{v}(t+\\Delta t)=\\mathbf{v}(t)+\\frac{\\mathbf{a}(t)+\\mathbf{a}(t+\\Delta t)}{2} \\Delta t .\n\\end{aligned}
\nHowever, on the Leapfrog page it gives the equations\n\\begin{aligned}\nx_{i+1} & =x_i+v_i \\Delta t+\\frac{1}{2} a_i \\Delta t^2, \\\\\nv_{i+1} & =v_i+\\frac{1}{2}\\left(a_i+a_{i+1}\\right) \\Delta t .\n\\end{aligned}\nThese seem identical to me. Is there a difference here I am missing? If not, why does the Verlet-page say that they are similar when they actually are identical?
\n", "question_id": 45230, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "On the Wikipedia-page for for Verlet integration, under the Velocity Verlet (https://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet) heading it says\n\n\n\n\n\n\n\nA related, and more commonly used algorithm is the velocity Verlet algorithm, similar to the leapfrog method, except that the velocity and position are calculated at the same value of the time variable (leapfrog does not, as the name suggests).\n\n\n\n\n\n\n\nThey then give the equations\n\\begin{aligned}\n& \\mathbf{x}(t+\\Delta t)=\\mathbf{x}(t)+\\mathbf{v}(t) \\Delta t+\\frac{1}{2} \\mathbf{a}(t) \\Delta t^2, \\\\\n& \\mathbf{v}(t+\\Delta t)=\\mathbf{v}(t)+\\frac{\\mathbf{a}(t)+\\mathbf{a}(t+\\Delta t)}{2} \\Delta t .\n\\end{aligned}\n\n\n\n\nHowever, on the Leapfrog (https://en.wikipedia.org/wiki/Leapfrog_integration#Algorithm) page it gives the equations\n\\begin{aligned}\nx_{i+1} & =x_i+v_i \\Delta t+\\frac{1}{2} a_i \\Delta t^2, \\\\\nv_{i+1} & =v_i+\\frac{1}{2}\\left(a_i+a_{i+1}\\right) \\Delta t .\n\\end{aligned}\nThese seem identical to me. Is there a difference here I am missing? If not, why does the Verlet-page say that they are similar when they actually are identical?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bendkok", "profile_url": "https://scicomp.stackexchange.com/users/54688/bendkok", "user_type": "registered"}, "created_at": "2025-09-08T15:10:04+00:00", "raw_file": "raw/codex_api_v1/8b02bbba3a1a1a633af4866e7fea0bd6789190b52c4b8380b0538b5c670e7131_1790825346551636200_0.json", "raw_sha256": "33050439b68e1f78cef06bf4c2ce07c0ec45a5fdf656fa1a9efd04691108f5e0", "revision_guid": "9C11818B-2F9B-4AE3-9E2B-8DE15DB86ADF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/9C11818B-2F9B-4AE3-9E2B-8DE15DB86ADF/view-source"}], "source_site": "scicomp", "source_url": "https://scicomp.stackexchange.com/questions/45230/are-velocity-verlet-and-leapfrog-identical", "split": "validation", "split_group": "aa1a9291de2e8bca42a8b731ea263fccd057b8408c9b92bcc6ca33e6d21d9d3f", "tags": ["ode", "computational-physics", "numerical-modelling", "time-integration"], "thread_id": "scicomp:45230", "title": "Are Velocity Verlet and Leapfrog Identical?"}} {"citation_context": "inear Algebra / Sparse libraries.\n\n\n\n\nCurrently my approach is to use Dykstra Projection Algorithm (https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm).\n\nI wonder if there are some acceleration tricks.", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm", "kind": "external_url", "post_id": 45263, "post_url": "https://scicomp.stackexchange.com/questions/45263/solve-projection-problem-with-linear-equality-and-box-constraints", "product": "citations", "record_id": "Scientific-Citation-Graph:f106783ddb3bedfb0fc44cda", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The Dykstra Projection Algorithm is basically the ADMM Framework.
\nHence my idea is to use adaptive $\\rho$ parameter according to the different relative errors as in Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers in part 3.4.
Assuming the matrix $\\boldsymbol{A}$ is dense:
\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\nRemark: I'd be happy to see an efficient case of the Sparse case.
\n", "answer_id": 45265, "answer_text": "Assuming the matrix $\\boldsymbol{A}$ is dense:\n\n\n\n\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\n\n\n\n\nRemark: I'd be happy to see an efficient case of the Sparse case.", "answer_url": "https://scicomp.stackexchange.com/a/45265", "author": "Royi", "author_url": "https://scicomp.stackexchange.com/users/7951/royi", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T12:41:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Royi", "profile_url": "https://scicomp.stackexchange.com/users/7951/royi", "user_type": "registered"}, "created_at": "2025-10-25T12:41:28+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DEFDA34D-10C0-48A1-B4C0-85196E02AF64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/DEFDA34D-10C0-48A1-B4C0-85196E02AF64/view-source"}], "score": 1, "updated_at": "2025-10-25T12:41:28+00:00"}, {"answer_html": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] and its associated implementation in scipy.optimize.minimize(method='trust-constr'). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.
\nSet:
\nsparse_jacobian = Truefactorization_method = 'AugmentedSystem'jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.bounds by your $l$ and $u$constraints to a LinearConstraint by your $A$ and using a scipy sparse arrayx0 to a sensible initial estimateIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.
\n\n", "answer_id": 45266, "answer_text": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] (https://epubs.siam.org/doi/book/10.1137/1.9780898719857) and its associated implementation in scipy.optimize.minimize(method='trust-constr') (https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.\n\n\n\n\nSet:\n\n\n\n\n\nsparse_jacobian = True\n\n\n\n\nfactorization_method = 'AugmentedSystem'\n\n\n\n\nYour jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.\n\n\n\n\nIn the upper-level minimize (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) interface, bounds by your $l$ and $u$\n\n\n\n\nconstraints to a LinearConstraint (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html) by your $A$ and using a scipy sparse array\n\n\n\n\nx0 to a sensible initial estimate\n\n\n\n\n\nIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.\n\n\n\n\n[image: convergence; source: https://i.sstatic.net/YJ8UEXx7.png] (https://i.sstatic.net/YJ8UEXx7.png)", "answer_url": "https://scicomp.stackexchange.com/a/45266", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T13:17:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T13:17:14+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "77444703-E320-475F-B89E-303773BDEE64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/77444703-E320-475F-B89E-303773BDEE64/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:40:38+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "C04032E9-FCDC-40CF-857D-605E6541C00E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/C04032E9-FCDC-40CF-857D-605E6541C00E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:54:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "09D74CCF-7C0C-4138-9B77-B959EBA73CBB", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/09D74CCF-7C0C-4138-9B77-B959EBA73CBB/view-source"}], "score": 2, "updated_at": "2025-10-25T19:54:56+00:00"}], "domain": "computational_science", "external_links": ["https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html", "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html", "https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html", "https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm", "https://epubs.siam.org/doi/book/10.1137/1.9780898719857", "https://i.sstatic.net/YJ8UEXx7.png", "https://web.stanford.edu/%7Eboyd/papers/admm_distr_stats.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Royi", "question_author_url": "https://scicomp.stackexchange.com/users/7951/royi", "question_author_user_type": "registered", "question_created_at": "2025-10-25T07:56:29+00:00", "question_html": "Solve the following problem:
\n$$\n\\begin{alignat*}{3}\n\\arg \\min_{ \\boldsymbol{x} } & \\quad & \\frac{1}{2} \\left\\| \\boldsymbol{x} - \\boldsymbol{y} \\right\\|_{2}^{2} \\\\\n\\text{subject to} & \\quad & \\boldsymbol{A} \\boldsymbol{x} = \\boldsymbol{b} \\\\\n& \\quad & \\boldsymbol{x} \\leq \\boldsymbol{u} \\\\\n& \\quad & \\boldsymbol{x} \\geq \\boldsymbol{l} \\\\\n\\end{alignat*}\n$$
\nWhere $\\boldsymbol{A} \\in \\mathbb{R}^{m \\times n}, \\; n \\gg m$ with independent rows.
\nI want to solve it for the cases:
\nIn most efficient way without using high level solvers.
\nBut just Use MATLAB / Python / Julia with their own Linear Algebra / Sparse libraries.
Currently my approach is to use Dykstra Projection Algorithm.
\nI wonder if there are some acceleration tricks.
The Dykstra Projection Algorithm is basically the ADMM Framework.
\nHence my idea is to use adaptive $\\rho$ parameter according to the different relative errors as in Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers in part 3.4.
Assuming the matrix $\\boldsymbol{A}$ is dense:
\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\nRemark: I'd be happy to see an efficient case of the Sparse case.
\n", "answer_id": 45265, "answer_text": "Assuming the matrix $\\boldsymbol{A}$ is dense:\n\n\n\n\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\n\n\n\n\nRemark: I'd be happy to see an efficient case of the Sparse case.", "answer_url": "https://scicomp.stackexchange.com/a/45265", "author": "Royi", "author_url": "https://scicomp.stackexchange.com/users/7951/royi", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T12:41:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Royi", "profile_url": "https://scicomp.stackexchange.com/users/7951/royi", "user_type": "registered"}, "created_at": "2025-10-25T12:41:28+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DEFDA34D-10C0-48A1-B4C0-85196E02AF64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/DEFDA34D-10C0-48A1-B4C0-85196E02AF64/view-source"}], "score": 1, "updated_at": "2025-10-25T12:41:28+00:00"}, {"answer_html": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] and its associated implementation in scipy.optimize.minimize(method='trust-constr'). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.
\nSet:
\nsparse_jacobian = Truefactorization_method = 'AugmentedSystem'jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.bounds by your $l$ and $u$constraints to a LinearConstraint by your $A$ and using a scipy sparse arrayx0 to a sensible initial estimateIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.
\n\n", "answer_id": 45266, "answer_text": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] (https://epubs.siam.org/doi/book/10.1137/1.9780898719857) and its associated implementation in scipy.optimize.minimize(method='trust-constr') (https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.\n\n\n\n\nSet:\n\n\n\n\n\nsparse_jacobian = True\n\n\n\n\nfactorization_method = 'AugmentedSystem'\n\n\n\n\nYour jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.\n\n\n\n\nIn the upper-level minimize (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) interface, bounds by your $l$ and $u$\n\n\n\n\nconstraints to a LinearConstraint (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html) by your $A$ and using a scipy sparse array\n\n\n\n\nx0 to a sensible initial estimate\n\n\n\n\n\nIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.\n\n\n\n\n[image: convergence; source: https://i.sstatic.net/YJ8UEXx7.png] (https://i.sstatic.net/YJ8UEXx7.png)", "answer_url": "https://scicomp.stackexchange.com/a/45266", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T13:17:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T13:17:14+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "77444703-E320-475F-B89E-303773BDEE64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/77444703-E320-475F-B89E-303773BDEE64/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:40:38+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "C04032E9-FCDC-40CF-857D-605E6541C00E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/C04032E9-FCDC-40CF-857D-605E6541C00E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:54:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "09D74CCF-7C0C-4138-9B77-B959EBA73CBB", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/09D74CCF-7C0C-4138-9B77-B959EBA73CBB/view-source"}], "score": 2, "updated_at": "2025-10-25T19:54:56+00:00"}], "domain": "computational_science", "external_links": ["https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html", "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html", "https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html", "https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm", "https://epubs.siam.org/doi/book/10.1137/1.9780898719857", "https://i.sstatic.net/YJ8UEXx7.png", "https://web.stanford.edu/%7Eboyd/papers/admm_distr_stats.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Royi", "question_author_url": "https://scicomp.stackexchange.com/users/7951/royi", "question_author_user_type": "registered", "question_created_at": "2025-10-25T07:56:29+00:00", "question_html": "Solve the following problem:
\n$$\n\\begin{alignat*}{3}\n\\arg \\min_{ \\boldsymbol{x} } & \\quad & \\frac{1}{2} \\left\\| \\boldsymbol{x} - \\boldsymbol{y} \\right\\|_{2}^{2} \\\\\n\\text{subject to} & \\quad & \\boldsymbol{A} \\boldsymbol{x} = \\boldsymbol{b} \\\\\n& \\quad & \\boldsymbol{x} \\leq \\boldsymbol{u} \\\\\n& \\quad & \\boldsymbol{x} \\geq \\boldsymbol{l} \\\\\n\\end{alignat*}\n$$
\nWhere $\\boldsymbol{A} \\in \\mathbb{R}^{m \\times n}, \\; n \\gg m$ with independent rows.
\nI want to solve it for the cases:
\nIn most efficient way without using high level solvers.
\nBut just Use MATLAB / Python / Julia with their own Linear Algebra / Sparse libraries.
Currently my approach is to use Dykstra Projection Algorithm.
\nI wonder if there are some acceleration tricks.
The Dykstra Projection Algorithm is basically the ADMM Framework.
\nHence my idea is to use adaptive $\\rho$ parameter according to the different relative errors as in Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers in part 3.4.
Assuming the matrix $\\boldsymbol{A}$ is dense:
\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\nRemark: I'd be happy to see an efficient case of the Sparse case.
\n", "answer_id": 45265, "answer_text": "Assuming the matrix $\\boldsymbol{A}$ is dense:\n\n\n\n\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\n\n\n\n\nRemark: I'd be happy to see an efficient case of the Sparse case.", "answer_url": "https://scicomp.stackexchange.com/a/45265", "author": "Royi", "author_url": "https://scicomp.stackexchange.com/users/7951/royi", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T12:41:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Royi", "profile_url": "https://scicomp.stackexchange.com/users/7951/royi", "user_type": "registered"}, "created_at": "2025-10-25T12:41:28+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DEFDA34D-10C0-48A1-B4C0-85196E02AF64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/DEFDA34D-10C0-48A1-B4C0-85196E02AF64/view-source"}], "score": 1, "updated_at": "2025-10-25T12:41:28+00:00"}, {"answer_html": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] and its associated implementation in scipy.optimize.minimize(method='trust-constr'). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.
\nSet:
\nsparse_jacobian = Truefactorization_method = 'AugmentedSystem'jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.bounds by your $l$ and $u$constraints to a LinearConstraint by your $A$ and using a scipy sparse arrayx0 to a sensible initial estimateIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.
\n\n", "answer_id": 45266, "answer_text": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] (https://epubs.siam.org/doi/book/10.1137/1.9780898719857) and its associated implementation in scipy.optimize.minimize(method='trust-constr') (https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.\n\n\n\n\nSet:\n\n\n\n\n\nsparse_jacobian = True\n\n\n\n\nfactorization_method = 'AugmentedSystem'\n\n\n\n\nYour jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.\n\n\n\n\nIn the upper-level minimize (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) interface, bounds by your $l$ and $u$\n\n\n\n\nconstraints to a LinearConstraint (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html) by your $A$ and using a scipy sparse array\n\n\n\n\nx0 to a sensible initial estimate\n\n\n\n\n\nIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.\n\n\n\n\n[image: convergence; source: https://i.sstatic.net/YJ8UEXx7.png] (https://i.sstatic.net/YJ8UEXx7.png)", "answer_url": "https://scicomp.stackexchange.com/a/45266", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T13:17:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T13:17:14+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "77444703-E320-475F-B89E-303773BDEE64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/77444703-E320-475F-B89E-303773BDEE64/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:40:38+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "C04032E9-FCDC-40CF-857D-605E6541C00E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/C04032E9-FCDC-40CF-857D-605E6541C00E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:54:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "09D74CCF-7C0C-4138-9B77-B959EBA73CBB", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/09D74CCF-7C0C-4138-9B77-B959EBA73CBB/view-source"}], "score": 2, "updated_at": "2025-10-25T19:54:56+00:00"}], "domain": "computational_science", "external_links": ["https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html", "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html", "https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html", "https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm", "https://epubs.siam.org/doi/book/10.1137/1.9780898719857", "https://i.sstatic.net/YJ8UEXx7.png", "https://web.stanford.edu/%7Eboyd/papers/admm_distr_stats.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Royi", "question_author_url": "https://scicomp.stackexchange.com/users/7951/royi", "question_author_user_type": "registered", "question_created_at": "2025-10-25T07:56:29+00:00", "question_html": "Solve the following problem:
\n$$\n\\begin{alignat*}{3}\n\\arg \\min_{ \\boldsymbol{x} } & \\quad & \\frac{1}{2} \\left\\| \\boldsymbol{x} - \\boldsymbol{y} \\right\\|_{2}^{2} \\\\\n\\text{subject to} & \\quad & \\boldsymbol{A} \\boldsymbol{x} = \\boldsymbol{b} \\\\\n& \\quad & \\boldsymbol{x} \\leq \\boldsymbol{u} \\\\\n& \\quad & \\boldsymbol{x} \\geq \\boldsymbol{l} \\\\\n\\end{alignat*}\n$$
\nWhere $\\boldsymbol{A} \\in \\mathbb{R}^{m \\times n}, \\; n \\gg m$ with independent rows.
\nI want to solve it for the cases:
\nIn most efficient way without using high level solvers.
\nBut just Use MATLAB / Python / Julia with their own Linear Algebra / Sparse libraries.
Currently my approach is to use Dykstra Projection Algorithm.
\nI wonder if there are some acceleration tricks.
The Dykstra Projection Algorithm is basically the ADMM Framework.
\nHence my idea is to use adaptive $\\rho$ parameter according to the different relative errors as in Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers in part 3.4.
Assuming the matrix $\\boldsymbol{A}$ is dense:
\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\nRemark: I'd be happy to see an efficient case of the Sparse case.
\n", "answer_id": 45265, "answer_text": "Assuming the matrix $\\boldsymbol{A}$ is dense:\n\n\n\n\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\n\n\n\n\nRemark: I'd be happy to see an efficient case of the Sparse case.", "answer_url": "https://scicomp.stackexchange.com/a/45265", "author": "Royi", "author_url": "https://scicomp.stackexchange.com/users/7951/royi", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T12:41:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Royi", "profile_url": "https://scicomp.stackexchange.com/users/7951/royi", "user_type": "registered"}, "created_at": "2025-10-25T12:41:28+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DEFDA34D-10C0-48A1-B4C0-85196E02AF64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/DEFDA34D-10C0-48A1-B4C0-85196E02AF64/view-source"}], "score": 1, "updated_at": "2025-10-25T12:41:28+00:00"}, {"answer_html": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] and its associated implementation in scipy.optimize.minimize(method='trust-constr'). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.
\nSet:
\nsparse_jacobian = Truefactorization_method = 'AugmentedSystem'jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.bounds by your $l$ and $u$constraints to a LinearConstraint by your $A$ and using a scipy sparse arrayx0 to a sensible initial estimateIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.
\n\n", "answer_id": 45266, "answer_text": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] (https://epubs.siam.org/doi/book/10.1137/1.9780898719857) and its associated implementation in scipy.optimize.minimize(method='trust-constr') (https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.\n\n\n\n\nSet:\n\n\n\n\n\nsparse_jacobian = True\n\n\n\n\nfactorization_method = 'AugmentedSystem'\n\n\n\n\nYour jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.\n\n\n\n\nIn the upper-level minimize (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) interface, bounds by your $l$ and $u$\n\n\n\n\nconstraints to a LinearConstraint (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html) by your $A$ and using a scipy sparse array\n\n\n\n\nx0 to a sensible initial estimate\n\n\n\n\n\nIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.\n\n\n\n\n[image: convergence; source: https://i.sstatic.net/YJ8UEXx7.png] (https://i.sstatic.net/YJ8UEXx7.png)", "answer_url": "https://scicomp.stackexchange.com/a/45266", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T13:17:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T13:17:14+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "77444703-E320-475F-B89E-303773BDEE64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/77444703-E320-475F-B89E-303773BDEE64/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:40:38+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "C04032E9-FCDC-40CF-857D-605E6541C00E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/C04032E9-FCDC-40CF-857D-605E6541C00E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:54:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "09D74CCF-7C0C-4138-9B77-B959EBA73CBB", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/09D74CCF-7C0C-4138-9B77-B959EBA73CBB/view-source"}], "score": 2, "updated_at": "2025-10-25T19:54:56+00:00"}], "domain": "computational_science", "external_links": ["https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html", "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html", "https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html", "https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm", "https://epubs.siam.org/doi/book/10.1137/1.9780898719857", "https://i.sstatic.net/YJ8UEXx7.png", "https://web.stanford.edu/%7Eboyd/papers/admm_distr_stats.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Royi", "question_author_url": "https://scicomp.stackexchange.com/users/7951/royi", "question_author_user_type": "registered", "question_created_at": "2025-10-25T07:56:29+00:00", "question_html": "Solve the following problem:
\n$$\n\\begin{alignat*}{3}\n\\arg \\min_{ \\boldsymbol{x} } & \\quad & \\frac{1}{2} \\left\\| \\boldsymbol{x} - \\boldsymbol{y} \\right\\|_{2}^{2} \\\\\n\\text{subject to} & \\quad & \\boldsymbol{A} \\boldsymbol{x} = \\boldsymbol{b} \\\\\n& \\quad & \\boldsymbol{x} \\leq \\boldsymbol{u} \\\\\n& \\quad & \\boldsymbol{x} \\geq \\boldsymbol{l} \\\\\n\\end{alignat*}\n$$
\nWhere $\\boldsymbol{A} \\in \\mathbb{R}^{m \\times n}, \\; n \\gg m$ with independent rows.
\nI want to solve it for the cases:
\nIn most efficient way without using high level solvers.
\nBut just Use MATLAB / Python / Julia with their own Linear Algebra / Sparse libraries.
Currently my approach is to use Dykstra Projection Algorithm.
\nI wonder if there are some acceleration tricks.
The Dykstra Projection Algorithm is basically the ADMM Framework.
\nHence my idea is to use adaptive $\\rho$ parameter according to the different relative errors as in Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers in part 3.4.
Assuming the matrix $\\boldsymbol{A}$ is dense:
\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\nRemark: I'd be happy to see an efficient case of the Sparse case.
\n", "answer_id": 45265, "answer_text": "Assuming the matrix $\\boldsymbol{A}$ is dense:\n\n\n\n\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\n\n\n\n\nRemark: I'd be happy to see an efficient case of the Sparse case.", "answer_url": "https://scicomp.stackexchange.com/a/45265", "author": "Royi", "author_url": "https://scicomp.stackexchange.com/users/7951/royi", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T12:41:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Royi", "profile_url": "https://scicomp.stackexchange.com/users/7951/royi", "user_type": "registered"}, "created_at": "2025-10-25T12:41:28+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DEFDA34D-10C0-48A1-B4C0-85196E02AF64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/DEFDA34D-10C0-48A1-B4C0-85196E02AF64/view-source"}], "score": 1, "updated_at": "2025-10-25T12:41:28+00:00"}, {"answer_html": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] and its associated implementation in scipy.optimize.minimize(method='trust-constr'). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.
\nSet:
\nsparse_jacobian = Truefactorization_method = 'AugmentedSystem'jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.bounds by your $l$ and $u$constraints to a LinearConstraint by your $A$ and using a scipy sparse arrayx0 to a sensible initial estimateIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.
\n\n", "answer_id": 45266, "answer_text": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] (https://epubs.siam.org/doi/book/10.1137/1.9780898719857) and its associated implementation in scipy.optimize.minimize(method='trust-constr') (https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.\n\n\n\n\nSet:\n\n\n\n\n\nsparse_jacobian = True\n\n\n\n\nfactorization_method = 'AugmentedSystem'\n\n\n\n\nYour jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.\n\n\n\n\nIn the upper-level minimize (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) interface, bounds by your $l$ and $u$\n\n\n\n\nconstraints to a LinearConstraint (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html) by your $A$ and using a scipy sparse array\n\n\n\n\nx0 to a sensible initial estimate\n\n\n\n\n\nIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.\n\n\n\n\n[image: convergence; source: https://i.sstatic.net/YJ8UEXx7.png] (https://i.sstatic.net/YJ8UEXx7.png)", "answer_url": "https://scicomp.stackexchange.com/a/45266", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T13:17:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T13:17:14+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "77444703-E320-475F-B89E-303773BDEE64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/77444703-E320-475F-B89E-303773BDEE64/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:40:38+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "C04032E9-FCDC-40CF-857D-605E6541C00E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/C04032E9-FCDC-40CF-857D-605E6541C00E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:54:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "09D74CCF-7C0C-4138-9B77-B959EBA73CBB", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/09D74CCF-7C0C-4138-9B77-B959EBA73CBB/view-source"}], "score": 2, "updated_at": "2025-10-25T19:54:56+00:00"}], "domain": "computational_science", "external_links": ["https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html", "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html", "https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html", "https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm", "https://epubs.siam.org/doi/book/10.1137/1.9780898719857", "https://i.sstatic.net/YJ8UEXx7.png", "https://web.stanford.edu/%7Eboyd/papers/admm_distr_stats.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Royi", "question_author_url": "https://scicomp.stackexchange.com/users/7951/royi", "question_author_user_type": "registered", "question_created_at": "2025-10-25T07:56:29+00:00", "question_html": "Solve the following problem:
\n$$\n\\begin{alignat*}{3}\n\\arg \\min_{ \\boldsymbol{x} } & \\quad & \\frac{1}{2} \\left\\| \\boldsymbol{x} - \\boldsymbol{y} \\right\\|_{2}^{2} \\\\\n\\text{subject to} & \\quad & \\boldsymbol{A} \\boldsymbol{x} = \\boldsymbol{b} \\\\\n& \\quad & \\boldsymbol{x} \\leq \\boldsymbol{u} \\\\\n& \\quad & \\boldsymbol{x} \\geq \\boldsymbol{l} \\\\\n\\end{alignat*}\n$$
\nWhere $\\boldsymbol{A} \\in \\mathbb{R}^{m \\times n}, \\; n \\gg m$ with independent rows.
\nI want to solve it for the cases:
\nIn most efficient way without using high level solvers.
\nBut just Use MATLAB / Python / Julia with their own Linear Algebra / Sparse libraries.
Currently my approach is to use Dykstra Projection Algorithm.
\nI wonder if there are some acceleration tricks.
The Dykstra Projection Algorithm is basically the ADMM Framework.
\nHence my idea is to use adaptive $\\rho$ parameter according to the different relative errors as in Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers in part 3.4.
Assuming the matrix $\\boldsymbol{A}$ is dense:
\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\nRemark: I'd be happy to see an efficient case of the Sparse case.
\n", "answer_id": 45265, "answer_text": "Assuming the matrix $\\boldsymbol{A}$ is dense:\n\n\n\n\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\n\n\n\n\nRemark: I'd be happy to see an efficient case of the Sparse case.", "answer_url": "https://scicomp.stackexchange.com/a/45265", "author": "Royi", "author_url": "https://scicomp.stackexchange.com/users/7951/royi", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T12:41:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Royi", "profile_url": "https://scicomp.stackexchange.com/users/7951/royi", "user_type": "registered"}, "created_at": "2025-10-25T12:41:28+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DEFDA34D-10C0-48A1-B4C0-85196E02AF64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/DEFDA34D-10C0-48A1-B4C0-85196E02AF64/view-source"}], "score": 1, "updated_at": "2025-10-25T12:41:28+00:00"}, {"answer_html": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] and its associated implementation in scipy.optimize.minimize(method='trust-constr'). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.
\nSet:
\nsparse_jacobian = Truefactorization_method = 'AugmentedSystem'jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.bounds by your $l$ and $u$constraints to a LinearConstraint by your $A$ and using a scipy sparse arrayx0 to a sensible initial estimateIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.
\n\n", "answer_id": 45266, "answer_text": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] (https://epubs.siam.org/doi/book/10.1137/1.9780898719857) and its associated implementation in scipy.optimize.minimize(method='trust-constr') (https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.\n\n\n\n\nSet:\n\n\n\n\n\nsparse_jacobian = True\n\n\n\n\nfactorization_method = 'AugmentedSystem'\n\n\n\n\nYour jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.\n\n\n\n\nIn the upper-level minimize (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) interface, bounds by your $l$ and $u$\n\n\n\n\nconstraints to a LinearConstraint (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html) by your $A$ and using a scipy sparse array\n\n\n\n\nx0 to a sensible initial estimate\n\n\n\n\n\nIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.\n\n\n\n\n[image: convergence; source: https://i.sstatic.net/YJ8UEXx7.png] (https://i.sstatic.net/YJ8UEXx7.png)", "answer_url": "https://scicomp.stackexchange.com/a/45266", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T13:17:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T13:17:14+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "77444703-E320-475F-B89E-303773BDEE64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/77444703-E320-475F-B89E-303773BDEE64/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:40:38+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "C04032E9-FCDC-40CF-857D-605E6541C00E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/C04032E9-FCDC-40CF-857D-605E6541C00E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:54:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "09D74CCF-7C0C-4138-9B77-B959EBA73CBB", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/09D74CCF-7C0C-4138-9B77-B959EBA73CBB/view-source"}], "score": 2, "updated_at": "2025-10-25T19:54:56+00:00"}], "domain": "computational_science", "external_links": ["https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html", "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html", "https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html", "https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm", "https://epubs.siam.org/doi/book/10.1137/1.9780898719857", "https://i.sstatic.net/YJ8UEXx7.png", "https://web.stanford.edu/%7Eboyd/papers/admm_distr_stats.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Royi", "question_author_url": "https://scicomp.stackexchange.com/users/7951/royi", "question_author_user_type": "registered", "question_created_at": "2025-10-25T07:56:29+00:00", "question_html": "Solve the following problem:
\n$$\n\\begin{alignat*}{3}\n\\arg \\min_{ \\boldsymbol{x} } & \\quad & \\frac{1}{2} \\left\\| \\boldsymbol{x} - \\boldsymbol{y} \\right\\|_{2}^{2} \\\\\n\\text{subject to} & \\quad & \\boldsymbol{A} \\boldsymbol{x} = \\boldsymbol{b} \\\\\n& \\quad & \\boldsymbol{x} \\leq \\boldsymbol{u} \\\\\n& \\quad & \\boldsymbol{x} \\geq \\boldsymbol{l} \\\\\n\\end{alignat*}\n$$
\nWhere $\\boldsymbol{A} \\in \\mathbb{R}^{m \\times n}, \\; n \\gg m$ with independent rows.
\nI want to solve it for the cases:
\nIn most efficient way without using high level solvers.
\nBut just Use MATLAB / Python / Julia with their own Linear Algebra / Sparse libraries.
Currently my approach is to use Dykstra Projection Algorithm.
\nI wonder if there are some acceleration tricks.
The Dykstra Projection Algorithm is basically the ADMM Framework.
\nHence my idea is to use adaptive $\\rho$ parameter according to the different relative errors as in Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers in part 3.4.
Assuming the matrix $\\boldsymbol{A}$ is dense:
\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\nRemark: I'd be happy to see an efficient case of the Sparse case.
\n", "answer_id": 45265, "answer_text": "Assuming the matrix $\\boldsymbol{A}$ is dense:\n\n\n\n\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\n\n\n\n\nRemark: I'd be happy to see an efficient case of the Sparse case.", "answer_url": "https://scicomp.stackexchange.com/a/45265", "author": "Royi", "author_url": "https://scicomp.stackexchange.com/users/7951/royi", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T12:41:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Royi", "profile_url": "https://scicomp.stackexchange.com/users/7951/royi", "user_type": "registered"}, "created_at": "2025-10-25T12:41:28+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DEFDA34D-10C0-48A1-B4C0-85196E02AF64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/DEFDA34D-10C0-48A1-B4C0-85196E02AF64/view-source"}], "score": 1, "updated_at": "2025-10-25T12:41:28+00:00"}, {"answer_html": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] and its associated implementation in scipy.optimize.minimize(method='trust-constr'). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.
\nSet:
\nsparse_jacobian = Truefactorization_method = 'AugmentedSystem'jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.bounds by your $l$ and $u$constraints to a LinearConstraint by your $A$ and using a scipy sparse arrayx0 to a sensible initial estimateIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.
\n\n", "answer_id": 45266, "answer_text": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] (https://epubs.siam.org/doi/book/10.1137/1.9780898719857) and its associated implementation in scipy.optimize.minimize(method='trust-constr') (https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.\n\n\n\n\nSet:\n\n\n\n\n\nsparse_jacobian = True\n\n\n\n\nfactorization_method = 'AugmentedSystem'\n\n\n\n\nYour jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.\n\n\n\n\nIn the upper-level minimize (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) interface, bounds by your $l$ and $u$\n\n\n\n\nconstraints to a LinearConstraint (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html) by your $A$ and using a scipy sparse array\n\n\n\n\nx0 to a sensible initial estimate\n\n\n\n\n\nIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.\n\n\n\n\n[image: convergence; source: https://i.sstatic.net/YJ8UEXx7.png] (https://i.sstatic.net/YJ8UEXx7.png)", "answer_url": "https://scicomp.stackexchange.com/a/45266", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T13:17:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T13:17:14+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "77444703-E320-475F-B89E-303773BDEE64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/77444703-E320-475F-B89E-303773BDEE64/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:40:38+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "C04032E9-FCDC-40CF-857D-605E6541C00E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/C04032E9-FCDC-40CF-857D-605E6541C00E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:54:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "09D74CCF-7C0C-4138-9B77-B959EBA73CBB", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/09D74CCF-7C0C-4138-9B77-B959EBA73CBB/view-source"}], "score": 2, "updated_at": "2025-10-25T19:54:56+00:00"}], "domain": "computational_science", "external_links": ["https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html", "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html", "https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html", "https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm", "https://epubs.siam.org/doi/book/10.1137/1.9780898719857", "https://i.sstatic.net/YJ8UEXx7.png", "https://web.stanford.edu/%7Eboyd/papers/admm_distr_stats.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Royi", "question_author_url": "https://scicomp.stackexchange.com/users/7951/royi", "question_author_user_type": "registered", "question_created_at": "2025-10-25T07:56:29+00:00", "question_html": "Solve the following problem:
\n$$\n\\begin{alignat*}{3}\n\\arg \\min_{ \\boldsymbol{x} } & \\quad & \\frac{1}{2} \\left\\| \\boldsymbol{x} - \\boldsymbol{y} \\right\\|_{2}^{2} \\\\\n\\text{subject to} & \\quad & \\boldsymbol{A} \\boldsymbol{x} = \\boldsymbol{b} \\\\\n& \\quad & \\boldsymbol{x} \\leq \\boldsymbol{u} \\\\\n& \\quad & \\boldsymbol{x} \\geq \\boldsymbol{l} \\\\\n\\end{alignat*}\n$$
\nWhere $\\boldsymbol{A} \\in \\mathbb{R}^{m \\times n}, \\; n \\gg m$ with independent rows.
\nI want to solve it for the cases:
\nIn most efficient way without using high level solvers.
\nBut just Use MATLAB / Python / Julia with their own Linear Algebra / Sparse libraries.
Currently my approach is to use Dykstra Projection Algorithm.
\nI wonder if there are some acceleration tricks.
The Dykstra Projection Algorithm is basically the ADMM Framework.
\nHence my idea is to use adaptive $\\rho$ parameter according to the different relative errors as in Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers in part 3.4.
Assuming the matrix $\\boldsymbol{A}$ is dense:
\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\nRemark: I'd be happy to see an efficient case of the Sparse case.
\n", "answer_id": 45265, "answer_text": "Assuming the matrix $\\boldsymbol{A}$ is dense:\n\n\n\n\nfunction SolveDysktra( vY :: Vector{T}, mA :: Matrix{T}, vB :: Vector{T}, vL :: Vector{T}, vU :: Vector{T}; numIterations = 100 ) where {T <: AbstractFloat}\n\n numElements = length(vY);\n vX = copy(vY);\n vZ = zeros(T, numElements);\n vP = zeros(T, numElements);\n vQ = zeros(T, numElements);\n vT = zeros(T, numElements);\n\n sSvd = svd(mA);\n mVV = sSvd.V * sSvd.Vt;\n # mVS⁺Uᵗ = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U';\n\n vBB = sSvd.V * Diagonal(inv.(sSvd.S)) * sSvd.U' * vB;\n \n for _ in 1:numIterations\n\n vZ .= vX .+ vP;\n # Project `vZ` onto the Linear Equality\n mul!(vT, mVV, vZ);\n # vZ .= vZ .- vT .+ vBB;\n vZ .+= vBB .- vT;\n\n vP .+= vX .- vZ;\n\n vX .= vZ .+ vQ;\n # Project `vX` onto the Box Constraints\n vX .= clamp.(vX, vL, vU);\n vQ .+= vZ .- vX;\n\n end\n\n return vX;\n\nend\n\n\n\n\n\nRemark: I'd be happy to see an efficient case of the Sparse case.", "answer_url": "https://scicomp.stackexchange.com/a/45265", "author": "Royi", "author_url": "https://scicomp.stackexchange.com/users/7951/royi", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T12:41:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Royi", "profile_url": "https://scicomp.stackexchange.com/users/7951/royi", "user_type": "registered"}, "created_at": "2025-10-25T12:41:28+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DEFDA34D-10C0-48A1-B4C0-85196E02AF64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/DEFDA34D-10C0-48A1-B4C0-85196E02AF64/view-source"}], "score": 1, "updated_at": "2025-10-25T12:41:28+00:00"}, {"answer_html": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] and its associated implementation in scipy.optimize.minimize(method='trust-constr'). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.
\nSet:
\nsparse_jacobian = Truefactorization_method = 'AugmentedSystem'jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.bounds by your $l$ and $u$constraints to a LinearConstraint by your $A$ and using a scipy sparse arrayx0 to a sensible initial estimateIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.
\n\n", "answer_id": 45266, "answer_text": "Read (if you're lucky, from your university's library)\nTrust Region Methods, Conn, Gould, and Toint [SIAM (2000)] (https://epubs.siam.org/doi/book/10.1137/1.9780898719857) and its associated implementation in scipy.optimize.minimize(method='trust-constr') (https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html). It will run for both the sparse and dense cases, though it may or may not be the most efficient approach in the dense case.\n\n\n\n\nSet:\n\n\n\n\n\nsparse_jacobian = True\n\n\n\n\nfactorization_method = 'AugmentedSystem'\n\n\n\n\nYour jac and hess to functions where you provide the analytic Jacobian and Hessian of the cost function. Very simply, the Jacobian is $x - y$, and the Hessian is the (sparse) identity matrix.\n\n\n\n\nIn the upper-level minimize (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) interface, bounds by your $l$ and $u$\n\n\n\n\nconstraints to a LinearConstraint (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html) by your $A$ and using a scipy sparse array\n\n\n\n\nx0 to a sensible initial estimate\n\n\n\n\n\nIn my testing, this converges to an optimality of $2.7 \\times 10^{-5}$ within 14 calls to the cost function for a problem size of 15x200 and density 15%.\n\n\n\n\n[image: convergence; source: https://i.sstatic.net/YJ8UEXx7.png] (https://i.sstatic.net/YJ8UEXx7.png)", "answer_url": "https://scicomp.stackexchange.com/a/45266", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-10-25T13:17:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45263, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T13:17:14+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "77444703-E320-475F-B89E-303773BDEE64", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/77444703-E320-475F-B89E-303773BDEE64/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:40:38+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "C04032E9-FCDC-40CF-857D-605E6541C00E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/C04032E9-FCDC-40CF-857D-605E6541C00E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2025-10-25T19:54:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "09D74CCF-7C0C-4138-9B77-B959EBA73CBB", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/09D74CCF-7C0C-4138-9B77-B959EBA73CBB/view-source"}], "score": 2, "updated_at": "2025-10-25T19:54:56+00:00"}], "domain": "computational_science", "external_links": ["https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.LinearConstraint.html", "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html", "https://docs.scipy.org/doc/scipy/reference/optimize.minimize-trustconstr.html", "https://en.wikipedia.org/wiki/Dykstra%27s_projection_algorithm", "https://epubs.siam.org/doi/book/10.1137/1.9780898719857", "https://i.sstatic.net/YJ8UEXx7.png", "https://web.stanford.edu/%7Eboyd/papers/admm_distr_stats.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Royi", "question_author_url": "https://scicomp.stackexchange.com/users/7951/royi", "question_author_user_type": "registered", "question_created_at": "2025-10-25T07:56:29+00:00", "question_html": "Solve the following problem:
\n$$\n\\begin{alignat*}{3}\n\\arg \\min_{ \\boldsymbol{x} } & \\quad & \\frac{1}{2} \\left\\| \\boldsymbol{x} - \\boldsymbol{y} \\right\\|_{2}^{2} \\\\\n\\text{subject to} & \\quad & \\boldsymbol{A} \\boldsymbol{x} = \\boldsymbol{b} \\\\\n& \\quad & \\boldsymbol{x} \\leq \\boldsymbol{u} \\\\\n& \\quad & \\boldsymbol{x} \\geq \\boldsymbol{l} \\\\\n\\end{alignat*}\n$$
\nWhere $\\boldsymbol{A} \\in \\mathbb{R}^{m \\times n}, \\; n \\gg m$ with independent rows.
\nI want to solve it for the cases:
\nIn most efficient way without using high level solvers.
\nBut just Use MATLAB / Python / Julia with their own Linear Algebra / Sparse libraries.
Currently my approach is to use Dykstra Projection Algorithm.
\nI wonder if there are some acceleration tricks.
I don't love the answer that I'm about to give because understanding all this requires an unholy amount of theory.\nBut you're likely to end up here anyway.
\nWhat you're dancing around here is something called exterior calculus.\nYou're probably familiar with the common differential operators of vector calculus:
\n$$\\text{scalar fields} \\stackrel{\\text{gradient}}{\\rightarrow} \\text{vector fields} \\stackrel{\\text{curl}}{\\rightarrow} \\text{vector fields} \\stackrel{\\text{divergence}}{\\rightarrow} \\text{scalar fields}$$
\nThe composition of any two of the operators in this sequence is zero: the curl of a gradient is zero, the divergence of a curl is zero.
\nEach of these mappings is a particular instance of the exterior derivative, which is written as $\\mathrm d$.\nThe fact that, for example, the curl of a gradient is zero is one instance of the general identity\n$$\\mathrm d\\mathrm d = 0.$$\nThe exterior derivative has an adjoint operator $\\mathrm d^*$.\nLikewise $\\mathrm d^*\\mathrm d^* = 0$.\nThe Helmholtz-Hodge decomposition states that any differential form $u$ can be written as\n$$u = \\mathrm d\\phi + \\mathrm d^*\\psi + \\eta$$\nwhere $\\eta$ is harmonic: both $\\mathrm d\\eta = 0$ and $\\mathrm d^*\\eta = 0$.
\nThe diagram I wrote above is called the de Rham complex.\nThe goal of finite element exterior calculus is to come up with discretizations of each of the spaces in the complex in such a way that we preserve the relation $\\mathrm d\\mathrm d = 0$.\nYou can read about finite element exterior calculus in this book by Doug Arnold.\nThe right spaces for discretizing the de Rham complex are implemented in FEniCS and most other finite element modeling packages.\nIf you read Doug Arnold's book, then you'll understand what are the right finite element spaces to use for each component of the Helmholtz-Hodge decomposition.
\nIf you want to see an application, I like this paper.
\n", "answer_id": 45310, "answer_text": "I don't love the answer that I'm about to give because understanding all this requires an unholy amount of theory.\nBut you're likely to end up here anyway.\n\n\n\n\nWhat you're dancing around here is something called exterior calculus.\nYou're probably familiar with the common differential operators of vector calculus:\n\n\n\n\n$$\\text{scalar fields} \\stackrel{\\text{gradient}}{\\rightarrow} \\text{vector fields} \\stackrel{\\text{curl}}{\\rightarrow} \\text{vector fields} \\stackrel{\\text{divergence}}{\\rightarrow} \\text{scalar fields}$$\n\n\n\n\nThe composition of any two of the operators in this sequence is zero: the curl of a gradient is zero, the divergence of a curl is zero.\n\n\n\n\nEach of these mappings is a particular instance of the exterior derivative, which is written as $\\mathrm d$.\nThe fact that, for example, the curl of a gradient is zero is one instance of the general identity\n$$\\mathrm d\\mathrm d = 0.$$\nThe exterior derivative has an adjoint operator $\\mathrm d^*$.\nLikewise $\\mathrm d^*\\mathrm d^* = 0$.\nThe Helmholtz-Hodge decomposition states that any differential form $u$ can be written as\n$$u = \\mathrm d\\phi + \\mathrm d^*\\psi + \\eta$$\nwhere $\\eta$ is harmonic: both $\\mathrm d\\eta = 0$ and $\\mathrm d^*\\eta = 0$.\n\n\n\n\nThe diagram I wrote above is called the de Rham complex.\nThe goal of finite element exterior calculus is to come up with discretizations of each of the spaces in the complex in such a way that we preserve the relation $\\mathrm d\\mathrm d = 0$.\nYou can read about finite element exterior calculus in this book (https://doi.org/10.1137/1.9781611975543) by Doug Arnold.\nThe right spaces for discretizing the de Rham complex are implemented in FEniCS and most other finite element modeling packages.\nIf you read Doug Arnold's book, then you'll understand what are the right finite element spaces to use for each component of the Helmholtz-Hodge decomposition.\n\n\n\n\nIf you want to see an application, I like this paper (https://doi.org/10.1093/climsys/dzw005).", "answer_url": "https://scicomp.stackexchange.com/a/45310", "author": "Daniel Shapero", "author_url": "https://scicomp.stackexchange.com/users/3481/daniel-shapero", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-12-11T00:49:13+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45309, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Daniel Shapero", "profile_url": "https://scicomp.stackexchange.com/users/3481/daniel-shapero", "user_type": "registered"}, "created_at": "2025-12-11T00:49:13+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "212119B9-8FEE-4DAD-BB23-D2F93FD8B34D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/212119B9-8FEE-4DAD-BB23-D2F93FD8B34D/view-source"}], "score": 6, "updated_at": "2025-12-11T00:49:13+00:00"}], "domain": "computational_science", "external_links": ["https://doi.org/10.1093/climsys/dzw005", "https://doi.org/10.1137/1.9781611975543"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Researcher R", "question_author_url": "https://scicomp.stackexchange.com/users/53321/researcher-r", "question_author_user_type": "registered", "question_created_at": "2025-12-10T11:15:56+00:00", "question_html": "I am working on a bit different variation of a Helmholtz decomposition where it is inside of a limited domain (this is called a Helmholtz Hodge decomposition?)\n$$\\textbf{V} = \\nabla \\phi + \\nabla \\times \\textbf{A} + \\textbf{V}_h$$
\nwhich is solved analytically in the paper I am reading from, however analytic methods often times give me trouble with very bad Gibbs Phenomena near the boundaries, and this problem was no exception. So, I want to use finite element methods and solvers instead, but it is probably crucial to determine which functionspace is optimal to define everything in, especially for a problem like this, so I wanted advice on that as someone that is very inexperienced in this area. The specific variation on Helmholtz decomposition defined in the paper is one probably not commonly seen:
\n$$\\textbf{V} = \\nabla\\chi_I + \\nabla^\\perp \\psi_I + \\textbf{V}_h \\ \\ \\ \\ \\forall (x,y) \\in R[0\\le x \\le 1; 0 \\le y \\le 1] \n$$
\n(where it is presumed that $\\nabla^\\perp \\psi = \\nabla \\times \\textbf{A}$). So the vector potential was broken down into a scalar potential, however the resulting vector field it produces is still nondivergent, as well as $\\nabla \\chi_I$ still being irrotational, and $\\textbf{V}_h$ is both nondivergent and irrotational. To solve the decomposition, we have to first solve 2 Poisson Equations\n$$\\nabla^2 \\psi_h = \\hat{\\textbf{k}}\\cdot \\nabla \\times \\textbf{V} = curl(\\textbf{V})\n\\\\\n\\psi_I = 0 \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega$$\n$$\\nabla^2 \\chi_h = \\nabla \\cdot \\textbf{V} = divergence(\\textbf{V})\n\\\\\n\\chi_I = 0 \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega$$
\nand 2 Laplace Equations
\n$$ \\nabla^2 \\psi_h = 0\n\\\\\n\\nabla^2 \\chi_h = 0\n\\\\ \n\\frac{\\partial \\psi_h}{\\partial n} + \\frac{\\partial \\chi_h}{\\partial s} = \\textbf{V}_h \\cdot \\hat{\\textbf{s}} \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega \n\\\\ \n-\\frac{\\partial \\psi_h}{\\partial s} + \\frac{\\partial \\chi_h}{\\partial n} = \\textbf{V}_h \\cdot \\hat{\\textbf{n}} \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega\n$$\nwhere $\\textbf{V}_h = \\textbf{V} - \\big(\\nabla^\\perp \\psi_I + \\nabla \\chi_I\\big)$, and we expect the net circulation and flux of $\\textbf{V}_h$ on the boundary to be $0$ (I am currently struggling to get it to satisfy this condition=).
\nI have been working in a Lagrangian space to define both my scalars and vectors in, and from my results, I am guessing that is not going to cut it, and a specialized space might be better suited. I would appreciate help in determining a sufficient functionspace for my problem, as well as any additional advice other users would like to give. For the record, I am working on this problem in Fenics in Python.
\nI can add my Python code to show how everything was set up if it helps. Just ask, and I'll add it!
\n", "question_id": 45309, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I am working on a bit different variation of a Helmholtz decomposition where it is inside of a limited domain (this is called a Helmholtz Hodge decomposition?)\n$$\\textbf{V} = \\nabla \\phi + \\nabla \\times \\textbf{A} + \\textbf{V}_h$$\n\n\n\n\nwhich is solved analytically in the paper I am reading from, however analytic methods often times give me trouble with very bad Gibbs Phenomena near the boundaries, and this problem was no exception. So, I want to use finite element methods and solvers instead, but it is probably crucial to determine which functionspace is optimal to define everything in, especially for a problem like this, so I wanted advice on that as someone that is very inexperienced in this area. The specific variation on Helmholtz decomposition defined in the paper is one probably not commonly seen:\n\n\n\n\n$$\\textbf{V} = \\nabla\\chi_I + \\nabla^\\perp \\psi_I + \\textbf{V}_h \\ \\ \\ \\ \\forall (x,y) \\in R[0\\le x \\le 1; 0 \\le y \\le 1] \n$$\n\n\n\n\n(where it is presumed that $\\nabla^\\perp \\psi = \\nabla \\times \\textbf{A}$). So the vector potential was broken down into a scalar potential, however the resulting vector field it produces is still nondivergent, as well as $\\nabla \\chi_I$ still being irrotational, and $\\textbf{V}_h$ is both nondivergent and irrotational. To solve the decomposition, we have to first solve 2 Poisson Equations\n$$\\nabla^2 \\psi_h = \\hat{\\textbf{k}}\\cdot \\nabla \\times \\textbf{V} = curl(\\textbf{V})\n\\\\\n\\psi_I = 0 \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega$$\n$$\\nabla^2 \\chi_h = \\nabla \\cdot \\textbf{V} = divergence(\\textbf{V})\n\\\\\n\\chi_I = 0 \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega$$\n\n\n\n\nand 2 Laplace Equations\n\n\n\n\n$$ \\nabla^2 \\psi_h = 0\n\\\\\n\\nabla^2 \\chi_h = 0\n\\\\ \n\\frac{\\partial \\psi_h}{\\partial n} + \\frac{\\partial \\chi_h}{\\partial s} = \\textbf{V}_h \\cdot \\hat{\\textbf{s}} \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega \n\\\\ \n-\\frac{\\partial \\psi_h}{\\partial s} + \\frac{\\partial \\chi_h}{\\partial n} = \\textbf{V}_h \\cdot \\hat{\\textbf{n}} \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega\n$$\nwhere $\\textbf{V}_h = \\textbf{V} - \\big(\\nabla^\\perp \\psi_I + \\nabla \\chi_I\\big)$, and we expect the net circulation and flux of $\\textbf{V}_h$ on the boundary to be $0$ (I am currently struggling to get it to satisfy this condition=).\n\n\n\n\nI have been working in a Lagrangian space to define both my scalars and vectors in, and from my results, I am guessing that is not going to cut it, and a specialized space might be better suited. I would appreciate help in determining a sufficient functionspace for my problem, as well as any additional advice other users would like to give. For the record, I am working on this problem in Fenics in Python.\n\n\n\n\n\n\n\nI can add my Python code to show how everything was set up if it helps. Just ask, and I'll add it!", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Researcher R", "profile_url": "https://scicomp.stackexchange.com/users/53321/researcher-r", "user_type": "registered"}, "created_at": "2025-12-10T11:15:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "62A6D641-E520-40FC-B2EF-032D184754C5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/62A6D641-E520-40FC-B2EF-032D184754C5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Researcher R", "profile_url": "https://scicomp.stackexchange.com/users/53321/researcher-r", "user_type": "registered"}, "created_at": "2025-12-10T21:28:52+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "E35767F2-220D-4BD5-9BDC-0958BF1004F2", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/E35767F2-220D-4BD5-9BDC-0958BF1004F2/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2025-12-11T05:35:00+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DDD76BBC-2D7A-44CA-93E4-4E9695ED2E31", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://scicomp.stackexchange.com/revisions/DDD76BBC-2D7A-44CA-93E4-4E9695ED2E31/view-source"}], "source_site": "scicomp", "source_url": "https://scicomp.stackexchange.com/questions/45309/which-functionspaces-should-be-used-to-solve-a-helmholtz-decomposition", "split": "validation", "split_group": "47bbeeb7fa491ea52d730b7179a95870784902c52223f5cc28f5f9c22f81ef1e", "tags": ["finite-element", "fluid-dynamics"], "thread_id": "scicomp:45309", "title": "Which functionspaces should be used to solve a Helmholtz decomposition?"}} {"citation_context": "elation $\\mathrm d\\mathrm d = 0$.\nYou can read about finite element exterior calculus in this book (https://doi.org/10.1137/1.9781611975543) by Doug Arnold.\nThe right spaces for discretizing the de Rham complex are implemented in FEniCS an", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": "10.1137/1.9781611975543", "external_url": "https://doi.org/10.1137/1.9781611975543", "kind": "doi_url", "post_id": 45310, "post_url": "https://scicomp.stackexchange.com/a/45310", "product": "citations", "record_id": "Scientific-Citation-Graph:defe68fa7a57bdfb52d14424", "split": "validation", "thread": {"accepted_answer_id": 45310, "answers": [{"answer_html": "I don't love the answer that I'm about to give because understanding all this requires an unholy amount of theory.\nBut you're likely to end up here anyway.
\nWhat you're dancing around here is something called exterior calculus.\nYou're probably familiar with the common differential operators of vector calculus:
\n$$\\text{scalar fields} \\stackrel{\\text{gradient}}{\\rightarrow} \\text{vector fields} \\stackrel{\\text{curl}}{\\rightarrow} \\text{vector fields} \\stackrel{\\text{divergence}}{\\rightarrow} \\text{scalar fields}$$
\nThe composition of any two of the operators in this sequence is zero: the curl of a gradient is zero, the divergence of a curl is zero.
\nEach of these mappings is a particular instance of the exterior derivative, which is written as $\\mathrm d$.\nThe fact that, for example, the curl of a gradient is zero is one instance of the general identity\n$$\\mathrm d\\mathrm d = 0.$$\nThe exterior derivative has an adjoint operator $\\mathrm d^*$.\nLikewise $\\mathrm d^*\\mathrm d^* = 0$.\nThe Helmholtz-Hodge decomposition states that any differential form $u$ can be written as\n$$u = \\mathrm d\\phi + \\mathrm d^*\\psi + \\eta$$\nwhere $\\eta$ is harmonic: both $\\mathrm d\\eta = 0$ and $\\mathrm d^*\\eta = 0$.
\nThe diagram I wrote above is called the de Rham complex.\nThe goal of finite element exterior calculus is to come up with discretizations of each of the spaces in the complex in such a way that we preserve the relation $\\mathrm d\\mathrm d = 0$.\nYou can read about finite element exterior calculus in this book by Doug Arnold.\nThe right spaces for discretizing the de Rham complex are implemented in FEniCS and most other finite element modeling packages.\nIf you read Doug Arnold's book, then you'll understand what are the right finite element spaces to use for each component of the Helmholtz-Hodge decomposition.
\nIf you want to see an application, I like this paper.
\n", "answer_id": 45310, "answer_text": "I don't love the answer that I'm about to give because understanding all this requires an unholy amount of theory.\nBut you're likely to end up here anyway.\n\n\n\n\nWhat you're dancing around here is something called exterior calculus.\nYou're probably familiar with the common differential operators of vector calculus:\n\n\n\n\n$$\\text{scalar fields} \\stackrel{\\text{gradient}}{\\rightarrow} \\text{vector fields} \\stackrel{\\text{curl}}{\\rightarrow} \\text{vector fields} \\stackrel{\\text{divergence}}{\\rightarrow} \\text{scalar fields}$$\n\n\n\n\nThe composition of any two of the operators in this sequence is zero: the curl of a gradient is zero, the divergence of a curl is zero.\n\n\n\n\nEach of these mappings is a particular instance of the exterior derivative, which is written as $\\mathrm d$.\nThe fact that, for example, the curl of a gradient is zero is one instance of the general identity\n$$\\mathrm d\\mathrm d = 0.$$\nThe exterior derivative has an adjoint operator $\\mathrm d^*$.\nLikewise $\\mathrm d^*\\mathrm d^* = 0$.\nThe Helmholtz-Hodge decomposition states that any differential form $u$ can be written as\n$$u = \\mathrm d\\phi + \\mathrm d^*\\psi + \\eta$$\nwhere $\\eta$ is harmonic: both $\\mathrm d\\eta = 0$ and $\\mathrm d^*\\eta = 0$.\n\n\n\n\nThe diagram I wrote above is called the de Rham complex.\nThe goal of finite element exterior calculus is to come up with discretizations of each of the spaces in the complex in such a way that we preserve the relation $\\mathrm d\\mathrm d = 0$.\nYou can read about finite element exterior calculus in this book (https://doi.org/10.1137/1.9781611975543) by Doug Arnold.\nThe right spaces for discretizing the de Rham complex are implemented in FEniCS and most other finite element modeling packages.\nIf you read Doug Arnold's book, then you'll understand what are the right finite element spaces to use for each component of the Helmholtz-Hodge decomposition.\n\n\n\n\nIf you want to see an application, I like this paper (https://doi.org/10.1093/climsys/dzw005).", "answer_url": "https://scicomp.stackexchange.com/a/45310", "author": "Daniel Shapero", "author_url": "https://scicomp.stackexchange.com/users/3481/daniel-shapero", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-12-11T00:49:13+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:47.033952+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/cb6e5f564c84a92c4e121c0637c99292018f8935652e423630f2001099a2410f_1790825327386675300_0.json", "raw_sha256": "1a957289f56621bebd21cb45dd99baaedb2c3bc11cb28d700558e4bbcaa19695", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=1&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45309, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Daniel Shapero", "profile_url": "https://scicomp.stackexchange.com/users/3481/daniel-shapero", "user_type": "registered"}, "created_at": "2025-12-11T00:49:13+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "212119B9-8FEE-4DAD-BB23-D2F93FD8B34D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/212119B9-8FEE-4DAD-BB23-D2F93FD8B34D/view-source"}], "score": 6, "updated_at": "2025-12-11T00:49:13+00:00"}], "domain": "computational_science", "external_links": ["https://doi.org/10.1093/climsys/dzw005", "https://doi.org/10.1137/1.9781611975543"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Researcher R", "question_author_url": "https://scicomp.stackexchange.com/users/53321/researcher-r", "question_author_user_type": "registered", "question_created_at": "2025-12-10T11:15:56+00:00", "question_html": "I am working on a bit different variation of a Helmholtz decomposition where it is inside of a limited domain (this is called a Helmholtz Hodge decomposition?)\n$$\\textbf{V} = \\nabla \\phi + \\nabla \\times \\textbf{A} + \\textbf{V}_h$$
\nwhich is solved analytically in the paper I am reading from, however analytic methods often times give me trouble with very bad Gibbs Phenomena near the boundaries, and this problem was no exception. So, I want to use finite element methods and solvers instead, but it is probably crucial to determine which functionspace is optimal to define everything in, especially for a problem like this, so I wanted advice on that as someone that is very inexperienced in this area. The specific variation on Helmholtz decomposition defined in the paper is one probably not commonly seen:
\n$$\\textbf{V} = \\nabla\\chi_I + \\nabla^\\perp \\psi_I + \\textbf{V}_h \\ \\ \\ \\ \\forall (x,y) \\in R[0\\le x \\le 1; 0 \\le y \\le 1] \n$$
\n(where it is presumed that $\\nabla^\\perp \\psi = \\nabla \\times \\textbf{A}$). So the vector potential was broken down into a scalar potential, however the resulting vector field it produces is still nondivergent, as well as $\\nabla \\chi_I$ still being irrotational, and $\\textbf{V}_h$ is both nondivergent and irrotational. To solve the decomposition, we have to first solve 2 Poisson Equations\n$$\\nabla^2 \\psi_h = \\hat{\\textbf{k}}\\cdot \\nabla \\times \\textbf{V} = curl(\\textbf{V})\n\\\\\n\\psi_I = 0 \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega$$\n$$\\nabla^2 \\chi_h = \\nabla \\cdot \\textbf{V} = divergence(\\textbf{V})\n\\\\\n\\chi_I = 0 \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega$$
\nand 2 Laplace Equations
\n$$ \\nabla^2 \\psi_h = 0\n\\\\\n\\nabla^2 \\chi_h = 0\n\\\\ \n\\frac{\\partial \\psi_h}{\\partial n} + \\frac{\\partial \\chi_h}{\\partial s} = \\textbf{V}_h \\cdot \\hat{\\textbf{s}} \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega \n\\\\ \n-\\frac{\\partial \\psi_h}{\\partial s} + \\frac{\\partial \\chi_h}{\\partial n} = \\textbf{V}_h \\cdot \\hat{\\textbf{n}} \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega\n$$\nwhere $\\textbf{V}_h = \\textbf{V} - \\big(\\nabla^\\perp \\psi_I + \\nabla \\chi_I\\big)$, and we expect the net circulation and flux of $\\textbf{V}_h$ on the boundary to be $0$ (I am currently struggling to get it to satisfy this condition=).
\nI have been working in a Lagrangian space to define both my scalars and vectors in, and from my results, I am guessing that is not going to cut it, and a specialized space might be better suited. I would appreciate help in determining a sufficient functionspace for my problem, as well as any additional advice other users would like to give. For the record, I am working on this problem in Fenics in Python.
\nI can add my Python code to show how everything was set up if it helps. Just ask, and I'll add it!
\n", "question_id": 45309, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I am working on a bit different variation of a Helmholtz decomposition where it is inside of a limited domain (this is called a Helmholtz Hodge decomposition?)\n$$\\textbf{V} = \\nabla \\phi + \\nabla \\times \\textbf{A} + \\textbf{V}_h$$\n\n\n\n\nwhich is solved analytically in the paper I am reading from, however analytic methods often times give me trouble with very bad Gibbs Phenomena near the boundaries, and this problem was no exception. So, I want to use finite element methods and solvers instead, but it is probably crucial to determine which functionspace is optimal to define everything in, especially for a problem like this, so I wanted advice on that as someone that is very inexperienced in this area. The specific variation on Helmholtz decomposition defined in the paper is one probably not commonly seen:\n\n\n\n\n$$\\textbf{V} = \\nabla\\chi_I + \\nabla^\\perp \\psi_I + \\textbf{V}_h \\ \\ \\ \\ \\forall (x,y) \\in R[0\\le x \\le 1; 0 \\le y \\le 1] \n$$\n\n\n\n\n(where it is presumed that $\\nabla^\\perp \\psi = \\nabla \\times \\textbf{A}$). So the vector potential was broken down into a scalar potential, however the resulting vector field it produces is still nondivergent, as well as $\\nabla \\chi_I$ still being irrotational, and $\\textbf{V}_h$ is both nondivergent and irrotational. To solve the decomposition, we have to first solve 2 Poisson Equations\n$$\\nabla^2 \\psi_h = \\hat{\\textbf{k}}\\cdot \\nabla \\times \\textbf{V} = curl(\\textbf{V})\n\\\\\n\\psi_I = 0 \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega$$\n$$\\nabla^2 \\chi_h = \\nabla \\cdot \\textbf{V} = divergence(\\textbf{V})\n\\\\\n\\chi_I = 0 \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega$$\n\n\n\n\nand 2 Laplace Equations\n\n\n\n\n$$ \\nabla^2 \\psi_h = 0\n\\\\\n\\nabla^2 \\chi_h = 0\n\\\\ \n\\frac{\\partial \\psi_h}{\\partial n} + \\frac{\\partial \\chi_h}{\\partial s} = \\textbf{V}_h \\cdot \\hat{\\textbf{s}} \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega \n\\\\ \n-\\frac{\\partial \\psi_h}{\\partial s} + \\frac{\\partial \\chi_h}{\\partial n} = \\textbf{V}_h \\cdot \\hat{\\textbf{n}} \\ \\ \\ \\ \\forall (x,y) \\in \\partial \\Omega\n$$\nwhere $\\textbf{V}_h = \\textbf{V} - \\big(\\nabla^\\perp \\psi_I + \\nabla \\chi_I\\big)$, and we expect the net circulation and flux of $\\textbf{V}_h$ on the boundary to be $0$ (I am currently struggling to get it to satisfy this condition=).\n\n\n\n\nI have been working in a Lagrangian space to define both my scalars and vectors in, and from my results, I am guessing that is not going to cut it, and a specialized space might be better suited. I would appreciate help in determining a sufficient functionspace for my problem, as well as any additional advice other users would like to give. For the record, I am working on this problem in Fenics in Python.\n\n\n\n\n\n\n\nI can add my Python code to show how everything was set up if it helps. Just ask, and I'll add it!", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Researcher R", "profile_url": "https://scicomp.stackexchange.com/users/53321/researcher-r", "user_type": "registered"}, "created_at": "2025-12-10T11:15:56+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "62A6D641-E520-40FC-B2EF-032D184754C5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/62A6D641-E520-40FC-B2EF-032D184754C5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Researcher R", "profile_url": "https://scicomp.stackexchange.com/users/53321/researcher-r", "user_type": "registered"}, "created_at": "2025-12-10T21:28:52+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "E35767F2-220D-4BD5-9BDC-0958BF1004F2", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/E35767F2-220D-4BD5-9BDC-0958BF1004F2/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2025-12-11T05:35:00+00:00", "raw_file": "raw/codex_api_v1/932c57dde4e92dfe2af05c19643e98b6494a44cb31534e6703e92349c4e07eb4_1790825333093747000_0.json", "raw_sha256": "646e25c86dbb0c4df1ebe365442e733a253ac993340d2ed18168bbf783f75cac", "revision_guid": "DDD76BBC-2D7A-44CA-93E4-4E9695ED2E31", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://scicomp.stackexchange.com/revisions/DDD76BBC-2D7A-44CA-93E4-4E9695ED2E31/view-source"}], "source_site": "scicomp", "source_url": "https://scicomp.stackexchange.com/questions/45309/which-functionspaces-should-be-used-to-solve-a-helmholtz-decomposition", "split": "validation", "split_group": "47bbeeb7fa491ea52d730b7179a95870784902c52223f5cc28f5f9c22f81ef1e", "tags": ["finite-element", "fluid-dynamics"], "thread_id": "scicomp:45309", "title": "Which functionspaces should be used to solve a Helmholtz decomposition?"}} {"citation_context": "ly see the term \"synthetic data\" bubbling up in funding calls and in my scientific context [e.g. 1 (https://www.sciencedirect.com/science/article/pii/S2001037024002393)]. My understanding of the term is that in cases where the actual dataset contains very sensitive i", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.sciencedirect.com/science/article/pii/S2001037024002393", "kind": "external_url", "post_id": 45474, "post_url": "https://scicomp.stackexchange.com/questions/45474/what-is-the-reason-to-argue-for-and-use-synthetic-data", "product": "citations", "record_id": "Scientific-Citation-Graph:5e034ec0383e8ec896d55bab", "split": "validation", "thread": {"accepted_answer_id": 45478, "answers": [{"answer_html": "One reason to do this is that a "synthetic data set" can be made available to other researchers while privacy considerations might prevent the sharing of the actual original data set.
\nOf course, this leaves the problem of checking that the synthesis procedure didn't alter the data in undesirable ways. One option would be to ask the peer reviewers to examine the actual and synthetic data sets for problems.
\n", "answer_id": 45475, "answer_text": "One reason to do this is that a \"synthetic data set\" can be made available to other researchers while privacy considerations might prevent the sharing of the actual original data set.\n\n\n\n\nOf course, this leaves the problem of checking that the synthesis procedure didn't alter the data in undesirable ways. One option would be to ask the peer reviewers to examine the actual and synthetic data sets for problems.", "answer_url": "https://scicomp.stackexchange.com/a/45475", "author": "Brian Borchers", "author_url": "https://scicomp.stackexchange.com/users/2150/brian-borchers", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-26T03:32:57+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Brian Borchers", "profile_url": "https://scicomp.stackexchange.com/users/2150/brian-borchers", "user_type": "registered"}, "created_at": "2026-06-26T03:32:57+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "AE0F0142-479D-46CB-8BE0-BD8B4FB1EA03", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/AE0F0142-479D-46CB-8BE0-BD8B4FB1EA03/view-source"}], "score": 2, "updated_at": "2026-06-26T03:32:57+00:00"}, {"answer_html": "I believe "synthetic data" is very often used to designate data that we can only characterize as the result of a process with certain characteristics. Thus we do not have a complete analytic characterization, like statistical distribution.
\nFor example, we often use synthetic seismic data, meaning seismic waves generated by a time integrator for the elastic wave equations through a model of the Earth. We measure the virtual output at seismometers, and compare that to actual data. The result of the integrator cannot be neatly summarized as you indicate above. We have also done a similar thing using data from the simulation of the combustion chamber of a hybrid rocket to look at turbulent correlations.
\n", "answer_id": 45476, "answer_text": "I believe \"synthetic data\" is very often used to designate data that we can only characterize as the result of a process with certain characteristics. Thus we do not have a complete analytic characterization, like statistical distribution.\n\n\n\n\nFor example, we often use synthetic seismic data, meaning seismic waves generated by a time integrator for the elastic wave equations through a model of the Earth. We measure the virtual output at seismometers, and compare that to actual data. The result of the integrator cannot be neatly summarized as you indicate above. We have also done a similar thing using data from the simulation of the combustion chamber of a hybrid rocket to look at turbulent correlations.", "answer_url": "https://scicomp.stackexchange.com/a/45476", "author": "Matt Knepley", "author_url": "https://scicomp.stackexchange.com/users/21/matt-knepley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-26T14:38:38+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Matt Knepley", "profile_url": "https://scicomp.stackexchange.com/users/21/matt-knepley", "user_type": "registered"}, "created_at": "2026-06-26T14:38:38+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "B6A66FA8-FB59-4295-8D07-5C149B6459ED", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/B6A66FA8-FB59-4295-8D07-5C149B6459ED/view-source"}], "score": 5, "updated_at": "2026-06-26T14:38:38+00:00"}, {"answer_html": "I used to work at a company that created the kind of synthetic medical data that you're talking about. In our case, we did it so that we could show a demonstration of the system without revealing private health information. A ML Algorithm might not care about an individual's record, but a doctor or administrator would want to see how the whole system works before buying it. We wouldn't include the doctor's notes (too much risk of personal identifiable information being inserted there) but we could create alternative patient and doctor names, change dates within a certain acceptable range (a few years for birthdays, a few weeks for visits), stuff like that. It was changed just enough that no one could look at our demo and figure out which real world person's medical record it was associated with, but not enough to mess up analytics on the dataset.
\nAnother use case for synthetic data is when you simply don't have a natural dataset that's up to the task, so you create one. A fun example was Corridor Digital creating a synthetic dataset of green screen footage to make a better green screen remover. (Their video on it here) They couldn't rely on previously shot green screen footage because they needed flawless examples of what that same footage would look like with the green screen perfectly removed, so they created a completely digital training set of fake green screen footage and rendered the same scene without the background as the ground truth. The resulting model was able to work just fine with real world green screen footage, even though it wasn't part of the training dataset at all.
\n", "answer_id": 45478, "answer_text": "I used to work at a company that created the kind of synthetic medical data that you're talking about. In our case, we did it so that we could show a demonstration of the system without revealing private health information. A ML Algorithm might not care about an individual's record, but a doctor or administrator would want to see how the whole system works before buying it. We wouldn't include the doctor's notes (too much risk of personal identifiable information being inserted there) but we could create alternative patient and doctor names, change dates within a certain acceptable range (a few years for birthdays, a few weeks for visits), stuff like that. It was changed just enough that no one could look at our demo and figure out which real world person's medical record it was associated with, but not enough to mess up analytics on the dataset.\n\n\n\n\nAnother use case for synthetic data is when you simply don't have a natural dataset that's up to the task, so you create one. A fun example was Corridor Digital creating a synthetic dataset of green screen footage to make a better green screen remover. (Their video on it here) (https://www.youtube.com/watch?v=3Ploi723hg4) They couldn't rely on previously shot green screen footage because they needed flawless examples of what that same footage would look like with the green screen perfectly removed, so they created a completely digital training set of fake green screen footage and rendered the same scene without the background as the ground truth. The resulting model was able to work just fine with real world green screen footage, even though it wasn't part of the training dataset at all.", "answer_url": "https://scicomp.stackexchange.com/a/45478", "author": "Dr. Cyanide", "author_url": "https://scicomp.stackexchange.com/users/56986/dr-cyanide", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-26T19:05:21+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dr. Cyanide", "profile_url": "https://scicomp.stackexchange.com/users/56986/dr-cyanide", "user_type": "registered"}, "created_at": "2026-06-26T19:05:21+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "58D1370C-30E1-48E0-85D3-61EF0F7449AA", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/58D1370C-30E1-48E0-85D3-61EF0F7449AA/view-source"}], "score": 7, "updated_at": "2026-06-26T19:05:21+00:00"}, {"answer_html": "Synthetic data in my area of machine learning just means using data generated by a model rather than "real" data collected from the environment. In my case, I often use synthetic data because you know what the true model is so you have "ground truth" you can use to judge the performance of your ML model. I use synthetic data in Monte Carlo simulations (where you perform the same analysis again and again with different data) as I can generate as much independent data as I like. This means I can detect biases in the ML models. Also because I can generate as much data as I like, I can get reliable performance estimates with a very low variance by having a very large test set. In those cases, I am usually investigating the properties of the learning algorithm, rather than the data or the process that generated the data (so there is no "over-interpretation").
\nAnother reason for using synthetic data is as a proof of concept, where there just isn't enough real data to meaningfully train a model.
\nIn other case, we can model the data in one direction very well, but want to do the prediction in the other direction. For instance, we might be able to work out what a magnetometer picks up when it runs over buried architectural remains, so we could use synthetic data to train a model to predict the depth of buried remains from magenetometer data, which archeologists could use to investigate historical sites without actually digging them up (save for a few test trenches used to validate the system). https://doi.org/10.1002/arp.236
\nHowever it may mean other things in other fields.
\n", "answer_id": 45480, "answer_text": "Synthetic data in my area of machine learning just means using data generated by a model rather than \"real\" data collected from the environment. In my case, I often use synthetic data because you know what the true model is so you have \"ground truth\" you can use to judge the performance of your ML model. I use synthetic data in Monte Carlo simulations (where you perform the same analysis again and again with different data) as I can generate as much independent data as I like. This means I can detect biases in the ML models. Also because I can generate as much data as I like, I can get reliable performance estimates with a very low variance by having a very large test set. In those cases, I am usually investigating the properties of the learning algorithm, rather than the data or the process that generated the data (so there is no \"over-interpretation\").\n\n\n\n\nAnother reason for using synthetic data is as a proof of concept, where there just isn't enough real data to meaningfully train a model.\n\n\n\n\nIn other case, we can model the data in one direction very well, but want to do the prediction in the other direction. For instance, we might be able to work out what a magnetometer picks up when it runs over buried architectural remains, so we could use synthetic data to train a model to predict the depth of buried remains from magenetometer data, which archeologists could use to investigate historical sites without actually digging them up (save for a few test trenches used to validate the system). https://doi.org/10.1002/arp.236 (https://doi.org/10.1002/arp.236)\n\n\n\n\nHowever it may mean other things in other fields.", "answer_url": "https://scicomp.stackexchange.com/a/45480", "author": "Dikran Marsupial", "author_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-27T15:51:23+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dikran Marsupial", "profile_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "user_type": "registered"}, "created_at": "2026-06-27T15:51:23+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "B3F429EC-FC98-4CEC-B864-39792D560780", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/B3F429EC-FC98-4CEC-B864-39792D560780/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dikran Marsupial", "profile_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "user_type": "registered"}, "created_at": "2026-06-27T15:56:36+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "5861285C-8F68-46CE-9D25-B14639ABD89C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/5861285C-8F68-46CE-9D25-B14639ABD89C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dikran Marsupial", "profile_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "user_type": "registered"}, "created_at": "2026-06-29T12:49:45+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "492BACCC-A8FD-4406-A28E-134F43DC4601", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/492BACCC-A8FD-4406-A28E-134F43DC4601/view-source"}], "score": 4, "updated_at": "2026-06-29T12:49:45+00:00"}, {"answer_html": "Another instance when synthetic data is useful is when there is a very low probability event that you want to train on. In a completely natural sample (with our without aliased names) where an unlikely event is nonetheless important (think about a self-driving program where a person steps off the sidewalk in the dark pushing a bicycle). This event would be rare, if even existant in sampled data, but you can create enough instances of it, with some variations, in synthetic data.\nThe 15% of events that occur 85% of the time should not consume 85% of your training time, and important events that occur 0.1% of the time need much more than 0.1% of your training time if they are to be learned.
\n", "answer_id": 45483, "answer_text": "Another instance when synthetic data is useful is when there is a very low probability event that you want to train on. In a completely natural sample (with our without aliased names) where an unlikely event is nonetheless important (think about a self-driving program where a person steps off the sidewalk in the dark pushing a bicycle). This event would be rare, if even existant in sampled data, but you can create enough instances of it, with some variations, in synthetic data.\nThe 15% of events that occur 85% of the time should not consume 85% of your training time, and important events that occur 0.1% of the time need much more than 0.1% of your training time if they are to be learned.", "answer_url": "https://scicomp.stackexchange.com/a/45483", "author": "user2540850", "author_url": "https://scicomp.stackexchange.com/users/56990/user2540850", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-29T00:19:21+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "user2540850", "profile_url": "https://scicomp.stackexchange.com/users/56990/user2540850", "user_type": "registered"}, "created_at": "2026-06-29T00:19:21+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "EACE18B0-EE6C-4205-A703-1A9C528C32E8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/EACE18B0-EE6C-4205-A703-1A9C528C32E8/view-source"}], "score": 1, "updated_at": "2026-06-29T00:19:21+00:00"}], "domain": "computational_science", "external_links": ["https://doi.org/10.1002/arp.236", "https://www.sciencedirect.com/science/article/pii/S2001037024002393", "https://www.youtube.com/watch?v=3Ploi723hg4"], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "MPIchael", "question_author_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "question_author_user_type": "registered", "question_created_at": "2026-06-25T05:45:16+00:00", "question_html": "I recently see the term "synthetic data" bubbling up in funding calls and in my scientific context [e.g. 1]. My understanding of the term is that in cases where the actual dataset contains very sensitive information, it is possible to create a separate dataset which has the same statistical properties as the real one. Then people use and share the "synthetic" dataset either to feed it to a downstream algorithm or to test/validate software.
\nOn the very first glance this approach sounds legitimate, because you strip all the privacy problems while retaining a dataset with the same statistical properties. My problem with this is, that by that very logic the only thing you are transporting/retaining from an information theory perspective is the statistical distribution. All which is downstream may only reasonable make use of that, - the distribution you used as input.
\nThe odd thing is that that data is then used to train ML Algorithms, which in turn do regression to re-capture those same statistical properties. Overinterpretation beyond the statistics that generated the new distribution would be bad science. In a very strict sense you are not really creating actual data, you are generating a random distribution which has the desired statistical properties.
\nIf that is the case, then there is no need to generate "synthetic data" in the first place. We could just use statistical properties from the original real-world dataset and say out loud that we only use aggregated information, which does not contain sensitive elements, - and be done with it.
\nThe more I think about it, the less it makes sense to me. What am I missing about "synthetic datasets"?
\n", "question_id": 45474, "question_license": "CC BY-SA 4.0", "question_score": 6, "question_text": "I recently see the term \"synthetic data\" bubbling up in funding calls and in my scientific context [e.g. 1 (https://www.sciencedirect.com/science/article/pii/S2001037024002393)]. My understanding of the term is that in cases where the actual dataset contains very sensitive information, it is possible to create a separate dataset which has the same statistical properties as the real one. Then people use and share the \"synthetic\" dataset either to feed it to a downstream algorithm or to test/validate software.\n\n\n\n\nOn the very first glance this approach sounds legitimate, because you strip all the privacy problems while retaining a dataset with the same statistical properties. My problem with this is, that by that very logic the only thing you are transporting/retaining from an information theory perspective is the statistical distribution. All which is downstream may only reasonable make use of that, - the distribution you used as input.\n\n\n\n\nThe odd thing is that that data is then used to train ML Algorithms, which in turn do regression to re-capture those same statistical properties. Overinterpretation beyond the statistics that generated the new distribution would be bad science. In a very strict sense you are not really creating actual data, you are generating a random distribution which has the desired statistical properties.\n\n\n\n\nIf that is the case, then there is no need to generate \"synthetic data\" in the first place. We could just use statistical properties from the original real-world dataset and say out loud that we only use aggregated information, which does not contain sensitive elements, - and be done with it.\n\n\n\n\nThe more I think about it, the less it makes sense to me. What am I missing about \"synthetic datasets\"?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MPIchael", "profile_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "user_type": "registered"}, "created_at": "2026-06-25T05:45:16+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "E2F45942-7443-4F15-8991-FDF70E27B9DF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/E2F45942-7443-4F15-8991-FDF70E27B9DF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MPIchael", "profile_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "user_type": "registered"}, "created_at": "2026-06-25T09:09:59+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "D6187EC0-3D62-4D69-9E19-3DB7B82A7314", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/D6187EC0-3D62-4D69-9E19-3DB7B82A7314/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MPIchael", "profile_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "user_type": "registered"}, "created_at": "2026-06-25T09:16:19+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "53D91AF9-3EEF-4C30-8105-7FC997301F9A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/53D91AF9-3EEF-4C30-8105-7FC997301F9A/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-06-26T12:51:11+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "488B6C83-6596-4ED8-86C9-FE9F51E7A076", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://scicomp.stackexchange.com/revisions/488B6C83-6596-4ED8-86C9-FE9F51E7A076/view-source"}], "source_site": "scicomp", "source_url": "https://scicomp.stackexchange.com/questions/45474/what-is-the-reason-to-argue-for-and-use-synthetic-data", "split": "validation", "split_group": "8e0b7e37727c75b4e59812f04cf6fc964d362ec27f7b583cdb9e039295a5406d", "tags": ["statistics", "data-sets", "sample-statistics", "anonymization"], "thread_id": "scicomp:45474", "title": "What is the reason to argue for and use \"synthetic data\"?"}} {"citation_context": "ic dataset of green screen footage to make a better green screen remover. (Their video on it here) (https://www.youtube.com/watch?v=3Ploi723hg4) They couldn't rely on previously shot green screen footage because they needed flawless examples o", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.youtube.com/watch?v=3Ploi723hg4", "kind": "external_url", "post_id": 45478, "post_url": "https://scicomp.stackexchange.com/a/45478", "product": "citations", "record_id": "Scientific-Citation-Graph:dfb2a67a06742e95f3b1516b", "split": "validation", "thread": {"accepted_answer_id": 45478, "answers": [{"answer_html": "One reason to do this is that a "synthetic data set" can be made available to other researchers while privacy considerations might prevent the sharing of the actual original data set.
\nOf course, this leaves the problem of checking that the synthesis procedure didn't alter the data in undesirable ways. One option would be to ask the peer reviewers to examine the actual and synthetic data sets for problems.
\n", "answer_id": 45475, "answer_text": "One reason to do this is that a \"synthetic data set\" can be made available to other researchers while privacy considerations might prevent the sharing of the actual original data set.\n\n\n\n\nOf course, this leaves the problem of checking that the synthesis procedure didn't alter the data in undesirable ways. One option would be to ask the peer reviewers to examine the actual and synthetic data sets for problems.", "answer_url": "https://scicomp.stackexchange.com/a/45475", "author": "Brian Borchers", "author_url": "https://scicomp.stackexchange.com/users/2150/brian-borchers", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-26T03:32:57+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Brian Borchers", "profile_url": "https://scicomp.stackexchange.com/users/2150/brian-borchers", "user_type": "registered"}, "created_at": "2026-06-26T03:32:57+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "AE0F0142-479D-46CB-8BE0-BD8B4FB1EA03", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/AE0F0142-479D-46CB-8BE0-BD8B4FB1EA03/view-source"}], "score": 2, "updated_at": "2026-06-26T03:32:57+00:00"}, {"answer_html": "I believe "synthetic data" is very often used to designate data that we can only characterize as the result of a process with certain characteristics. Thus we do not have a complete analytic characterization, like statistical distribution.
\nFor example, we often use synthetic seismic data, meaning seismic waves generated by a time integrator for the elastic wave equations through a model of the Earth. We measure the virtual output at seismometers, and compare that to actual data. The result of the integrator cannot be neatly summarized as you indicate above. We have also done a similar thing using data from the simulation of the combustion chamber of a hybrid rocket to look at turbulent correlations.
\n", "answer_id": 45476, "answer_text": "I believe \"synthetic data\" is very often used to designate data that we can only characterize as the result of a process with certain characteristics. Thus we do not have a complete analytic characterization, like statistical distribution.\n\n\n\n\nFor example, we often use synthetic seismic data, meaning seismic waves generated by a time integrator for the elastic wave equations through a model of the Earth. We measure the virtual output at seismometers, and compare that to actual data. The result of the integrator cannot be neatly summarized as you indicate above. We have also done a similar thing using data from the simulation of the combustion chamber of a hybrid rocket to look at turbulent correlations.", "answer_url": "https://scicomp.stackexchange.com/a/45476", "author": "Matt Knepley", "author_url": "https://scicomp.stackexchange.com/users/21/matt-knepley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-26T14:38:38+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Matt Knepley", "profile_url": "https://scicomp.stackexchange.com/users/21/matt-knepley", "user_type": "registered"}, "created_at": "2026-06-26T14:38:38+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "B6A66FA8-FB59-4295-8D07-5C149B6459ED", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/B6A66FA8-FB59-4295-8D07-5C149B6459ED/view-source"}], "score": 5, "updated_at": "2026-06-26T14:38:38+00:00"}, {"answer_html": "I used to work at a company that created the kind of synthetic medical data that you're talking about. In our case, we did it so that we could show a demonstration of the system without revealing private health information. A ML Algorithm might not care about an individual's record, but a doctor or administrator would want to see how the whole system works before buying it. We wouldn't include the doctor's notes (too much risk of personal identifiable information being inserted there) but we could create alternative patient and doctor names, change dates within a certain acceptable range (a few years for birthdays, a few weeks for visits), stuff like that. It was changed just enough that no one could look at our demo and figure out which real world person's medical record it was associated with, but not enough to mess up analytics on the dataset.
\nAnother use case for synthetic data is when you simply don't have a natural dataset that's up to the task, so you create one. A fun example was Corridor Digital creating a synthetic dataset of green screen footage to make a better green screen remover. (Their video on it here) They couldn't rely on previously shot green screen footage because they needed flawless examples of what that same footage would look like with the green screen perfectly removed, so they created a completely digital training set of fake green screen footage and rendered the same scene without the background as the ground truth. The resulting model was able to work just fine with real world green screen footage, even though it wasn't part of the training dataset at all.
\n", "answer_id": 45478, "answer_text": "I used to work at a company that created the kind of synthetic medical data that you're talking about. In our case, we did it so that we could show a demonstration of the system without revealing private health information. A ML Algorithm might not care about an individual's record, but a doctor or administrator would want to see how the whole system works before buying it. We wouldn't include the doctor's notes (too much risk of personal identifiable information being inserted there) but we could create alternative patient and doctor names, change dates within a certain acceptable range (a few years for birthdays, a few weeks for visits), stuff like that. It was changed just enough that no one could look at our demo and figure out which real world person's medical record it was associated with, but not enough to mess up analytics on the dataset.\n\n\n\n\nAnother use case for synthetic data is when you simply don't have a natural dataset that's up to the task, so you create one. A fun example was Corridor Digital creating a synthetic dataset of green screen footage to make a better green screen remover. (Their video on it here) (https://www.youtube.com/watch?v=3Ploi723hg4) They couldn't rely on previously shot green screen footage because they needed flawless examples of what that same footage would look like with the green screen perfectly removed, so they created a completely digital training set of fake green screen footage and rendered the same scene without the background as the ground truth. The resulting model was able to work just fine with real world green screen footage, even though it wasn't part of the training dataset at all.", "answer_url": "https://scicomp.stackexchange.com/a/45478", "author": "Dr. Cyanide", "author_url": "https://scicomp.stackexchange.com/users/56986/dr-cyanide", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-26T19:05:21+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dr. Cyanide", "profile_url": "https://scicomp.stackexchange.com/users/56986/dr-cyanide", "user_type": "registered"}, "created_at": "2026-06-26T19:05:21+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "58D1370C-30E1-48E0-85D3-61EF0F7449AA", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/58D1370C-30E1-48E0-85D3-61EF0F7449AA/view-source"}], "score": 7, "updated_at": "2026-06-26T19:05:21+00:00"}, {"answer_html": "Synthetic data in my area of machine learning just means using data generated by a model rather than "real" data collected from the environment. In my case, I often use synthetic data because you know what the true model is so you have "ground truth" you can use to judge the performance of your ML model. I use synthetic data in Monte Carlo simulations (where you perform the same analysis again and again with different data) as I can generate as much independent data as I like. This means I can detect biases in the ML models. Also because I can generate as much data as I like, I can get reliable performance estimates with a very low variance by having a very large test set. In those cases, I am usually investigating the properties of the learning algorithm, rather than the data or the process that generated the data (so there is no "over-interpretation").
\nAnother reason for using synthetic data is as a proof of concept, where there just isn't enough real data to meaningfully train a model.
\nIn other case, we can model the data in one direction very well, but want to do the prediction in the other direction. For instance, we might be able to work out what a magnetometer picks up when it runs over buried architectural remains, so we could use synthetic data to train a model to predict the depth of buried remains from magenetometer data, which archeologists could use to investigate historical sites without actually digging them up (save for a few test trenches used to validate the system). https://doi.org/10.1002/arp.236
\nHowever it may mean other things in other fields.
\n", "answer_id": 45480, "answer_text": "Synthetic data in my area of machine learning just means using data generated by a model rather than \"real\" data collected from the environment. In my case, I often use synthetic data because you know what the true model is so you have \"ground truth\" you can use to judge the performance of your ML model. I use synthetic data in Monte Carlo simulations (where you perform the same analysis again and again with different data) as I can generate as much independent data as I like. This means I can detect biases in the ML models. Also because I can generate as much data as I like, I can get reliable performance estimates with a very low variance by having a very large test set. In those cases, I am usually investigating the properties of the learning algorithm, rather than the data or the process that generated the data (so there is no \"over-interpretation\").\n\n\n\n\nAnother reason for using synthetic data is as a proof of concept, where there just isn't enough real data to meaningfully train a model.\n\n\n\n\nIn other case, we can model the data in one direction very well, but want to do the prediction in the other direction. For instance, we might be able to work out what a magnetometer picks up when it runs over buried architectural remains, so we could use synthetic data to train a model to predict the depth of buried remains from magenetometer data, which archeologists could use to investigate historical sites without actually digging them up (save for a few test trenches used to validate the system). https://doi.org/10.1002/arp.236 (https://doi.org/10.1002/arp.236)\n\n\n\n\nHowever it may mean other things in other fields.", "answer_url": "https://scicomp.stackexchange.com/a/45480", "author": "Dikran Marsupial", "author_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-27T15:51:23+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dikran Marsupial", "profile_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "user_type": "registered"}, "created_at": "2026-06-27T15:51:23+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "B3F429EC-FC98-4CEC-B864-39792D560780", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/B3F429EC-FC98-4CEC-B864-39792D560780/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dikran Marsupial", "profile_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "user_type": "registered"}, "created_at": "2026-06-27T15:56:36+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "5861285C-8F68-46CE-9D25-B14639ABD89C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/5861285C-8F68-46CE-9D25-B14639ABD89C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dikran Marsupial", "profile_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "user_type": "registered"}, "created_at": "2026-06-29T12:49:45+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "492BACCC-A8FD-4406-A28E-134F43DC4601", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/492BACCC-A8FD-4406-A28E-134F43DC4601/view-source"}], "score": 4, "updated_at": "2026-06-29T12:49:45+00:00"}, {"answer_html": "Another instance when synthetic data is useful is when there is a very low probability event that you want to train on. In a completely natural sample (with our without aliased names) where an unlikely event is nonetheless important (think about a self-driving program where a person steps off the sidewalk in the dark pushing a bicycle). This event would be rare, if even existant in sampled data, but you can create enough instances of it, with some variations, in synthetic data.\nThe 15% of events that occur 85% of the time should not consume 85% of your training time, and important events that occur 0.1% of the time need much more than 0.1% of your training time if they are to be learned.
\n", "answer_id": 45483, "answer_text": "Another instance when synthetic data is useful is when there is a very low probability event that you want to train on. In a completely natural sample (with our without aliased names) where an unlikely event is nonetheless important (think about a self-driving program where a person steps off the sidewalk in the dark pushing a bicycle). This event would be rare, if even existant in sampled data, but you can create enough instances of it, with some variations, in synthetic data.\nThe 15% of events that occur 85% of the time should not consume 85% of your training time, and important events that occur 0.1% of the time need much more than 0.1% of your training time if they are to be learned.", "answer_url": "https://scicomp.stackexchange.com/a/45483", "author": "user2540850", "author_url": "https://scicomp.stackexchange.com/users/56990/user2540850", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-29T00:19:21+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "user2540850", "profile_url": "https://scicomp.stackexchange.com/users/56990/user2540850", "user_type": "registered"}, "created_at": "2026-06-29T00:19:21+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "EACE18B0-EE6C-4205-A703-1A9C528C32E8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/EACE18B0-EE6C-4205-A703-1A9C528C32E8/view-source"}], "score": 1, "updated_at": "2026-06-29T00:19:21+00:00"}], "domain": "computational_science", "external_links": ["https://doi.org/10.1002/arp.236", "https://www.sciencedirect.com/science/article/pii/S2001037024002393", "https://www.youtube.com/watch?v=3Ploi723hg4"], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "MPIchael", "question_author_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "question_author_user_type": "registered", "question_created_at": "2026-06-25T05:45:16+00:00", "question_html": "I recently see the term "synthetic data" bubbling up in funding calls and in my scientific context [e.g. 1]. My understanding of the term is that in cases where the actual dataset contains very sensitive information, it is possible to create a separate dataset which has the same statistical properties as the real one. Then people use and share the "synthetic" dataset either to feed it to a downstream algorithm or to test/validate software.
\nOn the very first glance this approach sounds legitimate, because you strip all the privacy problems while retaining a dataset with the same statistical properties. My problem with this is, that by that very logic the only thing you are transporting/retaining from an information theory perspective is the statistical distribution. All which is downstream may only reasonable make use of that, - the distribution you used as input.
\nThe odd thing is that that data is then used to train ML Algorithms, which in turn do regression to re-capture those same statistical properties. Overinterpretation beyond the statistics that generated the new distribution would be bad science. In a very strict sense you are not really creating actual data, you are generating a random distribution which has the desired statistical properties.
\nIf that is the case, then there is no need to generate "synthetic data" in the first place. We could just use statistical properties from the original real-world dataset and say out loud that we only use aggregated information, which does not contain sensitive elements, - and be done with it.
\nThe more I think about it, the less it makes sense to me. What am I missing about "synthetic datasets"?
\n", "question_id": 45474, "question_license": "CC BY-SA 4.0", "question_score": 6, "question_text": "I recently see the term \"synthetic data\" bubbling up in funding calls and in my scientific context [e.g. 1 (https://www.sciencedirect.com/science/article/pii/S2001037024002393)]. My understanding of the term is that in cases where the actual dataset contains very sensitive information, it is possible to create a separate dataset which has the same statistical properties as the real one. Then people use and share the \"synthetic\" dataset either to feed it to a downstream algorithm or to test/validate software.\n\n\n\n\nOn the very first glance this approach sounds legitimate, because you strip all the privacy problems while retaining a dataset with the same statistical properties. My problem with this is, that by that very logic the only thing you are transporting/retaining from an information theory perspective is the statistical distribution. All which is downstream may only reasonable make use of that, - the distribution you used as input.\n\n\n\n\nThe odd thing is that that data is then used to train ML Algorithms, which in turn do regression to re-capture those same statistical properties. Overinterpretation beyond the statistics that generated the new distribution would be bad science. In a very strict sense you are not really creating actual data, you are generating a random distribution which has the desired statistical properties.\n\n\n\n\nIf that is the case, then there is no need to generate \"synthetic data\" in the first place. We could just use statistical properties from the original real-world dataset and say out loud that we only use aggregated information, which does not contain sensitive elements, - and be done with it.\n\n\n\n\nThe more I think about it, the less it makes sense to me. What am I missing about \"synthetic datasets\"?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MPIchael", "profile_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "user_type": "registered"}, "created_at": "2026-06-25T05:45:16+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "E2F45942-7443-4F15-8991-FDF70E27B9DF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/E2F45942-7443-4F15-8991-FDF70E27B9DF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MPIchael", "profile_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "user_type": "registered"}, "created_at": "2026-06-25T09:09:59+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "D6187EC0-3D62-4D69-9E19-3DB7B82A7314", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/D6187EC0-3D62-4D69-9E19-3DB7B82A7314/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MPIchael", "profile_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "user_type": "registered"}, "created_at": "2026-06-25T09:16:19+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "53D91AF9-3EEF-4C30-8105-7FC997301F9A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/53D91AF9-3EEF-4C30-8105-7FC997301F9A/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-06-26T12:51:11+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "488B6C83-6596-4ED8-86C9-FE9F51E7A076", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://scicomp.stackexchange.com/revisions/488B6C83-6596-4ED8-86C9-FE9F51E7A076/view-source"}], "source_site": "scicomp", "source_url": "https://scicomp.stackexchange.com/questions/45474/what-is-the-reason-to-argue-for-and-use-synthetic-data", "split": "validation", "split_group": "8e0b7e37727c75b4e59812f04cf6fc964d362ec27f7b583cdb9e039295a5406d", "tags": ["statistics", "data-sets", "sample-statistics", "anonymization"], "thread_id": "scicomp:45474", "title": "What is the reason to argue for and use \"synthetic data\"?"}} {"citation_context": "sites without actually digging them up (save for a few test trenches used to validate the system). https://doi.org/10.1002/arp.236 (https://doi.org/10.1002/arp.236)\n\n\n\n\nHowever it may mean other things in other fields.", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": "10.1002/arp.236", "external_url": "https://doi.org/10.1002/arp.236", "kind": "doi_url", "post_id": 45480, "post_url": "https://scicomp.stackexchange.com/a/45480", "product": "citations", "record_id": "Scientific-Citation-Graph:1453bb56c34b3d235daf82eb", "split": "validation", "thread": {"accepted_answer_id": 45478, "answers": [{"answer_html": "One reason to do this is that a "synthetic data set" can be made available to other researchers while privacy considerations might prevent the sharing of the actual original data set.
\nOf course, this leaves the problem of checking that the synthesis procedure didn't alter the data in undesirable ways. One option would be to ask the peer reviewers to examine the actual and synthetic data sets for problems.
\n", "answer_id": 45475, "answer_text": "One reason to do this is that a \"synthetic data set\" can be made available to other researchers while privacy considerations might prevent the sharing of the actual original data set.\n\n\n\n\nOf course, this leaves the problem of checking that the synthesis procedure didn't alter the data in undesirable ways. One option would be to ask the peer reviewers to examine the actual and synthetic data sets for problems.", "answer_url": "https://scicomp.stackexchange.com/a/45475", "author": "Brian Borchers", "author_url": "https://scicomp.stackexchange.com/users/2150/brian-borchers", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-26T03:32:57+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Brian Borchers", "profile_url": "https://scicomp.stackexchange.com/users/2150/brian-borchers", "user_type": "registered"}, "created_at": "2026-06-26T03:32:57+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "AE0F0142-479D-46CB-8BE0-BD8B4FB1EA03", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/AE0F0142-479D-46CB-8BE0-BD8B4FB1EA03/view-source"}], "score": 2, "updated_at": "2026-06-26T03:32:57+00:00"}, {"answer_html": "I believe "synthetic data" is very often used to designate data that we can only characterize as the result of a process with certain characteristics. Thus we do not have a complete analytic characterization, like statistical distribution.
\nFor example, we often use synthetic seismic data, meaning seismic waves generated by a time integrator for the elastic wave equations through a model of the Earth. We measure the virtual output at seismometers, and compare that to actual data. The result of the integrator cannot be neatly summarized as you indicate above. We have also done a similar thing using data from the simulation of the combustion chamber of a hybrid rocket to look at turbulent correlations.
\n", "answer_id": 45476, "answer_text": "I believe \"synthetic data\" is very often used to designate data that we can only characterize as the result of a process with certain characteristics. Thus we do not have a complete analytic characterization, like statistical distribution.\n\n\n\n\nFor example, we often use synthetic seismic data, meaning seismic waves generated by a time integrator for the elastic wave equations through a model of the Earth. We measure the virtual output at seismometers, and compare that to actual data. The result of the integrator cannot be neatly summarized as you indicate above. We have also done a similar thing using data from the simulation of the combustion chamber of a hybrid rocket to look at turbulent correlations.", "answer_url": "https://scicomp.stackexchange.com/a/45476", "author": "Matt Knepley", "author_url": "https://scicomp.stackexchange.com/users/21/matt-knepley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-26T14:38:38+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Matt Knepley", "profile_url": "https://scicomp.stackexchange.com/users/21/matt-knepley", "user_type": "registered"}, "created_at": "2026-06-26T14:38:38+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "B6A66FA8-FB59-4295-8D07-5C149B6459ED", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/B6A66FA8-FB59-4295-8D07-5C149B6459ED/view-source"}], "score": 5, "updated_at": "2026-06-26T14:38:38+00:00"}, {"answer_html": "I used to work at a company that created the kind of synthetic medical data that you're talking about. In our case, we did it so that we could show a demonstration of the system without revealing private health information. A ML Algorithm might not care about an individual's record, but a doctor or administrator would want to see how the whole system works before buying it. We wouldn't include the doctor's notes (too much risk of personal identifiable information being inserted there) but we could create alternative patient and doctor names, change dates within a certain acceptable range (a few years for birthdays, a few weeks for visits), stuff like that. It was changed just enough that no one could look at our demo and figure out which real world person's medical record it was associated with, but not enough to mess up analytics on the dataset.
\nAnother use case for synthetic data is when you simply don't have a natural dataset that's up to the task, so you create one. A fun example was Corridor Digital creating a synthetic dataset of green screen footage to make a better green screen remover. (Their video on it here) They couldn't rely on previously shot green screen footage because they needed flawless examples of what that same footage would look like with the green screen perfectly removed, so they created a completely digital training set of fake green screen footage and rendered the same scene without the background as the ground truth. The resulting model was able to work just fine with real world green screen footage, even though it wasn't part of the training dataset at all.
\n", "answer_id": 45478, "answer_text": "I used to work at a company that created the kind of synthetic medical data that you're talking about. In our case, we did it so that we could show a demonstration of the system without revealing private health information. A ML Algorithm might not care about an individual's record, but a doctor or administrator would want to see how the whole system works before buying it. We wouldn't include the doctor's notes (too much risk of personal identifiable information being inserted there) but we could create alternative patient and doctor names, change dates within a certain acceptable range (a few years for birthdays, a few weeks for visits), stuff like that. It was changed just enough that no one could look at our demo and figure out which real world person's medical record it was associated with, but not enough to mess up analytics on the dataset.\n\n\n\n\nAnother use case for synthetic data is when you simply don't have a natural dataset that's up to the task, so you create one. A fun example was Corridor Digital creating a synthetic dataset of green screen footage to make a better green screen remover. (Their video on it here) (https://www.youtube.com/watch?v=3Ploi723hg4) They couldn't rely on previously shot green screen footage because they needed flawless examples of what that same footage would look like with the green screen perfectly removed, so they created a completely digital training set of fake green screen footage and rendered the same scene without the background as the ground truth. The resulting model was able to work just fine with real world green screen footage, even though it wasn't part of the training dataset at all.", "answer_url": "https://scicomp.stackexchange.com/a/45478", "author": "Dr. Cyanide", "author_url": "https://scicomp.stackexchange.com/users/56986/dr-cyanide", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-26T19:05:21+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dr. Cyanide", "profile_url": "https://scicomp.stackexchange.com/users/56986/dr-cyanide", "user_type": "registered"}, "created_at": "2026-06-26T19:05:21+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "58D1370C-30E1-48E0-85D3-61EF0F7449AA", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/58D1370C-30E1-48E0-85D3-61EF0F7449AA/view-source"}], "score": 7, "updated_at": "2026-06-26T19:05:21+00:00"}, {"answer_html": "Synthetic data in my area of machine learning just means using data generated by a model rather than "real" data collected from the environment. In my case, I often use synthetic data because you know what the true model is so you have "ground truth" you can use to judge the performance of your ML model. I use synthetic data in Monte Carlo simulations (where you perform the same analysis again and again with different data) as I can generate as much independent data as I like. This means I can detect biases in the ML models. Also because I can generate as much data as I like, I can get reliable performance estimates with a very low variance by having a very large test set. In those cases, I am usually investigating the properties of the learning algorithm, rather than the data or the process that generated the data (so there is no "over-interpretation").
\nAnother reason for using synthetic data is as a proof of concept, where there just isn't enough real data to meaningfully train a model.
\nIn other case, we can model the data in one direction very well, but want to do the prediction in the other direction. For instance, we might be able to work out what a magnetometer picks up when it runs over buried architectural remains, so we could use synthetic data to train a model to predict the depth of buried remains from magenetometer data, which archeologists could use to investigate historical sites without actually digging them up (save for a few test trenches used to validate the system). https://doi.org/10.1002/arp.236
\nHowever it may mean other things in other fields.
\n", "answer_id": 45480, "answer_text": "Synthetic data in my area of machine learning just means using data generated by a model rather than \"real\" data collected from the environment. In my case, I often use synthetic data because you know what the true model is so you have \"ground truth\" you can use to judge the performance of your ML model. I use synthetic data in Monte Carlo simulations (where you perform the same analysis again and again with different data) as I can generate as much independent data as I like. This means I can detect biases in the ML models. Also because I can generate as much data as I like, I can get reliable performance estimates with a very low variance by having a very large test set. In those cases, I am usually investigating the properties of the learning algorithm, rather than the data or the process that generated the data (so there is no \"over-interpretation\").\n\n\n\n\nAnother reason for using synthetic data is as a proof of concept, where there just isn't enough real data to meaningfully train a model.\n\n\n\n\nIn other case, we can model the data in one direction very well, but want to do the prediction in the other direction. For instance, we might be able to work out what a magnetometer picks up when it runs over buried architectural remains, so we could use synthetic data to train a model to predict the depth of buried remains from magenetometer data, which archeologists could use to investigate historical sites without actually digging them up (save for a few test trenches used to validate the system). https://doi.org/10.1002/arp.236 (https://doi.org/10.1002/arp.236)\n\n\n\n\nHowever it may mean other things in other fields.", "answer_url": "https://scicomp.stackexchange.com/a/45480", "author": "Dikran Marsupial", "author_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-27T15:51:23+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dikran Marsupial", "profile_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "user_type": "registered"}, "created_at": "2026-06-27T15:51:23+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "B3F429EC-FC98-4CEC-B864-39792D560780", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/B3F429EC-FC98-4CEC-B864-39792D560780/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dikran Marsupial", "profile_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "user_type": "registered"}, "created_at": "2026-06-27T15:56:36+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "5861285C-8F68-46CE-9D25-B14639ABD89C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/5861285C-8F68-46CE-9D25-B14639ABD89C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Dikran Marsupial", "profile_url": "https://scicomp.stackexchange.com/users/56988/dikran-marsupial", "user_type": "registered"}, "created_at": "2026-06-29T12:49:45+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "492BACCC-A8FD-4406-A28E-134F43DC4601", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/492BACCC-A8FD-4406-A28E-134F43DC4601/view-source"}], "score": 4, "updated_at": "2026-06-29T12:49:45+00:00"}, {"answer_html": "Another instance when synthetic data is useful is when there is a very low probability event that you want to train on. In a completely natural sample (with our without aliased names) where an unlikely event is nonetheless important (think about a self-driving program where a person steps off the sidewalk in the dark pushing a bicycle). This event would be rare, if even existant in sampled data, but you can create enough instances of it, with some variations, in synthetic data.\nThe 15% of events that occur 85% of the time should not consume 85% of your training time, and important events that occur 0.1% of the time need much more than 0.1% of your training time if they are to be learned.
\n", "answer_id": 45483, "answer_text": "Another instance when synthetic data is useful is when there is a very low probability event that you want to train on. In a completely natural sample (with our without aliased names) where an unlikely event is nonetheless important (think about a self-driving program where a person steps off the sidewalk in the dark pushing a bicycle). This event would be rare, if even existant in sampled data, but you can create enough instances of it, with some variations, in synthetic data.\nThe 15% of events that occur 85% of the time should not consume 85% of your training time, and important events that occur 0.1% of the time need much more than 0.1% of your training time if they are to be learned.", "answer_url": "https://scicomp.stackexchange.com/a/45483", "author": "user2540850", "author_url": "https://scicomp.stackexchange.com/users/56990/user2540850", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-06-29T00:19:21+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45474, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "user2540850", "profile_url": "https://scicomp.stackexchange.com/users/56990/user2540850", "user_type": "registered"}, "created_at": "2026-06-29T00:19:21+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "EACE18B0-EE6C-4205-A703-1A9C528C32E8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/EACE18B0-EE6C-4205-A703-1A9C528C32E8/view-source"}], "score": 1, "updated_at": "2026-06-29T00:19:21+00:00"}], "domain": "computational_science", "external_links": ["https://doi.org/10.1002/arp.236", "https://www.sciencedirect.com/science/article/pii/S2001037024002393", "https://www.youtube.com/watch?v=3Ploi723hg4"], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "MPIchael", "question_author_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "question_author_user_type": "registered", "question_created_at": "2026-06-25T05:45:16+00:00", "question_html": "I recently see the term "synthetic data" bubbling up in funding calls and in my scientific context [e.g. 1]. My understanding of the term is that in cases where the actual dataset contains very sensitive information, it is possible to create a separate dataset which has the same statistical properties as the real one. Then people use and share the "synthetic" dataset either to feed it to a downstream algorithm or to test/validate software.
\nOn the very first glance this approach sounds legitimate, because you strip all the privacy problems while retaining a dataset with the same statistical properties. My problem with this is, that by that very logic the only thing you are transporting/retaining from an information theory perspective is the statistical distribution. All which is downstream may only reasonable make use of that, - the distribution you used as input.
\nThe odd thing is that that data is then used to train ML Algorithms, which in turn do regression to re-capture those same statistical properties. Overinterpretation beyond the statistics that generated the new distribution would be bad science. In a very strict sense you are not really creating actual data, you are generating a random distribution which has the desired statistical properties.
\nIf that is the case, then there is no need to generate "synthetic data" in the first place. We could just use statistical properties from the original real-world dataset and say out loud that we only use aggregated information, which does not contain sensitive elements, - and be done with it.
\nThe more I think about it, the less it makes sense to me. What am I missing about "synthetic datasets"?
\n", "question_id": 45474, "question_license": "CC BY-SA 4.0", "question_score": 6, "question_text": "I recently see the term \"synthetic data\" bubbling up in funding calls and in my scientific context [e.g. 1 (https://www.sciencedirect.com/science/article/pii/S2001037024002393)]. My understanding of the term is that in cases where the actual dataset contains very sensitive information, it is possible to create a separate dataset which has the same statistical properties as the real one. Then people use and share the \"synthetic\" dataset either to feed it to a downstream algorithm or to test/validate software.\n\n\n\n\nOn the very first glance this approach sounds legitimate, because you strip all the privacy problems while retaining a dataset with the same statistical properties. My problem with this is, that by that very logic the only thing you are transporting/retaining from an information theory perspective is the statistical distribution. All which is downstream may only reasonable make use of that, - the distribution you used as input.\n\n\n\n\nThe odd thing is that that data is then used to train ML Algorithms, which in turn do regression to re-capture those same statistical properties. Overinterpretation beyond the statistics that generated the new distribution would be bad science. In a very strict sense you are not really creating actual data, you are generating a random distribution which has the desired statistical properties.\n\n\n\n\nIf that is the case, then there is no need to generate \"synthetic data\" in the first place. We could just use statistical properties from the original real-world dataset and say out loud that we only use aggregated information, which does not contain sensitive elements, - and be done with it.\n\n\n\n\nThe more I think about it, the less it makes sense to me. What am I missing about \"synthetic datasets\"?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MPIchael", "profile_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "user_type": "registered"}, "created_at": "2026-06-25T05:45:16+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "E2F45942-7443-4F15-8991-FDF70E27B9DF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/E2F45942-7443-4F15-8991-FDF70E27B9DF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MPIchael", "profile_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "user_type": "registered"}, "created_at": "2026-06-25T09:09:59+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "D6187EC0-3D62-4D69-9E19-3DB7B82A7314", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/D6187EC0-3D62-4D69-9E19-3DB7B82A7314/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MPIchael", "profile_url": "https://scicomp.stackexchange.com/users/28636/mpichael", "user_type": "registered"}, "created_at": "2026-06-25T09:16:19+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "53D91AF9-3EEF-4C30-8105-7FC997301F9A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/53D91AF9-3EEF-4C30-8105-7FC997301F9A/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-06-26T12:51:11+00:00", "raw_file": "raw/codex_api_v1/09cbe10ae05462240864407122b451f89c4541eb0ee757adda70c0629772d57a_1790825351806992800_0.json", "raw_sha256": "34f3f34325937951c51090d8305fb513e1e88ef2ed40dcec5c0fe96d5710ba75", "revision_guid": "488B6C83-6596-4ED8-86C9-FE9F51E7A076", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://scicomp.stackexchange.com/revisions/488B6C83-6596-4ED8-86C9-FE9F51E7A076/view-source"}], "source_site": "scicomp", "source_url": "https://scicomp.stackexchange.com/questions/45474/what-is-the-reason-to-argue-for-and-use-synthetic-data", "split": "validation", "split_group": "8e0b7e37727c75b4e59812f04cf6fc964d362ec27f7b583cdb9e039295a5406d", "tags": ["statistics", "data-sets", "sample-statistics", "anonymization"], "thread_id": "scicomp:45474", "title": "What is the reason to argue for and use \"synthetic data\"?"}} {"citation_context": "For 90 bounding boxes, we see a non-axis intersection being selected:\n\n\n\n\n[image: 90 boxes; source: https://i.sstatic.net/B0XWwMzu.png] (https://i.sstatic.net/B0XWwMzu.png)\n\n\n\n\nOn my old laptop, this processes 1,000 bounding boxes in ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/B0XWwMzu.png", "kind": "external_url", "post_id": 45537, "post_url": "https://scicomp.stackexchange.com/a/45537", "product": "citations", "record_id": "Scientific-Citation-Graph:97cc1f6fede2aed935ef1fc6", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The key insight (also reflected in this comment) is that the closest non-occluded point will either be at the intersection of two bounding box segments, or will be at the intersection of one bounding box segment and one axis - after the problem space has been translated so that $P = (0,0)$. The axis intersection is because of the 'axis-aligned' bounding boxes and the fact that Euclidean norm to a point on vertical segments will scale as $\\frac 1 {\\cos(\\theta)}$ and norm to a point on horizontal segments will scale as $\\frac 1 {\\sin(\\theta)}$. In both cases, the result is that the norm minima are seen at axis intersections ($\\theta = \\frac {\\pi n} 2$).
\nSince you've failed to describe the scale of the problem, start with a simple $O(n^2)$ implementation - which, for small problems, may actually out-perform anything more sophisticated. That depends on a lot of things and requires benchmarking diligence. Loosely,
\nFor small bounding box count, it's very frequent that an axis intersection is selected:
\n\nFor 90 bounding boxes, we see a non-axis intersection being selected:
\n\nOn my old laptop, this processes 1,000 bounding boxes in 0.3 seconds.
\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.patches import Rectangle, Circle\n\n\ndef sample_data(n: int = 20, seed: int = 0) -> np.ndarray:\n """\n Generate a tensor of ((2=x,y), (2=min,max), n) bounding boxes\n """\n rand = np.random.default_rng(seed)\n box = np.empty(shape=(2, 2, n), dtype=np.float32)\n box[..., 0] = (\n (-0.3, +0.3),\n (-0.3, +0.3),\n )\n box[:, 0, 1:] = rand.uniform(low=-1, high=0.5, size=(2, n-1))\n box[:, 1, 1:] = rand.uniform(low=0, high=0.5, size=(2, n-1)) + box[:, 0, 1:]\n return box.round(2)\n\n\ndef intersect_points(box: np.ndarray) -> np.ndarray:\n n = box.shape[-1]\n\n # All segments from bounding boxes min,max, and axis:\n # segment coordinate values on parallel axis\n segments_par = np.empty(\n shape=(2, 2, 2*n + 1), # (x,y), (parmin,parmax), (perp min, perp max)n + axis\n dtype=box.dtype,\n )\n segments_par[..., :-1] = box.repeat(2, axis=-1)\n # The last line is the axis. The axis intersecting any bounding box produces candidate points\n # for the closest-exterior output.\n segments_par[..., -1] = -np.inf, +np.inf\n\n # segment coordinate values on perpendicular axis\n # (y,x), (perp min, perp max)n + axis\n segments_perp = np.empty(shape=segments_par.shape[1:], dtype=box.dtype)\n segments_perp[:, :-1] = box.transpose((0, 2, 1)).reshape((2, -1))\n segments_perp[:, -1] = 0 # Axis intersects (0,0)\n\n x0, x1 = segments_par[0, :, :, np.newaxis]\n y0, y1 = segments_par[1, :, np.newaxis, :]\n xp = segments_perp[0, np.newaxis, :]\n yp = segments_perp[1, :, np.newaxis]\n\n # Outer product produces boolean intersection predicate\n hits = (x0 <= xp) & (xp <= x1) & (y0 <= yp) & (yp <= y1)\n hits[:-1, :-1] &= ~np.kron(np.eye(n, dtype=bool), np.ones((2, 2), dtype=bool))\n hits[-1, -1] = 0\n\n k = segments_par.shape[-1]\n # Intersection coordinates\n xi = np.broadcast_to(xp, (k, k))[hits]\n yi = np.broadcast_to(yp, (k, k))[hits]\n return np.stack((xi, yi)) # (2, n')\n\n\ndef exclude_bounding(box: np.ndarray, xyi: np.ndarray) -> np.ndarray:\n xi, yi = xyi[:, :, np.newaxis]\n (\n (x0, x1),\n (y0, y1),\n ) = box[:, :, np.newaxis, :]\n\n return ~((x0 < xi) & (xi < x1) & (y0 < yi) & (yi < y1)).any(axis=1)\n\n\ndef choose_closest(xyi: np.ndarray) -> int:\n norm2 = np.einsum('ij,ij->j', xyi, xyi) # x**2 + y**2, product (2,n)\n return norm2.argmin()\n\n\ndef plot(box: np.ndarray, xyi: np.ndarray, xy_free: np.ndarray, free: np.ndarray, best: int) -> None:\n fig, ax = plt.subplots()\n ax.add_artist(Circle(xy_free[:, best], radius=0.03, fc='#A0FFA0A0', ec='black'))\n ax.set_xlim(-1.1, 1.1)\n ax.set_ylim(-1.1, 1.1)\n ax.scatter(*xyi[:, ~free], label='occluded')\n ax.scatter(*xy_free, label='free')\n ax.legend()\n\n for (x0, x1), (y0, y1) in box.transpose((2, 0, 1)):\n ax.add_artist(Rectangle((x0, y0), x1-x0, y1-y0, ec='black', fc='#80808020'))\n\n\ndef main() -> None:\n box = sample_data(90)\n xyi = intersect_points(box)\n free = exclude_bounding(box, xyi)\n xy_free = xyi[:, free]\n best = choose_closest(xy_free)\n plot(box, xyi, xy_free, free, best)\n plt.show()\n\n\nif __name__ == '__main__':\n main()\n\n", "answer_id": 45537, "answer_text": "The key insight (also reflected in this comment (https://scicomp.stackexchange.com/questions/45533/find-the-closest-point-outside-overlapping-aabbs-from-a-point-inside-them#comment93668_45533)) is that the closest non-occluded point will either be at the intersection of two bounding box segments, or will be at the intersection of one bounding box segment and one axis - after the problem space has been translated so that $P = (0,0)$. The axis intersection is because of the 'axis-aligned' bounding boxes and the fact that Euclidean norm to a point on vertical segments will scale as $\\frac 1 {\\cos(\\theta)}$ and norm to a point on horizontal segments will scale as $\\frac 1 {\\sin(\\theta)}$. In both cases, the result is that the norm minima are seen at axis intersections ($\\theta = \\frac {\\pi n} 2$).\n\n\n\n\nSince you've failed to describe the scale of the problem, start with a simple $O(n^2)$ implementation - which, for small problems, may actually out-perform anything more sophisticated. That depends on a lot of things and requires benchmarking diligence. Loosely,\n\n\n\n\n\nUnion the set of all box-box intersections and all box-axis intersections\n\n\n\n\nFrom that set, exclude all points that are occluded by a box\n\n\n\n\nDo a tensor contraction to get the squared norm for the remaining intersections\n\n\n\n\nChoose the smallest one.\n\n\n\n\n\nFor small bounding box count, it's very frequent that an axis intersection is selected:\n\n\n\n\n[image: small problem; source: https://i.sstatic.net/rLLW3nkZ.png] (https://i.sstatic.net/rLLW3nkZ.png)\n\n\n\n\nFor 90 bounding boxes, we see a non-axis intersection being selected:\n\n\n\n\n[image: 90 boxes; source: https://i.sstatic.net/B0XWwMzu.png] (https://i.sstatic.net/B0XWwMzu.png)\n\n\n\n\nOn my old laptop, this processes 1,000 bounding boxes in 0.3 seconds.\n\n\n\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.patches import Rectangle, Circle\n\n\ndef sample_data(n: int = 20, seed: int = 0) -> np.ndarray:\n \"\"\"\n Generate a tensor of ((2=x,y), (2=min,max), n) bounding boxes\n \"\"\"\n rand = np.random.default_rng(seed)\n box = np.empty(shape=(2, 2, n), dtype=np.float32)\n box[..., 0] = (\n (-0.3, +0.3),\n (-0.3, +0.3),\n )\n box[:, 0, 1:] = rand.uniform(low=-1, high=0.5, size=(2, n-1))\n box[:, 1, 1:] = rand.uniform(low=0, high=0.5, size=(2, n-1)) + box[:, 0, 1:]\n return box.round(2)\n\n\ndef intersect_points(box: np.ndarray) -> np.ndarray:\n n = box.shape[-1]\n\n # All segments from bounding boxes min,max, and axis:\n # segment coordinate values on parallel axis\n segments_par = np.empty(\n shape=(2, 2, 2*n + 1), # (x,y), (parmin,parmax), (perp min, perp max)n + axis\n dtype=box.dtype,\n )\n segments_par[..., :-1] = box.repeat(2, axis=-1)\n # The last line is the axis. The axis intersecting any bounding box produces candidate points\n # for the closest-exterior output.\n segments_par[..., -1] = -np.inf, +np.inf\n\n # segment coordinate values on perpendicular axis\n # (y,x), (perp min, perp max)n + axis\n segments_perp = np.empty(shape=segments_par.shape[1:], dtype=box.dtype)\n segments_perp[:, :-1] = box.transpose((0, 2, 1)).reshape((2, -1))\n segments_perp[:, -1] = 0 # Axis intersects (0,0)\n\n x0, x1 = segments_par[0, :, :, np.newaxis]\n y0, y1 = segments_par[1, :, np.newaxis, :]\n xp = segments_perp[0, np.newaxis, :]\n yp = segments_perp[1, :, np.newaxis]\n\n # Outer product produces boolean intersection predicate\n hits = (x0 <= xp) & (xp <= x1) & (y0 <= yp) & (yp <= y1)\n hits[:-1, :-1] &= ~np.kron(np.eye(n, dtype=bool), np.ones((2, 2), dtype=bool))\n hits[-1, -1] = 0\n\n k = segments_par.shape[-1]\n # Intersection coordinates\n xi = np.broadcast_to(xp, (k, k))[hits]\n yi = np.broadcast_to(yp, (k, k))[hits]\n return np.stack((xi, yi)) # (2, n')\n\n\ndef exclude_bounding(box: np.ndarray, xyi: np.ndarray) -> np.ndarray:\n xi, yi = xyi[:, :, np.newaxis]\n (\n (x0, x1),\n (y0, y1),\n ) = box[:, :, np.newaxis, :]\n\n return ~((x0 < xi) & (xi < x1) & (y0 < yi) & (yi < y1)).any(axis=1)\n\n\ndef choose_closest(xyi: np.ndarray) -> int:\n norm2 = np.einsum('ij,ij->j', xyi, xyi) # x**2 + y**2, product (2,n)\n return norm2.argmin()\n\n\ndef plot(box: np.ndarray, xyi: np.ndarray, xy_free: np.ndarray, free: np.ndarray, best: int) -> None:\n fig, ax = plt.subplots()\n ax.add_artist(Circle(xy_free[:, best], radius=0.03, fc='#A0FFA0A0', ec='black'))\n ax.set_xlim(-1.1, 1.1)\n ax.set_ylim(-1.1, 1.1)\n ax.scatter(*xyi[:, ~free], label='occluded')\n ax.scatter(*xy_free, label='free')\n ax.legend()\n\n for (x0, x1), (y0, y1) in box.transpose((2, 0, 1)):\n ax.add_artist(Rectangle((x0, y0), x1-x0, y1-y0, ec='black', fc='#80808020'))\n\n\ndef main() -> None:\n box = sample_data(90)\n xyi = intersect_points(box)\n free = exclude_bounding(box, xyi)\n xy_free = xyi[:, free]\n best = choose_closest(xy_free)\n plot(box, xyi, xy_free, free, best)\n plt.show()\n\n\nif __name__ == '__main__':\n main()", "answer_url": "https://scicomp.stackexchange.com/a/45537", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-07T22:20:58+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45533, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2026-09-07T22:20:58+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "EA034CBB-245E-47BE-9F83-73186A65FD54", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/EA034CBB-245E-47BE-9F83-73186A65FD54/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2026-09-07T22:53:19+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "13520681-83F3-4234-8A59-CE187F0BEA29", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/13520681-83F3-4234-8A59-CE187F0BEA29/view-source"}], "score": 2, "updated_at": "2026-09-07T22:53:19+00:00"}], "domain": "computational_science", "external_links": ["https://i.sstatic.net/B0XWwMzu.png", "https://i.sstatic.net/rLLW3nkZ.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "ffbh", "question_author_url": "https://scicomp.stackexchange.com/users/57252/ffbh", "question_author_user_type": "registered", "question_created_at": "2026-09-03T03:48:42+00:00", "question_html": "I have a collection of axis-aligned bounding boxes (AABBs). The AABBs may overlap each other and may form multiple disconnected groups.
\nIs there a known algorithm for this problem?
\nThanks.
\n", "question_id": 45533, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I have a collection of axis-aligned bounding boxes (AABBs). The AABBs may overlap each other and may form multiple disconnected groups.\n\n\n\n\n\nIf P is not inside any AABB, I don't need to do anything.\n\n\n\n\nIf P is inside one or more AABBs, I need to find the closest point to P that is outside all AABBs\n\n\n\n\nA point lying exactly on the edge/boundary of an AABB is considered valid (not inside). Therefore, when P is inside an AABB group, the desired result will normally be a point on the edge of one of the AABBs.\n\n\n\n\n\nIs there a known algorithm for this problem?\n\n\n\n\nThanks.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "ffbh", "profile_url": "https://scicomp.stackexchange.com/users/57252/ffbh", "user_type": "registered"}, "created_at": "2026-09-03T03:48:42+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "4165EEB0-A429-43DE-A4E0-E9FB5F902B12", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/4165EEB0-A429-43DE-A4E0-E9FB5F902B12/view-source"}], "source_site": "scicomp", "source_url": "https://scicomp.stackexchange.com/questions/45533/find-the-closest-point-outside-overlapping-aabbs-from-a-point-inside-them", "split": "validation", "split_group": "71a1e1aa9ca97a050ab7c198593fba301c532fe3b80fdc4f0cab34aff62615f9", "tags": ["algorithms", "computational-geometry", "geometry"], "thread_id": "scicomp:45533", "title": "Find the closest point outside overlapping AABBs from a point inside them"}} {"citation_context": "count, it's very frequent that an axis intersection is selected:\n\n\n\n\n[image: small problem; source: https://i.sstatic.net/rLLW3nkZ.png] (https://i.sstatic.net/rLLW3nkZ.png)\n\n\n\n\nFor 90 bounding boxes, we see a non-axis intersection bei", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/rLLW3nkZ.png", "kind": "external_url", "post_id": 45537, "post_url": "https://scicomp.stackexchange.com/a/45537", "product": "citations", "record_id": "Scientific-Citation-Graph:77de3b2f4dcbcb5e5b59c5f9", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The key insight (also reflected in this comment) is that the closest non-occluded point will either be at the intersection of two bounding box segments, or will be at the intersection of one bounding box segment and one axis - after the problem space has been translated so that $P = (0,0)$. The axis intersection is because of the 'axis-aligned' bounding boxes and the fact that Euclidean norm to a point on vertical segments will scale as $\\frac 1 {\\cos(\\theta)}$ and norm to a point on horizontal segments will scale as $\\frac 1 {\\sin(\\theta)}$. In both cases, the result is that the norm minima are seen at axis intersections ($\\theta = \\frac {\\pi n} 2$).
\nSince you've failed to describe the scale of the problem, start with a simple $O(n^2)$ implementation - which, for small problems, may actually out-perform anything more sophisticated. That depends on a lot of things and requires benchmarking diligence. Loosely,
\nFor small bounding box count, it's very frequent that an axis intersection is selected:
\n\nFor 90 bounding boxes, we see a non-axis intersection being selected:
\n\nOn my old laptop, this processes 1,000 bounding boxes in 0.3 seconds.
\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.patches import Rectangle, Circle\n\n\ndef sample_data(n: int = 20, seed: int = 0) -> np.ndarray:\n """\n Generate a tensor of ((2=x,y), (2=min,max), n) bounding boxes\n """\n rand = np.random.default_rng(seed)\n box = np.empty(shape=(2, 2, n), dtype=np.float32)\n box[..., 0] = (\n (-0.3, +0.3),\n (-0.3, +0.3),\n )\n box[:, 0, 1:] = rand.uniform(low=-1, high=0.5, size=(2, n-1))\n box[:, 1, 1:] = rand.uniform(low=0, high=0.5, size=(2, n-1)) + box[:, 0, 1:]\n return box.round(2)\n\n\ndef intersect_points(box: np.ndarray) -> np.ndarray:\n n = box.shape[-1]\n\n # All segments from bounding boxes min,max, and axis:\n # segment coordinate values on parallel axis\n segments_par = np.empty(\n shape=(2, 2, 2*n + 1), # (x,y), (parmin,parmax), (perp min, perp max)n + axis\n dtype=box.dtype,\n )\n segments_par[..., :-1] = box.repeat(2, axis=-1)\n # The last line is the axis. The axis intersecting any bounding box produces candidate points\n # for the closest-exterior output.\n segments_par[..., -1] = -np.inf, +np.inf\n\n # segment coordinate values on perpendicular axis\n # (y,x), (perp min, perp max)n + axis\n segments_perp = np.empty(shape=segments_par.shape[1:], dtype=box.dtype)\n segments_perp[:, :-1] = box.transpose((0, 2, 1)).reshape((2, -1))\n segments_perp[:, -1] = 0 # Axis intersects (0,0)\n\n x0, x1 = segments_par[0, :, :, np.newaxis]\n y0, y1 = segments_par[1, :, np.newaxis, :]\n xp = segments_perp[0, np.newaxis, :]\n yp = segments_perp[1, :, np.newaxis]\n\n # Outer product produces boolean intersection predicate\n hits = (x0 <= xp) & (xp <= x1) & (y0 <= yp) & (yp <= y1)\n hits[:-1, :-1] &= ~np.kron(np.eye(n, dtype=bool), np.ones((2, 2), dtype=bool))\n hits[-1, -1] = 0\n\n k = segments_par.shape[-1]\n # Intersection coordinates\n xi = np.broadcast_to(xp, (k, k))[hits]\n yi = np.broadcast_to(yp, (k, k))[hits]\n return np.stack((xi, yi)) # (2, n')\n\n\ndef exclude_bounding(box: np.ndarray, xyi: np.ndarray) -> np.ndarray:\n xi, yi = xyi[:, :, np.newaxis]\n (\n (x0, x1),\n (y0, y1),\n ) = box[:, :, np.newaxis, :]\n\n return ~((x0 < xi) & (xi < x1) & (y0 < yi) & (yi < y1)).any(axis=1)\n\n\ndef choose_closest(xyi: np.ndarray) -> int:\n norm2 = np.einsum('ij,ij->j', xyi, xyi) # x**2 + y**2, product (2,n)\n return norm2.argmin()\n\n\ndef plot(box: np.ndarray, xyi: np.ndarray, xy_free: np.ndarray, free: np.ndarray, best: int) -> None:\n fig, ax = plt.subplots()\n ax.add_artist(Circle(xy_free[:, best], radius=0.03, fc='#A0FFA0A0', ec='black'))\n ax.set_xlim(-1.1, 1.1)\n ax.set_ylim(-1.1, 1.1)\n ax.scatter(*xyi[:, ~free], label='occluded')\n ax.scatter(*xy_free, label='free')\n ax.legend()\n\n for (x0, x1), (y0, y1) in box.transpose((2, 0, 1)):\n ax.add_artist(Rectangle((x0, y0), x1-x0, y1-y0, ec='black', fc='#80808020'))\n\n\ndef main() -> None:\n box = sample_data(90)\n xyi = intersect_points(box)\n free = exclude_bounding(box, xyi)\n xy_free = xyi[:, free]\n best = choose_closest(xy_free)\n plot(box, xyi, xy_free, free, best)\n plt.show()\n\n\nif __name__ == '__main__':\n main()\n\n", "answer_id": 45537, "answer_text": "The key insight (also reflected in this comment (https://scicomp.stackexchange.com/questions/45533/find-the-closest-point-outside-overlapping-aabbs-from-a-point-inside-them#comment93668_45533)) is that the closest non-occluded point will either be at the intersection of two bounding box segments, or will be at the intersection of one bounding box segment and one axis - after the problem space has been translated so that $P = (0,0)$. The axis intersection is because of the 'axis-aligned' bounding boxes and the fact that Euclidean norm to a point on vertical segments will scale as $\\frac 1 {\\cos(\\theta)}$ and norm to a point on horizontal segments will scale as $\\frac 1 {\\sin(\\theta)}$. In both cases, the result is that the norm minima are seen at axis intersections ($\\theta = \\frac {\\pi n} 2$).\n\n\n\n\nSince you've failed to describe the scale of the problem, start with a simple $O(n^2)$ implementation - which, for small problems, may actually out-perform anything more sophisticated. That depends on a lot of things and requires benchmarking diligence. Loosely,\n\n\n\n\n\nUnion the set of all box-box intersections and all box-axis intersections\n\n\n\n\nFrom that set, exclude all points that are occluded by a box\n\n\n\n\nDo a tensor contraction to get the squared norm for the remaining intersections\n\n\n\n\nChoose the smallest one.\n\n\n\n\n\nFor small bounding box count, it's very frequent that an axis intersection is selected:\n\n\n\n\n[image: small problem; source: https://i.sstatic.net/rLLW3nkZ.png] (https://i.sstatic.net/rLLW3nkZ.png)\n\n\n\n\nFor 90 bounding boxes, we see a non-axis intersection being selected:\n\n\n\n\n[image: 90 boxes; source: https://i.sstatic.net/B0XWwMzu.png] (https://i.sstatic.net/B0XWwMzu.png)\n\n\n\n\nOn my old laptop, this processes 1,000 bounding boxes in 0.3 seconds.\n\n\n\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.patches import Rectangle, Circle\n\n\ndef sample_data(n: int = 20, seed: int = 0) -> np.ndarray:\n \"\"\"\n Generate a tensor of ((2=x,y), (2=min,max), n) bounding boxes\n \"\"\"\n rand = np.random.default_rng(seed)\n box = np.empty(shape=(2, 2, n), dtype=np.float32)\n box[..., 0] = (\n (-0.3, +0.3),\n (-0.3, +0.3),\n )\n box[:, 0, 1:] = rand.uniform(low=-1, high=0.5, size=(2, n-1))\n box[:, 1, 1:] = rand.uniform(low=0, high=0.5, size=(2, n-1)) + box[:, 0, 1:]\n return box.round(2)\n\n\ndef intersect_points(box: np.ndarray) -> np.ndarray:\n n = box.shape[-1]\n\n # All segments from bounding boxes min,max, and axis:\n # segment coordinate values on parallel axis\n segments_par = np.empty(\n shape=(2, 2, 2*n + 1), # (x,y), (parmin,parmax), (perp min, perp max)n + axis\n dtype=box.dtype,\n )\n segments_par[..., :-1] = box.repeat(2, axis=-1)\n # The last line is the axis. The axis intersecting any bounding box produces candidate points\n # for the closest-exterior output.\n segments_par[..., -1] = -np.inf, +np.inf\n\n # segment coordinate values on perpendicular axis\n # (y,x), (perp min, perp max)n + axis\n segments_perp = np.empty(shape=segments_par.shape[1:], dtype=box.dtype)\n segments_perp[:, :-1] = box.transpose((0, 2, 1)).reshape((2, -1))\n segments_perp[:, -1] = 0 # Axis intersects (0,0)\n\n x0, x1 = segments_par[0, :, :, np.newaxis]\n y0, y1 = segments_par[1, :, np.newaxis, :]\n xp = segments_perp[0, np.newaxis, :]\n yp = segments_perp[1, :, np.newaxis]\n\n # Outer product produces boolean intersection predicate\n hits = (x0 <= xp) & (xp <= x1) & (y0 <= yp) & (yp <= y1)\n hits[:-1, :-1] &= ~np.kron(np.eye(n, dtype=bool), np.ones((2, 2), dtype=bool))\n hits[-1, -1] = 0\n\n k = segments_par.shape[-1]\n # Intersection coordinates\n xi = np.broadcast_to(xp, (k, k))[hits]\n yi = np.broadcast_to(yp, (k, k))[hits]\n return np.stack((xi, yi)) # (2, n')\n\n\ndef exclude_bounding(box: np.ndarray, xyi: np.ndarray) -> np.ndarray:\n xi, yi = xyi[:, :, np.newaxis]\n (\n (x0, x1),\n (y0, y1),\n ) = box[:, :, np.newaxis, :]\n\n return ~((x0 < xi) & (xi < x1) & (y0 < yi) & (yi < y1)).any(axis=1)\n\n\ndef choose_closest(xyi: np.ndarray) -> int:\n norm2 = np.einsum('ij,ij->j', xyi, xyi) # x**2 + y**2, product (2,n)\n return norm2.argmin()\n\n\ndef plot(box: np.ndarray, xyi: np.ndarray, xy_free: np.ndarray, free: np.ndarray, best: int) -> None:\n fig, ax = plt.subplots()\n ax.add_artist(Circle(xy_free[:, best], radius=0.03, fc='#A0FFA0A0', ec='black'))\n ax.set_xlim(-1.1, 1.1)\n ax.set_ylim(-1.1, 1.1)\n ax.scatter(*xyi[:, ~free], label='occluded')\n ax.scatter(*xy_free, label='free')\n ax.legend()\n\n for (x0, x1), (y0, y1) in box.transpose((2, 0, 1)):\n ax.add_artist(Rectangle((x0, y0), x1-x0, y1-y0, ec='black', fc='#80808020'))\n\n\ndef main() -> None:\n box = sample_data(90)\n xyi = intersect_points(box)\n free = exclude_bounding(box, xyi)\n xy_free = xyi[:, free]\n best = choose_closest(xy_free)\n plot(box, xyi, xy_free, free, best)\n plt.show()\n\n\nif __name__ == '__main__':\n main()", "answer_url": "https://scicomp.stackexchange.com/a/45537", "author": "Reinderien", "author_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-07T22:20:58+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:49.393498+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bdd73bdc9d483cfaf7d50f2075e853261f39886330cd6d24a17f7b3b2fb731e5_1790825329894890800_0.json", "raw_sha256": "dfbb76df9ebacfee7e902db64890f154a777bd3049356aee472798c591424d79", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/45545;45541;45538;45533;45532;45530;45523;45513;45510;45507;45499;45493;45488;45487;45479;45474;45472;45463;45461;45447;45444;45436;45428;45425;45424;45423;45422;45416;45414;45410;45404;45401;45396;45391;45389;45387;45380;45377;45376;45375;45369;45366;45365;45363;45362;45359;45350;45347;45344;45336;45334;45331;45326;45322;45316;45313;45311;45309;45305;45302;45300;45291;45289;45285;45276;45269;45263;45262;45261;45253;45247;45246;45238;45236;45230;45229;45208;45201;45200;45185;45183;45171;45167;45165;45158;45154;45146;45141;45139;45134;45129;45127;45122;45114;45112;45108;45105;45100;45098;45096/answers?filter=withbody&order=asc&page=2&pagesize=100&site=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 45533, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2026-09-07T22:20:58+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "EA034CBB-245E-47BE-9F83-73186A65FD54", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/EA034CBB-245E-47BE-9F83-73186A65FD54/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Reinderien", "profile_url": "https://scicomp.stackexchange.com/users/41212/reinderien", "user_type": "registered"}, "created_at": "2026-09-07T22:53:19+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "13520681-83F3-4234-8A59-CE187F0BEA29", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/13520681-83F3-4234-8A59-CE187F0BEA29/view-source"}], "score": 2, "updated_at": "2026-09-07T22:53:19+00:00"}], "domain": "computational_science", "external_links": ["https://i.sstatic.net/B0XWwMzu.png", "https://i.sstatic.net/rLLW3nkZ.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:28:44.584971+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/272744bcc95b58699f7df6e6979b288bb8b00a80ab9c7982dbe170a6d0b63584_1790825325025901700_0.json", "raw_sha256": "27a81850a40920682c29ada76a2b55e80340a5c82764a3e9dde8a9c2ba23db4e", "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=scicomp&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "ffbh", "question_author_url": "https://scicomp.stackexchange.com/users/57252/ffbh", "question_author_user_type": "registered", "question_created_at": "2026-09-03T03:48:42+00:00", "question_html": "I have a collection of axis-aligned bounding boxes (AABBs). The AABBs may overlap each other and may form multiple disconnected groups.
\nIs there a known algorithm for this problem?
\nThanks.
\n", "question_id": 45533, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I have a collection of axis-aligned bounding boxes (AABBs). The AABBs may overlap each other and may form multiple disconnected groups.\n\n\n\n\n\nIf P is not inside any AABB, I don't need to do anything.\n\n\n\n\nIf P is inside one or more AABBs, I need to find the closest point to P that is outside all AABBs\n\n\n\n\nA point lying exactly on the edge/boundary of an AABB is considered valid (not inside). Therefore, when P is inside an AABB group, the desired result will normally be a point on the edge of one of the AABBs.\n\n\n\n\n\nIs there a known algorithm for this problem?\n\n\n\n\nThanks.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "ffbh", "profile_url": "https://scicomp.stackexchange.com/users/57252/ffbh", "user_type": "registered"}, "created_at": "2026-09-03T03:48:42+00:00", "raw_file": "raw/codex_api_v1/388d30597d4ce2c68c96b784f7bf92098fad8c44850c54687d3a3028cce83504_1790825358707940600_0.json", "raw_sha256": "798328140b22ca830f996dc29957e2ed66bad007670d3eb6cfce6a5d1c2b82b7", "revision_guid": "4165EEB0-A429-43DE-A4E0-E9FB5F902B12", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://scicomp.stackexchange.com/revisions/4165EEB0-A429-43DE-A4E0-E9FB5F902B12/view-source"}], "source_site": "scicomp", "source_url": "https://scicomp.stackexchange.com/questions/45533/find-the-closest-point-outside-overlapping-aabbs-from-a-point-inside-them", "split": "validation", "split_group": "71a1e1aa9ca97a050ab7c198593fba301c532fe3b80fdc4f0cab34aff62615f9", "tags": ["algorithms", "computational-geometry", "geometry"], "thread_id": "scicomp:45533", "title": "Find the closest point outside overlapping AABBs from a point inside them"}} {"citation_context": "s://en.wikipedia.org/wiki/Liger#Size_and_growth) for the larger size of ligers are imprinted genes (https://en.wikipedia.org/wiki/Genomic_imprinting).\n\n\n\n\nImprinted genes are genes that, unlike other genes, are only expressed when they come from th", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Genomic_imprinting", "kind": "external_url", "post_id": 118112, "post_url": "https://biology.stackexchange.com/a/118112", "product": "citations", "record_id": "Scientific-Citation-Graph:e6898c9fb93da3a30f7e02e2", "split": "validation", "thread": {"accepted_answer_id": 118112, "answers": [{"answer_html": "Although this has not been thoroughly research, a widely considered hypothesis for the larger size of ligers are imprinted genes.
\nImprinted genes are genes that, unlike other genes, are only expressed when they come from the mother/father. The exact function of these genes is not entirely understood, but we do know a few things. First, they are not present in all life, but all mammals have them. In mammals they are linked to the development of the embryo and placenta, where paternal genes help produce stronger placentas and maternal genes help produce stronger embryos.
\nAn interesting explanation for this is called the "parental conflict hypothesis". In short, the father wants the embryo to be strong even if the mother dies (i.e. wants a strong placenta that sucks as many nutrients as it can from the mother); while the mom wants the embryo to mature quickly to have a shorter pregnancy (i.e. a quickly developed healthy baby that she can give birth to quickly and easily). Also, the mother inhibits placental growth to avoid being killed by the invading embryo.
\nIn ligers it is quite likely that the female tiger does not have the right biological mechanisms to control the size of the placenta, while she does increase the embryo size. Strong placenta + strong embryo = large baby. Likely these mechanisms also play a part during the cub's development, as imprinted genes also have to do with post-natal development.
\nComplicated but cool stuff!
\n", "answer_id": 118112, "answer_text": "Although this has not been thoroughly research, a widely considered hypothesis (https://en.wikipedia.org/wiki/Liger#Size_and_growth) for the larger size of ligers are imprinted genes (https://en.wikipedia.org/wiki/Genomic_imprinting).\n\n\n\n\nImprinted genes are genes that, unlike other genes, are only expressed when they come from the mother/father. The exact function of these genes is not entirely understood, but we do know a few things. First, they are not present in all life, but all mammals have them. In mammals they are linked to the development of the embryo and placenta, where paternal genes help produce stronger placentas and maternal genes help produce stronger embryos.\n\n\n\n\nAn interesting explanation for this is called the \"parental conflict hypothesis\" (https://en.wikipedia.org/wiki/Genomic_imprinting#Hypotheses_on_the_origins_of_imprinting). In short, the father wants the embryo to be strong even if the mother dies (i.e. wants a strong placenta that sucks as many nutrients as it can from the mother); while the mom wants the embryo to mature quickly to have a shorter pregnancy (i.e. a quickly developed healthy baby that she can give birth to quickly and easily). Also, the mother inhibits placental growth to avoid being killed by the invading embryo.\n\n\n\n\nIn ligers it is quite likely that the female tiger does not have the right biological mechanisms to control the size of the placenta, while she does increase the embryo size. Strong placenta + strong embryo = large baby. Likely these mechanisms also play a part during the cub's development, as imprinted genes also have to do with post-natal development.\n\n\n\n\nComplicated but cool stuff!", "answer_url": "https://biology.stackexchange.com/a/118112", "author": "Athe", "author_url": "https://biology.stackexchange.com/users/17385/athe", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-11-12T16:23:30+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 118022, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Athe", "profile_url": "https://biology.stackexchange.com/users/17385/athe", "user_type": "registered"}, "created_at": "2025-11-12T16:23:30+00:00", "raw_file": "raw/codex_api_v1/24d8c4344fb56e0a47a9b0522e7fa13631e62cee2987c8bebddae0c2fd26f9ef_1790824157688070000_0.json", "raw_sha256": "4317829c6b2c1d1874a8b88f2daa4b8fa8bda8b06cf0c252f9adce0558f8183c", "revision_guid": "7184F2A8-80C5-433D-93B3-9BAA4CA76E3D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7184F2A8-80C5-433D-93B3-9BAA4CA76E3D/view-source"}], "score": 3, "updated_at": "2025-11-12T16:23:30+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Genomic_imprinting", "https://en.wikipedia.org/wiki/Genomic_imprinting#Hypotheses_on_the_origins_of_imprinting", "https://en.wikipedia.org/wiki/Liger#Size_and_growth"], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Root Groves", "question_author_url": "https://biology.stackexchange.com/users/78184/root-groves", "question_author_user_type": "registered", "question_created_at": "2025-10-15T19:01:28+00:00", "question_html": "Ligers are the result of breeding between a male lion and a female tiger.One would expect that the liger would have a size in between the size of the lion and tiger however as it turns out ligers are much bigger than either of their parents.
\nBut the following is also interesting.When a female liger interbreeds with a male tiger or a male lion their offspring (ti- or the li-liger) has the size in between the size of the female liger and the male tiger/lion so genetically the size peaks at the 1st generation interbreed offspring.Why is that?
\n", "question_id": 118022, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "Ligers are the result of breeding between a male lion and a female tiger.One would expect that the liger would have a size in between the size of the lion and tiger however as it turns out ligers are much bigger than either of their parents.\n\n\n\n\nBut the following is also interesting.When a female liger interbreeds with a male tiger or a male lion their offspring (ti- or the li-liger) has the size in between the size of the female liger and the male tiger/lion so genetically the size peaks at the 1st generation interbreed offspring.Why is that?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Root Groves", "profile_url": "https://biology.stackexchange.com/users/78184/root-groves", "user_type": "registered"}, "created_at": "2025-10-15T19:01:28+00:00", "raw_file": "raw/codex_api_v1/e6c4101e2e357aa8c5379bd547ec537e2ae9d3a66d32b72c727e9d2ad82690d6_1790824162028580600_0.json", "raw_sha256": "cba09186cd183cf1116bbe2f874d16b08a8bc537baa01c33e34f5c3821229cc5", "revision_guid": "0B952A6E-C2D6-4509-A7F2-DB8DB0A89FD4", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0B952A6E-C2D6-4509-A7F2-DB8DB0A89FD4/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/118022/why-are-ligers-bigger-than-their-parents", "split": "validation", "split_group": "de611e311ba75849144ef048bdf5b842762c7ac02255067d9d7d4e552dd736fe", "tags": ["evolution", "zoology", "dna"], "thread_id": "biology:118022", "title": "Why are ligers bigger than their parents?"}} {"citation_context": "nger embryos.\n\n\n\n\nAn interesting explanation for this is called the \"parental conflict hypothesis\" (https://en.wikipedia.org/wiki/Genomic_imprinting#Hypotheses_on_the_origins_of_imprinting). In short, the father wants the embryo to be strong even if the mother dies (i.e. wants a strong p", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Genomic_imprinting#Hypotheses_on_the_origins_of_imprinting", "kind": "external_url", "post_id": 118112, "post_url": "https://biology.stackexchange.com/a/118112", "product": "citations", "record_id": "Scientific-Citation-Graph:1cb76dd26fd981bd364243a2", "split": "validation", "thread": {"accepted_answer_id": 118112, "answers": [{"answer_html": "Although this has not been thoroughly research, a widely considered hypothesis for the larger size of ligers are imprinted genes.
\nImprinted genes are genes that, unlike other genes, are only expressed when they come from the mother/father. The exact function of these genes is not entirely understood, but we do know a few things. First, they are not present in all life, but all mammals have them. In mammals they are linked to the development of the embryo and placenta, where paternal genes help produce stronger placentas and maternal genes help produce stronger embryos.
\nAn interesting explanation for this is called the "parental conflict hypothesis". In short, the father wants the embryo to be strong even if the mother dies (i.e. wants a strong placenta that sucks as many nutrients as it can from the mother); while the mom wants the embryo to mature quickly to have a shorter pregnancy (i.e. a quickly developed healthy baby that she can give birth to quickly and easily). Also, the mother inhibits placental growth to avoid being killed by the invading embryo.
\nIn ligers it is quite likely that the female tiger does not have the right biological mechanisms to control the size of the placenta, while she does increase the embryo size. Strong placenta + strong embryo = large baby. Likely these mechanisms also play a part during the cub's development, as imprinted genes also have to do with post-natal development.
\nComplicated but cool stuff!
\n", "answer_id": 118112, "answer_text": "Although this has not been thoroughly research, a widely considered hypothesis (https://en.wikipedia.org/wiki/Liger#Size_and_growth) for the larger size of ligers are imprinted genes (https://en.wikipedia.org/wiki/Genomic_imprinting).\n\n\n\n\nImprinted genes are genes that, unlike other genes, are only expressed when they come from the mother/father. The exact function of these genes is not entirely understood, but we do know a few things. First, they are not present in all life, but all mammals have them. In mammals they are linked to the development of the embryo and placenta, where paternal genes help produce stronger placentas and maternal genes help produce stronger embryos.\n\n\n\n\nAn interesting explanation for this is called the \"parental conflict hypothesis\" (https://en.wikipedia.org/wiki/Genomic_imprinting#Hypotheses_on_the_origins_of_imprinting). In short, the father wants the embryo to be strong even if the mother dies (i.e. wants a strong placenta that sucks as many nutrients as it can from the mother); while the mom wants the embryo to mature quickly to have a shorter pregnancy (i.e. a quickly developed healthy baby that she can give birth to quickly and easily). Also, the mother inhibits placental growth to avoid being killed by the invading embryo.\n\n\n\n\nIn ligers it is quite likely that the female tiger does not have the right biological mechanisms to control the size of the placenta, while she does increase the embryo size. Strong placenta + strong embryo = large baby. Likely these mechanisms also play a part during the cub's development, as imprinted genes also have to do with post-natal development.\n\n\n\n\nComplicated but cool stuff!", "answer_url": "https://biology.stackexchange.com/a/118112", "author": "Athe", "author_url": "https://biology.stackexchange.com/users/17385/athe", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-11-12T16:23:30+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 118022, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Athe", "profile_url": "https://biology.stackexchange.com/users/17385/athe", "user_type": "registered"}, "created_at": "2025-11-12T16:23:30+00:00", "raw_file": "raw/codex_api_v1/24d8c4344fb56e0a47a9b0522e7fa13631e62cee2987c8bebddae0c2fd26f9ef_1790824157688070000_0.json", "raw_sha256": "4317829c6b2c1d1874a8b88f2daa4b8fa8bda8b06cf0c252f9adce0558f8183c", "revision_guid": "7184F2A8-80C5-433D-93B3-9BAA4CA76E3D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7184F2A8-80C5-433D-93B3-9BAA4CA76E3D/view-source"}], "score": 3, "updated_at": "2025-11-12T16:23:30+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Genomic_imprinting", "https://en.wikipedia.org/wiki/Genomic_imprinting#Hypotheses_on_the_origins_of_imprinting", "https://en.wikipedia.org/wiki/Liger#Size_and_growth"], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Root Groves", "question_author_url": "https://biology.stackexchange.com/users/78184/root-groves", "question_author_user_type": "registered", "question_created_at": "2025-10-15T19:01:28+00:00", "question_html": "Ligers are the result of breeding between a male lion and a female tiger.One would expect that the liger would have a size in between the size of the lion and tiger however as it turns out ligers are much bigger than either of their parents.
\nBut the following is also interesting.When a female liger interbreeds with a male tiger or a male lion their offspring (ti- or the li-liger) has the size in between the size of the female liger and the male tiger/lion so genetically the size peaks at the 1st generation interbreed offspring.Why is that?
\n", "question_id": 118022, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "Ligers are the result of breeding between a male lion and a female tiger.One would expect that the liger would have a size in between the size of the lion and tiger however as it turns out ligers are much bigger than either of their parents.\n\n\n\n\nBut the following is also interesting.When a female liger interbreeds with a male tiger or a male lion their offspring (ti- or the li-liger) has the size in between the size of the female liger and the male tiger/lion so genetically the size peaks at the 1st generation interbreed offspring.Why is that?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Root Groves", "profile_url": "https://biology.stackexchange.com/users/78184/root-groves", "user_type": "registered"}, "created_at": "2025-10-15T19:01:28+00:00", "raw_file": "raw/codex_api_v1/e6c4101e2e357aa8c5379bd547ec537e2ae9d3a66d32b72c727e9d2ad82690d6_1790824162028580600_0.json", "raw_sha256": "cba09186cd183cf1116bbe2f874d16b08a8bc537baa01c33e34f5c3821229cc5", "revision_guid": "0B952A6E-C2D6-4509-A7F2-DB8DB0A89FD4", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0B952A6E-C2D6-4509-A7F2-DB8DB0A89FD4/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/118022/why-are-ligers-bigger-than-their-parents", "split": "validation", "split_group": "de611e311ba75849144ef048bdf5b842762c7ac02255067d9d7d4e552dd736fe", "tags": ["evolution", "zoology", "dna"], "thread_id": "biology:118022", "title": "Why are ligers bigger than their parents?"}} {"citation_context": "Although this has not been thoroughly research, a widely considered hypothesis (https://en.wikipedia.org/wiki/Liger#Size_and_growth) for the larger size of ligers are imprinted genes (https://en.wikipedia.org/wiki/Genomic_imprintin", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Liger#Size_and_growth", "kind": "external_url", "post_id": 118112, "post_url": "https://biology.stackexchange.com/a/118112", "product": "citations", "record_id": "Scientific-Citation-Graph:07c1f5371089760b3e48819a", "split": "validation", "thread": {"accepted_answer_id": 118112, "answers": [{"answer_html": "Although this has not been thoroughly research, a widely considered hypothesis for the larger size of ligers are imprinted genes.
\nImprinted genes are genes that, unlike other genes, are only expressed when they come from the mother/father. The exact function of these genes is not entirely understood, but we do know a few things. First, they are not present in all life, but all mammals have them. In mammals they are linked to the development of the embryo and placenta, where paternal genes help produce stronger placentas and maternal genes help produce stronger embryos.
\nAn interesting explanation for this is called the "parental conflict hypothesis". In short, the father wants the embryo to be strong even if the mother dies (i.e. wants a strong placenta that sucks as many nutrients as it can from the mother); while the mom wants the embryo to mature quickly to have a shorter pregnancy (i.e. a quickly developed healthy baby that she can give birth to quickly and easily). Also, the mother inhibits placental growth to avoid being killed by the invading embryo.
\nIn ligers it is quite likely that the female tiger does not have the right biological mechanisms to control the size of the placenta, while she does increase the embryo size. Strong placenta + strong embryo = large baby. Likely these mechanisms also play a part during the cub's development, as imprinted genes also have to do with post-natal development.
\nComplicated but cool stuff!
\n", "answer_id": 118112, "answer_text": "Although this has not been thoroughly research, a widely considered hypothesis (https://en.wikipedia.org/wiki/Liger#Size_and_growth) for the larger size of ligers are imprinted genes (https://en.wikipedia.org/wiki/Genomic_imprinting).\n\n\n\n\nImprinted genes are genes that, unlike other genes, are only expressed when they come from the mother/father. The exact function of these genes is not entirely understood, but we do know a few things. First, they are not present in all life, but all mammals have them. In mammals they are linked to the development of the embryo and placenta, where paternal genes help produce stronger placentas and maternal genes help produce stronger embryos.\n\n\n\n\nAn interesting explanation for this is called the \"parental conflict hypothesis\" (https://en.wikipedia.org/wiki/Genomic_imprinting#Hypotheses_on_the_origins_of_imprinting). In short, the father wants the embryo to be strong even if the mother dies (i.e. wants a strong placenta that sucks as many nutrients as it can from the mother); while the mom wants the embryo to mature quickly to have a shorter pregnancy (i.e. a quickly developed healthy baby that she can give birth to quickly and easily). Also, the mother inhibits placental growth to avoid being killed by the invading embryo.\n\n\n\n\nIn ligers it is quite likely that the female tiger does not have the right biological mechanisms to control the size of the placenta, while she does increase the embryo size. Strong placenta + strong embryo = large baby. Likely these mechanisms also play a part during the cub's development, as imprinted genes also have to do with post-natal development.\n\n\n\n\nComplicated but cool stuff!", "answer_url": "https://biology.stackexchange.com/a/118112", "author": "Athe", "author_url": "https://biology.stackexchange.com/users/17385/athe", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-11-12T16:23:30+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 118022, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Athe", "profile_url": "https://biology.stackexchange.com/users/17385/athe", "user_type": "registered"}, "created_at": "2025-11-12T16:23:30+00:00", "raw_file": "raw/codex_api_v1/24d8c4344fb56e0a47a9b0522e7fa13631e62cee2987c8bebddae0c2fd26f9ef_1790824157688070000_0.json", "raw_sha256": "4317829c6b2c1d1874a8b88f2daa4b8fa8bda8b06cf0c252f9adce0558f8183c", "revision_guid": "7184F2A8-80C5-433D-93B3-9BAA4CA76E3D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7184F2A8-80C5-433D-93B3-9BAA4CA76E3D/view-source"}], "score": 3, "updated_at": "2025-11-12T16:23:30+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Genomic_imprinting", "https://en.wikipedia.org/wiki/Genomic_imprinting#Hypotheses_on_the_origins_of_imprinting", "https://en.wikipedia.org/wiki/Liger#Size_and_growth"], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Root Groves", "question_author_url": "https://biology.stackexchange.com/users/78184/root-groves", "question_author_user_type": "registered", "question_created_at": "2025-10-15T19:01:28+00:00", "question_html": "Ligers are the result of breeding between a male lion and a female tiger.One would expect that the liger would have a size in between the size of the lion and tiger however as it turns out ligers are much bigger than either of their parents.
\nBut the following is also interesting.When a female liger interbreeds with a male tiger or a male lion their offspring (ti- or the li-liger) has the size in between the size of the female liger and the male tiger/lion so genetically the size peaks at the 1st generation interbreed offspring.Why is that?
\n", "question_id": 118022, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "Ligers are the result of breeding between a male lion and a female tiger.One would expect that the liger would have a size in between the size of the lion and tiger however as it turns out ligers are much bigger than either of their parents.\n\n\n\n\nBut the following is also interesting.When a female liger interbreeds with a male tiger or a male lion their offspring (ti- or the li-liger) has the size in between the size of the female liger and the male tiger/lion so genetically the size peaks at the 1st generation interbreed offspring.Why is that?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Root Groves", "profile_url": "https://biology.stackexchange.com/users/78184/root-groves", "user_type": "registered"}, "created_at": "2025-10-15T19:01:28+00:00", "raw_file": "raw/codex_api_v1/e6c4101e2e357aa8c5379bd547ec537e2ae9d3a66d32b72c727e9d2ad82690d6_1790824162028580600_0.json", "raw_sha256": "cba09186cd183cf1116bbe2f874d16b08a8bc537baa01c33e34f5c3821229cc5", "revision_guid": "0B952A6E-C2D6-4509-A7F2-DB8DB0A89FD4", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0B952A6E-C2D6-4509-A7F2-DB8DB0A89FD4/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/118022/why-are-ligers-bigger-than-their-parents", "split": "validation", "split_group": "de611e311ba75849144ef048bdf5b842762c7ac02255067d9d7d4e552dd736fe", "tags": ["evolution", "zoology", "dna"], "thread_id": "biology:118022", "title": "Why are ligers bigger than their parents?"}} {"citation_context": "akes sense (see example).\n\n\n\n\n[image: Example of a hierarchical list of vegetation science; source: https://i.sstatic.net/WxveehZw.png] (https://i.sstatic.net/WxveehZw.png)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/WxveehZw.png", "kind": "external_url", "post_id": 116293, "post_url": "https://biology.stackexchange.com/a/116293", "product": "citations", "record_id": "Scientific-Citation-Graph:f680a80cbc810f2cb4061af1", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "If I understand the question correctly, it's not that far-fetched. But there are various systems, for example, online, that represent corresponding hierarchies and manage them in the background at the database level (e.g., https://www.floraweb.de/). Computer-based classification, for example, using corresponding hierarchical keys that map parent-child relationships, makes sense (see example).
\n\n", "answer_id": 116293, "answer_text": "If I understand the question correctly, it's not that far-fetched. But there are various systems, for example, online, that represent corresponding hierarchies and manage them in the background at the database level (e.g., https://www.floraweb.de/ (https://www.floraweb.de/)). Computer-based classification, for example, using corresponding hierarchical keys that map parent-child relationships, makes sense (see example).\n\n\n\n\n[image: Example of a hierarchical list of vegetation science; source: https://i.sstatic.net/WxveehZw.png] (https://i.sstatic.net/WxveehZw.png)", "answer_url": "https://biology.stackexchange.com/a/116293", "author": "Detlev Finke", "author_url": "https://biology.stackexchange.com/users/103641/detlev-finke", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-03-28T13:24:55+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:19.947691+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/df693642d727b738d2a533740632235c18a06cefec7a1e337c9589214a4ec91e_0.json", "raw_sha256": "9df534f437f3b2f12d33db8536999ec4e6ffa10f2f59394799d9fe01c3c1ad16", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/117606;117602;117598;117594;117585;117579;117570;117568;117565;117559;117558;117555;117552;117548;117538;117524;117523;117522;117520;117515;117510;116509;116508;116504;116499;116491;116485;116483;116461;116454;116453;116445;116441;116435;116430;116426;116425;116414;116412;116406;116401;116399;116396;116395;116394;116392;116389;116384;116370;116367;116363;116361;116352;116351;116347;116345;116343;116338;116337;116332;116331;116324;116320;116316;116314;116312;116306;116292;116290;116284;116280;116277;116271;116270;116268;116267;116257;116256;116253;116250;116249;116240;116237;116233;116219;116214;116212;116205;116204;116200;116198;116187;116184;116173;116172;116167;116162;116149;116142;116129/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 116284, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Detlev Finke", "profile_url": "https://biology.stackexchange.com/users/103641/detlev-finke", "user_type": "registered"}, "created_at": "2025-03-28T13:24:55+00:00", "raw_file": "raw/codex_api_v1/2e46271dd42cc68e540cd93745d874445294455a8c8fc89effd7f36ed497eee4_1790824137680573300_0.json", "raw_sha256": "21274b3e65918ff952c3e3901f10b15b146be4d989ae74907eaed06f2a54ef5e", "revision_guid": "E24A538B-9245-4C62-89EA-4A46CADEA068", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/E24A538B-9245-4C62-89EA-4A46CADEA068/view-source"}], "score": 2, "updated_at": "2025-03-28T13:24:55+00:00"}], "domain": "biology", "external_links": ["https://i.sstatic.net/WxveehZw.png", "https://www.floraweb.de/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:02.598621+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/5d480e4bd1bd45ab525a4baf3227fba404f89b6af9dad33215fd9fa7c302a211_0.json", "raw_sha256": "d723c7a62c8386d143891d26ae30b2234242ed3dac9599b11f141712ea994a96", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=3&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Laszlo Pav", "question_author_url": "https://biology.stackexchange.com/users/103448/laszlo-pav", "question_author_user_type": "registered", "question_created_at": "2025-03-25T22:42:54+00:00", "question_html": "Is there any representation of the taxonomic hierarchy as a computer directory, where in the root directory, there would be domains (also directories), and inside those, kingdoms and so on and so on? I couldn't find anything about it anywhere.
\nThank you!
\n", "question_id": 116284, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "Is there any representation of the taxonomic hierarchy as a computer directory, where in the root directory, there would be domains (also directories), and inside those, kingdoms and so on and so on? I couldn't find anything about it anywhere.\n\n\n\n\nThank you!", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laszlo Pav", "profile_url": "https://biology.stackexchange.com/users/103448/laszlo-pav", "user_type": "registered"}, "created_at": "2025-03-25T22:42:54+00:00", "raw_file": "raw/codex_api_v1/2e46271dd42cc68e540cd93745d874445294455a8c8fc89effd7f36ed497eee4_1790824137680573300_0.json", "raw_sha256": "21274b3e65918ff952c3e3901f10b15b146be4d989ae74907eaed06f2a54ef5e", "revision_guid": "302B837B-3F35-4D4A-BC87-F4F31A2B0577", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/302B837B-3F35-4D4A-BC87-F4F31A2B0577/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/116284/taxonomic-hierarchy-represented-as-a-computer-directory-hierarchy", "split": "validation", "split_group": "15c3bd1e2b140cafbfed3183218bf7bc732f4661f759ecae59395e36e1aa39ea", "tags": ["taxonomy"], "thread_id": "biology:116284", "title": "Taxonomic hierarchy represented as a computer directory hierarchy?"}} {"citation_context": " represent corresponding hierarchies and manage them in the background at the database level (e.g., https://www.floraweb.de/ (https://www.floraweb.de/)). Computer-based classification, for example, using corresponding hierar", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.floraweb.de/", "kind": "external_url", "post_id": 116293, "post_url": "https://biology.stackexchange.com/a/116293", "product": "citations", "record_id": "Scientific-Citation-Graph:4bde83d6a80e219131104e1c", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "If I understand the question correctly, it's not that far-fetched. But there are various systems, for example, online, that represent corresponding hierarchies and manage them in the background at the database level (e.g., https://www.floraweb.de/). Computer-based classification, for example, using corresponding hierarchical keys that map parent-child relationships, makes sense (see example).
\n\n", "answer_id": 116293, "answer_text": "If I understand the question correctly, it's not that far-fetched. But there are various systems, for example, online, that represent corresponding hierarchies and manage them in the background at the database level (e.g., https://www.floraweb.de/ (https://www.floraweb.de/)). Computer-based classification, for example, using corresponding hierarchical keys that map parent-child relationships, makes sense (see example).\n\n\n\n\n[image: Example of a hierarchical list of vegetation science; source: https://i.sstatic.net/WxveehZw.png] (https://i.sstatic.net/WxveehZw.png)", "answer_url": "https://biology.stackexchange.com/a/116293", "author": "Detlev Finke", "author_url": "https://biology.stackexchange.com/users/103641/detlev-finke", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-03-28T13:24:55+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:19.947691+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/df693642d727b738d2a533740632235c18a06cefec7a1e337c9589214a4ec91e_0.json", "raw_sha256": "9df534f437f3b2f12d33db8536999ec4e6ffa10f2f59394799d9fe01c3c1ad16", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/117606;117602;117598;117594;117585;117579;117570;117568;117565;117559;117558;117555;117552;117548;117538;117524;117523;117522;117520;117515;117510;116509;116508;116504;116499;116491;116485;116483;116461;116454;116453;116445;116441;116435;116430;116426;116425;116414;116412;116406;116401;116399;116396;116395;116394;116392;116389;116384;116370;116367;116363;116361;116352;116351;116347;116345;116343;116338;116337;116332;116331;116324;116320;116316;116314;116312;116306;116292;116290;116284;116280;116277;116271;116270;116268;116267;116257;116256;116253;116250;116249;116240;116237;116233;116219;116214;116212;116205;116204;116200;116198;116187;116184;116173;116172;116167;116162;116149;116142;116129/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 116284, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Detlev Finke", "profile_url": "https://biology.stackexchange.com/users/103641/detlev-finke", "user_type": "registered"}, "created_at": "2025-03-28T13:24:55+00:00", "raw_file": "raw/codex_api_v1/2e46271dd42cc68e540cd93745d874445294455a8c8fc89effd7f36ed497eee4_1790824137680573300_0.json", "raw_sha256": "21274b3e65918ff952c3e3901f10b15b146be4d989ae74907eaed06f2a54ef5e", "revision_guid": "E24A538B-9245-4C62-89EA-4A46CADEA068", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/E24A538B-9245-4C62-89EA-4A46CADEA068/view-source"}], "score": 2, "updated_at": "2025-03-28T13:24:55+00:00"}], "domain": "biology", "external_links": ["https://i.sstatic.net/WxveehZw.png", "https://www.floraweb.de/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:02.598621+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/5d480e4bd1bd45ab525a4baf3227fba404f89b6af9dad33215fd9fa7c302a211_0.json", "raw_sha256": "d723c7a62c8386d143891d26ae30b2234242ed3dac9599b11f141712ea994a96", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=3&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Laszlo Pav", "question_author_url": "https://biology.stackexchange.com/users/103448/laszlo-pav", "question_author_user_type": "registered", "question_created_at": "2025-03-25T22:42:54+00:00", "question_html": "Is there any representation of the taxonomic hierarchy as a computer directory, where in the root directory, there would be domains (also directories), and inside those, kingdoms and so on and so on? I couldn't find anything about it anywhere.
\nThank you!
\n", "question_id": 116284, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "Is there any representation of the taxonomic hierarchy as a computer directory, where in the root directory, there would be domains (also directories), and inside those, kingdoms and so on and so on? I couldn't find anything about it anywhere.\n\n\n\n\nThank you!", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laszlo Pav", "profile_url": "https://biology.stackexchange.com/users/103448/laszlo-pav", "user_type": "registered"}, "created_at": "2025-03-25T22:42:54+00:00", "raw_file": "raw/codex_api_v1/2e46271dd42cc68e540cd93745d874445294455a8c8fc89effd7f36ed497eee4_1790824137680573300_0.json", "raw_sha256": "21274b3e65918ff952c3e3901f10b15b146be4d989ae74907eaed06f2a54ef5e", "revision_guid": "302B837B-3F35-4D4A-BC87-F4F31A2B0577", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/302B837B-3F35-4D4A-BC87-F4F31A2B0577/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/116284/taxonomic-hierarchy-represented-as-a-computer-directory-hierarchy", "split": "validation", "split_group": "15c3bd1e2b140cafbfed3183218bf7bc732f4661f759ecae59395e36e1aa39ea", "tags": ["taxonomy"], "thread_id": "biology:116284", "title": "Taxonomic hierarchy represented as a computer directory hierarchy?"}} {"citation_context": "\n\n\nDo anyone knows what it belongs to?\n\n\n\n\nI'm leaning towards something related to the Reduviidae (https://es.wikipedia.org/wiki/Reduviidae) family?\n\n\n\n\ngoogle image search for Reduviidae (https://www.google.com/search?q=reduviidae+eggs&sc", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://es.wikipedia.org/wiki/Reduviidae", "kind": "external_url", "post_id": 115214, "post_url": "https://biology.stackexchange.com/questions/115214/what-may-these-eggs-belong-to", "product": "citations", "record_id": "Scientific-Citation-Graph:e5667bfa019d673b335ad632", "split": "validation", "thread": {"accepted_answer_id": 115228, "answers": [{"answer_html": "Just did a snap Google search for "assassin bug eggs" and the images that came up were very reminiscent of yours; here's a link to a good article with an image: https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs. So yeah, most likely possibility is assassin bug eggs.
\n", "answer_id": 115228, "answer_text": "Just did a snap Google search for \"assassin bug eggs\" and the images that came up were very reminiscent of yours; here's a link to a good article with an image: https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs (https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs). So yeah, most likely possibility is assassin bug eggs.", "answer_url": "https://biology.stackexchange.com/a/115228", "author": "Sir Thinksalot", "author_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-08-21T13:07:25+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:25.304620+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/7fe0b66593eb4c0f175024453138b8bd50811f1580a079ffb990af38e09cd1cf_0.json", "raw_sha256": "b0a655f3b4c9626cf981180b3ac018a4a26330c5ab9b925b3df78bedd8169a84", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/115493;115490;115488;115483;115479;115477;115456;115453;115452;115447;115445;115444;115436;115431;115427;115413;115404;115403;115396;115391;115389;115388;115386;115383;115382;115379;115367;115365;115355;115340;115334;115328;115321;115314;115309;115304;115296;115295;115292;115283;115272;115270;115269;115265;115264;115260;115255;115252;115243;115235;115233;115225;115218;115215;115214;115213;115207;115204;115179;115177;115170;115167;115165;115164;115154;115149;115137;115131;115129;115115;115107;115099;115095;115094;115093;115085;115082;115081;115077;115076;115075;115074;115073;115072;115063;115044;115039;115035;115030;115025;115022;115019;115016;115012;115003;115002;114997;114993;114991;114987/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115214, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sir Thinksalot", "profile_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "user_type": "registered"}, "created_at": "2024-08-21T13:07:25+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "99462C57-F01A-4035-B8BC-C1795FD8A5DD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/99462C57-F01A-4035-B8BC-C1795FD8A5DD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sir Thinksalot", "profile_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "user_type": "registered"}, "created_at": "2024-08-21T15:23:08+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "15565E89-16C1-49AD-B248-3F8119B0CD87", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/15565E89-16C1-49AD-B248-3F8119B0CD87/view-source"}], "score": 2, "updated_at": "2024-08-21T15:23:08+00:00"}], "domain": "biology", "external_links": ["https://es.wikipedia.org/wiki/Reduviidae", "https://i.sstatic.net/yrZLdw90.jpg", "https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs", "https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:05.762873+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/04ed2aa314c5d877c5d79e42620d1f80988a21de8d429a22d8c6af5280cfd6e8_0.json", "raw_sha256": "6dd355b99094bb9ba2c965ee7dd7b0e95f92a8078d3b2b85b64196fcb6cf717c", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=5&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Alfergon", "question_author_url": "https://biology.stackexchange.com/users/49841/alfergon", "question_author_user_type": "registered", "question_created_at": "2024-08-19T14:15:42+00:00", "question_html": "Today I've found these eggs on the outside of my house.
\nThis is located on the north of Spain.
\n\nDo anyone knows what it belongs to?
\nI'm leaning towards something related to the Reduviidae family?
\ngoogle image search for Reduviidae
\n", "question_id": 115214, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Today I've found these eggs on the outside of my house.\n\n\n\n\nThis is located on the north of Spain.\n\n\n\n\n[image: Image; source: https://i.sstatic.net/yrZLdw90.jpg] (https://i.sstatic.net/yrZLdw90.jpg)\n\n\n\n\nDo anyone knows what it belongs to?\n\n\n\n\nI'm leaning towards something related to the Reduviidae (https://es.wikipedia.org/wiki/Reduviidae) family?\n\n\n\n\ngoogle image search for Reduviidae (https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-19T14:15:42+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "3F151164-3974-4C03-B885-F93057D25FA2", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/3F151164-3974-4C03-B885-F93057D25FA2/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-20T12:01:47+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "1D514568-B8EC-48B0-9C0D-2CD06C9E3682", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/1D514568-B8EC-48B0-9C0D-2CD06C9E3682/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2024-08-20T22:50:08+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "6068B12C-CDCA-4CC7-99C5-6362F131A371", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/6068B12C-CDCA-4CC7-99C5-6362F131A371/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-21T06:17:51+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "04095937-ED17-4B06-811D-4FD1663FC2CB", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/04095937-ED17-4B06-811D-4FD1663FC2CB/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115214/what-may-these-eggs-belong-to", "split": "validation", "split_group": "738a6cda422d67bf432c7a18f6d175a66e8a690347b5dcd1fab9299983720752", "tags": ["species-identification", "entomology", "eggs"], "thread_id": "biology:115214", "title": "What may these eggs belong to?"}} {"citation_context": "s on the outside of my house.\n\n\n\n\nThis is located on the north of Spain.\n\n\n\n\n[image: Image; source: https://i.sstatic.net/yrZLdw90.jpg] (https://i.sstatic.net/yrZLdw90.jpg)\n\n\n\n\nDo anyone knows what it belongs to?\n\n\n\n\nI'm leaning towar", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/yrZLdw90.jpg", "kind": "external_url", "post_id": 115214, "post_url": "https://biology.stackexchange.com/questions/115214/what-may-these-eggs-belong-to", "product": "citations", "record_id": "Scientific-Citation-Graph:b26bf3869646e1e725661c3c", "split": "validation", "thread": {"accepted_answer_id": 115228, "answers": [{"answer_html": "Just did a snap Google search for "assassin bug eggs" and the images that came up were very reminiscent of yours; here's a link to a good article with an image: https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs. So yeah, most likely possibility is assassin bug eggs.
\n", "answer_id": 115228, "answer_text": "Just did a snap Google search for \"assassin bug eggs\" and the images that came up were very reminiscent of yours; here's a link to a good article with an image: https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs (https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs). So yeah, most likely possibility is assassin bug eggs.", "answer_url": "https://biology.stackexchange.com/a/115228", "author": "Sir Thinksalot", "author_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-08-21T13:07:25+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:25.304620+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/7fe0b66593eb4c0f175024453138b8bd50811f1580a079ffb990af38e09cd1cf_0.json", "raw_sha256": "b0a655f3b4c9626cf981180b3ac018a4a26330c5ab9b925b3df78bedd8169a84", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/115493;115490;115488;115483;115479;115477;115456;115453;115452;115447;115445;115444;115436;115431;115427;115413;115404;115403;115396;115391;115389;115388;115386;115383;115382;115379;115367;115365;115355;115340;115334;115328;115321;115314;115309;115304;115296;115295;115292;115283;115272;115270;115269;115265;115264;115260;115255;115252;115243;115235;115233;115225;115218;115215;115214;115213;115207;115204;115179;115177;115170;115167;115165;115164;115154;115149;115137;115131;115129;115115;115107;115099;115095;115094;115093;115085;115082;115081;115077;115076;115075;115074;115073;115072;115063;115044;115039;115035;115030;115025;115022;115019;115016;115012;115003;115002;114997;114993;114991;114987/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115214, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sir Thinksalot", "profile_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "user_type": "registered"}, "created_at": "2024-08-21T13:07:25+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "99462C57-F01A-4035-B8BC-C1795FD8A5DD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/99462C57-F01A-4035-B8BC-C1795FD8A5DD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sir Thinksalot", "profile_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "user_type": "registered"}, "created_at": "2024-08-21T15:23:08+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "15565E89-16C1-49AD-B248-3F8119B0CD87", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/15565E89-16C1-49AD-B248-3F8119B0CD87/view-source"}], "score": 2, "updated_at": "2024-08-21T15:23:08+00:00"}], "domain": "biology", "external_links": ["https://es.wikipedia.org/wiki/Reduviidae", "https://i.sstatic.net/yrZLdw90.jpg", "https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs", "https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:05.762873+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/04ed2aa314c5d877c5d79e42620d1f80988a21de8d429a22d8c6af5280cfd6e8_0.json", "raw_sha256": "6dd355b99094bb9ba2c965ee7dd7b0e95f92a8078d3b2b85b64196fcb6cf717c", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=5&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Alfergon", "question_author_url": "https://biology.stackexchange.com/users/49841/alfergon", "question_author_user_type": "registered", "question_created_at": "2024-08-19T14:15:42+00:00", "question_html": "Today I've found these eggs on the outside of my house.
\nThis is located on the north of Spain.
\n\nDo anyone knows what it belongs to?
\nI'm leaning towards something related to the Reduviidae family?
\ngoogle image search for Reduviidae
\n", "question_id": 115214, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Today I've found these eggs on the outside of my house.\n\n\n\n\nThis is located on the north of Spain.\n\n\n\n\n[image: Image; source: https://i.sstatic.net/yrZLdw90.jpg] (https://i.sstatic.net/yrZLdw90.jpg)\n\n\n\n\nDo anyone knows what it belongs to?\n\n\n\n\nI'm leaning towards something related to the Reduviidae (https://es.wikipedia.org/wiki/Reduviidae) family?\n\n\n\n\ngoogle image search for Reduviidae (https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-19T14:15:42+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "3F151164-3974-4C03-B885-F93057D25FA2", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/3F151164-3974-4C03-B885-F93057D25FA2/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-20T12:01:47+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "1D514568-B8EC-48B0-9C0D-2CD06C9E3682", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/1D514568-B8EC-48B0-9C0D-2CD06C9E3682/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2024-08-20T22:50:08+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "6068B12C-CDCA-4CC7-99C5-6362F131A371", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/6068B12C-CDCA-4CC7-99C5-6362F131A371/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-21T06:17:51+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "04095937-ED17-4B06-811D-4FD1663FC2CB", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/04095937-ED17-4B06-811D-4FD1663FC2CB/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115214/what-may-these-eggs-belong-to", "split": "validation", "split_group": "738a6cda422d67bf432c7a18f6d175a66e8a690347b5dcd1fab9299983720752", "tags": ["species-identification", "entomology", "eggs"], "thread_id": "biology:115214", "title": "What may these eggs belong to?"}} {"citation_context": "duviidae (https://es.wikipedia.org/wiki/Reduviidae) family?\n\n\n\n\ngoogle image search for Reduviidae (https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp", "kind": "external_url", "post_id": 115214, "post_url": "https://biology.stackexchange.com/questions/115214/what-may-these-eggs-belong-to", "product": "citations", "record_id": "Scientific-Citation-Graph:344ec3db7050eb4832f46681", "split": "validation", "thread": {"accepted_answer_id": 115228, "answers": [{"answer_html": "Just did a snap Google search for "assassin bug eggs" and the images that came up were very reminiscent of yours; here's a link to a good article with an image: https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs. So yeah, most likely possibility is assassin bug eggs.
\n", "answer_id": 115228, "answer_text": "Just did a snap Google search for \"assassin bug eggs\" and the images that came up were very reminiscent of yours; here's a link to a good article with an image: https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs (https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs). So yeah, most likely possibility is assassin bug eggs.", "answer_url": "https://biology.stackexchange.com/a/115228", "author": "Sir Thinksalot", "author_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-08-21T13:07:25+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:25.304620+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/7fe0b66593eb4c0f175024453138b8bd50811f1580a079ffb990af38e09cd1cf_0.json", "raw_sha256": "b0a655f3b4c9626cf981180b3ac018a4a26330c5ab9b925b3df78bedd8169a84", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/115493;115490;115488;115483;115479;115477;115456;115453;115452;115447;115445;115444;115436;115431;115427;115413;115404;115403;115396;115391;115389;115388;115386;115383;115382;115379;115367;115365;115355;115340;115334;115328;115321;115314;115309;115304;115296;115295;115292;115283;115272;115270;115269;115265;115264;115260;115255;115252;115243;115235;115233;115225;115218;115215;115214;115213;115207;115204;115179;115177;115170;115167;115165;115164;115154;115149;115137;115131;115129;115115;115107;115099;115095;115094;115093;115085;115082;115081;115077;115076;115075;115074;115073;115072;115063;115044;115039;115035;115030;115025;115022;115019;115016;115012;115003;115002;114997;114993;114991;114987/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115214, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sir Thinksalot", "profile_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "user_type": "registered"}, "created_at": "2024-08-21T13:07:25+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "99462C57-F01A-4035-B8BC-C1795FD8A5DD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/99462C57-F01A-4035-B8BC-C1795FD8A5DD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sir Thinksalot", "profile_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "user_type": "registered"}, "created_at": "2024-08-21T15:23:08+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "15565E89-16C1-49AD-B248-3F8119B0CD87", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/15565E89-16C1-49AD-B248-3F8119B0CD87/view-source"}], "score": 2, "updated_at": "2024-08-21T15:23:08+00:00"}], "domain": "biology", "external_links": ["https://es.wikipedia.org/wiki/Reduviidae", "https://i.sstatic.net/yrZLdw90.jpg", "https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs", "https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:05.762873+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/04ed2aa314c5d877c5d79e42620d1f80988a21de8d429a22d8c6af5280cfd6e8_0.json", "raw_sha256": "6dd355b99094bb9ba2c965ee7dd7b0e95f92a8078d3b2b85b64196fcb6cf717c", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=5&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Alfergon", "question_author_url": "https://biology.stackexchange.com/users/49841/alfergon", "question_author_user_type": "registered", "question_created_at": "2024-08-19T14:15:42+00:00", "question_html": "Today I've found these eggs on the outside of my house.
\nThis is located on the north of Spain.
\n\nDo anyone knows what it belongs to?
\nI'm leaning towards something related to the Reduviidae family?
\ngoogle image search for Reduviidae
\n", "question_id": 115214, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Today I've found these eggs on the outside of my house.\n\n\n\n\nThis is located on the north of Spain.\n\n\n\n\n[image: Image; source: https://i.sstatic.net/yrZLdw90.jpg] (https://i.sstatic.net/yrZLdw90.jpg)\n\n\n\n\nDo anyone knows what it belongs to?\n\n\n\n\nI'm leaning towards something related to the Reduviidae (https://es.wikipedia.org/wiki/Reduviidae) family?\n\n\n\n\ngoogle image search for Reduviidae (https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-19T14:15:42+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "3F151164-3974-4C03-B885-F93057D25FA2", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/3F151164-3974-4C03-B885-F93057D25FA2/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-20T12:01:47+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "1D514568-B8EC-48B0-9C0D-2CD06C9E3682", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/1D514568-B8EC-48B0-9C0D-2CD06C9E3682/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2024-08-20T22:50:08+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "6068B12C-CDCA-4CC7-99C5-6362F131A371", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/6068B12C-CDCA-4CC7-99C5-6362F131A371/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-21T06:17:51+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "04095937-ED17-4B06-811D-4FD1663FC2CB", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/04095937-ED17-4B06-811D-4FD1663FC2CB/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115214/what-may-these-eggs-belong-to", "split": "validation", "split_group": "738a6cda422d67bf432c7a18f6d175a66e8a690347b5dcd1fab9299983720752", "tags": ["species-identification", "entomology", "eggs"], "thread_id": "biology:115214", "title": "What may these eggs belong to?"}} {"citation_context": " images that came up were very reminiscent of yours; here's a link to a good article with an image: https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs (https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs). So yeah, most ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs", "kind": "external_url", "post_id": 115228, "post_url": "https://biology.stackexchange.com/a/115228", "product": "citations", "record_id": "Scientific-Citation-Graph:67e24c27309e4443f32fd5ae", "split": "validation", "thread": {"accepted_answer_id": 115228, "answers": [{"answer_html": "Just did a snap Google search for "assassin bug eggs" and the images that came up were very reminiscent of yours; here's a link to a good article with an image: https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs. So yeah, most likely possibility is assassin bug eggs.
\n", "answer_id": 115228, "answer_text": "Just did a snap Google search for \"assassin bug eggs\" and the images that came up were very reminiscent of yours; here's a link to a good article with an image: https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs (https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs). So yeah, most likely possibility is assassin bug eggs.", "answer_url": "https://biology.stackexchange.com/a/115228", "author": "Sir Thinksalot", "author_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-08-21T13:07:25+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:25.304620+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/7fe0b66593eb4c0f175024453138b8bd50811f1580a079ffb990af38e09cd1cf_0.json", "raw_sha256": "b0a655f3b4c9626cf981180b3ac018a4a26330c5ab9b925b3df78bedd8169a84", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/115493;115490;115488;115483;115479;115477;115456;115453;115452;115447;115445;115444;115436;115431;115427;115413;115404;115403;115396;115391;115389;115388;115386;115383;115382;115379;115367;115365;115355;115340;115334;115328;115321;115314;115309;115304;115296;115295;115292;115283;115272;115270;115269;115265;115264;115260;115255;115252;115243;115235;115233;115225;115218;115215;115214;115213;115207;115204;115179;115177;115170;115167;115165;115164;115154;115149;115137;115131;115129;115115;115107;115099;115095;115094;115093;115085;115082;115081;115077;115076;115075;115074;115073;115072;115063;115044;115039;115035;115030;115025;115022;115019;115016;115012;115003;115002;114997;114993;114991;114987/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115214, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sir Thinksalot", "profile_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "user_type": "registered"}, "created_at": "2024-08-21T13:07:25+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "99462C57-F01A-4035-B8BC-C1795FD8A5DD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/99462C57-F01A-4035-B8BC-C1795FD8A5DD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sir Thinksalot", "profile_url": "https://biology.stackexchange.com/users/77161/sir-thinksalot", "user_type": "registered"}, "created_at": "2024-08-21T15:23:08+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "15565E89-16C1-49AD-B248-3F8119B0CD87", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/15565E89-16C1-49AD-B248-3F8119B0CD87/view-source"}], "score": 2, "updated_at": "2024-08-21T15:23:08+00:00"}], "domain": "biology", "external_links": ["https://es.wikipedia.org/wiki/Reduviidae", "https://i.sstatic.net/yrZLdw90.jpg", "https://www.canr.msu.edu/news/michigan-insects-in-the-garden-week-3-assassin-bugs", "https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:05.762873+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/04ed2aa314c5d877c5d79e42620d1f80988a21de8d429a22d8c6af5280cfd6e8_0.json", "raw_sha256": "6dd355b99094bb9ba2c965ee7dd7b0e95f92a8078d3b2b85b64196fcb6cf717c", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=5&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Alfergon", "question_author_url": "https://biology.stackexchange.com/users/49841/alfergon", "question_author_user_type": "registered", "question_created_at": "2024-08-19T14:15:42+00:00", "question_html": "Today I've found these eggs on the outside of my house.
\nThis is located on the north of Spain.
\n\nDo anyone knows what it belongs to?
\nI'm leaning towards something related to the Reduviidae family?
\ngoogle image search for Reduviidae
\n", "question_id": 115214, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Today I've found these eggs on the outside of my house.\n\n\n\n\nThis is located on the north of Spain.\n\n\n\n\n[image: Image; source: https://i.sstatic.net/yrZLdw90.jpg] (https://i.sstatic.net/yrZLdw90.jpg)\n\n\n\n\nDo anyone knows what it belongs to?\n\n\n\n\nI'm leaning towards something related to the Reduviidae (https://es.wikipedia.org/wiki/Reduviidae) family?\n\n\n\n\ngoogle image search for Reduviidae (https://www.google.com/search?q=reduviidae+eggs&sca_esv=a72b5ec367167047&sca_upv=1&udm=2&biw=1920&bih=934&sxsrf=ADLYWIL6aLs8MK4Vvs3vh4brXGokYl8q7g%3A1724155110357&ei=5oTEZqjEFYWxhbIPzqOFsAM&oq=reduvi+eggs&gs_lp=Egxnd3Mtd2l6LXNlcnAiC3JlZHV2aSBlZ2dzKgIIADIGEAAYBxgeSNkhUO4BWLcacAR4AJABAJgBZ6ABggaqAQM1LjO4AQPIAQD4AQL4AQGYAgWgAogDmAMAiAYBkgcDMy4yoAfREQ&sclient=gws-wiz-serp)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-19T14:15:42+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "3F151164-3974-4C03-B885-F93057D25FA2", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/3F151164-3974-4C03-B885-F93057D25FA2/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-20T12:01:47+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "1D514568-B8EC-48B0-9C0D-2CD06C9E3682", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/1D514568-B8EC-48B0-9C0D-2CD06C9E3682/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2024-08-20T22:50:08+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "6068B12C-CDCA-4CC7-99C5-6362F131A371", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/6068B12C-CDCA-4CC7-99C5-6362F131A371/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Alfergon", "profile_url": "https://biology.stackexchange.com/users/49841/alfergon", "user_type": "registered"}, "created_at": "2024-08-21T06:17:51+00:00", "raw_file": "raw/codex_api_v1/920b7e5633cbad837bacc37f0887fd883044a5fce63b6e0fa3cc1504390bec54_1790824091899465600_0.json", "raw_sha256": "bac2cc1988c9b300f258cae319a9302dc73ac2617e76f7491908df2a0b939d11", "revision_guid": "04095937-ED17-4B06-811D-4FD1663FC2CB", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/04095937-ED17-4B06-811D-4FD1663FC2CB/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115214/what-may-these-eggs-belong-to", "split": "validation", "split_group": "738a6cda422d67bf432c7a18f6d175a66e8a690347b5dcd1fab9299983720752", "tags": ["species-identification", "entomology", "eggs"], "thread_id": "biology:115214", "title": "What may these eggs belong to?"}} {"citation_context": " do experiments. Here (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3148252/) is another. And here (https://www.nature.com/articles/srep30591) is another. Several of these appear to share authors, I don't know if that's Google SEO or a small", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.nature.com/articles/srep30591", "kind": "external_url", "post_id": 112860, "post_url": "https://biology.stackexchange.com/a/112860", "product": "citations", "record_id": "Scientific-Citation-Graph:2900c4d63c1b83d75f77c9af", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "I assume that you want to e.g. express fluorescent proteins for doing some kind of experimental study of Salmonella, as opposed to industrial protein production.
\nI would suggest looking into prior work that uses Salmonella as a model. For example, I found this paper somewhat at random that uses several vectors in Salmonella to do experiments. Here is another. And here is another. Several of these appear to share authors, I don't know if that's Google SEO or a small research community.
\n", "answer_id": 112860, "answer_text": "I assume that you want to e.g. express fluorescent proteins for doing some kind of experimental study of Salmonella, as opposed to industrial protein production.\n\n\n\n\nI would suggest looking into prior work that uses Salmonella as a model. For example, I found this paper (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1230934/) somewhat at random that uses several vectors in Salmonella to do experiments. Here (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3148252/) is another. And here (https://www.nature.com/articles/srep30591) is another. Several of these appear to share authors, I don't know if that's Google SEO or a small research community.", "answer_url": "https://biology.stackexchange.com/a/112860", "author": "Maximilian Press", "author_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2023-08-23T23:34:46+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:38.885561+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/a145de97eabc007745b45919875489a41261075cbdf33d916d9640ba4ad0bd35_0.json", "raw_sha256": "e7d8d4315eef8e039a452d2811869cbe305575c6ff8a6bef8f80d6dfb58c5bfd", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/112982;112980;112979;112977;112972;112967;112962;112956;112952;112948;112941;112938;112937;112936;112927;112925;112923;112919;112909;112905;112904;112898;112895;112893;112884;112881;112880;112879;112873;112872;112870;112869;112867;112850;112849;112848;112841;112835;112831;112824;112818;112811;112808;112807;112790;112789;112785;112777;112773;112770;112762;112759;112757;112756;112746;112739;112738;112737;112731;112705;112703;112700;112699;112698;112693;112691;112687;112685;112677;112671;112667;112663;112659;112653;112647;112646;112645;112636;112625;112621;112615;112614;112613;112610;112598;112593;112592;112586;112580;112575;112574;112564;112558;112552;112550;112549;112544;112539;112535;112531/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 112848, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2023-08-23T23:34:46+00:00", "raw_file": "raw/codex_api_v1/9b8fea4e5df4051aa25c1aa90b42eca7481ee703f92ba25aeabed3d0b53e7a04_1790824026598483100_0.json", "raw_sha256": "f252fc1b154815b8794116efb3b685202eda8dddb2cd870ae32ee5e82716c300", "revision_guid": "924D87E9-4094-4AE1-A1E6-1208DFE16664", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/924D87E9-4094-4AE1-A1E6-1208DFE16664/view-source"}], "score": 1, "updated_at": "2023-08-23T23:34:46+00:00"}], "domain": "biology", "external_links": ["https://www.nature.com/articles/srep30591", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1230934/", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3148252/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:12.794960+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/01e5186067e30dc1b8d7a145670ab7edd6b017797b271a481af8b7b7f55f13c2_0.json", "raw_sha256": "6c3960de7e1d3d7920bb88d02e2184614c219b391f39d9bddc2a582fdc9a71e7", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=10&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "John Appleseed", "question_author_url": "https://biology.stackexchange.com/users/76665/john-appleseed", "question_author_user_type": "registered", "question_created_at": "2023-08-22T01:38:00+00:00", "question_html": "I am interested in expressing custom proteins in a Salmonella strain, however I am facing difficulties in finding the appropriate expression vector for it. It seems that most of the resources provide for E. coli expression. Does anyone have any recommendations?
\nThanks in advance.
\n", "question_id": 112848, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "I am interested in expressing custom proteins in a Salmonella strain, however I am facing difficulties in finding the appropriate expression vector for it. It seems that most of the resources provide for E. coli expression. Does anyone have any recommendations?\n\n\n\n\nThanks in advance.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John Appleseed", "profile_url": "https://biology.stackexchange.com/users/76665/john-appleseed", "user_type": "registered"}, "created_at": "2023-08-22T01:38:00+00:00", "raw_file": "raw/codex_api_v1/9b8fea4e5df4051aa25c1aa90b42eca7481ee703f92ba25aeabed3d0b53e7a04_1790824026598483100_0.json", "raw_sha256": "f252fc1b154815b8794116efb3b685202eda8dddb2cd870ae32ee5e82716c300", "revision_guid": "DCF88F7D-806A-43EA-89F1-8DE13B79EBA9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/DCF88F7D-806A-43EA-89F1-8DE13B79EBA9/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://biology.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2023-09-23T01:06:05+00:00", "raw_file": "raw/codex_api_v1/276704dec9e06f92cc8145549f11d289b09416db9510f3666cf41802c4fac079_1790824013419814500_0.json", "raw_sha256": "062895378f6d877b905162e2e8855c08fb76517235f50b72affe2d1d54cb9ced", "revision_guid": "A7856B8E-0876-45EE-8251-5540F0DC7551", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/A7856B8E-0876-45EE-8251-5540F0DC7551/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://biology.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2024-01-21T02:07:35+00:00", "raw_file": "raw/codex_api_v1/276704dec9e06f92cc8145549f11d289b09416db9510f3666cf41802c4fac079_1790824013419814500_0.json", "raw_sha256": "062895378f6d877b905162e2e8855c08fb76517235f50b72affe2d1d54cb9ced", "revision_guid": "6D741F30-7C13-42E4-BDAE-AB8EBB416841", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/6D741F30-7C13-42E4-BDAE-AB8EBB416841/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://biology.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2024-05-20T03:07:40+00:00", "raw_file": "raw/codex_api_v1/276704dec9e06f92cc8145549f11d289b09416db9510f3666cf41802c4fac079_1790824013419814500_0.json", "raw_sha256": "062895378f6d877b905162e2e8855c08fb76517235f50b72affe2d1d54cb9ced", "revision_guid": "0C2B5E60-7F44-42BD-99F9-5662C7C1CAF8", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/0C2B5E60-7F44-42BD-99F9-5662C7C1CAF8/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/112848/what-is-a-good-expression-vector-for-salmonella-enterica-subsp-enterica-serovar", "split": "validation", "split_group": "32bb2544b1b44160af1154cd51a54ae39b2c7115ff87d64fbc9cdde35edd1529", "tags": ["genetics", "gene-expression", "plasmids", "protein-expression", "biomedical-engineering"], "thread_id": "biology:112848", "title": "What is a good expression vector for Salmonella enterica subsp. enterica serovar typhimurium"}} {"citation_context": "d suggest looking into prior work that uses Salmonella as a model. For example, I found this paper (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1230934/) somewhat at random that uses several vectors in Salmonella to do experiments. Here (https://www.nc", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1230934/", "kind": "external_url", "post_id": 112860, "post_url": "https://biology.stackexchange.com/a/112860", "product": "citations", "record_id": "Scientific-Citation-Graph:04046356126756f893667660", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "I assume that you want to e.g. express fluorescent proteins for doing some kind of experimental study of Salmonella, as opposed to industrial protein production.
\nI would suggest looking into prior work that uses Salmonella as a model. For example, I found this paper somewhat at random that uses several vectors in Salmonella to do experiments. Here is another. And here is another. Several of these appear to share authors, I don't know if that's Google SEO or a small research community.
\n", "answer_id": 112860, "answer_text": "I assume that you want to e.g. express fluorescent proteins for doing some kind of experimental study of Salmonella, as opposed to industrial protein production.\n\n\n\n\nI would suggest looking into prior work that uses Salmonella as a model. For example, I found this paper (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1230934/) somewhat at random that uses several vectors in Salmonella to do experiments. Here (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3148252/) is another. And here (https://www.nature.com/articles/srep30591) is another. Several of these appear to share authors, I don't know if that's Google SEO or a small research community.", "answer_url": "https://biology.stackexchange.com/a/112860", "author": "Maximilian Press", "author_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2023-08-23T23:34:46+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:38.885561+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/a145de97eabc007745b45919875489a41261075cbdf33d916d9640ba4ad0bd35_0.json", "raw_sha256": "e7d8d4315eef8e039a452d2811869cbe305575c6ff8a6bef8f80d6dfb58c5bfd", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/112982;112980;112979;112977;112972;112967;112962;112956;112952;112948;112941;112938;112937;112936;112927;112925;112923;112919;112909;112905;112904;112898;112895;112893;112884;112881;112880;112879;112873;112872;112870;112869;112867;112850;112849;112848;112841;112835;112831;112824;112818;112811;112808;112807;112790;112789;112785;112777;112773;112770;112762;112759;112757;112756;112746;112739;112738;112737;112731;112705;112703;112700;112699;112698;112693;112691;112687;112685;112677;112671;112667;112663;112659;112653;112647;112646;112645;112636;112625;112621;112615;112614;112613;112610;112598;112593;112592;112586;112580;112575;112574;112564;112558;112552;112550;112549;112544;112539;112535;112531/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 112848, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2023-08-23T23:34:46+00:00", "raw_file": "raw/codex_api_v1/9b8fea4e5df4051aa25c1aa90b42eca7481ee703f92ba25aeabed3d0b53e7a04_1790824026598483100_0.json", "raw_sha256": "f252fc1b154815b8794116efb3b685202eda8dddb2cd870ae32ee5e82716c300", "revision_guid": "924D87E9-4094-4AE1-A1E6-1208DFE16664", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/924D87E9-4094-4AE1-A1E6-1208DFE16664/view-source"}], "score": 1, "updated_at": "2023-08-23T23:34:46+00:00"}], "domain": "biology", "external_links": ["https://www.nature.com/articles/srep30591", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1230934/", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3148252/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:12.794960+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/01e5186067e30dc1b8d7a145670ab7edd6b017797b271a481af8b7b7f55f13c2_0.json", "raw_sha256": "6c3960de7e1d3d7920bb88d02e2184614c219b391f39d9bddc2a582fdc9a71e7", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=10&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "John Appleseed", "question_author_url": "https://biology.stackexchange.com/users/76665/john-appleseed", "question_author_user_type": "registered", "question_created_at": "2023-08-22T01:38:00+00:00", "question_html": "I am interested in expressing custom proteins in a Salmonella strain, however I am facing difficulties in finding the appropriate expression vector for it. It seems that most of the resources provide for E. coli expression. Does anyone have any recommendations?
\nThanks in advance.
\n", "question_id": 112848, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "I am interested in expressing custom proteins in a Salmonella strain, however I am facing difficulties in finding the appropriate expression vector for it. It seems that most of the resources provide for E. coli expression. Does anyone have any recommendations?\n\n\n\n\nThanks in advance.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John Appleseed", "profile_url": "https://biology.stackexchange.com/users/76665/john-appleseed", "user_type": "registered"}, "created_at": "2023-08-22T01:38:00+00:00", "raw_file": "raw/codex_api_v1/9b8fea4e5df4051aa25c1aa90b42eca7481ee703f92ba25aeabed3d0b53e7a04_1790824026598483100_0.json", "raw_sha256": "f252fc1b154815b8794116efb3b685202eda8dddb2cd870ae32ee5e82716c300", "revision_guid": "DCF88F7D-806A-43EA-89F1-8DE13B79EBA9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/DCF88F7D-806A-43EA-89F1-8DE13B79EBA9/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://biology.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2023-09-23T01:06:05+00:00", "raw_file": "raw/codex_api_v1/276704dec9e06f92cc8145549f11d289b09416db9510f3666cf41802c4fac079_1790824013419814500_0.json", "raw_sha256": "062895378f6d877b905162e2e8855c08fb76517235f50b72affe2d1d54cb9ced", "revision_guid": "A7856B8E-0876-45EE-8251-5540F0DC7551", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/A7856B8E-0876-45EE-8251-5540F0DC7551/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://biology.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2024-01-21T02:07:35+00:00", "raw_file": "raw/codex_api_v1/276704dec9e06f92cc8145549f11d289b09416db9510f3666cf41802c4fac079_1790824013419814500_0.json", "raw_sha256": "062895378f6d877b905162e2e8855c08fb76517235f50b72affe2d1d54cb9ced", "revision_guid": "6D741F30-7C13-42E4-BDAE-AB8EBB416841", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/6D741F30-7C13-42E4-BDAE-AB8EBB416841/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://biology.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2024-05-20T03:07:40+00:00", "raw_file": "raw/codex_api_v1/276704dec9e06f92cc8145549f11d289b09416db9510f3666cf41802c4fac079_1790824013419814500_0.json", "raw_sha256": "062895378f6d877b905162e2e8855c08fb76517235f50b72affe2d1d54cb9ced", "revision_guid": "0C2B5E60-7F44-42BD-99F9-5662C7C1CAF8", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/0C2B5E60-7F44-42BD-99F9-5662C7C1CAF8/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/112848/what-is-a-good-expression-vector-for-salmonella-enterica-subsp-enterica-serovar", "split": "validation", "split_group": "32bb2544b1b44160af1154cd51a54ae39b2c7115ff87d64fbc9cdde35edd1529", "tags": ["genetics", "gene-expression", "plasmids", "protein-expression", "biomedical-engineering"], "thread_id": "biology:112848", "title": "What is a good expression vector for Salmonella enterica subsp. enterica serovar typhimurium"}} {"citation_context": "es/PMC1230934/) somewhat at random that uses several vectors in Salmonella to do experiments. Here (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3148252/) is another. And here (https://www.nature.com/articles/srep30591) is another. Several of these appe", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3148252/", "kind": "external_url", "post_id": 112860, "post_url": "https://biology.stackexchange.com/a/112860", "product": "citations", "record_id": "Scientific-Citation-Graph:3c928297b4be86e175f0d177", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "I assume that you want to e.g. express fluorescent proteins for doing some kind of experimental study of Salmonella, as opposed to industrial protein production.
\nI would suggest looking into prior work that uses Salmonella as a model. For example, I found this paper somewhat at random that uses several vectors in Salmonella to do experiments. Here is another. And here is another. Several of these appear to share authors, I don't know if that's Google SEO or a small research community.
\n", "answer_id": 112860, "answer_text": "I assume that you want to e.g. express fluorescent proteins for doing some kind of experimental study of Salmonella, as opposed to industrial protein production.\n\n\n\n\nI would suggest looking into prior work that uses Salmonella as a model. For example, I found this paper (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1230934/) somewhat at random that uses several vectors in Salmonella to do experiments. Here (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3148252/) is another. And here (https://www.nature.com/articles/srep30591) is another. Several of these appear to share authors, I don't know if that's Google SEO or a small research community.", "answer_url": "https://biology.stackexchange.com/a/112860", "author": "Maximilian Press", "author_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2023-08-23T23:34:46+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:38.885561+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/a145de97eabc007745b45919875489a41261075cbdf33d916d9640ba4ad0bd35_0.json", "raw_sha256": "e7d8d4315eef8e039a452d2811869cbe305575c6ff8a6bef8f80d6dfb58c5bfd", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/112982;112980;112979;112977;112972;112967;112962;112956;112952;112948;112941;112938;112937;112936;112927;112925;112923;112919;112909;112905;112904;112898;112895;112893;112884;112881;112880;112879;112873;112872;112870;112869;112867;112850;112849;112848;112841;112835;112831;112824;112818;112811;112808;112807;112790;112789;112785;112777;112773;112770;112762;112759;112757;112756;112746;112739;112738;112737;112731;112705;112703;112700;112699;112698;112693;112691;112687;112685;112677;112671;112667;112663;112659;112653;112647;112646;112645;112636;112625;112621;112615;112614;112613;112610;112598;112593;112592;112586;112580;112575;112574;112564;112558;112552;112550;112549;112544;112539;112535;112531/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 112848, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2023-08-23T23:34:46+00:00", "raw_file": "raw/codex_api_v1/9b8fea4e5df4051aa25c1aa90b42eca7481ee703f92ba25aeabed3d0b53e7a04_1790824026598483100_0.json", "raw_sha256": "f252fc1b154815b8794116efb3b685202eda8dddb2cd870ae32ee5e82716c300", "revision_guid": "924D87E9-4094-4AE1-A1E6-1208DFE16664", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/924D87E9-4094-4AE1-A1E6-1208DFE16664/view-source"}], "score": 1, "updated_at": "2023-08-23T23:34:46+00:00"}], "domain": "biology", "external_links": ["https://www.nature.com/articles/srep30591", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1230934/", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3148252/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:12.794960+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/01e5186067e30dc1b8d7a145670ab7edd6b017797b271a481af8b7b7f55f13c2_0.json", "raw_sha256": "6c3960de7e1d3d7920bb88d02e2184614c219b391f39d9bddc2a582fdc9a71e7", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=10&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "John Appleseed", "question_author_url": "https://biology.stackexchange.com/users/76665/john-appleseed", "question_author_user_type": "registered", "question_created_at": "2023-08-22T01:38:00+00:00", "question_html": "I am interested in expressing custom proteins in a Salmonella strain, however I am facing difficulties in finding the appropriate expression vector for it. It seems that most of the resources provide for E. coli expression. Does anyone have any recommendations?
\nThanks in advance.
\n", "question_id": 112848, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "I am interested in expressing custom proteins in a Salmonella strain, however I am facing difficulties in finding the appropriate expression vector for it. It seems that most of the resources provide for E. coli expression. Does anyone have any recommendations?\n\n\n\n\nThanks in advance.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John Appleseed", "profile_url": "https://biology.stackexchange.com/users/76665/john-appleseed", "user_type": "registered"}, "created_at": "2023-08-22T01:38:00+00:00", "raw_file": "raw/codex_api_v1/9b8fea4e5df4051aa25c1aa90b42eca7481ee703f92ba25aeabed3d0b53e7a04_1790824026598483100_0.json", "raw_sha256": "f252fc1b154815b8794116efb3b685202eda8dddb2cd870ae32ee5e82716c300", "revision_guid": "DCF88F7D-806A-43EA-89F1-8DE13B79EBA9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/DCF88F7D-806A-43EA-89F1-8DE13B79EBA9/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://biology.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2023-09-23T01:06:05+00:00", "raw_file": "raw/codex_api_v1/276704dec9e06f92cc8145549f11d289b09416db9510f3666cf41802c4fac079_1790824013419814500_0.json", "raw_sha256": "062895378f6d877b905162e2e8855c08fb76517235f50b72affe2d1d54cb9ced", "revision_guid": "A7856B8E-0876-45EE-8251-5540F0DC7551", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/A7856B8E-0876-45EE-8251-5540F0DC7551/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://biology.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2024-01-21T02:07:35+00:00", "raw_file": "raw/codex_api_v1/276704dec9e06f92cc8145549f11d289b09416db9510f3666cf41802c4fac079_1790824013419814500_0.json", "raw_sha256": "062895378f6d877b905162e2e8855c08fb76517235f50b72affe2d1d54cb9ced", "revision_guid": "6D741F30-7C13-42E4-BDAE-AB8EBB416841", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/6D741F30-7C13-42E4-BDAE-AB8EBB416841/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://biology.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2024-05-20T03:07:40+00:00", "raw_file": "raw/codex_api_v1/276704dec9e06f92cc8145549f11d289b09416db9510f3666cf41802c4fac079_1790824013419814500_0.json", "raw_sha256": "062895378f6d877b905162e2e8855c08fb76517235f50b72affe2d1d54cb9ced", "revision_guid": "0C2B5E60-7F44-42BD-99F9-5662C7C1CAF8", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/0C2B5E60-7F44-42BD-99F9-5662C7C1CAF8/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/112848/what-is-a-good-expression-vector-for-salmonella-enterica-subsp-enterica-serovar", "split": "validation", "split_group": "32bb2544b1b44160af1154cd51a54ae39b2c7115ff87d64fbc9cdde35edd1529", "tags": ["genetics", "gene-expression", "plasmids", "protein-expression", "biomedical-engineering"], "thread_id": "biology:112848", "title": "What is a good expression vector for Salmonella enterica subsp. enterica serovar typhimurium"}} {"citation_context": "EzeAZo7.jpg] (https://i.sstatic.net/vEzeAZo7.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/8M2o9qBT.jpg] (https://i.sstatic.net/8M2o9qBT.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.s", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/8M2o9qBT.jpg", "kind": "external_url", "post_id": 115012, "post_url": "https://biology.stackexchange.com/questions/115012/what-is-this-worm-like-creature", "product": "citations", "record_id": "Scientific-Citation-Graph:f708dd369eca2d41a107e06e", "split": "validation", "thread": {"accepted_answer_id": 115018, "answers": [{"answer_html": "This bears resemblance to Calci worms (also known as Black Soldier Fly Worms).
\nhttps://kimmyfarm.com/en/black-soldier-fly/larvae\nHope this helps :)
What is it? It moves like a worm. The things on the body are some seeds.\n
It is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024
\nIt is 1cm long and 0.2 cm wide and high
\nThe source is the trash can where more were found
\n", "question_id": 115012, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "What is it? It moves like a worm. The things on the body are some seeds.\n[image: enter image description here; source: https://i.sstatic.net/vEzeAZo7.jpg] (https://i.sstatic.net/vEzeAZo7.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/8M2o9qBT.jpg] (https://i.sstatic.net/8M2o9qBT.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/AJjCUnV8.jpg] (https://i.sstatic.net/AJjCUnV8.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/A2ct6A28.jpg] (https://i.sstatic.net/A2ct6A28.jpg)\n\n\n\n\nIt is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024\n\n\n\n\nIt is 1cm long and 0.2 cm wide and high\n\n\n\n\nThe source is the trash can where more were found", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T10:37:04+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "7276A956-C370-4924-A727-F851251F6C81", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7276A956-C370-4924-A727-F851251F6C81/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T11:31:51+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "77317B06-4C15-4098-B2C2-C3C1583871D0", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/77317B06-4C15-4098-B2C2-C3C1583871D0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115012/what-is-this-worm-like-creature", "split": "validation", "split_group": "37af3db6c13d115dbfb8ca78f8dce29c61eec0dcf1cd3b70eab508386ae7a58b", "tags": ["species-identification"], "thread_id": "biology:115012", "title": "What is this worm like creature"}} {"citation_context": "JjCUnV8.jpg] (https://i.sstatic.net/AJjCUnV8.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/A2ct6A28.jpg] (https://i.sstatic.net/A2ct6A28.jpg)\n\n\n\n\nIt is found in Germany near Düsseldorf. It is 12:30 on 19", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/A2ct6A28.jpg", "kind": "external_url", "post_id": 115012, "post_url": "https://biology.stackexchange.com/questions/115012/what-is-this-worm-like-creature", "product": "citations", "record_id": "Scientific-Citation-Graph:e9bf58489959647587e144a3", "split": "validation", "thread": {"accepted_answer_id": 115018, "answers": [{"answer_html": "This bears resemblance to Calci worms (also known as Black Soldier Fly Worms).
\nhttps://kimmyfarm.com/en/black-soldier-fly/larvae\nHope this helps :)
What is it? It moves like a worm. The things on the body are some seeds.\n
It is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024
\nIt is 1cm long and 0.2 cm wide and high
\nThe source is the trash can where more were found
\n", "question_id": 115012, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "What is it? It moves like a worm. The things on the body are some seeds.\n[image: enter image description here; source: https://i.sstatic.net/vEzeAZo7.jpg] (https://i.sstatic.net/vEzeAZo7.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/8M2o9qBT.jpg] (https://i.sstatic.net/8M2o9qBT.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/AJjCUnV8.jpg] (https://i.sstatic.net/AJjCUnV8.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/A2ct6A28.jpg] (https://i.sstatic.net/A2ct6A28.jpg)\n\n\n\n\nIt is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024\n\n\n\n\nIt is 1cm long and 0.2 cm wide and high\n\n\n\n\nThe source is the trash can where more were found", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T10:37:04+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "7276A956-C370-4924-A727-F851251F6C81", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7276A956-C370-4924-A727-F851251F6C81/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T11:31:51+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "77317B06-4C15-4098-B2C2-C3C1583871D0", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/77317B06-4C15-4098-B2C2-C3C1583871D0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115012/what-is-this-worm-like-creature", "split": "validation", "split_group": "37af3db6c13d115dbfb8ca78f8dce29c61eec0dcf1cd3b70eab508386ae7a58b", "tags": ["species-identification"], "thread_id": "biology:115012", "title": "What is this worm like creature"}} {"citation_context": "M2o9qBT.jpg] (https://i.sstatic.net/8M2o9qBT.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/AJjCUnV8.jpg] (https://i.sstatic.net/AJjCUnV8.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.s", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/AJjCUnV8.jpg", "kind": "external_url", "post_id": 115012, "post_url": "https://biology.stackexchange.com/questions/115012/what-is-this-worm-like-creature", "product": "citations", "record_id": "Scientific-Citation-Graph:ce7491c1a34abd0c6f8e2256", "split": "validation", "thread": {"accepted_answer_id": 115018, "answers": [{"answer_html": "This bears resemblance to Calci worms (also known as Black Soldier Fly Worms).
\nhttps://kimmyfarm.com/en/black-soldier-fly/larvae\nHope this helps :)
What is it? It moves like a worm. The things on the body are some seeds.\n
It is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024
\nIt is 1cm long and 0.2 cm wide and high
\nThe source is the trash can where more were found
\n", "question_id": 115012, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "What is it? It moves like a worm. The things on the body are some seeds.\n[image: enter image description here; source: https://i.sstatic.net/vEzeAZo7.jpg] (https://i.sstatic.net/vEzeAZo7.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/8M2o9qBT.jpg] (https://i.sstatic.net/8M2o9qBT.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/AJjCUnV8.jpg] (https://i.sstatic.net/AJjCUnV8.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/A2ct6A28.jpg] (https://i.sstatic.net/A2ct6A28.jpg)\n\n\n\n\nIt is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024\n\n\n\n\nIt is 1cm long and 0.2 cm wide and high\n\n\n\n\nThe source is the trash can where more were found", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T10:37:04+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "7276A956-C370-4924-A727-F851251F6C81", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7276A956-C370-4924-A727-F851251F6C81/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T11:31:51+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "77317B06-4C15-4098-B2C2-C3C1583871D0", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/77317B06-4C15-4098-B2C2-C3C1583871D0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115012/what-is-this-worm-like-creature", "split": "validation", "split_group": "37af3db6c13d115dbfb8ca78f8dce29c61eec0dcf1cd3b70eab508386ae7a58b", "tags": ["species-identification"], "thread_id": "biology:115012", "title": "What is this worm like creature"}} {"citation_context": "s like a worm. The things on the body are some seeds.\n[image: enter image description here; source: https://i.sstatic.net/vEzeAZo7.jpg] (https://i.sstatic.net/vEzeAZo7.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.s", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/vEzeAZo7.jpg", "kind": "external_url", "post_id": 115012, "post_url": "https://biology.stackexchange.com/questions/115012/what-is-this-worm-like-creature", "product": "citations", "record_id": "Scientific-Citation-Graph:89b00a9566950a334e8427de", "split": "validation", "thread": {"accepted_answer_id": 115018, "answers": [{"answer_html": "This bears resemblance to Calci worms (also known as Black Soldier Fly Worms).
\nhttps://kimmyfarm.com/en/black-soldier-fly/larvae\nHope this helps :)
What is it? It moves like a worm. The things on the body are some seeds.\n
It is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024
\nIt is 1cm long and 0.2 cm wide and high
\nThe source is the trash can where more were found
\n", "question_id": 115012, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "What is it? It moves like a worm. The things on the body are some seeds.\n[image: enter image description here; source: https://i.sstatic.net/vEzeAZo7.jpg] (https://i.sstatic.net/vEzeAZo7.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/8M2o9qBT.jpg] (https://i.sstatic.net/8M2o9qBT.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/AJjCUnV8.jpg] (https://i.sstatic.net/AJjCUnV8.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/A2ct6A28.jpg] (https://i.sstatic.net/A2ct6A28.jpg)\n\n\n\n\nIt is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024\n\n\n\n\nIt is 1cm long and 0.2 cm wide and high\n\n\n\n\nThe source is the trash can where more were found", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T10:37:04+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "7276A956-C370-4924-A727-F851251F6C81", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7276A956-C370-4924-A727-F851251F6C81/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T11:31:51+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "77317B06-4C15-4098-B2C2-C3C1583871D0", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/77317B06-4C15-4098-B2C2-C3C1583871D0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115012/what-is-this-worm-like-creature", "split": "validation", "split_group": "37af3db6c13d115dbfb8ca78f8dce29c61eec0dcf1cd3b70eab508386ae7a58b", "tags": ["species-identification"], "thread_id": "biology:115012", "title": "What is this worm like creature"}} {"citation_context": "This bears resemblance to Calci worms (also known as Black Soldier Fly Worms).\n\nhttps://kimmyfarm.com/en/black-soldier-fly/larvae (https://kimmyfarm.com/en/black-soldier-fly/larvae)\nHope this helps :)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://kimmyfarm.com/en/black-soldier-fly/larvae", "kind": "external_url", "post_id": 115018, "post_url": "https://biology.stackexchange.com/a/115018", "product": "citations", "record_id": "Scientific-Citation-Graph:225a241e923b26335457e830", "split": "validation", "thread": {"accepted_answer_id": 115018, "answers": [{"answer_html": "This bears resemblance to Calci worms (also known as Black Soldier Fly Worms).
\nhttps://kimmyfarm.com/en/black-soldier-fly/larvae\nHope this helps :)
What is it? It moves like a worm. The things on the body are some seeds.\n
It is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024
\nIt is 1cm long and 0.2 cm wide and high
\nThe source is the trash can where more were found
\n", "question_id": 115012, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "What is it? It moves like a worm. The things on the body are some seeds.\n[image: enter image description here; source: https://i.sstatic.net/vEzeAZo7.jpg] (https://i.sstatic.net/vEzeAZo7.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/8M2o9qBT.jpg] (https://i.sstatic.net/8M2o9qBT.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/AJjCUnV8.jpg] (https://i.sstatic.net/AJjCUnV8.jpg)\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/A2ct6A28.jpg] (https://i.sstatic.net/A2ct6A28.jpg)\n\n\n\n\nIt is found in Germany near Düsseldorf. It is 12:30 on 19.07.2024\n\n\n\n\nIt is 1cm long and 0.2 cm wide and high\n\n\n\n\nThe source is the trash can where more were found", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T10:37:04+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "7276A956-C370-4924-A727-F851251F6C81", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7276A956-C370-4924-A727-F851251F6C81/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bastian Müller", "profile_url": "https://biology.stackexchange.com/users/83913/bastian-m%c3%bcller", "user_type": "registered"}, "created_at": "2024-07-19T11:31:51+00:00", "raw_file": "raw/codex_api_v1/b791c89400945e2056cb034a53d0e8f06f87fe6cbca4604878f1fbb196e52630_1790824084561721000_0.json", "raw_sha256": "00e0c2f3f9bf340522a9a667da4c0320086ed2d8ffa96deda47042bc8afd545c", "revision_guid": "77317B06-4C15-4098-B2C2-C3C1583871D0", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/77317B06-4C15-4098-B2C2-C3C1583871D0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115012/what-is-this-worm-like-creature", "split": "validation", "split_group": "37af3db6c13d115dbfb8ca78f8dce29c61eec0dcf1cd3b70eab508386ae7a58b", "tags": ["species-identification"], "thread_id": "biology:115012", "title": "What is this worm like creature"}} {"citation_context": "I read on Britannica (https://curiosity.britannica.com/science-of-curiosity.html) that all animals down to microorganisms are \"information seeking\", but there was no source to back", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://curiosity.britannica.com/science-of-curiosity.html", "kind": "external_url", "post_id": 113761, "post_url": "https://biology.stackexchange.com/questions/113761/are-all-animals-information-seeking", "product": "citations", "record_id": "Scientific-Citation-Graph:b4662bc1c5afc357ff554eaf", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The answer is going to entirely depend on how you define "information seeking". How do you choose to define it? If Britannica does not define what they mean by "information seeking" then that statement is not useful by itself. It's common to encounter these sorts of statements in writing targeted to a non-specialist audience. They are not meant to be taken quite so literally, they're designed to get your mind working and exploring to help you interpret the next things they're going to say. So, let's look at what else they say:
\n\n\nThis is so they know how to navigate it.
\n
Not all animals even move, so for this to make sense for "all animals" it must be a pretty broad meaning of "navigate" to be true.
\n\n\nIn fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.
\n
Every animal has some ability to sense the outside world; I'd argue that even every plant and single-celled organism does as well, this is an absolute requirement for life.
\n\n\nto supply the brain with information
\n
Well, we're back to more specific then, many animal species do not have brains. Sponges, for one; cnidarians also, though they do have a nervous system they're not typically thought of as having a brain.
\nSo, it seems that all Britannica means by "information seeking" is "somehow collect information from the outside world". That's not a very strong statement since "collecting information" can mean almost anything. But, it's also not the sort of thing anyone can prove: there could always be some hypothetical life out there that doesn't collect information but it's not anything we've found.
\n", "answer_id": 113769, "answer_text": "The answer is going to entirely depend on how you define \"information seeking\". How do you choose to define it? If Britannica does not define what they mean by \"information seeking\" then that statement is not useful by itself. It's common to encounter these sorts of statements in writing targeted to a non-specialist audience. They are not meant to be taken quite so literally, they're designed to get your mind working and exploring to help you interpret the next things they're going to say. So, let's look at what else they say:\n\n\n\n\n\n\n\nThis is so they know how to navigate it.\n\n\n\n\n\n\n\nNot all animals even move (https://en.wikipedia.org/wiki/Sponge), so for this to make sense for \"all animals\" it must be a pretty broad meaning of \"navigate\" to be true.\n\n\n\n\n\n\n\nIn fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.\n\n\n\n\n\n\n\nEvery animal has some ability to sense the outside world; I'd argue that even every plant and single-celled organism does as well, this is an absolute requirement for life.\n\n\n\n\n\n\n\nto supply the brain with information\n\n\n\n\n\n\n\nWell, we're back to more specific then, many animal species do not have brains. Sponges, for one; cnidarians also (https://en.wikipedia.org/wiki/Cnidaria), though they do have a nervous system they're not typically thought of as having a brain.\n\n\n\n\nSo, it seems that all Britannica means by \"information seeking\" is \"somehow collect information from the outside world\". That's not a very strong statement since \"collecting information\" can mean almost anything. But, it's also not the sort of thing anyone can prove: there could always be some hypothetical life out there that doesn't collect information but it's not anything we've found.", "answer_url": "https://biology.stackexchange.com/a/113769", "author": "Bryan Krause", "author_url": "https://biology.stackexchange.com/users/27148/bryan-krause", "author_user_type": "moderator", "content_license": "CC BY-SA 4.0", "created_at": "2024-01-02T15:06:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:33.526680+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/d1acc50471f82e02a014a291913995889f5ddcd7076433532102b9b97a4a3a3d_0.json", "raw_sha256": "e6b5a7d5e11f0ac54d756d69e21baee1de119b759ec7e8caa7f174d67cf80eff", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/113978;113977;113976;113967;113965;113959;113955;113947;113946;113937;113936;113924;113918;113912;113907;113904;113902;113898;113897;113887;113884;113873;113869;113863;113858;113855;113849;113846;113836;113833;113828;113827;113822;113811;113810;113806;113795;113788;113781;113780;113777;113775;113773;113763;113761;113748;113747;113739;113738;113734;113722;113715;113712;113694;113688;113681;113678;113677;113655;113654;113648;113647;113643;113642;113638;113634;113633;113631;113614;113611;113599;113598;113596;113595;113593;113590;113581;113576;113575;113570;113569;113566;113561;113557;113554;113551;113545;113537;113534;113531;113515;113508;113507;113505;113498;113491;113484;113483;113471;113469/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 113761, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bryan Krause", "profile_url": "https://biology.stackexchange.com/users/27148/bryan-krause", "user_type": "moderator"}, "created_at": "2024-01-02T15:06:14+00:00", "raw_file": "raw/codex_api_v1/4b76a36d403acfa9117b7f3b75e82752ff87ef3625482a25f27c7a9f24c1f834_1790824054076617800_0.json", "raw_sha256": "f49ea509a52f9f9993721157653fc6d23e3725c8e5ccf6806a681a879219d452", "revision_guid": "7724F4DB-618F-4A21-9770-32FE521A3B32", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7724F4DB-618F-4A21-9770-32FE521A3B32/view-source"}], "score": 1, "updated_at": "2024-01-02T15:06:14+00:00"}], "domain": "biology", "external_links": ["https://curiosity.britannica.com/science-of-curiosity.html", "https://en.wikipedia.org/wiki/Cnidaria", "https://en.wikipedia.org/wiki/Sponge"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:09.960411+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f3d8f52a1a12ba8e3a85266c887134296fd3686fb5ffec1a38526e2b8ccdcc24_0.json", "raw_sha256": "b1b59ebb5f220f357ffaa8464594a3d8f391df66ad06b024355499ef7eff18cb", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=8&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Hasan Zaeem", "question_author_url": "https://biology.stackexchange.com/users/78350/hasan-zaeem", "question_author_user_type": "registered", "question_created_at": "2023-12-31T07:25:03+00:00", "question_html": "I read on Britannica that all animals down to microorganisms are "information seeking", but there was no source to back up the claim.
\n\n\nOne way to begin exploring curiosity is to understand ‘information seeking’. This behavior is observable across the entire animal kingdom – from apes and dolphins all the way down to crabs and tiny nematode worms. ‘Information seeking’ means that every animal seeks information about their environment. This is so they know how to navigate it. In fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.
\n
Are there any sources or facts to support these claims?
\n", "question_id": 113761, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "I read on Britannica (https://curiosity.britannica.com/science-of-curiosity.html) that all animals down to microorganisms are \"information seeking\", but there was no source to back up the claim.\n\n\n\n\n\n\n\nOne way to begin exploring curiosity is to understand ‘information seeking’. This behavior is observable across the entire animal kingdom – from apes and dolphins all the way down to crabs and tiny nematode worms. ‘Information seeking’ means that every animal seeks information about their environment. This is so they know how to navigate it. In fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.\n\n\n\n\n\n\n\nAre there any sources or facts to support these claims?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Hasan Zaeem", "profile_url": "https://biology.stackexchange.com/users/78350/hasan-zaeem", "user_type": "registered"}, "created_at": "2023-12-31T07:25:03+00:00", "raw_file": "raw/codex_api_v1/4b76a36d403acfa9117b7f3b75e82752ff87ef3625482a25f27c7a9f24c1f834_1790824054076617800_0.json", "raw_sha256": "f49ea509a52f9f9993721157653fc6d23e3725c8e5ccf6806a681a879219d452", "revision_guid": "D18CAFF3-BE0C-47EF-8035-93B849234D5E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/D18CAFF3-BE0C-47EF-8035-93B849234D5E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Domen", "profile_url": "https://biology.stackexchange.com/users/39423/domen", "user_type": "registered"}, "created_at": "2023-12-31T23:07:57+00:00", "raw_file": "raw/codex_api_v1/4b76a36d403acfa9117b7f3b75e82752ff87ef3625482a25f27c7a9f24c1f834_1790824054076617800_0.json", "raw_sha256": "f49ea509a52f9f9993721157653fc6d23e3725c8e5ccf6806a681a879219d452", "revision_guid": "B1612E95-4FF6-4A53-A274-82E0935509B6", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B1612E95-4FF6-4A53-A274-82E0935509B6/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/113761/are-all-animals-information-seeking", "split": "validation", "split_group": "01e1d7167dd5679757e5e7c69406b0ef034ccfa46f24940d410b36edfcae5af3", "tags": ["zoology", "life", "information-theory"], "thread_id": "biology:113761", "title": "Are all animals “information seeking”?"}} {"citation_context": "k to more specific then, many animal species do not have brains. Sponges, for one; cnidarians also (https://en.wikipedia.org/wiki/Cnidaria), though they do have a nervous system they're not typically thought of as having a brain.\n\n\n\n\nSo, ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Cnidaria", "kind": "external_url", "post_id": 113769, "post_url": "https://biology.stackexchange.com/a/113769", "product": "citations", "record_id": "Scientific-Citation-Graph:9a812778c8567dbf3ff425fa", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The answer is going to entirely depend on how you define "information seeking". How do you choose to define it? If Britannica does not define what they mean by "information seeking" then that statement is not useful by itself. It's common to encounter these sorts of statements in writing targeted to a non-specialist audience. They are not meant to be taken quite so literally, they're designed to get your mind working and exploring to help you interpret the next things they're going to say. So, let's look at what else they say:
\n\n\nThis is so they know how to navigate it.
\n
Not all animals even move, so for this to make sense for "all animals" it must be a pretty broad meaning of "navigate" to be true.
\n\n\nIn fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.
\n
Every animal has some ability to sense the outside world; I'd argue that even every plant and single-celled organism does as well, this is an absolute requirement for life.
\n\n\nto supply the brain with information
\n
Well, we're back to more specific then, many animal species do not have brains. Sponges, for one; cnidarians also, though they do have a nervous system they're not typically thought of as having a brain.
\nSo, it seems that all Britannica means by "information seeking" is "somehow collect information from the outside world". That's not a very strong statement since "collecting information" can mean almost anything. But, it's also not the sort of thing anyone can prove: there could always be some hypothetical life out there that doesn't collect information but it's not anything we've found.
\n", "answer_id": 113769, "answer_text": "The answer is going to entirely depend on how you define \"information seeking\". How do you choose to define it? If Britannica does not define what they mean by \"information seeking\" then that statement is not useful by itself. It's common to encounter these sorts of statements in writing targeted to a non-specialist audience. They are not meant to be taken quite so literally, they're designed to get your mind working and exploring to help you interpret the next things they're going to say. So, let's look at what else they say:\n\n\n\n\n\n\n\nThis is so they know how to navigate it.\n\n\n\n\n\n\n\nNot all animals even move (https://en.wikipedia.org/wiki/Sponge), so for this to make sense for \"all animals\" it must be a pretty broad meaning of \"navigate\" to be true.\n\n\n\n\n\n\n\nIn fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.\n\n\n\n\n\n\n\nEvery animal has some ability to sense the outside world; I'd argue that even every plant and single-celled organism does as well, this is an absolute requirement for life.\n\n\n\n\n\n\n\nto supply the brain with information\n\n\n\n\n\n\n\nWell, we're back to more specific then, many animal species do not have brains. Sponges, for one; cnidarians also (https://en.wikipedia.org/wiki/Cnidaria), though they do have a nervous system they're not typically thought of as having a brain.\n\n\n\n\nSo, it seems that all Britannica means by \"information seeking\" is \"somehow collect information from the outside world\". That's not a very strong statement since \"collecting information\" can mean almost anything. But, it's also not the sort of thing anyone can prove: there could always be some hypothetical life out there that doesn't collect information but it's not anything we've found.", "answer_url": "https://biology.stackexchange.com/a/113769", "author": "Bryan Krause", "author_url": "https://biology.stackexchange.com/users/27148/bryan-krause", "author_user_type": "moderator", "content_license": "CC BY-SA 4.0", "created_at": "2024-01-02T15:06:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:33.526680+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/d1acc50471f82e02a014a291913995889f5ddcd7076433532102b9b97a4a3a3d_0.json", "raw_sha256": "e6b5a7d5e11f0ac54d756d69e21baee1de119b759ec7e8caa7f174d67cf80eff", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/113978;113977;113976;113967;113965;113959;113955;113947;113946;113937;113936;113924;113918;113912;113907;113904;113902;113898;113897;113887;113884;113873;113869;113863;113858;113855;113849;113846;113836;113833;113828;113827;113822;113811;113810;113806;113795;113788;113781;113780;113777;113775;113773;113763;113761;113748;113747;113739;113738;113734;113722;113715;113712;113694;113688;113681;113678;113677;113655;113654;113648;113647;113643;113642;113638;113634;113633;113631;113614;113611;113599;113598;113596;113595;113593;113590;113581;113576;113575;113570;113569;113566;113561;113557;113554;113551;113545;113537;113534;113531;113515;113508;113507;113505;113498;113491;113484;113483;113471;113469/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 113761, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bryan Krause", "profile_url": "https://biology.stackexchange.com/users/27148/bryan-krause", "user_type": "moderator"}, "created_at": "2024-01-02T15:06:14+00:00", "raw_file": "raw/codex_api_v1/4b76a36d403acfa9117b7f3b75e82752ff87ef3625482a25f27c7a9f24c1f834_1790824054076617800_0.json", "raw_sha256": "f49ea509a52f9f9993721157653fc6d23e3725c8e5ccf6806a681a879219d452", "revision_guid": "7724F4DB-618F-4A21-9770-32FE521A3B32", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7724F4DB-618F-4A21-9770-32FE521A3B32/view-source"}], "score": 1, "updated_at": "2024-01-02T15:06:14+00:00"}], "domain": "biology", "external_links": ["https://curiosity.britannica.com/science-of-curiosity.html", "https://en.wikipedia.org/wiki/Cnidaria", "https://en.wikipedia.org/wiki/Sponge"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:09.960411+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f3d8f52a1a12ba8e3a85266c887134296fd3686fb5ffec1a38526e2b8ccdcc24_0.json", "raw_sha256": "b1b59ebb5f220f357ffaa8464594a3d8f391df66ad06b024355499ef7eff18cb", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=8&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Hasan Zaeem", "question_author_url": "https://biology.stackexchange.com/users/78350/hasan-zaeem", "question_author_user_type": "registered", "question_created_at": "2023-12-31T07:25:03+00:00", "question_html": "I read on Britannica that all animals down to microorganisms are "information seeking", but there was no source to back up the claim.
\n\n\nOne way to begin exploring curiosity is to understand ‘information seeking’. This behavior is observable across the entire animal kingdom – from apes and dolphins all the way down to crabs and tiny nematode worms. ‘Information seeking’ means that every animal seeks information about their environment. This is so they know how to navigate it. In fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.
\n
Are there any sources or facts to support these claims?
\n", "question_id": 113761, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "I read on Britannica (https://curiosity.britannica.com/science-of-curiosity.html) that all animals down to microorganisms are \"information seeking\", but there was no source to back up the claim.\n\n\n\n\n\n\n\nOne way to begin exploring curiosity is to understand ‘information seeking’. This behavior is observable across the entire animal kingdom – from apes and dolphins all the way down to crabs and tiny nematode worms. ‘Information seeking’ means that every animal seeks information about their environment. This is so they know how to navigate it. In fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.\n\n\n\n\n\n\n\nAre there any sources or facts to support these claims?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Hasan Zaeem", "profile_url": "https://biology.stackexchange.com/users/78350/hasan-zaeem", "user_type": "registered"}, "created_at": "2023-12-31T07:25:03+00:00", "raw_file": "raw/codex_api_v1/4b76a36d403acfa9117b7f3b75e82752ff87ef3625482a25f27c7a9f24c1f834_1790824054076617800_0.json", "raw_sha256": "f49ea509a52f9f9993721157653fc6d23e3725c8e5ccf6806a681a879219d452", "revision_guid": "D18CAFF3-BE0C-47EF-8035-93B849234D5E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/D18CAFF3-BE0C-47EF-8035-93B849234D5E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Domen", "profile_url": "https://biology.stackexchange.com/users/39423/domen", "user_type": "registered"}, "created_at": "2023-12-31T23:07:57+00:00", "raw_file": "raw/codex_api_v1/4b76a36d403acfa9117b7f3b75e82752ff87ef3625482a25f27c7a9f24c1f834_1790824054076617800_0.json", "raw_sha256": "f49ea509a52f9f9993721157653fc6d23e3725c8e5ccf6806a681a879219d452", "revision_guid": "B1612E95-4FF6-4A53-A274-82E0935509B6", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B1612E95-4FF6-4A53-A274-82E0935509B6/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/113761/are-all-animals-information-seeking", "split": "validation", "split_group": "01e1d7167dd5679757e5e7c69406b0ef034ccfa46f24940d410b36edfcae5af3", "tags": ["zoology", "life", "information-theory"], "thread_id": "biology:113761", "title": "Are all animals “information seeking”?"}} {"citation_context": "at else they say:\n\n\n\n\n\n\n\nThis is so they know how to navigate it.\n\n\n\n\n\n\n\nNot all animals even move (https://en.wikipedia.org/wiki/Sponge), so for this to make sense for \"all animals\" it must be a pretty broad meaning of \"navigate\" to be", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Sponge", "kind": "external_url", "post_id": 113769, "post_url": "https://biology.stackexchange.com/a/113769", "product": "citations", "record_id": "Scientific-Citation-Graph:0eea889bbc1c20054a62107b", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The answer is going to entirely depend on how you define "information seeking". How do you choose to define it? If Britannica does not define what they mean by "information seeking" then that statement is not useful by itself. It's common to encounter these sorts of statements in writing targeted to a non-specialist audience. They are not meant to be taken quite so literally, they're designed to get your mind working and exploring to help you interpret the next things they're going to say. So, let's look at what else they say:
\n\n\nThis is so they know how to navigate it.
\n
Not all animals even move, so for this to make sense for "all animals" it must be a pretty broad meaning of "navigate" to be true.
\n\n\nIn fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.
\n
Every animal has some ability to sense the outside world; I'd argue that even every plant and single-celled organism does as well, this is an absolute requirement for life.
\n\n\nto supply the brain with information
\n
Well, we're back to more specific then, many animal species do not have brains. Sponges, for one; cnidarians also, though they do have a nervous system they're not typically thought of as having a brain.
\nSo, it seems that all Britannica means by "information seeking" is "somehow collect information from the outside world". That's not a very strong statement since "collecting information" can mean almost anything. But, it's also not the sort of thing anyone can prove: there could always be some hypothetical life out there that doesn't collect information but it's not anything we've found.
\n", "answer_id": 113769, "answer_text": "The answer is going to entirely depend on how you define \"information seeking\". How do you choose to define it? If Britannica does not define what they mean by \"information seeking\" then that statement is not useful by itself. It's common to encounter these sorts of statements in writing targeted to a non-specialist audience. They are not meant to be taken quite so literally, they're designed to get your mind working and exploring to help you interpret the next things they're going to say. So, let's look at what else they say:\n\n\n\n\n\n\n\nThis is so they know how to navigate it.\n\n\n\n\n\n\n\nNot all animals even move (https://en.wikipedia.org/wiki/Sponge), so for this to make sense for \"all animals\" it must be a pretty broad meaning of \"navigate\" to be true.\n\n\n\n\n\n\n\nIn fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.\n\n\n\n\n\n\n\nEvery animal has some ability to sense the outside world; I'd argue that even every plant and single-celled organism does as well, this is an absolute requirement for life.\n\n\n\n\n\n\n\nto supply the brain with information\n\n\n\n\n\n\n\nWell, we're back to more specific then, many animal species do not have brains. Sponges, for one; cnidarians also (https://en.wikipedia.org/wiki/Cnidaria), though they do have a nervous system they're not typically thought of as having a brain.\n\n\n\n\nSo, it seems that all Britannica means by \"information seeking\" is \"somehow collect information from the outside world\". That's not a very strong statement since \"collecting information\" can mean almost anything. But, it's also not the sort of thing anyone can prove: there could always be some hypothetical life out there that doesn't collect information but it's not anything we've found.", "answer_url": "https://biology.stackexchange.com/a/113769", "author": "Bryan Krause", "author_url": "https://biology.stackexchange.com/users/27148/bryan-krause", "author_user_type": "moderator", "content_license": "CC BY-SA 4.0", "created_at": "2024-01-02T15:06:14+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:33.526680+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/d1acc50471f82e02a014a291913995889f5ddcd7076433532102b9b97a4a3a3d_0.json", "raw_sha256": "e6b5a7d5e11f0ac54d756d69e21baee1de119b759ec7e8caa7f174d67cf80eff", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/113978;113977;113976;113967;113965;113959;113955;113947;113946;113937;113936;113924;113918;113912;113907;113904;113902;113898;113897;113887;113884;113873;113869;113863;113858;113855;113849;113846;113836;113833;113828;113827;113822;113811;113810;113806;113795;113788;113781;113780;113777;113775;113773;113763;113761;113748;113747;113739;113738;113734;113722;113715;113712;113694;113688;113681;113678;113677;113655;113654;113648;113647;113643;113642;113638;113634;113633;113631;113614;113611;113599;113598;113596;113595;113593;113590;113581;113576;113575;113570;113569;113566;113561;113557;113554;113551;113545;113537;113534;113531;113515;113508;113507;113505;113498;113491;113484;113483;113471;113469/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 113761, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Bryan Krause", "profile_url": "https://biology.stackexchange.com/users/27148/bryan-krause", "user_type": "moderator"}, "created_at": "2024-01-02T15:06:14+00:00", "raw_file": "raw/codex_api_v1/4b76a36d403acfa9117b7f3b75e82752ff87ef3625482a25f27c7a9f24c1f834_1790824054076617800_0.json", "raw_sha256": "f49ea509a52f9f9993721157653fc6d23e3725c8e5ccf6806a681a879219d452", "revision_guid": "7724F4DB-618F-4A21-9770-32FE521A3B32", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7724F4DB-618F-4A21-9770-32FE521A3B32/view-source"}], "score": 1, "updated_at": "2024-01-02T15:06:14+00:00"}], "domain": "biology", "external_links": ["https://curiosity.britannica.com/science-of-curiosity.html", "https://en.wikipedia.org/wiki/Cnidaria", "https://en.wikipedia.org/wiki/Sponge"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:09.960411+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f3d8f52a1a12ba8e3a85266c887134296fd3686fb5ffec1a38526e2b8ccdcc24_0.json", "raw_sha256": "b1b59ebb5f220f357ffaa8464594a3d8f391df66ad06b024355499ef7eff18cb", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=8&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Hasan Zaeem", "question_author_url": "https://biology.stackexchange.com/users/78350/hasan-zaeem", "question_author_user_type": "registered", "question_created_at": "2023-12-31T07:25:03+00:00", "question_html": "I read on Britannica that all animals down to microorganisms are "information seeking", but there was no source to back up the claim.
\n\n\nOne way to begin exploring curiosity is to understand ‘information seeking’. This behavior is observable across the entire animal kingdom – from apes and dolphins all the way down to crabs and tiny nematode worms. ‘Information seeking’ means that every animal seeks information about their environment. This is so they know how to navigate it. In fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.
\n
Are there any sources or facts to support these claims?
\n", "question_id": 113761, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "I read on Britannica (https://curiosity.britannica.com/science-of-curiosity.html) that all animals down to microorganisms are \"information seeking\", but there was no source to back up the claim.\n\n\n\n\n\n\n\nOne way to begin exploring curiosity is to understand ‘information seeking’. This behavior is observable across the entire animal kingdom – from apes and dolphins all the way down to crabs and tiny nematode worms. ‘Information seeking’ means that every animal seeks information about their environment. This is so they know how to navigate it. In fact, it’s why sensory organs exist – to supply the brain with information that helps you understand your environment and make better choices.\n\n\n\n\n\n\n\nAre there any sources or facts to support these claims?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Hasan Zaeem", "profile_url": "https://biology.stackexchange.com/users/78350/hasan-zaeem", "user_type": "registered"}, "created_at": "2023-12-31T07:25:03+00:00", "raw_file": "raw/codex_api_v1/4b76a36d403acfa9117b7f3b75e82752ff87ef3625482a25f27c7a9f24c1f834_1790824054076617800_0.json", "raw_sha256": "f49ea509a52f9f9993721157653fc6d23e3725c8e5ccf6806a681a879219d452", "revision_guid": "D18CAFF3-BE0C-47EF-8035-93B849234D5E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/D18CAFF3-BE0C-47EF-8035-93B849234D5E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Domen", "profile_url": "https://biology.stackexchange.com/users/39423/domen", "user_type": "registered"}, "created_at": "2023-12-31T23:07:57+00:00", "raw_file": "raw/codex_api_v1/4b76a36d403acfa9117b7f3b75e82752ff87ef3625482a25f27c7a9f24c1f834_1790824054076617800_0.json", "raw_sha256": "f49ea509a52f9f9993721157653fc6d23e3725c8e5ccf6806a681a879219d452", "revision_guid": "B1612E95-4FF6-4A53-A274-82E0935509B6", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B1612E95-4FF6-4A53-A274-82E0935509B6/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/113761/are-all-animals-information-seeking", "split": "validation", "split_group": "01e1d7167dd5679757e5e7c69406b0ef034ccfa46f24940d410b36edfcae5af3", "tags": ["zoology", "life", "information-theory"], "thread_id": "biology:113761", "title": "Are all animals “information seeking”?"}} {"citation_context": "ugh some of these will require library access to journals. A 2016 review in Trends in Cell Biology (http://dx.doi.org/10.1016/j.tcb.2015.11.002) provides several referenced examples and makes the proposal that autocrine signalling is in some c", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": "10.1016/j.tcb.2015.11.002", "external_url": "http://dx.doi.org/10.1016/j.tcb.2015.11.002", "kind": "doi_url", "post_id": 116460, "post_url": "https://biology.stackexchange.com/a/116460", "product": "citations", "record_id": "Scientific-Citation-Graph:faaeb5745d5971436b839442", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The Wikipedia entry for ‘Hormone’ indicates two signalling types of hormone that fall into this category.
\n\n\nAutocrine: Affects the cell types that secreted it and causes a biological effect.
\nIntracrine: Acts intracellularly on the cells that synthesized it.
\n
The key difference is that autocrine signalling involves the hormone being secreted from the cell, whereas in intracrine signalling the hormone is not.
\nIt would appear that the question relates more to autocrine signalling, in which case (again from the Wikipedia entry) examples include:
\ncytokine interleukin-1 in monocytes
\ninterleukin-2 in T cell lymphocytes
\nGlancing through the rest of the article it would appear that autocrine signalling is most common in the class of hormone known as growth factors rather than the more well-known earlier discovered types such as insulin and testosterone which are classified as being involved in endocrine signalling.
\nFor further information — and considerations of the rationale of autocrine signalling systems — the reader should consult more authoritative sources than Wikipedia, although some of these will require library access to journals. A 2016 review in Trends in Cell Biology provides several referenced examples and makes the proposal that autocrine signalling is in some cases analogous to quorum sensing in bacteria. This seems to be similar to the point made by @BrianKrause in a comment — that autocrine signalling can be a way of getting cells and their neighbours to respond in a co-ordinated manner.
\nBrian also makes the point that “there are examples of autocrine signaling where if there is high activity among a group of neurons releasing the same neurotransmitter, the same neurotransmitter inhibits themselves and others of the same type through auto-receptors.”
\nAlthough this is not my field, I would venture to suggest that in other circumstances autocrine signalling may be a means of initiating the division of the secreting cells. The secretion of growth-factor (or presence/strength of receptors) may not be a continuous or recurring event, but a single event in response to an external stimulus at some stage in cellular development.
\n", "answer_id": 116460, "answer_text": "The Wikipedia entry for ‘Hormone’ (https://en.wikipedia.org/wiki/Hormone) indicates two signalling types of hormone that fall into this category.\n\n\n\n\n\n\n\nAutocrine: Affects the cell types that secreted it and causes a biological effect.\n\n\n\n\nIntracrine: Acts intracellularly on the cells that synthesized it.\n\n\n\n\n\n\n\nThe key difference is that autocrine signalling involves the hormone being secreted from the cell, whereas in intracrine signalling the hormone is not.\n\n\n\n\nIt would appear that the question relates more to autocrine signalling, in which case (again from the Wikipedia entry (https://en.wikipedia.org/wiki/Autocrine_signaling)) examples include:\n\n\n\n\n\n\n\ncytokine interleukin-1 in monocytes\n\n\n\n\n\n\n\n\n\ninterleukin-2 in T cell lymphocytes\n\n\n\n\n\n\n\n\nGlancing through the rest of the article it would appear that autocrine signalling is most common in the class of hormone known as growth factors (https://en.wikipedia.org/wiki/Growth_factor) rather than the more well-known earlier discovered types such as insulin and testosterone which are classified as being involved in endocrine signalling.\n\n\n\n\nFor further information — and considerations of the rationale of autocrine signalling systems — the reader should consult more authoritative sources than Wikipedia, although some of these will require library access to journals. A 2016 review in Trends in Cell Biology (http://dx.doi.org/10.1016/j.tcb.2015.11.002) provides several referenced examples and makes the proposal that autocrine signalling is in some cases analogous to quorum sensing in bacteria. This seems to be similar to the point made by @BrianKrause in a comment — that autocrine signalling can be a way of getting cells and their neighbours to respond in a co-ordinated manner.\n\n\n\n\nBrian also makes the point that “there are examples of autocrine signaling where if there is high activity among a group of neurons releasing the same neurotransmitter, the same neurotransmitter inhibits themselves and others of the same type through auto-receptors.”\n\n\n\n\nAlthough this is not my field, I would venture to suggest that in other circumstances autocrine signalling may be a means of initiating the division of the secreting cells. The secretion of growth-factor (or presence/strength of receptors) may not be a continuous or recurring event, but a single event in response to an external stimulus at some stage in cellular development.", "answer_url": "https://biology.stackexchange.com/a/116460", "author": "David", "author_url": "https://biology.stackexchange.com/users/22057/david", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-05-07T15:09:45+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:19.947691+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/df693642d727b738d2a533740632235c18a06cefec7a1e337c9589214a4ec91e_0.json", "raw_sha256": "9df534f437f3b2f12d33db8536999ec4e6ffa10f2f59394799d9fe01c3c1ad16", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/117606;117602;117598;117594;117585;117579;117570;117568;117565;117559;117558;117555;117552;117548;117538;117524;117523;117522;117520;117515;117510;116509;116508;116504;116499;116491;116485;116483;116461;116454;116453;116445;116441;116435;116430;116426;116425;116414;116412;116406;116401;116399;116396;116395;116394;116392;116389;116384;116370;116367;116363;116361;116352;116351;116347;116345;116343;116338;116337;116332;116331;116324;116320;116316;116314;116312;116306;116292;116290;116284;116280;116277;116271;116270;116268;116267;116257;116256;116253;116250;116249;116240;116237;116233;116219;116214;116212;116205;116204;116200;116198;116187;116184;116173;116172;116167;116162;116149;116142;116129/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 116453, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-07T15:09:45+00:00", "raw_file": "raw/codex_api_v1/44a668e829ce1e5d355c0dcd71925c16fb650d744ddea539b26c827698be07fc_1790824147175909500_0.json", "raw_sha256": "cacbff1e3cd30ece568cbed70e415ee7bb13ad0f92e723966430c45bae70706a", "revision_guid": "5DD38544-77C2-4D73-ACC9-D4F03C30B469", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/5DD38544-77C2-4D73-ACC9-D4F03C30B469/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-08T09:58:51+00:00", "raw_file": "raw/codex_api_v1/513f34509ea5b8cfd23e2c22ec69b0af899072a5df884318581dc59cdc06558f_1790824145019083900_0.json", "raw_sha256": "e49bc4b696ee886e85729b5e43d509e97eb936a63dd33019b0855e8f32360f99", "revision_guid": "71147A40-BE42-4C8B-B7D8-7AAD0200B62C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/71147A40-BE42-4C8B-B7D8-7AAD0200B62C/view-source"}], "score": 5, "updated_at": "2025-05-08T09:58:51+00:00"}], "domain": "biology", "external_links": ["http://dx.doi.org/10.1016/j.tcb.2015.11.002", "https://en.wikipedia.org/wiki/Autocrine_signaling", "https://en.wikipedia.org/wiki/Growth_factor", "https://en.wikipedia.org/wiki/Hormone"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:02.598621+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/5d480e4bd1bd45ab525a4baf3227fba404f89b6af9dad33215fd9fa7c302a211_0.json", "raw_sha256": "d723c7a62c8386d143891d26ae30b2234242ed3dac9599b11f141712ea994a96", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=3&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "youthdoo", "question_author_url": "https://biology.stackexchange.com/users/105597/youthdoo", "question_author_user_type": "registered", "question_created_at": "2025-05-07T07:17:25+00:00", "question_html": "In the human body, does there exist a cell that can produce a hormone, such that the receptor of that hormone is on that cell?
\nNormally, hormones are produced by endocrine glands, and they affect the target cell by combining with a specific receptor. It would seem strange if the receptor is on the producer cell, but I would like to know whether there are any known examples of this,
\n", "question_id": 116453, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "In the human body, does there exist a cell that can produce a hormone, such that the receptor of that hormone is on that cell?\n\n\n\n\nNormally, hormones are produced by endocrine glands, and they affect the target cell by combining with a specific receptor. It would seem strange if the receptor is on the producer cell, but I would like to know whether there are any known examples of this,", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "youthdoo", "profile_url": "https://biology.stackexchange.com/users/105597/youthdoo", "user_type": "registered"}, "created_at": "2025-05-07T07:17:25+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "4AA8C058-3998-4C7E-A17D-7AB40398E354", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AA8C058-3998-4C7E-A17D-7AB40398E354/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-07T14:44:18+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "8F835600-2115-4953-A9F0-951E9AD9747F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/8F835600-2115-4953-A9F0-951E9AD9747F/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2025-05-07T15:48:25+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "C79C7805-DB3F-4C11-8327-490D7239DB4B", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/C79C7805-DB3F-4C11-8327-490D7239DB4B/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/116453/is-there-a-cell-that-produces-a-hormone-that-acts-on-the-same-type-of-cell", "split": "validation", "split_group": "f9d2c2a40e13040840b8ff52274661f3319531d81d7b9453056f67cbcd6b7b1b", "tags": ["human-biology", "cell-biology", "endocrinology"], "thread_id": "biology:116453", "title": "Is there a cell that produces a hormone that acts on the same type of cell"}} {"citation_context": "t the question relates more to autocrine signalling, in which case (again from the Wikipedia entry (https://en.wikipedia.org/wiki/Autocrine_signaling)) examples include:\n\n\n\n\n\n\n\ncytokine interleukin-1 in monocytes\n\n\n\n\n\n\n\n\n\ninterleukin-2 in T cell lym", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Autocrine_signaling", "kind": "external_url", "post_id": 116460, "post_url": "https://biology.stackexchange.com/a/116460", "product": "citations", "record_id": "Scientific-Citation-Graph:691b4ebb9f627949781e30c5", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The Wikipedia entry for ‘Hormone’ indicates two signalling types of hormone that fall into this category.
\n\n\nAutocrine: Affects the cell types that secreted it and causes a biological effect.
\nIntracrine: Acts intracellularly on the cells that synthesized it.
\n
The key difference is that autocrine signalling involves the hormone being secreted from the cell, whereas in intracrine signalling the hormone is not.
\nIt would appear that the question relates more to autocrine signalling, in which case (again from the Wikipedia entry) examples include:
\ncytokine interleukin-1 in monocytes
\ninterleukin-2 in T cell lymphocytes
\nGlancing through the rest of the article it would appear that autocrine signalling is most common in the class of hormone known as growth factors rather than the more well-known earlier discovered types such as insulin and testosterone which are classified as being involved in endocrine signalling.
\nFor further information — and considerations of the rationale of autocrine signalling systems — the reader should consult more authoritative sources than Wikipedia, although some of these will require library access to journals. A 2016 review in Trends in Cell Biology provides several referenced examples and makes the proposal that autocrine signalling is in some cases analogous to quorum sensing in bacteria. This seems to be similar to the point made by @BrianKrause in a comment — that autocrine signalling can be a way of getting cells and their neighbours to respond in a co-ordinated manner.
\nBrian also makes the point that “there are examples of autocrine signaling where if there is high activity among a group of neurons releasing the same neurotransmitter, the same neurotransmitter inhibits themselves and others of the same type through auto-receptors.”
\nAlthough this is not my field, I would venture to suggest that in other circumstances autocrine signalling may be a means of initiating the division of the secreting cells. The secretion of growth-factor (or presence/strength of receptors) may not be a continuous or recurring event, but a single event in response to an external stimulus at some stage in cellular development.
\n", "answer_id": 116460, "answer_text": "The Wikipedia entry for ‘Hormone’ (https://en.wikipedia.org/wiki/Hormone) indicates two signalling types of hormone that fall into this category.\n\n\n\n\n\n\n\nAutocrine: Affects the cell types that secreted it and causes a biological effect.\n\n\n\n\nIntracrine: Acts intracellularly on the cells that synthesized it.\n\n\n\n\n\n\n\nThe key difference is that autocrine signalling involves the hormone being secreted from the cell, whereas in intracrine signalling the hormone is not.\n\n\n\n\nIt would appear that the question relates more to autocrine signalling, in which case (again from the Wikipedia entry (https://en.wikipedia.org/wiki/Autocrine_signaling)) examples include:\n\n\n\n\n\n\n\ncytokine interleukin-1 in monocytes\n\n\n\n\n\n\n\n\n\ninterleukin-2 in T cell lymphocytes\n\n\n\n\n\n\n\n\nGlancing through the rest of the article it would appear that autocrine signalling is most common in the class of hormone known as growth factors (https://en.wikipedia.org/wiki/Growth_factor) rather than the more well-known earlier discovered types such as insulin and testosterone which are classified as being involved in endocrine signalling.\n\n\n\n\nFor further information — and considerations of the rationale of autocrine signalling systems — the reader should consult more authoritative sources than Wikipedia, although some of these will require library access to journals. A 2016 review in Trends in Cell Biology (http://dx.doi.org/10.1016/j.tcb.2015.11.002) provides several referenced examples and makes the proposal that autocrine signalling is in some cases analogous to quorum sensing in bacteria. This seems to be similar to the point made by @BrianKrause in a comment — that autocrine signalling can be a way of getting cells and their neighbours to respond in a co-ordinated manner.\n\n\n\n\nBrian also makes the point that “there are examples of autocrine signaling where if there is high activity among a group of neurons releasing the same neurotransmitter, the same neurotransmitter inhibits themselves and others of the same type through auto-receptors.”\n\n\n\n\nAlthough this is not my field, I would venture to suggest that in other circumstances autocrine signalling may be a means of initiating the division of the secreting cells. The secretion of growth-factor (or presence/strength of receptors) may not be a continuous or recurring event, but a single event in response to an external stimulus at some stage in cellular development.", "answer_url": "https://biology.stackexchange.com/a/116460", "author": "David", "author_url": "https://biology.stackexchange.com/users/22057/david", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-05-07T15:09:45+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:19.947691+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/df693642d727b738d2a533740632235c18a06cefec7a1e337c9589214a4ec91e_0.json", "raw_sha256": "9df534f437f3b2f12d33db8536999ec4e6ffa10f2f59394799d9fe01c3c1ad16", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/117606;117602;117598;117594;117585;117579;117570;117568;117565;117559;117558;117555;117552;117548;117538;117524;117523;117522;117520;117515;117510;116509;116508;116504;116499;116491;116485;116483;116461;116454;116453;116445;116441;116435;116430;116426;116425;116414;116412;116406;116401;116399;116396;116395;116394;116392;116389;116384;116370;116367;116363;116361;116352;116351;116347;116345;116343;116338;116337;116332;116331;116324;116320;116316;116314;116312;116306;116292;116290;116284;116280;116277;116271;116270;116268;116267;116257;116256;116253;116250;116249;116240;116237;116233;116219;116214;116212;116205;116204;116200;116198;116187;116184;116173;116172;116167;116162;116149;116142;116129/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 116453, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-07T15:09:45+00:00", "raw_file": "raw/codex_api_v1/44a668e829ce1e5d355c0dcd71925c16fb650d744ddea539b26c827698be07fc_1790824147175909500_0.json", "raw_sha256": "cacbff1e3cd30ece568cbed70e415ee7bb13ad0f92e723966430c45bae70706a", "revision_guid": "5DD38544-77C2-4D73-ACC9-D4F03C30B469", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/5DD38544-77C2-4D73-ACC9-D4F03C30B469/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-08T09:58:51+00:00", "raw_file": "raw/codex_api_v1/513f34509ea5b8cfd23e2c22ec69b0af899072a5df884318581dc59cdc06558f_1790824145019083900_0.json", "raw_sha256": "e49bc4b696ee886e85729b5e43d509e97eb936a63dd33019b0855e8f32360f99", "revision_guid": "71147A40-BE42-4C8B-B7D8-7AAD0200B62C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/71147A40-BE42-4C8B-B7D8-7AAD0200B62C/view-source"}], "score": 5, "updated_at": "2025-05-08T09:58:51+00:00"}], "domain": "biology", "external_links": ["http://dx.doi.org/10.1016/j.tcb.2015.11.002", "https://en.wikipedia.org/wiki/Autocrine_signaling", "https://en.wikipedia.org/wiki/Growth_factor", "https://en.wikipedia.org/wiki/Hormone"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:02.598621+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/5d480e4bd1bd45ab525a4baf3227fba404f89b6af9dad33215fd9fa7c302a211_0.json", "raw_sha256": "d723c7a62c8386d143891d26ae30b2234242ed3dac9599b11f141712ea994a96", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=3&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "youthdoo", "question_author_url": "https://biology.stackexchange.com/users/105597/youthdoo", "question_author_user_type": "registered", "question_created_at": "2025-05-07T07:17:25+00:00", "question_html": "In the human body, does there exist a cell that can produce a hormone, such that the receptor of that hormone is on that cell?
\nNormally, hormones are produced by endocrine glands, and they affect the target cell by combining with a specific receptor. It would seem strange if the receptor is on the producer cell, but I would like to know whether there are any known examples of this,
\n", "question_id": 116453, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "In the human body, does there exist a cell that can produce a hormone, such that the receptor of that hormone is on that cell?\n\n\n\n\nNormally, hormones are produced by endocrine glands, and they affect the target cell by combining with a specific receptor. It would seem strange if the receptor is on the producer cell, but I would like to know whether there are any known examples of this,", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "youthdoo", "profile_url": "https://biology.stackexchange.com/users/105597/youthdoo", "user_type": "registered"}, "created_at": "2025-05-07T07:17:25+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "4AA8C058-3998-4C7E-A17D-7AB40398E354", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AA8C058-3998-4C7E-A17D-7AB40398E354/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-07T14:44:18+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "8F835600-2115-4953-A9F0-951E9AD9747F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/8F835600-2115-4953-A9F0-951E9AD9747F/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2025-05-07T15:48:25+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "C79C7805-DB3F-4C11-8327-490D7239DB4B", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/C79C7805-DB3F-4C11-8327-490D7239DB4B/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/116453/is-there-a-cell-that-produces-a-hormone-that-acts-on-the-same-type-of-cell", "split": "validation", "split_group": "f9d2c2a40e13040840b8ff52274661f3319531d81d7b9453056f67cbcd6b7b1b", "tags": ["human-biology", "cell-biology", "endocrinology"], "thread_id": "biology:116453", "title": "Is there a cell that produces a hormone that acts on the same type of cell"}} {"citation_context": "ld appear that autocrine signalling is most common in the class of hormone known as growth factors (https://en.wikipedia.org/wiki/Growth_factor) rather than the more well-known earlier discovered types such as insulin and testosterone which ar", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Growth_factor", "kind": "external_url", "post_id": 116460, "post_url": "https://biology.stackexchange.com/a/116460", "product": "citations", "record_id": "Scientific-Citation-Graph:b7d9c710ae457e12f929c498", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The Wikipedia entry for ‘Hormone’ indicates two signalling types of hormone that fall into this category.
\n\n\nAutocrine: Affects the cell types that secreted it and causes a biological effect.
\nIntracrine: Acts intracellularly on the cells that synthesized it.
\n
The key difference is that autocrine signalling involves the hormone being secreted from the cell, whereas in intracrine signalling the hormone is not.
\nIt would appear that the question relates more to autocrine signalling, in which case (again from the Wikipedia entry) examples include:
\ncytokine interleukin-1 in monocytes
\ninterleukin-2 in T cell lymphocytes
\nGlancing through the rest of the article it would appear that autocrine signalling is most common in the class of hormone known as growth factors rather than the more well-known earlier discovered types such as insulin and testosterone which are classified as being involved in endocrine signalling.
\nFor further information — and considerations of the rationale of autocrine signalling systems — the reader should consult more authoritative sources than Wikipedia, although some of these will require library access to journals. A 2016 review in Trends in Cell Biology provides several referenced examples and makes the proposal that autocrine signalling is in some cases analogous to quorum sensing in bacteria. This seems to be similar to the point made by @BrianKrause in a comment — that autocrine signalling can be a way of getting cells and their neighbours to respond in a co-ordinated manner.
\nBrian also makes the point that “there are examples of autocrine signaling where if there is high activity among a group of neurons releasing the same neurotransmitter, the same neurotransmitter inhibits themselves and others of the same type through auto-receptors.”
\nAlthough this is not my field, I would venture to suggest that in other circumstances autocrine signalling may be a means of initiating the division of the secreting cells. The secretion of growth-factor (or presence/strength of receptors) may not be a continuous or recurring event, but a single event in response to an external stimulus at some stage in cellular development.
\n", "answer_id": 116460, "answer_text": "The Wikipedia entry for ‘Hormone’ (https://en.wikipedia.org/wiki/Hormone) indicates two signalling types of hormone that fall into this category.\n\n\n\n\n\n\n\nAutocrine: Affects the cell types that secreted it and causes a biological effect.\n\n\n\n\nIntracrine: Acts intracellularly on the cells that synthesized it.\n\n\n\n\n\n\n\nThe key difference is that autocrine signalling involves the hormone being secreted from the cell, whereas in intracrine signalling the hormone is not.\n\n\n\n\nIt would appear that the question relates more to autocrine signalling, in which case (again from the Wikipedia entry (https://en.wikipedia.org/wiki/Autocrine_signaling)) examples include:\n\n\n\n\n\n\n\ncytokine interleukin-1 in monocytes\n\n\n\n\n\n\n\n\n\ninterleukin-2 in T cell lymphocytes\n\n\n\n\n\n\n\n\nGlancing through the rest of the article it would appear that autocrine signalling is most common in the class of hormone known as growth factors (https://en.wikipedia.org/wiki/Growth_factor) rather than the more well-known earlier discovered types such as insulin and testosterone which are classified as being involved in endocrine signalling.\n\n\n\n\nFor further information — and considerations of the rationale of autocrine signalling systems — the reader should consult more authoritative sources than Wikipedia, although some of these will require library access to journals. A 2016 review in Trends in Cell Biology (http://dx.doi.org/10.1016/j.tcb.2015.11.002) provides several referenced examples and makes the proposal that autocrine signalling is in some cases analogous to quorum sensing in bacteria. This seems to be similar to the point made by @BrianKrause in a comment — that autocrine signalling can be a way of getting cells and their neighbours to respond in a co-ordinated manner.\n\n\n\n\nBrian also makes the point that “there are examples of autocrine signaling where if there is high activity among a group of neurons releasing the same neurotransmitter, the same neurotransmitter inhibits themselves and others of the same type through auto-receptors.”\n\n\n\n\nAlthough this is not my field, I would venture to suggest that in other circumstances autocrine signalling may be a means of initiating the division of the secreting cells. The secretion of growth-factor (or presence/strength of receptors) may not be a continuous or recurring event, but a single event in response to an external stimulus at some stage in cellular development.", "answer_url": "https://biology.stackexchange.com/a/116460", "author": "David", "author_url": "https://biology.stackexchange.com/users/22057/david", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-05-07T15:09:45+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:19.947691+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/df693642d727b738d2a533740632235c18a06cefec7a1e337c9589214a4ec91e_0.json", "raw_sha256": "9df534f437f3b2f12d33db8536999ec4e6ffa10f2f59394799d9fe01c3c1ad16", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/117606;117602;117598;117594;117585;117579;117570;117568;117565;117559;117558;117555;117552;117548;117538;117524;117523;117522;117520;117515;117510;116509;116508;116504;116499;116491;116485;116483;116461;116454;116453;116445;116441;116435;116430;116426;116425;116414;116412;116406;116401;116399;116396;116395;116394;116392;116389;116384;116370;116367;116363;116361;116352;116351;116347;116345;116343;116338;116337;116332;116331;116324;116320;116316;116314;116312;116306;116292;116290;116284;116280;116277;116271;116270;116268;116267;116257;116256;116253;116250;116249;116240;116237;116233;116219;116214;116212;116205;116204;116200;116198;116187;116184;116173;116172;116167;116162;116149;116142;116129/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 116453, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-07T15:09:45+00:00", "raw_file": "raw/codex_api_v1/44a668e829ce1e5d355c0dcd71925c16fb650d744ddea539b26c827698be07fc_1790824147175909500_0.json", "raw_sha256": "cacbff1e3cd30ece568cbed70e415ee7bb13ad0f92e723966430c45bae70706a", "revision_guid": "5DD38544-77C2-4D73-ACC9-D4F03C30B469", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/5DD38544-77C2-4D73-ACC9-D4F03C30B469/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-08T09:58:51+00:00", "raw_file": "raw/codex_api_v1/513f34509ea5b8cfd23e2c22ec69b0af899072a5df884318581dc59cdc06558f_1790824145019083900_0.json", "raw_sha256": "e49bc4b696ee886e85729b5e43d509e97eb936a63dd33019b0855e8f32360f99", "revision_guid": "71147A40-BE42-4C8B-B7D8-7AAD0200B62C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/71147A40-BE42-4C8B-B7D8-7AAD0200B62C/view-source"}], "score": 5, "updated_at": "2025-05-08T09:58:51+00:00"}], "domain": "biology", "external_links": ["http://dx.doi.org/10.1016/j.tcb.2015.11.002", "https://en.wikipedia.org/wiki/Autocrine_signaling", "https://en.wikipedia.org/wiki/Growth_factor", "https://en.wikipedia.org/wiki/Hormone"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:02.598621+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/5d480e4bd1bd45ab525a4baf3227fba404f89b6af9dad33215fd9fa7c302a211_0.json", "raw_sha256": "d723c7a62c8386d143891d26ae30b2234242ed3dac9599b11f141712ea994a96", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=3&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "youthdoo", "question_author_url": "https://biology.stackexchange.com/users/105597/youthdoo", "question_author_user_type": "registered", "question_created_at": "2025-05-07T07:17:25+00:00", "question_html": "In the human body, does there exist a cell that can produce a hormone, such that the receptor of that hormone is on that cell?
\nNormally, hormones are produced by endocrine glands, and they affect the target cell by combining with a specific receptor. It would seem strange if the receptor is on the producer cell, but I would like to know whether there are any known examples of this,
\n", "question_id": 116453, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "In the human body, does there exist a cell that can produce a hormone, such that the receptor of that hormone is on that cell?\n\n\n\n\nNormally, hormones are produced by endocrine glands, and they affect the target cell by combining with a specific receptor. It would seem strange if the receptor is on the producer cell, but I would like to know whether there are any known examples of this,", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "youthdoo", "profile_url": "https://biology.stackexchange.com/users/105597/youthdoo", "user_type": "registered"}, "created_at": "2025-05-07T07:17:25+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "4AA8C058-3998-4C7E-A17D-7AB40398E354", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AA8C058-3998-4C7E-A17D-7AB40398E354/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-07T14:44:18+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "8F835600-2115-4953-A9F0-951E9AD9747F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/8F835600-2115-4953-A9F0-951E9AD9747F/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2025-05-07T15:48:25+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "C79C7805-DB3F-4C11-8327-490D7239DB4B", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/C79C7805-DB3F-4C11-8327-490D7239DB4B/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/116453/is-there-a-cell-that-produces-a-hormone-that-acts-on-the-same-type-of-cell", "split": "validation", "split_group": "f9d2c2a40e13040840b8ff52274661f3319531d81d7b9453056f67cbcd6b7b1b", "tags": ["human-biology", "cell-biology", "endocrinology"], "thread_id": "biology:116453", "title": "Is there a cell that produces a hormone that acts on the same type of cell"}} {"citation_context": "The Wikipedia entry for ‘Hormone’ (https://en.wikipedia.org/wiki/Hormone) indicates two signalling types of hormone that fall into this category.\n\n\n\n\n\n\n\nAutocrine: Affects ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Hormone", "kind": "external_url", "post_id": 116460, "post_url": "https://biology.stackexchange.com/a/116460", "product": "citations", "record_id": "Scientific-Citation-Graph:b2fadfad26e5cdb2a978b184", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "The Wikipedia entry for ‘Hormone’ indicates two signalling types of hormone that fall into this category.
\n\n\nAutocrine: Affects the cell types that secreted it and causes a biological effect.
\nIntracrine: Acts intracellularly on the cells that synthesized it.
\n
The key difference is that autocrine signalling involves the hormone being secreted from the cell, whereas in intracrine signalling the hormone is not.
\nIt would appear that the question relates more to autocrine signalling, in which case (again from the Wikipedia entry) examples include:
\ncytokine interleukin-1 in monocytes
\ninterleukin-2 in T cell lymphocytes
\nGlancing through the rest of the article it would appear that autocrine signalling is most common in the class of hormone known as growth factors rather than the more well-known earlier discovered types such as insulin and testosterone which are classified as being involved in endocrine signalling.
\nFor further information — and considerations of the rationale of autocrine signalling systems — the reader should consult more authoritative sources than Wikipedia, although some of these will require library access to journals. A 2016 review in Trends in Cell Biology provides several referenced examples and makes the proposal that autocrine signalling is in some cases analogous to quorum sensing in bacteria. This seems to be similar to the point made by @BrianKrause in a comment — that autocrine signalling can be a way of getting cells and their neighbours to respond in a co-ordinated manner.
\nBrian also makes the point that “there are examples of autocrine signaling where if there is high activity among a group of neurons releasing the same neurotransmitter, the same neurotransmitter inhibits themselves and others of the same type through auto-receptors.”
\nAlthough this is not my field, I would venture to suggest that in other circumstances autocrine signalling may be a means of initiating the division of the secreting cells. The secretion of growth-factor (or presence/strength of receptors) may not be a continuous or recurring event, but a single event in response to an external stimulus at some stage in cellular development.
\n", "answer_id": 116460, "answer_text": "The Wikipedia entry for ‘Hormone’ (https://en.wikipedia.org/wiki/Hormone) indicates two signalling types of hormone that fall into this category.\n\n\n\n\n\n\n\nAutocrine: Affects the cell types that secreted it and causes a biological effect.\n\n\n\n\nIntracrine: Acts intracellularly on the cells that synthesized it.\n\n\n\n\n\n\n\nThe key difference is that autocrine signalling involves the hormone being secreted from the cell, whereas in intracrine signalling the hormone is not.\n\n\n\n\nIt would appear that the question relates more to autocrine signalling, in which case (again from the Wikipedia entry (https://en.wikipedia.org/wiki/Autocrine_signaling)) examples include:\n\n\n\n\n\n\n\ncytokine interleukin-1 in monocytes\n\n\n\n\n\n\n\n\n\ninterleukin-2 in T cell lymphocytes\n\n\n\n\n\n\n\n\nGlancing through the rest of the article it would appear that autocrine signalling is most common in the class of hormone known as growth factors (https://en.wikipedia.org/wiki/Growth_factor) rather than the more well-known earlier discovered types such as insulin and testosterone which are classified as being involved in endocrine signalling.\n\n\n\n\nFor further information — and considerations of the rationale of autocrine signalling systems — the reader should consult more authoritative sources than Wikipedia, although some of these will require library access to journals. A 2016 review in Trends in Cell Biology (http://dx.doi.org/10.1016/j.tcb.2015.11.002) provides several referenced examples and makes the proposal that autocrine signalling is in some cases analogous to quorum sensing in bacteria. This seems to be similar to the point made by @BrianKrause in a comment — that autocrine signalling can be a way of getting cells and their neighbours to respond in a co-ordinated manner.\n\n\n\n\nBrian also makes the point that “there are examples of autocrine signaling where if there is high activity among a group of neurons releasing the same neurotransmitter, the same neurotransmitter inhibits themselves and others of the same type through auto-receptors.”\n\n\n\n\nAlthough this is not my field, I would venture to suggest that in other circumstances autocrine signalling may be a means of initiating the division of the secreting cells. The secretion of growth-factor (or presence/strength of receptors) may not be a continuous or recurring event, but a single event in response to an external stimulus at some stage in cellular development.", "answer_url": "https://biology.stackexchange.com/a/116460", "author": "David", "author_url": "https://biology.stackexchange.com/users/22057/david", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-05-07T15:09:45+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:19.947691+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/df693642d727b738d2a533740632235c18a06cefec7a1e337c9589214a4ec91e_0.json", "raw_sha256": "9df534f437f3b2f12d33db8536999ec4e6ffa10f2f59394799d9fe01c3c1ad16", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/117606;117602;117598;117594;117585;117579;117570;117568;117565;117559;117558;117555;117552;117548;117538;117524;117523;117522;117520;117515;117510;116509;116508;116504;116499;116491;116485;116483;116461;116454;116453;116445;116441;116435;116430;116426;116425;116414;116412;116406;116401;116399;116396;116395;116394;116392;116389;116384;116370;116367;116363;116361;116352;116351;116347;116345;116343;116338;116337;116332;116331;116324;116320;116316;116314;116312;116306;116292;116290;116284;116280;116277;116271;116270;116268;116267;116257;116256;116253;116250;116249;116240;116237;116233;116219;116214;116212;116205;116204;116200;116198;116187;116184;116173;116172;116167;116162;116149;116142;116129/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 116453, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-07T15:09:45+00:00", "raw_file": "raw/codex_api_v1/44a668e829ce1e5d355c0dcd71925c16fb650d744ddea539b26c827698be07fc_1790824147175909500_0.json", "raw_sha256": "cacbff1e3cd30ece568cbed70e415ee7bb13ad0f92e723966430c45bae70706a", "revision_guid": "5DD38544-77C2-4D73-ACC9-D4F03C30B469", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/5DD38544-77C2-4D73-ACC9-D4F03C30B469/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-08T09:58:51+00:00", "raw_file": "raw/codex_api_v1/513f34509ea5b8cfd23e2c22ec69b0af899072a5df884318581dc59cdc06558f_1790824145019083900_0.json", "raw_sha256": "e49bc4b696ee886e85729b5e43d509e97eb936a63dd33019b0855e8f32360f99", "revision_guid": "71147A40-BE42-4C8B-B7D8-7AAD0200B62C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/71147A40-BE42-4C8B-B7D8-7AAD0200B62C/view-source"}], "score": 5, "updated_at": "2025-05-08T09:58:51+00:00"}], "domain": "biology", "external_links": ["http://dx.doi.org/10.1016/j.tcb.2015.11.002", "https://en.wikipedia.org/wiki/Autocrine_signaling", "https://en.wikipedia.org/wiki/Growth_factor", "https://en.wikipedia.org/wiki/Hormone"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:02.598621+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/5d480e4bd1bd45ab525a4baf3227fba404f89b6af9dad33215fd9fa7c302a211_0.json", "raw_sha256": "d723c7a62c8386d143891d26ae30b2234242ed3dac9599b11f141712ea994a96", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=3&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "youthdoo", "question_author_url": "https://biology.stackexchange.com/users/105597/youthdoo", "question_author_user_type": "registered", "question_created_at": "2025-05-07T07:17:25+00:00", "question_html": "In the human body, does there exist a cell that can produce a hormone, such that the receptor of that hormone is on that cell?
\nNormally, hormones are produced by endocrine glands, and they affect the target cell by combining with a specific receptor. It would seem strange if the receptor is on the producer cell, but I would like to know whether there are any known examples of this,
\n", "question_id": 116453, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "In the human body, does there exist a cell that can produce a hormone, such that the receptor of that hormone is on that cell?\n\n\n\n\nNormally, hormones are produced by endocrine glands, and they affect the target cell by combining with a specific receptor. It would seem strange if the receptor is on the producer cell, but I would like to know whether there are any known examples of this,", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "youthdoo", "profile_url": "https://biology.stackexchange.com/users/105597/youthdoo", "user_type": "registered"}, "created_at": "2025-05-07T07:17:25+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "4AA8C058-3998-4C7E-A17D-7AB40398E354", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AA8C058-3998-4C7E-A17D-7AB40398E354/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "David", "profile_url": "https://biology.stackexchange.com/users/22057/david", "user_type": "registered"}, "created_at": "2025-05-07T14:44:18+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "8F835600-2115-4953-A9F0-951E9AD9747F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/8F835600-2115-4953-A9F0-951E9AD9747F/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2025-05-07T15:48:25+00:00", "raw_file": "raw/codex_api_v1/00f792a35cd1fe53cc744b44d1c7f5a2081648f5d4403a4e8f1d570c00e5dc95_1790824135500262400_0.json", "raw_sha256": "0face46f22b53414ff8968bb035acf71d0f5c1f84da8d6f0813602f842802d98", "revision_guid": "C79C7805-DB3F-4C11-8327-490D7239DB4B", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/C79C7805-DB3F-4C11-8327-490D7239DB4B/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/116453/is-there-a-cell-that-produces-a-hormone-that-acts-on-the-same-type-of-cell", "split": "validation", "split_group": "f9d2c2a40e13040840b8ff52274661f3319531d81d7b9453056f67cbcd6b7b1b", "tags": ["human-biology", "cell-biology", "endocrinology"], "thread_id": "biology:116453", "title": "Is there a cell that produces a hormone that acts on the same type of cell"}} {"citation_context": "Update\n\n\n\n\nSee this very recent post on this topic (https://open.substack.com/pub/theinfinitesimal/p/where-are-the-recent-selective-sweeps?utm_source=post-email-title&publication_id=2719736&post_id=147097482&utm_campaign=email-post-title&isFreemail=true&r=2gc0&token=eyJ1c2VyX2lkIjoxMTQ0ODAsInBvc3RfaWQiOjE0NzA5NzQ4MiwiaWF0IjoxNzI2MzI1ODgxLCJleHAiOjE3Mjg5MTc4ODEsImlzcyI6InB1Yi0yNzE5NzM2Iiwic3ViIjoicG9zdC1yZWFjdGlvbiJ9.pkUfIdERWtRjBFzKkzb-HMVbnsr5XSZTuRJ9oI_BOtw) from the excellent Sasha Gusev.\n\n\n\n\nOriginal answer\n\n\n\n\nI would suggest this recent review of the ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://open.substack.com/pub/theinfinitesimal/p/where-are-the-recent-selective-sweeps?utm_source=post-email-title&publication_id=2719736&post_id=147097482&utm_campaign=email-post-title&isFreemail=true&r=2gc0&token=eyJ1c2VyX2lkIjoxMTQ0ODAsInBvc3RfaWQiOjE0NzA5NzQ4MiwiaWF0IjoxNzI2MzI1ODgxLCJleHAiOjE3Mjg5MTc4ODEsImlzcyI6InB1Yi0yNzE5NzM2Iiwic3ViIjoicG9zdC1yZWFjdGlvbiJ9.pkUfIdERWtRjBFzKkzb-HMVbnsr5XSZTuRJ9oI_BOtw", "kind": "external_url", "post_id": 115332, "post_url": "https://biology.stackexchange.com/a/115332", "product": "citations", "record_id": "Scientific-Citation-Graph:0178ff99efce91d0396b408b", "split": "validation", "thread": {"accepted_answer_id": 115332, "answers": [{"answer_html": "See this very recent post on this topic from the excellent Sasha Gusev.
\nI would suggest this recent review of the literature on techniques for detecting very recent selection in human populations and some of the results they've gotten.
\nSome of the least ambiguous results are as follows:
\n\n\nMarkovian coalescent (ASMC) detects targets of recent positive selection by inferring pairwise coalescent times and looking for unusually high densities of coalescent events in the recent past (Fig 2C(v)) [16,17]. When applied to whole-genome sequences of approximately 3,200 individuals of European ancestry, SDS detected selection signals in the past 2,000 to 3,000 years in the major histocompatibility complex (MHC) region and at variants associated with lactose tolerance and pigmentation [15]. In comparison, application of ASMC to over 487,000 British individuals identified signals of selection in the past 1,500 years, including those detected by SDS, as well as several new candidate loci harboring genes related to immune response, tumor growth, and other phenotypes [17].
\n...\nThese new methods have confirmed strong selection on variants associated with lactase persistence, immune response, and pigmentation traits in Europeans in the past few thousand years and some signals in other populations (such as the EDAR gene in East Asians), although very few new signals have been detected. [my emphasis]
\n
There are some more results in there. However, I would pay a lot of attention to the methodological issues and caveats that are given. It's very hard to detect this kind of thing, and the possibility of confounding is very high.
\nFurthermore, I am not sure that these constitute "dramatic" change in allele frequency of the kind that you seem to be interested in. For example, they have this to say about genes associated with resistance to pandemics like the Black Death (one of the most clear cut examples of selection on differential fitness).
\n\n\nThese results suggest the selection effects of historical pandemics at individual genomic loci are relatively modest, necessitating expansive sample sizes for detection.
\n
They are statistically detectable, implying that they are strong from a microevolutionary point of view, but it is not at all clear that they are significant from a historical point of view, or that they lead to meaningful group distinctions.
\nLooking at your interest in trying to "date" a genome like with carbon dating, that sounds difficult. A more answerable question might be, if you got very lucky and found an example of a distinct population group that died out, you might be able to put bounds on that person based on the existence of that group. But that's probably on the thousands of years scale (more) rather than hundreds.
\nIn summary: recent evolution in humans is the exception and not the rule. Most of the important stuff happened prehistorically (like, out-of-Africa and before).
\n", "answer_id": 115332, "answer_text": "Update\n\n\n\n\nSee this very recent post on this topic (https://open.substack.com/pub/theinfinitesimal/p/where-are-the-recent-selective-sweeps?utm_source=post-email-title&publication_id=2719736&post_id=147097482&utm_campaign=email-post-title&isFreemail=true&r=2gc0&token=eyJ1c2VyX2lkIjoxMTQ0ODAsInBvc3RfaWQiOjE0NzA5NzQ4MiwiaWF0IjoxNzI2MzI1ODgxLCJleHAiOjE3Mjg5MTc4ODEsImlzcyI6InB1Yi0yNzE5NzM2Iiwic3ViIjoicG9zdC1yZWFjdGlvbiJ9.pkUfIdERWtRjBFzKkzb-HMVbnsr5XSZTuRJ9oI_BOtw) from the excellent Sasha Gusev.\n\n\n\n\nOriginal answer\n\n\n\n\nI would suggest this recent review of the literature (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10796035/) on techniques for detecting very recent selection in human populations and some of the results they've gotten.\n\n\n\n\nSome of the least ambiguous results are as follows:\n\n\n\n\n\n\n\nMarkovian coalescent (ASMC) detects targets of recent positive selection by inferring pairwise coalescent times and looking for unusually high densities of coalescent events in the recent past (Fig 2C(v)) [16,17]. When applied to whole-genome sequences of approximately 3,200 individuals of European ancestry, SDS detected selection signals in the past 2,000 to 3,000 years in the major histocompatibility complex (MHC) region and at variants associated with lactose tolerance and pigmentation [15]. In comparison, application of ASMC to over 487,000 British individuals identified signals of selection in the past 1,500 years, including those detected by SDS, as well as several new candidate loci harboring genes related to immune response, tumor growth, and other phenotypes [17].\n\n\n\n\n...\nThese new methods have confirmed strong selection on variants associated with lactase persistence, immune response, and pigmentation traits in Europeans in the past few thousand years and some signals in other populations (such as the EDAR gene in East Asians), although very few new signals have been detected. [my emphasis]\n\n\n\n\n\n\n\nThere are some more results in there. However, I would pay a lot of attention to the methodological issues and caveats that are given. It's very hard to detect this kind of thing, and the possibility of confounding is very high.\n\n\n\n\nFurthermore, I am not sure that these constitute \"dramatic\" change in allele frequency of the kind that you seem to be interested in. For example, they have this to say about genes associated with resistance to pandemics like the Black Death (one of the most clear cut examples of selection on differential fitness).\n\n\n\n\n\n\n\nThese results suggest the selection effects of historical pandemics at individual genomic loci are relatively modest, necessitating expansive sample sizes for detection.\n\n\n\n\n\n\n\nThey are statistically detectable, implying that they are strong from a microevolutionary point of view, but it is not at all clear that they are significant from a historical point of view, or that they lead to meaningful group distinctions.\n\n\n\n\nLooking at your interest in trying to \"date\" a genome like with carbon dating, that sounds difficult. A more answerable question might be, if you got very lucky and found an example of a distinct population group that died out, you might be able to put bounds on that person based on the existence of that group. But that's probably on the thousands of years scale (more) rather than hundreds.\n\n\n\n\nIn summary: recent evolution in humans is the exception and not the rule. Most of the important stuff happened prehistorically (like, out-of-Africa and before).", "answer_url": "https://biology.stackexchange.com/a/115332", "author": "Maximilian Press", "author_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-09-10T16:27:08+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:25.304620+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/7fe0b66593eb4c0f175024453138b8bd50811f1580a079ffb990af38e09cd1cf_0.json", "raw_sha256": "b0a655f3b4c9626cf981180b3ac018a4a26330c5ab9b925b3df78bedd8169a84", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/115493;115490;115488;115483;115479;115477;115456;115453;115452;115447;115445;115444;115436;115431;115427;115413;115404;115403;115396;115391;115389;115388;115386;115383;115382;115379;115367;115365;115355;115340;115334;115328;115321;115314;115309;115304;115296;115295;115292;115283;115272;115270;115269;115265;115264;115260;115255;115252;115243;115235;115233;115225;115218;115215;115214;115213;115207;115204;115179;115177;115170;115167;115165;115164;115154;115149;115137;115131;115129;115115;115107;115099;115095;115094;115093;115085;115082;115081;115077;115076;115075;115074;115073;115072;115063;115044;115039;115035;115030;115025;115022;115019;115016;115012;115003;115002;114997;114993;114991;114987/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115309, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2024-09-10T16:27:08+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "04A4E2EE-503A-4407-A287-89C2012FD337", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/04A4E2EE-503A-4407-A287-89C2012FD337/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2024-09-10T16:46:56+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "33E970F7-A8BD-4548-92A3-8B6FFE6B4798", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/33E970F7-A8BD-4548-92A3-8B6FFE6B4798/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2024-09-16T17:48:27+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "04FD1FFC-9AE4-4411-B362-E7E94F134323", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/04FD1FFC-9AE4-4411-B362-E7E94F134323/view-source"}], "score": 5, "updated_at": "2024-09-16T17:48:27+00:00"}], "domain": "biology", "external_links": ["https://open.substack.com/pub/theinfinitesimal/p/where-are-the-recent-selective-sweeps?utm_source=post-email-title&publication_id=2719736&post_id=147097482&utm_campaign=email-post-title&isFreemail=true&r=2gc0&token=eyJ1c2VyX2lkIjoxMTQ0ODAsInBvc3RfaWQiOjE0NzA5NzQ4MiwiaWF0IjoxNzI2MzI1ODgxLCJleHAiOjE3Mjg5MTc4ODEsImlzcyI6InB1Yi0yNzE5NzM2Iiwic3ViIjoicG9zdC1yZWFjdGlvbiJ9.pkUfIdERWtRjBFzKkzb-HMVbnsr5XSZTuRJ9oI_BOtw", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10796035/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:05.762873+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/04ed2aa314c5d877c5d79e42620d1f80988a21de8d429a22d8c6af5280cfd6e8_0.json", "raw_sha256": "6dd355b99094bb9ba2c965ee7dd7b0e95f92a8078d3b2b85b64196fcb6cf717c", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=5&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "CXJ", "question_author_url": "https://biology.stackexchange.com/users/78949/cxj", "question_author_user_type": "registered", "question_created_at": "2024-09-06T00:56:58+00:00", "question_html": "I'm a writer and engineer, not a biologist, so please forgive me on errors. I've done hours and hours of reading of biology texts and research papers trying to answer this question for myself before asking here.
\nIs there evidence for any allele that has dramatically changed in frequency of occurrence in the past 500 years (or in that time frame)?
\nI'm just trying to get an idea of whether a genome would provide any evidence of deriving from one century versus another, so to speak (i.e. I'm not really concerned with actual centuries, but rather changes over that time scale).
\n", "question_id": 115309, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I'm a writer and engineer, not a biologist, so please forgive me on errors. I've done hours and hours of reading of biology texts and research papers trying to answer this question for myself before asking here.\n\n\n\n\nIs there evidence for any allele that has dramatically changed in frequency of occurrence in the past 500 years (or in that time frame)?\n\n\n\n\nI'm just trying to get an idea of whether a genome would provide any evidence of deriving from one century versus another, so to speak (i.e. I'm not really concerned with actual centuries, but rather changes over that time scale).", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "CXJ", "profile_url": "https://biology.stackexchange.com/users/78949/cxj", "user_type": "registered"}, "created_at": "2024-09-06T00:56:58+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "17A5B3FE-7A4F-42F3-B00D-E3852B2D6363", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/17A5B3FE-7A4F-42F3-B00D-E3852B2D6363/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2024-09-10T16:41:59+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "FAE6F173-D955-4F06-BFED-917030294AB0", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/FAE6F173-D955-4F06-BFED-917030294AB0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115309/is-there-a-human-gene-or-allele-that-has-dramatically-changed-in-frequency-of-oc", "split": "validation", "split_group": "37d4ec92804f2e0f41ccb632d364b86bbfe512b31451321727b5353703ef7e59", "tags": ["human-genetics", "population-genetics", "natural-selection", "human-evolution"], "thread_id": "biology:115309", "title": "Is there a human gene or allele that has dramatically changed in frequency of occurence in the past circa 500 years?"}} {"citation_context": "xcellent Sasha Gusev.\n\n\n\n\nOriginal answer\n\n\n\n\nI would suggest this recent review of the literature (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10796035/) on techniques for detecting very recent selection in human populations and some of the results the", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10796035/", "kind": "external_url", "post_id": 115332, "post_url": "https://biology.stackexchange.com/a/115332", "product": "citations", "record_id": "Scientific-Citation-Graph:6d3b20c47c4a5bf1c1d8a439", "split": "validation", "thread": {"accepted_answer_id": 115332, "answers": [{"answer_html": "See this very recent post on this topic from the excellent Sasha Gusev.
\nI would suggest this recent review of the literature on techniques for detecting very recent selection in human populations and some of the results they've gotten.
\nSome of the least ambiguous results are as follows:
\n\n\nMarkovian coalescent (ASMC) detects targets of recent positive selection by inferring pairwise coalescent times and looking for unusually high densities of coalescent events in the recent past (Fig 2C(v)) [16,17]. When applied to whole-genome sequences of approximately 3,200 individuals of European ancestry, SDS detected selection signals in the past 2,000 to 3,000 years in the major histocompatibility complex (MHC) region and at variants associated with lactose tolerance and pigmentation [15]. In comparison, application of ASMC to over 487,000 British individuals identified signals of selection in the past 1,500 years, including those detected by SDS, as well as several new candidate loci harboring genes related to immune response, tumor growth, and other phenotypes [17].
\n...\nThese new methods have confirmed strong selection on variants associated with lactase persistence, immune response, and pigmentation traits in Europeans in the past few thousand years and some signals in other populations (such as the EDAR gene in East Asians), although very few new signals have been detected. [my emphasis]
\n
There are some more results in there. However, I would pay a lot of attention to the methodological issues and caveats that are given. It's very hard to detect this kind of thing, and the possibility of confounding is very high.
\nFurthermore, I am not sure that these constitute "dramatic" change in allele frequency of the kind that you seem to be interested in. For example, they have this to say about genes associated with resistance to pandemics like the Black Death (one of the most clear cut examples of selection on differential fitness).
\n\n\nThese results suggest the selection effects of historical pandemics at individual genomic loci are relatively modest, necessitating expansive sample sizes for detection.
\n
They are statistically detectable, implying that they are strong from a microevolutionary point of view, but it is not at all clear that they are significant from a historical point of view, or that they lead to meaningful group distinctions.
\nLooking at your interest in trying to "date" a genome like with carbon dating, that sounds difficult. A more answerable question might be, if you got very lucky and found an example of a distinct population group that died out, you might be able to put bounds on that person based on the existence of that group. But that's probably on the thousands of years scale (more) rather than hundreds.
\nIn summary: recent evolution in humans is the exception and not the rule. Most of the important stuff happened prehistorically (like, out-of-Africa and before).
\n", "answer_id": 115332, "answer_text": "Update\n\n\n\n\nSee this very recent post on this topic (https://open.substack.com/pub/theinfinitesimal/p/where-are-the-recent-selective-sweeps?utm_source=post-email-title&publication_id=2719736&post_id=147097482&utm_campaign=email-post-title&isFreemail=true&r=2gc0&token=eyJ1c2VyX2lkIjoxMTQ0ODAsInBvc3RfaWQiOjE0NzA5NzQ4MiwiaWF0IjoxNzI2MzI1ODgxLCJleHAiOjE3Mjg5MTc4ODEsImlzcyI6InB1Yi0yNzE5NzM2Iiwic3ViIjoicG9zdC1yZWFjdGlvbiJ9.pkUfIdERWtRjBFzKkzb-HMVbnsr5XSZTuRJ9oI_BOtw) from the excellent Sasha Gusev.\n\n\n\n\nOriginal answer\n\n\n\n\nI would suggest this recent review of the literature (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10796035/) on techniques for detecting very recent selection in human populations and some of the results they've gotten.\n\n\n\n\nSome of the least ambiguous results are as follows:\n\n\n\n\n\n\n\nMarkovian coalescent (ASMC) detects targets of recent positive selection by inferring pairwise coalescent times and looking for unusually high densities of coalescent events in the recent past (Fig 2C(v)) [16,17]. When applied to whole-genome sequences of approximately 3,200 individuals of European ancestry, SDS detected selection signals in the past 2,000 to 3,000 years in the major histocompatibility complex (MHC) region and at variants associated with lactose tolerance and pigmentation [15]. In comparison, application of ASMC to over 487,000 British individuals identified signals of selection in the past 1,500 years, including those detected by SDS, as well as several new candidate loci harboring genes related to immune response, tumor growth, and other phenotypes [17].\n\n\n\n\n...\nThese new methods have confirmed strong selection on variants associated with lactase persistence, immune response, and pigmentation traits in Europeans in the past few thousand years and some signals in other populations (such as the EDAR gene in East Asians), although very few new signals have been detected. [my emphasis]\n\n\n\n\n\n\n\nThere are some more results in there. However, I would pay a lot of attention to the methodological issues and caveats that are given. It's very hard to detect this kind of thing, and the possibility of confounding is very high.\n\n\n\n\nFurthermore, I am not sure that these constitute \"dramatic\" change in allele frequency of the kind that you seem to be interested in. For example, they have this to say about genes associated with resistance to pandemics like the Black Death (one of the most clear cut examples of selection on differential fitness).\n\n\n\n\n\n\n\nThese results suggest the selection effects of historical pandemics at individual genomic loci are relatively modest, necessitating expansive sample sizes for detection.\n\n\n\n\n\n\n\nThey are statistically detectable, implying that they are strong from a microevolutionary point of view, but it is not at all clear that they are significant from a historical point of view, or that they lead to meaningful group distinctions.\n\n\n\n\nLooking at your interest in trying to \"date\" a genome like with carbon dating, that sounds difficult. A more answerable question might be, if you got very lucky and found an example of a distinct population group that died out, you might be able to put bounds on that person based on the existence of that group. But that's probably on the thousands of years scale (more) rather than hundreds.\n\n\n\n\nIn summary: recent evolution in humans is the exception and not the rule. Most of the important stuff happened prehistorically (like, out-of-Africa and before).", "answer_url": "https://biology.stackexchange.com/a/115332", "author": "Maximilian Press", "author_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-09-10T16:27:08+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:25.304620+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/7fe0b66593eb4c0f175024453138b8bd50811f1580a079ffb990af38e09cd1cf_0.json", "raw_sha256": "b0a655f3b4c9626cf981180b3ac018a4a26330c5ab9b925b3df78bedd8169a84", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/115493;115490;115488;115483;115479;115477;115456;115453;115452;115447;115445;115444;115436;115431;115427;115413;115404;115403;115396;115391;115389;115388;115386;115383;115382;115379;115367;115365;115355;115340;115334;115328;115321;115314;115309;115304;115296;115295;115292;115283;115272;115270;115269;115265;115264;115260;115255;115252;115243;115235;115233;115225;115218;115215;115214;115213;115207;115204;115179;115177;115170;115167;115165;115164;115154;115149;115137;115131;115129;115115;115107;115099;115095;115094;115093;115085;115082;115081;115077;115076;115075;115074;115073;115072;115063;115044;115039;115035;115030;115025;115022;115019;115016;115012;115003;115002;114997;114993;114991;114987/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115309, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2024-09-10T16:27:08+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "04A4E2EE-503A-4407-A287-89C2012FD337", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/04A4E2EE-503A-4407-A287-89C2012FD337/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2024-09-10T16:46:56+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "33E970F7-A8BD-4548-92A3-8B6FFE6B4798", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/33E970F7-A8BD-4548-92A3-8B6FFE6B4798/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2024-09-16T17:48:27+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "04FD1FFC-9AE4-4411-B362-E7E94F134323", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/04FD1FFC-9AE4-4411-B362-E7E94F134323/view-source"}], "score": 5, "updated_at": "2024-09-16T17:48:27+00:00"}], "domain": "biology", "external_links": ["https://open.substack.com/pub/theinfinitesimal/p/where-are-the-recent-selective-sweeps?utm_source=post-email-title&publication_id=2719736&post_id=147097482&utm_campaign=email-post-title&isFreemail=true&r=2gc0&token=eyJ1c2VyX2lkIjoxMTQ0ODAsInBvc3RfaWQiOjE0NzA5NzQ4MiwiaWF0IjoxNzI2MzI1ODgxLCJleHAiOjE3Mjg5MTc4ODEsImlzcyI6InB1Yi0yNzE5NzM2Iiwic3ViIjoicG9zdC1yZWFjdGlvbiJ9.pkUfIdERWtRjBFzKkzb-HMVbnsr5XSZTuRJ9oI_BOtw", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10796035/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:05.762873+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/04ed2aa314c5d877c5d79e42620d1f80988a21de8d429a22d8c6af5280cfd6e8_0.json", "raw_sha256": "6dd355b99094bb9ba2c965ee7dd7b0e95f92a8078d3b2b85b64196fcb6cf717c", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=5&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "CXJ", "question_author_url": "https://biology.stackexchange.com/users/78949/cxj", "question_author_user_type": "registered", "question_created_at": "2024-09-06T00:56:58+00:00", "question_html": "I'm a writer and engineer, not a biologist, so please forgive me on errors. I've done hours and hours of reading of biology texts and research papers trying to answer this question for myself before asking here.
\nIs there evidence for any allele that has dramatically changed in frequency of occurrence in the past 500 years (or in that time frame)?
\nI'm just trying to get an idea of whether a genome would provide any evidence of deriving from one century versus another, so to speak (i.e. I'm not really concerned with actual centuries, but rather changes over that time scale).
\n", "question_id": 115309, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I'm a writer and engineer, not a biologist, so please forgive me on errors. I've done hours and hours of reading of biology texts and research papers trying to answer this question for myself before asking here.\n\n\n\n\nIs there evidence for any allele that has dramatically changed in frequency of occurrence in the past 500 years (or in that time frame)?\n\n\n\n\nI'm just trying to get an idea of whether a genome would provide any evidence of deriving from one century versus another, so to speak (i.e. I'm not really concerned with actual centuries, but rather changes over that time scale).", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "CXJ", "profile_url": "https://biology.stackexchange.com/users/78949/cxj", "user_type": "registered"}, "created_at": "2024-09-06T00:56:58+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "17A5B3FE-7A4F-42F3-B00D-E3852B2D6363", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/17A5B3FE-7A4F-42F3-B00D-E3852B2D6363/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Maximilian Press", "profile_url": "https://biology.stackexchange.com/users/22392/maximilian-press", "user_type": "registered"}, "created_at": "2024-09-10T16:41:59+00:00", "raw_file": "raw/codex_api_v1/cedb71cd945e8f995b79cadd8e6718011c2863cc935a3a1410ded32d454feeef_1790824099288070500_0.json", "raw_sha256": "6569d2607abeaad3ebe6e725128dec16202338bf9cbd6c8013a07c01af6e0905", "revision_guid": "FAE6F173-D955-4F06-BFED-917030294AB0", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/FAE6F173-D955-4F06-BFED-917030294AB0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115309/is-there-a-human-gene-or-allele-that-has-dramatically-changed-in-frequency-of-oc", "split": "validation", "split_group": "37d4ec92804f2e0f41ccb632d364b86bbfe512b31451321727b5353703ef7e59", "tags": ["human-genetics", "population-genetics", "natural-selection", "human-evolution"], "thread_id": "biology:115309", "title": "Is there a human gene or allele that has dramatically changed in frequency of occurence in the past circa 500 years?"}} {"citation_context": "relevant results from Google Search for \"blue light mosquito larvae\". Here is just one of them:\n\n\n\n\nhttps://www.nature.com/articles/s41598-022-14096-y (https://www.nature.com/articles/s41598-022-14096-y)\n\n\n\n\nThey are not all only mosquito related eit", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.nature.com/articles/s41598-022-14096-y", "kind": "external_url", "post_id": 113489, "post_url": "https://biology.stackexchange.com/a/113489", "product": "citations", "record_id": "Scientific-Citation-Graph:a3cbe8f367da0b307f0f4707", "split": "validation", "thread": {"accepted_answer_id": 113489, "answers": [{"answer_html": "There are lots of relevant results from Google Search for "blue light mosquito larvae". Here is just one of them:
\nhttps://www.nature.com/articles/s41598-022-14096-y
\nThey are not all only mosquito related either, such as this one for insects in general:\nhttps://www.nature.com/articles/srep07383
\nOr you could just find out for yourself. You are already set up for it. All you need is a control group, and preferably a third group that is exposed to high intensity laser light of a significantly different wavelength such as red or green in order to determine if it is just the intensity of the light or the wavelength.
\n", "answer_id": 113489, "answer_text": "There are lots of relevant results from Google Search for \"blue light mosquito larvae\". Here is just one of them:\n\n\n\n\nhttps://www.nature.com/articles/s41598-022-14096-y (https://www.nature.com/articles/s41598-022-14096-y)\n\n\n\n\nThey are not all only mosquito related either, such as this one for insects in general:\nhttps://www.nature.com/articles/srep07383 (https://www.nature.com/articles/srep07383)\n\n\n\n\nOr you could just find out for yourself. You are already set up for it. All you need is a control group, and preferably a third group that is exposed to high intensity laser light of a significantly different wavelength such as red or green in order to determine if it is just the intensity of the light or the wavelength.", "answer_url": "https://biology.stackexchange.com/a/113489", "author": "DKNguyen", "author_url": "https://biology.stackexchange.com/users/56968/dknguyen", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2023-11-15T01:44:47+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:33.526680+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/d1acc50471f82e02a014a291913995889f5ddcd7076433532102b9b97a4a3a3d_0.json", "raw_sha256": "e6b5a7d5e11f0ac54d756d69e21baee1de119b759ec7e8caa7f174d67cf80eff", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/113978;113977;113976;113967;113965;113959;113955;113947;113946;113937;113936;113924;113918;113912;113907;113904;113902;113898;113897;113887;113884;113873;113869;113863;113858;113855;113849;113846;113836;113833;113828;113827;113822;113811;113810;113806;113795;113788;113781;113780;113777;113775;113773;113763;113761;113748;113747;113739;113738;113734;113722;113715;113712;113694;113688;113681;113678;113677;113655;113654;113648;113647;113643;113642;113638;113634;113633;113631;113614;113611;113599;113598;113596;113595;113593;113590;113581;113576;113575;113570;113569;113566;113561;113557;113554;113551;113545;113537;113534;113531;113515;113508;113507;113505;113498;113491;113484;113483;113471;113469/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 113484, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "DKNguyen", "profile_url": "https://biology.stackexchange.com/users/56968/dknguyen", "user_type": "registered"}, "created_at": "2023-11-15T01:44:47+00:00", "raw_file": "raw/codex_api_v1/dd2ec40a5fd89c86baf1df900910393bf6ce6ec67fd07493fc5fb9dcd3e21d06_1790824048829330400_0.json", "raw_sha256": "543debf5d698aa4490d105f431e8f442c0f067237add2fc696b1bcaa58d49ecd", "revision_guid": "16A97E4C-2A19-4D22-9F4D-368BDABB5CA6", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/16A97E4C-2A19-4D22-9F4D-368BDABB5CA6/view-source"}], "score": 4, "updated_at": "2023-11-15T01:44:47+00:00"}], "domain": "biology", "external_links": ["https://www.nature.com/articles/s41598-022-14096-y", "https://www.nature.com/articles/srep07383"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:09.960411+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f3d8f52a1a12ba8e3a85266c887134296fd3686fb5ffec1a38526e2b8ccdcc24_0.json", "raw_sha256": "b1b59ebb5f220f357ffaa8464594a3d8f391df66ad06b024355499ef7eff18cb", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=8&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Vidushi Aggarwal", "question_author_url": "https://biology.stackexchange.com/users/77442/vidushi-aggarwal", "question_author_user_type": "registered", "question_created_at": "2023-11-14T11:10:18+00:00", "question_html": "I have been observing developing mosquito larvae since 2 days and I saw, while exposing my laser light of blue colour to it, that it becomes unstable on exposure to blue light.\nThus, I wish to ask, will it die or whether it is fine? It has been one day since I shone the light on it, so please tell me: will it grow further or not?
\n", "question_id": 113484, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I have been observing developing mosquito larvae since 2 days and I saw, while exposing my laser light of blue colour to it, that it becomes unstable on exposure to blue light.\nThus, I wish to ask, will it die or whether it is fine? It has been one day since I shone the light on it, so please tell me: will it grow further or not?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Vidushi Aggarwal", "profile_url": "https://biology.stackexchange.com/users/77442/vidushi-aggarwal", "user_type": "registered"}, "created_at": "2023-11-14T11:10:18+00:00", "raw_file": "raw/codex_api_v1/dd2ec40a5fd89c86baf1df900910393bf6ce6ec67fd07493fc5fb9dcd3e21d06_1790824048829330400_0.json", "raw_sha256": "543debf5d698aa4490d105f431e8f442c0f067237add2fc696b1bcaa58d49ecd", "revision_guid": "25E791AD-5262-4BE6-B624-C81117DB7392", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/25E791AD-5262-4BE6-B624-C81117DB7392/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Vidushi Aggarwal", "profile_url": "https://biology.stackexchange.com/users/77442/vidushi-aggarwal", "user_type": "registered"}, "created_at": "2023-11-14T17:38:11+00:00", "raw_file": "raw/codex_api_v1/dd2ec40a5fd89c86baf1df900910393bf6ce6ec67fd07493fc5fb9dcd3e21d06_1790824048829330400_0.json", "raw_sha256": "543debf5d698aa4490d105f431e8f442c0f067237add2fc696b1bcaa58d49ecd", "revision_guid": "87CFD454-D8F6-42D5-9A66-35E78FA1AB52", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/87CFD454-D8F6-42D5-9A66-35E78FA1AB52/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Smarika Singh", "profile_url": "https://biology.stackexchange.com/users/61261/smarika-singh", "user_type": "registered"}, "created_at": "2023-11-15T06:58:25+00:00", "raw_file": "raw/codex_api_v1/dd2ec40a5fd89c86baf1df900910393bf6ce6ec67fd07493fc5fb9dcd3e21d06_1790824048829330400_0.json", "raw_sha256": "543debf5d698aa4490d105f431e8f442c0f067237add2fc696b1bcaa58d49ecd", "revision_guid": "728212E9-BF8B-4BAB-8C53-C528162280BF", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/728212E9-BF8B-4BAB-8C53-C528162280BF/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/113484/is-continuous-exposure-to-blue-light-lethal-for-mosquito-larvae", "split": "validation", "split_group": "47ad992a876ac16f50968382e1bf2e72ea3bc433d4ede93501fca43a348d66c6", "tags": ["entomology", "mosquitoes"], "thread_id": "biology:113484", "title": "Is continuous exposure to blue light lethal for mosquito larvae?"}} {"citation_context": "4096-y)\n\n\n\n\nThey are not all only mosquito related either, such as this one for insects in general:\nhttps://www.nature.com/articles/srep07383 (https://www.nature.com/articles/srep07383)\n\n\n\n\nOr you could just find out for yourself. You are al", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.nature.com/articles/srep07383", "kind": "external_url", "post_id": 113489, "post_url": "https://biology.stackexchange.com/a/113489", "product": "citations", "record_id": "Scientific-Citation-Graph:9258ba3cf6876c5541c8bebe", "split": "validation", "thread": {"accepted_answer_id": 113489, "answers": [{"answer_html": "There are lots of relevant results from Google Search for "blue light mosquito larvae". Here is just one of them:
\nhttps://www.nature.com/articles/s41598-022-14096-y
\nThey are not all only mosquito related either, such as this one for insects in general:\nhttps://www.nature.com/articles/srep07383
\nOr you could just find out for yourself. You are already set up for it. All you need is a control group, and preferably a third group that is exposed to high intensity laser light of a significantly different wavelength such as red or green in order to determine if it is just the intensity of the light or the wavelength.
\n", "answer_id": 113489, "answer_text": "There are lots of relevant results from Google Search for \"blue light mosquito larvae\". Here is just one of them:\n\n\n\n\nhttps://www.nature.com/articles/s41598-022-14096-y (https://www.nature.com/articles/s41598-022-14096-y)\n\n\n\n\nThey are not all only mosquito related either, such as this one for insects in general:\nhttps://www.nature.com/articles/srep07383 (https://www.nature.com/articles/srep07383)\n\n\n\n\nOr you could just find out for yourself. You are already set up for it. All you need is a control group, and preferably a third group that is exposed to high intensity laser light of a significantly different wavelength such as red or green in order to determine if it is just the intensity of the light or the wavelength.", "answer_url": "https://biology.stackexchange.com/a/113489", "author": "DKNguyen", "author_url": "https://biology.stackexchange.com/users/56968/dknguyen", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2023-11-15T01:44:47+00:00", "is_accepted": true, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:33.526680+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/d1acc50471f82e02a014a291913995889f5ddcd7076433532102b9b97a4a3a3d_0.json", "raw_sha256": "e6b5a7d5e11f0ac54d756d69e21baee1de119b759ec7e8caa7f174d67cf80eff", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/113978;113977;113976;113967;113965;113959;113955;113947;113946;113937;113936;113924;113918;113912;113907;113904;113902;113898;113897;113887;113884;113873;113869;113863;113858;113855;113849;113846;113836;113833;113828;113827;113822;113811;113810;113806;113795;113788;113781;113780;113777;113775;113773;113763;113761;113748;113747;113739;113738;113734;113722;113715;113712;113694;113688;113681;113678;113677;113655;113654;113648;113647;113643;113642;113638;113634;113633;113631;113614;113611;113599;113598;113596;113595;113593;113590;113581;113576;113575;113570;113569;113566;113561;113557;113554;113551;113545;113537;113534;113531;113515;113508;113507;113505;113498;113491;113484;113483;113471;113469/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 113484, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "DKNguyen", "profile_url": "https://biology.stackexchange.com/users/56968/dknguyen", "user_type": "registered"}, "created_at": "2023-11-15T01:44:47+00:00", "raw_file": "raw/codex_api_v1/dd2ec40a5fd89c86baf1df900910393bf6ce6ec67fd07493fc5fb9dcd3e21d06_1790824048829330400_0.json", "raw_sha256": "543debf5d698aa4490d105f431e8f442c0f067237add2fc696b1bcaa58d49ecd", "revision_guid": "16A97E4C-2A19-4D22-9F4D-368BDABB5CA6", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/16A97E4C-2A19-4D22-9F4D-368BDABB5CA6/view-source"}], "score": 4, "updated_at": "2023-11-15T01:44:47+00:00"}], "domain": "biology", "external_links": ["https://www.nature.com/articles/s41598-022-14096-y", "https://www.nature.com/articles/srep07383"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:09.960411+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f3d8f52a1a12ba8e3a85266c887134296fd3686fb5ffec1a38526e2b8ccdcc24_0.json", "raw_sha256": "b1b59ebb5f220f357ffaa8464594a3d8f391df66ad06b024355499ef7eff18cb", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=8&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Vidushi Aggarwal", "question_author_url": "https://biology.stackexchange.com/users/77442/vidushi-aggarwal", "question_author_user_type": "registered", "question_created_at": "2023-11-14T11:10:18+00:00", "question_html": "I have been observing developing mosquito larvae since 2 days and I saw, while exposing my laser light of blue colour to it, that it becomes unstable on exposure to blue light.\nThus, I wish to ask, will it die or whether it is fine? It has been one day since I shone the light on it, so please tell me: will it grow further or not?
\n", "question_id": 113484, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I have been observing developing mosquito larvae since 2 days and I saw, while exposing my laser light of blue colour to it, that it becomes unstable on exposure to blue light.\nThus, I wish to ask, will it die or whether it is fine? It has been one day since I shone the light on it, so please tell me: will it grow further or not?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Vidushi Aggarwal", "profile_url": "https://biology.stackexchange.com/users/77442/vidushi-aggarwal", "user_type": "registered"}, "created_at": "2023-11-14T11:10:18+00:00", "raw_file": "raw/codex_api_v1/dd2ec40a5fd89c86baf1df900910393bf6ce6ec67fd07493fc5fb9dcd3e21d06_1790824048829330400_0.json", "raw_sha256": "543debf5d698aa4490d105f431e8f442c0f067237add2fc696b1bcaa58d49ecd", "revision_guid": "25E791AD-5262-4BE6-B624-C81117DB7392", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/25E791AD-5262-4BE6-B624-C81117DB7392/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Vidushi Aggarwal", "profile_url": "https://biology.stackexchange.com/users/77442/vidushi-aggarwal", "user_type": "registered"}, "created_at": "2023-11-14T17:38:11+00:00", "raw_file": "raw/codex_api_v1/dd2ec40a5fd89c86baf1df900910393bf6ce6ec67fd07493fc5fb9dcd3e21d06_1790824048829330400_0.json", "raw_sha256": "543debf5d698aa4490d105f431e8f442c0f067237add2fc696b1bcaa58d49ecd", "revision_guid": "87CFD454-D8F6-42D5-9A66-35E78FA1AB52", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/87CFD454-D8F6-42D5-9A66-35E78FA1AB52/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Smarika Singh", "profile_url": "https://biology.stackexchange.com/users/61261/smarika-singh", "user_type": "registered"}, "created_at": "2023-11-15T06:58:25+00:00", "raw_file": "raw/codex_api_v1/dd2ec40a5fd89c86baf1df900910393bf6ce6ec67fd07493fc5fb9dcd3e21d06_1790824048829330400_0.json", "raw_sha256": "543debf5d698aa4490d105f431e8f442c0f067237add2fc696b1bcaa58d49ecd", "revision_guid": "728212E9-BF8B-4BAB-8C53-C528162280BF", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/728212E9-BF8B-4BAB-8C53-C528162280BF/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/113484/is-continuous-exposure-to-blue-light-lethal-for-mosquito-larvae", "split": "validation", "split_group": "47ad992a876ac16f50968382e1bf2e72ea3bc433d4ede93501fca43a348d66c6", "tags": ["entomology", "mosquitoes"], "thread_id": "biology:113484", "title": "Is continuous exposure to blue light lethal for mosquito larvae?"}} {"citation_context": "es, mounting on a slide, and then observing these via transmitted light - brightfield illumination (https://en.wikipedia.org/wiki/Bright-field_microscopy), with the light shining from the bottom, directly through the object. Some stereomicroscopes will ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Bright-field_microscopy", "kind": "external_url", "post_id": 114421, "post_url": "https://biology.stackexchange.com/a/114421", "product": "citations", "record_id": "Scientific-Citation-Graph:2bb70553cf711eef0907740e", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "I'm not sure, but I suspect the answer here is a general "no".
\nThe reason I say this is that stereo microscopes typically do not have the magnifications needed to see the mycelium and other structures needed for ID of fungi clearly. For this you need a minimum of 100x (total magnification) and ideally 400x - 1000x magnification (that's 10x, 40x and 100x objective lenses on a compound microscope respectively). The one you mentioned from AmScope should just be capable of this range with a maximum magnification of 225x. I don't know if that magnification is with a Barlow fitted or not.
\nFungal ID is typically done by staining the hyphae and fruiting structures, mounting on a slide, and then observing these via transmitted light - brightfield illumination, with the light shining from the bottom, directly through the object. Some stereomicroscopes will have this capability, but definitely not all. Those that do won't have a condenser, which converts the point illumination of the bulb into a parallel or converging beam, which is needed to provide even illumination of the right angle for the objective lens being used so that you can see the object clearly.
\nStereomicroscopes would be useful for observing a fungal colony from above, but this isn't often all that useful for identification purposes.
\nBarlow lenses will help provide more magnification, I think at the expense of depth of field, though this shouldn't be much of a consideration for mounted specimens. Nikon's Microscopy U has lots of really good information on stereomicroscopes, including Barlow lenses (they call them "attachment" lenses) that you might find useful in determining for yourself.
\n", "answer_id": 114421, "answer_text": "I'm not sure, but I suspect the answer here is a general \"no\".\n\n\n\n\nThe reason I say this is that stereo microscopes typically do not have the magnifications needed to see the mycelium and other structures needed for ID of fungi clearly. For this you need a minimum of 100x (total magnification) and ideally 400x - 1000x magnification (that's 10x, 40x and 100x objective lenses on a compound microscope respectively). The one you mentioned from AmScope should just be capable of this range with a maximum magnification of 225x. I don't know if that magnification is with a Barlow fitted or not.\n\n\n\n\nFungal ID is typically done by staining the hyphae and fruiting structures, mounting on a slide, and then observing these via transmitted light - brightfield illumination (https://en.wikipedia.org/wiki/Bright-field_microscopy), with the light shining from the bottom, directly through the object. Some stereomicroscopes will have this capability, but definitely not all. Those that do won't have a condenser (https://en.wikipedia.org/wiki/Condenser_(optics)), which converts the point illumination of the bulb into a parallel or converging beam, which is needed to provide even illumination of the right angle for the objective lens being used so that you can see the object clearly.\n\n\n\n\nStereomicroscopes would be useful for observing a fungal colony from above, but this isn't often all that useful for identification purposes.\n\n\n\n\nBarlow lenses will help provide more magnification, I think at the expense of depth of field, though this shouldn't be much of a consideration for mounted specimens. Nikon's Microscopy U (https://www.microscopyu.com/techniques/stereomicroscopy/introduction-to-stereomicroscopy) has lots of really good information on stereomicroscopes, including Barlow lenses (they call them \"attachment\" lenses) that you might find useful in determining for yourself.", "answer_url": "https://biology.stackexchange.com/a/114421", "author": "bob1", "author_url": "https://biology.stackexchange.com/users/65284/bob1", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-04-01T19:34:17+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:32.233008+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/29e10377e709be0879cc174e9be11ba5513feaafd20aa842a20668af70c6d683_0.json", "raw_sha256": "535e870bb8fe62b3db0c0b66043a398cf2f6d26fcd7ad4a13a2a7e2a09999ee9", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/114428;114427;114412;114410;114399;114395;114391;114386;114385;114381;114378;114377;114376;114374;114372;114371;114370;114361;114354;114353;114348;114342;114331;114329;114324;114321;114319;114307;114305;114304;114299;114298;114295;114290;114281;114277;114273;114266;114256;114239;114238;114222;114216;114213;114211;114207;114197;114192;114185;114180;114178;114175;114174;114173;114172;114169;114161;114156;114155;114148;114145;114144;114139;114136;114135;114127;114119;114117;114114;114111;114110;114103;114098;114096;114094;114089;114085;114078;114076;114069;114067;114065;114058;114055;114048;114045;114038;114031;114028;114027;114025;114021;114020;114012;114006;113998;113997;113988;113986;113983/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 114372, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2024-04-01T19:34:17+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "19B282D2-E309-4C3F-8916-0C9DDC333CF5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/19B282D2-E309-4C3F-8916-0C9DDC333CF5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-04-01T20:22:57+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "B88230FD-ED4B-461B-AF76-B863073DA74E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B88230FD-ED4B-461B-AF76-B863073DA74E/view-source"}], "score": 1, "updated_at": "2024-04-01T20:22:57+00:00"}, {"answer_html": "for some things sure, like looking at surface structures in more detail, and with 200x power you might see micro structures including perhaps cells. but most fungal microscopy is done with a compound microscope of 400-1000x power, which allows you to clearly see cells and cell types, hyphae, and spores
\n", "answer_id": 114430, "answer_text": "for some things sure, like looking at surface structures in more detail, and with 200x power you might see micro structures including perhaps cells. but most fungal microscopy is done with a compound microscope of 400-1000x power, which allows you to clearly see cells and cell types, hyphae, and spores", "answer_url": "https://biology.stackexchange.com/a/114430", "author": "imrobert", "author_url": "https://biology.stackexchange.com/users/75153/imrobert", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-04-02T17:05:42+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:32.233008+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/29e10377e709be0879cc174e9be11ba5513feaafd20aa842a20668af70c6d683_0.json", "raw_sha256": "535e870bb8fe62b3db0c0b66043a398cf2f6d26fcd7ad4a13a2a7e2a09999ee9", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/114428;114427;114412;114410;114399;114395;114391;114386;114385;114381;114378;114377;114376;114374;114372;114371;114370;114361;114354;114353;114348;114342;114331;114329;114324;114321;114319;114307;114305;114304;114299;114298;114295;114290;114281;114277;114273;114266;114256;114239;114238;114222;114216;114213;114211;114207;114197;114192;114185;114180;114178;114175;114174;114173;114172;114169;114161;114156;114155;114148;114145;114144;114139;114136;114135;114127;114119;114117;114114;114111;114110;114103;114098;114096;114094;114089;114085;114078;114076;114069;114067;114065;114058;114055;114048;114045;114038;114031;114028;114027;114025;114021;114020;114012;114006;113998;113997;113988;113986;113983/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 114372, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "imrobert", "profile_url": "https://biology.stackexchange.com/users/75153/imrobert", "user_type": "registered"}, "created_at": "2024-04-02T17:05:42+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "4ACF5EF0-89C5-4532-8BE7-E11E12D8F28C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4ACF5EF0-89C5-4532-8BE7-E11E12D8F28C/view-source"}], "score": 1, "updated_at": "2024-04-02T17:05:42+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Bright-field_microscopy", "https://en.wikipedia.org/wiki/Condenser_(optics", "https://www.microscopyu.com/techniques/stereomicroscopy/introduction-to-stereomicroscopy"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:08.576606+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/1051d4f3e38449f1419d1973ac812b2286659e454a76f89a23fdaa941dfadddb_0.json", "raw_sha256": "583dcd577e20d33b29e9f8818a7ab6a1fab039c19ab79927e16096cff23fa61d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=7&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Evan Carroll", "question_author_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "question_author_user_type": "registered", "question_created_at": "2024-03-25T15:44:36+00:00", "question_html": "I have a need for a stereo microscope to do electronics work. I also have a strong desire for a stereo microscope to do mycology. I would like to be able to,
\nCould I take a trinocular stereo microscope and add a barrow lens that increases the zoom and decreases the focal length, and use it for biology as desired above? Some stereomicroscopes that have 2x Barlow advertise 225x, like the AmScope ZM2225NT.
\nWhat would the downsides of this approach be?
\n", "question_id": 114372, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I have a need for a stereo microscope to do electronics work. I also have a strong desire for a stereo microscope to do mycology. I would like to be able to,\n\n\n\n\n\nClearly identify mycelium, from bacterial contamination (no interest in bacteria).\n\n\n\n\nBe able to isolate spores of mycelium.\n\n\n\n\nIdentify dikaryon, from monokaryon\n\n\n\n\nIdeally, but not required be able to identify different types of mycelium that are undesirable (mold).\n\n\n\n\n\nCould I take a trinocular stereo microscope and add a barrow lens that increases the zoom and decreases the focal length, and use it for biology as desired above? Some stereomicroscopes that have 2x Barlow advertise 225x, like the AmScope ZM2225NT.\n\n\n\n\nWhat would the downsides of this approach be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-03-25T15:44:36+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "F04254FF-7335-4404-B8C2-75E45C2124B3", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/F04254FF-7335-4404-B8C2-75E45C2124B3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-04-01T18:24:53+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "BAF1EB83-29B2-48B5-B879-C0F2F5930EB5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/BAF1EB83-29B2-48B5-B879-C0F2F5930EB5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-04-01T19:56:58+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "954A76B9-A1FC-4F7E-92BD-3380590147B0", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/954A76B9-A1FC-4F7E-92BD-3380590147B0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/114372/can-a-stereo-microscope-be-used-for-mycology", "split": "validation", "split_group": "d04c9b21cea254d430cb9f9f76af9b5f77eaf95949a97f5a530292fe9e05ac0d", "tags": ["microbiology", "microscopy"], "thread_id": "biology:114372", "title": "Can a stereo microscope be used for mycology?"}} {"citation_context": "icroscopes will have this capability, but definitely not all. Those that do won't have a condenser (https://en.wikipedia.org/wiki/Condenser_(optics)), which converts the point illumination of the bulb into a parallel or converging beam, which is n", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Condenser_(optics", "kind": "external_url", "post_id": 114421, "post_url": "https://biology.stackexchange.com/a/114421", "product": "citations", "record_id": "Scientific-Citation-Graph:06b1213aa2fbf74c8ad6bc02", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "I'm not sure, but I suspect the answer here is a general "no".
\nThe reason I say this is that stereo microscopes typically do not have the magnifications needed to see the mycelium and other structures needed for ID of fungi clearly. For this you need a minimum of 100x (total magnification) and ideally 400x - 1000x magnification (that's 10x, 40x and 100x objective lenses on a compound microscope respectively). The one you mentioned from AmScope should just be capable of this range with a maximum magnification of 225x. I don't know if that magnification is with a Barlow fitted or not.
\nFungal ID is typically done by staining the hyphae and fruiting structures, mounting on a slide, and then observing these via transmitted light - brightfield illumination, with the light shining from the bottom, directly through the object. Some stereomicroscopes will have this capability, but definitely not all. Those that do won't have a condenser, which converts the point illumination of the bulb into a parallel or converging beam, which is needed to provide even illumination of the right angle for the objective lens being used so that you can see the object clearly.
\nStereomicroscopes would be useful for observing a fungal colony from above, but this isn't often all that useful for identification purposes.
\nBarlow lenses will help provide more magnification, I think at the expense of depth of field, though this shouldn't be much of a consideration for mounted specimens. Nikon's Microscopy U has lots of really good information on stereomicroscopes, including Barlow lenses (they call them "attachment" lenses) that you might find useful in determining for yourself.
\n", "answer_id": 114421, "answer_text": "I'm not sure, but I suspect the answer here is a general \"no\".\n\n\n\n\nThe reason I say this is that stereo microscopes typically do not have the magnifications needed to see the mycelium and other structures needed for ID of fungi clearly. For this you need a minimum of 100x (total magnification) and ideally 400x - 1000x magnification (that's 10x, 40x and 100x objective lenses on a compound microscope respectively). The one you mentioned from AmScope should just be capable of this range with a maximum magnification of 225x. I don't know if that magnification is with a Barlow fitted or not.\n\n\n\n\nFungal ID is typically done by staining the hyphae and fruiting structures, mounting on a slide, and then observing these via transmitted light - brightfield illumination (https://en.wikipedia.org/wiki/Bright-field_microscopy), with the light shining from the bottom, directly through the object. Some stereomicroscopes will have this capability, but definitely not all. Those that do won't have a condenser (https://en.wikipedia.org/wiki/Condenser_(optics)), which converts the point illumination of the bulb into a parallel or converging beam, which is needed to provide even illumination of the right angle for the objective lens being used so that you can see the object clearly.\n\n\n\n\nStereomicroscopes would be useful for observing a fungal colony from above, but this isn't often all that useful for identification purposes.\n\n\n\n\nBarlow lenses will help provide more magnification, I think at the expense of depth of field, though this shouldn't be much of a consideration for mounted specimens. Nikon's Microscopy U (https://www.microscopyu.com/techniques/stereomicroscopy/introduction-to-stereomicroscopy) has lots of really good information on stereomicroscopes, including Barlow lenses (they call them \"attachment\" lenses) that you might find useful in determining for yourself.", "answer_url": "https://biology.stackexchange.com/a/114421", "author": "bob1", "author_url": "https://biology.stackexchange.com/users/65284/bob1", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-04-01T19:34:17+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:32.233008+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/29e10377e709be0879cc174e9be11ba5513feaafd20aa842a20668af70c6d683_0.json", "raw_sha256": "535e870bb8fe62b3db0c0b66043a398cf2f6d26fcd7ad4a13a2a7e2a09999ee9", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/114428;114427;114412;114410;114399;114395;114391;114386;114385;114381;114378;114377;114376;114374;114372;114371;114370;114361;114354;114353;114348;114342;114331;114329;114324;114321;114319;114307;114305;114304;114299;114298;114295;114290;114281;114277;114273;114266;114256;114239;114238;114222;114216;114213;114211;114207;114197;114192;114185;114180;114178;114175;114174;114173;114172;114169;114161;114156;114155;114148;114145;114144;114139;114136;114135;114127;114119;114117;114114;114111;114110;114103;114098;114096;114094;114089;114085;114078;114076;114069;114067;114065;114058;114055;114048;114045;114038;114031;114028;114027;114025;114021;114020;114012;114006;113998;113997;113988;113986;113983/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 114372, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2024-04-01T19:34:17+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "19B282D2-E309-4C3F-8916-0C9DDC333CF5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/19B282D2-E309-4C3F-8916-0C9DDC333CF5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-04-01T20:22:57+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "B88230FD-ED4B-461B-AF76-B863073DA74E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B88230FD-ED4B-461B-AF76-B863073DA74E/view-source"}], "score": 1, "updated_at": "2024-04-01T20:22:57+00:00"}, {"answer_html": "for some things sure, like looking at surface structures in more detail, and with 200x power you might see micro structures including perhaps cells. but most fungal microscopy is done with a compound microscope of 400-1000x power, which allows you to clearly see cells and cell types, hyphae, and spores
\n", "answer_id": 114430, "answer_text": "for some things sure, like looking at surface structures in more detail, and with 200x power you might see micro structures including perhaps cells. but most fungal microscopy is done with a compound microscope of 400-1000x power, which allows you to clearly see cells and cell types, hyphae, and spores", "answer_url": "https://biology.stackexchange.com/a/114430", "author": "imrobert", "author_url": "https://biology.stackexchange.com/users/75153/imrobert", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-04-02T17:05:42+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:32.233008+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/29e10377e709be0879cc174e9be11ba5513feaafd20aa842a20668af70c6d683_0.json", "raw_sha256": "535e870bb8fe62b3db0c0b66043a398cf2f6d26fcd7ad4a13a2a7e2a09999ee9", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/114428;114427;114412;114410;114399;114395;114391;114386;114385;114381;114378;114377;114376;114374;114372;114371;114370;114361;114354;114353;114348;114342;114331;114329;114324;114321;114319;114307;114305;114304;114299;114298;114295;114290;114281;114277;114273;114266;114256;114239;114238;114222;114216;114213;114211;114207;114197;114192;114185;114180;114178;114175;114174;114173;114172;114169;114161;114156;114155;114148;114145;114144;114139;114136;114135;114127;114119;114117;114114;114111;114110;114103;114098;114096;114094;114089;114085;114078;114076;114069;114067;114065;114058;114055;114048;114045;114038;114031;114028;114027;114025;114021;114020;114012;114006;113998;113997;113988;113986;113983/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 114372, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "imrobert", "profile_url": "https://biology.stackexchange.com/users/75153/imrobert", "user_type": "registered"}, "created_at": "2024-04-02T17:05:42+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "4ACF5EF0-89C5-4532-8BE7-E11E12D8F28C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4ACF5EF0-89C5-4532-8BE7-E11E12D8F28C/view-source"}], "score": 1, "updated_at": "2024-04-02T17:05:42+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Bright-field_microscopy", "https://en.wikipedia.org/wiki/Condenser_(optics", "https://www.microscopyu.com/techniques/stereomicroscopy/introduction-to-stereomicroscopy"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:08.576606+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/1051d4f3e38449f1419d1973ac812b2286659e454a76f89a23fdaa941dfadddb_0.json", "raw_sha256": "583dcd577e20d33b29e9f8818a7ab6a1fab039c19ab79927e16096cff23fa61d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=7&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Evan Carroll", "question_author_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "question_author_user_type": "registered", "question_created_at": "2024-03-25T15:44:36+00:00", "question_html": "I have a need for a stereo microscope to do electronics work. I also have a strong desire for a stereo microscope to do mycology. I would like to be able to,
\nCould I take a trinocular stereo microscope and add a barrow lens that increases the zoom and decreases the focal length, and use it for biology as desired above? Some stereomicroscopes that have 2x Barlow advertise 225x, like the AmScope ZM2225NT.
\nWhat would the downsides of this approach be?
\n", "question_id": 114372, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I have a need for a stereo microscope to do electronics work. I also have a strong desire for a stereo microscope to do mycology. I would like to be able to,\n\n\n\n\n\nClearly identify mycelium, from bacterial contamination (no interest in bacteria).\n\n\n\n\nBe able to isolate spores of mycelium.\n\n\n\n\nIdentify dikaryon, from monokaryon\n\n\n\n\nIdeally, but not required be able to identify different types of mycelium that are undesirable (mold).\n\n\n\n\n\nCould I take a trinocular stereo microscope and add a barrow lens that increases the zoom and decreases the focal length, and use it for biology as desired above? Some stereomicroscopes that have 2x Barlow advertise 225x, like the AmScope ZM2225NT.\n\n\n\n\nWhat would the downsides of this approach be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-03-25T15:44:36+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "F04254FF-7335-4404-B8C2-75E45C2124B3", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/F04254FF-7335-4404-B8C2-75E45C2124B3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-04-01T18:24:53+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "BAF1EB83-29B2-48B5-B879-C0F2F5930EB5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/BAF1EB83-29B2-48B5-B879-C0F2F5930EB5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-04-01T19:56:58+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "954A76B9-A1FC-4F7E-92BD-3380590147B0", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/954A76B9-A1FC-4F7E-92BD-3380590147B0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/114372/can-a-stereo-microscope-be-used-for-mycology", "split": "validation", "split_group": "d04c9b21cea254d430cb9f9f76af9b5f77eaf95949a97f5a530292fe9e05ac0d", "tags": ["microbiology", "microscopy"], "thread_id": "biology:114372", "title": "Can a stereo microscope be used for mycology?"}} {"citation_context": "ield, though this shouldn't be much of a consideration for mounted specimens. Nikon's Microscopy U (https://www.microscopyu.com/techniques/stereomicroscopy/introduction-to-stereomicroscopy) has lots of really good information on stereomicroscopes, including Barlow lenses (they call them ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.microscopyu.com/techniques/stereomicroscopy/introduction-to-stereomicroscopy", "kind": "external_url", "post_id": 114421, "post_url": "https://biology.stackexchange.com/a/114421", "product": "citations", "record_id": "Scientific-Citation-Graph:fe361e9a8fef6a855f552549", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "I'm not sure, but I suspect the answer here is a general "no".
\nThe reason I say this is that stereo microscopes typically do not have the magnifications needed to see the mycelium and other structures needed for ID of fungi clearly. For this you need a minimum of 100x (total magnification) and ideally 400x - 1000x magnification (that's 10x, 40x and 100x objective lenses on a compound microscope respectively). The one you mentioned from AmScope should just be capable of this range with a maximum magnification of 225x. I don't know if that magnification is with a Barlow fitted or not.
\nFungal ID is typically done by staining the hyphae and fruiting structures, mounting on a slide, and then observing these via transmitted light - brightfield illumination, with the light shining from the bottom, directly through the object. Some stereomicroscopes will have this capability, but definitely not all. Those that do won't have a condenser, which converts the point illumination of the bulb into a parallel or converging beam, which is needed to provide even illumination of the right angle for the objective lens being used so that you can see the object clearly.
\nStereomicroscopes would be useful for observing a fungal colony from above, but this isn't often all that useful for identification purposes.
\nBarlow lenses will help provide more magnification, I think at the expense of depth of field, though this shouldn't be much of a consideration for mounted specimens. Nikon's Microscopy U has lots of really good information on stereomicroscopes, including Barlow lenses (they call them "attachment" lenses) that you might find useful in determining for yourself.
\n", "answer_id": 114421, "answer_text": "I'm not sure, but I suspect the answer here is a general \"no\".\n\n\n\n\nThe reason I say this is that stereo microscopes typically do not have the magnifications needed to see the mycelium and other structures needed for ID of fungi clearly. For this you need a minimum of 100x (total magnification) and ideally 400x - 1000x magnification (that's 10x, 40x and 100x objective lenses on a compound microscope respectively). The one you mentioned from AmScope should just be capable of this range with a maximum magnification of 225x. I don't know if that magnification is with a Barlow fitted or not.\n\n\n\n\nFungal ID is typically done by staining the hyphae and fruiting structures, mounting on a slide, and then observing these via transmitted light - brightfield illumination (https://en.wikipedia.org/wiki/Bright-field_microscopy), with the light shining from the bottom, directly through the object. Some stereomicroscopes will have this capability, but definitely not all. Those that do won't have a condenser (https://en.wikipedia.org/wiki/Condenser_(optics)), which converts the point illumination of the bulb into a parallel or converging beam, which is needed to provide even illumination of the right angle for the objective lens being used so that you can see the object clearly.\n\n\n\n\nStereomicroscopes would be useful for observing a fungal colony from above, but this isn't often all that useful for identification purposes.\n\n\n\n\nBarlow lenses will help provide more magnification, I think at the expense of depth of field, though this shouldn't be much of a consideration for mounted specimens. Nikon's Microscopy U (https://www.microscopyu.com/techniques/stereomicroscopy/introduction-to-stereomicroscopy) has lots of really good information on stereomicroscopes, including Barlow lenses (they call them \"attachment\" lenses) that you might find useful in determining for yourself.", "answer_url": "https://biology.stackexchange.com/a/114421", "author": "bob1", "author_url": "https://biology.stackexchange.com/users/65284/bob1", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-04-01T19:34:17+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:32.233008+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/29e10377e709be0879cc174e9be11ba5513feaafd20aa842a20668af70c6d683_0.json", "raw_sha256": "535e870bb8fe62b3db0c0b66043a398cf2f6d26fcd7ad4a13a2a7e2a09999ee9", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/114428;114427;114412;114410;114399;114395;114391;114386;114385;114381;114378;114377;114376;114374;114372;114371;114370;114361;114354;114353;114348;114342;114331;114329;114324;114321;114319;114307;114305;114304;114299;114298;114295;114290;114281;114277;114273;114266;114256;114239;114238;114222;114216;114213;114211;114207;114197;114192;114185;114180;114178;114175;114174;114173;114172;114169;114161;114156;114155;114148;114145;114144;114139;114136;114135;114127;114119;114117;114114;114111;114110;114103;114098;114096;114094;114089;114085;114078;114076;114069;114067;114065;114058;114055;114048;114045;114038;114031;114028;114027;114025;114021;114020;114012;114006;113998;113997;113988;113986;113983/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 114372, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2024-04-01T19:34:17+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "19B282D2-E309-4C3F-8916-0C9DDC333CF5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/19B282D2-E309-4C3F-8916-0C9DDC333CF5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-04-01T20:22:57+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "B88230FD-ED4B-461B-AF76-B863073DA74E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B88230FD-ED4B-461B-AF76-B863073DA74E/view-source"}], "score": 1, "updated_at": "2024-04-01T20:22:57+00:00"}, {"answer_html": "for some things sure, like looking at surface structures in more detail, and with 200x power you might see micro structures including perhaps cells. but most fungal microscopy is done with a compound microscope of 400-1000x power, which allows you to clearly see cells and cell types, hyphae, and spores
\n", "answer_id": 114430, "answer_text": "for some things sure, like looking at surface structures in more detail, and with 200x power you might see micro structures including perhaps cells. but most fungal microscopy is done with a compound microscope of 400-1000x power, which allows you to clearly see cells and cell types, hyphae, and spores", "answer_url": "https://biology.stackexchange.com/a/114430", "author": "imrobert", "author_url": "https://biology.stackexchange.com/users/75153/imrobert", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2024-04-02T17:05:42+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:32.233008+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/29e10377e709be0879cc174e9be11ba5513feaafd20aa842a20668af70c6d683_0.json", "raw_sha256": "535e870bb8fe62b3db0c0b66043a398cf2f6d26fcd7ad4a13a2a7e2a09999ee9", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/114428;114427;114412;114410;114399;114395;114391;114386;114385;114381;114378;114377;114376;114374;114372;114371;114370;114361;114354;114353;114348;114342;114331;114329;114324;114321;114319;114307;114305;114304;114299;114298;114295;114290;114281;114277;114273;114266;114256;114239;114238;114222;114216;114213;114211;114207;114197;114192;114185;114180;114178;114175;114174;114173;114172;114169;114161;114156;114155;114148;114145;114144;114139;114136;114135;114127;114119;114117;114114;114111;114110;114103;114098;114096;114094;114089;114085;114078;114076;114069;114067;114065;114058;114055;114048;114045;114038;114031;114028;114027;114025;114021;114020;114012;114006;113998;113997;113988;113986;113983/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 114372, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "imrobert", "profile_url": "https://biology.stackexchange.com/users/75153/imrobert", "user_type": "registered"}, "created_at": "2024-04-02T17:05:42+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "4ACF5EF0-89C5-4532-8BE7-E11E12D8F28C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4ACF5EF0-89C5-4532-8BE7-E11E12D8F28C/view-source"}], "score": 1, "updated_at": "2024-04-02T17:05:42+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Bright-field_microscopy", "https://en.wikipedia.org/wiki/Condenser_(optics", "https://www.microscopyu.com/techniques/stereomicroscopy/introduction-to-stereomicroscopy"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:08.576606+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/1051d4f3e38449f1419d1973ac812b2286659e454a76f89a23fdaa941dfadddb_0.json", "raw_sha256": "583dcd577e20d33b29e9f8818a7ab6a1fab039c19ab79927e16096cff23fa61d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=7&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Evan Carroll", "question_author_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "question_author_user_type": "registered", "question_created_at": "2024-03-25T15:44:36+00:00", "question_html": "I have a need for a stereo microscope to do electronics work. I also have a strong desire for a stereo microscope to do mycology. I would like to be able to,
\nCould I take a trinocular stereo microscope and add a barrow lens that increases the zoom and decreases the focal length, and use it for biology as desired above? Some stereomicroscopes that have 2x Barlow advertise 225x, like the AmScope ZM2225NT.
\nWhat would the downsides of this approach be?
\n", "question_id": 114372, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I have a need for a stereo microscope to do electronics work. I also have a strong desire for a stereo microscope to do mycology. I would like to be able to,\n\n\n\n\n\nClearly identify mycelium, from bacterial contamination (no interest in bacteria).\n\n\n\n\nBe able to isolate spores of mycelium.\n\n\n\n\nIdentify dikaryon, from monokaryon\n\n\n\n\nIdeally, but not required be able to identify different types of mycelium that are undesirable (mold).\n\n\n\n\n\nCould I take a trinocular stereo microscope and add a barrow lens that increases the zoom and decreases the focal length, and use it for biology as desired above? Some stereomicroscopes that have 2x Barlow advertise 225x, like the AmScope ZM2225NT.\n\n\n\n\nWhat would the downsides of this approach be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-03-25T15:44:36+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "F04254FF-7335-4404-B8C2-75E45C2124B3", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/F04254FF-7335-4404-B8C2-75E45C2124B3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-04-01T18:24:53+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "BAF1EB83-29B2-48B5-B879-C0F2F5930EB5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/BAF1EB83-29B2-48B5-B879-C0F2F5930EB5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Evan Carroll", "profile_url": "https://biology.stackexchange.com/users/8241/evan-carroll", "user_type": "registered"}, "created_at": "2024-04-01T19:56:58+00:00", "raw_file": "raw/codex_api_v1/22e8417b315063b6d3b906d11f4422eb4ac33f788b9058bddc9dd7bfc046cafc_1790824071906161300_0.json", "raw_sha256": "84dcb0018b97f3e9f1f4320ffea98714a55b6054974fc678a4c6cac9e312e078", "revision_guid": "954A76B9-A1FC-4F7E-92BD-3380590147B0", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/954A76B9-A1FC-4F7E-92BD-3380590147B0/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/114372/can-a-stereo-microscope-be-used-for-mycology", "split": "validation", "split_group": "d04c9b21cea254d430cb9f9f76af9b5f77eaf95949a97f5a530292fe9e05ac0d", "tags": ["microbiology", "microscopy"], "thread_id": "biology:114372", "title": "Can a stereo microscope be used for mycology?"}} {"citation_context": "eet smell could indicate cockroaches, this is often described as smelling like stale oil or grease (https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/), but is sometimes described as sweet. Cockroaches produce two types of droppings - small black spe", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/", "kind": "external_url", "post_id": 119290, "post_url": "https://biology.stackexchange.com/a/119290", "product": "citations", "record_id": "Scientific-Citation-Graph:bc80f44b8eee33f12dc88bae", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.
\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.
\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease, but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.
\n
\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260
The other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator:
\n
\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/
As to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.
\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.
\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.
\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.
\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!
\n", "answer_id": 119290, "answer_text": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.\n\n\n\n\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.\n\n\n\n\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease (https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/), but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (https://en.wikipedia.org/wiki/German_cockroach) (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.\n\n\n\n\n[image: American cockroach and droppings; source: https://i.sstatic.net/XOYdeTcg.png] (https://i.sstatic.net/XOYdeTcg.png)\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260 (https://commons.wikimedia.org/w/index.php?curid=21887260) \n\n\n\n\nThe other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator (https://thebuginator.com/roach-poop/):\n\n\n\n\n[image: Orange cockroach with liquid feces; source: https://i.sstatic.net/GPuXwqUQ.png] (https://i.sstatic.net/GPuXwqUQ.png)\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/ (https://thebuginator.com/roach-poop/) \n\n\n\n\nAs to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.\n\n\n\n\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.\n\n\n\n\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.\n\n\n\n\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.\n\n\n\n\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!", "answer_url": "https://biology.stackexchange.com/a/119290", "author": "bob1", "author_url": "https://biology.stackexchange.com/users/65284/bob1", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-01-28T20:23:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:14.203473+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bc31fe4e1e84f43ae95f846a38e90acc9e22beb08e25c5d964f94cb8f2d4bfcb_0.json", "raw_sha256": "d7cf716376a9764909548809f10c8760f535f0ca4093eb29d910aae44edf1878", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/119725;119721;119720;119695;119675;119670;119661;119648;119640;119639;119635;119631;119628;119607;119605;119601;119598;119586;119582;119579;119577;119565;119561;119560;119542;119539;119529;119527;119522;119518;119506;119501;119497;119489;119487;119479;119465;119455;119453;119450;119444;119439;119434;119430;119421;119416;119404;119399;119398;119377;119376;119369;119362;119361;119355;119353;119350;119342;119340;119328;119326;119321;119317;119313;119312;119311;119306;119304;119287;119275;119273;119270;119268;119267;119260;119256;119251;119248;119238;119237;119235;119231;119227;119221;119212;119211;119209;119207;119201;119195;119193;119190;119185;119180;118180;118175;118172;118168;118158;118155/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 119287, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2026-01-28T20:23:28+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "A51BBA80-6DD2-424E-971B-0E5DE5C9140F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/A51BBA80-6DD2-424E-971B-0E5DE5C9140F/view-source"}], "score": 3, "updated_at": "2026-01-28T20:23:28+00:00"}], "domain": "biology", "external_links": ["https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/", "https://commons.wikimedia.org/w/index.php?curid=21887260", "https://en.wikipedia.org/wiki/German_cockroach", "https://i.sstatic.net/GPuXwqUQ.png", "https://i.sstatic.net/XOYdeTcg.png", "https://thebuginator.com/roach-poop/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:02:59.816967+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/55bbc2350ddd64077cfc2cba10ad5323a3aabdbe06356ba63f9b4f2161e7b47f_0.json", "raw_sha256": "816eaaa302266f8cc647e663e24b4d7ecdb9f8cc125751c689d3329286131873", "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=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Laura", "question_author_url": "https://biology.stackexchange.com/users/124506/laura", "question_author_user_type": "registered", "question_created_at": "2026-01-27T11:03:02+00:00", "question_html": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.
\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.
\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.
\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.
\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.
\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.
\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?
\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.
\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.
\n", "question_id": 119287, "question_license": "CC BY-SA 4.0", "question_score": 7, "question_text": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.\n\n\n\n\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.\n\n\n\n\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.\n\n\n\n\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.\n\n\n\n\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.\n\n\n\n\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.\n\n\n\n\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?\n\n\n\n\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.\n\n\n\n\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-27T11:03:02+00:00", "raw_file": "raw/codex_api_v1/91e75308ae5d4e2adbc966eeaa33ee31183f3dcee03ede8f8105b7c8973deeb6_1790824169436990200_0.json", "raw_sha256": "4ecc6c39f2269357dfd5478f8b88ef2f2e3d1b91841927b9ef870a736f612c14", "revision_guid": "B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-29T21:43:59+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "BE219B8F-F166-482A-8322-A78F7B8BF490", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/BE219B8F-F166-482A-8322-A78F7B8BF490/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/119287/black-solid-colonies-of-microorganisms-on-plastics", "split": "validation", "split_group": "932c447eff16da26de567f7cc490902604899b97a7193869278c9ce692f6fe04", "tags": ["species-identification", "microbiology", "bacteriology", "yeast"], "thread_id": "biology:119287", "title": "Black solid colonies of microorganisms on plastics"}} {"citation_context": "png] (https://i.sstatic.net/XOYdeTcg.png)\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260 (https://commons.wikimedia.org/w/index.php?curid=21887260) \n\n\n\n\nThe other type of dropping is a dar", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://commons.wikimedia.org/w/index.php?curid=21887260", "kind": "external_url", "post_id": 119290, "post_url": "https://biology.stackexchange.com/a/119290", "product": "citations", "record_id": "Scientific-Citation-Graph:10f72e9ff32c45bd150635fc", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.
\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.
\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease, but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.
\n
\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260
The other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator:
\n
\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/
As to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.
\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.
\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.
\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.
\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!
\n", "answer_id": 119290, "answer_text": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.\n\n\n\n\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.\n\n\n\n\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease (https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/), but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (https://en.wikipedia.org/wiki/German_cockroach) (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.\n\n\n\n\n[image: American cockroach and droppings; source: https://i.sstatic.net/XOYdeTcg.png] (https://i.sstatic.net/XOYdeTcg.png)\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260 (https://commons.wikimedia.org/w/index.php?curid=21887260) \n\n\n\n\nThe other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator (https://thebuginator.com/roach-poop/):\n\n\n\n\n[image: Orange cockroach with liquid feces; source: https://i.sstatic.net/GPuXwqUQ.png] (https://i.sstatic.net/GPuXwqUQ.png)\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/ (https://thebuginator.com/roach-poop/) \n\n\n\n\nAs to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.\n\n\n\n\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.\n\n\n\n\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.\n\n\n\n\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.\n\n\n\n\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!", "answer_url": "https://biology.stackexchange.com/a/119290", "author": "bob1", "author_url": "https://biology.stackexchange.com/users/65284/bob1", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-01-28T20:23:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:14.203473+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bc31fe4e1e84f43ae95f846a38e90acc9e22beb08e25c5d964f94cb8f2d4bfcb_0.json", "raw_sha256": "d7cf716376a9764909548809f10c8760f535f0ca4093eb29d910aae44edf1878", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/119725;119721;119720;119695;119675;119670;119661;119648;119640;119639;119635;119631;119628;119607;119605;119601;119598;119586;119582;119579;119577;119565;119561;119560;119542;119539;119529;119527;119522;119518;119506;119501;119497;119489;119487;119479;119465;119455;119453;119450;119444;119439;119434;119430;119421;119416;119404;119399;119398;119377;119376;119369;119362;119361;119355;119353;119350;119342;119340;119328;119326;119321;119317;119313;119312;119311;119306;119304;119287;119275;119273;119270;119268;119267;119260;119256;119251;119248;119238;119237;119235;119231;119227;119221;119212;119211;119209;119207;119201;119195;119193;119190;119185;119180;118180;118175;118172;118168;118158;118155/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 119287, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2026-01-28T20:23:28+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "A51BBA80-6DD2-424E-971B-0E5DE5C9140F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/A51BBA80-6DD2-424E-971B-0E5DE5C9140F/view-source"}], "score": 3, "updated_at": "2026-01-28T20:23:28+00:00"}], "domain": "biology", "external_links": ["https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/", "https://commons.wikimedia.org/w/index.php?curid=21887260", "https://en.wikipedia.org/wiki/German_cockroach", "https://i.sstatic.net/GPuXwqUQ.png", "https://i.sstatic.net/XOYdeTcg.png", "https://thebuginator.com/roach-poop/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:02:59.816967+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/55bbc2350ddd64077cfc2cba10ad5323a3aabdbe06356ba63f9b4f2161e7b47f_0.json", "raw_sha256": "816eaaa302266f8cc647e663e24b4d7ecdb9f8cc125751c689d3329286131873", "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=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Laura", "question_author_url": "https://biology.stackexchange.com/users/124506/laura", "question_author_user_type": "registered", "question_created_at": "2026-01-27T11:03:02+00:00", "question_html": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.
\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.
\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.
\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.
\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.
\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.
\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?
\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.
\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.
\n", "question_id": 119287, "question_license": "CC BY-SA 4.0", "question_score": 7, "question_text": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.\n\n\n\n\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.\n\n\n\n\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.\n\n\n\n\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.\n\n\n\n\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.\n\n\n\n\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.\n\n\n\n\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?\n\n\n\n\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.\n\n\n\n\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-27T11:03:02+00:00", "raw_file": "raw/codex_api_v1/91e75308ae5d4e2adbc966eeaa33ee31183f3dcee03ede8f8105b7c8973deeb6_1790824169436990200_0.json", "raw_sha256": "4ecc6c39f2269357dfd5478f8b88ef2f2e3d1b91841927b9ef870a736f612c14", "revision_guid": "B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-29T21:43:59+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "BE219B8F-F166-482A-8322-A78F7B8BF490", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/BE219B8F-F166-482A-8322-A78F7B8BF490/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/119287/black-solid-colonies-of-microorganisms-on-plastics", "split": "validation", "split_group": "932c447eff16da26de567f7cc490902604899b97a7193869278c9ce692f6fe04", "tags": ["species-identification", "microbiology", "bacteriology", "yeast"], "thread_id": "biology:119287", "title": "Black solid colonies of microorganisms on plastics"}} {"citation_context": "e different sizes depending on the species of roach. Large species, such as the American cockroach (https://en.wikipedia.org/wiki/German_cockroach) (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a simi", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/German_cockroach", "kind": "external_url", "post_id": 119290, "post_url": "https://biology.stackexchange.com/a/119290", "product": "citations", "record_id": "Scientific-Citation-Graph:e9893bda89ebe3915cd6cdb6", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.
\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.
\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease, but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.
\n
\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260
The other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator:
\n
\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/
As to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.
\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.
\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.
\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.
\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!
\n", "answer_id": 119290, "answer_text": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.\n\n\n\n\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.\n\n\n\n\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease (https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/), but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (https://en.wikipedia.org/wiki/German_cockroach) (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.\n\n\n\n\n[image: American cockroach and droppings; source: https://i.sstatic.net/XOYdeTcg.png] (https://i.sstatic.net/XOYdeTcg.png)\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260 (https://commons.wikimedia.org/w/index.php?curid=21887260) \n\n\n\n\nThe other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator (https://thebuginator.com/roach-poop/):\n\n\n\n\n[image: Orange cockroach with liquid feces; source: https://i.sstatic.net/GPuXwqUQ.png] (https://i.sstatic.net/GPuXwqUQ.png)\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/ (https://thebuginator.com/roach-poop/) \n\n\n\n\nAs to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.\n\n\n\n\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.\n\n\n\n\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.\n\n\n\n\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.\n\n\n\n\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!", "answer_url": "https://biology.stackexchange.com/a/119290", "author": "bob1", "author_url": "https://biology.stackexchange.com/users/65284/bob1", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-01-28T20:23:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:14.203473+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bc31fe4e1e84f43ae95f846a38e90acc9e22beb08e25c5d964f94cb8f2d4bfcb_0.json", "raw_sha256": "d7cf716376a9764909548809f10c8760f535f0ca4093eb29d910aae44edf1878", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/119725;119721;119720;119695;119675;119670;119661;119648;119640;119639;119635;119631;119628;119607;119605;119601;119598;119586;119582;119579;119577;119565;119561;119560;119542;119539;119529;119527;119522;119518;119506;119501;119497;119489;119487;119479;119465;119455;119453;119450;119444;119439;119434;119430;119421;119416;119404;119399;119398;119377;119376;119369;119362;119361;119355;119353;119350;119342;119340;119328;119326;119321;119317;119313;119312;119311;119306;119304;119287;119275;119273;119270;119268;119267;119260;119256;119251;119248;119238;119237;119235;119231;119227;119221;119212;119211;119209;119207;119201;119195;119193;119190;119185;119180;118180;118175;118172;118168;118158;118155/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 119287, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2026-01-28T20:23:28+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "A51BBA80-6DD2-424E-971B-0E5DE5C9140F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/A51BBA80-6DD2-424E-971B-0E5DE5C9140F/view-source"}], "score": 3, "updated_at": "2026-01-28T20:23:28+00:00"}], "domain": "biology", "external_links": ["https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/", "https://commons.wikimedia.org/w/index.php?curid=21887260", "https://en.wikipedia.org/wiki/German_cockroach", "https://i.sstatic.net/GPuXwqUQ.png", "https://i.sstatic.net/XOYdeTcg.png", "https://thebuginator.com/roach-poop/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:02:59.816967+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/55bbc2350ddd64077cfc2cba10ad5323a3aabdbe06356ba63f9b4f2161e7b47f_0.json", "raw_sha256": "816eaaa302266f8cc647e663e24b4d7ecdb9f8cc125751c689d3329286131873", "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=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Laura", "question_author_url": "https://biology.stackexchange.com/users/124506/laura", "question_author_user_type": "registered", "question_created_at": "2026-01-27T11:03:02+00:00", "question_html": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.
\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.
\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.
\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.
\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.
\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.
\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?
\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.
\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.
\n", "question_id": 119287, "question_license": "CC BY-SA 4.0", "question_score": 7, "question_text": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.\n\n\n\n\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.\n\n\n\n\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.\n\n\n\n\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.\n\n\n\n\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.\n\n\n\n\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.\n\n\n\n\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?\n\n\n\n\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.\n\n\n\n\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-27T11:03:02+00:00", "raw_file": "raw/codex_api_v1/91e75308ae5d4e2adbc966eeaa33ee31183f3dcee03ede8f8105b7c8973deeb6_1790824169436990200_0.json", "raw_sha256": "4ecc6c39f2269357dfd5478f8b88ef2f2e3d1b91841927b9ef870a736f612c14", "revision_guid": "B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-29T21:43:59+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "BE219B8F-F166-482A-8322-A78F7B8BF490", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/BE219B8F-F166-482A-8322-A78F7B8BF490/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/119287/black-solid-colonies-of-microorganisms-on-plastics", "split": "validation", "split_group": "932c447eff16da26de567f7cc490902604899b97a7193869278c9ce692f6fe04", "tags": ["species-identification", "microbiology", "bacteriology", "yeast"], "thread_id": "biology:119287", "title": "Black solid colonies of microorganisms on plastics"}} {"citation_context": "tor (https://thebuginator.com/roach-poop/):\n\n\n\n\n[image: Orange cockroach with liquid feces; source: https://i.sstatic.net/GPuXwqUQ.png] (https://i.sstatic.net/GPuXwqUQ.png)\n Image attribution: The Buginator. https://thebuginator.com/r", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/GPuXwqUQ.png", "kind": "external_url", "post_id": 119290, "post_url": "https://biology.stackexchange.com/a/119290", "product": "citations", "record_id": "Scientific-Citation-Graph:60c90735740fe202f43e675a", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.
\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.
\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease, but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.
\n
\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260
The other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator:
\n
\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/
As to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.
\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.
\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.
\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.
\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!
\n", "answer_id": 119290, "answer_text": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.\n\n\n\n\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.\n\n\n\n\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease (https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/), but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (https://en.wikipedia.org/wiki/German_cockroach) (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.\n\n\n\n\n[image: American cockroach and droppings; source: https://i.sstatic.net/XOYdeTcg.png] (https://i.sstatic.net/XOYdeTcg.png)\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260 (https://commons.wikimedia.org/w/index.php?curid=21887260) \n\n\n\n\nThe other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator (https://thebuginator.com/roach-poop/):\n\n\n\n\n[image: Orange cockroach with liquid feces; source: https://i.sstatic.net/GPuXwqUQ.png] (https://i.sstatic.net/GPuXwqUQ.png)\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/ (https://thebuginator.com/roach-poop/) \n\n\n\n\nAs to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.\n\n\n\n\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.\n\n\n\n\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.\n\n\n\n\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.\n\n\n\n\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!", "answer_url": "https://biology.stackexchange.com/a/119290", "author": "bob1", "author_url": "https://biology.stackexchange.com/users/65284/bob1", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-01-28T20:23:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:14.203473+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bc31fe4e1e84f43ae95f846a38e90acc9e22beb08e25c5d964f94cb8f2d4bfcb_0.json", "raw_sha256": "d7cf716376a9764909548809f10c8760f535f0ca4093eb29d910aae44edf1878", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/119725;119721;119720;119695;119675;119670;119661;119648;119640;119639;119635;119631;119628;119607;119605;119601;119598;119586;119582;119579;119577;119565;119561;119560;119542;119539;119529;119527;119522;119518;119506;119501;119497;119489;119487;119479;119465;119455;119453;119450;119444;119439;119434;119430;119421;119416;119404;119399;119398;119377;119376;119369;119362;119361;119355;119353;119350;119342;119340;119328;119326;119321;119317;119313;119312;119311;119306;119304;119287;119275;119273;119270;119268;119267;119260;119256;119251;119248;119238;119237;119235;119231;119227;119221;119212;119211;119209;119207;119201;119195;119193;119190;119185;119180;118180;118175;118172;118168;118158;118155/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 119287, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2026-01-28T20:23:28+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "A51BBA80-6DD2-424E-971B-0E5DE5C9140F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/A51BBA80-6DD2-424E-971B-0E5DE5C9140F/view-source"}], "score": 3, "updated_at": "2026-01-28T20:23:28+00:00"}], "domain": "biology", "external_links": ["https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/", "https://commons.wikimedia.org/w/index.php?curid=21887260", "https://en.wikipedia.org/wiki/German_cockroach", "https://i.sstatic.net/GPuXwqUQ.png", "https://i.sstatic.net/XOYdeTcg.png", "https://thebuginator.com/roach-poop/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:02:59.816967+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/55bbc2350ddd64077cfc2cba10ad5323a3aabdbe06356ba63f9b4f2161e7b47f_0.json", "raw_sha256": "816eaaa302266f8cc647e663e24b4d7ecdb9f8cc125751c689d3329286131873", "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=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Laura", "question_author_url": "https://biology.stackexchange.com/users/124506/laura", "question_author_user_type": "registered", "question_created_at": "2026-01-27T11:03:02+00:00", "question_html": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.
\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.
\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.
\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.
\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.
\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.
\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?
\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.
\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.
\n", "question_id": 119287, "question_license": "CC BY-SA 4.0", "question_score": 7, "question_text": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.\n\n\n\n\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.\n\n\n\n\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.\n\n\n\n\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.\n\n\n\n\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.\n\n\n\n\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.\n\n\n\n\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?\n\n\n\n\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.\n\n\n\n\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-27T11:03:02+00:00", "raw_file": "raw/codex_api_v1/91e75308ae5d4e2adbc966eeaa33ee31183f3dcee03ede8f8105b7c8973deeb6_1790824169436990200_0.json", "raw_sha256": "4ecc6c39f2269357dfd5478f8b88ef2f2e3d1b91841927b9ef870a736f612c14", "revision_guid": "B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-29T21:43:59+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "BE219B8F-F166-482A-8322-A78F7B8BF490", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/BE219B8F-F166-482A-8322-A78F7B8BF490/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/119287/black-solid-colonies-of-microorganisms-on-plastics", "split": "validation", "split_group": "932c447eff16da26de567f7cc490902604899b97a7193869278c9ce692f6fe04", "tags": ["species-identification", "microbiology", "bacteriology", "yeast"], "thread_id": "biology:119287", "title": "Black solid colonies of microorganisms on plastics"}} {"citation_context": "drains enter walls or anywhere damp and dark.\n\n\n\n\n[image: American cockroach and droppings; source: https://i.sstatic.net/XOYdeTcg.png] (https://i.sstatic.net/XOYdeTcg.png)\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, htt", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/XOYdeTcg.png", "kind": "external_url", "post_id": 119290, "post_url": "https://biology.stackexchange.com/a/119290", "product": "citations", "record_id": "Scientific-Citation-Graph:f3fb4f582ab558d64964984c", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.
\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.
\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease, but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.
\n
\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260
The other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator:
\n
\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/
As to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.
\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.
\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.
\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.
\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!
\n", "answer_id": 119290, "answer_text": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.\n\n\n\n\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.\n\n\n\n\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease (https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/), but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (https://en.wikipedia.org/wiki/German_cockroach) (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.\n\n\n\n\n[image: American cockroach and droppings; source: https://i.sstatic.net/XOYdeTcg.png] (https://i.sstatic.net/XOYdeTcg.png)\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260 (https://commons.wikimedia.org/w/index.php?curid=21887260) \n\n\n\n\nThe other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator (https://thebuginator.com/roach-poop/):\n\n\n\n\n[image: Orange cockroach with liquid feces; source: https://i.sstatic.net/GPuXwqUQ.png] (https://i.sstatic.net/GPuXwqUQ.png)\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/ (https://thebuginator.com/roach-poop/) \n\n\n\n\nAs to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.\n\n\n\n\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.\n\n\n\n\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.\n\n\n\n\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.\n\n\n\n\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!", "answer_url": "https://biology.stackexchange.com/a/119290", "author": "bob1", "author_url": "https://biology.stackexchange.com/users/65284/bob1", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-01-28T20:23:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:14.203473+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bc31fe4e1e84f43ae95f846a38e90acc9e22beb08e25c5d964f94cb8f2d4bfcb_0.json", "raw_sha256": "d7cf716376a9764909548809f10c8760f535f0ca4093eb29d910aae44edf1878", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/119725;119721;119720;119695;119675;119670;119661;119648;119640;119639;119635;119631;119628;119607;119605;119601;119598;119586;119582;119579;119577;119565;119561;119560;119542;119539;119529;119527;119522;119518;119506;119501;119497;119489;119487;119479;119465;119455;119453;119450;119444;119439;119434;119430;119421;119416;119404;119399;119398;119377;119376;119369;119362;119361;119355;119353;119350;119342;119340;119328;119326;119321;119317;119313;119312;119311;119306;119304;119287;119275;119273;119270;119268;119267;119260;119256;119251;119248;119238;119237;119235;119231;119227;119221;119212;119211;119209;119207;119201;119195;119193;119190;119185;119180;118180;118175;118172;118168;118158;118155/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 119287, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2026-01-28T20:23:28+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "A51BBA80-6DD2-424E-971B-0E5DE5C9140F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/A51BBA80-6DD2-424E-971B-0E5DE5C9140F/view-source"}], "score": 3, "updated_at": "2026-01-28T20:23:28+00:00"}], "domain": "biology", "external_links": ["https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/", "https://commons.wikimedia.org/w/index.php?curid=21887260", "https://en.wikipedia.org/wiki/German_cockroach", "https://i.sstatic.net/GPuXwqUQ.png", "https://i.sstatic.net/XOYdeTcg.png", "https://thebuginator.com/roach-poop/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:02:59.816967+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/55bbc2350ddd64077cfc2cba10ad5323a3aabdbe06356ba63f9b4f2161e7b47f_0.json", "raw_sha256": "816eaaa302266f8cc647e663e24b4d7ecdb9f8cc125751c689d3329286131873", "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=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Laura", "question_author_url": "https://biology.stackexchange.com/users/124506/laura", "question_author_user_type": "registered", "question_created_at": "2026-01-27T11:03:02+00:00", "question_html": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.
\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.
\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.
\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.
\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.
\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.
\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?
\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.
\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.
\n", "question_id": 119287, "question_license": "CC BY-SA 4.0", "question_score": 7, "question_text": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.\n\n\n\n\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.\n\n\n\n\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.\n\n\n\n\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.\n\n\n\n\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.\n\n\n\n\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.\n\n\n\n\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?\n\n\n\n\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.\n\n\n\n\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-27T11:03:02+00:00", "raw_file": "raw/codex_api_v1/91e75308ae5d4e2adbc966eeaa33ee31183f3dcee03ede8f8105b7c8973deeb6_1790824169436990200_0.json", "raw_sha256": "4ecc6c39f2269357dfd5478f8b88ef2f2e3d1b91841927b9ef870a736f612c14", "revision_guid": "B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-29T21:43:59+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "BE219B8F-F166-482A-8322-A78F7B8BF490", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/BE219B8F-F166-482A-8322-A78F7B8BF490/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/119287/black-solid-colonies-of-microorganisms-on-plastics", "split": "validation", "split_group": "932c447eff16da26de567f7cc490902604899b97a7193869278c9ce692f6fe04", "tags": ["species-identification", "microbiology", "bacteriology", "yeast"], "thread_id": "biology:119287", "title": "Black solid colonies of microorganisms on plastics"}} {"citation_context": " but you should be able to wash it off. Here's an example of what it looks like from The Buginator (https://thebuginator.com/roach-poop/):\n\n\n\n\n[image: Orange cockroach with liquid feces; source: https://i.sstatic.net/GPuXwqUQ.png] (http", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://thebuginator.com/roach-poop/", "kind": "external_url", "post_id": 119290, "post_url": "https://biology.stackexchange.com/a/119290", "product": "citations", "record_id": "Scientific-Citation-Graph:17518f3f95d2b7dba541d6ec", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.
\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.
\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease, but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.
\n
\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260
The other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator:
\n
\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/
As to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.
\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.
\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.
\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.
\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!
\n", "answer_id": 119290, "answer_text": "These are almost certainly arthropod excretions. Spider droppings look similar to this, but would be accompanied by a web above them, and would not be on all surfaces.\n\n\n\n\nThat they appear on many surfaces indicates something that can crawl or fly to different surfaces, and the abundance means there are likely a lot of them. Because you don't see them during the day, this means something largely nocturnal or light avoidant. There aren't many common insects in houses that have these features, cockroaches being the most common. Cockroaches are quite allergenic. Another option is bedbugs, but they are often confined to a single space (e.g. bedroom) and tend to leave droppings in hidden spots where they cluster.\n\n\n\n\nA strong sweet smell could indicate cockroaches, this is often described as smelling like stale oil or grease (https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/), but is sometimes described as sweet. Cockroaches produce two types of droppings - small black specks and blobs of black matter that dry onto surfaces. The small black specks can be different sizes depending on the species of roach. Large species, such as the American cockroach (https://en.wikipedia.org/wiki/German_cockroach) (Periplaneta americana) produce droppings only slightly smaller than mouse droppings and of a similar shape, though more square on the ends. You can see a number of these in the following image, just below the two round objects on the bottom left. Smaller species produce droppings that might look like black dust or pepper grindings. You should look for feces near where drains enter walls or anywhere damp and dark.\n\n\n\n\n[image: American cockroach and droppings; source: https://i.sstatic.net/XOYdeTcg.png] (https://i.sstatic.net/XOYdeTcg.png)\n Image attribution: By SuperJew - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=21887260 (https://commons.wikimedia.org/w/index.php?curid=21887260) \n\n\n\n\nThe other type of dropping is a dark blob of liquid feces, which will dry hard, but you should be able to wash it off. Here's an example of what it looks like from The Buginator (https://thebuginator.com/roach-poop/):\n\n\n\n\n[image: Orange cockroach with liquid feces; source: https://i.sstatic.net/GPuXwqUQ.png] (https://i.sstatic.net/GPuXwqUQ.png)\n Image attribution: The Buginator. https://thebuginator.com/roach-poop/ (https://thebuginator.com/roach-poop/) \n\n\n\n\nAs to the white powder - that could be anything, but is possibly the droppings from a small species of cockroach. Put out some glue traps in dark spots below your sink or in laundry spaces and see what you catch - a pest control person can (and should) do this too.\n\n\n\n\nThe other option of bedbugs is more problematic. They are very hard to get rid of as a lot of them are insecticide resistant. Bedbugs also give off a distinct smell (usually described as coriander or almonds), but you would need to have a lot of them present, which would mean you would probably notice bites on yourself, though not all people react to them. Check your bedframe and mattress in the corners and along the seams for concentrations of dark spots. Also check any soft furniture in your lounge etc. They can also inhabit hard furniture such as drawers or anything that will give them a crack to hide in.\n\n\n\n\nIf you are in an apartment with neighbours, check with them on signs of bedbugs or cockroaches, they are very commonly spread from neighbouring apartments.\n\n\n\n\nCall a reliable pest control company in your area. I hate to say it, but your current one isn't much good if they can't identify it from the clues you gave and they should put out traps.\n\n\n\n\nNew renovations sometimes have odours from new fittings such as carpet, but these fade over time. It may have been renovated to get rid of or hide a pest problem!", "answer_url": "https://biology.stackexchange.com/a/119290", "author": "bob1", "author_url": "https://biology.stackexchange.com/users/65284/bob1", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-01-28T20:23:28+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:14.203473+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/bc31fe4e1e84f43ae95f846a38e90acc9e22beb08e25c5d964f94cb8f2d4bfcb_0.json", "raw_sha256": "d7cf716376a9764909548809f10c8760f535f0ca4093eb29d910aae44edf1878", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/119725;119721;119720;119695;119675;119670;119661;119648;119640;119639;119635;119631;119628;119607;119605;119601;119598;119586;119582;119579;119577;119565;119561;119560;119542;119539;119529;119527;119522;119518;119506;119501;119497;119489;119487;119479;119465;119455;119453;119450;119444;119439;119434;119430;119421;119416;119404;119399;119398;119377;119376;119369;119362;119361;119355;119353;119350;119342;119340;119328;119326;119321;119317;119313;119312;119311;119306;119304;119287;119275;119273;119270;119268;119267;119260;119256;119251;119248;119238;119237;119235;119231;119227;119221;119212;119211;119209;119207;119201;119195;119193;119190;119185;119180;118180;118175;118172;118168;118158;118155/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 119287, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "bob1", "profile_url": "https://biology.stackexchange.com/users/65284/bob1", "user_type": "registered"}, "created_at": "2026-01-28T20:23:28+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "A51BBA80-6DD2-424E-971B-0E5DE5C9140F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/A51BBA80-6DD2-424E-971B-0E5DE5C9140F/view-source"}], "score": 3, "updated_at": "2026-01-28T20:23:28+00:00"}], "domain": "biology", "external_links": ["https://biologyinsights.com/what-does-a-cockroach-infestation-smell-like/", "https://commons.wikimedia.org/w/index.php?curid=21887260", "https://en.wikipedia.org/wiki/German_cockroach", "https://i.sstatic.net/GPuXwqUQ.png", "https://i.sstatic.net/XOYdeTcg.png", "https://thebuginator.com/roach-poop/"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:02:59.816967+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/55bbc2350ddd64077cfc2cba10ad5323a3aabdbe06356ba63f9b4f2161e7b47f_0.json", "raw_sha256": "816eaaa302266f8cc647e663e24b4d7ecdb9f8cc125751c689d3329286131873", "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=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Laura", "question_author_url": "https://biology.stackexchange.com/users/124506/laura", "question_author_user_type": "registered", "question_created_at": "2026-01-27T11:03:02+00:00", "question_html": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.
\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.
\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.
\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.
\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.
\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.
\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?
\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.
\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.
\n", "question_id": 119287, "question_license": "CC BY-SA 4.0", "question_score": 7, "question_text": "I have the following riddle to solve.\nOut of necessity, I lived in a house heavily burdened by water damage and rot in the roof structure, as well as mold in the apartment below me. Only for a short time. Since I started developing health problems quite quickly, I moved out in time.\n\n\n\n\nAs a precaution, I disinfected my belongings with alcohol as much as possible and moved into a completely new house—not old, everything newly renovated. The humidity is very low.\n\n\n\n\nGradually, it turned out—and it took a little while—that the items from the apartment, which had a somewhat sweet smell, shifted in odor towards something acidic.\n\n\n\n\nMore weeks later, I noticed that there are small, black, solid, hard dots on all objects. The strange thing is that a whitish powder also appears, and whatever it is, it grows on plastic, silicone, etc.\n\n\n\n\nThe terrible part is that this organism is now spreading to the house. That means these black colonies are now also growing on the marble windowsills, among other places.\n\n\n\n\nI have no idea what this could be. We have already called in a professional. However, he is at a loss, and previous tests have not yielded any results yet.\n\n\n\n\nDoes this sound familiar to any of you? Does anyone have an idea what this could be?\n\n\n\n\nAn extremely sweet smell (MVOC), almost like fabric softener; an organism that feeds on plastic but doesn't stop at windowsills.\n\n\n\n\nIt forms small, solid, dot-like craters and is highly allergenic. At the very least, I react to this organism with eye inflammation and respiratory irritation. I am grateful for any hint. Thank you very much.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-27T11:03:02+00:00", "raw_file": "raw/codex_api_v1/91e75308ae5d4e2adbc966eeaa33ee31183f3dcee03ede8f8105b7c8973deeb6_1790824169436990200_0.json", "raw_sha256": "4ecc6c39f2269357dfd5478f8b88ef2f2e3d1b91841927b9ef870a736f612c14", "revision_guid": "B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B9F12FF2-13C4-43FD-BF6E-30D66D4CFABF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Laura", "profile_url": "https://biology.stackexchange.com/users/124506/laura", "user_type": "registered"}, "created_at": "2026-01-29T21:43:59+00:00", "raw_file": "raw/codex_api_v1/8e952f166349d197ca438d4c6da0a6ceb83001adf6bf53b79021f6f47dbac9ed_1790824167246505200_0.json", "raw_sha256": "e4bf5a8cf72ab19ae92569b60006ce309cee9bb0a51afc54be5e3a597306b0a8", "revision_guid": "BE219B8F-F166-482A-8322-A78F7B8BF490", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/BE219B8F-F166-482A-8322-A78F7B8BF490/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/119287/black-solid-colonies-of-microorganisms-on-plastics", "split": "validation", "split_group": "932c447eff16da26de567f7cc490902604899b97a7193869278c9ce692f6fe04", "tags": ["species-identification", "microbiology", "bacteriology", "yeast"], "thread_id": "biology:119287", "title": "Black solid colonies of microorganisms on plastics"}} {"citation_context": "nd all kinds of similiar behavior.\n\n\n\n\nhere is a short list of most common bees in Pennsyvania.\n\n\n\n\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/ (https://emoyer.com/services/pestcontrol/pestlibrary/bees/)\n\n\n\n\nHere is a more detailed breakdown.\n", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://emoyer.com/services/pestcontrol/pestlibrary/bees/", "kind": "external_url", "post_id": 117784, "post_url": "https://biology.stackexchange.com/a/117784", "product": "citations", "record_id": "Scientific-Citation-Graph:c195a083fed804c059863a02", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.
\nhere is a short list of most common bees in Pennsyvania.
\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/
\nHere is a more detailed breakdown.
\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/
\none kind of leafcutter bee
\n\n", "answer_id": 117784, "answer_text": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.\n\n\n\n\nhere is a short list of most common bees in Pennsyvania.\n\n\n\n\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/ (https://emoyer.com/services/pestcontrol/pestlibrary/bees/)\n\n\n\n\nHere is a more detailed breakdown.\n\n\n\n\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/ (https://lopezuribelab.com/checklist-bees-pennsylvania/)\n\n\n\n\none kind of leafcutter bee\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fz1jwb06s.png] (https://i.sstatic.net/fz1jwb06s.png)", "answer_url": "https://biology.stackexchange.com/a/117784", "author": "John", "author_url": "https://biology.stackexchange.com/users/28022/john", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:38:06+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:38:06+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "63A82717-A88C-4EC8-96AF-7F6E0CE81838", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/63A82717-A88C-4EC8-96AF-7F6E0CE81838/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:45:23+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "756F7865-735F-4123-BB7B-4375FC4AB945", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/756F7865-735F-4123-BB7B-4375FC4AB945/view-source"}], "score": 3, "updated_at": "2025-08-10T14:45:23+00:00"}, {"answer_html": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (image is proprietary so can only supply link)
\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.
\n\nWhile flying it could be seen to hover, which bees do not do.
\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly
\n", "answer_id": 117785, "answer_text": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html) (image is proprietary so can only supply link)\n\n\n\n\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.\n\n\n\n\n[image: hoverfly; source: https://i.sstatic.net/Z4zOIC1m.png] (https://i.sstatic.net/Z4zOIC1m.png)\n\n\n\n\nWhile flying it could be seen to hover, which bees do not do.\n\n\n\n\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly (https://en.wikipedia.org/wiki/Hoverfly)", "answer_url": "https://biology.stackexchange.com/a/117785", "author": "Rich", "author_url": "https://biology.stackexchange.com/users/78837/rich", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:59:09+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-10T14:59:09+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-11T17:41:44+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C/view-source"}], "score": 7, "updated_at": "2025-08-11T17:41:44+00:00"}, {"answer_html": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, "fuzzy" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.
\n\n", "answer_id": 119462, "answer_text": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, \"fuzzy\" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/oJTRLMmA.png] (https://i.sstatic.net/oJTRLMmA.png)", "answer_url": "https://biology.stackexchange.com/a/119462", "author": "OllieVet", "author_url": "https://biology.stackexchange.com/users/76792/ollievet", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-04-29T17:48:35+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-29T17:48:35+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "06315489-5A0C-4C60-9D5D-8818A8F9DFBF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/06315489-5A0C-4C60-9D5D-8818A8F9DFBF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-30T20:04:27+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "0D64A651-2F79-47CE-A317-9DA329A606B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0D64A651-2F79-47CE-A317-9DA329A606B4/view-source"}], "score": 2, "updated_at": "2026-04-30T20:04:27+00:00"}], "domain": "biology", "external_links": ["https://emoyer.com/services/pestcontrol/pestlibrary/bees/", "https://en.wikipedia.org/wiki/Hoverfly", "https://i.sstatic.net/Z4zOIC1m.png", "https://i.sstatic.net/fz1jwb06s.png", "https://i.sstatic.net/oJTRLMmA.png", "https://lopezuribelab.com/checklist-bees-pennsylvania/", "https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Rich", "question_author_url": "https://biology.stackexchange.com/users/78837/rich", "question_author_user_type": "registered", "question_created_at": "2025-08-09T16:27:38+00:00", "question_html": "It looks like a bee, about 5/8" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.
\nThis is how much it resembles a bee:
\nWhile I was watching it, one part of my brain was saying "That insect is laying eggs on our cucumber leaves." This was overruled by another part of my brain that said," NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:
\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.
\nIs this normal behavior? Or does this bee need glasses?
\n
Following the comment by @mgkrebbs I realized my error and rethought my original hypothesis,
\nSo, what could it be?
\n", "question_id": 117782, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "It looks like a bee, about 5/8\" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.\n\n\n\n\nThis is how much it resembles a bee:\n\n\n\n\nWhile I was watching it, one part of my brain was saying \"That insect is laying eggs on our cucumber leaves.\" This was overruled by another part of my brain that said,\" NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:\n\n\n\n\n\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2\" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.\n\n\n\n\nIs this normal behavior? Or does this bee need glasses?\n\n\n\n\n\n\n\nFollowing the comment by @mgkrebbs I realized my error and rethought my original hypothesis,\n\n\n\n\nSo, what could it be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T16:27:38+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "26F16ABE-A9AB-4E15-A597-9D5340023B0B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/26F16ABE-A9AB-4E15-A597-9D5340023B0B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T22:30:33+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "B0569837-0B0E-40F1-BF48-70E9D1B5E80F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B0569837-0B0E-40F1-BF48-70E9D1B5E80F/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/117782/looks-just-like-a-bee-but-it-isnt-what-is-it", "split": "validation", "split_group": "3ed922a8b7a0373b9e5fceeb9225e200a8f0eb3dd0336e397519db89232554e5", "tags": ["species-identification", "entomology"], "thread_id": "biology:117782", "title": "Looks just like a bee, but it isn't. What is it?"}} {"citation_context": "ees-pennsylvania/)\n\n\n\n\none kind of leafcutter bee\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fz1jwb06s.png] (https://i.sstatic.net/fz1jwb06s.png)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/fz1jwb06s.png", "kind": "external_url", "post_id": 117784, "post_url": "https://biology.stackexchange.com/a/117784", "product": "citations", "record_id": "Scientific-Citation-Graph:cd2484891417a69deeb5eadb", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.
\nhere is a short list of most common bees in Pennsyvania.
\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/
\nHere is a more detailed breakdown.
\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/
\none kind of leafcutter bee
\n\n", "answer_id": 117784, "answer_text": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.\n\n\n\n\nhere is a short list of most common bees in Pennsyvania.\n\n\n\n\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/ (https://emoyer.com/services/pestcontrol/pestlibrary/bees/)\n\n\n\n\nHere is a more detailed breakdown.\n\n\n\n\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/ (https://lopezuribelab.com/checklist-bees-pennsylvania/)\n\n\n\n\none kind of leafcutter bee\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fz1jwb06s.png] (https://i.sstatic.net/fz1jwb06s.png)", "answer_url": "https://biology.stackexchange.com/a/117784", "author": "John", "author_url": "https://biology.stackexchange.com/users/28022/john", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:38:06+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:38:06+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "63A82717-A88C-4EC8-96AF-7F6E0CE81838", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/63A82717-A88C-4EC8-96AF-7F6E0CE81838/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:45:23+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "756F7865-735F-4123-BB7B-4375FC4AB945", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/756F7865-735F-4123-BB7B-4375FC4AB945/view-source"}], "score": 3, "updated_at": "2025-08-10T14:45:23+00:00"}, {"answer_html": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (image is proprietary so can only supply link)
\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.
\n\nWhile flying it could be seen to hover, which bees do not do.
\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly
\n", "answer_id": 117785, "answer_text": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html) (image is proprietary so can only supply link)\n\n\n\n\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.\n\n\n\n\n[image: hoverfly; source: https://i.sstatic.net/Z4zOIC1m.png] (https://i.sstatic.net/Z4zOIC1m.png)\n\n\n\n\nWhile flying it could be seen to hover, which bees do not do.\n\n\n\n\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly (https://en.wikipedia.org/wiki/Hoverfly)", "answer_url": "https://biology.stackexchange.com/a/117785", "author": "Rich", "author_url": "https://biology.stackexchange.com/users/78837/rich", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:59:09+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-10T14:59:09+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-11T17:41:44+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C/view-source"}], "score": 7, "updated_at": "2025-08-11T17:41:44+00:00"}, {"answer_html": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, "fuzzy" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.
\n\n", "answer_id": 119462, "answer_text": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, \"fuzzy\" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/oJTRLMmA.png] (https://i.sstatic.net/oJTRLMmA.png)", "answer_url": "https://biology.stackexchange.com/a/119462", "author": "OllieVet", "author_url": "https://biology.stackexchange.com/users/76792/ollievet", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-04-29T17:48:35+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-29T17:48:35+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "06315489-5A0C-4C60-9D5D-8818A8F9DFBF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/06315489-5A0C-4C60-9D5D-8818A8F9DFBF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-30T20:04:27+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "0D64A651-2F79-47CE-A317-9DA329A606B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0D64A651-2F79-47CE-A317-9DA329A606B4/view-source"}], "score": 2, "updated_at": "2026-04-30T20:04:27+00:00"}], "domain": "biology", "external_links": ["https://emoyer.com/services/pestcontrol/pestlibrary/bees/", "https://en.wikipedia.org/wiki/Hoverfly", "https://i.sstatic.net/Z4zOIC1m.png", "https://i.sstatic.net/fz1jwb06s.png", "https://i.sstatic.net/oJTRLMmA.png", "https://lopezuribelab.com/checklist-bees-pennsylvania/", "https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Rich", "question_author_url": "https://biology.stackexchange.com/users/78837/rich", "question_author_user_type": "registered", "question_created_at": "2025-08-09T16:27:38+00:00", "question_html": "It looks like a bee, about 5/8" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.
\nThis is how much it resembles a bee:
\nWhile I was watching it, one part of my brain was saying "That insect is laying eggs on our cucumber leaves." This was overruled by another part of my brain that said," NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:
\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.
\nIs this normal behavior? Or does this bee need glasses?
\n
Following the comment by @mgkrebbs I realized my error and rethought my original hypothesis,
\nSo, what could it be?
\n", "question_id": 117782, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "It looks like a bee, about 5/8\" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.\n\n\n\n\nThis is how much it resembles a bee:\n\n\n\n\nWhile I was watching it, one part of my brain was saying \"That insect is laying eggs on our cucumber leaves.\" This was overruled by another part of my brain that said,\" NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:\n\n\n\n\n\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2\" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.\n\n\n\n\nIs this normal behavior? Or does this bee need glasses?\n\n\n\n\n\n\n\nFollowing the comment by @mgkrebbs I realized my error and rethought my original hypothesis,\n\n\n\n\nSo, what could it be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T16:27:38+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "26F16ABE-A9AB-4E15-A597-9D5340023B0B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/26F16ABE-A9AB-4E15-A597-9D5340023B0B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T22:30:33+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "B0569837-0B0E-40F1-BF48-70E9D1B5E80F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B0569837-0B0E-40F1-BF48-70E9D1B5E80F/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/117782/looks-just-like-a-bee-but-it-isnt-what-is-it", "split": "validation", "split_group": "3ed922a8b7a0373b9e5fceeb9225e200a8f0eb3dd0336e397519db89232554e5", "tags": ["species-identification", "entomology"], "thread_id": "biology:117782", "title": "Looks just like a bee, but it isn't. What is it?"}} {"citation_context": "tps://emoyer.com/services/pestcontrol/pestlibrary/bees/)\n\n\n\n\nHere is a more detailed breakdown.\n\n\n\n\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/ (https://lopezuribelab.com/checklist-bees-pennsylvania/)\n\n\n\n\none kind of leafcutter bee\n\n\n\n\n[image:", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://lopezuribelab.com/checklist-bees-pennsylvania/", "kind": "external_url", "post_id": 117784, "post_url": "https://biology.stackexchange.com/a/117784", "product": "citations", "record_id": "Scientific-Citation-Graph:7c3894a49be9dd1f171531ce", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.
\nhere is a short list of most common bees in Pennsyvania.
\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/
\nHere is a more detailed breakdown.
\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/
\none kind of leafcutter bee
\n\n", "answer_id": 117784, "answer_text": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.\n\n\n\n\nhere is a short list of most common bees in Pennsyvania.\n\n\n\n\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/ (https://emoyer.com/services/pestcontrol/pestlibrary/bees/)\n\n\n\n\nHere is a more detailed breakdown.\n\n\n\n\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/ (https://lopezuribelab.com/checklist-bees-pennsylvania/)\n\n\n\n\none kind of leafcutter bee\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fz1jwb06s.png] (https://i.sstatic.net/fz1jwb06s.png)", "answer_url": "https://biology.stackexchange.com/a/117784", "author": "John", "author_url": "https://biology.stackexchange.com/users/28022/john", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:38:06+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:38:06+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "63A82717-A88C-4EC8-96AF-7F6E0CE81838", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/63A82717-A88C-4EC8-96AF-7F6E0CE81838/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:45:23+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "756F7865-735F-4123-BB7B-4375FC4AB945", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/756F7865-735F-4123-BB7B-4375FC4AB945/view-source"}], "score": 3, "updated_at": "2025-08-10T14:45:23+00:00"}, {"answer_html": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (image is proprietary so can only supply link)
\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.
\n\nWhile flying it could be seen to hover, which bees do not do.
\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly
\n", "answer_id": 117785, "answer_text": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html) (image is proprietary so can only supply link)\n\n\n\n\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.\n\n\n\n\n[image: hoverfly; source: https://i.sstatic.net/Z4zOIC1m.png] (https://i.sstatic.net/Z4zOIC1m.png)\n\n\n\n\nWhile flying it could be seen to hover, which bees do not do.\n\n\n\n\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly (https://en.wikipedia.org/wiki/Hoverfly)", "answer_url": "https://biology.stackexchange.com/a/117785", "author": "Rich", "author_url": "https://biology.stackexchange.com/users/78837/rich", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:59:09+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-10T14:59:09+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-11T17:41:44+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C/view-source"}], "score": 7, "updated_at": "2025-08-11T17:41:44+00:00"}, {"answer_html": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, "fuzzy" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.
\n\n", "answer_id": 119462, "answer_text": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, \"fuzzy\" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/oJTRLMmA.png] (https://i.sstatic.net/oJTRLMmA.png)", "answer_url": "https://biology.stackexchange.com/a/119462", "author": "OllieVet", "author_url": "https://biology.stackexchange.com/users/76792/ollievet", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-04-29T17:48:35+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-29T17:48:35+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "06315489-5A0C-4C60-9D5D-8818A8F9DFBF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/06315489-5A0C-4C60-9D5D-8818A8F9DFBF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-30T20:04:27+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "0D64A651-2F79-47CE-A317-9DA329A606B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0D64A651-2F79-47CE-A317-9DA329A606B4/view-source"}], "score": 2, "updated_at": "2026-04-30T20:04:27+00:00"}], "domain": "biology", "external_links": ["https://emoyer.com/services/pestcontrol/pestlibrary/bees/", "https://en.wikipedia.org/wiki/Hoverfly", "https://i.sstatic.net/Z4zOIC1m.png", "https://i.sstatic.net/fz1jwb06s.png", "https://i.sstatic.net/oJTRLMmA.png", "https://lopezuribelab.com/checklist-bees-pennsylvania/", "https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Rich", "question_author_url": "https://biology.stackexchange.com/users/78837/rich", "question_author_user_type": "registered", "question_created_at": "2025-08-09T16:27:38+00:00", "question_html": "It looks like a bee, about 5/8" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.
\nThis is how much it resembles a bee:
\nWhile I was watching it, one part of my brain was saying "That insect is laying eggs on our cucumber leaves." This was overruled by another part of my brain that said," NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:
\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.
\nIs this normal behavior? Or does this bee need glasses?
\n
Following the comment by @mgkrebbs I realized my error and rethought my original hypothesis,
\nSo, what could it be?
\n", "question_id": 117782, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "It looks like a bee, about 5/8\" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.\n\n\n\n\nThis is how much it resembles a bee:\n\n\n\n\nWhile I was watching it, one part of my brain was saying \"That insect is laying eggs on our cucumber leaves.\" This was overruled by another part of my brain that said,\" NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:\n\n\n\n\n\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2\" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.\n\n\n\n\nIs this normal behavior? Or does this bee need glasses?\n\n\n\n\n\n\n\nFollowing the comment by @mgkrebbs I realized my error and rethought my original hypothesis,\n\n\n\n\nSo, what could it be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T16:27:38+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "26F16ABE-A9AB-4E15-A597-9D5340023B0B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/26F16ABE-A9AB-4E15-A597-9D5340023B0B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T22:30:33+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "B0569837-0B0E-40F1-BF48-70E9D1B5E80F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B0569837-0B0E-40F1-BF48-70E9D1B5E80F/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/117782/looks-just-like-a-bee-but-it-isnt-what-is-it", "split": "validation", "split_group": "3ed922a8b7a0373b9e5fceeb9225e200a8f0eb3dd0336e397519db89232554e5", "tags": ["species-identification", "entomology"], "thread_id": "biology:117782", "title": "Looks just like a bee, but it isn't. What is it?"}} {"citation_context": "e I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly (https://en.wikipedia.org/wiki/Hoverfly)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Hoverfly", "kind": "external_url", "post_id": 117785, "post_url": "https://biology.stackexchange.com/a/117785", "product": "citations", "record_id": "Scientific-Citation-Graph:177159ffe48be70d7c2c2df6", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.
\nhere is a short list of most common bees in Pennsyvania.
\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/
\nHere is a more detailed breakdown.
\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/
\none kind of leafcutter bee
\n\n", "answer_id": 117784, "answer_text": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.\n\n\n\n\nhere is a short list of most common bees in Pennsyvania.\n\n\n\n\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/ (https://emoyer.com/services/pestcontrol/pestlibrary/bees/)\n\n\n\n\nHere is a more detailed breakdown.\n\n\n\n\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/ (https://lopezuribelab.com/checklist-bees-pennsylvania/)\n\n\n\n\none kind of leafcutter bee\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fz1jwb06s.png] (https://i.sstatic.net/fz1jwb06s.png)", "answer_url": "https://biology.stackexchange.com/a/117784", "author": "John", "author_url": "https://biology.stackexchange.com/users/28022/john", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:38:06+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:38:06+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "63A82717-A88C-4EC8-96AF-7F6E0CE81838", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/63A82717-A88C-4EC8-96AF-7F6E0CE81838/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:45:23+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "756F7865-735F-4123-BB7B-4375FC4AB945", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/756F7865-735F-4123-BB7B-4375FC4AB945/view-source"}], "score": 3, "updated_at": "2025-08-10T14:45:23+00:00"}, {"answer_html": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (image is proprietary so can only supply link)
\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.
\n\nWhile flying it could be seen to hover, which bees do not do.
\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly
\n", "answer_id": 117785, "answer_text": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html) (image is proprietary so can only supply link)\n\n\n\n\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.\n\n\n\n\n[image: hoverfly; source: https://i.sstatic.net/Z4zOIC1m.png] (https://i.sstatic.net/Z4zOIC1m.png)\n\n\n\n\nWhile flying it could be seen to hover, which bees do not do.\n\n\n\n\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly (https://en.wikipedia.org/wiki/Hoverfly)", "answer_url": "https://biology.stackexchange.com/a/117785", "author": "Rich", "author_url": "https://biology.stackexchange.com/users/78837/rich", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:59:09+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-10T14:59:09+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-11T17:41:44+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C/view-source"}], "score": 7, "updated_at": "2025-08-11T17:41:44+00:00"}, {"answer_html": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, "fuzzy" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.
\n\n", "answer_id": 119462, "answer_text": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, \"fuzzy\" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/oJTRLMmA.png] (https://i.sstatic.net/oJTRLMmA.png)", "answer_url": "https://biology.stackexchange.com/a/119462", "author": "OllieVet", "author_url": "https://biology.stackexchange.com/users/76792/ollievet", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-04-29T17:48:35+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-29T17:48:35+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "06315489-5A0C-4C60-9D5D-8818A8F9DFBF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/06315489-5A0C-4C60-9D5D-8818A8F9DFBF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-30T20:04:27+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "0D64A651-2F79-47CE-A317-9DA329A606B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0D64A651-2F79-47CE-A317-9DA329A606B4/view-source"}], "score": 2, "updated_at": "2026-04-30T20:04:27+00:00"}], "domain": "biology", "external_links": ["https://emoyer.com/services/pestcontrol/pestlibrary/bees/", "https://en.wikipedia.org/wiki/Hoverfly", "https://i.sstatic.net/Z4zOIC1m.png", "https://i.sstatic.net/fz1jwb06s.png", "https://i.sstatic.net/oJTRLMmA.png", "https://lopezuribelab.com/checklist-bees-pennsylvania/", "https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Rich", "question_author_url": "https://biology.stackexchange.com/users/78837/rich", "question_author_user_type": "registered", "question_created_at": "2025-08-09T16:27:38+00:00", "question_html": "It looks like a bee, about 5/8" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.
\nThis is how much it resembles a bee:
\nWhile I was watching it, one part of my brain was saying "That insect is laying eggs on our cucumber leaves." This was overruled by another part of my brain that said," NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:
\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.
\nIs this normal behavior? Or does this bee need glasses?
\n
Following the comment by @mgkrebbs I realized my error and rethought my original hypothesis,
\nSo, what could it be?
\n", "question_id": 117782, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "It looks like a bee, about 5/8\" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.\n\n\n\n\nThis is how much it resembles a bee:\n\n\n\n\nWhile I was watching it, one part of my brain was saying \"That insect is laying eggs on our cucumber leaves.\" This was overruled by another part of my brain that said,\" NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:\n\n\n\n\n\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2\" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.\n\n\n\n\nIs this normal behavior? Or does this bee need glasses?\n\n\n\n\n\n\n\nFollowing the comment by @mgkrebbs I realized my error and rethought my original hypothesis,\n\n\n\n\nSo, what could it be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T16:27:38+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "26F16ABE-A9AB-4E15-A597-9D5340023B0B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/26F16ABE-A9AB-4E15-A597-9D5340023B0B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T22:30:33+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "B0569837-0B0E-40F1-BF48-70E9D1B5E80F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B0569837-0B0E-40F1-BF48-70E9D1B5E80F/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/117782/looks-just-like-a-bee-but-it-isnt-what-is-it", "split": "validation", "split_group": "3ed922a8b7a0373b9e5fceeb9225e200a8f0eb3dd0336e397519db89232554e5", "tags": ["species-identification", "entomology"], "thread_id": "biology:117782", "title": "Looks just like a bee, but it isn't. What is it?"}} {"citation_context": "antennae, where bees have two pair of wings and articulated antennae.\n\n\n\n\n[image: hoverfly; source: https://i.sstatic.net/Z4zOIC1m.png] (https://i.sstatic.net/Z4zOIC1m.png)\n\n\n\n\nWhile flying it could be seen to hover, which bees do not", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/Z4zOIC1m.png", "kind": "external_url", "post_id": 117785, "post_url": "https://biology.stackexchange.com/a/117785", "product": "citations", "record_id": "Scientific-Citation-Graph:0c79cd499392924fd7074335", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.
\nhere is a short list of most common bees in Pennsyvania.
\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/
\nHere is a more detailed breakdown.
\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/
\none kind of leafcutter bee
\n\n", "answer_id": 117784, "answer_text": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.\n\n\n\n\nhere is a short list of most common bees in Pennsyvania.\n\n\n\n\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/ (https://emoyer.com/services/pestcontrol/pestlibrary/bees/)\n\n\n\n\nHere is a more detailed breakdown.\n\n\n\n\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/ (https://lopezuribelab.com/checklist-bees-pennsylvania/)\n\n\n\n\none kind of leafcutter bee\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fz1jwb06s.png] (https://i.sstatic.net/fz1jwb06s.png)", "answer_url": "https://biology.stackexchange.com/a/117784", "author": "John", "author_url": "https://biology.stackexchange.com/users/28022/john", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:38:06+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:38:06+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "63A82717-A88C-4EC8-96AF-7F6E0CE81838", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/63A82717-A88C-4EC8-96AF-7F6E0CE81838/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:45:23+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "756F7865-735F-4123-BB7B-4375FC4AB945", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/756F7865-735F-4123-BB7B-4375FC4AB945/view-source"}], "score": 3, "updated_at": "2025-08-10T14:45:23+00:00"}, {"answer_html": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (image is proprietary so can only supply link)
\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.
\n\nWhile flying it could be seen to hover, which bees do not do.
\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly
\n", "answer_id": 117785, "answer_text": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html) (image is proprietary so can only supply link)\n\n\n\n\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.\n\n\n\n\n[image: hoverfly; source: https://i.sstatic.net/Z4zOIC1m.png] (https://i.sstatic.net/Z4zOIC1m.png)\n\n\n\n\nWhile flying it could be seen to hover, which bees do not do.\n\n\n\n\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly (https://en.wikipedia.org/wiki/Hoverfly)", "answer_url": "https://biology.stackexchange.com/a/117785", "author": "Rich", "author_url": "https://biology.stackexchange.com/users/78837/rich", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:59:09+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-10T14:59:09+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-11T17:41:44+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C/view-source"}], "score": 7, "updated_at": "2025-08-11T17:41:44+00:00"}, {"answer_html": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, "fuzzy" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.
\n\n", "answer_id": 119462, "answer_text": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, \"fuzzy\" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/oJTRLMmA.png] (https://i.sstatic.net/oJTRLMmA.png)", "answer_url": "https://biology.stackexchange.com/a/119462", "author": "OllieVet", "author_url": "https://biology.stackexchange.com/users/76792/ollievet", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-04-29T17:48:35+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-29T17:48:35+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "06315489-5A0C-4C60-9D5D-8818A8F9DFBF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/06315489-5A0C-4C60-9D5D-8818A8F9DFBF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-30T20:04:27+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "0D64A651-2F79-47CE-A317-9DA329A606B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0D64A651-2F79-47CE-A317-9DA329A606B4/view-source"}], "score": 2, "updated_at": "2026-04-30T20:04:27+00:00"}], "domain": "biology", "external_links": ["https://emoyer.com/services/pestcontrol/pestlibrary/bees/", "https://en.wikipedia.org/wiki/Hoverfly", "https://i.sstatic.net/Z4zOIC1m.png", "https://i.sstatic.net/fz1jwb06s.png", "https://i.sstatic.net/oJTRLMmA.png", "https://lopezuribelab.com/checklist-bees-pennsylvania/", "https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Rich", "question_author_url": "https://biology.stackexchange.com/users/78837/rich", "question_author_user_type": "registered", "question_created_at": "2025-08-09T16:27:38+00:00", "question_html": "It looks like a bee, about 5/8" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.
\nThis is how much it resembles a bee:
\nWhile I was watching it, one part of my brain was saying "That insect is laying eggs on our cucumber leaves." This was overruled by another part of my brain that said," NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:
\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.
\nIs this normal behavior? Or does this bee need glasses?
\n
Following the comment by @mgkrebbs I realized my error and rethought my original hypothesis,
\nSo, what could it be?
\n", "question_id": 117782, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "It looks like a bee, about 5/8\" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.\n\n\n\n\nThis is how much it resembles a bee:\n\n\n\n\nWhile I was watching it, one part of my brain was saying \"That insect is laying eggs on our cucumber leaves.\" This was overruled by another part of my brain that said,\" NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:\n\n\n\n\n\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2\" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.\n\n\n\n\nIs this normal behavior? Or does this bee need glasses?\n\n\n\n\n\n\n\nFollowing the comment by @mgkrebbs I realized my error and rethought my original hypothesis,\n\n\n\n\nSo, what could it be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T16:27:38+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "26F16ABE-A9AB-4E15-A597-9D5340023B0B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/26F16ABE-A9AB-4E15-A597-9D5340023B0B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T22:30:33+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "B0569837-0B0E-40F1-BF48-70E9D1B5E80F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B0569837-0B0E-40F1-BF48-70E9D1B5E80F/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/117782/looks-just-like-a-bee-but-it-isnt-what-is-it", "split": "validation", "split_group": "3ed922a8b7a0373b9e5fceeb9225e200a8f0eb3dd0336e397519db89232554e5", "tags": ["species-identification", "entomology"], "thread_id": "biology:117782", "title": "Looks just like a bee, but it isn't. What is it?"}} {"citation_context": "the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html) (image is proprietary so can only supply link)\n\n\n\n\nHere is the one I saw today. You can see that i", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html", "kind": "external_url", "post_id": 117785, "post_url": "https://biology.stackexchange.com/a/117785", "product": "citations", "record_id": "Scientific-Citation-Graph:82f2e57cf367ff56744af187", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.
\nhere is a short list of most common bees in Pennsyvania.
\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/
\nHere is a more detailed breakdown.
\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/
\none kind of leafcutter bee
\n\n", "answer_id": 117784, "answer_text": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.\n\n\n\n\nhere is a short list of most common bees in Pennsyvania.\n\n\n\n\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/ (https://emoyer.com/services/pestcontrol/pestlibrary/bees/)\n\n\n\n\nHere is a more detailed breakdown.\n\n\n\n\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/ (https://lopezuribelab.com/checklist-bees-pennsylvania/)\n\n\n\n\none kind of leafcutter bee\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fz1jwb06s.png] (https://i.sstatic.net/fz1jwb06s.png)", "answer_url": "https://biology.stackexchange.com/a/117784", "author": "John", "author_url": "https://biology.stackexchange.com/users/28022/john", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:38:06+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:38:06+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "63A82717-A88C-4EC8-96AF-7F6E0CE81838", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/63A82717-A88C-4EC8-96AF-7F6E0CE81838/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:45:23+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "756F7865-735F-4123-BB7B-4375FC4AB945", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/756F7865-735F-4123-BB7B-4375FC4AB945/view-source"}], "score": 3, "updated_at": "2025-08-10T14:45:23+00:00"}, {"answer_html": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (image is proprietary so can only supply link)
\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.
\n\nWhile flying it could be seen to hover, which bees do not do.
\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly
\n", "answer_id": 117785, "answer_text": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html) (image is proprietary so can only supply link)\n\n\n\n\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.\n\n\n\n\n[image: hoverfly; source: https://i.sstatic.net/Z4zOIC1m.png] (https://i.sstatic.net/Z4zOIC1m.png)\n\n\n\n\nWhile flying it could be seen to hover, which bees do not do.\n\n\n\n\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly (https://en.wikipedia.org/wiki/Hoverfly)", "answer_url": "https://biology.stackexchange.com/a/117785", "author": "Rich", "author_url": "https://biology.stackexchange.com/users/78837/rich", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:59:09+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-10T14:59:09+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-11T17:41:44+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C/view-source"}], "score": 7, "updated_at": "2025-08-11T17:41:44+00:00"}, {"answer_html": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, "fuzzy" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.
\n\n", "answer_id": 119462, "answer_text": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, \"fuzzy\" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/oJTRLMmA.png] (https://i.sstatic.net/oJTRLMmA.png)", "answer_url": "https://biology.stackexchange.com/a/119462", "author": "OllieVet", "author_url": "https://biology.stackexchange.com/users/76792/ollievet", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-04-29T17:48:35+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-29T17:48:35+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "06315489-5A0C-4C60-9D5D-8818A8F9DFBF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/06315489-5A0C-4C60-9D5D-8818A8F9DFBF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-30T20:04:27+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "0D64A651-2F79-47CE-A317-9DA329A606B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0D64A651-2F79-47CE-A317-9DA329A606B4/view-source"}], "score": 2, "updated_at": "2026-04-30T20:04:27+00:00"}], "domain": "biology", "external_links": ["https://emoyer.com/services/pestcontrol/pestlibrary/bees/", "https://en.wikipedia.org/wiki/Hoverfly", "https://i.sstatic.net/Z4zOIC1m.png", "https://i.sstatic.net/fz1jwb06s.png", "https://i.sstatic.net/oJTRLMmA.png", "https://lopezuribelab.com/checklist-bees-pennsylvania/", "https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Rich", "question_author_url": "https://biology.stackexchange.com/users/78837/rich", "question_author_user_type": "registered", "question_created_at": "2025-08-09T16:27:38+00:00", "question_html": "It looks like a bee, about 5/8" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.
\nThis is how much it resembles a bee:
\nWhile I was watching it, one part of my brain was saying "That insect is laying eggs on our cucumber leaves." This was overruled by another part of my brain that said," NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:
\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.
\nIs this normal behavior? Or does this bee need glasses?
\n
Following the comment by @mgkrebbs I realized my error and rethought my original hypothesis,
\nSo, what could it be?
\n", "question_id": 117782, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "It looks like a bee, about 5/8\" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.\n\n\n\n\nThis is how much it resembles a bee:\n\n\n\n\nWhile I was watching it, one part of my brain was saying \"That insect is laying eggs on our cucumber leaves.\" This was overruled by another part of my brain that said,\" NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:\n\n\n\n\n\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2\" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.\n\n\n\n\nIs this normal behavior? Or does this bee need glasses?\n\n\n\n\n\n\n\nFollowing the comment by @mgkrebbs I realized my error and rethought my original hypothesis,\n\n\n\n\nSo, what could it be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T16:27:38+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "26F16ABE-A9AB-4E15-A597-9D5340023B0B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/26F16ABE-A9AB-4E15-A597-9D5340023B0B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T22:30:33+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "B0569837-0B0E-40F1-BF48-70E9D1B5E80F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B0569837-0B0E-40F1-BF48-70E9D1B5E80F/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/117782/looks-just-like-a-bee-but-it-isnt-what-is-it", "split": "validation", "split_group": "3ed922a8b7a0373b9e5fceeb9225e200a8f0eb3dd0336e397519db89232554e5", "tags": ["species-identification", "entomology"], "thread_id": "biology:117782", "title": "Looks just like a bee, but it isn't. What is it?"}} {"citation_context": "his link has more information about this species.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/oJTRLMmA.png] (https://i.sstatic.net/oJTRLMmA.png)", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://i.sstatic.net/oJTRLMmA.png", "kind": "external_url", "post_id": 119462, "post_url": "https://biology.stackexchange.com/a/119462", "product": "citations", "record_id": "Scientific-Citation-Graph:0e8997a52daf9f98ac5b8179", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.
\nhere is a short list of most common bees in Pennsyvania.
\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/
\nHere is a more detailed breakdown.
\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/
\none kind of leafcutter bee
\n\n", "answer_id": 117784, "answer_text": "Based on the description it could be a leafcutter bee, squash bee, or plasterer bee. But there are more than a hundred bee species in PA alone and the come in a huge range of shapes and sizes and patterns. no one is going to ID it from such a description. Your best bet is to search images of PA bees. there are bees that chew up leaves, and all kinds of similiar behavior.\n\n\n\n\nhere is a short list of most common bees in Pennsyvania.\n\n\n\n\nhttps://emoyer.com/services/pestcontrol/pestlibrary/bees/ (https://emoyer.com/services/pestcontrol/pestlibrary/bees/)\n\n\n\n\nHere is a more detailed breakdown.\n\n\n\n\nhttps://lopezuribelab.com/checklist-bees-pennsylvania/ (https://lopezuribelab.com/checklist-bees-pennsylvania/)\n\n\n\n\none kind of leafcutter bee\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/fz1jwb06s.png] (https://i.sstatic.net/fz1jwb06s.png)", "answer_url": "https://biology.stackexchange.com/a/117784", "author": "John", "author_url": "https://biology.stackexchange.com/users/28022/john", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:38:06+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:38:06+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "63A82717-A88C-4EC8-96AF-7F6E0CE81838", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/63A82717-A88C-4EC8-96AF-7F6E0CE81838/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "John", "profile_url": "https://biology.stackexchange.com/users/28022/john", "user_type": "registered"}, "created_at": "2025-08-10T14:45:23+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "756F7865-735F-4123-BB7B-4375FC4AB945", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/756F7865-735F-4123-BB7B-4375FC4AB945/view-source"}], "score": 3, "updated_at": "2025-08-10T14:45:23+00:00"}, {"answer_html": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (image is proprietary so can only supply link)
\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.
\n\nWhile flying it could be seen to hover, which bees do not do.
\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly
\n", "answer_id": 117785, "answer_text": "It was most probably a hoverfly (syrphid) that imitates a bee. Though I didn't get a picture of that one, today I did get a picture, but of a different species. This one was feeding off the flowers. The one I saw yesterday was obviously laying eggs. It looked like this one: hoverfly (https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html) (image is proprietary so can only supply link)\n\n\n\n\nHere is the one I saw today. You can see that it is not a bee. It has only one pair of wings and stubby antennae, where bees have two pair of wings and articulated antennae.\n\n\n\n\n[image: hoverfly; source: https://i.sstatic.net/Z4zOIC1m.png] (https://i.sstatic.net/Z4zOIC1m.png)\n\n\n\n\nWhile flying it could be seen to hover, which bees do not do.\n\n\n\n\nThere are about 6000 species of syrphid found around the world. They are extremely beneficial insects. Besides being important pollinators, some of them are detritivors, eating decaying plant and animal matter and others, as in the case of the one I saw, the larvae are insectivores eating aphids and other plant sucking insects. wiki hoverfly (https://en.wikipedia.org/wiki/Hoverfly)", "answer_url": "https://biology.stackexchange.com/a/117785", "author": "Rich", "author_url": "https://biology.stackexchange.com/users/78837/rich", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-08-10T14:59:09+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:16.948131+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/46a41fae37d5c2c243f9abcbf6829a0045f46a51c624fbba2b897c320cdcba71_0.json", "raw_sha256": "e039e310d0106dc61f992ee05bbb0b0b57ded1c5092f97df2c52989edd5eaf68", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-10T14:59:09+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/7FDF9A31-BF6F-4878-9C8C-4BF48DD679C8/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-11T17:41:44+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/CA2F3A49-4686-4DF6-A2BD-51C0423C8D9C/view-source"}], "score": 7, "updated_at": "2025-08-11T17:41:44+00:00"}, {"answer_html": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, "fuzzy" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.
\n\n", "answer_id": 119462, "answer_text": "Your description did remind me of a dark-edged bee fly (Bombylius major), see photo (from Norfolk Wildlife Trust) below. Particularly, the description of size, \"fuzzy\" body, coloration, and similarity to bee body form brought a bee fly to mind. This link has more information about this species.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/oJTRLMmA.png] (https://i.sstatic.net/oJTRLMmA.png)", "answer_url": "https://biology.stackexchange.com/a/119462", "author": "OllieVet", "author_url": "https://biology.stackexchange.com/users/76792/ollievet", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-04-29T17:48:35+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:18.621890+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/af0d3457619c0da44037d660ba62b34ff4f307b5f5add32aa47548a02d98cd9c_0.json", "raw_sha256": "1bae8c6935dc08a5e6562c41b0b68738a9f472d70ac4bf71308b1f7ace0f101d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/118153;118142;118137;118126;118122;118117;118113;118102;118099;118097;118094;118081;118076;118072;118069;118065;118059;118056;118043;118039;118036;118030;118029;118025;118022;118018;117994;117992;117990;117987;117983;117981;117975;117971;117956;117953;117951;117945;117943;117941;117934;117926;117924;117920;117916;117914;117907;117892;117889;117887;117883;117876;117872;117867;117861;117860;117856;117855;117850;117849;117844;117840;117833;117821;117819;117817;117815;117814;117805;117794;117782;117774;117771;117767;117766;117761;117759;117756;117747;117732;117726;117724;117709;117701;117694;117693;117681;117680;117677;117671;117668;117664;117662;117659;117651;117641;117632;117624;117623;117607/answers?filter=withbody&order=asc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 117782, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-29T17:48:35+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "06315489-5A0C-4C60-9D5D-8818A8F9DFBF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/06315489-5A0C-4C60-9D5D-8818A8F9DFBF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "OllieVet", "profile_url": "https://biology.stackexchange.com/users/76792/ollievet", "user_type": "registered"}, "created_at": "2026-04-30T20:04:27+00:00", "raw_file": "raw/codex_api_v1/579a4d2562ba9524cfbccb0521aa128aef0c357c985479e84dfae99b419043f3_1790824187996707100_0.json", "raw_sha256": "498851e9e2788dd78c09b5bc32fc2c43c0983eaa43d2c56d9c618718c8202873", "revision_guid": "0D64A651-2F79-47CE-A317-9DA329A606B4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/0D64A651-2F79-47CE-A317-9DA329A606B4/view-source"}], "score": 2, "updated_at": "2026-04-30T20:04:27+00:00"}], "domain": "biology", "external_links": ["https://emoyer.com/services/pestcontrol/pestlibrary/bees/", "https://en.wikipedia.org/wiki/Hoverfly", "https://i.sstatic.net/Z4zOIC1m.png", "https://i.sstatic.net/fz1jwb06s.png", "https://i.sstatic.net/oJTRLMmA.png", "https://lopezuribelab.com/checklist-bees-pennsylvania/", "https://pixels.com/featured/bee-mimic-hoverfly-bob-gibbons.html"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:01.208074+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/f1b387b48f36041f506f18fa9796531023c7eae1e796ec622ad56833c02bea98_0.json", "raw_sha256": "3f8214c87c0fe16dd016324597332ca392e0ba98600877cc746483ef492ce03d", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=2&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Rich", "question_author_url": "https://biology.stackexchange.com/users/78837/rich", "question_author_user_type": "registered", "question_created_at": "2025-08-09T16:27:38+00:00", "question_html": "It looks like a bee, about 5/8" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.
\nThis is how much it resembles a bee:
\nWhile I was watching it, one part of my brain was saying "That insect is laying eggs on our cucumber leaves." This was overruled by another part of my brain that said," NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:
\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.
\nIs this normal behavior? Or does this bee need glasses?
\n
Following the comment by @mgkrebbs I realized my error and rethought my original hypothesis,
\nSo, what could it be?
\n", "question_id": 117782, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "It looks like a bee, about 5/8\" long, hairy(fuzzy) almost black with thin, pale white or yellow bands. I could not see its head clearly.\n\n\n\n\nThis is how much it resembles a bee:\n\n\n\n\nWhile I was watching it, one part of my brain was saying \"That insect is laying eggs on our cucumber leaves.\" This was overruled by another part of my brain that said,\" NO, that is obviously a bee. It must be mistaking the green of the leaves for the yellow of the flowers. I was very concerned that it would not find food and would die before it could return to its nest/hive. Hence my original question:\n\n\n\n\n\n\n\nPennsylvania. On our cucumber plants, whilst most bees flew from\nflower to flower, one bee flew from leaf to leaf, landing only\nmomentarily. It would land under the leaf, bend its abdomen slightly,\nthen take off again. It did this several dozen times. This bee was\nabout 1/2\" long mostly black with thin pale yellow bands. Sorry but by\nthe time I got my camera it had flown off.\n\n\n\n\nIs this normal behavior? Or does this bee need glasses?\n\n\n\n\n\n\n\nFollowing the comment by @mgkrebbs I realized my error and rethought my original hypothesis,\n\n\n\n\nSo, what could it be?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T16:27:38+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "26F16ABE-A9AB-4E15-A597-9D5340023B0B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/26F16ABE-A9AB-4E15-A597-9D5340023B0B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rich", "profile_url": "https://biology.stackexchange.com/users/78837/rich", "user_type": "registered"}, "created_at": "2025-08-09T22:30:33+00:00", "raw_file": "raw/codex_api_v1/d8f60fae1c998cc8c158494f81f9d96078105a2ba0c494044a17f0f0183714e8_1790824152377234600_0.json", "raw_sha256": "271777c6d25c770388803b7ee2725f9a2ad11be7bd2802305c1c50f6e43933bb", "revision_guid": "B0569837-0B0E-40F1-BF48-70E9D1B5E80F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B0569837-0B0E-40F1-BF48-70E9D1B5E80F/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/117782/looks-just-like-a-bee-but-it-isnt-what-is-it", "split": "validation", "split_group": "3ed922a8b7a0373b9e5fceeb9225e200a8f0eb3dd0336e397519db89232554e5", "tags": ["species-identification", "entomology"], "thread_id": "biology:117782", "title": "Looks just like a bee, but it isn't. What is it?"}} {"citation_context": "er. Counting 4 squares is fine, however you need to be counting at least 100 cells over that space (https://bitesizebio.com/13687/cell-counting-with-a-hemocytometer-easy-as-1-2-3/) (see step 3 in link from Bitesize Bio). This doesn't mean stop counting if you reach 100, finish t", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://bitesizebio.com/13687/cell-counting-with-a-hemocytometer-easy-as-1-2-3/", "kind": "external_url", "post_id": 114728, "post_url": "https://biology.stackexchange.com/a/114728", "product": "citations", "record_id": "Scientific-Citation-Graph:f77f15ae47162e756073efcf", "split": "validation", "thread": {"accepted_answer_id": 114728, "answers": [{"answer_html": "Without further information it is quite hard to say. However, there are a few things that might be playing into this.
\nStatistics - For your counts you need to be counting a decent number of cells on each side (and each square) of the hemocytometer. Counting 4 squares is fine, however you need to be counting at least 100 cells over that space (see step 3 in link from Bitesize Bio). This doesn't mean stop counting if you reach 100, finish the square you are in at least and it means 20+ cells per large square. If you are counting fewer cells, your counts will be inaccurate.
\nStatistics - hemocytometers have about an error of about +/-15% in the hands of an experienced user.
\nStatistics - Low cell density; this plays into the one above. If you resuspend your cells in too large a volume, it is much harder to take a representative sample of your cells, this means you can't rely on the sample to accurately represent your cell population. This also goes for your subsample and dilution - there's no reason you can't do a 1:1 dilution with trypan blue rather than a 1 in 10.
\nSettling - cells settle quite fast in all the tubes you use. You must resuspend the cells immediately prior to sampling and immediately prior to loading the hemocytometer. I've documented an example of how fast they settle in my own counting (out of interest, decided to see if there was an effect): If I take up 100 ul of cells in a micropipette (say P-200) and load both sides of a hemocytometer from that same volume (takes me less than 20 s for both sides), there is a consistent ~20% difference between the sides due to settling of the cells in the tip. If I take separate samples, that error goes away.
\nCell type - Fibroblasts are large. This means you don't get as many per area as you might see in examples of cell density (e.g. Invitrogen's guide to Useful Numbers for Cell Culture), which plays into 1 and 3 above.
\nCell type - Fibroblasts attach quite firmly. This means you need to visually inspect the cells to ensure detachment and look to see that you have successfully harvested the majority (there are always a few left behind). Don't use too large a volume for this as it plays into 1 and 3 again.
\nCell handling - if you over detached your cells (i.e trypsin for too long) or scraped your cells off instead of using trypsin (or similar), then the cells will clump. It is very hard to count clumps of cells accurately and even harder to sample them accurately - they settle much faster than single cells.
\nCell handling - Making a single cell suspension. You successfully detached your cells, but they have clumped and you didn't make a single cell suspension. As in 7 above, these are very hard to count. You must ensure that the majority of the cells you count are single; you should have <5% clumps.
\nIncorrect usage - you are counting using the large squares right? That's the ones sub-divided into 16 or 25 smaller squares (see red squares in image by step 3 in Bitesize Bio link) and often surrounded by 2-3 lines (Neubauer hemocytometer). If you were using the small subdivisions, you will be out by a factor of 16, but sampling errors will play a big role in how accurate the counts are.
\nFor some reason, when I use my hemocytometer, my counts and calculations always come out really small. My equation is: (cell count / # of boxes) * dilution factor * 10,000 = cells/ml. (I usually only count the four corner boxes for my fibroblast cultures).
\nMy calculations usually are less than half of what I expect them to be from the microscope estimations and confluency. I have tried various dilutions and have even vortexed the cell mixtures to ensure even distribution. Are there any suggestions as to what I'm possibly doing wrong?
\nEDIT: I usually use a dilution factor of 10 and then multiply the end number by the original number of mLs that the sample was taken from.
\n", "question_id": 114726, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "For some reason, when I use my hemocytometer, my counts and calculations always come out really small. My equation is: (cell count / # of boxes) * dilution factor * 10,000 = cells/ml. (I usually only count the four corner boxes for my fibroblast cultures).\n\n\n\n\nMy calculations usually are less than half of what I expect them to be from the microscope estimations and confluency. I have tried various dilutions and have even vortexed the cell mixtures to ensure even distribution. Are there any suggestions as to what I'm possibly doing wrong?\n\n\n\n\nEDIT: I usually use a dilution factor of 10 and then multiply the end number by the original number of mLs that the sample was taken from.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MakM", "profile_url": "https://biology.stackexchange.com/users/80980/makm", "user_type": "registered"}, "created_at": "2024-05-20T17:09:13+00:00", "raw_file": "raw/codex_api_v1/282295cb58dc6e06535acb3b0271f00300dd2b6c85e78f47464472e253aa1cdd_1790824077120302400_0.json", "raw_sha256": "93650624b92f65499fe4854f330ed8fd8aceb1ad0cb02a65e5016e49e4b22c69", "revision_guid": "CE7F3F5A-C38B-4F4A-8EE4-17A5924847F4", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/CE7F3F5A-C38B-4F4A-8EE4-17A5924847F4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MakM", "profile_url": "https://biology.stackexchange.com/users/80980/makm", "user_type": "registered"}, "created_at": "2024-05-20T19:33:00+00:00", "raw_file": "raw/codex_api_v1/282295cb58dc6e06535acb3b0271f00300dd2b6c85e78f47464472e253aa1cdd_1790824077120302400_0.json", "raw_sha256": "93650624b92f65499fe4854f330ed8fd8aceb1ad0cb02a65e5016e49e4b22c69", "revision_guid": "91A78453-692F-4772-8F9B-F86079246EFB", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/91A78453-692F-4772-8F9B-F86079246EFB/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/114726/how-can-i-be-more-accurate-in-my-cell-counting", "split": "validation", "split_group": "22c21807ecb95f077c60ea7e27d34fe13ff209cf8271e91452a944c57ff4762f", "tags": ["cell-biology", "cell-culture"], "thread_id": "biology:114726", "title": "How can I be more accurate in my cell counting?"}} {"citation_context": " might see in examples of cell density (e.g. Invitrogen's guide to Useful Numbers for Cell Culture (https://www.thermofisher.com/nz/en/home/references/gibco-cell-culture-basics/cell-culture-protocols/cell-culture-useful-numbers.html)), which plays into 1 and 3 above.\n\n\n\n\n\n\n\n\n\nCell type - Fibroblasts attach quite firmly. This means", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.thermofisher.com/nz/en/home/references/gibco-cell-culture-basics/cell-culture-protocols/cell-culture-useful-numbers.html", "kind": "external_url", "post_id": 114728, "post_url": "https://biology.stackexchange.com/a/114728", "product": "citations", "record_id": "Scientific-Citation-Graph:ba16530915a8a3958b51d895", "split": "validation", "thread": {"accepted_answer_id": 114728, "answers": [{"answer_html": "Without further information it is quite hard to say. However, there are a few things that might be playing into this.
\nStatistics - For your counts you need to be counting a decent number of cells on each side (and each square) of the hemocytometer. Counting 4 squares is fine, however you need to be counting at least 100 cells over that space (see step 3 in link from Bitesize Bio). This doesn't mean stop counting if you reach 100, finish the square you are in at least and it means 20+ cells per large square. If you are counting fewer cells, your counts will be inaccurate.
\nStatistics - hemocytometers have about an error of about +/-15% in the hands of an experienced user.
\nStatistics - Low cell density; this plays into the one above. If you resuspend your cells in too large a volume, it is much harder to take a representative sample of your cells, this means you can't rely on the sample to accurately represent your cell population. This also goes for your subsample and dilution - there's no reason you can't do a 1:1 dilution with trypan blue rather than a 1 in 10.
\nSettling - cells settle quite fast in all the tubes you use. You must resuspend the cells immediately prior to sampling and immediately prior to loading the hemocytometer. I've documented an example of how fast they settle in my own counting (out of interest, decided to see if there was an effect): If I take up 100 ul of cells in a micropipette (say P-200) and load both sides of a hemocytometer from that same volume (takes me less than 20 s for both sides), there is a consistent ~20% difference between the sides due to settling of the cells in the tip. If I take separate samples, that error goes away.
\nCell type - Fibroblasts are large. This means you don't get as many per area as you might see in examples of cell density (e.g. Invitrogen's guide to Useful Numbers for Cell Culture), which plays into 1 and 3 above.
\nCell type - Fibroblasts attach quite firmly. This means you need to visually inspect the cells to ensure detachment and look to see that you have successfully harvested the majority (there are always a few left behind). Don't use too large a volume for this as it plays into 1 and 3 again.
\nCell handling - if you over detached your cells (i.e trypsin for too long) or scraped your cells off instead of using trypsin (or similar), then the cells will clump. It is very hard to count clumps of cells accurately and even harder to sample them accurately - they settle much faster than single cells.
\nCell handling - Making a single cell suspension. You successfully detached your cells, but they have clumped and you didn't make a single cell suspension. As in 7 above, these are very hard to count. You must ensure that the majority of the cells you count are single; you should have <5% clumps.
\nIncorrect usage - you are counting using the large squares right? That's the ones sub-divided into 16 or 25 smaller squares (see red squares in image by step 3 in Bitesize Bio link) and often surrounded by 2-3 lines (Neubauer hemocytometer). If you were using the small subdivisions, you will be out by a factor of 16, but sampling errors will play a big role in how accurate the counts are.
\nFor some reason, when I use my hemocytometer, my counts and calculations always come out really small. My equation is: (cell count / # of boxes) * dilution factor * 10,000 = cells/ml. (I usually only count the four corner boxes for my fibroblast cultures).
\nMy calculations usually are less than half of what I expect them to be from the microscope estimations and confluency. I have tried various dilutions and have even vortexed the cell mixtures to ensure even distribution. Are there any suggestions as to what I'm possibly doing wrong?
\nEDIT: I usually use a dilution factor of 10 and then multiply the end number by the original number of mLs that the sample was taken from.
\n", "question_id": 114726, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "For some reason, when I use my hemocytometer, my counts and calculations always come out really small. My equation is: (cell count / # of boxes) * dilution factor * 10,000 = cells/ml. (I usually only count the four corner boxes for my fibroblast cultures).\n\n\n\n\nMy calculations usually are less than half of what I expect them to be from the microscope estimations and confluency. I have tried various dilutions and have even vortexed the cell mixtures to ensure even distribution. Are there any suggestions as to what I'm possibly doing wrong?\n\n\n\n\nEDIT: I usually use a dilution factor of 10 and then multiply the end number by the original number of mLs that the sample was taken from.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MakM", "profile_url": "https://biology.stackexchange.com/users/80980/makm", "user_type": "registered"}, "created_at": "2024-05-20T17:09:13+00:00", "raw_file": "raw/codex_api_v1/282295cb58dc6e06535acb3b0271f00300dd2b6c85e78f47464472e253aa1cdd_1790824077120302400_0.json", "raw_sha256": "93650624b92f65499fe4854f330ed8fd8aceb1ad0cb02a65e5016e49e4b22c69", "revision_guid": "CE7F3F5A-C38B-4F4A-8EE4-17A5924847F4", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/CE7F3F5A-C38B-4F4A-8EE4-17A5924847F4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "MakM", "profile_url": "https://biology.stackexchange.com/users/80980/makm", "user_type": "registered"}, "created_at": "2024-05-20T19:33:00+00:00", "raw_file": "raw/codex_api_v1/282295cb58dc6e06535acb3b0271f00300dd2b6c85e78f47464472e253aa1cdd_1790824077120302400_0.json", "raw_sha256": "93650624b92f65499fe4854f330ed8fd8aceb1ad0cb02a65e5016e49e4b22c69", "revision_guid": "91A78453-692F-4772-8F9B-F86079246EFB", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/91A78453-692F-4772-8F9B-F86079246EFB/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/114726/how-can-i-be-more-accurate-in-my-cell-counting", "split": "validation", "split_group": "22c21807ecb95f077c60ea7e27d34fe13ff209cf8271e91452a944c57ff4762f", "tags": ["cell-biology", "cell-culture"], "thread_id": "biology:114726", "title": "How can I be more accurate in my cell counting?"}} {"citation_context": "such that their contents would just merge with the soup.\n\n\n\n\nOf course bone, tendon and perimysium (https://en.wikipedia.org/wiki/Perimysium) (connective material within muscle tissue) may survive and keep the contents trapped, so a piece o", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://en.wikipedia.org/wiki/Perimysium", "kind": "external_url", "post_id": 115987, "post_url": "https://biology.stackexchange.com/questions/115987/are-there-still-chicken-cells-in-chicken-soup", "product": "citations", "record_id": "Scientific-Citation-Graph:0e50ccae50674e80aaf451f0", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.
\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.
\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.
\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm. Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8
\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019).
\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.
\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.
\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.
\n", "answer_id": 115992, "answer_text": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.\n\n\n\n\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.\n\n\n\n\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.\n\n\n\n\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm (https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm). Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8\n\n\n\n\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019 (https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019)).\n\n\n\n\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane (https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane) , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.\n\n\n\n\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.\n\n\n\n\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.", "answer_url": "https://biology.stackexchange.com/a/115992", "author": "Woody", "author_url": "https://biology.stackexchange.com/users/98830/woody", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-01-22T20:42:53+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:22.614155+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/2c8799380b8f5d7bf0fd42e594fd78a1835b27e1da9f481cc00f096bab9c01ca_0.json", "raw_sha256": "348375a094fdfd6d9ca55d0bddc65d8dc7a7f0757e1e5a44c25e22a66b1a4892", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/116119;116113;116097;116096;116091;116087;116076;116067;116063;116059;116055;116037;116034;116028;116022;116012;116005;115997;115989;115988;115987;115979;115978;115976;115974;115973;115970;115966;115965;115957;115952;115939;115933;115932;115927;115921;115915;115903;115897;115894;115886;115885;115884;115881;115880;115868;115867;115857;115852;115840;115830;115825;115819;115815;115791;115780;115773;115764;115759;115756;115743;115736;115726;115723;115713;115699;115691;115689;115685;115678;115668;115664;115657;115650;115642;115639;115632;115627;115626;115609;115602;115598;115592;115588;115587;115580;115578;115570;115566;115562;115549;115537;115536;115531;115530;115528;115525;115521;115513;115510/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115987, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T20:42:53+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "4AD6E1A7-A688-4381-BC0E-612F66202747", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AD6E1A7-A688-4381-BC0E-612F66202747/view-source"}, {"content_license": null, "contributor": {"display_name": "AliceD", "profile_url": "https://biology.stackexchange.com/users/9943/aliced", "user_type": "registered"}, "created_at": "2025-01-22T22:08:15+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T22:46:31+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "B7973B09-2242-45E6-BBC3-31AC3F1053AD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B7973B09-2242-45E6-BBC3-31AC3F1053AD/view-source"}, {"content_license": null, "contributor": {"display_name": "Chris", "profile_url": "https://biology.stackexchange.com/users/5144/chris", "user_type": "moderator"}, "created_at": "2025-01-24T06:40:20+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "BF004751-6C6B-4181-A98F-35A4E06EB3A7", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/BF004751-6C6B-4181-A98F-35A4E06EB3A7/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "JimN", "profile_url": "https://biology.stackexchange.com/users/61490/jimn", "user_type": "registered"}, "created_at": "2025-01-26T19:50:07+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "EF637342-A242-4D2E-B088-8365AF4C953A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/EF637342-A242-4D2E-B088-8365AF4C953A/view-source"}], "score": 2, "updated_at": "2025-01-26T19:50:07+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Perimysium", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane", "https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:04.377249+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/54ece81cba3a5a552bb15d6d3feedc4324a2ba2706d33480080ece9537efd4b1_0.json", "raw_sha256": "f1eb8f7eda9336b81701b663029f9411e040c0bcf262148b7ede9a103ae73e69", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=4&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "uhoh", "question_author_url": "https://biology.stackexchange.com/users/27918/uhoh", "question_author_user_type": "registered", "question_created_at": "2025-01-21T02:21:19+00:00", "question_html": "In a discussion elsewhere I referred to chicken soup as having plenty of "cellular material" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.
\nOf course bone, tendon and perimysium (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other "cellular material" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.
\nGenerally speaking, are there still chicken cells in chicken soup?
\nOr are they all pretty much destroyed in the cooking process?
\n", "question_id": 115987, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "In a discussion elsewhere I referred to chicken soup as having plenty of \"cellular material\" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.\n\n\n\n\nOf course bone, tendon and perimysium (https://en.wikipedia.org/wiki/Perimysium) (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other \"cellular material\" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.\n\n\n\n\nGenerally speaking, are there still chicken cells in chicken soup?\n\n\n\n\nOr are they all pretty much destroyed in the cooking process?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "uhoh", "profile_url": "https://biology.stackexchange.com/users/27918/uhoh", "user_type": "registered"}, "created_at": "2025-01-21T02:21:19+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "40730F9A-9111-4C99-8DDD-96B63953B376", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/40730F9A-9111-4C99-8DDD-96B63953B376/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115987/are-there-still-chicken-cells-in-chicken-soup", "split": "validation", "split_group": "99c83c44d9c03188772962d7913b0710583cb38e45692eb0f5fa6a24b801f58c", "tags": ["cell-membrane", "temperature"], "thread_id": "biology:115987", "title": "Are there still chicken cells in chicken soup?"}} {"citation_context": "pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019 (https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019)).\n\n\n\n\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/en", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "kind": "external_url", "post_id": 115992, "post_url": "https://biology.stackexchange.com/a/115992", "product": "citations", "record_id": "Scientific-Citation-Graph:727817a8a0db05e3d15f9b7e", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.
\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.
\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.
\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm. Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8
\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019).
\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.
\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.
\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.
\n", "answer_id": 115992, "answer_text": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.\n\n\n\n\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.\n\n\n\n\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.\n\n\n\n\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm (https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm). Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8\n\n\n\n\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019 (https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019)).\n\n\n\n\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane (https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane) , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.\n\n\n\n\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.\n\n\n\n\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.", "answer_url": "https://biology.stackexchange.com/a/115992", "author": "Woody", "author_url": "https://biology.stackexchange.com/users/98830/woody", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-01-22T20:42:53+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:22.614155+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/2c8799380b8f5d7bf0fd42e594fd78a1835b27e1da9f481cc00f096bab9c01ca_0.json", "raw_sha256": "348375a094fdfd6d9ca55d0bddc65d8dc7a7f0757e1e5a44c25e22a66b1a4892", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/116119;116113;116097;116096;116091;116087;116076;116067;116063;116059;116055;116037;116034;116028;116022;116012;116005;115997;115989;115988;115987;115979;115978;115976;115974;115973;115970;115966;115965;115957;115952;115939;115933;115932;115927;115921;115915;115903;115897;115894;115886;115885;115884;115881;115880;115868;115867;115857;115852;115840;115830;115825;115819;115815;115791;115780;115773;115764;115759;115756;115743;115736;115726;115723;115713;115699;115691;115689;115685;115678;115668;115664;115657;115650;115642;115639;115632;115627;115626;115609;115602;115598;115592;115588;115587;115580;115578;115570;115566;115562;115549;115537;115536;115531;115530;115528;115525;115521;115513;115510/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115987, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T20:42:53+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "4AD6E1A7-A688-4381-BC0E-612F66202747", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AD6E1A7-A688-4381-BC0E-612F66202747/view-source"}, {"content_license": null, "contributor": {"display_name": "AliceD", "profile_url": "https://biology.stackexchange.com/users/9943/aliced", "user_type": "registered"}, "created_at": "2025-01-22T22:08:15+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T22:46:31+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "B7973B09-2242-45E6-BBC3-31AC3F1053AD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B7973B09-2242-45E6-BBC3-31AC3F1053AD/view-source"}, {"content_license": null, "contributor": {"display_name": "Chris", "profile_url": "https://biology.stackexchange.com/users/5144/chris", "user_type": "moderator"}, "created_at": "2025-01-24T06:40:20+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "BF004751-6C6B-4181-A98F-35A4E06EB3A7", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/BF004751-6C6B-4181-A98F-35A4E06EB3A7/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "JimN", "profile_url": "https://biology.stackexchange.com/users/61490/jimn", "user_type": "registered"}, "created_at": "2025-01-26T19:50:07+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "EF637342-A242-4D2E-B088-8365AF4C953A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/EF637342-A242-4D2E-B088-8365AF4C953A/view-source"}], "score": 2, "updated_at": "2025-01-26T19:50:07+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Perimysium", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane", "https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:04.377249+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/54ece81cba3a5a552bb15d6d3feedc4324a2ba2706d33480080ece9537efd4b1_0.json", "raw_sha256": "f1eb8f7eda9336b81701b663029f9411e040c0bcf262148b7ede9a103ae73e69", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=4&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "uhoh", "question_author_url": "https://biology.stackexchange.com/users/27918/uhoh", "question_author_user_type": "registered", "question_created_at": "2025-01-21T02:21:19+00:00", "question_html": "In a discussion elsewhere I referred to chicken soup as having plenty of "cellular material" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.
\nOf course bone, tendon and perimysium (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other "cellular material" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.
\nGenerally speaking, are there still chicken cells in chicken soup?
\nOr are they all pretty much destroyed in the cooking process?
\n", "question_id": 115987, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "In a discussion elsewhere I referred to chicken soup as having plenty of \"cellular material\" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.\n\n\n\n\nOf course bone, tendon and perimysium (https://en.wikipedia.org/wiki/Perimysium) (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other \"cellular material\" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.\n\n\n\n\nGenerally speaking, are there still chicken cells in chicken soup?\n\n\n\n\nOr are they all pretty much destroyed in the cooking process?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "uhoh", "profile_url": "https://biology.stackexchange.com/users/27918/uhoh", "user_type": "registered"}, "created_at": "2025-01-21T02:21:19+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "40730F9A-9111-4C99-8DDD-96B63953B376", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/40730F9A-9111-4C99-8DDD-96B63953B376/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115987/are-there-still-chicken-cells-in-chicken-soup", "split": "validation", "split_group": "99c83c44d9c03188772962d7913b0710583cb38e45692eb0f5fa6a24b801f58c", "tags": ["cell-membrane", "temperature"], "thread_id": "biology:115987", "title": "Are there still chicken cells in chicken soup?"}} {"citation_context": "cken broth 5.8\n\n\n\n\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019 (https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%20", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "kind": "external_url", "post_id": 115992, "post_url": "https://biology.stackexchange.com/a/115992", "product": "citations", "record_id": "Scientific-Citation-Graph:2a15620670dc4add6d6d00b1", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.
\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.
\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.
\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm. Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8
\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019).
\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.
\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.
\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.
\n", "answer_id": 115992, "answer_text": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.\n\n\n\n\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.\n\n\n\n\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.\n\n\n\n\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm (https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm). Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8\n\n\n\n\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019 (https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019)).\n\n\n\n\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane (https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane) , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.\n\n\n\n\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.\n\n\n\n\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.", "answer_url": "https://biology.stackexchange.com/a/115992", "author": "Woody", "author_url": "https://biology.stackexchange.com/users/98830/woody", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-01-22T20:42:53+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:22.614155+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/2c8799380b8f5d7bf0fd42e594fd78a1835b27e1da9f481cc00f096bab9c01ca_0.json", "raw_sha256": "348375a094fdfd6d9ca55d0bddc65d8dc7a7f0757e1e5a44c25e22a66b1a4892", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/116119;116113;116097;116096;116091;116087;116076;116067;116063;116059;116055;116037;116034;116028;116022;116012;116005;115997;115989;115988;115987;115979;115978;115976;115974;115973;115970;115966;115965;115957;115952;115939;115933;115932;115927;115921;115915;115903;115897;115894;115886;115885;115884;115881;115880;115868;115867;115857;115852;115840;115830;115825;115819;115815;115791;115780;115773;115764;115759;115756;115743;115736;115726;115723;115713;115699;115691;115689;115685;115678;115668;115664;115657;115650;115642;115639;115632;115627;115626;115609;115602;115598;115592;115588;115587;115580;115578;115570;115566;115562;115549;115537;115536;115531;115530;115528;115525;115521;115513;115510/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115987, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T20:42:53+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "4AD6E1A7-A688-4381-BC0E-612F66202747", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AD6E1A7-A688-4381-BC0E-612F66202747/view-source"}, {"content_license": null, "contributor": {"display_name": "AliceD", "profile_url": "https://biology.stackexchange.com/users/9943/aliced", "user_type": "registered"}, "created_at": "2025-01-22T22:08:15+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T22:46:31+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "B7973B09-2242-45E6-BBC3-31AC3F1053AD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B7973B09-2242-45E6-BBC3-31AC3F1053AD/view-source"}, {"content_license": null, "contributor": {"display_name": "Chris", "profile_url": "https://biology.stackexchange.com/users/5144/chris", "user_type": "moderator"}, "created_at": "2025-01-24T06:40:20+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "BF004751-6C6B-4181-A98F-35A4E06EB3A7", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/BF004751-6C6B-4181-A98F-35A4E06EB3A7/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "JimN", "profile_url": "https://biology.stackexchange.com/users/61490/jimn", "user_type": "registered"}, "created_at": "2025-01-26T19:50:07+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "EF637342-A242-4D2E-B088-8365AF4C953A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/EF637342-A242-4D2E-B088-8365AF4C953A/view-source"}], "score": 2, "updated_at": "2025-01-26T19:50:07+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Perimysium", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane", "https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:04.377249+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/54ece81cba3a5a552bb15d6d3feedc4324a2ba2706d33480080ece9537efd4b1_0.json", "raw_sha256": "f1eb8f7eda9336b81701b663029f9411e040c0bcf262148b7ede9a103ae73e69", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=4&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "uhoh", "question_author_url": "https://biology.stackexchange.com/users/27918/uhoh", "question_author_user_type": "registered", "question_created_at": "2025-01-21T02:21:19+00:00", "question_html": "In a discussion elsewhere I referred to chicken soup as having plenty of "cellular material" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.
\nOf course bone, tendon and perimysium (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other "cellular material" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.
\nGenerally speaking, are there still chicken cells in chicken soup?
\nOr are they all pretty much destroyed in the cooking process?
\n", "question_id": 115987, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "In a discussion elsewhere I referred to chicken soup as having plenty of \"cellular material\" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.\n\n\n\n\nOf course bone, tendon and perimysium (https://en.wikipedia.org/wiki/Perimysium) (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other \"cellular material\" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.\n\n\n\n\nGenerally speaking, are there still chicken cells in chicken soup?\n\n\n\n\nOr are they all pretty much destroyed in the cooking process?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "uhoh", "profile_url": "https://biology.stackexchange.com/users/27918/uhoh", "user_type": "registered"}, "created_at": "2025-01-21T02:21:19+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "40730F9A-9111-4C99-8DDD-96B63953B376", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/40730F9A-9111-4C99-8DDD-96B63953B376/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115987/are-there-still-chicken-cells-in-chicken-soup", "split": "validation", "split_group": "99c83c44d9c03188772962d7913b0710583cb38e45692eb0f5fa6a24b801f58c", "tags": ["cell-membrane", "temperature"], "thread_id": "biology:115987", "title": "Are there still chicken cells in chicken soup?"}} {"citation_context": "03904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm (https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm). Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8\n\n\n\n\nHe", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "kind": "external_url", "post_id": 115992, "post_url": "https://biology.stackexchange.com/a/115992", "product": "citations", "record_id": "Scientific-Citation-Graph:3834d6ce572c2dbe3c898d90", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.
\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.
\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.
\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm. Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8
\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019).
\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.
\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.
\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.
\n", "answer_id": 115992, "answer_text": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.\n\n\n\n\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.\n\n\n\n\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.\n\n\n\n\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm (https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm). Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8\n\n\n\n\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019 (https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019)).\n\n\n\n\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane (https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane) , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.\n\n\n\n\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.\n\n\n\n\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.", "answer_url": "https://biology.stackexchange.com/a/115992", "author": "Woody", "author_url": "https://biology.stackexchange.com/users/98830/woody", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-01-22T20:42:53+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:22.614155+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/2c8799380b8f5d7bf0fd42e594fd78a1835b27e1da9f481cc00f096bab9c01ca_0.json", "raw_sha256": "348375a094fdfd6d9ca55d0bddc65d8dc7a7f0757e1e5a44c25e22a66b1a4892", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/116119;116113;116097;116096;116091;116087;116076;116067;116063;116059;116055;116037;116034;116028;116022;116012;116005;115997;115989;115988;115987;115979;115978;115976;115974;115973;115970;115966;115965;115957;115952;115939;115933;115932;115927;115921;115915;115903;115897;115894;115886;115885;115884;115881;115880;115868;115867;115857;115852;115840;115830;115825;115819;115815;115791;115780;115773;115764;115759;115756;115743;115736;115726;115723;115713;115699;115691;115689;115685;115678;115668;115664;115657;115650;115642;115639;115632;115627;115626;115609;115602;115598;115592;115588;115587;115580;115578;115570;115566;115562;115549;115537;115536;115531;115530;115528;115525;115521;115513;115510/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115987, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T20:42:53+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "4AD6E1A7-A688-4381-BC0E-612F66202747", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AD6E1A7-A688-4381-BC0E-612F66202747/view-source"}, {"content_license": null, "contributor": {"display_name": "AliceD", "profile_url": "https://biology.stackexchange.com/users/9943/aliced", "user_type": "registered"}, "created_at": "2025-01-22T22:08:15+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T22:46:31+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "B7973B09-2242-45E6-BBC3-31AC3F1053AD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B7973B09-2242-45E6-BBC3-31AC3F1053AD/view-source"}, {"content_license": null, "contributor": {"display_name": "Chris", "profile_url": "https://biology.stackexchange.com/users/5144/chris", "user_type": "moderator"}, "created_at": "2025-01-24T06:40:20+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "BF004751-6C6B-4181-A98F-35A4E06EB3A7", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/BF004751-6C6B-4181-A98F-35A4E06EB3A7/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "JimN", "profile_url": "https://biology.stackexchange.com/users/61490/jimn", "user_type": "registered"}, "created_at": "2025-01-26T19:50:07+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "EF637342-A242-4D2E-B088-8365AF4C953A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/EF637342-A242-4D2E-B088-8365AF4C953A/view-source"}], "score": 2, "updated_at": "2025-01-26T19:50:07+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Perimysium", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane", "https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:04.377249+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/54ece81cba3a5a552bb15d6d3feedc4324a2ba2706d33480080ece9537efd4b1_0.json", "raw_sha256": "f1eb8f7eda9336b81701b663029f9411e040c0bcf262148b7ede9a103ae73e69", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=4&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "uhoh", "question_author_url": "https://biology.stackexchange.com/users/27918/uhoh", "question_author_user_type": "registered", "question_created_at": "2025-01-21T02:21:19+00:00", "question_html": "In a discussion elsewhere I referred to chicken soup as having plenty of "cellular material" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.
\nOf course bone, tendon and perimysium (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other "cellular material" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.
\nGenerally speaking, are there still chicken cells in chicken soup?
\nOr are they all pretty much destroyed in the cooking process?
\n", "question_id": 115987, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "In a discussion elsewhere I referred to chicken soup as having plenty of \"cellular material\" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.\n\n\n\n\nOf course bone, tendon and perimysium (https://en.wikipedia.org/wiki/Perimysium) (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other \"cellular material\" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.\n\n\n\n\nGenerally speaking, are there still chicken cells in chicken soup?\n\n\n\n\nOr are they all pretty much destroyed in the cooking process?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "uhoh", "profile_url": "https://biology.stackexchange.com/users/27918/uhoh", "user_type": "registered"}, "created_at": "2025-01-21T02:21:19+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "40730F9A-9111-4C99-8DDD-96B63953B376", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/40730F9A-9111-4C99-8DDD-96B63953B376/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115987/are-there-still-chicken-cells-in-chicken-soup", "split": "validation", "split_group": "99c83c44d9c03188772962d7913b0710583cb38e45692eb0f5fa6a24b801f58c", "tags": ["cell-membrane", "temperature"], "thread_id": "biology:115987", "title": "Are there still chicken cells in chicken soup?"}} {"citation_context": "r digest cell structure, so lysis starts a chain reaction.\n\n\n\n\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm (https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellu", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "kind": "external_url", "post_id": 115992, "post_url": "https://biology.stackexchange.com/a/115992", "product": "citations", "record_id": "Scientific-Citation-Graph:d92d9d2a2765919eb69419a5", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.
\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.
\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.
\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm. Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8
\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019).
\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.
\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.
\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.
\n", "answer_id": 115992, "answer_text": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.\n\n\n\n\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.\n\n\n\n\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.\n\n\n\n\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm (https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm). Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8\n\n\n\n\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019 (https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019)).\n\n\n\n\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane (https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane) , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.\n\n\n\n\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.\n\n\n\n\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.", "answer_url": "https://biology.stackexchange.com/a/115992", "author": "Woody", "author_url": "https://biology.stackexchange.com/users/98830/woody", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-01-22T20:42:53+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:22.614155+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/2c8799380b8f5d7bf0fd42e594fd78a1835b27e1da9f481cc00f096bab9c01ca_0.json", "raw_sha256": "348375a094fdfd6d9ca55d0bddc65d8dc7a7f0757e1e5a44c25e22a66b1a4892", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/116119;116113;116097;116096;116091;116087;116076;116067;116063;116059;116055;116037;116034;116028;116022;116012;116005;115997;115989;115988;115987;115979;115978;115976;115974;115973;115970;115966;115965;115957;115952;115939;115933;115932;115927;115921;115915;115903;115897;115894;115886;115885;115884;115881;115880;115868;115867;115857;115852;115840;115830;115825;115819;115815;115791;115780;115773;115764;115759;115756;115743;115736;115726;115723;115713;115699;115691;115689;115685;115678;115668;115664;115657;115650;115642;115639;115632;115627;115626;115609;115602;115598;115592;115588;115587;115580;115578;115570;115566;115562;115549;115537;115536;115531;115530;115528;115525;115521;115513;115510/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115987, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T20:42:53+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "4AD6E1A7-A688-4381-BC0E-612F66202747", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AD6E1A7-A688-4381-BC0E-612F66202747/view-source"}, {"content_license": null, "contributor": {"display_name": "AliceD", "profile_url": "https://biology.stackexchange.com/users/9943/aliced", "user_type": "registered"}, "created_at": "2025-01-22T22:08:15+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T22:46:31+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "B7973B09-2242-45E6-BBC3-31AC3F1053AD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B7973B09-2242-45E6-BBC3-31AC3F1053AD/view-source"}, {"content_license": null, "contributor": {"display_name": "Chris", "profile_url": "https://biology.stackexchange.com/users/5144/chris", "user_type": "moderator"}, "created_at": "2025-01-24T06:40:20+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "BF004751-6C6B-4181-A98F-35A4E06EB3A7", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/BF004751-6C6B-4181-A98F-35A4E06EB3A7/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "JimN", "profile_url": "https://biology.stackexchange.com/users/61490/jimn", "user_type": "registered"}, "created_at": "2025-01-26T19:50:07+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "EF637342-A242-4D2E-B088-8365AF4C953A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/EF637342-A242-4D2E-B088-8365AF4C953A/view-source"}], "score": 2, "updated_at": "2025-01-26T19:50:07+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Perimysium", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane", "https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:04.377249+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/54ece81cba3a5a552bb15d6d3feedc4324a2ba2706d33480080ece9537efd4b1_0.json", "raw_sha256": "f1eb8f7eda9336b81701b663029f9411e040c0bcf262148b7ede9a103ae73e69", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=4&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "uhoh", "question_author_url": "https://biology.stackexchange.com/users/27918/uhoh", "question_author_user_type": "registered", "question_created_at": "2025-01-21T02:21:19+00:00", "question_html": "In a discussion elsewhere I referred to chicken soup as having plenty of "cellular material" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.
\nOf course bone, tendon and perimysium (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other "cellular material" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.
\nGenerally speaking, are there still chicken cells in chicken soup?
\nOr are they all pretty much destroyed in the cooking process?
\n", "question_id": 115987, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "In a discussion elsewhere I referred to chicken soup as having plenty of \"cellular material\" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.\n\n\n\n\nOf course bone, tendon and perimysium (https://en.wikipedia.org/wiki/Perimysium) (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other \"cellular material\" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.\n\n\n\n\nGenerally speaking, are there still chicken cells in chicken soup?\n\n\n\n\nOr are they all pretty much destroyed in the cooking process?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "uhoh", "profile_url": "https://biology.stackexchange.com/users/27918/uhoh", "user_type": "registered"}, "created_at": "2025-01-21T02:21:19+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "40730F9A-9111-4C99-8DDD-96B63953B376", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/40730F9A-9111-4C99-8DDD-96B63953B376/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115987/are-there-still-chicken-cells-in-chicken-soup", "split": "validation", "split_group": "99c83c44d9c03188772962d7913b0710583cb38e45692eb0f5fa6a24b801f58c", "tags": ["cell-membrane", "temperature"], "thread_id": "biology:115987", "title": "Are there still chicken cells in chicken soup?"}} {"citation_context": "smolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane (https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane) , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if ", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane", "kind": "external_url", "post_id": 115992, "post_url": "https://biology.stackexchange.com/a/115992", "product": "citations", "record_id": "Scientific-Citation-Graph:4e5c8d52ec3690d329ca462c", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.
\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.
\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.
\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm. Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8
\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019).
\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.
\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.
\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.
\n", "answer_id": 115992, "answer_text": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.\n\n\n\n\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.\n\n\n\n\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.\n\n\n\n\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm (https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm). Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8\n\n\n\n\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019 (https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019)).\n\n\n\n\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane (https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane) , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.\n\n\n\n\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.\n\n\n\n\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.", "answer_url": "https://biology.stackexchange.com/a/115992", "author": "Woody", "author_url": "https://biology.stackexchange.com/users/98830/woody", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-01-22T20:42:53+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:22.614155+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/2c8799380b8f5d7bf0fd42e594fd78a1835b27e1da9f481cc00f096bab9c01ca_0.json", "raw_sha256": "348375a094fdfd6d9ca55d0bddc65d8dc7a7f0757e1e5a44c25e22a66b1a4892", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/116119;116113;116097;116096;116091;116087;116076;116067;116063;116059;116055;116037;116034;116028;116022;116012;116005;115997;115989;115988;115987;115979;115978;115976;115974;115973;115970;115966;115965;115957;115952;115939;115933;115932;115927;115921;115915;115903;115897;115894;115886;115885;115884;115881;115880;115868;115867;115857;115852;115840;115830;115825;115819;115815;115791;115780;115773;115764;115759;115756;115743;115736;115726;115723;115713;115699;115691;115689;115685;115678;115668;115664;115657;115650;115642;115639;115632;115627;115626;115609;115602;115598;115592;115588;115587;115580;115578;115570;115566;115562;115549;115537;115536;115531;115530;115528;115525;115521;115513;115510/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115987, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T20:42:53+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "4AD6E1A7-A688-4381-BC0E-612F66202747", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AD6E1A7-A688-4381-BC0E-612F66202747/view-source"}, {"content_license": null, "contributor": {"display_name": "AliceD", "profile_url": "https://biology.stackexchange.com/users/9943/aliced", "user_type": "registered"}, "created_at": "2025-01-22T22:08:15+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T22:46:31+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "B7973B09-2242-45E6-BBC3-31AC3F1053AD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B7973B09-2242-45E6-BBC3-31AC3F1053AD/view-source"}, {"content_license": null, "contributor": {"display_name": "Chris", "profile_url": "https://biology.stackexchange.com/users/5144/chris", "user_type": "moderator"}, "created_at": "2025-01-24T06:40:20+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "BF004751-6C6B-4181-A98F-35A4E06EB3A7", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/BF004751-6C6B-4181-A98F-35A4E06EB3A7/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "JimN", "profile_url": "https://biology.stackexchange.com/users/61490/jimn", "user_type": "registered"}, "created_at": "2025-01-26T19:50:07+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "EF637342-A242-4D2E-B088-8365AF4C953A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/EF637342-A242-4D2E-B088-8365AF4C953A/view-source"}], "score": 2, "updated_at": "2025-01-26T19:50:07+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Perimysium", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane", "https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:04.377249+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/54ece81cba3a5a552bb15d6d3feedc4324a2ba2706d33480080ece9537efd4b1_0.json", "raw_sha256": "f1eb8f7eda9336b81701b663029f9411e040c0bcf262148b7ede9a103ae73e69", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=4&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "uhoh", "question_author_url": "https://biology.stackexchange.com/users/27918/uhoh", "question_author_user_type": "registered", "question_created_at": "2025-01-21T02:21:19+00:00", "question_html": "In a discussion elsewhere I referred to chicken soup as having plenty of "cellular material" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.
\nOf course bone, tendon and perimysium (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other "cellular material" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.
\nGenerally speaking, are there still chicken cells in chicken soup?
\nOr are they all pretty much destroyed in the cooking process?
\n", "question_id": 115987, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "In a discussion elsewhere I referred to chicken soup as having plenty of \"cellular material\" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.\n\n\n\n\nOf course bone, tendon and perimysium (https://en.wikipedia.org/wiki/Perimysium) (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other \"cellular material\" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.\n\n\n\n\nGenerally speaking, are there still chicken cells in chicken soup?\n\n\n\n\nOr are they all pretty much destroyed in the cooking process?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "uhoh", "profile_url": "https://biology.stackexchange.com/users/27918/uhoh", "user_type": "registered"}, "created_at": "2025-01-21T02:21:19+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "40730F9A-9111-4C99-8DDD-96B63953B376", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/40730F9A-9111-4C99-8DDD-96B63953B376/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115987/are-there-still-chicken-cells-in-chicken-soup", "split": "validation", "split_group": "99c83c44d9c03188772962d7913b0710583cb38e45692eb0f5fa6a24b801f58c", "tags": ["cell-membrane", "temperature"], "thread_id": "biology:115987", "title": "Are there still chicken cells in chicken soup?"}} {"citation_context": "0well%20known%20that,17%2C%2018%2C%2019)).\n\n\n\n\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane (https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20i", "content_license": "CC BY-SA 4.0", "context_method": "literal text window; null if identifier only in original HTML", "correctness_verified": false, "doi": null, "external_url": "https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane", "kind": "external_url", "post_id": 115992, "post_url": "https://biology.stackexchange.com/a/115992", "product": "citations", "record_id": "Scientific-Citation-Graph:4d4f01bc3dd6690db73fce78", "split": "validation", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.
\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.
\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.
\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm. Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8
\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019).
\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.
\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.
\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.
\n", "answer_id": 115992, "answer_text": "Answer: Few intact chicken cells, lots of vegetable cells in rough shape.\n\n\n\n\nAnimal cells have no cell walls (unlike plants) to reinforce their cell membranes. Because of this, they have a narrow range of tolerance for pH, temperature and osmolarity before lysing (bursting) and releasing the cell's contents.\n\n\n\n\nSome of those cell contents will be lysozymes, organelles which contain enzymes which further digest cell structure, so lysis starts a chain reaction.\n\n\n\n\nBelow pH 6.8, membranes break down . https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm (https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm). Vinegar (pH 3) is a common ingredient in soup recipes, making the pH of chicken broth 5.8\n\n\n\n\nHeat breaks down the lipid bilayer making up cell membranes, typically at 40-50C https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019 (https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019)).\n\n\n\n\nThe cytoplasm of animal cells is typically 300mOsm/l https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane (https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane) , the same as the extracellular fluid. This corresponds to over 7 atmospheres. In other words, if an isolated cell is immersed in fresh water, the osmotic gradient could generate more than enough pressure to lyse the cell.\n\n\n\n\nA recipe that calls for covering the ingredients in tap water, adding vinegar and bringing to a simmer will burst animal cells three times over.\n\n\n\n\nPlant cells will fare much better since they have cell walls to resist rupture, but the cell membranes within will have a rough time.", "answer_url": "https://biology.stackexchange.com/a/115992", "author": "Woody", "author_url": "https://biology.stackexchange.com/users/98830/woody", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2025-01-22T20:42:53+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:22.614155+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/2c8799380b8f5d7bf0fd42e594fd78a1835b27e1da9f481cc00f096bab9c01ca_0.json", "raw_sha256": "348375a094fdfd6d9ca55d0bddc65d8dc7a7f0757e1e5a44c25e22a66b1a4892", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/116119;116113;116097;116096;116091;116087;116076;116067;116063;116059;116055;116037;116034;116028;116022;116012;116005;115997;115989;115988;115987;115979;115978;115976;115974;115973;115970;115966;115965;115957;115952;115939;115933;115932;115927;115921;115915;115903;115897;115894;115886;115885;115884;115881;115880;115868;115867;115857;115852;115840;115830;115825;115819;115815;115791;115780;115773;115764;115759;115756;115743;115736;115726;115723;115713;115699;115691;115689;115685;115678;115668;115664;115657;115650;115642;115639;115632;115627;115626;115609;115602;115598;115592;115588;115587;115580;115578;115570;115566;115562;115549;115537;115536;115531;115530;115528;115525;115521;115513;115510/answers?filter=withbody&order=asc&page=1&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 115987, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T20:42:53+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "4AD6E1A7-A688-4381-BC0E-612F66202747", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/4AD6E1A7-A688-4381-BC0E-612F66202747/view-source"}, {"content_license": null, "contributor": {"display_name": "AliceD", "profile_url": "https://biology.stackexchange.com/users/9943/aliced", "user_type": "registered"}, "created_at": "2025-01-22T22:08:15+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/E80F9EDB-C9A0-4F10-899B-7F7D62E3E7F3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Woody", "profile_url": "https://biology.stackexchange.com/users/98830/woody", "user_type": "registered"}, "created_at": "2025-01-22T22:46:31+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "B7973B09-2242-45E6-BBC3-31AC3F1053AD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/B7973B09-2242-45E6-BBC3-31AC3F1053AD/view-source"}, {"content_license": null, "contributor": {"display_name": "Chris", "profile_url": "https://biology.stackexchange.com/users/5144/chris", "user_type": "moderator"}, "created_at": "2025-01-24T06:40:20+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "BF004751-6C6B-4181-A98F-35A4E06EB3A7", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://biology.stackexchange.com/revisions/BF004751-6C6B-4181-A98F-35A4E06EB3A7/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "JimN", "profile_url": "https://biology.stackexchange.com/users/61490/jimn", "user_type": "registered"}, "created_at": "2025-01-26T19:50:07+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "EF637342-A242-4D2E-B088-8365AF4C953A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/EF637342-A242-4D2E-B088-8365AF4C953A/view-source"}], "score": 2, "updated_at": "2025-01-26T19:50:07+00:00"}], "domain": "biology", "external_links": ["https://en.wikipedia.org/wiki/Perimysium", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:%7E:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pmc.ncbi.nlm.nih.gov/articles/PMC5985002/#:~:text=It%20is%20well%20known%20that,17%2C%2018%2C%2019", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:%7E:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://pubmed.ncbi.nlm.nih.gov/1503904/#:~:text=Cell%20killing%20can%20be%20achieved,extracellular%20space%20into%20the%20cytoplasm", "https://www.sciencedirect.com/topics/engineering/osmolarity#:%7E:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane", "https://www.sciencedirect.com/topics/engineering/osmolarity#:~:text=The%20total%20osmolarity%20inside%20the,water%20across%20the%20plasma%20membrane"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:03:04.377249+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/54ece81cba3a5a552bb15d6d3feedc4324a2ba2706d33480080ece9537efd4b1_0.json", "raw_sha256": "f1eb8f7eda9336b81701b663029f9411e040c0bcf262148b7ede9a103ae73e69", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=4&pagesize=100&site=biology&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "uhoh", "question_author_url": "https://biology.stackexchange.com/users/27918/uhoh", "question_author_user_type": "registered", "question_created_at": "2025-01-21T02:21:19+00:00", "question_html": "In a discussion elsewhere I referred to chicken soup as having plenty of "cellular material" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.
\nOf course bone, tendon and perimysium (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other "cellular material" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.
\nGenerally speaking, are there still chicken cells in chicken soup?
\nOr are they all pretty much destroyed in the cooking process?
\n", "question_id": 115987, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "In a discussion elsewhere I referred to chicken soup as having plenty of \"cellular material\" (e.g. protein and lipid molecules) but no longer having actual cells. I'd assumed that the heat and time of the cooking process disrupts cell membranes and individual cells would loose their integrity such that their contents would just merge with the soup.\n\n\n\n\nOf course bone, tendon and perimysium (https://en.wikipedia.org/wiki/Perimysium) (connective material within muscle tissue) may survive and keep the contents trapped, so a piece of chicken meat would still be full of protein and other \"cellular material\" but if it were properly examined, intact cells would no longer be present even if the spaces where they were may still delineate cellular material (roughly like the way wood preserves the cellular nature of the tree without having actual cells in it anymore.\n\n\n\n\nGenerally speaking, are there still chicken cells in chicken soup?\n\n\n\n\nOr are they all pretty much destroyed in the cooking process?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "uhoh", "profile_url": "https://biology.stackexchange.com/users/27918/uhoh", "user_type": "registered"}, "created_at": "2025-01-21T02:21:19+00:00", "raw_file": "raw/codex_api_v1/9208faf10edface85b193538ceee277a2c29dd57b691eaef3dbbd7fcb70c256f_1790824112025498400_0.json", "raw_sha256": "cacf2fdbe629fb39b1a0932a5485abc61f5635b5e51482d0d3b8ab40f1450c36", "revision_guid": "40730F9A-9111-4C99-8DDD-96B63953B376", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://biology.stackexchange.com/revisions/40730F9A-9111-4C99-8DDD-96B63953B376/view-source"}], "source_site": "biology", "source_url": "https://biology.stackexchange.com/questions/115987/are-there-still-chicken-cells-in-chicken-soup", "split": "validation", "split_group": "99c83c44d9c03188772962d7913b0710583cb38e45692eb0f5fa6a24b801f58c", "tags": ["cell-membrane", "temperature"], "thread_id": "biology:115987", "title": "Are there still chicken cells in chicken soup?"}}