diff --git "a/train.jsonl" "b/train.jsonl" new file mode 100644--- /dev/null +++ "b/train.jsonl" @@ -0,0 +1,59 @@ +{"accepted_answer": {"answer_html": "

Concurvity is only really an issue if it causes the estimated effects of other terms to change qualitatively when you remove one of the concurved terms.

\n

In this instance, I don't see why you need to decompose the 2d function $f(\\text{time}, \\text{z})$ into "main" effects and pure interaction? If you fit the model as

\n
m2 <- gam(\n  y ~ s(subject, bs = "re") +\n    te(time, z, k = c(6,10)),\n  data = dat,\n  method = "REML"\n)\n
\n

you get essentially the same fit without the concurvity issues and with fewer smoothing parameters to estimate to boot.

\n

I wouldn't worry about the concurvity in your decomposed model; that a flat function is concurved with the random intercepts isn't an issue because it doesn't affect the estimated terms. All that $f^{*}(\\text{z})$ (the "main" effect of $z$) is doing is pulling the interaction surface up or down a bit.

\n", "answer_id": 676825, "answer_text": "Concurvity is only really an issue if it causes the estimated effects of other terms to change qualitatively when you remove one of the concurved terms.\n\n\n\n\nIn this instance, I don't see why you need to decompose the 2d function $f(\\text{time}, \\text{z})$ into \"main\" effects and pure interaction? If you fit the model as\n\n\n\n\nm2 <- gam(\n y ~ s(subject, bs = \"re\") +\n te(time, z, k = c(6,10)),\n data = dat,\n method = \"REML\"\n)\n\n\n\n\n\nyou get essentially the same fit without the concurvity issues and with fewer smoothing parameters to estimate to boot.\n\n\n\n\nI wouldn't worry about the concurvity in your decomposed model; that a flat function is concurved with the random intercepts isn't an issue because it doesn't affect the estimated terms. All that $f^{*}(\\text{z})$ (the \"main\" effect of $z$) is doing is pulling the interaction surface up or down a bit.", "answer_url": "https://stats.stackexchange.com/a/676825", "author": "Gavin Simpson", "author_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-10T13:46: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": 676821, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Gavin Simpson", "profile_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "user_type": "registered"}, "created_at": "2026-08-10T13:46:19+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "F2BC6152-84F6-49C2-A240-5C8FBED68528", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F2BC6152-84F6-49C2-A240-5C8FBED68528/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Gavin Simpson", "profile_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "user_type": "registered"}, "created_at": "2026-08-10T14:27:48+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "49FD277A-D37F-425E-AE90-F3246031F5A9", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/49FD277A-D37F-425E-AE90-F3246031F5A9/view-source"}], "score": 3, "updated_at": "2026-08-10T14:27:48+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "I have repeated-measures data — multiple observations per subject over time — and a covariate that is constant within subject (e.g., a baseline characteristic measured once). My model includes a subject-level random intercept and I want to test whether this covariate's association with the outcome changes over time.\n\n\n\n\n\nm <- gam(y ~ s(time) + s(subject, bs = \"re\") + s(z) + ti(time, z), data = dat)\n\n\n\n\n\nconcurvity(m, full = FALSE)$estimate shows s(subject) and s(z) (z's own main effect) at 1.000 in one direction, confirming total non-identifiability — since z has zero within-subject variation, s(subject, bs=\"re\") can fully reproduce whatever flat contribution s(z) would estimate.\n\n\n\n\nMy current approach is to drop s(z) entirely and keep only ti(time, z), on the reasoning that ti()'s own identifiability constraints make it self-contained regardless of whether the (non-identifiable) main effect is present — interpreting the retained term as \"how the association between z and y changes over time,\" while treating any claim about z's flat/average association as unrecoverable given this random-effect structure.\n\n\n\n\nReproducible example:\n\n\n\n\nlibrary(mgcv)\nset.seed(1)\n\nn_subject <- 150\nn_visit <- 6\ntime_seq <- seq(0, 10, length.out = n_visit)\n\nz <- rnorm(n_subject)\nsubject_effect <- rnorm(n_subject, sd = 2)\n\ndat <- do.call(rbind, lapply(seq_len(n_subject), function(i) {\n y <- 5 + sqrt(time_seq) + subject_effect[i] + 0.5*z[i] + 0.3*z[i]*time_seq/10 + rnorm(n_visit, sd = 0.5)\n data.frame(subject = i, time = time_seq, y = y, z = z[i])\n}))\ndat$subject <- factor(dat$subject)\n\nm <- gam(y ~ s(time, k = 5) + s(subject, bs = \"re\") + s(z, k = 8) + ti(time, z, k = c(4,4)), data = dat)\nround(concurvity(m, full = FALSE)$estimate, 3)\n\n\n\n\n\nQuestions:\n\n\n\n\n\nIs dropping z's main effect while retaining ti(time, z) a way to handle this, or is there a better-established approach?\n\n\n\n\nDoes ti(time, z)'s own estimate depend in any way on whether the non-identifiable main effect is included or excluded from the model?\n\n\n\n\n\nMany thanks", "record_id": "Scientific-Statistics-QA:stats:676821", "selected_answer": {"answer_html": "

Concurvity is only really an issue if it causes the estimated effects of other terms to change qualitatively when you remove one of the concurved terms.

\n

In this instance, I don't see why you need to decompose the 2d function $f(\\text{time}, \\text{z})$ into "main" effects and pure interaction? If you fit the model as

\n
m2 <- gam(\n  y ~ s(subject, bs = "re") +\n    te(time, z, k = c(6,10)),\n  data = dat,\n  method = "REML"\n)\n
\n

you get essentially the same fit without the concurvity issues and with fewer smoothing parameters to estimate to boot.

\n

I wouldn't worry about the concurvity in your decomposed model; that a flat function is concurved with the random intercepts isn't an issue because it doesn't affect the estimated terms. All that $f^{*}(\\text{z})$ (the "main" effect of $z$) is doing is pulling the interaction surface up or down a bit.

\n", "answer_id": 676825, "answer_text": "Concurvity is only really an issue if it causes the estimated effects of other terms to change qualitatively when you remove one of the concurved terms.\n\n\n\n\nIn this instance, I don't see why you need to decompose the 2d function $f(\\text{time}, \\text{z})$ into \"main\" effects and pure interaction? If you fit the model as\n\n\n\n\nm2 <- gam(\n y ~ s(subject, bs = \"re\") +\n te(time, z, k = c(6,10)),\n data = dat,\n method = \"REML\"\n)\n\n\n\n\n\nyou get essentially the same fit without the concurvity issues and with fewer smoothing parameters to estimate to boot.\n\n\n\n\nI wouldn't worry about the concurvity in your decomposed model; that a flat function is concurved with the random intercepts isn't an issue because it doesn't affect the estimated terms. All that $f^{*}(\\text{z})$ (the \"main\" effect of $z$) is doing is pulling the interaction surface up or down a bit.", "answer_url": "https://stats.stackexchange.com/a/676825", "author": "Gavin Simpson", "author_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-10T13:46: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": 676821, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Gavin Simpson", "profile_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "user_type": "registered"}, "created_at": "2026-08-10T13:46:19+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "F2BC6152-84F6-49C2-A240-5C8FBED68528", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F2BC6152-84F6-49C2-A240-5C8FBED68528/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Gavin Simpson", "profile_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "user_type": "registered"}, "created_at": "2026-08-10T14:27:48+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "49FD277A-D37F-425E-AE90-F3246031F5A9", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/49FD277A-D37F-425E-AE90-F3246031F5A9/view-source"}], "score": 3, "updated_at": "2026-08-10T14:27:48+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 676825, "answers": [{"answer_html": "

Concurvity is only really an issue if it causes the estimated effects of other terms to change qualitatively when you remove one of the concurved terms.

\n

In this instance, I don't see why you need to decompose the 2d function $f(\\text{time}, \\text{z})$ into "main" effects and pure interaction? If you fit the model as

\n
m2 <- gam(\n  y ~ s(subject, bs = "re") +\n    te(time, z, k = c(6,10)),\n  data = dat,\n  method = "REML"\n)\n
\n

you get essentially the same fit without the concurvity issues and with fewer smoothing parameters to estimate to boot.

\n

I wouldn't worry about the concurvity in your decomposed model; that a flat function is concurved with the random intercepts isn't an issue because it doesn't affect the estimated terms. All that $f^{*}(\\text{z})$ (the "main" effect of $z$) is doing is pulling the interaction surface up or down a bit.

\n", "answer_id": 676825, "answer_text": "Concurvity is only really an issue if it causes the estimated effects of other terms to change qualitatively when you remove one of the concurved terms.\n\n\n\n\nIn this instance, I don't see why you need to decompose the 2d function $f(\\text{time}, \\text{z})$ into \"main\" effects and pure interaction? If you fit the model as\n\n\n\n\nm2 <- gam(\n y ~ s(subject, bs = \"re\") +\n te(time, z, k = c(6,10)),\n data = dat,\n method = \"REML\"\n)\n\n\n\n\n\nyou get essentially the same fit without the concurvity issues and with fewer smoothing parameters to estimate to boot.\n\n\n\n\nI wouldn't worry about the concurvity in your decomposed model; that a flat function is concurved with the random intercepts isn't an issue because it doesn't affect the estimated terms. All that $f^{*}(\\text{z})$ (the \"main\" effect of $z$) is doing is pulling the interaction surface up or down a bit.", "answer_url": "https://stats.stackexchange.com/a/676825", "author": "Gavin Simpson", "author_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-10T13:46: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": 676821, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Gavin Simpson", "profile_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "user_type": "registered"}, "created_at": "2026-08-10T13:46:19+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "F2BC6152-84F6-49C2-A240-5C8FBED68528", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F2BC6152-84F6-49C2-A240-5C8FBED68528/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Gavin Simpson", "profile_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "user_type": "registered"}, "created_at": "2026-08-10T14:27:48+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "49FD277A-D37F-425E-AE90-F3246031F5A9", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/49FD277A-D37F-425E-AE90-F3246031F5A9/view-source"}], "score": 3, "updated_at": "2026-08-10T14:27:48+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Elara", "question_author_url": "https://stats.stackexchange.com/users/515316/elara", "question_author_user_type": "registered", "question_created_at": "2026-08-10T10:16:49+00:00", "question_html": "

I have repeated-measures data — multiple observations per subject over time — and a covariate that is constant within subject (e.g., a baseline characteristic measured once). My model includes a subject-level random intercept and I want to test whether this covariate's association with the outcome changes over time.

\n
\nm <- gam(y ~ s(time) + s(subject, bs = "re") + s(z) + ti(time, z), data = dat)\n
\n

concurvity(m, full = FALSE)$estimate shows s(subject) and s(z) (z's own main effect) at 1.000 in one direction, confirming total non-identifiability — since z has zero within-subject variation, s(subject, bs="re") can fully reproduce whatever flat contribution s(z) would estimate.

\n

My current approach is to drop s(z) entirely and keep only ti(time, z), on the reasoning that ti()'s own identifiability constraints make it self-contained regardless of whether the (non-identifiable) main effect is present — interpreting the retained term as "how the association between z and y changes over time," while treating any claim about z's flat/average association as unrecoverable given this random-effect structure.

\n

Reproducible example:

\n
library(mgcv)\nset.seed(1)\n\nn_subject <- 150\nn_visit   <- 6\ntime_seq  <- seq(0, 10, length.out = n_visit)\n\nz <- rnorm(n_subject)\nsubject_effect <- rnorm(n_subject, sd = 2)\n\ndat <- do.call(rbind, lapply(seq_len(n_subject), function(i) {\n  y <- 5 + sqrt(time_seq) + subject_effect[i] + 0.5*z[i] + 0.3*z[i]*time_seq/10 + rnorm(n_visit, sd = 0.5)\n  data.frame(subject = i, time = time_seq, y = y, z = z[i])\n}))\ndat$subject <- factor(dat$subject)\n\nm <- gam(y ~ s(time, k = 5) + s(subject, bs = "re") + s(z, k = 8) + ti(time, z, k = c(4,4)), data = dat)\nround(concurvity(m, full = FALSE)$estimate, 3)\n
\n

Questions:

\n
    \n
  1. Is dropping z's main effect while retaining ti(time, z) a way to handle this, or is there a better-established approach?
  2. \n
  3. Does ti(time, z)'s own estimate depend in any way on whether the non-identifiable main effect is included or excluded from the model?
  4. \n
\n

Many thanks

\n", "question_id": 676821, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I have repeated-measures data — multiple observations per subject over time — and a covariate that is constant within subject (e.g., a baseline characteristic measured once). My model includes a subject-level random intercept and I want to test whether this covariate's association with the outcome changes over time.\n\n\n\n\n\nm <- gam(y ~ s(time) + s(subject, bs = \"re\") + s(z) + ti(time, z), data = dat)\n\n\n\n\n\nconcurvity(m, full = FALSE)$estimate shows s(subject) and s(z) (z's own main effect) at 1.000 in one direction, confirming total non-identifiability — since z has zero within-subject variation, s(subject, bs=\"re\") can fully reproduce whatever flat contribution s(z) would estimate.\n\n\n\n\nMy current approach is to drop s(z) entirely and keep only ti(time, z), on the reasoning that ti()'s own identifiability constraints make it self-contained regardless of whether the (non-identifiable) main effect is present — interpreting the retained term as \"how the association between z and y changes over time,\" while treating any claim about z's flat/average association as unrecoverable given this random-effect structure.\n\n\n\n\nReproducible example:\n\n\n\n\nlibrary(mgcv)\nset.seed(1)\n\nn_subject <- 150\nn_visit <- 6\ntime_seq <- seq(0, 10, length.out = n_visit)\n\nz <- rnorm(n_subject)\nsubject_effect <- rnorm(n_subject, sd = 2)\n\ndat <- do.call(rbind, lapply(seq_len(n_subject), function(i) {\n y <- 5 + sqrt(time_seq) + subject_effect[i] + 0.5*z[i] + 0.3*z[i]*time_seq/10 + rnorm(n_visit, sd = 0.5)\n data.frame(subject = i, time = time_seq, y = y, z = z[i])\n}))\ndat$subject <- factor(dat$subject)\n\nm <- gam(y ~ s(time, k = 5) + s(subject, bs = \"re\") + s(z, k = 8) + ti(time, z, k = c(4,4)), data = dat)\nround(concurvity(m, full = FALSE)$estimate, 3)\n\n\n\n\n\nQuestions:\n\n\n\n\n\nIs dropping z's main effect while retaining ti(time, z) a way to handle this, or is there a better-established approach?\n\n\n\n\nDoes ti(time, z)'s own estimate depend in any way on whether the non-identifiable main effect is included or excluded from the model?\n\n\n\n\n\nMany thanks", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Elara", "profile_url": "https://stats.stackexchange.com/users/515316/elara", "user_type": "registered"}, "created_at": "2026-08-10T10:16:49+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "E53E485F-D0B2-4D71-A71D-49FBF67B610C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E53E485F-D0B2-4D71-A71D-49FBF67B610C/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-10T18:21:03+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "87843E03-0788-44C4-AC39-D6D27DF85636", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/87843E03-0788-44C4-AC39-D6D27DF85636/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676821/should-a-covariates-main-effect-be-dropped-when-its-totally-confounded-concur", "split": "train", "split_group": "a67c79324cd462d3f9e765754df2a7a00495b44528883bd5734192a2b6a73ff1", "tags": ["interaction", "generalized-additive-model", "mgcv", "identifiability", "concurvity"], "thread_id": "stats:676821", "title": "Should a covariate's main effect be dropped when it's totally confounded (concurvity = 1) with a random intercept in a repeated-measures GAMM?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "The following is a multivariate Student's t distribution\n$$ p_{\\sigma^2}(\\mathrm{x})= {\\displaystyle {N_{\\nu,\\sigma^2}}\\left[1+\\frac{1}{\\nu\\sigma^2}\\sum_{i=1}^nx_i^2\\right]^{-(\\nu +n)/2}}, \\;\\mathrm{x}=[x_1,\\cdots,x_n]^{\\top}\\in \\mathbb{R}^n,\\;\\nu>2,$$ where $N_{\\nu,\\sigma^2}=\\frac {\\Gamma \\left[(\\nu +n)/2\\right]}{\\Gamma (\\nu /2)\\nu ^{n/2} \\pi^{n/2}{\\sigma}^{n}}.$ I am struggling to find the higher-order moments $E[X^{\\top}X]$, $E[X^{\\top}X(X^{\\top}X)^{\\top}]$. Is there a way to get these quantities?", "record_id": "Scientific-Statistics-QA:stats:676824", "selected_answer": {"answer_html": "

I offer an elementary solution. It requires one substitution in an ordinary integral which, when repeated for each variable, yields a product of Beta function values.

\n

There are other solutions that might provide simpler formulas but are less elementary (e.g., use cylindrical coordinates).

\n

Initial simplification

\n

Because $\\sqrt{\\nu}\\sigma$ evidently is a scale parameter we can ignore it (for now), leaving everything to depend on the number of variables $n$ and the parameter $\\nu.$ Writing $\\mathbf x = (x_1, x_2, \\ldots, x_n),$ let the density be

\n

$$p(\\mathbf x;\\nu) = \\frac{\\Gamma\\left(\\frac{\\nu + n}{2}\\right)}{\\Gamma\\left(\\frac{\\nu}{2}\\right)\\pi^{n/2}} \\left(1 + \\sum_{i=1}^n x_i^2\\right)^{-(\\nu + n)/2} = \\frac{1}{C(\\nu, n)}\\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu + n)/2}.$$

\n

The moment of degree $\\mathbf k = (k_1, k_2, \\ldots, k_n)$ is, by definition,

\n

$$\\mu(\\mathbf k; \\nu) = \\int \\mathbf x^{\\mathbf k} p(\\mathbf x;\\nu)\\,\\mathrm d\\mathbf x = \\int_{-\\infty}^{\\infty}\\cdots\\int_{-\\infty}^{\\infty} x_1^{k_1}x_2^{k_2}\\cdots x_n^{k_n} p(\\mathbf x;\\nu)\\,\\mathrm dx_1\\mathrm dx_2\\cdots \\mathrm dx_n.$$

\n

Because $p$ depends only on the squares $x_i^2,$ it is an even function of all the variables. Consequently (implicitly assuming $\\mu(\\mathbf k;\\nu)$ exists),

\n
\n

whenever any $k_i$ is an odd integer, $\\mu(\\mathbf k;\\nu) = 0.$

\n
\n

Otherwise, when all the $k_i$ are even integers, we may integrate over positive $x_i$ only and double the result. Doing this for all $n$ variables gives

\n

$$\\mu(\\mathbf k; \\nu) = 2^n\\int_{(0,\\ldots,0)}^{(\\infty,\\ldots,\\infty)} \\mathbf x^{\\mathbf k} p(\\mathbf x;\\nu)\\,\\mathrm d\\mathbf x = \\frac{2^n}{C(\\nu,n)}\\int_{(0,\\ldots,0)}^{(\\infty,\\ldots,\\infty)} \\mathbf x^{\\mathbf k} \\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu+n)/2}\\,\\mathrm d\\mathbf x$$

\n

The question comes down to computing the integral on the right hand side. It deserves a name; let's call it

\n

$$f(\\mathbf k;\\nu) = C(\\nu,n)\\mu(\\mathbf k;\\nu) = 2^n\\int \\mathbf x^{\\mathbf k}\\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu + n)/2}\\,\\mathrm d\\mathbf x,$$

\n

where from now on the integral is understood as encompassing all non-negative values of the $x_i.$

\n

The key formula

\n

One way to evaluate such integrals is to integrate one variable at a time. To this end, set $y^2 = 1 + x_1^2 + \\cdots + x_{n-1}^2 = 1 + ||\\mathbf x_{\\hat n}||^2$ (with $y\\ge 0$). The notation $\\mathbf x_{\\hat n}$ means the component $x_n$ is omitted. Substituting $u = (x/y)^2$ shows

\n

$$\\begin{aligned}\n2\\int_0^\\infty x^{k} \\left(y^2 + x^2\\right)^{-\\alpha/2} \\,\\mathrm dx &= y^{k +1 - \\alpha}\\int_0^\\infty u^{(k-1)/2}\\left(1 + u\\right)^{-\\alpha/2} \\,\\mathrm du\\\\\n& = \\left(y^2\\right)^{-(\\alpha - k - 1)/2}\\,B\\left(\\frac{k+1}{2}, \\frac{\\alpha-k-1}{2}\\right)\n\\end{aligned}$$

\n

(a Beta function, arising e.g. from normalizing a Beta prime distribution).

\n

Applying this in the case $\\alpha = \\nu + n$ and $k = k_n$ says

\n

$$\\begin{aligned}\n2\\int_0^\\infty x^{k_n} \\left(y^2 + x^2\\right)^{-(\\nu + n)/2} \\,\\mathrm dx = \\left(y^2\\right)^{-(\\nu - k_n + (n - 1))/2}\\,B\\left(\\frac{k_n+1}{2}, \\frac{\\nu - k_n + (n-1)}{2}\\right)\n\\end{aligned}$$

\n

Performing the remaining integration over $(x_1, x_2, \\ldots, x_{n-1}) = \\mathbf x_{\\hat n}$ shows

\n

$$f(\\mathbf k;\\nu) = f(\\mathbf k_{\\hat n};\\, \\nu - k_n)B\\left(\\frac{k_n+1}{2}, \\frac{\\nu - k_n + (n-1)}{2}\\right).$$

\n

Iterating from $i = n$ down to $1$ decreases $n$ by $1$ at each step and decreases $\\nu$ by $k_i$ for the next step, whence

\n
\n

$$f(\\mathbf{k};\\,\\nu) = \\prod_{i=1}^n B\\left(\\frac{k_i+1}{2}, \\frac{\\nu - (k_i + k_{i+1} + \\cdots + k_n) + i - 1}{2}\\right).$$

\n
\n

(Although this can be simplified using basic properties of Gamma functions, it is good enough for computation and analysis.)

\n

As a check, we recover the normalizing constant as the zeroth moment,

\n

$$\\begin{aligned}\n C(\\nu, n) &= f((0,\\ldots,0);\\, n) \\\\\n&=\\prod_{i=1}^n B\\left(\\frac{0+1}{2}, \\frac{\\nu - 0 + (i-1)}{2}\\right)\\\\\n&=\\prod_{i=1}^n \\frac{\\Gamma\\left(\\frac{0+1}{2}\\right)\\Gamma\\left(\\frac{\\nu - 0 + (i-1)}{2}\\right)}{\\Gamma\\left(\\frac{\\nu + (i-1) + 1}{2}\\right)}\\\\\n&= \\frac{\\Gamma\\left(\\frac{1}{2}\\right)^n \\Gamma\\left(\\frac{\\nu}{2}\\right)}{\\Gamma\\left(\\frac{\\nu+n}{2}\\right)}.\n\\end{aligned}$$

\n

This agrees with the value quoted in the question, since $\\Gamma(1/2)=\\sqrt{\\pi}.$

\n

Finally, recall that a scale parameter $\\tau$ multiplies each variable $x_i$ by $\\tau,$ whence it multiplies the moment of order $\\mathbf k$ by $\\tau(k_1+k_2+\\cdots+k_n).$ Writing

\n

$$\\kappa = k_1+k_2+\\cdots+k_n$$

\n

and recalling the scale parameter is $\\tau = \\sqrt{\\nu}\\sigma$ shows that

\n
\n

$$\\mu(\\mathbf k;\\,\\nu,\\sigma) = \\frac{\\nu^{\\kappa/2}\\sigma^\\kappa f(\\mathbf k;\\,\\nu)}{C(\\nu, n)}.$$

\n
\n

The question concerns linear combinations of moments of order $4$ ($\\kappa = 4$). Computing the coefficients--which is merely a matter of multiplying the matrices--is of no interest here.

\n

Implementation and testing

\n

To maintain precision and avoid numerical overflow, it is best to compute products of Beta functions using logarithms. Here is an example of how that's done in R, using its built-in lbeta (logarithm of Beta) function.

\n
#\n# log(f(k; nu))\n#\nlf <- function(k, nu) {\n  n <- length(k)\n  i <- seq_len(n)\n  sum(lbeta((rev(k) + 1)/2, (nu - cumsum(rev(k)) + rev(i) - 1) / 2))\n}\n#\n# Absolute multivariate moments.\n# (They can be fractional--but not negative.)\n#\nmu <- function(k, nu, sigma = 1) {\n  n <- length(k)\n  y <- lf(k, nu)\n  exp(y + lgamma((nu + n)/2) - lgamma(nu/2) - (n/2) * log(pi) + \n          sum(k) * (log(nu)/2 + log(sigma)))\n}\n
\n

The sum and cumsum functions require only $O(n)$ computational effort and storage.

\n

For example, the $(0,1,2,3)$ moment with $\\nu=12$ is found as

\n
> mu(c(0,1,2,3), 12, 1)\n[1] 4.583662\n
\n

As a test, I generated datasets of one million iid observations from multivariate $t$ distributions (using the mnormt package) and compared the sample moments (for various $\\mathbf k$) to the formula:

\n
set.seed(17)\nk <- c(0, 1, 2)\nnu <- 5\nX <- t(rmt(1e6, 0, diag(1, n), df = nu)) # One row for each coordinate\nm <- mean(apply(abs(X)^k, 2, prod))      # The estimated moment of order `k`\nm / mu(k, nu)                   \n
\n

The output, equal to $1.012$ in this example, ideally would be $1,$ indicating perfect agreement. But $t$ distributions, especially for smallish $\\nu,$ are rather heavy-tailed, resulting in very high sampling variances for the higher moments (this one is of order $\\kappa = 0+1+2=3$). In light of this, $1.012$ is excellent agreement.

\n

The output of additional tests continues to support the conclusion that the formulas for $f$ and $\\mu$ are correct.

\n", "answer_id": 676851, "answer_text": "I offer an elementary solution. It requires one substitution in an ordinary integral which, when repeated for each variable, yields a product of Beta function values.\n\n\n\n\nThere are other solutions that might provide simpler formulas but are less elementary (e.g., use cylindrical coordinates).\n\n\n\n\nInitial simplification\n\n\n\n\nBecause $\\sqrt{\\nu}\\sigma$ evidently is a scale parameter we can ignore it (for now), leaving everything to depend on the number of variables $n$ and the parameter $\\nu.$ Writing $\\mathbf x = (x_1, x_2, \\ldots, x_n),$ let the density be\n\n\n\n\n$$p(\\mathbf x;\\nu) = \\frac{\\Gamma\\left(\\frac{\\nu + n}{2}\\right)}{\\Gamma\\left(\\frac{\\nu}{2}\\right)\\pi^{n/2}} \\left(1 + \\sum_{i=1}^n x_i^2\\right)^{-(\\nu + n)/2} = \\frac{1}{C(\\nu, n)}\\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu + n)/2}.$$\n\n\n\n\nThe moment of degree $\\mathbf k = (k_1, k_2, \\ldots, k_n)$ is, by definition,\n\n\n\n\n$$\\mu(\\mathbf k; \\nu) = \\int \\mathbf x^{\\mathbf k} p(\\mathbf x;\\nu)\\,\\mathrm d\\mathbf x = \\int_{-\\infty}^{\\infty}\\cdots\\int_{-\\infty}^{\\infty} x_1^{k_1}x_2^{k_2}\\cdots x_n^{k_n} p(\\mathbf x;\\nu)\\,\\mathrm dx_1\\mathrm dx_2\\cdots \\mathrm dx_n.$$\n\n\n\n\nBecause $p$ depends only on the squares $x_i^2,$ it is an even function of all the variables. Consequently (implicitly assuming $\\mu(\\mathbf k;\\nu)$ exists),\n\n\n\n\n\n\n\nwhenever any $k_i$ is an odd integer, $\\mu(\\mathbf k;\\nu) = 0.$\n\n\n\n\n\n\n\nOtherwise, when all the $k_i$ are even integers, we may integrate over positive $x_i$ only and double the result. Doing this for all $n$ variables gives\n\n\n\n\n$$\\mu(\\mathbf k; \\nu) = 2^n\\int_{(0,\\ldots,0)}^{(\\infty,\\ldots,\\infty)} \\mathbf x^{\\mathbf k} p(\\mathbf x;\\nu)\\,\\mathrm d\\mathbf x = \\frac{2^n}{C(\\nu,n)}\\int_{(0,\\ldots,0)}^{(\\infty,\\ldots,\\infty)} \\mathbf x^{\\mathbf k} \\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu+n)/2}\\,\\mathrm d\\mathbf x$$\n\n\n\n\nThe question comes down to computing the integral on the right hand side. It deserves a name; let's call it\n\n\n\n\n$$f(\\mathbf k;\\nu) = C(\\nu,n)\\mu(\\mathbf k;\\nu) = 2^n\\int \\mathbf x^{\\mathbf k}\\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu + n)/2}\\,\\mathrm d\\mathbf x,$$\n\n\n\n\nwhere from now on the integral is understood as encompassing all non-negative values of the $x_i.$\n\n\n\n\nThe key formula\n\n\n\n\nOne way to evaluate such integrals is to integrate one variable at a time. To this end, set $y^2 = 1 + x_1^2 + \\cdots + x_{n-1}^2 = 1 + ||\\mathbf x_{\\hat n}||^2$ (with $y\\ge 0$). The notation $\\mathbf x_{\\hat n}$ means the component $x_n$ is omitted. Substituting $u = (x/y)^2$ shows\n\n\n\n\n$$\\begin{aligned}\n2\\int_0^\\infty x^{k} \\left(y^2 + x^2\\right)^{-\\alpha/2} \\,\\mathrm dx &= y^{k +1 - \\alpha}\\int_0^\\infty u^{(k-1)/2}\\left(1 + u\\right)^{-\\alpha/2} \\,\\mathrm du\\\\\n& = \\left(y^2\\right)^{-(\\alpha - k - 1)/2}\\,B\\left(\\frac{k+1}{2}, \\frac{\\alpha-k-1}{2}\\right)\n\\end{aligned}$$\n\n\n\n\n(a Beta function, arising e.g. from normalizing a Beta prime distribution (https://en.wikipedia.org/wiki/Beta_prime_distribution#Generalization)).\n\n\n\n\nApplying this in the case $\\alpha = \\nu + n$ and $k = k_n$ says\n\n\n\n\n$$\\begin{aligned}\n2\\int_0^\\infty x^{k_n} \\left(y^2 + x^2\\right)^{-(\\nu + n)/2} \\,\\mathrm dx = \\left(y^2\\right)^{-(\\nu - k_n + (n - 1))/2}\\,B\\left(\\frac{k_n+1}{2}, \\frac{\\nu - k_n + (n-1)}{2}\\right)\n\\end{aligned}$$\n\n\n\n\nPerforming the remaining integration over $(x_1, x_2, \\ldots, x_{n-1}) = \\mathbf x_{\\hat n}$ shows\n\n\n\n\n$$f(\\mathbf k;\\nu) = f(\\mathbf k_{\\hat n};\\, \\nu - k_n)B\\left(\\frac{k_n+1}{2}, \\frac{\\nu - k_n + (n-1)}{2}\\right).$$\n\n\n\n\nIterating from $i = n$ down to $1$ decreases $n$ by $1$ at each step and decreases $\\nu$ by $k_i$ for the next step, whence\n\n\n\n\n\n\n\n$$f(\\mathbf{k};\\,\\nu) = \\prod_{i=1}^n B\\left(\\frac{k_i+1}{2}, \\frac{\\nu - (k_i + k_{i+1} + \\cdots + k_n) + i - 1}{2}\\right).$$\n\n\n\n\n\n\n\n(Although this can be simplified using basic properties of Gamma functions, it is good enough for computation and analysis.)\n\n\n\n\nAs a check, we recover the normalizing constant as the zeroth moment,\n\n\n\n\n$$\\begin{aligned}\n C(\\nu, n) &= f((0,\\ldots,0);\\, n) \\\\\n&=\\prod_{i=1}^n B\\left(\\frac{0+1}{2}, \\frac{\\nu - 0 + (i-1)}{2}\\right)\\\\\n&=\\prod_{i=1}^n \\frac{\\Gamma\\left(\\frac{0+1}{2}\\right)\\Gamma\\left(\\frac{\\nu - 0 + (i-1)}{2}\\right)}{\\Gamma\\left(\\frac{\\nu + (i-1) + 1}{2}\\right)}\\\\\n&= \\frac{\\Gamma\\left(\\frac{1}{2}\\right)^n \\Gamma\\left(\\frac{\\nu}{2}\\right)}{\\Gamma\\left(\\frac{\\nu+n}{2}\\right)}.\n\\end{aligned}$$\n\n\n\n\nThis agrees with the value quoted in the question, since $\\Gamma(1/2)=\\sqrt{\\pi}.$\n\n\n\n\nFinally, recall that a scale parameter $\\tau$ multiplies each variable $x_i$ by $\\tau,$ whence it multiplies the moment of order $\\mathbf k$ by $\\tau(k_1+k_2+\\cdots+k_n).$ Writing\n\n\n\n\n$$\\kappa = k_1+k_2+\\cdots+k_n$$\n\n\n\n\nand recalling the scale parameter is $\\tau = \\sqrt{\\nu}\\sigma$ shows that\n\n\n\n\n\n\n\n$$\\mu(\\mathbf k;\\,\\nu,\\sigma) = \\frac{\\nu^{\\kappa/2}\\sigma^\\kappa f(\\mathbf k;\\,\\nu)}{C(\\nu, n)}.$$\n\n\n\n\n\n\n\nThe question concerns linear combinations of moments of order $4$ ($\\kappa = 4$). Computing the coefficients--which is merely a matter of multiplying the matrices--is of no interest here.\n\n\n\n\nImplementation and testing\n\n\n\n\nTo maintain precision and avoid numerical overflow, it is best to compute products of Beta functions using logarithms. Here is an example of how that's done in R, using its built-in lbeta (logarithm of Beta) function.\n\n\n\n\n#\n# log(f(k; nu))\n#\nlf <- function(k, nu) {\n n <- length(k)\n i <- seq_len(n)\n sum(lbeta((rev(k) + 1)/2, (nu - cumsum(rev(k)) + rev(i) - 1) / 2))\n}\n#\n# Absolute multivariate moments.\n# (They can be fractional--but not negative.)\n#\nmu <- function(k, nu, sigma = 1) {\n n <- length(k)\n y <- lf(k, nu)\n exp(y + lgamma((nu + n)/2) - lgamma(nu/2) - (n/2) * log(pi) + \n sum(k) * (log(nu)/2 + log(sigma)))\n}\n\n\n\n\n\nThe sum and cumsum functions require only $O(n)$ computational effort and storage.\n\n\n\n\nFor example, the $(0,1,2,3)$ moment with $\\nu=12$ is found as\n\n\n\n\n> mu(c(0,1,2,3), 12, 1)\n[1] 4.583662\n\n\n\n\n\nAs a test, I generated datasets of one million iid observations from multivariate $t$ distributions (using the mnormt package) and compared the sample moments (for various $\\mathbf k$) to the formula:\n\n\n\n\nset.seed(17)\nk <- c(0, 1, 2)\nnu <- 5\nX <- t(rmt(1e6, 0, diag(1, n), df = nu)) # One row for each coordinate\nm <- mean(apply(abs(X)^k, 2, prod)) # The estimated moment of order `k`\nm / mu(k, nu) \n\n\n\n\n\nThe output, equal to $1.012$ in this example, ideally would be $1,$ indicating perfect agreement. But $t$ distributions, especially for smallish $\\nu,$ are rather heavy-tailed, resulting in very high sampling variances for the higher moments (this one is of order $\\kappa = 0+1+2=3$). In light of this, $1.012$ is excellent agreement.\n\n\n\n\nThe output of additional tests continues to support the conclusion that the formulas for $f$ and $\\mu$ are correct.", "answer_url": "https://stats.stackexchange.com/a/676851", "author": "whuber", "author_url": "https://stats.stackexchange.com/users/919/whuber", "author_user_type": "moderator", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-12T15:28:16+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": 676824, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-08-12T15:28:16+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "C9CDAB77-2DD2-446E-837A-211128FD0EE9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C9CDAB77-2DD2-446E-837A-211128FD0EE9/view-source"}], "score": 2, "updated_at": "2026-08-12T15:28:16+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

I offer an elementary solution. It requires one substitution in an ordinary integral which, when repeated for each variable, yields a product of Beta function values.

\n

There are other solutions that might provide simpler formulas but are less elementary (e.g., use cylindrical coordinates).

\n

Initial simplification

\n

Because $\\sqrt{\\nu}\\sigma$ evidently is a scale parameter we can ignore it (for now), leaving everything to depend on the number of variables $n$ and the parameter $\\nu.$ Writing $\\mathbf x = (x_1, x_2, \\ldots, x_n),$ let the density be

\n

$$p(\\mathbf x;\\nu) = \\frac{\\Gamma\\left(\\frac{\\nu + n}{2}\\right)}{\\Gamma\\left(\\frac{\\nu}{2}\\right)\\pi^{n/2}} \\left(1 + \\sum_{i=1}^n x_i^2\\right)^{-(\\nu + n)/2} = \\frac{1}{C(\\nu, n)}\\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu + n)/2}.$$

\n

The moment of degree $\\mathbf k = (k_1, k_2, \\ldots, k_n)$ is, by definition,

\n

$$\\mu(\\mathbf k; \\nu) = \\int \\mathbf x^{\\mathbf k} p(\\mathbf x;\\nu)\\,\\mathrm d\\mathbf x = \\int_{-\\infty}^{\\infty}\\cdots\\int_{-\\infty}^{\\infty} x_1^{k_1}x_2^{k_2}\\cdots x_n^{k_n} p(\\mathbf x;\\nu)\\,\\mathrm dx_1\\mathrm dx_2\\cdots \\mathrm dx_n.$$

\n

Because $p$ depends only on the squares $x_i^2,$ it is an even function of all the variables. Consequently (implicitly assuming $\\mu(\\mathbf k;\\nu)$ exists),

\n
\n

whenever any $k_i$ is an odd integer, $\\mu(\\mathbf k;\\nu) = 0.$

\n
\n

Otherwise, when all the $k_i$ are even integers, we may integrate over positive $x_i$ only and double the result. Doing this for all $n$ variables gives

\n

$$\\mu(\\mathbf k; \\nu) = 2^n\\int_{(0,\\ldots,0)}^{(\\infty,\\ldots,\\infty)} \\mathbf x^{\\mathbf k} p(\\mathbf x;\\nu)\\,\\mathrm d\\mathbf x = \\frac{2^n}{C(\\nu,n)}\\int_{(0,\\ldots,0)}^{(\\infty,\\ldots,\\infty)} \\mathbf x^{\\mathbf k} \\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu+n)/2}\\,\\mathrm d\\mathbf x$$

\n

The question comes down to computing the integral on the right hand side. It deserves a name; let's call it

\n

$$f(\\mathbf k;\\nu) = C(\\nu,n)\\mu(\\mathbf k;\\nu) = 2^n\\int \\mathbf x^{\\mathbf k}\\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu + n)/2}\\,\\mathrm d\\mathbf x,$$

\n

where from now on the integral is understood as encompassing all non-negative values of the $x_i.$

\n

The key formula

\n

One way to evaluate such integrals is to integrate one variable at a time. To this end, set $y^2 = 1 + x_1^2 + \\cdots + x_{n-1}^2 = 1 + ||\\mathbf x_{\\hat n}||^2$ (with $y\\ge 0$). The notation $\\mathbf x_{\\hat n}$ means the component $x_n$ is omitted. Substituting $u = (x/y)^2$ shows

\n

$$\\begin{aligned}\n2\\int_0^\\infty x^{k} \\left(y^2 + x^2\\right)^{-\\alpha/2} \\,\\mathrm dx &= y^{k +1 - \\alpha}\\int_0^\\infty u^{(k-1)/2}\\left(1 + u\\right)^{-\\alpha/2} \\,\\mathrm du\\\\\n& = \\left(y^2\\right)^{-(\\alpha - k - 1)/2}\\,B\\left(\\frac{k+1}{2}, \\frac{\\alpha-k-1}{2}\\right)\n\\end{aligned}$$

\n

(a Beta function, arising e.g. from normalizing a Beta prime distribution).

\n

Applying this in the case $\\alpha = \\nu + n$ and $k = k_n$ says

\n

$$\\begin{aligned}\n2\\int_0^\\infty x^{k_n} \\left(y^2 + x^2\\right)^{-(\\nu + n)/2} \\,\\mathrm dx = \\left(y^2\\right)^{-(\\nu - k_n + (n - 1))/2}\\,B\\left(\\frac{k_n+1}{2}, \\frac{\\nu - k_n + (n-1)}{2}\\right)\n\\end{aligned}$$

\n

Performing the remaining integration over $(x_1, x_2, \\ldots, x_{n-1}) = \\mathbf x_{\\hat n}$ shows

\n

$$f(\\mathbf k;\\nu) = f(\\mathbf k_{\\hat n};\\, \\nu - k_n)B\\left(\\frac{k_n+1}{2}, \\frac{\\nu - k_n + (n-1)}{2}\\right).$$

\n

Iterating from $i = n$ down to $1$ decreases $n$ by $1$ at each step and decreases $\\nu$ by $k_i$ for the next step, whence

\n
\n

$$f(\\mathbf{k};\\,\\nu) = \\prod_{i=1}^n B\\left(\\frac{k_i+1}{2}, \\frac{\\nu - (k_i + k_{i+1} + \\cdots + k_n) + i - 1}{2}\\right).$$

\n
\n

(Although this can be simplified using basic properties of Gamma functions, it is good enough for computation and analysis.)

\n

As a check, we recover the normalizing constant as the zeroth moment,

\n

$$\\begin{aligned}\n C(\\nu, n) &= f((0,\\ldots,0);\\, n) \\\\\n&=\\prod_{i=1}^n B\\left(\\frac{0+1}{2}, \\frac{\\nu - 0 + (i-1)}{2}\\right)\\\\\n&=\\prod_{i=1}^n \\frac{\\Gamma\\left(\\frac{0+1}{2}\\right)\\Gamma\\left(\\frac{\\nu - 0 + (i-1)}{2}\\right)}{\\Gamma\\left(\\frac{\\nu + (i-1) + 1}{2}\\right)}\\\\\n&= \\frac{\\Gamma\\left(\\frac{1}{2}\\right)^n \\Gamma\\left(\\frac{\\nu}{2}\\right)}{\\Gamma\\left(\\frac{\\nu+n}{2}\\right)}.\n\\end{aligned}$$

\n

This agrees with the value quoted in the question, since $\\Gamma(1/2)=\\sqrt{\\pi}.$

\n

Finally, recall that a scale parameter $\\tau$ multiplies each variable $x_i$ by $\\tau,$ whence it multiplies the moment of order $\\mathbf k$ by $\\tau(k_1+k_2+\\cdots+k_n).$ Writing

\n

$$\\kappa = k_1+k_2+\\cdots+k_n$$

\n

and recalling the scale parameter is $\\tau = \\sqrt{\\nu}\\sigma$ shows that

\n
\n

$$\\mu(\\mathbf k;\\,\\nu,\\sigma) = \\frac{\\nu^{\\kappa/2}\\sigma^\\kappa f(\\mathbf k;\\,\\nu)}{C(\\nu, n)}.$$

\n
\n

The question concerns linear combinations of moments of order $4$ ($\\kappa = 4$). Computing the coefficients--which is merely a matter of multiplying the matrices--is of no interest here.

\n

Implementation and testing

\n

To maintain precision and avoid numerical overflow, it is best to compute products of Beta functions using logarithms. Here is an example of how that's done in R, using its built-in lbeta (logarithm of Beta) function.

\n
#\n# log(f(k; nu))\n#\nlf <- function(k, nu) {\n  n <- length(k)\n  i <- seq_len(n)\n  sum(lbeta((rev(k) + 1)/2, (nu - cumsum(rev(k)) + rev(i) - 1) / 2))\n}\n#\n# Absolute multivariate moments.\n# (They can be fractional--but not negative.)\n#\nmu <- function(k, nu, sigma = 1) {\n  n <- length(k)\n  y <- lf(k, nu)\n  exp(y + lgamma((nu + n)/2) - lgamma(nu/2) - (n/2) * log(pi) + \n          sum(k) * (log(nu)/2 + log(sigma)))\n}\n
\n

The sum and cumsum functions require only $O(n)$ computational effort and storage.

\n

For example, the $(0,1,2,3)$ moment with $\\nu=12$ is found as

\n
> mu(c(0,1,2,3), 12, 1)\n[1] 4.583662\n
\n

As a test, I generated datasets of one million iid observations from multivariate $t$ distributions (using the mnormt package) and compared the sample moments (for various $\\mathbf k$) to the formula:

\n
set.seed(17)\nk <- c(0, 1, 2)\nnu <- 5\nX <- t(rmt(1e6, 0, diag(1, n), df = nu)) # One row for each coordinate\nm <- mean(apply(abs(X)^k, 2, prod))      # The estimated moment of order `k`\nm / mu(k, nu)                   \n
\n

The output, equal to $1.012$ in this example, ideally would be $1,$ indicating perfect agreement. But $t$ distributions, especially for smallish $\\nu,$ are rather heavy-tailed, resulting in very high sampling variances for the higher moments (this one is of order $\\kappa = 0+1+2=3$). In light of this, $1.012$ is excellent agreement.

\n

The output of additional tests continues to support the conclusion that the formulas for $f$ and $\\mu$ are correct.

\n", "answer_id": 676851, "answer_text": "I offer an elementary solution. It requires one substitution in an ordinary integral which, when repeated for each variable, yields a product of Beta function values.\n\n\n\n\nThere are other solutions that might provide simpler formulas but are less elementary (e.g., use cylindrical coordinates).\n\n\n\n\nInitial simplification\n\n\n\n\nBecause $\\sqrt{\\nu}\\sigma$ evidently is a scale parameter we can ignore it (for now), leaving everything to depend on the number of variables $n$ and the parameter $\\nu.$ Writing $\\mathbf x = (x_1, x_2, \\ldots, x_n),$ let the density be\n\n\n\n\n$$p(\\mathbf x;\\nu) = \\frac{\\Gamma\\left(\\frac{\\nu + n}{2}\\right)}{\\Gamma\\left(\\frac{\\nu}{2}\\right)\\pi^{n/2}} \\left(1 + \\sum_{i=1}^n x_i^2\\right)^{-(\\nu + n)/2} = \\frac{1}{C(\\nu, n)}\\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu + n)/2}.$$\n\n\n\n\nThe moment of degree $\\mathbf k = (k_1, k_2, \\ldots, k_n)$ is, by definition,\n\n\n\n\n$$\\mu(\\mathbf k; \\nu) = \\int \\mathbf x^{\\mathbf k} p(\\mathbf x;\\nu)\\,\\mathrm d\\mathbf x = \\int_{-\\infty}^{\\infty}\\cdots\\int_{-\\infty}^{\\infty} x_1^{k_1}x_2^{k_2}\\cdots x_n^{k_n} p(\\mathbf x;\\nu)\\,\\mathrm dx_1\\mathrm dx_2\\cdots \\mathrm dx_n.$$\n\n\n\n\nBecause $p$ depends only on the squares $x_i^2,$ it is an even function of all the variables. Consequently (implicitly assuming $\\mu(\\mathbf k;\\nu)$ exists),\n\n\n\n\n\n\n\nwhenever any $k_i$ is an odd integer, $\\mu(\\mathbf k;\\nu) = 0.$\n\n\n\n\n\n\n\nOtherwise, when all the $k_i$ are even integers, we may integrate over positive $x_i$ only and double the result. Doing this for all $n$ variables gives\n\n\n\n\n$$\\mu(\\mathbf k; \\nu) = 2^n\\int_{(0,\\ldots,0)}^{(\\infty,\\ldots,\\infty)} \\mathbf x^{\\mathbf k} p(\\mathbf x;\\nu)\\,\\mathrm d\\mathbf x = \\frac{2^n}{C(\\nu,n)}\\int_{(0,\\ldots,0)}^{(\\infty,\\ldots,\\infty)} \\mathbf x^{\\mathbf k} \\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu+n)/2}\\,\\mathrm d\\mathbf x$$\n\n\n\n\nThe question comes down to computing the integral on the right hand side. It deserves a name; let's call it\n\n\n\n\n$$f(\\mathbf k;\\nu) = C(\\nu,n)\\mu(\\mathbf k;\\nu) = 2^n\\int \\mathbf x^{\\mathbf k}\\left(1 + ||\\mathbf x||^2\\right)^{-(\\nu + n)/2}\\,\\mathrm d\\mathbf x,$$\n\n\n\n\nwhere from now on the integral is understood as encompassing all non-negative values of the $x_i.$\n\n\n\n\nThe key formula\n\n\n\n\nOne way to evaluate such integrals is to integrate one variable at a time. To this end, set $y^2 = 1 + x_1^2 + \\cdots + x_{n-1}^2 = 1 + ||\\mathbf x_{\\hat n}||^2$ (with $y\\ge 0$). The notation $\\mathbf x_{\\hat n}$ means the component $x_n$ is omitted. Substituting $u = (x/y)^2$ shows\n\n\n\n\n$$\\begin{aligned}\n2\\int_0^\\infty x^{k} \\left(y^2 + x^2\\right)^{-\\alpha/2} \\,\\mathrm dx &= y^{k +1 - \\alpha}\\int_0^\\infty u^{(k-1)/2}\\left(1 + u\\right)^{-\\alpha/2} \\,\\mathrm du\\\\\n& = \\left(y^2\\right)^{-(\\alpha - k - 1)/2}\\,B\\left(\\frac{k+1}{2}, \\frac{\\alpha-k-1}{2}\\right)\n\\end{aligned}$$\n\n\n\n\n(a Beta function, arising e.g. from normalizing a Beta prime distribution (https://en.wikipedia.org/wiki/Beta_prime_distribution#Generalization)).\n\n\n\n\nApplying this in the case $\\alpha = \\nu + n$ and $k = k_n$ says\n\n\n\n\n$$\\begin{aligned}\n2\\int_0^\\infty x^{k_n} \\left(y^2 + x^2\\right)^{-(\\nu + n)/2} \\,\\mathrm dx = \\left(y^2\\right)^{-(\\nu - k_n + (n - 1))/2}\\,B\\left(\\frac{k_n+1}{2}, \\frac{\\nu - k_n + (n-1)}{2}\\right)\n\\end{aligned}$$\n\n\n\n\nPerforming the remaining integration over $(x_1, x_2, \\ldots, x_{n-1}) = \\mathbf x_{\\hat n}$ shows\n\n\n\n\n$$f(\\mathbf k;\\nu) = f(\\mathbf k_{\\hat n};\\, \\nu - k_n)B\\left(\\frac{k_n+1}{2}, \\frac{\\nu - k_n + (n-1)}{2}\\right).$$\n\n\n\n\nIterating from $i = n$ down to $1$ decreases $n$ by $1$ at each step and decreases $\\nu$ by $k_i$ for the next step, whence\n\n\n\n\n\n\n\n$$f(\\mathbf{k};\\,\\nu) = \\prod_{i=1}^n B\\left(\\frac{k_i+1}{2}, \\frac{\\nu - (k_i + k_{i+1} + \\cdots + k_n) + i - 1}{2}\\right).$$\n\n\n\n\n\n\n\n(Although this can be simplified using basic properties of Gamma functions, it is good enough for computation and analysis.)\n\n\n\n\nAs a check, we recover the normalizing constant as the zeroth moment,\n\n\n\n\n$$\\begin{aligned}\n C(\\nu, n) &= f((0,\\ldots,0);\\, n) \\\\\n&=\\prod_{i=1}^n B\\left(\\frac{0+1}{2}, \\frac{\\nu - 0 + (i-1)}{2}\\right)\\\\\n&=\\prod_{i=1}^n \\frac{\\Gamma\\left(\\frac{0+1}{2}\\right)\\Gamma\\left(\\frac{\\nu - 0 + (i-1)}{2}\\right)}{\\Gamma\\left(\\frac{\\nu + (i-1) + 1}{2}\\right)}\\\\\n&= \\frac{\\Gamma\\left(\\frac{1}{2}\\right)^n \\Gamma\\left(\\frac{\\nu}{2}\\right)}{\\Gamma\\left(\\frac{\\nu+n}{2}\\right)}.\n\\end{aligned}$$\n\n\n\n\nThis agrees with the value quoted in the question, since $\\Gamma(1/2)=\\sqrt{\\pi}.$\n\n\n\n\nFinally, recall that a scale parameter $\\tau$ multiplies each variable $x_i$ by $\\tau,$ whence it multiplies the moment of order $\\mathbf k$ by $\\tau(k_1+k_2+\\cdots+k_n).$ Writing\n\n\n\n\n$$\\kappa = k_1+k_2+\\cdots+k_n$$\n\n\n\n\nand recalling the scale parameter is $\\tau = \\sqrt{\\nu}\\sigma$ shows that\n\n\n\n\n\n\n\n$$\\mu(\\mathbf k;\\,\\nu,\\sigma) = \\frac{\\nu^{\\kappa/2}\\sigma^\\kappa f(\\mathbf k;\\,\\nu)}{C(\\nu, n)}.$$\n\n\n\n\n\n\n\nThe question concerns linear combinations of moments of order $4$ ($\\kappa = 4$). Computing the coefficients--which is merely a matter of multiplying the matrices--is of no interest here.\n\n\n\n\nImplementation and testing\n\n\n\n\nTo maintain precision and avoid numerical overflow, it is best to compute products of Beta functions using logarithms. Here is an example of how that's done in R, using its built-in lbeta (logarithm of Beta) function.\n\n\n\n\n#\n# log(f(k; nu))\n#\nlf <- function(k, nu) {\n n <- length(k)\n i <- seq_len(n)\n sum(lbeta((rev(k) + 1)/2, (nu - cumsum(rev(k)) + rev(i) - 1) / 2))\n}\n#\n# Absolute multivariate moments.\n# (They can be fractional--but not negative.)\n#\nmu <- function(k, nu, sigma = 1) {\n n <- length(k)\n y <- lf(k, nu)\n exp(y + lgamma((nu + n)/2) - lgamma(nu/2) - (n/2) * log(pi) + \n sum(k) * (log(nu)/2 + log(sigma)))\n}\n\n\n\n\n\nThe sum and cumsum functions require only $O(n)$ computational effort and storage.\n\n\n\n\nFor example, the $(0,1,2,3)$ moment with $\\nu=12$ is found as\n\n\n\n\n> mu(c(0,1,2,3), 12, 1)\n[1] 4.583662\n\n\n\n\n\nAs a test, I generated datasets of one million iid observations from multivariate $t$ distributions (using the mnormt package) and compared the sample moments (for various $\\mathbf k$) to the formula:\n\n\n\n\nset.seed(17)\nk <- c(0, 1, 2)\nnu <- 5\nX <- t(rmt(1e6, 0, diag(1, n), df = nu)) # One row for each coordinate\nm <- mean(apply(abs(X)^k, 2, prod)) # The estimated moment of order `k`\nm / mu(k, nu) \n\n\n\n\n\nThe output, equal to $1.012$ in this example, ideally would be $1,$ indicating perfect agreement. But $t$ distributions, especially for smallish $\\nu,$ are rather heavy-tailed, resulting in very high sampling variances for the higher moments (this one is of order $\\kappa = 0+1+2=3$). In light of this, $1.012$ is excellent agreement.\n\n\n\n\nThe output of additional tests continues to support the conclusion that the formulas for $f$ and $\\mu$ are correct.", "answer_url": "https://stats.stackexchange.com/a/676851", "author": "whuber", "author_url": "https://stats.stackexchange.com/users/919/whuber", "author_user_type": "moderator", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-12T15:28:16+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": 676824, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-08-12T15:28:16+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "C9CDAB77-2DD2-446E-837A-211128FD0EE9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C9CDAB77-2DD2-446E-837A-211128FD0EE9/view-source"}], "score": 2, "updated_at": "2026-08-12T15:28:16+00:00"}], "domain": "statistics", "external_links": ["https://en.wikipedia.org/wiki/Beta_prime_distribution#Generalization"], "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": "SATYA", "question_author_url": "https://stats.stackexchange.com/users/375640/satya", "question_author_user_type": "registered", "question_created_at": "2026-08-10T13:38:12+00:00", "question_html": "

The following is a multivariate Student's t distribution\n$$ p_{\\sigma^2}(\\mathrm{x})= {\\displaystyle {N_{\\nu,\\sigma^2}}\\left[1+\\frac{1}{\\nu\\sigma^2}\\sum_{i=1}^nx_i^2\\right]^{-(\\nu +n)/2}}, \\;\\mathrm{x}=[x_1,\\cdots,x_n]^{\\top}\\in \\mathbb{R}^n,\\;\\nu>2,$$ where $N_{\\nu,\\sigma^2}=\\frac {\\Gamma \\left[(\\nu +n)/2\\right]}{\\Gamma (\\nu /2)\\nu ^{n/2} \\pi^{n/2}{\\sigma}^{n}}.$ I am struggling to find the higher-order moments $E[X^{\\top}X]$, $E[X^{\\top}X(X^{\\top}X)^{\\top}]$. Is there a way to get these quantities?

\n", "question_id": 676824, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "The following is a multivariate Student's t distribution\n$$ p_{\\sigma^2}(\\mathrm{x})= {\\displaystyle {N_{\\nu,\\sigma^2}}\\left[1+\\frac{1}{\\nu\\sigma^2}\\sum_{i=1}^nx_i^2\\right]^{-(\\nu +n)/2}}, \\;\\mathrm{x}=[x_1,\\cdots,x_n]^{\\top}\\in \\mathbb{R}^n,\\;\\nu>2,$$ where $N_{\\nu,\\sigma^2}=\\frac {\\Gamma \\left[(\\nu +n)/2\\right]}{\\Gamma (\\nu /2)\\nu ^{n/2} \\pi^{n/2}{\\sigma}^{n}}.$ I am struggling to find the higher-order moments $E[X^{\\top}X]$, $E[X^{\\top}X(X^{\\top}X)^{\\top}]$. Is there a way to get these quantities?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "SATYA", "profile_url": "https://stats.stackexchange.com/users/375640/satya", "user_type": "registered"}, "created_at": "2026-08-10T13:38:12+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "FE80823D-F8D4-4BF7-916A-95ECE3955E38", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FE80823D-F8D4-4BF7-916A-95ECE3955E38/view-source"}, {"content_license": null, "contributor": {"display_name": "kjetil b halvorsen", "profile_url": "https://stats.stackexchange.com/users/11887/kjetil-b-halvorsen", "user_type": "moderator"}, "created_at": "2026-08-10T13:43:33+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "09839026-A5FE-44BE-B46A-D0FCD7254AFE", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/09839026-A5FE-44BE-B46A-D0FCD7254AFE/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676824/higher-moments-of-multivariate-students-t-distribution", "split": "train", "split_group": "d616db2eb7c80d9bcbf195f175fdfced0ba92b76f0e66918c59a439d07fa96f0", "tags": ["mathematical-statistics", "inference", "moments", "t-distribution"], "thread_id": "stats:676824", "title": "Higher Moments of multivariate Student's t distribution"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "Is Kaplan–Meier appropriate when multiple observations come from the same contributor?\n\n\n\n\nI would appreciate advice from researchers familiar with survival analysis and clustered/repeated observations.\n\n\n\n\nI am analyzing GitHub pull requests (PRs) to study whether a contributor's time to submit their next PR differs depending on whether their current/focal PR is abandoned or non-abandoned.\n\n\n\n\nMy analysis treats each PR as a focal observation. For every focal PR, I identify its contributor and calculate the time from that focal PR until the contributor submits their next PR.\n\n\n\n\nFor example:\n\n\n\n\n\n\n\n\n\nFocal PR\nContributor\nFocal PR Status\nTime to Next PR\n\n\n\n\n\n\n\n\n\tPR1\n\tA\n\tAbandoned\n\t10 days\n\n\n\n\n\n\n\tPR2\n\tA\n\tNon-abandoned\n\t25 days\n\n\n\n\n\n\n\tPR3\n\tB\n\tNon-abandoned\n\t7 days\n\n\n\n\n\n\n\tPR4\n\tB\n\tAbandoned\n\t15 days\n\n\n\n\n\n\n\n\n\nIf a contributor does not submit another PR before the end of the observation period, the observation is right-censored.\n\n\n\n\nThe issue is that the same contributor can appear multiple times as a focal observation, and can appear in both groups.\n\n\n\n\nFor example, if Contributor A submits:\n\n\n\n\nPR1 → PR2 → PR3\n\n\n\n\nthen PR1 has a time-to-next-PR of PR1→PR2, while PR2 has a time-to-next-PR of PR2→PR3. Thus, these are separate PR-level observations but are generated by the same contributor's contribution process.\n\n\n\n\nI am considering using Kaplan–Meier curves and the log-rank test to compare the time-to-next-PR distributions between abandoned and non-abandoned focal PRs.\n\n\n\n\nMy questions are:\n\n\n\n\n\nDoes the conventional Kaplan–Meier estimator assume that the observations are independent in this setting?\n\n\n\n\nDoes having multiple focal PRs from the same contributor violate this assumption?\n\n\n\n\nIf so, does the dependence mainly affect the standard errors, confidence intervals, and log-rank p-values, or does it also affect the Kaplan–Meier survival estimates?\n\n\n\n\nDoes having a large number of unique contributors make conventional Kaplan–Meier/log-rank inference reasonably defensible despite repeated observations?\n\n\n\n\nWould a cluster-robust approach, shared-frailty model, or another survival model be more appropriate?\n\n\n\n\n\nMy main concern is whether the p-values and statistical inference from the conventional Kaplan–Meier/log-rank analysis are valid when the same contributor can contribute multiple focal-PR observations.\n\n\n\n\nAny advice on the appropriate way to handle this dependence would be greatly appreciated.", "record_id": "Scientific-Statistics-QA:stats:676830", "selected_answer": {"answer_html": "
\n

I am considering using Kaplan–Meier curves and the log-rank test to compare the time-to-next-PR distributions between abandoned and non-abandoned focal PRs.

\n
\n

That could be a start, but it won't allow you to incorporate additional predictors that might affect the time-to-next-PR (age, experience, working group, number/complexity of pending PRs, ...). A Cox proportional-hazards survival model would. As Frank Harrell says: "There is no advantage to using the log-rank statistic and several disadvantages."

\n
\n

Does the conventional Kaplan–Meier estimator assume that the observations are independent in this setting?

\n
\n

Yes.

\n
\n

Does having multiple focal PRs from the same contributor violate this assumption?

\n
\n

Yes.

\n
\n

If so, does the dependence mainly affect the standard errors, confidence intervals, and log-rank p-values, or does it also affect the Kaplan–Meier survival estimates?

\n
\n

Standard error, confidence intervals and p-values are certainly affected. What happens to point estimates of survival depends on how you model the repeated events per individual. See below.

\n
\n

Does having a large number of unique contributors make conventional Kaplan–Meier/log-rank inference reasonably defensible despite repeated observations?

\n
\n

No. Inference requires proper standard errors/confidence intervals. Point estimates of survival might be good enough, but inference would be hard to defend.

\n
\n

Would a cluster-robust approach, shared-frailty model, or another survival model be more appropriate?

\n
\n

Yes.

\n

The title of Chapter 8 of Therneau and Grambsch is "Multiple Events per Subject." Quoting:

\n
\n

A major issue in extending proportional hazards regression models to this situation is intrasubject correlation... Several approaches to such data have appeared in the literature: Time to first event, ignoring the multiplicity... Random effects or frailty model... A marginal models approach...

\n
\n

They focus on marginal models, the cluster-robust approach. They outline three steps.

\n
\n

• Decide on a model (issues such as strata, time-dependent covariates, etc.) and structure the data set accordingly.

\n

• Fit the data as an ordinary Cox model, ignoring the possible correlation.

\n

• Replace the standard variance estimate with one which is corrected for the possible correlations.

\n
\n

You need to make choices about how to handle the repeated PRs within an individual. You have chosen to model "time-to-next-PR," which means that you structure the data to reset time 0 for survival at each PR event for an individual and use the inter-PR interval instead of total elapsed time as the time to the next event.

\n

Next, you have to choose whether the ordered-in-time PRs should be treated as equivalent (given the same covariates), or should the baseline hazard change with each subsequent PR event.

\n

If you consider the ordered-in-time PRs to be equivalent, you can use an Andersen-Gill model (a Cox proportional hazard model of the properly structured data). If there aren't any covariates beyond focal PR status, the point estimates of survival will be about the same as the corresponding Kaplan-Meier estimates on the data structured for the Andersen-Gill model, but with much more reliable standard-error estimates.*

\n

If you think that sequential PRs should be modeled separately, specify a separate stratum for each event in sequence. See Section 8.5 of Therneau and Grambsch. That will give different results from a simple Kaplan-Meier analysis.

\n

You could use a "frailty" model (a single random per-individual intercept in your case) instead. More general random-effects models (e.g., with the R coxme package) would allow modeling of nested correlation structures (e.g., individuals within working groups).

\n

The R survival package has many vignettes illustrating aspects of survival modeling.

\n
\n

*The Kaplan-Meier survival estimate can differ a bit from the Nelson-Aalen estimate that's typically used for baseline survival in Cox model. See Chapter 2 of Therneau and Grambsch.

\n", "answer_id": 676835, "answer_text": "I am considering using Kaplan–Meier curves and the log-rank test to compare the time-to-next-PR distributions between abandoned and non-abandoned focal PRs.\n\n\n\n\n\n\n\nThat could be a start, but it won't allow you to incorporate additional predictors that might affect the time-to-next-PR (age, experience, working group, number/complexity of pending PRs, ...). A Cox proportional-hazards survival model would. As Frank Harrell says (https://stats.stackexchange.com/a/486810/28500): \"There is no advantage to using the log-rank statistic and several disadvantages.\"\n\n\n\n\n\n\n\nDoes the conventional Kaplan–Meier estimator assume that the observations are independent in this setting?\n\n\n\n\n\n\n\nYes.\n\n\n\n\n\n\n\nDoes having multiple focal PRs from the same contributor violate this assumption?\n\n\n\n\n\n\n\nYes.\n\n\n\n\n\n\n\nIf so, does the dependence mainly affect the standard errors, confidence intervals, and log-rank p-values, or does it also affect the Kaplan–Meier survival estimates?\n\n\n\n\n\n\n\nStandard error, confidence intervals and p-values are certainly affected. What happens to point estimates of survival depends on how you model the repeated events per individual. See below.\n\n\n\n\n\n\n\nDoes having a large number of unique contributors make conventional Kaplan–Meier/log-rank inference reasonably defensible despite repeated observations?\n\n\n\n\n\n\n\nNo. Inference requires proper standard errors/confidence intervals. Point estimates of survival might be good enough, but inference would be hard to defend.\n\n\n\n\n\n\n\nWould a cluster-robust approach, shared-frailty model, or another survival model be more appropriate?\n\n\n\n\n\n\n\nYes.\n\n\n\n\nThe title of Chapter 8 of Therneau and Grambsch (https://www.springer.com/us/book/9780387987842) is \"Multiple Events per Subject.\" Quoting:\n\n\n\n\n\n\n\nA major issue in extending proportional hazards regression models to this situation is intrasubject correlation... Several approaches to such data have appeared in the literature: Time to first event, ignoring the multiplicity... Random effects or frailty model... A marginal models approach...\n\n\n\n\n\n\n\nThey focus on marginal models, the cluster-robust approach. They outline three steps.\n\n\n\n\n\n\n\n• Decide on a model (issues such as strata, time-dependent covariates, etc.) and structure the data set accordingly.\n\n\n\n\n• Fit the data as an ordinary Cox model, ignoring the possible correlation.\n\n\n\n\n• Replace the standard variance estimate with one which is corrected for the possible correlations.\n\n\n\n\n\n\n\nYou need to make choices about how to handle the repeated PRs within an individual. You have chosen to model \"time-to-next-PR,\" which means that you structure the data to reset time 0 for survival at each PR event for an individual and use the inter-PR interval instead of total elapsed time as the time to the next event.\n\n\n\n\nNext, you have to choose whether the ordered-in-time PRs should be treated as equivalent (given the same covariates), or should the baseline hazard change with each subsequent PR event.\n\n\n\n\nIf you consider the ordered-in-time PRs to be equivalent, you can use an Andersen-Gill model (a Cox proportional hazard model of the properly structured data). If there aren't any covariates beyond focal PR status, the point estimates of survival will be about the same as the corresponding Kaplan-Meier estimates on the data structured for the Andersen-Gill model, but with much more reliable standard-error estimates.*\n\n\n\n\nIf you think that sequential PRs should be modeled separately, specify a separate stratum for each event in sequence. See Section 8.5 of Therneau and Grambsch. That will give different results from a simple Kaplan-Meier analysis.\n\n\n\n\nYou could use a \"frailty\" model (a single random per-individual intercept in your case) instead. More general random-effects models (e.g., with the R coxme package (https://cran.r-project.org/package=coxme)) would allow modeling of nested correlation structures (e.g., individuals within working groups).\n\n\n\n\nThe R survival package (https://cran.r-project.org/package=survival) has many vignettes illustrating aspects of survival modeling.\n\n\n\n\n\n\n\n*The Kaplan-Meier survival estimate can differ a bit from the Nelson-Aalen estimate that's typically used for baseline survival in Cox model. See Chapter 2 of Therneau and Grambsch.", "answer_url": "https://stats.stackexchange.com/a/676835", "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-10T21:14:38+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676830, "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-10T21:14:38+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "480875B7-6656-4E0C-A68D-F29EFB4EE694", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/480875B7-6656-4E0C-A68D-F29EFB4EE694/view-source"}], "score": 3, "updated_at": "2026-08-10T21:14:38+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "
\n

I am considering using Kaplan–Meier curves and the log-rank test to compare the time-to-next-PR distributions between abandoned and non-abandoned focal PRs.

\n
\n

That could be a start, but it won't allow you to incorporate additional predictors that might affect the time-to-next-PR (age, experience, working group, number/complexity of pending PRs, ...). A Cox proportional-hazards survival model would. As Frank Harrell says: "There is no advantage to using the log-rank statistic and several disadvantages."

\n
\n

Does the conventional Kaplan–Meier estimator assume that the observations are independent in this setting?

\n
\n

Yes.

\n
\n

Does having multiple focal PRs from the same contributor violate this assumption?

\n
\n

Yes.

\n
\n

If so, does the dependence mainly affect the standard errors, confidence intervals, and log-rank p-values, or does it also affect the Kaplan–Meier survival estimates?

\n
\n

Standard error, confidence intervals and p-values are certainly affected. What happens to point estimates of survival depends on how you model the repeated events per individual. See below.

\n
\n

Does having a large number of unique contributors make conventional Kaplan–Meier/log-rank inference reasonably defensible despite repeated observations?

\n
\n

No. Inference requires proper standard errors/confidence intervals. Point estimates of survival might be good enough, but inference would be hard to defend.

\n
\n

Would a cluster-robust approach, shared-frailty model, or another survival model be more appropriate?

\n
\n

Yes.

\n

The title of Chapter 8 of Therneau and Grambsch is "Multiple Events per Subject." Quoting:

\n
\n

A major issue in extending proportional hazards regression models to this situation is intrasubject correlation... Several approaches to such data have appeared in the literature: Time to first event, ignoring the multiplicity... Random effects or frailty model... A marginal models approach...

\n
\n

They focus on marginal models, the cluster-robust approach. They outline three steps.

\n
\n

• Decide on a model (issues such as strata, time-dependent covariates, etc.) and structure the data set accordingly.

\n

• Fit the data as an ordinary Cox model, ignoring the possible correlation.

\n

• Replace the standard variance estimate with one which is corrected for the possible correlations.

\n
\n

You need to make choices about how to handle the repeated PRs within an individual. You have chosen to model "time-to-next-PR," which means that you structure the data to reset time 0 for survival at each PR event for an individual and use the inter-PR interval instead of total elapsed time as the time to the next event.

\n

Next, you have to choose whether the ordered-in-time PRs should be treated as equivalent (given the same covariates), or should the baseline hazard change with each subsequent PR event.

\n

If you consider the ordered-in-time PRs to be equivalent, you can use an Andersen-Gill model (a Cox proportional hazard model of the properly structured data). If there aren't any covariates beyond focal PR status, the point estimates of survival will be about the same as the corresponding Kaplan-Meier estimates on the data structured for the Andersen-Gill model, but with much more reliable standard-error estimates.*

\n

If you think that sequential PRs should be modeled separately, specify a separate stratum for each event in sequence. See Section 8.5 of Therneau and Grambsch. That will give different results from a simple Kaplan-Meier analysis.

\n

You could use a "frailty" model (a single random per-individual intercept in your case) instead. More general random-effects models (e.g., with the R coxme package) would allow modeling of nested correlation structures (e.g., individuals within working groups).

\n

The R survival package has many vignettes illustrating aspects of survival modeling.

\n
\n

*The Kaplan-Meier survival estimate can differ a bit from the Nelson-Aalen estimate that's typically used for baseline survival in Cox model. See Chapter 2 of Therneau and Grambsch.

\n", "answer_id": 676835, "answer_text": "I am considering using Kaplan–Meier curves and the log-rank test to compare the time-to-next-PR distributions between abandoned and non-abandoned focal PRs.\n\n\n\n\n\n\n\nThat could be a start, but it won't allow you to incorporate additional predictors that might affect the time-to-next-PR (age, experience, working group, number/complexity of pending PRs, ...). A Cox proportional-hazards survival model would. As Frank Harrell says (https://stats.stackexchange.com/a/486810/28500): \"There is no advantage to using the log-rank statistic and several disadvantages.\"\n\n\n\n\n\n\n\nDoes the conventional Kaplan–Meier estimator assume that the observations are independent in this setting?\n\n\n\n\n\n\n\nYes.\n\n\n\n\n\n\n\nDoes having multiple focal PRs from the same contributor violate this assumption?\n\n\n\n\n\n\n\nYes.\n\n\n\n\n\n\n\nIf so, does the dependence mainly affect the standard errors, confidence intervals, and log-rank p-values, or does it also affect the Kaplan–Meier survival estimates?\n\n\n\n\n\n\n\nStandard error, confidence intervals and p-values are certainly affected. What happens to point estimates of survival depends on how you model the repeated events per individual. See below.\n\n\n\n\n\n\n\nDoes having a large number of unique contributors make conventional Kaplan–Meier/log-rank inference reasonably defensible despite repeated observations?\n\n\n\n\n\n\n\nNo. Inference requires proper standard errors/confidence intervals. Point estimates of survival might be good enough, but inference would be hard to defend.\n\n\n\n\n\n\n\nWould a cluster-robust approach, shared-frailty model, or another survival model be more appropriate?\n\n\n\n\n\n\n\nYes.\n\n\n\n\nThe title of Chapter 8 of Therneau and Grambsch (https://www.springer.com/us/book/9780387987842) is \"Multiple Events per Subject.\" Quoting:\n\n\n\n\n\n\n\nA major issue in extending proportional hazards regression models to this situation is intrasubject correlation... Several approaches to such data have appeared in the literature: Time to first event, ignoring the multiplicity... Random effects or frailty model... A marginal models approach...\n\n\n\n\n\n\n\nThey focus on marginal models, the cluster-robust approach. They outline three steps.\n\n\n\n\n\n\n\n• Decide on a model (issues such as strata, time-dependent covariates, etc.) and structure the data set accordingly.\n\n\n\n\n• Fit the data as an ordinary Cox model, ignoring the possible correlation.\n\n\n\n\n• Replace the standard variance estimate with one which is corrected for the possible correlations.\n\n\n\n\n\n\n\nYou need to make choices about how to handle the repeated PRs within an individual. You have chosen to model \"time-to-next-PR,\" which means that you structure the data to reset time 0 for survival at each PR event for an individual and use the inter-PR interval instead of total elapsed time as the time to the next event.\n\n\n\n\nNext, you have to choose whether the ordered-in-time PRs should be treated as equivalent (given the same covariates), or should the baseline hazard change with each subsequent PR event.\n\n\n\n\nIf you consider the ordered-in-time PRs to be equivalent, you can use an Andersen-Gill model (a Cox proportional hazard model of the properly structured data). If there aren't any covariates beyond focal PR status, the point estimates of survival will be about the same as the corresponding Kaplan-Meier estimates on the data structured for the Andersen-Gill model, but with much more reliable standard-error estimates.*\n\n\n\n\nIf you think that sequential PRs should be modeled separately, specify a separate stratum for each event in sequence. See Section 8.5 of Therneau and Grambsch. That will give different results from a simple Kaplan-Meier analysis.\n\n\n\n\nYou could use a \"frailty\" model (a single random per-individual intercept in your case) instead. More general random-effects models (e.g., with the R coxme package (https://cran.r-project.org/package=coxme)) would allow modeling of nested correlation structures (e.g., individuals within working groups).\n\n\n\n\nThe R survival package (https://cran.r-project.org/package=survival) has many vignettes illustrating aspects of survival modeling.\n\n\n\n\n\n\n\n*The Kaplan-Meier survival estimate can differ a bit from the Nelson-Aalen estimate that's typically used for baseline survival in Cox model. See Chapter 2 of Therneau and Grambsch.", "answer_url": "https://stats.stackexchange.com/a/676835", "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-10T21:14:38+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676830, "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-10T21:14:38+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "480875B7-6656-4E0C-A68D-F29EFB4EE694", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/480875B7-6656-4E0C-A68D-F29EFB4EE694/view-source"}], "score": 3, "updated_at": "2026-08-10T21:14:38+00:00"}], "domain": "statistics", "external_links": ["https://cran.r-project.org/package=coxme", "https://cran.r-project.org/package=survival", "https://www.springer.com/us/book/9780387987842"], "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": "pritpal Rehan", "question_author_url": "https://stats.stackexchange.com/users/485224/pritpal-rehan", "question_author_user_type": "registered", "question_created_at": "2026-08-10T16:30:06+00:00", "question_html": "

Is Kaplan–Meier appropriate when multiple observations come from the same contributor?

\n

I would appreciate advice from researchers familiar with survival analysis and clustered/repeated observations.

\n

I am analyzing GitHub pull requests (PRs) to study whether a contributor's time to submit their next PR differs depending on whether their current/focal PR is abandoned or non-abandoned.

\n

My analysis treats each PR as a focal observation. For every focal PR, I identify its contributor and calculate the time from that focal PR until the contributor submits their next PR.

\n

For example:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Focal PRContributorFocal PR StatusTime to Next PR
PR1AAbandoned10 days
PR2ANon-abandoned25 days
PR3BNon-abandoned7 days
PR4BAbandoned15 days
\n

If a contributor does not submit another PR before the end of the observation period, the observation is right-censored.

\n

The issue is that the same contributor can appear multiple times as a focal observation, and can appear in both groups.

\n

For example, if Contributor A submits:

\n

PR1 → PR2 → PR3

\n

then PR1 has a time-to-next-PR of PR1→PR2, while PR2 has a time-to-next-PR of PR2→PR3. Thus, these are separate PR-level observations but are generated by the same contributor's contribution process.

\n

I am considering using Kaplan–Meier curves and the log-rank test to compare the time-to-next-PR distributions between abandoned and non-abandoned focal PRs.

\n

My questions are:

\n
    \n
  1. Does the conventional Kaplan–Meier estimator assume that the observations are independent in this setting?
  2. \n
  3. Does having multiple focal PRs from the same contributor violate this assumption?
  4. \n
  5. If so, does the dependence mainly affect the standard errors, confidence intervals, and log-rank p-values, or does it also affect the Kaplan–Meier survival estimates?
  6. \n
  7. Does having a large number of unique contributors make conventional Kaplan–Meier/log-rank inference reasonably defensible despite repeated observations?
  8. \n
  9. Would a cluster-robust approach, shared-frailty model, or another survival model be more appropriate?
  10. \n
\n

My main concern is whether the p-values and statistical inference from the conventional Kaplan–Meier/log-rank analysis are valid when the same contributor can contribute multiple focal-PR observations.

\n

Any advice on the appropriate way to handle this dependence would be greatly appreciated.

\n", "question_id": 676830, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "Is Kaplan–Meier appropriate when multiple observations come from the same contributor?\n\n\n\n\nI would appreciate advice from researchers familiar with survival analysis and clustered/repeated observations.\n\n\n\n\nI am analyzing GitHub pull requests (PRs) to study whether a contributor's time to submit their next PR differs depending on whether their current/focal PR is abandoned or non-abandoned.\n\n\n\n\nMy analysis treats each PR as a focal observation. For every focal PR, I identify its contributor and calculate the time from that focal PR until the contributor submits their next PR.\n\n\n\n\nFor example:\n\n\n\n\n\n\n\n\n\nFocal PR\nContributor\nFocal PR Status\nTime to Next PR\n\n\n\n\n\n\n\n\n\tPR1\n\tA\n\tAbandoned\n\t10 days\n\n\n\n\n\n\n\tPR2\n\tA\n\tNon-abandoned\n\t25 days\n\n\n\n\n\n\n\tPR3\n\tB\n\tNon-abandoned\n\t7 days\n\n\n\n\n\n\n\tPR4\n\tB\n\tAbandoned\n\t15 days\n\n\n\n\n\n\n\n\n\nIf a contributor does not submit another PR before the end of the observation period, the observation is right-censored.\n\n\n\n\nThe issue is that the same contributor can appear multiple times as a focal observation, and can appear in both groups.\n\n\n\n\nFor example, if Contributor A submits:\n\n\n\n\nPR1 → PR2 → PR3\n\n\n\n\nthen PR1 has a time-to-next-PR of PR1→PR2, while PR2 has a time-to-next-PR of PR2→PR3. Thus, these are separate PR-level observations but are generated by the same contributor's contribution process.\n\n\n\n\nI am considering using Kaplan–Meier curves and the log-rank test to compare the time-to-next-PR distributions between abandoned and non-abandoned focal PRs.\n\n\n\n\nMy questions are:\n\n\n\n\n\nDoes the conventional Kaplan–Meier estimator assume that the observations are independent in this setting?\n\n\n\n\nDoes having multiple focal PRs from the same contributor violate this assumption?\n\n\n\n\nIf so, does the dependence mainly affect the standard errors, confidence intervals, and log-rank p-values, or does it also affect the Kaplan–Meier survival estimates?\n\n\n\n\nDoes having a large number of unique contributors make conventional Kaplan–Meier/log-rank inference reasonably defensible despite repeated observations?\n\n\n\n\nWould a cluster-robust approach, shared-frailty model, or another survival model be more appropriate?\n\n\n\n\n\nMy main concern is whether the p-values and statistical inference from the conventional Kaplan–Meier/log-rank analysis are valid when the same contributor can contribute multiple focal-PR observations.\n\n\n\n\nAny advice on the appropriate way to handle this dependence would be greatly appreciated.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "pritpal Rehan", "profile_url": "https://stats.stackexchange.com/users/485224/pritpal-rehan", "user_type": "registered"}, "created_at": "2026-08-10T16:30:06+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "F25AEB11-F6EE-4139-A27B-8DA7E73D2655", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F25AEB11-F6EE-4139-A27B-8DA7E73D2655/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "pritpal Rehan", "profile_url": "https://stats.stackexchange.com/users/485224/pritpal-rehan", "user_type": "registered"}, "created_at": "2026-08-10T16:31:22+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "E6A36D2B-EFF7-4BF0-8556-D72E548E6F3D", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E6A36D2B-EFF7-4BF0-8556-D72E548E6F3D/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "pritpal Rehan", "profile_url": "https://stats.stackexchange.com/users/485224/pritpal-rehan", "user_type": "registered"}, "created_at": "2026-08-10T16:33:30+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "435AA604-B6C7-4559-95E4-987EC7572F29", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/435AA604-B6C7-4559-95E4-987EC7572F29/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-11T00:36:17+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "721F6DEE-2518-445D-B171-EFC8C381CB53", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/721F6DEE-2518-445D-B171-EFC8C381CB53/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676830/is-the-independence-assumption-of-kaplan-meier-analysis-satisfied-when-analyzing", "split": "train", "split_group": "7330dd122ab32547240419e1df4a2d471afad6cfdec710aeec015f19da377079", "tags": ["survival", "kaplan-meier", "open-source"], "thread_id": "stats:676830", "title": "Is the independence assumption of Kaplan–Meier analysis satisfied when analyzing time to a contributor's next PR?"}} +{"accepted_answer": {"answer_html": "

It is still true that the asymptotic null distribution of the LRT is the null distribution of a local Gaussian shift alternative. In your $N(\\mu,\\sigma^2)$ example that means the asymptotic null distribution is the same as testing $\\mu=0$ or $\\sigma^2=1$ for the bivariate Normal distribution that's the limit of $\\sqrt{n}(\\hat\\mu-\\mu,\\hat\\sigma^2-\\sigma^2)$

\n

This doesn't initially get you all that far further forward, because that distribution is ugly. You can now notice that for this specific asymptotic bivariate Normal problem the variables are orthogonal. The restricted MLE under the null is either $(0,\\hat\\sigma^2)$ or $(\\hat\\mu,1)$, depending on which is closer to $\\hat\\theta$. That means the log likelihood ratio is the minimum of two independent scaled $\\chi^2_1$

\n

Specifically, we should get the minimum of two $\\chi^2_1$s. The red line shows this CDF on your plot.

\n

\"enter

\n

For the more general case you have a limiting bivariate Normal problem with non-diagonal variance. It's still true that you just work out the distance to the restricted MLE, but that's the closest point in a non-rectangular norm. The geometry is not the same in all the orthants. Also, the restricted MLE can be at the equivalent of $(0,1)$ with non-zero probability, so there's a $\\chi^2_0$ component to the mixture. I think you end up with five components in total for two parameters.

\n

With more than two parameters taking part, everything is exactly the same only incomparably worse: the geometry of the closest point in the null hypothesis just gets more and more complicated, with more and more components. But the idea is the same: the LRT is asymptotically the LRT for a single-observation local Gaussian shift problem. This is, in some sense, why Wald's Theorem works and why Chernoff's result for boundary problems works and lots of other things.

\n", "answer_id": 676849, "answer_text": "It is still true that the asymptotic null distribution of the LRT is the null distribution of a local Gaussian shift alternative. In your $N(\\mu,\\sigma^2)$ example that means the asymptotic null distribution is the same as testing $\\mu=0$ or $\\sigma^2=1$ for the bivariate Normal distribution that's the limit of $\\sqrt{n}(\\hat\\mu-\\mu,\\hat\\sigma^2-\\sigma^2)$\n\n\n\n\nThis doesn't initially get you all that far further forward, because that distribution is ugly. You can now notice that for this specific asymptotic bivariate Normal problem the variables are orthogonal. The restricted MLE under the null is either $(0,\\hat\\sigma^2)$ or $(\\hat\\mu,1)$, depending on which is closer to $\\hat\\theta$. That means the log likelihood ratio is the minimum of two independent scaled $\\chi^2_1$\n\n\n\n\nSpecifically, we should get the minimum of two $\\chi^2_1$s. The red line shows this CDF on your plot.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/Qsmelzjn.png] (https://i.sstatic.net/Qsmelzjn.png)\n\n\n\n\nFor the more general case you have a limiting bivariate Normal problem with non-diagonal variance. It's still true that you just work out the distance to the restricted MLE, but that's the closest point in a non-rectangular norm. The geometry is not the same in all the orthants. Also, the restricted MLE can be at the equivalent of $(0,1)$ with non-zero probability, so there's a $\\chi^2_0$ component to the mixture. I think you end up with five components in total for two parameters.\n\n\n\n\nWith more than two parameters taking part, everything is exactly the same only incomparably worse: the geometry of the closest point in the null hypothesis just gets more and more complicated, with more and more components. But the idea is the same: the LRT is asymptotically the LRT for a single-observation local Gaussian shift problem. This is, in some sense, why Wald's Theorem works and why Chernoff's result for boundary problems works and lots of other things.", "answer_url": "https://stats.stackexchange.com/a/676849", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-12T03:14:18+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": 676842, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-12T03:14:18+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "EF5747F6-4B6A-42A4-8968-9F80C87019F6", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EF5747F6-4B6A-42A4-8968-9F80C87019F6/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-12T03:21:16+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "A9820920-337C-4445-864A-E2CE6845065B", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A9820920-337C-4445-864A-E2CE6845065B/view-source"}], "score": 4, "updated_at": "2026-08-12T03:21:16+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "In fact I doubt if such kind of hypothesis test will be used in real work, but just out of curiosity I have a question on the property of such test.\n\n\n\n\nQuestion. Consider an $n$-dimensional parameter $\\theta= (\\theta_1, \\cdots, \\theta_n)\\in \\Theta$ where $\\Theta$ is an open subset in $\\mathbb R^n$, and the hypothesis\n$$ H_0: \\text{either }\\theta_1= c_1 \\text{ or }\\theta_2= c_2\\longleftrightarrow\nH_1:\\text{ otherwise},$$\nwhere $c_1, c_2$ are given constant.\nWhat is the asymptotic distribution of $-2 \\log\\lambda$ where $\\lambda$ is the likelihood ratio statistic, if the true model is $\\theta_1= c_1$ and $\\theta_2= c_2$?\n(Assuming all other conditions of Wilks's Theorem).\n\n\n\n\nFor example, consider $X_1,\\cdots, X_n$ are i.i.d. samples from $N(\\mu, \\sigma^2)$,\nand test if $H_0: \\text{either }\\mu=0 \\text{ or }\\sigma^2= 1$ holds.\nThen the maximum likelihood estimation is the one in $(\\mu, \\sigma^2)= (0, \\sqrt{\\frac{1}{n}\\sum_{i=1}^n X_i^2} )$ and $(\\mu, \\sigma^2)= (\\frac 1n\\sum_{i=1}^n X_i, 1)$\nwhich has a larger likelihood, and from this we can compute the LR statistic $\\lambda$.\n\n\n\n\nIf, say, the model is generated under true parameter $\\mu= 1, \\sigma^2= 1$, then\nthe simulating data shows that the empirical cdf of $-2\\log\\lambda$\nand $\\chi^2_1$ are very close, which seems to suggest that $-2\\log\\lambda\\to_d\\chi^2_1$,\nand this is in fact the case, as, when the sample size tends to infinity, the probability that the MLE under $H_0$ is $(\\mu, \\sigma^2)= (\\frac 1n\\sum_{i=1}^n X_i, 1)$ (which corresponds to the true parameter) will tend to $1$, so the LR statistic is the same as testing $H_0: \\sigma^2= 1$ which probability tending to $1$.\n\n\n\n\nHowever, if the true parameter is $(\\mu, \\sigma^2)= (0, 1)$, then the empirical cdf of $-2\\log\\lambda$ is no longer close to $\\chi^2_1$, as the figure below shows.\n\n\n\n\nMy question is, does $-2\\log\\lambda$ has a general asymptotic distribution in such case?\n\n\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/cWv54DMg.png] (https://i.sstatic.net/cWv54DMg.png)\n\n\n\n\n# R code for simulation\n\nnsim=1000 # number of simulation\nnsample= 20000 # number of sample\n\nN= nsample\nT= rep(0, nsim)\n\nfor(i in 1: nsim){\n x= rnorm(mean=0, sd=1, n=N)\n muhat= mean(x)\n sigmahat= sqrt(mean((x- muhat)^2))\n ll_mu_in_H0 = sum(dnorm(x, mean = 0, sd = sqrt(mean(x^2)), log = TRUE))\n ll_sigma_in_H0= sum(dnorm(x, mean = muhat, sd = 1, log = TRUE))\n llr= max(ll_mu_in_H0, ll_sigma_in_H0)- sum(dnorm(x, mean = muhat, sd = sigmahat, log = TRUE))\n T[i]= -2*llr\n}\n\npar(mar=c(5,4,4,12), xpd=TRUE)\nplot(sort(T), (1:nsim)/nsim, type='l', lty=2, xlab= 'x', ylab= 'CDF')\nlines(qchisq(p= (1:nsim)/nsim, df= 1, ncp = 0, lower.tail = TRUE, log.p = FALSE), (1:nsim)/nsim, lty=1)\nlegend(\"topright\",inset= c(-0.5,0), lty= c(2,1), legend= c('empirical', 'chi^2 with df=1'))", "record_id": "Scientific-Statistics-QA:stats:676842", "selected_answer": {"answer_html": "

It is still true that the asymptotic null distribution of the LRT is the null distribution of a local Gaussian shift alternative. In your $N(\\mu,\\sigma^2)$ example that means the asymptotic null distribution is the same as testing $\\mu=0$ or $\\sigma^2=1$ for the bivariate Normal distribution that's the limit of $\\sqrt{n}(\\hat\\mu-\\mu,\\hat\\sigma^2-\\sigma^2)$

\n

This doesn't initially get you all that far further forward, because that distribution is ugly. You can now notice that for this specific asymptotic bivariate Normal problem the variables are orthogonal. The restricted MLE under the null is either $(0,\\hat\\sigma^2)$ or $(\\hat\\mu,1)$, depending on which is closer to $\\hat\\theta$. That means the log likelihood ratio is the minimum of two independent scaled $\\chi^2_1$

\n

Specifically, we should get the minimum of two $\\chi^2_1$s. The red line shows this CDF on your plot.

\n

\"enter

\n

For the more general case you have a limiting bivariate Normal problem with non-diagonal variance. It's still true that you just work out the distance to the restricted MLE, but that's the closest point in a non-rectangular norm. The geometry is not the same in all the orthants. Also, the restricted MLE can be at the equivalent of $(0,1)$ with non-zero probability, so there's a $\\chi^2_0$ component to the mixture. I think you end up with five components in total for two parameters.

\n

With more than two parameters taking part, everything is exactly the same only incomparably worse: the geometry of the closest point in the null hypothesis just gets more and more complicated, with more and more components. But the idea is the same: the LRT is asymptotically the LRT for a single-observation local Gaussian shift problem. This is, in some sense, why Wald's Theorem works and why Chernoff's result for boundary problems works and lots of other things.

\n", "answer_id": 676849, "answer_text": "It is still true that the asymptotic null distribution of the LRT is the null distribution of a local Gaussian shift alternative. In your $N(\\mu,\\sigma^2)$ example that means the asymptotic null distribution is the same as testing $\\mu=0$ or $\\sigma^2=1$ for the bivariate Normal distribution that's the limit of $\\sqrt{n}(\\hat\\mu-\\mu,\\hat\\sigma^2-\\sigma^2)$\n\n\n\n\nThis doesn't initially get you all that far further forward, because that distribution is ugly. You can now notice that for this specific asymptotic bivariate Normal problem the variables are orthogonal. The restricted MLE under the null is either $(0,\\hat\\sigma^2)$ or $(\\hat\\mu,1)$, depending on which is closer to $\\hat\\theta$. That means the log likelihood ratio is the minimum of two independent scaled $\\chi^2_1$\n\n\n\n\nSpecifically, we should get the minimum of two $\\chi^2_1$s. The red line shows this CDF on your plot.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/Qsmelzjn.png] (https://i.sstatic.net/Qsmelzjn.png)\n\n\n\n\nFor the more general case you have a limiting bivariate Normal problem with non-diagonal variance. It's still true that you just work out the distance to the restricted MLE, but that's the closest point in a non-rectangular norm. The geometry is not the same in all the orthants. Also, the restricted MLE can be at the equivalent of $(0,1)$ with non-zero probability, so there's a $\\chi^2_0$ component to the mixture. I think you end up with five components in total for two parameters.\n\n\n\n\nWith more than two parameters taking part, everything is exactly the same only incomparably worse: the geometry of the closest point in the null hypothesis just gets more and more complicated, with more and more components. But the idea is the same: the LRT is asymptotically the LRT for a single-observation local Gaussian shift problem. This is, in some sense, why Wald's Theorem works and why Chernoff's result for boundary problems works and lots of other things.", "answer_url": "https://stats.stackexchange.com/a/676849", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-12T03:14:18+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": 676842, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-12T03:14:18+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "EF5747F6-4B6A-42A4-8968-9F80C87019F6", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EF5747F6-4B6A-42A4-8968-9F80C87019F6/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-12T03:21:16+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "A9820920-337C-4445-864A-E2CE6845065B", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A9820920-337C-4445-864A-E2CE6845065B/view-source"}], "score": 4, "updated_at": "2026-08-12T03:21:16+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 676849, "answers": [{"answer_html": "

It is still true that the asymptotic null distribution of the LRT is the null distribution of a local Gaussian shift alternative. In your $N(\\mu,\\sigma^2)$ example that means the asymptotic null distribution is the same as testing $\\mu=0$ or $\\sigma^2=1$ for the bivariate Normal distribution that's the limit of $\\sqrt{n}(\\hat\\mu-\\mu,\\hat\\sigma^2-\\sigma^2)$

\n

This doesn't initially get you all that far further forward, because that distribution is ugly. You can now notice that for this specific asymptotic bivariate Normal problem the variables are orthogonal. The restricted MLE under the null is either $(0,\\hat\\sigma^2)$ or $(\\hat\\mu,1)$, depending on which is closer to $\\hat\\theta$. That means the log likelihood ratio is the minimum of two independent scaled $\\chi^2_1$

\n

Specifically, we should get the minimum of two $\\chi^2_1$s. The red line shows this CDF on your plot.

\n

\"enter

\n

For the more general case you have a limiting bivariate Normal problem with non-diagonal variance. It's still true that you just work out the distance to the restricted MLE, but that's the closest point in a non-rectangular norm. The geometry is not the same in all the orthants. Also, the restricted MLE can be at the equivalent of $(0,1)$ with non-zero probability, so there's a $\\chi^2_0$ component to the mixture. I think you end up with five components in total for two parameters.

\n

With more than two parameters taking part, everything is exactly the same only incomparably worse: the geometry of the closest point in the null hypothesis just gets more and more complicated, with more and more components. But the idea is the same: the LRT is asymptotically the LRT for a single-observation local Gaussian shift problem. This is, in some sense, why Wald's Theorem works and why Chernoff's result for boundary problems works and lots of other things.

\n", "answer_id": 676849, "answer_text": "It is still true that the asymptotic null distribution of the LRT is the null distribution of a local Gaussian shift alternative. In your $N(\\mu,\\sigma^2)$ example that means the asymptotic null distribution is the same as testing $\\mu=0$ or $\\sigma^2=1$ for the bivariate Normal distribution that's the limit of $\\sqrt{n}(\\hat\\mu-\\mu,\\hat\\sigma^2-\\sigma^2)$\n\n\n\n\nThis doesn't initially get you all that far further forward, because that distribution is ugly. You can now notice that for this specific asymptotic bivariate Normal problem the variables are orthogonal. The restricted MLE under the null is either $(0,\\hat\\sigma^2)$ or $(\\hat\\mu,1)$, depending on which is closer to $\\hat\\theta$. That means the log likelihood ratio is the minimum of two independent scaled $\\chi^2_1$\n\n\n\n\nSpecifically, we should get the minimum of two $\\chi^2_1$s. The red line shows this CDF on your plot.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/Qsmelzjn.png] (https://i.sstatic.net/Qsmelzjn.png)\n\n\n\n\nFor the more general case you have a limiting bivariate Normal problem with non-diagonal variance. It's still true that you just work out the distance to the restricted MLE, but that's the closest point in a non-rectangular norm. The geometry is not the same in all the orthants. Also, the restricted MLE can be at the equivalent of $(0,1)$ with non-zero probability, so there's a $\\chi^2_0$ component to the mixture. I think you end up with five components in total for two parameters.\n\n\n\n\nWith more than two parameters taking part, everything is exactly the same only incomparably worse: the geometry of the closest point in the null hypothesis just gets more and more complicated, with more and more components. But the idea is the same: the LRT is asymptotically the LRT for a single-observation local Gaussian shift problem. This is, in some sense, why Wald's Theorem works and why Chernoff's result for boundary problems works and lots of other things.", "answer_url": "https://stats.stackexchange.com/a/676849", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-12T03:14:18+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": 676842, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-12T03:14:18+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "EF5747F6-4B6A-42A4-8968-9F80C87019F6", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EF5747F6-4B6A-42A4-8968-9F80C87019F6/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-12T03:21:16+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "A9820920-337C-4445-864A-E2CE6845065B", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A9820920-337C-4445-864A-E2CE6845065B/view-source"}], "score": 4, "updated_at": "2026-08-12T03:21:16+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/Qsmelzjn.png", "https://i.sstatic.net/cWv54DMg.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": "Asigan", "question_author_url": "https://stats.stackexchange.com/users/499652/asigan", "question_author_user_type": "registered", "question_created_at": "2026-08-11T15:31:10+00:00", "question_html": "

In fact I doubt if such kind of hypothesis test will be used in real work, but just out of curiosity I have a question on the property of such test.

\n

Question. Consider an $n$-dimensional parameter $\\theta= (\\theta_1, \\cdots, \\theta_n)\\in \\Theta$ where $\\Theta$ is an open subset in $\\mathbb R^n$, and the hypothesis\n$$ H_0: \\text{either }\\theta_1= c_1 \\text{ or }\\theta_2= c_2\\longleftrightarrow\nH_1:\\text{ otherwise},$$\nwhere $c_1, c_2$ are given constant.\nWhat is the asymptotic distribution of $-2 \\log\\lambda$ where $\\lambda$ is the likelihood ratio statistic, if the true model is $\\theta_1= c_1$ and $\\theta_2= c_2$?\n(Assuming all other conditions of Wilks's Theorem).

\n

For example, consider $X_1,\\cdots, X_n$ are i.i.d. samples from $N(\\mu, \\sigma^2)$,\nand test if $H_0: \\text{either }\\mu=0 \\text{ or }\\sigma^2= 1$ holds.\nThen the maximum likelihood estimation is the one in $(\\mu, \\sigma^2)= (0, \\sqrt{\\frac{1}{n}\\sum_{i=1}^n X_i^2} )$ and $(\\mu, \\sigma^2)= (\\frac 1n\\sum_{i=1}^n X_i, 1)$\nwhich has a larger likelihood, and from this we can compute the LR statistic $\\lambda$.

\n

If, say, the model is generated under true parameter $\\mu= 1, \\sigma^2= 1$, then\nthe simulating data shows that the empirical cdf of $-2\\log\\lambda$\nand $\\chi^2_1$ are very close, which seems to suggest that $-2\\log\\lambda\\to_d\\chi^2_1$,\nand this is in fact the case, as, when the sample size tends to infinity, the probability that the MLE under $H_0$ is $(\\mu, \\sigma^2)= (\\frac 1n\\sum_{i=1}^n X_i, 1)$ (which corresponds to the true parameter) will tend to $1$, so the LR statistic is the same as testing $H_0: \\sigma^2= 1$ which probability tending to $1$.

\n

However, if the true parameter is $(\\mu, \\sigma^2)= (0, 1)$, then the empirical cdf of $-2\\log\\lambda$ is no longer close to $\\chi^2_1$, as the figure below shows.

\n

My question is, does $-2\\log\\lambda$ has a general asymptotic distribution in such case?

\n
\n

\"\"

\n
# R code for simulation\n\nnsim=1000 # number of simulation\nnsample= 20000 # number of sample\n\nN= nsample\nT= rep(0, nsim)\n\nfor(i in 1: nsim){\n    x= rnorm(mean=0, sd=1, n=N)\n    muhat= mean(x)\n    sigmahat= sqrt(mean((x- muhat)^2))\n    ll_mu_in_H0 = sum(dnorm(x, mean = 0, sd = sqrt(mean(x^2)), log = TRUE))\n    ll_sigma_in_H0= sum(dnorm(x, mean = muhat, sd = 1, log = TRUE))\n    llr= max(ll_mu_in_H0, ll_sigma_in_H0)- sum(dnorm(x, mean = muhat, sd = sigmahat, log = TRUE))\n    T[i]= -2*llr\n}\n\npar(mar=c(5,4,4,12), xpd=TRUE)\nplot(sort(T), (1:nsim)/nsim, type='l', lty=2, xlab= 'x', ylab= 'CDF')\nlines(qchisq(p= (1:nsim)/nsim, df= 1, ncp = 0, lower.tail = TRUE, log.p = FALSE), (1:nsim)/nsim, lty=1)\nlegend("topright",inset= c(-0.5,0), lty= c(2,1), legend= c('empirical', 'chi^2 with df=1'))\n
\n", "question_id": 676842, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "In fact I doubt if such kind of hypothesis test will be used in real work, but just out of curiosity I have a question on the property of such test.\n\n\n\n\nQuestion. Consider an $n$-dimensional parameter $\\theta= (\\theta_1, \\cdots, \\theta_n)\\in \\Theta$ where $\\Theta$ is an open subset in $\\mathbb R^n$, and the hypothesis\n$$ H_0: \\text{either }\\theta_1= c_1 \\text{ or }\\theta_2= c_2\\longleftrightarrow\nH_1:\\text{ otherwise},$$\nwhere $c_1, c_2$ are given constant.\nWhat is the asymptotic distribution of $-2 \\log\\lambda$ where $\\lambda$ is the likelihood ratio statistic, if the true model is $\\theta_1= c_1$ and $\\theta_2= c_2$?\n(Assuming all other conditions of Wilks's Theorem).\n\n\n\n\nFor example, consider $X_1,\\cdots, X_n$ are i.i.d. samples from $N(\\mu, \\sigma^2)$,\nand test if $H_0: \\text{either }\\mu=0 \\text{ or }\\sigma^2= 1$ holds.\nThen the maximum likelihood estimation is the one in $(\\mu, \\sigma^2)= (0, \\sqrt{\\frac{1}{n}\\sum_{i=1}^n X_i^2} )$ and $(\\mu, \\sigma^2)= (\\frac 1n\\sum_{i=1}^n X_i, 1)$\nwhich has a larger likelihood, and from this we can compute the LR statistic $\\lambda$.\n\n\n\n\nIf, say, the model is generated under true parameter $\\mu= 1, \\sigma^2= 1$, then\nthe simulating data shows that the empirical cdf of $-2\\log\\lambda$\nand $\\chi^2_1$ are very close, which seems to suggest that $-2\\log\\lambda\\to_d\\chi^2_1$,\nand this is in fact the case, as, when the sample size tends to infinity, the probability that the MLE under $H_0$ is $(\\mu, \\sigma^2)= (\\frac 1n\\sum_{i=1}^n X_i, 1)$ (which corresponds to the true parameter) will tend to $1$, so the LR statistic is the same as testing $H_0: \\sigma^2= 1$ which probability tending to $1$.\n\n\n\n\nHowever, if the true parameter is $(\\mu, \\sigma^2)= (0, 1)$, then the empirical cdf of $-2\\log\\lambda$ is no longer close to $\\chi^2_1$, as the figure below shows.\n\n\n\n\nMy question is, does $-2\\log\\lambda$ has a general asymptotic distribution in such case?\n\n\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/cWv54DMg.png] (https://i.sstatic.net/cWv54DMg.png)\n\n\n\n\n# R code for simulation\n\nnsim=1000 # number of simulation\nnsample= 20000 # number of sample\n\nN= nsample\nT= rep(0, nsim)\n\nfor(i in 1: nsim){\n x= rnorm(mean=0, sd=1, n=N)\n muhat= mean(x)\n sigmahat= sqrt(mean((x- muhat)^2))\n ll_mu_in_H0 = sum(dnorm(x, mean = 0, sd = sqrt(mean(x^2)), log = TRUE))\n ll_sigma_in_H0= sum(dnorm(x, mean = muhat, sd = 1, log = TRUE))\n llr= max(ll_mu_in_H0, ll_sigma_in_H0)- sum(dnorm(x, mean = muhat, sd = sigmahat, log = TRUE))\n T[i]= -2*llr\n}\n\npar(mar=c(5,4,4,12), xpd=TRUE)\nplot(sort(T), (1:nsim)/nsim, type='l', lty=2, xlab= 'x', ylab= 'CDF')\nlines(qchisq(p= (1:nsim)/nsim, df= 1, ncp = 0, lower.tail = TRUE, log.p = FALSE), (1:nsim)/nsim, lty=1)\nlegend(\"topright\",inset= c(-0.5,0), lty= c(2,1), legend= c('empirical', 'chi^2 with df=1'))", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Asigan", "profile_url": "https://stats.stackexchange.com/users/499652/asigan", "user_type": "registered"}, "created_at": "2026-08-11T15:31:10+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "12CBC237-71E5-4C7A-8DB4-C9CB01074B9D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/12CBC237-71E5-4C7A-8DB4-C9CB01074B9D/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-12T01:24:32+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "C0DDD5BE-21BF-4736-ABCF-642B92C21EDA", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C0DDD5BE-21BF-4736-ABCF-642B92C21EDA/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-12T04:37:20+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "03306B28-DD9D-42D1-990F-0DBB141FA2C2", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/03306B28-DD9D-42D1-990F-0DBB141FA2C2/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676842/the-asymptotic-distribution-of-likelihood-ratio-statistic-when-the-null-hypothes", "split": "train", "split_group": "04f52474e604252adf534b05534d06a31a2b2b196a4a54978ab75b8b8a135d5c", "tags": ["mathematical-statistics", "likelihood-ratio"], "thread_id": "stats:676842", "title": "The asymptotic distribution of likelihood ratio statistic when the null hypothesis is described by an \"or\" condition"}} +{"accepted_answer": {"answer_html": "

The scale parameter is routinely analysed in survival models, because the scale parameter is a location parameter for $\\log T$. Accelerated-failure models are of the form\n$$\\log T_i=x_t\\beta+\\log T_{0i}$$\nwhere $T_{0i}$ is a Weibull with some fixed scale and shape parameters.

\n

Similar models are used for other models with scale parameters, such as the log-Normal and Gamma.

\n

I don't know of a use for regression on the shape parameter, but I could certainly see someone being interested in testing whether $\\gamma-1$ is zero vs positive or negative as @Glen_b suggests.

\n", "answer_id": 676856, "answer_text": "The scale parameter is routinely analysed in survival models, because the scale parameter is a location parameter for $\\log T$. Accelerated-failure models are of the form\n$$\\log T_i=x_t\\beta+\\log T_{0i}$$\nwhere $T_{0i}$ is a Weibull with some fixed scale and shape parameters.\n\n\n\n\nSimilar models are used for other models with scale parameters, such as the log-Normal and Gamma.\n\n\n\n\nI don't know of a use for regression on the shape parameter, but I could certainly see someone being interested in testing whether $\\gamma-1$ is zero vs positive or negative as @Glen_b suggests.", "answer_url": "https://stats.stackexchange.com/a/676856", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-13T06:33:27+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": 676855, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-13T06:33:27+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "AB5891E4-C878-4F21-8C87-14A3C04B1146", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AB5891E4-C878-4F21-8C87-14A3C04B1146/view-source"}], "score": 8, "updated_at": "2026-08-13T06:33:27+00:00"}, "other_answers": [{"answer_html": "

To see more about the basis for Thomas Lumley's answer, look at these course notes by Germán Rodríguez. They start with the general form for accelerated-failure-time (AFT) models* in Prof. Lumley's answer, and show how that form can be used to understand how covariates enter into several families of survival models.

\n

In general, for an AFT model with no covariates, survival time $T$ can be modeled as:

\n

$$ \\log T \\sim \\alpha + \\sigma W,$$

\n

where $W$ is some standard probability distribution, $\\alpha$ is typically called the location parameter, and $\\sigma$ the scale parameter.

\n

For a Weibull model, $W$ is a standard minimum extreme value distribution. That leaves the question of how your Weibull "shape/scale" parameters correspond to $\\alpha$ and $\\sigma$.

\n

I still get confused by the multiple parameterizations of the Weibull distribution. Yours is the first optional parameterization in Wikipedia. The Rodríguez notes linked above use a form similar to Wikipedia's "Standard parameterization," but with a "$\\lambda$" the inverse of Wikipedia's choice of "scale parameter" $\\lambda$. The "$\\lambda$" in your parameterization would be $\\lambda^{-k}$ in the Wikipedia standard paramterization (where the shape parameter $k$ corresponds to your $\\gamma$).

\n

Even in R, the rweibull() function uses Wikipedia's standard parameterization while the survreg() function uses the form shown for the general AFT model above, based on $W$ distributed as minimum extreme value with a completely different use of the word "scale." The survreg() help page explains:

\n
\n

There are multiple ways to parameterize a Weibull distribution. The survreg function embeds it in a general location-scale family, which is a different parameterization than the rweibull function, and often leads to confusion.

\n

survreg's scale [$\\sigma$ in general AFT form above] = 1/(rweibull shape)

\n

survreg's intercept [$\\alpha$ in general AFT form] = log(rweibull scale).

\n
\n

In the above general AFT form without covariates in the Wikipedia/rweibull() standard parameterization of the "scale parameter" $\\lambda$, $\\alpha = \\log \\lambda$. As noted above, that's different from your "scale parameter" $\\lambda$.

\n

In the general AFT form above, covariates $x$ for regression with coefficients $\\beta$ (including an intercept) are incorporated as:

\n

$$ \\log T \\sim x'\\beta + \\sigma W$$

\n

with the intercept $\\beta_0$ representing the distribution of survival times when covariates are at their baseline values.

\n

As Prof. Lumley said, it's hard to think of a situation where you would model $\\sigma$ (inverse of Weibull shape) as a function of covariates, but it's possible for example with the R flexsurv package.

\n

To summarize:

\n

There can be interest in whether (and in what direction) the Weibull shape parameter differs "significantly" from 1 (log scale different from 0), but it's not typically modeled as a function of covariates.

\n

The different uses of "scale parameter" for Weibull make it impossible to make general statements about its "significance." As it's necessarily positive you'd might be interested in whether log(scale) (other than in the survreg() meaning) differs from 0, but what that means would differ among parameterizations.

\n

What does matter is whether covariates "significantly" affect the distribution of survival times, which typically are modeled as shown above. You can think about those as covariate-associated changes in the "scale" (in your or the Wikipedia standard parameterization).

\n
\n

*Unlike other distributions, Weibull can be modeled either as PH or AFT.

\n", "answer_id": 676861, "answer_text": "To see more about the basis for Thomas Lumley's answer, look at these course notes (https://grodri.github.io/survival/ParametricSurvival.pdf) by Germán Rodríguez. They start with the general form for accelerated-failure-time (AFT) models* in Prof. Lumley's answer, and show how that form can be used to understand how covariates enter into several families of survival models.\n\n\n\n\nIn general, for an AFT model with no covariates, survival time $T$ can be modeled as:\n\n\n\n\n$$ \\log T \\sim \\alpha + \\sigma W,$$\n\n\n\n\nwhere $W$ is some standard probability distribution, $\\alpha$ is typically called the location parameter, and $\\sigma$ the scale parameter.\n\n\n\n\nFor a Weibull model, $W$ is a standard minimum extreme value distribution. That leaves the question of how your Weibull \"shape/scale\" parameters correspond to $\\alpha$ and $\\sigma$.\n\n\n\n\nI still get confused by the multiple parameterizations of the Weibull distribution (https://stats.stackexchange.com/a/468333/28500). Yours is the first optional parameterization (https://en.wikipedia.org/wiki/Weibull_distribution#First_option) in Wikipedia. The Rodríguez notes linked above use a form similar to Wikipedia's \"Standard parameterization,\" (https://en.wikipedia.org/wiki/Weibull_distribution#Standard_parameterization) but with a \"$\\lambda$\" the inverse of Wikipedia's choice of \"scale parameter\" $\\lambda$. The \"$\\lambda$\" in your parameterization would be $\\lambda^{-k}$ in the Wikipedia standard paramterization (where the shape parameter $k$ corresponds to your $\\gamma$).\n\n\n\n\nEven in R, the rweibull() function uses Wikipedia's standard parameterization while the survreg() function uses the form shown for the general AFT model above, based on $W$ distributed as minimum extreme value with a completely different use of the word \"scale.\" The survreg() help page explains:\n\n\n\n\n\n\n\nThere are multiple ways to parameterize a Weibull distribution. The survreg function embeds it in a general location-scale family, which is a different parameterization than the rweibull function, and often leads to confusion.\n\n\n\n\nsurvreg's scale [$\\sigma$ in general AFT form above] = 1/(rweibull shape)\n\n\n\n\nsurvreg's intercept [$\\alpha$ in general AFT form] = log(rweibull scale).\n\n\n\n\n\n\n\nIn the above general AFT form without covariates in the Wikipedia/rweibull() standard parameterization of the \"scale parameter\" $\\lambda$, $\\alpha = \\log \\lambda$. As noted above, that's different from your \"scale parameter\" $\\lambda$.\n\n\n\n\nIn the general AFT form above, covariates $x$ for regression with coefficients $\\beta$ (including an intercept) are incorporated as:\n\n\n\n\n$$ \\log T \\sim x'\\beta + \\sigma W$$\n\n\n\n\nwith the intercept $\\beta_0$ representing the distribution of survival times when covariates are at their baseline values.\n\n\n\n\nAs Prof. Lumley said, it's hard to think of a situation where you would model $\\sigma$ (inverse of Weibull shape) as a function of covariates, but it's possible for example with the R flexsurv package (https://cran.r-project.org/package=flexsurv).\n\n\n\n\nTo summarize:\n\n\n\n\nThere can be interest in whether (and in what direction) the Weibull shape parameter differs \"significantly\" from 1 (log scale different from 0), but it's not typically modeled as a function of covariates.\n\n\n\n\nThe different uses of \"scale parameter\" for Weibull make it impossible to make general statements about its \"significance.\" As it's necessarily positive you'd might be interested in whether log(scale) (other than in the survreg() meaning) differs from 0, but what that means would differ among parameterizations.\n\n\n\n\nWhat does matter is whether covariates \"significantly\" affect the distribution of survival times, which typically are modeled as shown above. You can think about those as covariate-associated changes in the \"scale\" (in your or the Wikipedia standard parameterization).\n\n\n\n\n\n\n\n*Unlike other distributions, Weibull can be modeled either as PH or AFT.", "answer_url": "https://stats.stackexchange.com/a/676861", "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-13T20:23:55+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": 676855, "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-13T20:23:55+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "14C5622E-FF4B-4355-AE84-6E6E7028D63D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/14C5622E-FF4B-4355-AE84-6E6E7028D63D/view-source"}], "score": 4, "updated_at": "2026-08-13T20:23:55+00:00"}], "product": "statistics_qa", "question": "Here is a Weibull proportional hazards model:\n\n\n\n\n$$h(t \\mid \\mathbf{x}) = h_0(t)\\,\\exp(\\boldsymbol{\\beta}^\\top \\mathbf{x}) = \\gamma \\lambda\\, t^{\\gamma - 1} \\exp(\\boldsymbol{\\beta}^\\top \\mathbf{x})$$\n\n\n\n\nIs statistical inference ever performed on the shape and scale parameters ($\\gamma, \\lambda $)? For example, do researchers ever comment on whether the estimates of the shape and scale parameters are statistically significant? Or what about determining the influence an extra unit change in shape or scale would have on hazard and survival rates (marginal effects)?", "record_id": "Scientific-Statistics-QA:stats:676855", "selected_answer": {"answer_html": "

The scale parameter is routinely analysed in survival models, because the scale parameter is a location parameter for $\\log T$. Accelerated-failure models are of the form\n$$\\log T_i=x_t\\beta+\\log T_{0i}$$\nwhere $T_{0i}$ is a Weibull with some fixed scale and shape parameters.

\n

Similar models are used for other models with scale parameters, such as the log-Normal and Gamma.

\n

I don't know of a use for regression on the shape parameter, but I could certainly see someone being interested in testing whether $\\gamma-1$ is zero vs positive or negative as @Glen_b suggests.

\n", "answer_id": 676856, "answer_text": "The scale parameter is routinely analysed in survival models, because the scale parameter is a location parameter for $\\log T$. Accelerated-failure models are of the form\n$$\\log T_i=x_t\\beta+\\log T_{0i}$$\nwhere $T_{0i}$ is a Weibull with some fixed scale and shape parameters.\n\n\n\n\nSimilar models are used for other models with scale parameters, such as the log-Normal and Gamma.\n\n\n\n\nI don't know of a use for regression on the shape parameter, but I could certainly see someone being interested in testing whether $\\gamma-1$ is zero vs positive or negative as @Glen_b suggests.", "answer_url": "https://stats.stackexchange.com/a/676856", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-13T06:33:27+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": 676855, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-13T06:33:27+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "AB5891E4-C878-4F21-8C87-14A3C04B1146", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AB5891E4-C878-4F21-8C87-14A3C04B1146/view-source"}], "score": 8, "updated_at": "2026-08-13T06:33:27+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 676856, "answers": [{"answer_html": "

The scale parameter is routinely analysed in survival models, because the scale parameter is a location parameter for $\\log T$. Accelerated-failure models are of the form\n$$\\log T_i=x_t\\beta+\\log T_{0i}$$\nwhere $T_{0i}$ is a Weibull with some fixed scale and shape parameters.

\n

Similar models are used for other models with scale parameters, such as the log-Normal and Gamma.

\n

I don't know of a use for regression on the shape parameter, but I could certainly see someone being interested in testing whether $\\gamma-1$ is zero vs positive or negative as @Glen_b suggests.

\n", "answer_id": 676856, "answer_text": "The scale parameter is routinely analysed in survival models, because the scale parameter is a location parameter for $\\log T$. Accelerated-failure models are of the form\n$$\\log T_i=x_t\\beta+\\log T_{0i}$$\nwhere $T_{0i}$ is a Weibull with some fixed scale and shape parameters.\n\n\n\n\nSimilar models are used for other models with scale parameters, such as the log-Normal and Gamma.\n\n\n\n\nI don't know of a use for regression on the shape parameter, but I could certainly see someone being interested in testing whether $\\gamma-1$ is zero vs positive or negative as @Glen_b suggests.", "answer_url": "https://stats.stackexchange.com/a/676856", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-13T06:33:27+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": 676855, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-13T06:33:27+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "AB5891E4-C878-4F21-8C87-14A3C04B1146", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AB5891E4-C878-4F21-8C87-14A3C04B1146/view-source"}], "score": 8, "updated_at": "2026-08-13T06:33:27+00:00"}, {"answer_html": "

To see more about the basis for Thomas Lumley's answer, look at these course notes by Germán Rodríguez. They start with the general form for accelerated-failure-time (AFT) models* in Prof. Lumley's answer, and show how that form can be used to understand how covariates enter into several families of survival models.

\n

In general, for an AFT model with no covariates, survival time $T$ can be modeled as:

\n

$$ \\log T \\sim \\alpha + \\sigma W,$$

\n

where $W$ is some standard probability distribution, $\\alpha$ is typically called the location parameter, and $\\sigma$ the scale parameter.

\n

For a Weibull model, $W$ is a standard minimum extreme value distribution. That leaves the question of how your Weibull "shape/scale" parameters correspond to $\\alpha$ and $\\sigma$.

\n

I still get confused by the multiple parameterizations of the Weibull distribution. Yours is the first optional parameterization in Wikipedia. The Rodríguez notes linked above use a form similar to Wikipedia's "Standard parameterization," but with a "$\\lambda$" the inverse of Wikipedia's choice of "scale parameter" $\\lambda$. The "$\\lambda$" in your parameterization would be $\\lambda^{-k}$ in the Wikipedia standard paramterization (where the shape parameter $k$ corresponds to your $\\gamma$).

\n

Even in R, the rweibull() function uses Wikipedia's standard parameterization while the survreg() function uses the form shown for the general AFT model above, based on $W$ distributed as minimum extreme value with a completely different use of the word "scale." The survreg() help page explains:

\n
\n

There are multiple ways to parameterize a Weibull distribution. The survreg function embeds it in a general location-scale family, which is a different parameterization than the rweibull function, and often leads to confusion.

\n

survreg's scale [$\\sigma$ in general AFT form above] = 1/(rweibull shape)

\n

survreg's intercept [$\\alpha$ in general AFT form] = log(rweibull scale).

\n
\n

In the above general AFT form without covariates in the Wikipedia/rweibull() standard parameterization of the "scale parameter" $\\lambda$, $\\alpha = \\log \\lambda$. As noted above, that's different from your "scale parameter" $\\lambda$.

\n

In the general AFT form above, covariates $x$ for regression with coefficients $\\beta$ (including an intercept) are incorporated as:

\n

$$ \\log T \\sim x'\\beta + \\sigma W$$

\n

with the intercept $\\beta_0$ representing the distribution of survival times when covariates are at their baseline values.

\n

As Prof. Lumley said, it's hard to think of a situation where you would model $\\sigma$ (inverse of Weibull shape) as a function of covariates, but it's possible for example with the R flexsurv package.

\n

To summarize:

\n

There can be interest in whether (and in what direction) the Weibull shape parameter differs "significantly" from 1 (log scale different from 0), but it's not typically modeled as a function of covariates.

\n

The different uses of "scale parameter" for Weibull make it impossible to make general statements about its "significance." As it's necessarily positive you'd might be interested in whether log(scale) (other than in the survreg() meaning) differs from 0, but what that means would differ among parameterizations.

\n

What does matter is whether covariates "significantly" affect the distribution of survival times, which typically are modeled as shown above. You can think about those as covariate-associated changes in the "scale" (in your or the Wikipedia standard parameterization).

\n
\n

*Unlike other distributions, Weibull can be modeled either as PH or AFT.

\n", "answer_id": 676861, "answer_text": "To see more about the basis for Thomas Lumley's answer, look at these course notes (https://grodri.github.io/survival/ParametricSurvival.pdf) by Germán Rodríguez. They start with the general form for accelerated-failure-time (AFT) models* in Prof. Lumley's answer, and show how that form can be used to understand how covariates enter into several families of survival models.\n\n\n\n\nIn general, for an AFT model with no covariates, survival time $T$ can be modeled as:\n\n\n\n\n$$ \\log T \\sim \\alpha + \\sigma W,$$\n\n\n\n\nwhere $W$ is some standard probability distribution, $\\alpha$ is typically called the location parameter, and $\\sigma$ the scale parameter.\n\n\n\n\nFor a Weibull model, $W$ is a standard minimum extreme value distribution. That leaves the question of how your Weibull \"shape/scale\" parameters correspond to $\\alpha$ and $\\sigma$.\n\n\n\n\nI still get confused by the multiple parameterizations of the Weibull distribution (https://stats.stackexchange.com/a/468333/28500). Yours is the first optional parameterization (https://en.wikipedia.org/wiki/Weibull_distribution#First_option) in Wikipedia. The Rodríguez notes linked above use a form similar to Wikipedia's \"Standard parameterization,\" (https://en.wikipedia.org/wiki/Weibull_distribution#Standard_parameterization) but with a \"$\\lambda$\" the inverse of Wikipedia's choice of \"scale parameter\" $\\lambda$. The \"$\\lambda$\" in your parameterization would be $\\lambda^{-k}$ in the Wikipedia standard paramterization (where the shape parameter $k$ corresponds to your $\\gamma$).\n\n\n\n\nEven in R, the rweibull() function uses Wikipedia's standard parameterization while the survreg() function uses the form shown for the general AFT model above, based on $W$ distributed as minimum extreme value with a completely different use of the word \"scale.\" The survreg() help page explains:\n\n\n\n\n\n\n\nThere are multiple ways to parameterize a Weibull distribution. The survreg function embeds it in a general location-scale family, which is a different parameterization than the rweibull function, and often leads to confusion.\n\n\n\n\nsurvreg's scale [$\\sigma$ in general AFT form above] = 1/(rweibull shape)\n\n\n\n\nsurvreg's intercept [$\\alpha$ in general AFT form] = log(rweibull scale).\n\n\n\n\n\n\n\nIn the above general AFT form without covariates in the Wikipedia/rweibull() standard parameterization of the \"scale parameter\" $\\lambda$, $\\alpha = \\log \\lambda$. As noted above, that's different from your \"scale parameter\" $\\lambda$.\n\n\n\n\nIn the general AFT form above, covariates $x$ for regression with coefficients $\\beta$ (including an intercept) are incorporated as:\n\n\n\n\n$$ \\log T \\sim x'\\beta + \\sigma W$$\n\n\n\n\nwith the intercept $\\beta_0$ representing the distribution of survival times when covariates are at their baseline values.\n\n\n\n\nAs Prof. Lumley said, it's hard to think of a situation where you would model $\\sigma$ (inverse of Weibull shape) as a function of covariates, but it's possible for example with the R flexsurv package (https://cran.r-project.org/package=flexsurv).\n\n\n\n\nTo summarize:\n\n\n\n\nThere can be interest in whether (and in what direction) the Weibull shape parameter differs \"significantly\" from 1 (log scale different from 0), but it's not typically modeled as a function of covariates.\n\n\n\n\nThe different uses of \"scale parameter\" for Weibull make it impossible to make general statements about its \"significance.\" As it's necessarily positive you'd might be interested in whether log(scale) (other than in the survreg() meaning) differs from 0, but what that means would differ among parameterizations.\n\n\n\n\nWhat does matter is whether covariates \"significantly\" affect the distribution of survival times, which typically are modeled as shown above. You can think about those as covariate-associated changes in the \"scale\" (in your or the Wikipedia standard parameterization).\n\n\n\n\n\n\n\n*Unlike other distributions, Weibull can be modeled either as PH or AFT.", "answer_url": "https://stats.stackexchange.com/a/676861", "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-13T20:23:55+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": 676855, "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-13T20:23:55+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "14C5622E-FF4B-4355-AE84-6E6E7028D63D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/14C5622E-FF4B-4355-AE84-6E6E7028D63D/view-source"}], "score": 4, "updated_at": "2026-08-13T20:23:55+00:00"}], "domain": "statistics", "external_links": ["https://cran.r-project.org/package=flexsurv", "https://en.wikipedia.org/wiki/Weibull_distribution#First_option", "https://en.wikipedia.org/wiki/Weibull_distribution#Standard_parameterization", "https://grodri.github.io/survival/ParametricSurvival.pdf"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "adamkostanov", "question_author_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "question_author_user_type": "registered", "question_created_at": "2026-08-13T02:10:03+00:00", "question_html": "

Here is a Weibull proportional hazards model:

\n

$$h(t \\mid \\mathbf{x}) = h_0(t)\\,\\exp(\\boldsymbol{\\beta}^\\top \\mathbf{x}) = \\gamma \\lambda\\, t^{\\gamma - 1} \\exp(\\boldsymbol{\\beta}^\\top \\mathbf{x})$$

\n

Is statistical inference ever performed on the shape and scale parameters ($\\gamma, \\lambda $)? For example, do researchers ever comment on whether the estimates of the shape and scale parameters are statistically significant? Or what about determining the influence an extra unit change in shape or scale would have on hazard and survival rates (marginal effects)?

\n", "question_id": 676855, "question_license": "CC BY-SA 4.0", "question_score": 6, "question_text": "Here is a Weibull proportional hazards model:\n\n\n\n\n$$h(t \\mid \\mathbf{x}) = h_0(t)\\,\\exp(\\boldsymbol{\\beta}^\\top \\mathbf{x}) = \\gamma \\lambda\\, t^{\\gamma - 1} \\exp(\\boldsymbol{\\beta}^\\top \\mathbf{x})$$\n\n\n\n\nIs statistical inference ever performed on the shape and scale parameters ($\\gamma, \\lambda $)? For example, do researchers ever comment on whether the estimates of the shape and scale parameters are statistically significant? Or what about determining the influence an extra unit change in shape or scale would have on hazard and survival rates (marginal effects)?", "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-13T02:10:03+00:00", "raw_file": "raw/codex_api_v1/4f74c7234d8d68222a97a637c85bc14d5aa045a3d3f336d95a6178b29bc656cd_1790825248437413600_0.json", "raw_sha256": "8385102f4bd0517d9240ab820144fa12ccb111d0c4dd000e66bdc0e0ba0294fe", "revision_guid": "B7D363AF-1F5D-4946-9B8F-2F6F418F7AA6", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B7D363AF-1F5D-4946-9B8F-2F6F418F7AA6/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-13T15:19:35+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "8DA1C57F-6FD3-463B-A666-4671DB101E02", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8DA1C57F-6FD3-463B-A666-4671DB101E02/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-13T20:38:59+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "207032C0-C318-48F8-8F5C-54C79997A86B", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/207032C0-C318-48F8-8F5C-54C79997A86B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-08-13T23:37:00+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "EF625F54-00CC-4666-AC48-280CD2EF0ACE", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EF625F54-00CC-4666-AC48-280CD2EF0ACE/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676855/do-the-shape-and-scale-parameters-have-statistical-interpretations", "split": "train", "split_group": "b21f26372276ef4da66c7b0ef2298fec9eb6475ec2b2c00bd011c6fac4d4b742", "tags": ["survival", "maximum-likelihood"], "thread_id": "stats:676855", "title": "Do the shape and scale parameters have statistical interpretations?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I am trying to evaluate which environmental variables drive variation in microbial communities. I have 5 samples collected at 15 sites, and for each sample, I have a microbial community, soil pH, soil NO3, and MAT.\n\n\n\n\nI wanted to account for site when testing the effect of my environmental variables, so I tried:\n\n\n\n\nlibrary(vegan)\n\ndbrda(Y ~ pH + NO3 + MAT + Condition(Site))\n\n\n\n\n\nbut because all samples at a site have the same MAT, the model does not evaluate MAT.\n\n\n\n\nHow can I test the effects of all of my environmental variables while accounting for site?", "record_id": "Scientific-Statistics-QA:stats:676858", "selected_answer": {"answer_html": "

There are two options for testing ordination models in vegan:

\n
    \n
  1. model-based permutations, and
  2. \n
  3. design-based
  4. \n
\n

In 1. you model the site effects (like you have) and you assume the residuals are no conditionally independent, so you can just randomise the data.

\n

In 2. you would fit you model (even without the Condition() bit, but I would advise you keep it in, and then you restrict the permutations to be within the levels of site.

\n

In both cases you would pass something to the anova() function. This gives you some options as "test the effect of my environmental variables" is not a well-defined things; do you mean to fit an omnibus test of the joint effects of the three terms in the model, or to test sequential or marginal effects of each individual term?

\n

If you want the omnibus test, essentially of the whole model, you would do:

\n
ord <- dbrda(Y ~ pH + NO3 + MAT + Condition(Site), data = my_df)\n\nset.seed(20260814)\nanova(ord)\n
\n

This would use complete randomisation (so it is a model-based test) of the amount of variation in the $d_{ij}$ dissimilarities in Y explained by the model containing pH, NO3, MAT after removing the between site differences (due to the Condition()).

\n

A restricted permutation for a design-based test would be

\n
ctrl <- with(\n  my_df,\n  how(\n    blocks = site\n  )\n)\n\nset.seed(20260814)\nanova(ord, permutations = ctrl)\n
\n

Or for marginal effects, where you get a test of adding say pH to a model with MAT + NO3, for each term in turn:

\n
set.seed(20260814)\nanova(ord, by = "margin")\n\nset.seed(20260814)\nanova(ord, by = "margin", permutations = ctrl)\n
\n

The entire problem in your data however is that MAT is confounded with site; there isn't a way to test MAT and account for site as mathematically MAT and site have the same representation in the model and hence have the same estimated effect (as long as you code MAT as a factor) in the model.

\n

Because you don't have replication of MAT within levels of site there isn't anything you can do that includes both variables.

\n

That said, including MAT in the model (if coded as a factor) will account for the crude between site differences in Y. So you can use the model-based route and just do:

\n
my_df <- my_df |>\n  transform(\n    fMAT = factor(MAT)\n  )\n\nord <- dbrda(Y ~ pH + NO3 + fMAT, data = my_df)\n\nset.seed(20260814)\nanova(ord, by "margin")\n
\n

The interpretation is complicated however; you can't claim that the estimated effect of MAT is due to MAT as it could be due to any differences between your sites, which may or may not include a temperature effect.

\n

This is where experimental design comes in; ideally a statistical analysis plan created before you collected the data would have identified the issue, allowing you to address these problem (where possible) or highlight hypotheses that cannot be tested given the chosen design.

\n", "answer_id": 676863, "answer_text": "There are two options for testing ordination models in vegan:\n\n\n\n\n\nmodel-based permutations, and\n\n\n\n\ndesign-based\n\n\n\n\n\nIn 1. you model the site effects (like you have) and you assume the residuals are no conditionally independent, so you can just randomise the data.\n\n\n\n\nIn 2. you would fit you model (even without the Condition() bit, but I would advise you keep it in, and then you restrict the permutations to be within the levels of site.\n\n\n\n\nIn both cases you would pass something to the anova() function. This gives you some options as \"test the effect of my environmental variables\" is not a well-defined things; do you mean to fit an omnibus test of the joint effects of the three terms in the model, or to test sequential or marginal effects of each individual term?\n\n\n\n\nIf you want the omnibus test, essentially of the whole model, you would do:\n\n\n\n\nord <- dbrda(Y ~ pH + NO3 + MAT + Condition(Site), data = my_df)\n\nset.seed(20260814)\nanova(ord)\n\n\n\n\n\nThis would use complete randomisation (so it is a model-based test) of the amount of variation in the $d_{ij}$ dissimilarities in Y explained by the model containing pH, NO3, MAT after removing the between site differences (due to the Condition()).\n\n\n\n\nA restricted permutation for a design-based test would be\n\n\n\n\nctrl <- with(\n my_df,\n how(\n blocks = site\n )\n)\n\nset.seed(20260814)\nanova(ord, permutations = ctrl)\n\n\n\n\n\nOr for marginal effects, where you get a test of adding say pH to a model with MAT + NO3, for each term in turn:\n\n\n\n\nset.seed(20260814)\nanova(ord, by = \"margin\")\n\nset.seed(20260814)\nanova(ord, by = \"margin\", permutations = ctrl)\n\n\n\n\n\nThe entire problem in your data however is that MAT is confounded with site; there isn't a way to test MAT and account for site as mathematically MAT and site have the same representation in the model and hence have the same estimated effect (as long as you code MAT as a factor) in the model.\n\n\n\n\nBecause you don't have replication of MAT within levels of site there isn't anything you can do that includes both variables.\n\n\n\n\nThat said, including MAT in the model (if coded as a factor) will account for the crude between site differences in Y. So you can use the model-based route and just do:\n\n\n\n\nmy_df <- my_df |>\n transform(\n fMAT = factor(MAT)\n )\n\nord <- dbrda(Y ~ pH + NO3 + fMAT, data = my_df)\n\nset.seed(20260814)\nanova(ord, by \"margin\")\n\n\n\n\n\nThe interpretation is complicated however; you can't claim that the estimated effect of MAT is due to MAT as it could be due to any differences between your sites, which may or may not include a temperature effect.\n\n\n\n\nThis is where experimental design comes in; ideally a statistical analysis plan created before you collected the data would have identified the issue, allowing you to address these problem (where possible) or highlight hypotheses that cannot be tested given the chosen design.", "answer_url": "https://stats.stackexchange.com/a/676863", "author": "Gavin Simpson", "author_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-14T06:11:59+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": 676858, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Gavin Simpson", "profile_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "user_type": "registered"}, "created_at": "2026-08-14T06:11:59+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "A07F8661-3C22-4FF1-B601-E3771400D740", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A07F8661-3C22-4FF1-B601-E3771400D740/view-source"}], "score": 2, "updated_at": "2026-08-14T06:11:59+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

There are two options for testing ordination models in vegan:

\n
    \n
  1. model-based permutations, and
  2. \n
  3. design-based
  4. \n
\n

In 1. you model the site effects (like you have) and you assume the residuals are no conditionally independent, so you can just randomise the data.

\n

In 2. you would fit you model (even without the Condition() bit, but I would advise you keep it in, and then you restrict the permutations to be within the levels of site.

\n

In both cases you would pass something to the anova() function. This gives you some options as "test the effect of my environmental variables" is not a well-defined things; do you mean to fit an omnibus test of the joint effects of the three terms in the model, or to test sequential or marginal effects of each individual term?

\n

If you want the omnibus test, essentially of the whole model, you would do:

\n
ord <- dbrda(Y ~ pH + NO3 + MAT + Condition(Site), data = my_df)\n\nset.seed(20260814)\nanova(ord)\n
\n

This would use complete randomisation (so it is a model-based test) of the amount of variation in the $d_{ij}$ dissimilarities in Y explained by the model containing pH, NO3, MAT after removing the between site differences (due to the Condition()).

\n

A restricted permutation for a design-based test would be

\n
ctrl <- with(\n  my_df,\n  how(\n    blocks = site\n  )\n)\n\nset.seed(20260814)\nanova(ord, permutations = ctrl)\n
\n

Or for marginal effects, where you get a test of adding say pH to a model with MAT + NO3, for each term in turn:

\n
set.seed(20260814)\nanova(ord, by = "margin")\n\nset.seed(20260814)\nanova(ord, by = "margin", permutations = ctrl)\n
\n

The entire problem in your data however is that MAT is confounded with site; there isn't a way to test MAT and account for site as mathematically MAT and site have the same representation in the model and hence have the same estimated effect (as long as you code MAT as a factor) in the model.

\n

Because you don't have replication of MAT within levels of site there isn't anything you can do that includes both variables.

\n

That said, including MAT in the model (if coded as a factor) will account for the crude between site differences in Y. So you can use the model-based route and just do:

\n
my_df <- my_df |>\n  transform(\n    fMAT = factor(MAT)\n  )\n\nord <- dbrda(Y ~ pH + NO3 + fMAT, data = my_df)\n\nset.seed(20260814)\nanova(ord, by "margin")\n
\n

The interpretation is complicated however; you can't claim that the estimated effect of MAT is due to MAT as it could be due to any differences between your sites, which may or may not include a temperature effect.

\n

This is where experimental design comes in; ideally a statistical analysis plan created before you collected the data would have identified the issue, allowing you to address these problem (where possible) or highlight hypotheses that cannot be tested given the chosen design.

\n", "answer_id": 676863, "answer_text": "There are two options for testing ordination models in vegan:\n\n\n\n\n\nmodel-based permutations, and\n\n\n\n\ndesign-based\n\n\n\n\n\nIn 1. you model the site effects (like you have) and you assume the residuals are no conditionally independent, so you can just randomise the data.\n\n\n\n\nIn 2. you would fit you model (even without the Condition() bit, but I would advise you keep it in, and then you restrict the permutations to be within the levels of site.\n\n\n\n\nIn both cases you would pass something to the anova() function. This gives you some options as \"test the effect of my environmental variables\" is not a well-defined things; do you mean to fit an omnibus test of the joint effects of the three terms in the model, or to test sequential or marginal effects of each individual term?\n\n\n\n\nIf you want the omnibus test, essentially of the whole model, you would do:\n\n\n\n\nord <- dbrda(Y ~ pH + NO3 + MAT + Condition(Site), data = my_df)\n\nset.seed(20260814)\nanova(ord)\n\n\n\n\n\nThis would use complete randomisation (so it is a model-based test) of the amount of variation in the $d_{ij}$ dissimilarities in Y explained by the model containing pH, NO3, MAT after removing the between site differences (due to the Condition()).\n\n\n\n\nA restricted permutation for a design-based test would be\n\n\n\n\nctrl <- with(\n my_df,\n how(\n blocks = site\n )\n)\n\nset.seed(20260814)\nanova(ord, permutations = ctrl)\n\n\n\n\n\nOr for marginal effects, where you get a test of adding say pH to a model with MAT + NO3, for each term in turn:\n\n\n\n\nset.seed(20260814)\nanova(ord, by = \"margin\")\n\nset.seed(20260814)\nanova(ord, by = \"margin\", permutations = ctrl)\n\n\n\n\n\nThe entire problem in your data however is that MAT is confounded with site; there isn't a way to test MAT and account for site as mathematically MAT and site have the same representation in the model and hence have the same estimated effect (as long as you code MAT as a factor) in the model.\n\n\n\n\nBecause you don't have replication of MAT within levels of site there isn't anything you can do that includes both variables.\n\n\n\n\nThat said, including MAT in the model (if coded as a factor) will account for the crude between site differences in Y. So you can use the model-based route and just do:\n\n\n\n\nmy_df <- my_df |>\n transform(\n fMAT = factor(MAT)\n )\n\nord <- dbrda(Y ~ pH + NO3 + fMAT, data = my_df)\n\nset.seed(20260814)\nanova(ord, by \"margin\")\n\n\n\n\n\nThe interpretation is complicated however; you can't claim that the estimated effect of MAT is due to MAT as it could be due to any differences between your sites, which may or may not include a temperature effect.\n\n\n\n\nThis is where experimental design comes in; ideally a statistical analysis plan created before you collected the data would have identified the issue, allowing you to address these problem (where possible) or highlight hypotheses that cannot be tested given the chosen design.", "answer_url": "https://stats.stackexchange.com/a/676863", "author": "Gavin Simpson", "author_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-14T06:11:59+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": 676858, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Gavin Simpson", "profile_url": "https://stats.stackexchange.com/users/1390/gavin-simpson", "user_type": "registered"}, "created_at": "2026-08-14T06:11:59+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "A07F8661-3C22-4FF1-B601-E3771400D740", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A07F8661-3C22-4FF1-B601-E3771400D740/view-source"}], "score": 2, "updated_at": "2026-08-14T06:11:59+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Tillandsia123", "question_author_url": "https://stats.stackexchange.com/users/489435/tillandsia123", "question_author_user_type": "registered", "question_created_at": "2026-08-13T14:13:45+00:00", "question_html": "

I am trying to evaluate which environmental variables drive variation in microbial communities. I have 5 samples collected at 15 sites, and for each sample, I have a microbial community, soil pH, soil NO3, and MAT.

\n

I wanted to account for site when testing the effect of my environmental variables, so I tried:

\n
library(vegan)\n\ndbrda(Y ~ pH + NO3 + MAT + Condition(Site))\n
\n

but because all samples at a site have the same MAT, the model does not evaluate MAT.

\n

How can I test the effects of all of my environmental variables while accounting for site?

\n", "question_id": 676858, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I am trying to evaluate which environmental variables drive variation in microbial communities. I have 5 samples collected at 15 sites, and for each sample, I have a microbial community, soil pH, soil NO3, and MAT.\n\n\n\n\nI wanted to account for site when testing the effect of my environmental variables, so I tried:\n\n\n\n\nlibrary(vegan)\n\ndbrda(Y ~ pH + NO3 + MAT + Condition(Site))\n\n\n\n\n\nbut because all samples at a site have the same MAT, the model does not evaluate MAT.\n\n\n\n\nHow can I test the effects of all of my environmental variables while accounting for site?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Tillandsia123", "profile_url": "https://stats.stackexchange.com/users/489435/tillandsia123", "user_type": "registered"}, "created_at": "2026-08-13T14:13:45+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "7B37CEAA-255C-414E-8A5C-901D88775172", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7B37CEAA-255C-414E-8A5C-901D88775172/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://stats.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2026-08-13T16:05:23+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "0B02F8B6-209E-470E-B9B3-ADE3ADB3F0F3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/0B02F8B6-209E-470E-B9B3-ADE3ADB3F0F3/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676858/how-do-i-account-for-site-in-a-dbrda-while-evaluating-the-effect-of-variables-th", "split": "train", "split_group": "b7a109258c68d4c0ad147c01da06f4600be94b148c00d9e8d67cbc16243ff6b8", "tags": ["r", "vegan", "redundancy-analysis"], "thread_id": "stats:676858", "title": "How do I account for site in a dbRDA while evaluating the effect of variables that are the same across all samples in a site?"}} +{"accepted_answer": {"answer_html": "

Your approach is perfectly reasonable. It is true that using a caliper changes the target estimand, but it does so only when the remaining matched sample has a different covariate distribution from the overall sample. With a caliper like the one you imposed, I would guess that the matched sample still resembles the overall population based on how few units were discarded.

\n

It's worth remembering also that the subgroups don't need to resemble each other for you to perform subgroup analysis or study moderation. However, you won't be able to conclude that it is the moderator itself that causes the difference in effect estimates (if there is one); any difference could simply be due to differences in the compositions of the subgroups, which may be further exacerbated by the imposition of the caliper.

\n

My advice would be first to try different methods of increasing the ESS, such as using the min.controls and max.controls arguments to prevent too many units assigned to one subclass. See an example below on the lalonde dataset, where using the max.controls option both improves balance and increases the ESS of the smaller group (which affects precision the most), and is a bit better than using a caliper:

\n
library(MatchIt); library(cobalt)\n\ndata("lalonde", package = "MatchIt")\n\n# Full matching\nM1 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n              data = lalonde, method = "full", estimand = "ATE", tol = 1e-7,\n              link = "linear.logit", exact = ~race)\n\n# Full matching with max.controls limited\nM2 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n              data = lalonde, method = "full", estimand = "ATE", tol = 1e-7,\n              link = "linear.logit", exact = ~race,\n              max.controls = 10)\n\n# Full matching with caliper on PS\nM3 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n              data = lalonde, method = "full", estimand = "ATE", tol = 1e-7,\n              link = "linear.logit", exact = ~race,\n              caliper = .1)\n\nbal.tab(M1, weights = list(max.c = M2, cal = M3))\n#> Balance Measures\n#>                 Type Diff.matchit Diff.max.c Diff.cal\n#> distance    Distance       0.0391     0.0300   0.0068\n#> age          Contin.      -0.1377     0.0318  -0.0370\n#> educ         Contin.       0.1166     0.0524   0.0335\n#> race_black    Binary      -0.0000     0.0000  -0.0000\n#> race_hispan   Binary      -0.0000     0.0000  -0.0000\n#> race_white    Binary      -0.0000     0.0000   0.0000\n#> married       Binary      -0.0061    -0.0026  -0.0129\n#> nodegree      Binary      -0.0878    -0.0569  -0.0815\n#> re74         Contin.      -0.3139    -0.1761  -0.2054\n#> re75         Contin.      -0.2884    -0.1247  -0.2248\n#> \n#> Effective sample sizes\n#>         Control Treated\n#> All      429.    185.  \n#> matchit  257.09   26.49\n#> max.c    156.88   86.58\n#> cal      210.74   43.47\n
\n

You can assess whether many units are assigned to the same subclass by using

\n
with(M1, table(treat, subclass))\n
\n

Doing this on M1 reveals that one subclass contains 89 control units and 1 treated unit, yielding more extreme weights: that treated unit receives a weight of 90. With M2, no more than 10 control units per treated unit are in each subclass, by definition, so no treated units receive a weight larger than 11. Decreasing the variability of the weights increases the ESS.

\n

In general, I would avoid calipers unless it's impossible to achieve balance without them. There are often enough ways to adjust a matching specification that you can achieve the properties of the matched sample you desire without resorting to a caliper. I would also recommend trying weighting methods before using a caliper unless your field looks down on weighting.

\n

If you do decide to use a caliper, see how relaxed of a caliper you can use to achieve your goals; a relaxed caliper will discard fewer units, making your results more generalizable to your population of interest. All that said, if your sample isn't a representative sample from a population, it doesn't matter whether the result generalize: your caliper matched sample is no less representative of a meaningful population than your original sample.

\n", "answer_id": 676905, "answer_text": "Your approach is perfectly reasonable. It is true that using a caliper changes the target estimand, but it does so only when the remaining matched sample has a different covariate distribution from the overall sample. With a caliper like the one you imposed, I would guess that the matched sample still resembles the overall population based on how few units were discarded.\n\n\n\n\nIt's worth remembering also that the subgroups don't need to resemble each other for you to perform subgroup analysis or study moderation. However, you won't be able to conclude that it is the moderator itself that causes the difference in effect estimates (if there is one); any difference could simply be due to differences in the compositions of the subgroups, which may be further exacerbated by the imposition of the caliper.\n\n\n\n\nMy advice would be first to try different methods of increasing the ESS, such as using the min.controls and max.controls arguments to prevent too many units assigned to one subclass. See an example below on the lalonde dataset, where using the max.controls option both improves balance and increases the ESS of the smaller group (which affects precision the most), and is a bit better than using a caliper:\n\n\n\n\nlibrary(MatchIt); library(cobalt)\n\ndata(\"lalonde\", package = \"MatchIt\")\n\n# Full matching\nM1 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n data = lalonde, method = \"full\", estimand = \"ATE\", tol = 1e-7,\n link = \"linear.logit\", exact = ~race)\n\n# Full matching with max.controls limited\nM2 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n data = lalonde, method = \"full\", estimand = \"ATE\", tol = 1e-7,\n link = \"linear.logit\", exact = ~race,\n max.controls = 10)\n\n# Full matching with caliper on PS\nM3 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n data = lalonde, method = \"full\", estimand = \"ATE\", tol = 1e-7,\n link = \"linear.logit\", exact = ~race,\n caliper = .1)\n\nbal.tab(M1, weights = list(max.c = M2, cal = M3))\n#> Balance Measures\n#> Type Diff.matchit Diff.max.c Diff.cal\n#> distance Distance 0.0391 0.0300 0.0068\n#> age Contin. -0.1377 0.0318 -0.0370\n#> educ Contin. 0.1166 0.0524 0.0335\n#> race_black Binary -0.0000 0.0000 -0.0000\n#> race_hispan Binary -0.0000 0.0000 -0.0000\n#> race_white Binary -0.0000 0.0000 0.0000\n#> married Binary -0.0061 -0.0026 -0.0129\n#> nodegree Binary -0.0878 -0.0569 -0.0815\n#> re74 Contin. -0.3139 -0.1761 -0.2054\n#> re75 Contin. -0.2884 -0.1247 -0.2248\n#> \n#> Effective sample sizes\n#> Control Treated\n#> All 429. 185. \n#> matchit 257.09 26.49\n#> max.c 156.88 86.58\n#> cal 210.74 43.47\n\n\n\n\n\nYou can assess whether many units are assigned to the same subclass by using\n\n\n\n\nwith(M1, table(treat, subclass))\n\n\n\n\n\nDoing this on M1 reveals that one subclass contains 89 control units and 1 treated unit, yielding more extreme weights: that treated unit receives a weight of 90. With M2, no more than 10 control units per treated unit are in each subclass, by definition, so no treated units receive a weight larger than 11. Decreasing the variability of the weights increases the ESS.\n\n\n\n\nIn general, I would avoid calipers unless it's impossible to achieve balance without them. There are often enough ways to adjust a matching specification that you can achieve the properties of the matched sample you desire without resorting to a caliper. I would also recommend trying weighting methods before using a caliper unless your field looks down on weighting.\n\n\n\n\nIf you do decide to use a caliper, see how relaxed of a caliper you can use to achieve your goals; a relaxed caliper will discard fewer units, making your results more generalizable to your population of interest. All that said, if your sample isn't a representative sample from a population, it doesn't matter whether the result generalize: your caliper matched sample is no less representative of a meaningful population than your original sample.", "answer_url": "https://stats.stackexchange.com/a/676905", "author": "Noah", "author_url": "https://stats.stackexchange.com/users/116195/noah", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-18T15:26:28+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": 676867, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Noah", "profile_url": "https://stats.stackexchange.com/users/116195/noah", "user_type": "registered"}, "created_at": "2026-08-18T15:26:28+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "CB48996D-4B71-49A4-AD23-E5B278A942D5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB48996D-4B71-49A4-AD23-E5B278A942D5/view-source"}], "score": 3, "updated_at": "2026-08-18T15:26:28+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "I was using full matching (using MatchIt, method = \"full\") to estimate the ATE. Now I want to extend this to examine a moderation effect by a categorical variable. I am fitting separate propensity score models within each moderator subgroup, and setting the estimand to ATE as well.\nI am getting quite high weights in separate groups (maximum of 22 in 1 group and 15 in the other - which as I understand is a way high), as well as relatively low ESS. I tried to apply calipers, which did help to improve the max weights (subgroup 1: 22.4 → 13.2; subgroup 2: 14.8 → 8.0) and ESS (subgroup 1: 74 → 111; subgroup 2: 93 → 156), balance was also mainly improved. It led to discarding 20 out of 275 observations in one subgroup and 6 out of 251 in the other.\nAs I understand the result may not anymore correspond to the ATE. After applying the calipers I am targeting slightly different populations, correct? How reasonable it is then to compare these subgroup estimates in order to draw conclusions about moderation in this case? any additional diagnostics I should try? should I avoid calipers in moderation at all?", "record_id": "Scientific-Statistics-QA:stats:676867", "selected_answer": {"answer_html": "

Your approach is perfectly reasonable. It is true that using a caliper changes the target estimand, but it does so only when the remaining matched sample has a different covariate distribution from the overall sample. With a caliper like the one you imposed, I would guess that the matched sample still resembles the overall population based on how few units were discarded.

\n

It's worth remembering also that the subgroups don't need to resemble each other for you to perform subgroup analysis or study moderation. However, you won't be able to conclude that it is the moderator itself that causes the difference in effect estimates (if there is one); any difference could simply be due to differences in the compositions of the subgroups, which may be further exacerbated by the imposition of the caliper.

\n

My advice would be first to try different methods of increasing the ESS, such as using the min.controls and max.controls arguments to prevent too many units assigned to one subclass. See an example below on the lalonde dataset, where using the max.controls option both improves balance and increases the ESS of the smaller group (which affects precision the most), and is a bit better than using a caliper:

\n
library(MatchIt); library(cobalt)\n\ndata("lalonde", package = "MatchIt")\n\n# Full matching\nM1 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n              data = lalonde, method = "full", estimand = "ATE", tol = 1e-7,\n              link = "linear.logit", exact = ~race)\n\n# Full matching with max.controls limited\nM2 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n              data = lalonde, method = "full", estimand = "ATE", tol = 1e-7,\n              link = "linear.logit", exact = ~race,\n              max.controls = 10)\n\n# Full matching with caliper on PS\nM3 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n              data = lalonde, method = "full", estimand = "ATE", tol = 1e-7,\n              link = "linear.logit", exact = ~race,\n              caliper = .1)\n\nbal.tab(M1, weights = list(max.c = M2, cal = M3))\n#> Balance Measures\n#>                 Type Diff.matchit Diff.max.c Diff.cal\n#> distance    Distance       0.0391     0.0300   0.0068\n#> age          Contin.      -0.1377     0.0318  -0.0370\n#> educ         Contin.       0.1166     0.0524   0.0335\n#> race_black    Binary      -0.0000     0.0000  -0.0000\n#> race_hispan   Binary      -0.0000     0.0000  -0.0000\n#> race_white    Binary      -0.0000     0.0000   0.0000\n#> married       Binary      -0.0061    -0.0026  -0.0129\n#> nodegree      Binary      -0.0878    -0.0569  -0.0815\n#> re74         Contin.      -0.3139    -0.1761  -0.2054\n#> re75         Contin.      -0.2884    -0.1247  -0.2248\n#> \n#> Effective sample sizes\n#>         Control Treated\n#> All      429.    185.  \n#> matchit  257.09   26.49\n#> max.c    156.88   86.58\n#> cal      210.74   43.47\n
\n

You can assess whether many units are assigned to the same subclass by using

\n
with(M1, table(treat, subclass))\n
\n

Doing this on M1 reveals that one subclass contains 89 control units and 1 treated unit, yielding more extreme weights: that treated unit receives a weight of 90. With M2, no more than 10 control units per treated unit are in each subclass, by definition, so no treated units receive a weight larger than 11. Decreasing the variability of the weights increases the ESS.

\n

In general, I would avoid calipers unless it's impossible to achieve balance without them. There are often enough ways to adjust a matching specification that you can achieve the properties of the matched sample you desire without resorting to a caliper. I would also recommend trying weighting methods before using a caliper unless your field looks down on weighting.

\n

If you do decide to use a caliper, see how relaxed of a caliper you can use to achieve your goals; a relaxed caliper will discard fewer units, making your results more generalizable to your population of interest. All that said, if your sample isn't a representative sample from a population, it doesn't matter whether the result generalize: your caliper matched sample is no less representative of a meaningful population than your original sample.

\n", "answer_id": 676905, "answer_text": "Your approach is perfectly reasonable. It is true that using a caliper changes the target estimand, but it does so only when the remaining matched sample has a different covariate distribution from the overall sample. With a caliper like the one you imposed, I would guess that the matched sample still resembles the overall population based on how few units were discarded.\n\n\n\n\nIt's worth remembering also that the subgroups don't need to resemble each other for you to perform subgroup analysis or study moderation. However, you won't be able to conclude that it is the moderator itself that causes the difference in effect estimates (if there is one); any difference could simply be due to differences in the compositions of the subgroups, which may be further exacerbated by the imposition of the caliper.\n\n\n\n\nMy advice would be first to try different methods of increasing the ESS, such as using the min.controls and max.controls arguments to prevent too many units assigned to one subclass. See an example below on the lalonde dataset, where using the max.controls option both improves balance and increases the ESS of the smaller group (which affects precision the most), and is a bit better than using a caliper:\n\n\n\n\nlibrary(MatchIt); library(cobalt)\n\ndata(\"lalonde\", package = \"MatchIt\")\n\n# Full matching\nM1 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n data = lalonde, method = \"full\", estimand = \"ATE\", tol = 1e-7,\n link = \"linear.logit\", exact = ~race)\n\n# Full matching with max.controls limited\nM2 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n data = lalonde, method = \"full\", estimand = \"ATE\", tol = 1e-7,\n link = \"linear.logit\", exact = ~race,\n max.controls = 10)\n\n# Full matching with caliper on PS\nM3 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n data = lalonde, method = \"full\", estimand = \"ATE\", tol = 1e-7,\n link = \"linear.logit\", exact = ~race,\n caliper = .1)\n\nbal.tab(M1, weights = list(max.c = M2, cal = M3))\n#> Balance Measures\n#> Type Diff.matchit Diff.max.c Diff.cal\n#> distance Distance 0.0391 0.0300 0.0068\n#> age Contin. -0.1377 0.0318 -0.0370\n#> educ Contin. 0.1166 0.0524 0.0335\n#> race_black Binary -0.0000 0.0000 -0.0000\n#> race_hispan Binary -0.0000 0.0000 -0.0000\n#> race_white Binary -0.0000 0.0000 0.0000\n#> married Binary -0.0061 -0.0026 -0.0129\n#> nodegree Binary -0.0878 -0.0569 -0.0815\n#> re74 Contin. -0.3139 -0.1761 -0.2054\n#> re75 Contin. -0.2884 -0.1247 -0.2248\n#> \n#> Effective sample sizes\n#> Control Treated\n#> All 429. 185. \n#> matchit 257.09 26.49\n#> max.c 156.88 86.58\n#> cal 210.74 43.47\n\n\n\n\n\nYou can assess whether many units are assigned to the same subclass by using\n\n\n\n\nwith(M1, table(treat, subclass))\n\n\n\n\n\nDoing this on M1 reveals that one subclass contains 89 control units and 1 treated unit, yielding more extreme weights: that treated unit receives a weight of 90. With M2, no more than 10 control units per treated unit are in each subclass, by definition, so no treated units receive a weight larger than 11. Decreasing the variability of the weights increases the ESS.\n\n\n\n\nIn general, I would avoid calipers unless it's impossible to achieve balance without them. There are often enough ways to adjust a matching specification that you can achieve the properties of the matched sample you desire without resorting to a caliper. I would also recommend trying weighting methods before using a caliper unless your field looks down on weighting.\n\n\n\n\nIf you do decide to use a caliper, see how relaxed of a caliper you can use to achieve your goals; a relaxed caliper will discard fewer units, making your results more generalizable to your population of interest. All that said, if your sample isn't a representative sample from a population, it doesn't matter whether the result generalize: your caliper matched sample is no less representative of a meaningful population than your original sample.", "answer_url": "https://stats.stackexchange.com/a/676905", "author": "Noah", "author_url": "https://stats.stackexchange.com/users/116195/noah", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-18T15:26:28+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": 676867, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Noah", "profile_url": "https://stats.stackexchange.com/users/116195/noah", "user_type": "registered"}, "created_at": "2026-08-18T15:26:28+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "CB48996D-4B71-49A4-AD23-E5B278A942D5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB48996D-4B71-49A4-AD23-E5B278A942D5/view-source"}], "score": 3, "updated_at": "2026-08-18T15:26:28+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 676905, "answers": [{"answer_html": "

Your approach is perfectly reasonable. It is true that using a caliper changes the target estimand, but it does so only when the remaining matched sample has a different covariate distribution from the overall sample. With a caliper like the one you imposed, I would guess that the matched sample still resembles the overall population based on how few units were discarded.

\n

It's worth remembering also that the subgroups don't need to resemble each other for you to perform subgroup analysis or study moderation. However, you won't be able to conclude that it is the moderator itself that causes the difference in effect estimates (if there is one); any difference could simply be due to differences in the compositions of the subgroups, which may be further exacerbated by the imposition of the caliper.

\n

My advice would be first to try different methods of increasing the ESS, such as using the min.controls and max.controls arguments to prevent too many units assigned to one subclass. See an example below on the lalonde dataset, where using the max.controls option both improves balance and increases the ESS of the smaller group (which affects precision the most), and is a bit better than using a caliper:

\n
library(MatchIt); library(cobalt)\n\ndata("lalonde", package = "MatchIt")\n\n# Full matching\nM1 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n              data = lalonde, method = "full", estimand = "ATE", tol = 1e-7,\n              link = "linear.logit", exact = ~race)\n\n# Full matching with max.controls limited\nM2 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n              data = lalonde, method = "full", estimand = "ATE", tol = 1e-7,\n              link = "linear.logit", exact = ~race,\n              max.controls = 10)\n\n# Full matching with caliper on PS\nM3 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n              data = lalonde, method = "full", estimand = "ATE", tol = 1e-7,\n              link = "linear.logit", exact = ~race,\n              caliper = .1)\n\nbal.tab(M1, weights = list(max.c = M2, cal = M3))\n#> Balance Measures\n#>                 Type Diff.matchit Diff.max.c Diff.cal\n#> distance    Distance       0.0391     0.0300   0.0068\n#> age          Contin.      -0.1377     0.0318  -0.0370\n#> educ         Contin.       0.1166     0.0524   0.0335\n#> race_black    Binary      -0.0000     0.0000  -0.0000\n#> race_hispan   Binary      -0.0000     0.0000  -0.0000\n#> race_white    Binary      -0.0000     0.0000   0.0000\n#> married       Binary      -0.0061    -0.0026  -0.0129\n#> nodegree      Binary      -0.0878    -0.0569  -0.0815\n#> re74         Contin.      -0.3139    -0.1761  -0.2054\n#> re75         Contin.      -0.2884    -0.1247  -0.2248\n#> \n#> Effective sample sizes\n#>         Control Treated\n#> All      429.    185.  \n#> matchit  257.09   26.49\n#> max.c    156.88   86.58\n#> cal      210.74   43.47\n
\n

You can assess whether many units are assigned to the same subclass by using

\n
with(M1, table(treat, subclass))\n
\n

Doing this on M1 reveals that one subclass contains 89 control units and 1 treated unit, yielding more extreme weights: that treated unit receives a weight of 90. With M2, no more than 10 control units per treated unit are in each subclass, by definition, so no treated units receive a weight larger than 11. Decreasing the variability of the weights increases the ESS.

\n

In general, I would avoid calipers unless it's impossible to achieve balance without them. There are often enough ways to adjust a matching specification that you can achieve the properties of the matched sample you desire without resorting to a caliper. I would also recommend trying weighting methods before using a caliper unless your field looks down on weighting.

\n

If you do decide to use a caliper, see how relaxed of a caliper you can use to achieve your goals; a relaxed caliper will discard fewer units, making your results more generalizable to your population of interest. All that said, if your sample isn't a representative sample from a population, it doesn't matter whether the result generalize: your caliper matched sample is no less representative of a meaningful population than your original sample.

\n", "answer_id": 676905, "answer_text": "Your approach is perfectly reasonable. It is true that using a caliper changes the target estimand, but it does so only when the remaining matched sample has a different covariate distribution from the overall sample. With a caliper like the one you imposed, I would guess that the matched sample still resembles the overall population based on how few units were discarded.\n\n\n\n\nIt's worth remembering also that the subgroups don't need to resemble each other for you to perform subgroup analysis or study moderation. However, you won't be able to conclude that it is the moderator itself that causes the difference in effect estimates (if there is one); any difference could simply be due to differences in the compositions of the subgroups, which may be further exacerbated by the imposition of the caliper.\n\n\n\n\nMy advice would be first to try different methods of increasing the ESS, such as using the min.controls and max.controls arguments to prevent too many units assigned to one subclass. See an example below on the lalonde dataset, where using the max.controls option both improves balance and increases the ESS of the smaller group (which affects precision the most), and is a bit better than using a caliper:\n\n\n\n\nlibrary(MatchIt); library(cobalt)\n\ndata(\"lalonde\", package = \"MatchIt\")\n\n# Full matching\nM1 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n data = lalonde, method = \"full\", estimand = \"ATE\", tol = 1e-7,\n link = \"linear.logit\", exact = ~race)\n\n# Full matching with max.controls limited\nM2 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n data = lalonde, method = \"full\", estimand = \"ATE\", tol = 1e-7,\n link = \"linear.logit\", exact = ~race,\n max.controls = 10)\n\n# Full matching with caliper on PS\nM3 <- matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,\n data = lalonde, method = \"full\", estimand = \"ATE\", tol = 1e-7,\n link = \"linear.logit\", exact = ~race,\n caliper = .1)\n\nbal.tab(M1, weights = list(max.c = M2, cal = M3))\n#> Balance Measures\n#> Type Diff.matchit Diff.max.c Diff.cal\n#> distance Distance 0.0391 0.0300 0.0068\n#> age Contin. -0.1377 0.0318 -0.0370\n#> educ Contin. 0.1166 0.0524 0.0335\n#> race_black Binary -0.0000 0.0000 -0.0000\n#> race_hispan Binary -0.0000 0.0000 -0.0000\n#> race_white Binary -0.0000 0.0000 0.0000\n#> married Binary -0.0061 -0.0026 -0.0129\n#> nodegree Binary -0.0878 -0.0569 -0.0815\n#> re74 Contin. -0.3139 -0.1761 -0.2054\n#> re75 Contin. -0.2884 -0.1247 -0.2248\n#> \n#> Effective sample sizes\n#> Control Treated\n#> All 429. 185. \n#> matchit 257.09 26.49\n#> max.c 156.88 86.58\n#> cal 210.74 43.47\n\n\n\n\n\nYou can assess whether many units are assigned to the same subclass by using\n\n\n\n\nwith(M1, table(treat, subclass))\n\n\n\n\n\nDoing this on M1 reveals that one subclass contains 89 control units and 1 treated unit, yielding more extreme weights: that treated unit receives a weight of 90. With M2, no more than 10 control units per treated unit are in each subclass, by definition, so no treated units receive a weight larger than 11. Decreasing the variability of the weights increases the ESS.\n\n\n\n\nIn general, I would avoid calipers unless it's impossible to achieve balance without them. There are often enough ways to adjust a matching specification that you can achieve the properties of the matched sample you desire without resorting to a caliper. I would also recommend trying weighting methods before using a caliper unless your field looks down on weighting.\n\n\n\n\nIf you do decide to use a caliper, see how relaxed of a caliper you can use to achieve your goals; a relaxed caliper will discard fewer units, making your results more generalizable to your population of interest. All that said, if your sample isn't a representative sample from a population, it doesn't matter whether the result generalize: your caliper matched sample is no less representative of a meaningful population than your original sample.", "answer_url": "https://stats.stackexchange.com/a/676905", "author": "Noah", "author_url": "https://stats.stackexchange.com/users/116195/noah", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-18T15:26:28+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": 676867, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Noah", "profile_url": "https://stats.stackexchange.com/users/116195/noah", "user_type": "registered"}, "created_at": "2026-08-18T15:26:28+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "CB48996D-4B71-49A4-AD23-E5B278A942D5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB48996D-4B71-49A4-AD23-E5B278A942D5/view-source"}], "score": 3, "updated_at": "2026-08-18T15:26:28+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "user31214993", "question_author_url": "https://stats.stackexchange.com/users/490497/user31214993", "question_author_user_type": "registered", "question_created_at": "2026-08-14T14:13:25+00:00", "question_html": "

I was using full matching (using MatchIt, method = "full") to estimate the ATE. Now I want to extend this to examine a moderation effect by a categorical variable. I am fitting separate propensity score models within each moderator subgroup, and setting the estimand to ATE as well.\nI am getting quite high weights in separate groups (maximum of 22 in 1 group and 15 in the other - which as I understand is a way high), as well as relatively low ESS. I tried to apply calipers, which did help to improve the max weights (subgroup 1: 22.4 → 13.2; subgroup 2: 14.8 → 8.0) and ESS (subgroup 1: 74 → 111; subgroup 2: 93 → 156), balance was also mainly improved. It led to discarding 20 out of 275 observations in one subgroup and 6 out of 251 in the other.\nAs I understand the result may not anymore correspond to the ATE. After applying the calipers I am targeting slightly different populations, correct? How reasonable it is then to compare these subgroup estimates in order to draw conclusions about moderation in this case? any additional diagnostics I should try? should I avoid calipers in moderation at all?

\n", "question_id": 676867, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I was using full matching (using MatchIt, method = \"full\") to estimate the ATE. Now I want to extend this to examine a moderation effect by a categorical variable. I am fitting separate propensity score models within each moderator subgroup, and setting the estimand to ATE as well.\nI am getting quite high weights in separate groups (maximum of 22 in 1 group and 15 in the other - which as I understand is a way high), as well as relatively low ESS. I tried to apply calipers, which did help to improve the max weights (subgroup 1: 22.4 → 13.2; subgroup 2: 14.8 → 8.0) and ESS (subgroup 1: 74 → 111; subgroup 2: 93 → 156), balance was also mainly improved. It led to discarding 20 out of 275 observations in one subgroup and 6 out of 251 in the other.\nAs I understand the result may not anymore correspond to the ATE. After applying the calipers I am targeting slightly different populations, correct? How reasonable it is then to compare these subgroup estimates in order to draw conclusions about moderation in this case? any additional diagnostics I should try? should I avoid calipers in moderation at all?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "user31214993", "profile_url": "https://stats.stackexchange.com/users/490497/user31214993", "user_type": "registered"}, "created_at": "2026-08-14T14:13:25+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "E972484E-5136-4868-B279-F1B4F45BA217", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E972484E-5136-4868-B279-F1B4F45BA217/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676867/can-i-use-caliper-in-moderation-analysis-with-ate-is-the-target-estimand", "split": "train", "split_group": "b48d86f70b30568513b23fc942f009f575dd2790b7c2253380088fa85fbbcec7", "tags": ["interaction", "matching", "treatment-effect"], "thread_id": "stats:676867", "title": "Can I use caliper in moderation analysis with ATE is the target estimand?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I am studying the following problem from an exam.\n\n\n\n\nA system consists of two subsystems connected in parallel.\nThe first subsystem is just one component c1​.\nThe second subsystem is made of three components c2,c3,c4 connected in series.\nThe lifetimes of c1,…,c4​ are independent exponential random variables with rates\nλ1=0.11,λ2=0.03,λ3=0.01,λ4=0.06\n\n\n\n\n(times in minutes).\nCompute the probability that the whole system is still working 9 minutes after switching on\n\n\n\n\nMy reasoning was the following.\nLet Xi​ be the lifetime of component ci​, so\nP(Xi​>t)=e^−λi​t\n\n\n\n\nFor the series subsystem c2,c3,c4 the lifetime is\nY=min(X2​,X3​,X4​),\n\n\n\n\nso\nP(Y>t)=e^−(λ2​+λ3​+λ4​)t\n\n\n\n\nSince the first subsystem c1​ and the series subsystem are in parallel, the lifetime of the whole system is\nX=max(X1​,Y).\n\n\n\n\nThus\nP(X>t)=1−P(X1​≤t,Y≤t)=1−(1−e−λ1​t)(1−e−(λ2​+λ3​+λ4​)t).\n\n\n\n\nSo for t=9\n$P(X>9)=e^{−9λ1}​+e^{−9(λ2​+λ3​+λ4​)}−e^{−9(λ1​+λ2​+λ3​+λ4​)}$.\n\n\n\n\nWith the given values I get\nP(X>9)≈0.631.\n\n\n\n\nHowever, when I discussed the exam with the professor, he said that I was mixing things, and that putting two exponential lifetimes in parallel does not give an exponential lifetime. I understand that the maximum of independent exponentials is not exponential, but I did not assume it was: I used the complement formula above.\n\n\n\n\nSo my questions are:\nIs the value i get correct?\nIf yes, why would the professor say that I was treating the parallel system as exponential?\nIf not, where exactly is the mistake?", "record_id": "Scientific-Statistics-QA:stats:676870", "selected_answer": {"answer_html": "

You are correct that the probability of component $c_i$ surviving past time $t$ is $e^{-\\lambda_i t}$. And that is pretty much the only exponential distribution related formula we will need. The rest is based on the fact that the probability of an "and" condition of independent probabilities is their product.

\n

So you can compute the probability of survival at time $t=9$ for all 4 components, $P_i$.
\nFor the $c_2,c_3,c_4$ subsystem, the probability of survival of that subsystem will be $P_2 \\cdot P_3 \\cdot P_4 = P_{234}$ (the product; for the subsystem to survive, they all need to survide).
\nNow, we can use the complement formula. For the complete system to fail, both subsystems have to fail (parallel); the probability of both failing will then be $(1-P_1) \\cdot (1-P_{234})=P_{fail}$.
\nTherefore, the probability of the system surviving becomes $1-P_{fail}$.

\n

If you plug in the actual values, you obtain $0.627..$, just as @whuber found.

\n

I am not sure where the error came from. Your equations are all correct, and would yield 0.627 (not .631: close but?). Maybe a rounding error in the computations? Use e.g. Excel to do the actual computation, and you will get the same result...

\n

You definitively should talk to your professor; your logic is correct (while maybe a bit more cumbersome than it could have been, but...) and you certainly did not "mix things".

\n", "answer_id": 676871, "answer_text": "You are correct that the probability of component $c_i$ surviving past time $t$ is $e^{-\\lambda_i t}$. And that is pretty much the only exponential distribution related formula we will need. The rest is based on the fact that the probability of an \"and\" condition of independent probabilities is their product.\n\n\n\n\nSo you can compute the probability of survival at time $t=9$ for all 4 components, $P_i$.\n\nFor the $c_2,c_3,c_4$ subsystem, the probability of survival of that subsystem will be $P_2 \\cdot P_3 \\cdot P_4 = P_{234}$ (the product; for the subsystem to survive, they all need to survide).\n\nNow, we can use the complement formula. For the complete system to fail, both subsystems have to fail (parallel); the probability of both failing will then be $(1-P_1) \\cdot (1-P_{234})=P_{fail}$.\n\nTherefore, the probability of the system surviving becomes $1-P_{fail}$.\n\n\n\n\nIf you plug in the actual values, you obtain $0.627..$, just as @whuber found.\n\n\n\n\nI am not sure where the error came from. Your equations are all correct, and would yield 0.627 (not .631: close but?). Maybe a rounding error in the computations? Use e.g. Excel to do the actual computation, and you will get the same result...\n\n\n\n\nYou definitively should talk to your professor; your logic is correct (while maybe a bit more cumbersome than it could have been, but...) and you certainly did not \"mix things\".", "answer_url": "https://stats.stackexchange.com/a/676871", "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-08-14T17:32:39+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": 676870, "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-08-14T17:32:39+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "06DA3DD9-A221-40D2-9E1F-78CE6F599986", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/06DA3DD9-A221-40D2-9E1F-78CE6F599986/view-source"}, {"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-08-14T19:17:13+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "7787B2AE-4750-4A8F-A630-D5F6C5FA2386", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7787B2AE-4750-4A8F-A630-D5F6C5FA2386/view-source"}], "score": 2, "updated_at": "2026-08-14T19:17:13+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

You are correct that the probability of component $c_i$ surviving past time $t$ is $e^{-\\lambda_i t}$. And that is pretty much the only exponential distribution related formula we will need. The rest is based on the fact that the probability of an "and" condition of independent probabilities is their product.

\n

So you can compute the probability of survival at time $t=9$ for all 4 components, $P_i$.
\nFor the $c_2,c_3,c_4$ subsystem, the probability of survival of that subsystem will be $P_2 \\cdot P_3 \\cdot P_4 = P_{234}$ (the product; for the subsystem to survive, they all need to survide).
\nNow, we can use the complement formula. For the complete system to fail, both subsystems have to fail (parallel); the probability of both failing will then be $(1-P_1) \\cdot (1-P_{234})=P_{fail}$.
\nTherefore, the probability of the system surviving becomes $1-P_{fail}$.

\n

If you plug in the actual values, you obtain $0.627..$, just as @whuber found.

\n

I am not sure where the error came from. Your equations are all correct, and would yield 0.627 (not .631: close but?). Maybe a rounding error in the computations? Use e.g. Excel to do the actual computation, and you will get the same result...

\n

You definitively should talk to your professor; your logic is correct (while maybe a bit more cumbersome than it could have been, but...) and you certainly did not "mix things".

\n", "answer_id": 676871, "answer_text": "You are correct that the probability of component $c_i$ surviving past time $t$ is $e^{-\\lambda_i t}$. And that is pretty much the only exponential distribution related formula we will need. The rest is based on the fact that the probability of an \"and\" condition of independent probabilities is their product.\n\n\n\n\nSo you can compute the probability of survival at time $t=9$ for all 4 components, $P_i$.\n\nFor the $c_2,c_3,c_4$ subsystem, the probability of survival of that subsystem will be $P_2 \\cdot P_3 \\cdot P_4 = P_{234}$ (the product; for the subsystem to survive, they all need to survide).\n\nNow, we can use the complement formula. For the complete system to fail, both subsystems have to fail (parallel); the probability of both failing will then be $(1-P_1) \\cdot (1-P_{234})=P_{fail}$.\n\nTherefore, the probability of the system surviving becomes $1-P_{fail}$.\n\n\n\n\nIf you plug in the actual values, you obtain $0.627..$, just as @whuber found.\n\n\n\n\nI am not sure where the error came from. Your equations are all correct, and would yield 0.627 (not .631: close but?). Maybe a rounding error in the computations? Use e.g. Excel to do the actual computation, and you will get the same result...\n\n\n\n\nYou definitively should talk to your professor; your logic is correct (while maybe a bit more cumbersome than it could have been, but...) and you certainly did not \"mix things\".", "answer_url": "https://stats.stackexchange.com/a/676871", "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-08-14T17:32:39+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": 676870, "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-08-14T17:32:39+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "06DA3DD9-A221-40D2-9E1F-78CE6F599986", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/06DA3DD9-A221-40D2-9E1F-78CE6F599986/view-source"}, {"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-08-14T19:17:13+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "7787B2AE-4750-4A8F-A630-D5F6C5FA2386", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7787B2AE-4750-4A8F-A630-D5F6C5FA2386/view-source"}], "score": 2, "updated_at": "2026-08-14T19:17:13+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "nito", "question_author_url": "https://stats.stackexchange.com/users/515495/nito", "question_author_user_type": "unregistered", "question_created_at": "2026-08-14T15:54:09+00:00", "question_html": "

I am studying the following problem from an exam.

\n

A system consists of two subsystems connected in parallel.\nThe first subsystem is just one component c1​.\nThe second subsystem is made of three components c2,c3,c4 connected in series.\nThe lifetimes of c1,…,c4​ are independent exponential random variables with rates\nλ1=0.11,λ2=0.03,λ3=0.01,λ4=0.06

\n

(times in minutes).\nCompute the probability that the whole system is still working 9 minutes after switching on

\n

My reasoning was the following.\nLet Xi​ be the lifetime of component ci​, so\nP(Xi​>t)=e^−λi​t

\n

For the series subsystem c2,c3,c4 the lifetime is\nY=min(X2​,X3​,X4​),

\n

so\nP(Y>t)=e^−(λ2​+λ3​+λ4​)t

\n

Since the first subsystem c1​ and the series subsystem are in parallel, the lifetime of the whole system is\nX=max(X1​,Y).

\n

Thus\nP(X>t)=1−P(X1​≤t,Y≤t)=1−(1−e−λ1​t)(1−e−(λ2​+λ3​+λ4​)t).

\n

So for t=9\n$P(X>9)=e^{−9λ1}​+e^{−9(λ2​+λ3​+λ4​)}−e^{−9(λ1​+λ2​+λ3​+λ4​)}$.

\n

With the given values I get\nP(X>9)≈0.631.

\n

However, when I discussed the exam with the professor, he said that I was mixing things, and that putting two exponential lifetimes in parallel does not give an exponential lifetime. I understand that the maximum of independent exponentials is not exponential, but I did not assume it was: I used the complement formula above.

\n

So my questions are:\nIs the value i get correct?\nIf yes, why would the professor say that I was treating the parallel system as exponential?\nIf not, where exactly is the mistake?

\n", "question_id": 676870, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I am studying the following problem from an exam.\n\n\n\n\nA system consists of two subsystems connected in parallel.\nThe first subsystem is just one component c1​.\nThe second subsystem is made of three components c2,c3,c4 connected in series.\nThe lifetimes of c1,…,c4​ are independent exponential random variables with rates\nλ1=0.11,λ2=0.03,λ3=0.01,λ4=0.06\n\n\n\n\n(times in minutes).\nCompute the probability that the whole system is still working 9 minutes after switching on\n\n\n\n\nMy reasoning was the following.\nLet Xi​ be the lifetime of component ci​, so\nP(Xi​>t)=e^−λi​t\n\n\n\n\nFor the series subsystem c2,c3,c4 the lifetime is\nY=min(X2​,X3​,X4​),\n\n\n\n\nso\nP(Y>t)=e^−(λ2​+λ3​+λ4​)t\n\n\n\n\nSince the first subsystem c1​ and the series subsystem are in parallel, the lifetime of the whole system is\nX=max(X1​,Y).\n\n\n\n\nThus\nP(X>t)=1−P(X1​≤t,Y≤t)=1−(1−e−λ1​t)(1−e−(λ2​+λ3​+λ4​)t).\n\n\n\n\nSo for t=9\n$P(X>9)=e^{−9λ1}​+e^{−9(λ2​+λ3​+λ4​)}−e^{−9(λ1​+λ2​+λ3​+λ4​)}$.\n\n\n\n\nWith the given values I get\nP(X>9)≈0.631.\n\n\n\n\nHowever, when I discussed the exam with the professor, he said that I was mixing things, and that putting two exponential lifetimes in parallel does not give an exponential lifetime. I understand that the maximum of independent exponentials is not exponential, but I did not assume it was: I used the complement formula above.\n\n\n\n\nSo my questions are:\nIs the value i get correct?\nIf yes, why would the professor say that I was treating the parallel system as exponential?\nIf not, where exactly is the mistake?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "nito", "profile_url": "https://stats.stackexchange.com/users/515495/nito", "user_type": "unregistered"}, "created_at": "2026-08-14T15:54:09+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "FC6BF45C-454F-4D07-B38F-B3A113BB7B0D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FC6BF45C-454F-4D07-B38F-B3A113BB7B0D/view-source"}, {"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-08-14T19:20:36+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "BC023EC3-6983-4139-B5B9-0C3FDA83D37A", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/BC023EC3-6983-4139-B5B9-0C3FDA83D37A/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-14T23:54:58+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "EAFBBBC5-C427-4DF3-8A2D-0E9FCCD42F7C", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/EAFBBBC5-C427-4DF3-8A2D-0E9FCCD42F7C/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676870/exponential-lifetime-of-components-in-a-system-probability-system-survives-past", "split": "train", "split_group": "66dcf723157420bc63a4ab74ff31595827a4e94797a2400f49960b6b944619d1", "tags": ["probability", "exponential-distribution", "reliability", "order-statistics"], "thread_id": "stats:676870", "title": "Exponential lifetime of components in a system: probability system survives past time t"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "Let's say you have a classic mixture model and you want to use a Gibbs sampler over the parameters and the latent variable. How do you deal with your sampler getting stuck at a single node?", "record_id": "Scientific-Statistics-QA:stats:676879", "selected_answer": {"answer_html": "

If you run a plain Gibbs on a classic mixture model, you face the paradox that the Markov chain is uniformly ergodic (because the latent space is finite and hence compact) AND usually fails to switch between modes, i.e. does not exhibit label switching. This is the point we make in the 2000 JASA paper with Gilles Celeux and Merilee Hurn.

\n

The literature has now expanded with several solutions for ensuring the label switching property by:

\n\n

These perspectives are discussed in our edited book\nHandbook of Mixture Analysis

\n", "answer_id": 676884, "answer_text": "If you run a plain Gibbs on a classic mixture model, you face the paradox that the Markov chain is uniformly ergodic (because the latent space is finite and hence compact) AND usually fails to switch between modes, i.e. does not exhibit label switching. This is the point we make in the 2000 JASA paper with Gilles Celeux and Merilee Hurn (https://www.jstor.org/stable/2669477?searchText=celeux%20hurn%20robert&searchUri=%2Faction%2FdoBasicSearch%3FQuery%3Dceleux%2Bhurn%2Brobert%26so%3Drel%26efqs%3DeyJjdHkiOlsiYW05MWNtNWhiQT09Il19&ab_segments=0%2Fbasic_search_gsv2%2Fcontrol&refreqid=fastly-default%3A0dc4861d75073d6e1d8fc9756aa699a8).\n\n\n\n\nThe literature has now expanded with several solutions for ensuring the label switching property by:\n\n\n\n\n\nrandomly shuffling the labels at each iteration, à la Früwirth-Schnatter\n\n\n\n\ninserting tempering steps between each iteration, à la Neal\n\n\n\n\navoiding the latent variable simulation (as we suggest in our paper)\n\n\n\n\nusing the point process representation of the mixture parameters, à la Green\n\n\n\n\nusing a sequential approach where new labels appear with new observations, à la Chopin\n\n\n\n\n\nThese perspectives are discussed in our edited book\nHandbook of Mixture Analysis (https://www.routledge.com/Handbook-of-Mixture-Analysis/Fruhwirth-Schnatter-Celeux-Robert/p/book/9780367732066)", "answer_url": "https://stats.stackexchange.com/a/676884", "author": "Xi'an", "author_url": "https://stats.stackexchange.com/users/7224/xian", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-15T20:39:37+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": 676879, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Xi'an", "profile_url": "https://stats.stackexchange.com/users/7224/xian", "user_type": "registered"}, "created_at": "2026-08-15T20:39:37+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "CB906748-9A2D-45A6-B13C-3B60265A0A79", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB906748-9A2D-45A6-B13C-3B60265A0A79/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-08-16T08:08:52+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "835E1857-6F7B-4983-806C-8B86C7B28C02", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/835E1857-6F7B-4983-806C-8B86C7B28C02/view-source"}], "score": 11, "updated_at": "2026-08-16T08:08:52+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

If you run a plain Gibbs on a classic mixture model, you face the paradox that the Markov chain is uniformly ergodic (because the latent space is finite and hence compact) AND usually fails to switch between modes, i.e. does not exhibit label switching. This is the point we make in the 2000 JASA paper with Gilles Celeux and Merilee Hurn.

\n

The literature has now expanded with several solutions for ensuring the label switching property by:

\n\n

These perspectives are discussed in our edited book\nHandbook of Mixture Analysis

\n", "answer_id": 676884, "answer_text": "If you run a plain Gibbs on a classic mixture model, you face the paradox that the Markov chain is uniformly ergodic (because the latent space is finite and hence compact) AND usually fails to switch between modes, i.e. does not exhibit label switching. This is the point we make in the 2000 JASA paper with Gilles Celeux and Merilee Hurn (https://www.jstor.org/stable/2669477?searchText=celeux%20hurn%20robert&searchUri=%2Faction%2FdoBasicSearch%3FQuery%3Dceleux%2Bhurn%2Brobert%26so%3Drel%26efqs%3DeyJjdHkiOlsiYW05MWNtNWhiQT09Il19&ab_segments=0%2Fbasic_search_gsv2%2Fcontrol&refreqid=fastly-default%3A0dc4861d75073d6e1d8fc9756aa699a8).\n\n\n\n\nThe literature has now expanded with several solutions for ensuring the label switching property by:\n\n\n\n\n\nrandomly shuffling the labels at each iteration, à la Früwirth-Schnatter\n\n\n\n\ninserting tempering steps between each iteration, à la Neal\n\n\n\n\navoiding the latent variable simulation (as we suggest in our paper)\n\n\n\n\nusing the point process representation of the mixture parameters, à la Green\n\n\n\n\nusing a sequential approach where new labels appear with new observations, à la Chopin\n\n\n\n\n\nThese perspectives are discussed in our edited book\nHandbook of Mixture Analysis (https://www.routledge.com/Handbook-of-Mixture-Analysis/Fruhwirth-Schnatter-Celeux-Robert/p/book/9780367732066)", "answer_url": "https://stats.stackexchange.com/a/676884", "author": "Xi'an", "author_url": "https://stats.stackexchange.com/users/7224/xian", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-15T20:39:37+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": 676879, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Xi'an", "profile_url": "https://stats.stackexchange.com/users/7224/xian", "user_type": "registered"}, "created_at": "2026-08-15T20:39:37+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "CB906748-9A2D-45A6-B13C-3B60265A0A79", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB906748-9A2D-45A6-B13C-3B60265A0A79/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-08-16T08:08:52+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "835E1857-6F7B-4983-806C-8B86C7B28C02", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/835E1857-6F7B-4983-806C-8B86C7B28C02/view-source"}], "score": 11, "updated_at": "2026-08-16T08:08:52+00:00"}], "domain": "statistics", "external_links": ["https://www.jstor.org/stable/2669477?searchText=celeux%20hurn%20robert&searchUri=%2Faction%2FdoBasicSearch%3FQuery%3Dceleux%2Bhurn%2Brobert%26so%3Drel%26efqs%3DeyJjdHkiOlsiYW05MWNtNWhiQT09Il19&ab_segments=0%2Fbasic_search_gsv2%2Fcontrol&refreqid=fastly-default%3A0dc4861d75073d6e1d8fc9756aa699a8", "https://www.routledge.com/Handbook-of-Mixture-Analysis/Fruhwirth-Schnatter-Celeux-Robert/p/book/9780367732066"], "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": "5 d", "question_author_url": "https://stats.stackexchange.com/users/515521/5-d", "question_author_user_type": "registered", "question_created_at": "2026-08-15T12:45:58+00:00", "question_html": "

Let's say you have a classic mixture model and you want to use a Gibbs sampler over the parameters and the latent variable. How do you deal with your sampler getting stuck at a single node?

\n", "question_id": 676879, "question_license": "CC BY-SA 4.0", "question_score": 6, "question_text": "Let's say you have a classic mixture model and you want to use a Gibbs sampler over the parameters and the latent variable. How do you deal with your sampler getting stuck at a single node?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "5 d", "profile_url": "https://stats.stackexchange.com/users/515521/5-d", "user_type": "registered"}, "created_at": "2026-08-15T12:45:58+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "82BC8558-016A-4705-A5FD-57942444684B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/82BC8558-016A-4705-A5FD-57942444684B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-08-15T18:07:14+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "001C88C1-DF6C-4863-973A-9A264F1A2C79", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/001C88C1-DF6C-4863-973A-9A264F1A2C79/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-16T08:56:04+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "51FF7245-F5D9-4250-AECD-11ED7475CAA3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/51FF7245-F5D9-4250-AECD-11ED7475CAA3/view-source"}, {"content_license": null, "contributor": {"display_name": "kjetil b halvorsen", "profile_url": "https://stats.stackexchange.com/users/11887/kjetil-b-halvorsen", "user_type": "moderator"}, "created_at": "2026-08-16T21:02:28+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "1124C47B-8496-4670-BAD8-1A5DA7F237F6", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1124C47B-8496-4670-BAD8-1A5DA7F237F6/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676879/how-does-one-deal-with-the-gibbs-sampler-being-stuck-in-a-node-when-we-consider", "split": "train", "split_group": "9941ddac4dbdb87214c02ad8a10a4e58365523de7cdf38dd95eb1dc574d1f183", "tags": ["bayesian", "sampling", "gibbs"], "thread_id": "stats:676879", "title": "How does one deal with the Gibbs sampler being stuck in a node when we consider a mixture model"}} +{"accepted_answer": {"answer_html": "

As comments to the question already mentioned, the question is ill-posed. The first part implies an estimation problem (“estimate the mean and variance of machine reliability of the population”). But for that, we would need to know the desired margins of error $E_{\\mu}, E_{\\sigma}$, which are not in the problem statement.
\nThe last sentence however suggests a statistical test (“a statistically significant result”), which would require a null hypothesis (absent?), as well as a significance level and a desired power...
\nBut, there may be some ways to get “near” a solution? Below is not an “answer”, but more a way to look at this ill-posed problem and try to make some sense of it.

\n

I will start by postulating that each machine $X_i$ follows a Bernoulli distribution $\\text {Bernoulli}(p_i)$. I will then add a “strong” assumption, which simplifies the problem (and later, will relax it), namely that $p_i=p, \\forall i$ (Is that what the OP meant when he added in a comment “we assume that there is a single DGP (data generating process) which governs the behavior of all machines”??).
\nIn that case, as hinted by @whuber, sampling n machines once, or one machine n times provides the exact same information. A sample of size n will be binomial $B(n,p)$ distributed.
\nWe can now use our "favorite" confidence interval method (Wald? -probably not, Wilson score?, Clopper-Pearson -my favorite-), and obtain a CI. In all cases, the half-width of the CI (which is the margin of error) depends on $n$, and so we can generate an equation which gives $n$ as a function of $E_{\\mu}$.
\nIf we note the CI of $p$ as $[p_L,p_U]$, then the low bound of the CI of the variance will be $n \\cdot p_L \\cdot (1-p_L)$ and the upper bound will be $n \\cdot p_U \\cdot (1-p_U)$. Unless the CI for $p$ includes $p=.5$, in which case the worse case variance is simply the peak value $\\frac n 4$. And again, given a desired margin of error $E_{\\sigma}$, you can derive a formula for $n$ as a function of $E_{\\sigma}$.
\nThen pick the $n$ which satisfies both desired margins of error.
\nThis is all well and good, but said formulas also contain $p$, and we have no idea of the value of $p$. Two options:

\n\n

And as far as a “significant test", I am not sure what the null could be? Probably something like $H0: p \\le p_0, H1: p \\gt p_0$? But what $p_0$? Again, the worst case is $p_0 = 0.5$. But we do not know $p$, so we have no idea of how large (or small) an effect we are trying to find? So the only answer would be to run a small exploratory study, to estimate $p$, and then compute a sample size based on that estimate.
\nNote that the 3 “questions” (estimate of the mean reliability, estimate of the variance reliability, and statistical test) most likely require 3 different $n$’s. So then the answer is "pick the max"...

\n

Now we can relax the initial assumption, by simply assuming that each machine $X_i$ follows a Bernoulli distribution with probability (of working) $p_i$; but $p_i$ remains constant between measurements on a given machine.
\nHere, I would use a two-stage sampling plan; test n machines k times each. You can then estimate the means of the n machines, and then of the population. And you can use a two-way ANOVA to separate the variance within the machines from the variance between machines.
\nI have to say that I am unsure of how to derive formulas expressing $n$ and $k$ as a function of $E_{mu}$ or $E_{sigma}$.

\n

Last, if we now assume that $p_i$ is itself a random variable (which is what the OP has done, when using a Beta-Binomial model: but nothing in the question implies this scenario?!), I have to say that I give up trying to make sense of such a scenario.

\n", "answer_id": 676891, "answer_text": "As comments to the question already mentioned, the question is ill-posed. The first part implies an estimation problem (“estimate the mean and variance of machine reliability of the population”). But for that, we would need to know the desired margins of error $E_{\\mu}, E_{\\sigma}$, which are not in the problem statement.\n\nThe last sentence however suggests a statistical test (“a statistically significant result”), which would require a null hypothesis (absent?), as well as a significance level and a desired power...\n\nBut, there may be some ways to get “near” a solution? Below is not an “answer”, but more a way to look at this ill-posed problem and try to make some sense of it.\n\n\n\n\nI will start by postulating that each machine $X_i$ follows a Bernoulli distribution $\\text {Bernoulli}(p_i)$. I will then add a “strong” assumption, which simplifies the problem (and later, will relax it), namely that $p_i=p, \\forall i$ (Is that what the OP meant when he added in a comment “we assume that there is a single DGP (data generating process) which governs the behavior of all machines”??).\n\nIn that case, as hinted by @whuber, sampling n machines once, or one machine n times provides the exact same information. A sample of size n will be binomial $B(n,p)$ distributed.\n\nWe can now use our \"favorite\" confidence interval method (Wald? -probably not, Wilson score?, Clopper-Pearson -my favorite-), and obtain a CI. In all cases, the half-width of the CI (which is the margin of error) depends on $n$, and so we can generate an equation which gives $n$ as a function of $E_{\\mu}$.\n\nIf we note the CI of $p$ as $[p_L,p_U]$, then the low bound of the CI of the variance will be $n \\cdot p_L \\cdot (1-p_L)$ and the upper bound will be $n \\cdot p_U \\cdot (1-p_U)$. Unless the CI for $p$ includes $p=.5$, in which case the worse case variance is simply the peak value $\\frac n 4$. And again, given a desired margin of error $E_{\\sigma}$, you can derive a formula for $n$ as a function of $E_{\\sigma}$.\n\nThen pick the $n$ which satisfies both desired margins of error.\n\nThis is all well and good, but said formulas also contain $p$, and we have no idea of the value of $p$. Two options:\n\n\n\n\n\nRun a small exploratory sample (n=15?), to get an idea of $\\hat p$, hoping $\\hat p$ is far of 0.5. That will let you pick a smaller $n$.\n\n\n\n\nAssume the worst case, which is $p=0.5$ and determine $n$ on that basis.\n\n\n\n\n\nAnd as far as a “significant test\", I am not sure what the null could be? Probably something like $H0: p \\le p_0, H1: p \\gt p_0$? But what $p_0$? Again, the worst case is $p_0 = 0.5$. But we do not know $p$, so we have no idea of how large (or small) an effect we are trying to find? So the only answer would be to run a small exploratory study, to estimate $p$, and then compute a sample size based on that estimate.\n\nNote that the 3 “questions” (estimate of the mean reliability, estimate of the variance reliability, and statistical test) most likely require 3 different $n$’s. So then the answer is \"pick the max\"...\n\n\n\n\nNow we can relax the initial assumption, by simply assuming that each machine $X_i$ follows a Bernoulli distribution with probability (of working) $p_i$; but $p_i$ remains constant between measurements on a given machine.\n\nHere, I would use a two-stage sampling plan; test n machines k times each. You can then estimate the means of the n machines, and then of the population. And you can use a two-way ANOVA to separate the variance within the machines from the variance between machines.\n\nI have to say that I am unsure of how to derive formulas expressing $n$ and $k$ as a function of $E_{mu}$ or $E_{sigma}$.\n\n\n\n\nLast, if we now assume that $p_i$ is itself a random variable (which is what the OP has done, when using a Beta-Binomial model: but nothing in the question implies this scenario?!), I have to say that I give up trying to make sense of such a scenario.", "answer_url": "https://stats.stackexchange.com/a/676891", "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-08-16T21:37:58+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": 676888, "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-08-16T21:37:58+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "73406A70-9203-4045-AF24-09AB9C30742E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/73406A70-9203-4045-AF24-09AB9C30742E/view-source"}, {"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-08-17T02:39:48+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "A231D113-2ECC-4E6B-ADA4-769EBEFADDE6", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A231D113-2ECC-4E6B-ADA4-769EBEFADDE6/view-source"}], "score": 3, "updated_at": "2026-08-17T02:39:48+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "In most introductory sampling problems involving proportions, it is typically assumed that there is no variability within a given unit. For example, if we want to know what percent of a population has a car, we assume that when we select a person, they either have or do not have a car.\n\n\n\n\nI have come across this problem:\n\n\n\n\n\n\n\nThere is a population of many machines. On the same day, a given\nmachine can sometimes work and sometimes not work. An experiment is\nbeing planned to estimate the mean and variance of machine reliability\nof the population based on a statistical sample. You need to\ndecide the sample size: how many machines to test and how many times to repeat tests on each machine?\n\n\n\n\n\n\n\n\n\n\nAssume the cost of selecting any machine is constant, the cost of each test is constant, any tests are not destructive (i.e. a test on a machine does not interfere with the future performance of the machine). Also assume that the future performance of a given machine does not depend on past performance of that machine.\n\n\n\n\n\n\n\nAssuming iid, I thought a Beta-Binomial model can describe this situation:\n\n\n\n\n$$\\theta_i \\overset{iid}{\\sim} \\text{Beta}(\\alpha,\\beta), \\qquad Y_i \\mid \\theta_i \\sim \\text{Binomial}(n_i,\\theta_i), \\qquad i=1,\\dots,M$$\n\n\n\n\nBut I am unsure how to decide the number of machines to test and how many times to test each machine.\n\n\n\n\nIntuitively, I think the underlying values of $\\alpha,\\beta$ influence this decision. For example, suppose you have a fixed budget of $k$ tests. If the population has low variability, then you can test many machines a small number of times. If the population has high variability, you are pushed towards testing fewer machines but testing each machine more time.\n\n\n\n\nHow is this problem usually dealt with in statistics? (I was thinking of doing a simulation for different values of $\\alpha,\\beta$ and seeing how different sample sizes influence coverage probability and estimation error).", "record_id": "Scientific-Statistics-QA:stats:676888", "selected_answer": {"answer_html": "

As comments to the question already mentioned, the question is ill-posed. The first part implies an estimation problem (“estimate the mean and variance of machine reliability of the population”). But for that, we would need to know the desired margins of error $E_{\\mu}, E_{\\sigma}$, which are not in the problem statement.
\nThe last sentence however suggests a statistical test (“a statistically significant result”), which would require a null hypothesis (absent?), as well as a significance level and a desired power...
\nBut, there may be some ways to get “near” a solution? Below is not an “answer”, but more a way to look at this ill-posed problem and try to make some sense of it.

\n

I will start by postulating that each machine $X_i$ follows a Bernoulli distribution $\\text {Bernoulli}(p_i)$. I will then add a “strong” assumption, which simplifies the problem (and later, will relax it), namely that $p_i=p, \\forall i$ (Is that what the OP meant when he added in a comment “we assume that there is a single DGP (data generating process) which governs the behavior of all machines”??).
\nIn that case, as hinted by @whuber, sampling n machines once, or one machine n times provides the exact same information. A sample of size n will be binomial $B(n,p)$ distributed.
\nWe can now use our "favorite" confidence interval method (Wald? -probably not, Wilson score?, Clopper-Pearson -my favorite-), and obtain a CI. In all cases, the half-width of the CI (which is the margin of error) depends on $n$, and so we can generate an equation which gives $n$ as a function of $E_{\\mu}$.
\nIf we note the CI of $p$ as $[p_L,p_U]$, then the low bound of the CI of the variance will be $n \\cdot p_L \\cdot (1-p_L)$ and the upper bound will be $n \\cdot p_U \\cdot (1-p_U)$. Unless the CI for $p$ includes $p=.5$, in which case the worse case variance is simply the peak value $\\frac n 4$. And again, given a desired margin of error $E_{\\sigma}$, you can derive a formula for $n$ as a function of $E_{\\sigma}$.
\nThen pick the $n$ which satisfies both desired margins of error.
\nThis is all well and good, but said formulas also contain $p$, and we have no idea of the value of $p$. Two options:

\n\n

And as far as a “significant test", I am not sure what the null could be? Probably something like $H0: p \\le p_0, H1: p \\gt p_0$? But what $p_0$? Again, the worst case is $p_0 = 0.5$. But we do not know $p$, so we have no idea of how large (or small) an effect we are trying to find? So the only answer would be to run a small exploratory study, to estimate $p$, and then compute a sample size based on that estimate.
\nNote that the 3 “questions” (estimate of the mean reliability, estimate of the variance reliability, and statistical test) most likely require 3 different $n$’s. So then the answer is "pick the max"...

\n

Now we can relax the initial assumption, by simply assuming that each machine $X_i$ follows a Bernoulli distribution with probability (of working) $p_i$; but $p_i$ remains constant between measurements on a given machine.
\nHere, I would use a two-stage sampling plan; test n machines k times each. You can then estimate the means of the n machines, and then of the population. And you can use a two-way ANOVA to separate the variance within the machines from the variance between machines.
\nI have to say that I am unsure of how to derive formulas expressing $n$ and $k$ as a function of $E_{mu}$ or $E_{sigma}$.

\n

Last, if we now assume that $p_i$ is itself a random variable (which is what the OP has done, when using a Beta-Binomial model: but nothing in the question implies this scenario?!), I have to say that I give up trying to make sense of such a scenario.

\n", "answer_id": 676891, "answer_text": "As comments to the question already mentioned, the question is ill-posed. The first part implies an estimation problem (“estimate the mean and variance of machine reliability of the population”). But for that, we would need to know the desired margins of error $E_{\\mu}, E_{\\sigma}$, which are not in the problem statement.\n\nThe last sentence however suggests a statistical test (“a statistically significant result”), which would require a null hypothesis (absent?), as well as a significance level and a desired power...\n\nBut, there may be some ways to get “near” a solution? Below is not an “answer”, but more a way to look at this ill-posed problem and try to make some sense of it.\n\n\n\n\nI will start by postulating that each machine $X_i$ follows a Bernoulli distribution $\\text {Bernoulli}(p_i)$. I will then add a “strong” assumption, which simplifies the problem (and later, will relax it), namely that $p_i=p, \\forall i$ (Is that what the OP meant when he added in a comment “we assume that there is a single DGP (data generating process) which governs the behavior of all machines”??).\n\nIn that case, as hinted by @whuber, sampling n machines once, or one machine n times provides the exact same information. A sample of size n will be binomial $B(n,p)$ distributed.\n\nWe can now use our \"favorite\" confidence interval method (Wald? -probably not, Wilson score?, Clopper-Pearson -my favorite-), and obtain a CI. In all cases, the half-width of the CI (which is the margin of error) depends on $n$, and so we can generate an equation which gives $n$ as a function of $E_{\\mu}$.\n\nIf we note the CI of $p$ as $[p_L,p_U]$, then the low bound of the CI of the variance will be $n \\cdot p_L \\cdot (1-p_L)$ and the upper bound will be $n \\cdot p_U \\cdot (1-p_U)$. Unless the CI for $p$ includes $p=.5$, in which case the worse case variance is simply the peak value $\\frac n 4$. And again, given a desired margin of error $E_{\\sigma}$, you can derive a formula for $n$ as a function of $E_{\\sigma}$.\n\nThen pick the $n$ which satisfies both desired margins of error.\n\nThis is all well and good, but said formulas also contain $p$, and we have no idea of the value of $p$. Two options:\n\n\n\n\n\nRun a small exploratory sample (n=15?), to get an idea of $\\hat p$, hoping $\\hat p$ is far of 0.5. That will let you pick a smaller $n$.\n\n\n\n\nAssume the worst case, which is $p=0.5$ and determine $n$ on that basis.\n\n\n\n\n\nAnd as far as a “significant test\", I am not sure what the null could be? Probably something like $H0: p \\le p_0, H1: p \\gt p_0$? But what $p_0$? Again, the worst case is $p_0 = 0.5$. But we do not know $p$, so we have no idea of how large (or small) an effect we are trying to find? So the only answer would be to run a small exploratory study, to estimate $p$, and then compute a sample size based on that estimate.\n\nNote that the 3 “questions” (estimate of the mean reliability, estimate of the variance reliability, and statistical test) most likely require 3 different $n$’s. So then the answer is \"pick the max\"...\n\n\n\n\nNow we can relax the initial assumption, by simply assuming that each machine $X_i$ follows a Bernoulli distribution with probability (of working) $p_i$; but $p_i$ remains constant between measurements on a given machine.\n\nHere, I would use a two-stage sampling plan; test n machines k times each. You can then estimate the means of the n machines, and then of the population. And you can use a two-way ANOVA to separate the variance within the machines from the variance between machines.\n\nI have to say that I am unsure of how to derive formulas expressing $n$ and $k$ as a function of $E_{mu}$ or $E_{sigma}$.\n\n\n\n\nLast, if we now assume that $p_i$ is itself a random variable (which is what the OP has done, when using a Beta-Binomial model: but nothing in the question implies this scenario?!), I have to say that I give up trying to make sense of such a scenario.", "answer_url": "https://stats.stackexchange.com/a/676891", "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-08-16T21:37:58+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": 676888, "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-08-16T21:37:58+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "73406A70-9203-4045-AF24-09AB9C30742E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/73406A70-9203-4045-AF24-09AB9C30742E/view-source"}, {"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-08-17T02:39:48+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "A231D113-2ECC-4E6B-ADA4-769EBEFADDE6", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A231D113-2ECC-4E6B-ADA4-769EBEFADDE6/view-source"}], "score": 3, "updated_at": "2026-08-17T02:39:48+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 676891, "answers": [{"answer_html": "

As comments to the question already mentioned, the question is ill-posed. The first part implies an estimation problem (“estimate the mean and variance of machine reliability of the population”). But for that, we would need to know the desired margins of error $E_{\\mu}, E_{\\sigma}$, which are not in the problem statement.
\nThe last sentence however suggests a statistical test (“a statistically significant result”), which would require a null hypothesis (absent?), as well as a significance level and a desired power...
\nBut, there may be some ways to get “near” a solution? Below is not an “answer”, but more a way to look at this ill-posed problem and try to make some sense of it.

\n

I will start by postulating that each machine $X_i$ follows a Bernoulli distribution $\\text {Bernoulli}(p_i)$. I will then add a “strong” assumption, which simplifies the problem (and later, will relax it), namely that $p_i=p, \\forall i$ (Is that what the OP meant when he added in a comment “we assume that there is a single DGP (data generating process) which governs the behavior of all machines”??).
\nIn that case, as hinted by @whuber, sampling n machines once, or one machine n times provides the exact same information. A sample of size n will be binomial $B(n,p)$ distributed.
\nWe can now use our "favorite" confidence interval method (Wald? -probably not, Wilson score?, Clopper-Pearson -my favorite-), and obtain a CI. In all cases, the half-width of the CI (which is the margin of error) depends on $n$, and so we can generate an equation which gives $n$ as a function of $E_{\\mu}$.
\nIf we note the CI of $p$ as $[p_L,p_U]$, then the low bound of the CI of the variance will be $n \\cdot p_L \\cdot (1-p_L)$ and the upper bound will be $n \\cdot p_U \\cdot (1-p_U)$. Unless the CI for $p$ includes $p=.5$, in which case the worse case variance is simply the peak value $\\frac n 4$. And again, given a desired margin of error $E_{\\sigma}$, you can derive a formula for $n$ as a function of $E_{\\sigma}$.
\nThen pick the $n$ which satisfies both desired margins of error.
\nThis is all well and good, but said formulas also contain $p$, and we have no idea of the value of $p$. Two options:

\n\n

And as far as a “significant test", I am not sure what the null could be? Probably something like $H0: p \\le p_0, H1: p \\gt p_0$? But what $p_0$? Again, the worst case is $p_0 = 0.5$. But we do not know $p$, so we have no idea of how large (or small) an effect we are trying to find? So the only answer would be to run a small exploratory study, to estimate $p$, and then compute a sample size based on that estimate.
\nNote that the 3 “questions” (estimate of the mean reliability, estimate of the variance reliability, and statistical test) most likely require 3 different $n$’s. So then the answer is "pick the max"...

\n

Now we can relax the initial assumption, by simply assuming that each machine $X_i$ follows a Bernoulli distribution with probability (of working) $p_i$; but $p_i$ remains constant between measurements on a given machine.
\nHere, I would use a two-stage sampling plan; test n machines k times each. You can then estimate the means of the n machines, and then of the population. And you can use a two-way ANOVA to separate the variance within the machines from the variance between machines.
\nI have to say that I am unsure of how to derive formulas expressing $n$ and $k$ as a function of $E_{mu}$ or $E_{sigma}$.

\n

Last, if we now assume that $p_i$ is itself a random variable (which is what the OP has done, when using a Beta-Binomial model: but nothing in the question implies this scenario?!), I have to say that I give up trying to make sense of such a scenario.

\n", "answer_id": 676891, "answer_text": "As comments to the question already mentioned, the question is ill-posed. The first part implies an estimation problem (“estimate the mean and variance of machine reliability of the population”). But for that, we would need to know the desired margins of error $E_{\\mu}, E_{\\sigma}$, which are not in the problem statement.\n\nThe last sentence however suggests a statistical test (“a statistically significant result”), which would require a null hypothesis (absent?), as well as a significance level and a desired power...\n\nBut, there may be some ways to get “near” a solution? Below is not an “answer”, but more a way to look at this ill-posed problem and try to make some sense of it.\n\n\n\n\nI will start by postulating that each machine $X_i$ follows a Bernoulli distribution $\\text {Bernoulli}(p_i)$. I will then add a “strong” assumption, which simplifies the problem (and later, will relax it), namely that $p_i=p, \\forall i$ (Is that what the OP meant when he added in a comment “we assume that there is a single DGP (data generating process) which governs the behavior of all machines”??).\n\nIn that case, as hinted by @whuber, sampling n machines once, or one machine n times provides the exact same information. A sample of size n will be binomial $B(n,p)$ distributed.\n\nWe can now use our \"favorite\" confidence interval method (Wald? -probably not, Wilson score?, Clopper-Pearson -my favorite-), and obtain a CI. In all cases, the half-width of the CI (which is the margin of error) depends on $n$, and so we can generate an equation which gives $n$ as a function of $E_{\\mu}$.\n\nIf we note the CI of $p$ as $[p_L,p_U]$, then the low bound of the CI of the variance will be $n \\cdot p_L \\cdot (1-p_L)$ and the upper bound will be $n \\cdot p_U \\cdot (1-p_U)$. Unless the CI for $p$ includes $p=.5$, in which case the worse case variance is simply the peak value $\\frac n 4$. And again, given a desired margin of error $E_{\\sigma}$, you can derive a formula for $n$ as a function of $E_{\\sigma}$.\n\nThen pick the $n$ which satisfies both desired margins of error.\n\nThis is all well and good, but said formulas also contain $p$, and we have no idea of the value of $p$. Two options:\n\n\n\n\n\nRun a small exploratory sample (n=15?), to get an idea of $\\hat p$, hoping $\\hat p$ is far of 0.5. That will let you pick a smaller $n$.\n\n\n\n\nAssume the worst case, which is $p=0.5$ and determine $n$ on that basis.\n\n\n\n\n\nAnd as far as a “significant test\", I am not sure what the null could be? Probably something like $H0: p \\le p_0, H1: p \\gt p_0$? But what $p_0$? Again, the worst case is $p_0 = 0.5$. But we do not know $p$, so we have no idea of how large (or small) an effect we are trying to find? So the only answer would be to run a small exploratory study, to estimate $p$, and then compute a sample size based on that estimate.\n\nNote that the 3 “questions” (estimate of the mean reliability, estimate of the variance reliability, and statistical test) most likely require 3 different $n$’s. So then the answer is \"pick the max\"...\n\n\n\n\nNow we can relax the initial assumption, by simply assuming that each machine $X_i$ follows a Bernoulli distribution with probability (of working) $p_i$; but $p_i$ remains constant between measurements on a given machine.\n\nHere, I would use a two-stage sampling plan; test n machines k times each. You can then estimate the means of the n machines, and then of the population. And you can use a two-way ANOVA to separate the variance within the machines from the variance between machines.\n\nI have to say that I am unsure of how to derive formulas expressing $n$ and $k$ as a function of $E_{mu}$ or $E_{sigma}$.\n\n\n\n\nLast, if we now assume that $p_i$ is itself a random variable (which is what the OP has done, when using a Beta-Binomial model: but nothing in the question implies this scenario?!), I have to say that I give up trying to make sense of such a scenario.", "answer_url": "https://stats.stackexchange.com/a/676891", "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-08-16T21:37:58+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": 676888, "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-08-16T21:37:58+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "73406A70-9203-4045-AF24-09AB9C30742E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/73406A70-9203-4045-AF24-09AB9C30742E/view-source"}, {"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-08-17T02:39:48+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "A231D113-2ECC-4E6B-ADA4-769EBEFADDE6", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A231D113-2ECC-4E6B-ADA4-769EBEFADDE6/view-source"}], "score": 3, "updated_at": "2026-08-17T02:39:48+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "adamkostanov", "question_author_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "question_author_user_type": "registered", "question_created_at": "2026-08-16T15:53:10+00:00", "question_html": "

In most introductory sampling problems involving proportions, it is typically assumed that there is no variability within a given unit. For example, if we want to know what percent of a population has a car, we assume that when we select a person, they either have or do not have a car.

\n

I have come across this problem:

\n
\n

There is a population of many machines. On the same day, a given\nmachine can sometimes work and sometimes not work. An experiment is\nbeing planned to estimate the mean and variance of machine reliability\nof the population based on a statistical sample. You need to\ndecide the sample size: how many machines to test and how many times to repeat tests on each machine?

\n
\n
\n

Assume the cost of selecting any machine is constant, the cost of each test is constant, any tests are not destructive (i.e. a test on a machine does not interfere with the future performance of the machine). Also assume that the future performance of a given machine does not depend on past performance of that machine.

\n
\n

Assuming iid, I thought a Beta-Binomial model can describe this situation:

\n

$$\\theta_i \\overset{iid}{\\sim} \\text{Beta}(\\alpha,\\beta), \\qquad Y_i \\mid \\theta_i \\sim \\text{Binomial}(n_i,\\theta_i), \\qquad i=1,\\dots,M$$

\n

But I am unsure how to decide the number of machines to test and how many times to test each machine.

\n

Intuitively, I think the underlying values of $\\alpha,\\beta$ influence this decision. For example, suppose you have a fixed budget of $k$ tests. If the population has low variability, then you can test many machines a small number of times. If the population has high variability, you are pushed towards testing fewer machines but testing each machine more time.

\n

How is this problem usually dealt with in statistics? (I was thinking of doing a simulation for different values of $\\alpha,\\beta$ and seeing how different sample sizes influence coverage probability and estimation error).

\n", "question_id": 676888, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "In most introductory sampling problems involving proportions, it is typically assumed that there is no variability within a given unit. For example, if we want to know what percent of a population has a car, we assume that when we select a person, they either have or do not have a car.\n\n\n\n\nI have come across this problem:\n\n\n\n\n\n\n\nThere is a population of many machines. On the same day, a given\nmachine can sometimes work and sometimes not work. An experiment is\nbeing planned to estimate the mean and variance of machine reliability\nof the population based on a statistical sample. You need to\ndecide the sample size: how many machines to test and how many times to repeat tests on each machine?\n\n\n\n\n\n\n\n\n\n\nAssume the cost of selecting any machine is constant, the cost of each test is constant, any tests are not destructive (i.e. a test on a machine does not interfere with the future performance of the machine). Also assume that the future performance of a given machine does not depend on past performance of that machine.\n\n\n\n\n\n\n\nAssuming iid, I thought a Beta-Binomial model can describe this situation:\n\n\n\n\n$$\\theta_i \\overset{iid}{\\sim} \\text{Beta}(\\alpha,\\beta), \\qquad Y_i \\mid \\theta_i \\sim \\text{Binomial}(n_i,\\theta_i), \\qquad i=1,\\dots,M$$\n\n\n\n\nBut I am unsure how to decide the number of machines to test and how many times to test each machine.\n\n\n\n\nIntuitively, I think the underlying values of $\\alpha,\\beta$ influence this decision. For example, suppose you have a fixed budget of $k$ tests. If the population has low variability, then you can test many machines a small number of times. If the population has high variability, you are pushed towards testing fewer machines but testing each machine more time.\n\n\n\n\nHow is this problem usually dealt with in statistics? (I was thinking of doing a simulation for different values of $\\alpha,\\beta$ and seeing how different sample sizes influence coverage probability and estimation error).", "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-16T15:53:10+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "46B07BB5-8769-4D34-BFAE-901D1577D84D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/46B07BB5-8769-4D34-BFAE-901D1577D84D/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-17T00:26:36+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "30CB04CD-0F87-42D3-BB90-57372D127371", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/30CB04CD-0F87-42D3-BB90-57372D127371/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-08-17T01:09:12+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "BCC2F1C4-CD60-4328-84FF-267F2C42256D", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/BCC2F1C4-CD60-4328-84FF-267F2C42256D/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676888/sampling-units-that-can-vary-between-measurements", "split": "train", "split_group": "a39f745df58a20526c5c05fcb16de49bc95ab0727f3dc0428b8554d559714bc7", "tags": ["sampling"], "thread_id": "stats:676888", "title": "Sampling units that can vary between measurements"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I am linking two public datasets of vehicle incidents published by the same regulator (NHTSA) through entirely separate channels. One is incident filings submitted by manufacturers under a standing order. The other is consumer complaints filed by vehicle owners. Neither source publishes a key identifying an individual vehicle or an individual event, and no external record states which filing corresponds to which complaint. There is no labelled data and no way to obtain any.\n\n\n\n\nThe shared fields\n\n\n\n\n\nReporting entity name. Free text, formatted differently in each source, so it needs normalization and fuzzy comparison.\n\n\n\n\nAn 11 character VIN prefix. WMI, VDS, check digit, model year, plant. Characters 12 to 17, the serial identifying one specific vehicle, are published by neither source. A shared prefix means \"same configuration, model year and plant\", which thousands of vehicles share.\n\n\n\n\nIncident date. Filings publish month only (for example \"APR-2026\"). Complaints carry a full date. The finest shared resolution is the month.\n\n\n\n\n\nWhat I built\n\n\n\n\nA deterministic gate. Two records link only if all three hold:\n\n\n\n\n\nsame reporting entity after normalization,\n\n\n\n\nsame 11 character VIN prefix,\n\n\n\n\nincident months within 1 of each other.\n\n\n\n\n\nEntity name similarity is banded at 90 and above for an automatic merge, 80 to 89 for a flagged candidate never merged unattended, below 80 rejected. No similarity score overrides any of the three conditions. The design deliberately biases toward non-linkage, because a false link fabricates an apparent difference between two unrelated events. For scale, against 1,181 independent records the gate produces 44 links in one subpopulation and 0 in the other.\n\n\n\n\nThree weaknesses I can see in my own approach\n\n\n\n\n\nThe thresholds are asserted, not estimated. The 90/80 bands and the one month tolerance were carried over from earlier work, not fitted to this data. I can defend them as conservative, not as optimal.\n\n\n\n\nThe gate gives a binary decision with no calibrated uncertainty. Every output is labelled low confidence, but that is a word, not a number, and I have no principled route to turning it into one.\n\n\n\n\nI have traded recall for precision without being able to quantify either. I know the direction of the bias. I do not know its size.\n\n\n\n\n\nQuestions\n\n\n\n\n\nWhen no labelled data can exist, is a deterministic gate the defensible choice, or is it just an undeclared probabilistic model with its parameters hidden in threshold constants?\n\n\n\n\nCan a false negative rate be bounded at all in this setting, or is \"recall is not estimable here\" the honest thing to state and stop?\n\n\n\n\nDoes the one month tolerance earn the candidate space it adds? With month only precision on one side, plus or minus one month roughly triples the candidate window, and I cannot tell whether that buys real recall or only noise.\n\n\n\n\n\nI have posted my own current reasoning as an answer below and would like it argued with.\n\n\n\n\nI am asking about method only. The code built on this linkage computes no match rate as a claim about anyone's behaviour, produces no conduct claims, and names no organization as having done anything. It reports differences between two cited documents and stops. I would rather be told this approach does not hold up than be reassured that it does.", "record_id": "Scientific-Statistics-QA:stats:676889", "selected_answer": {"answer_html": "

This is my own current reasoning, posted so it can be argued with rather than because I think it settles anything. I am not confident in it.

\n

On the gate versus a probabilistic model

\n

The argument for the gate is that with no labelled data, any probabilistic score here would be a monotone rescaling of my own modelling choices rather than a measurement of anything. EM would still converge and still report m and u, but those values would be driven by my choice of comparison functions and by the class balance I implicitly assumed, not by evidence in the data. A threshold constant at least has the virtue of being visible in a config file, where a reviewer can see it and disagree with it. A fitted parameter that is really an assumption is harder to audit, not easier.

\n

I am aware this is close to an admission that my thresholds are unvalidated assumptions, and I am not sure "at least they are visible" is a sufficient defence. That is the part of question 1 I would most like challenged.

\n

On bounding recall

\n

I think the honest position is that recall is not estimable here. Bounding a false negative rate requires knowing how many true matches exist, and the only route to that quantity in this setting is the linkage itself. Anything I reported would be circular. So I state that recall is unknown rather than estimate it badly, and I accept that this makes the output weaker than a properly validated linkage would be.

\n

On the one month tolerance

\n

My justification is precision honesty rather than performance. One side of the comparison carries month precision only, so a day level gate would assert a precision the data does not have. Plus or minus one month covers the boundary case where an incident near a month end is filed in the adjacent month. I have not tested whether it adds more true links than false candidates, and I do not currently know how I would test that without labels, which is why it is question 3.

\n", "answer_id": 676890, "answer_text": "This is my own current reasoning, posted so it can be argued with rather than because I think it settles anything. I am not confident in it.\n\n\n\n\nOn the gate versus a probabilistic model\n\n\n\n\nThe argument for the gate is that with no labelled data, any probabilistic score here would be a monotone rescaling of my own modelling choices rather than a measurement of anything. EM would still converge and still report m and u, but those values would be driven by my choice of comparison functions and by the class balance I implicitly assumed, not by evidence in the data. A threshold constant at least has the virtue of being visible in a config file, where a reviewer can see it and disagree with it. A fitted parameter that is really an assumption is harder to audit, not easier.\n\n\n\n\nI am aware this is close to an admission that my thresholds are unvalidated assumptions, and I am not sure \"at least they are visible\" is a sufficient defence. That is the part of question 1 I would most like challenged.\n\n\n\n\nOn bounding recall\n\n\n\n\nI think the honest position is that recall is not estimable here. Bounding a false negative rate requires knowing how many true matches exist, and the only route to that quantity in this setting is the linkage itself. Anything I reported would be circular. So I state that recall is unknown rather than estimate it badly, and I accept that this makes the output weaker than a properly validated linkage would be.\n\n\n\n\nOn the one month tolerance\n\n\n\n\nMy justification is precision honesty rather than performance. One side of the comparison carries month precision only, so a day level gate would assert a precision the data does not have. Plus or minus one month covers the boundary case where an incident near a month end is filed in the adjacent month. I have not tested whether it adds more true links than false candidates, and I do not currently know how I would test that without labels, which is why it is question 3.", "answer_url": "https://stats.stackexchange.com/a/676890", "author": "Jak Potvin", "author_url": "https://stats.stackexchange.com/users/515560/jak-potvin", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-16T20:57:47+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": 676889, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Jak Potvin", "profile_url": "https://stats.stackexchange.com/users/515560/jak-potvin", "user_type": "registered"}, "created_at": "2026-08-16T20:57:47+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "4DE7F50B-3939-4666-8116-291309C1545E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4DE7F50B-3939-4666-8116-291309C1545E/view-source"}], "score": 2, "updated_at": "2026-08-16T20:57:47+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

This is my own current reasoning, posted so it can be argued with rather than because I think it settles anything. I am not confident in it.

\n

On the gate versus a probabilistic model

\n

The argument for the gate is that with no labelled data, any probabilistic score here would be a monotone rescaling of my own modelling choices rather than a measurement of anything. EM would still converge and still report m and u, but those values would be driven by my choice of comparison functions and by the class balance I implicitly assumed, not by evidence in the data. A threshold constant at least has the virtue of being visible in a config file, where a reviewer can see it and disagree with it. A fitted parameter that is really an assumption is harder to audit, not easier.

\n

I am aware this is close to an admission that my thresholds are unvalidated assumptions, and I am not sure "at least they are visible" is a sufficient defence. That is the part of question 1 I would most like challenged.

\n

On bounding recall

\n

I think the honest position is that recall is not estimable here. Bounding a false negative rate requires knowing how many true matches exist, and the only route to that quantity in this setting is the linkage itself. Anything I reported would be circular. So I state that recall is unknown rather than estimate it badly, and I accept that this makes the output weaker than a properly validated linkage would be.

\n

On the one month tolerance

\n

My justification is precision honesty rather than performance. One side of the comparison carries month precision only, so a day level gate would assert a precision the data does not have. Plus or minus one month covers the boundary case where an incident near a month end is filed in the adjacent month. I have not tested whether it adds more true links than false candidates, and I do not currently know how I would test that without labels, which is why it is question 3.

\n", "answer_id": 676890, "answer_text": "This is my own current reasoning, posted so it can be argued with rather than because I think it settles anything. I am not confident in it.\n\n\n\n\nOn the gate versus a probabilistic model\n\n\n\n\nThe argument for the gate is that with no labelled data, any probabilistic score here would be a monotone rescaling of my own modelling choices rather than a measurement of anything. EM would still converge and still report m and u, but those values would be driven by my choice of comparison functions and by the class balance I implicitly assumed, not by evidence in the data. A threshold constant at least has the virtue of being visible in a config file, where a reviewer can see it and disagree with it. A fitted parameter that is really an assumption is harder to audit, not easier.\n\n\n\n\nI am aware this is close to an admission that my thresholds are unvalidated assumptions, and I am not sure \"at least they are visible\" is a sufficient defence. That is the part of question 1 I would most like challenged.\n\n\n\n\nOn bounding recall\n\n\n\n\nI think the honest position is that recall is not estimable here. Bounding a false negative rate requires knowing how many true matches exist, and the only route to that quantity in this setting is the linkage itself. Anything I reported would be circular. So I state that recall is unknown rather than estimate it badly, and I accept that this makes the output weaker than a properly validated linkage would be.\n\n\n\n\nOn the one month tolerance\n\n\n\n\nMy justification is precision honesty rather than performance. One side of the comparison carries month precision only, so a day level gate would assert a precision the data does not have. Plus or minus one month covers the boundary case where an incident near a month end is filed in the adjacent month. I have not tested whether it adds more true links than false candidates, and I do not currently know how I would test that without labels, which is why it is question 3.", "answer_url": "https://stats.stackexchange.com/a/676890", "author": "Jak Potvin", "author_url": "https://stats.stackexchange.com/users/515560/jak-potvin", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-16T20:57:47+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": 676889, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Jak Potvin", "profile_url": "https://stats.stackexchange.com/users/515560/jak-potvin", "user_type": "registered"}, "created_at": "2026-08-16T20:57:47+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "4DE7F50B-3939-4666-8116-291309C1545E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4DE7F50B-3939-4666-8116-291309C1545E/view-source"}], "score": 2, "updated_at": "2026-08-16T20:57:47+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Jak Potvin", "question_author_url": "https://stats.stackexchange.com/users/515560/jak-potvin", "question_author_user_type": "registered", "question_created_at": "2026-08-16T20:52:59+00:00", "question_html": "

I am linking two public datasets of vehicle incidents published by the same regulator (NHTSA) through entirely separate channels. One is incident filings submitted by manufacturers under a standing order. The other is consumer complaints filed by vehicle owners. Neither source publishes a key identifying an individual vehicle or an individual event, and no external record states which filing corresponds to which complaint. There is no labelled data and no way to obtain any.

\n

The shared fields

\n
    \n
  1. Reporting entity name. Free text, formatted differently in each source, so it needs normalization and fuzzy comparison.
  2. \n
  3. An 11 character VIN prefix. WMI, VDS, check digit, model year, plant. Characters 12 to 17, the serial identifying one specific vehicle, are published by neither source. A shared prefix means "same configuration, model year and plant", which thousands of vehicles share.
  4. \n
  5. Incident date. Filings publish month only (for example "APR-2026"). Complaints carry a full date. The finest shared resolution is the month.
  6. \n
\n

What I built

\n

A deterministic gate. Two records link only if all three hold:

\n\n

Entity name similarity is banded at 90 and above for an automatic merge, 80 to 89 for a flagged candidate never merged unattended, below 80 rejected. No similarity score overrides any of the three conditions. The design deliberately biases toward non-linkage, because a false link fabricates an apparent difference between two unrelated events. For scale, against 1,181 independent records the gate produces 44 links in one subpopulation and 0 in the other.

\n

Three weaknesses I can see in my own approach

\n
    \n
  1. The thresholds are asserted, not estimated. The 90/80 bands and the one month tolerance were carried over from earlier work, not fitted to this data. I can defend them as conservative, not as optimal.
  2. \n
  3. The gate gives a binary decision with no calibrated uncertainty. Every output is labelled low confidence, but that is a word, not a number, and I have no principled route to turning it into one.
  4. \n
  5. I have traded recall for precision without being able to quantify either. I know the direction of the bias. I do not know its size.
  6. \n
\n

Questions

\n
    \n
  1. When no labelled data can exist, is a deterministic gate the defensible choice, or is it just an undeclared probabilistic model with its parameters hidden in threshold constants?
  2. \n
  3. Can a false negative rate be bounded at all in this setting, or is "recall is not estimable here" the honest thing to state and stop?
  4. \n
  5. Does the one month tolerance earn the candidate space it adds? With month only precision on one side, plus or minus one month roughly triples the candidate window, and I cannot tell whether that buys real recall or only noise.
  6. \n
\n

I have posted my own current reasoning as an answer below and would like it argued with.

\n

I am asking about method only. The code built on this linkage computes no match rate as a claim about anyone's behaviour, produces no conduct claims, and names no organization as having done anything. It reports differences between two cited documents and stops. I would rather be told this approach does not hold up than be reassured that it does.

\n", "question_id": 676889, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "I am linking two public datasets of vehicle incidents published by the same regulator (NHTSA) through entirely separate channels. One is incident filings submitted by manufacturers under a standing order. The other is consumer complaints filed by vehicle owners. Neither source publishes a key identifying an individual vehicle or an individual event, and no external record states which filing corresponds to which complaint. There is no labelled data and no way to obtain any.\n\n\n\n\nThe shared fields\n\n\n\n\n\nReporting entity name. Free text, formatted differently in each source, so it needs normalization and fuzzy comparison.\n\n\n\n\nAn 11 character VIN prefix. WMI, VDS, check digit, model year, plant. Characters 12 to 17, the serial identifying one specific vehicle, are published by neither source. A shared prefix means \"same configuration, model year and plant\", which thousands of vehicles share.\n\n\n\n\nIncident date. Filings publish month only (for example \"APR-2026\"). Complaints carry a full date. The finest shared resolution is the month.\n\n\n\n\n\nWhat I built\n\n\n\n\nA deterministic gate. Two records link only if all three hold:\n\n\n\n\n\nsame reporting entity after normalization,\n\n\n\n\nsame 11 character VIN prefix,\n\n\n\n\nincident months within 1 of each other.\n\n\n\n\n\nEntity name similarity is banded at 90 and above for an automatic merge, 80 to 89 for a flagged candidate never merged unattended, below 80 rejected. No similarity score overrides any of the three conditions. The design deliberately biases toward non-linkage, because a false link fabricates an apparent difference between two unrelated events. For scale, against 1,181 independent records the gate produces 44 links in one subpopulation and 0 in the other.\n\n\n\n\nThree weaknesses I can see in my own approach\n\n\n\n\n\nThe thresholds are asserted, not estimated. The 90/80 bands and the one month tolerance were carried over from earlier work, not fitted to this data. I can defend them as conservative, not as optimal.\n\n\n\n\nThe gate gives a binary decision with no calibrated uncertainty. Every output is labelled low confidence, but that is a word, not a number, and I have no principled route to turning it into one.\n\n\n\n\nI have traded recall for precision without being able to quantify either. I know the direction of the bias. I do not know its size.\n\n\n\n\n\nQuestions\n\n\n\n\n\nWhen no labelled data can exist, is a deterministic gate the defensible choice, or is it just an undeclared probabilistic model with its parameters hidden in threshold constants?\n\n\n\n\nCan a false negative rate be bounded at all in this setting, or is \"recall is not estimable here\" the honest thing to state and stop?\n\n\n\n\nDoes the one month tolerance earn the candidate space it adds? With month only precision on one side, plus or minus one month roughly triples the candidate window, and I cannot tell whether that buys real recall or only noise.\n\n\n\n\n\nI have posted my own current reasoning as an answer below and would like it argued with.\n\n\n\n\nI am asking about method only. The code built on this linkage computes no match rate as a claim about anyone's behaviour, produces no conduct claims, and names no organization as having done anything. It reports differences between two cited documents and stops. I would rather be told this approach does not hold up than be reassured that it does.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Jak Potvin", "profile_url": "https://stats.stackexchange.com/users/515560/jak-potvin", "user_type": "registered"}, "created_at": "2026-08-16T20:52:59+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "3F7FDCA8-4899-4D45-84D3-8551EC997D6E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3F7FDCA8-4899-4D45-84D3-8551EC997D6E/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-17T04:56:46+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "6EECAFC6-1B72-400E-AECE-E276505C081A", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/6EECAFC6-1B72-400E-AECE-E276505C081A/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676889/is-a-deterministic-linkage-gate-the-honest-choice-when-no-labelled-data-exists", "split": "train", "split_group": "cb5a0cb6eee8771a26947de9e15dd518b7b07a08f646a288f72ed2c89f723e6b", "tags": ["model-evaluation", "unsupervised-learning", "precision-recall", "record-linkage"], "thread_id": "stats:676889", "title": "Is a deterministic linkage gate the honest choice when no labelled data exists, and can its false negative rate be bounded at all?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I use regression by zero intercept in Microsoft Excel that it results:\n\n\n\n\nRegression Statistics\n\nMultiple R 0.999515949\n\nR Square 0.999032132\n\nAdjusted R Square 0.945993029\n\nStandard Error 324445.7038\n\nObservations 28\n\n\n\n\nWhy Adjusted R Square does not consistent to formula (Adjusted R² = 1 - (1 - R²) × (df_total / df_residual)) when intercept is zero?", "record_id": "Scientific-Statistics-QA:stats:676899", "selected_answer": {"answer_html": "

There's an aphorism that "friends don't let friends use Excel for statistics". I know of two built-in ways to conduct linear regression in Excel: using the LINEST function, which does not calculate an adjusted $\\text{R}^2$, and using the Analysis ToolPak.

\n

Documentation for the latter is extremely sparse and only mentions that it uses LINEST internally. We're left guessing as to what formula is actually being used to adjust $\\text{R}^2$.

\n

Using some random examples from R -- which I would let friends use for statistics -- we can show that the Analysis ToolPak doesn't match any expected result:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Model$n$$\\text{R}^2$Correct adj. $\\text{R}^2$ToolPak adj. $\\text{R}^2$
lm(mpg~0+disp, data=mtcars)320.54121590.52641640.5089578
lm(hp~0+wt, data=mtcars)320.9011150.89792510.8688569
lm(Temp~0+Wind, data=airquality)1530.84257210.84153640.8359932
lm(weight~0+Time, data=ChickWeight)5780.91331990.91316960.9115868
\n

To be sure, these models are nonsensical & were simply chosen to provide values across a range of $n$ and $\\text{R}^2$. The correct values as calculated by R all correspond to the expected adjustment of $1-(1-\\text{R}^2)\\frac{n}{n-k}$ (these models all have $k=1$).

\n

The ToolPak values are wrong, and they are off by a very specific amount: something like $\\text{R}^2-\\frac{1}{n-1}$ is being calculated here. While that formula reproduces these results it doesn't generalize to larger $k$ nor to your data though (which might use $k>1$?). There could be some continuing trend approximate to $\\sqrt k$, but frankly it's clear that (i) the Analysis ToolPak's adjusted $\\text{R}^2$ is wrong, and (ii) they won't even tell you what they implemented or intended, so I'd not spend any more time or effort on this.

\n", "answer_id": 676903, "answer_text": "There's an aphorism that \"friends don't let friends use Excel for statistics\". I know of two built-in ways to conduct linear regression in Excel: using the LINEST (https://support.microsoft.com/en-us/excel/functions/linest-function) function, which does not calculate an adjusted $\\text{R}^2$, and using the Analysis ToolPak (https://support.microsoft.com/en-US/Excel/use-the-analysis-toolpak-to-perform-complex-data-analysis).\n\n\n\n\nDocumentation for the latter is extremely sparse and only mentions that it uses LINEST internally. We're left guessing as to what formula is actually being used to adjust $\\text{R}^2$.\n\n\n\n\nUsing some random examples from R (https://www.r-project.org/) -- which I would let friends use for statistics -- we can show that the Analysis ToolPak doesn't match any expected result:\n\n\n\n\n\n\n\n\n\nModel\n$n$\n$\\text{R}^2$\nCorrect adj. $\\text{R}^2$\nToolPak adj. $\\text{R}^2$\n\n\n\n\n\n\n\n\n\tlm(mpg~0+disp, data=mtcars)\n\t32\n\t0.5412159\n\t0.5264164\n\t0.5089578\n\n\n\n\n\n\n\tlm(hp~0+wt, data=mtcars)\n\t32\n\t0.901115\n\t0.8979251\n\t0.8688569\n\n\n\n\n\n\n\tlm(Temp~0+Wind, data=airquality)\n\t153\n\t0.8425721\n\t0.8415364\n\t0.8359932\n\n\n\n\n\n\n\tlm(weight~0+Time, data=ChickWeight)\n\t578\n\t0.9133199\n\t0.9131696\n\t0.9115868\n\n\n\n\n\n\n\n\n\nTo be sure, these models are nonsensical & were simply chosen to provide values across a range of $n$ and $\\text{R}^2$. The correct values as calculated by R all correspond to the expected adjustment of $1-(1-\\text{R}^2)\\frac{n}{n-k}$ (these models all have $k=1$).\n\n\n\n\nThe ToolPak values are wrong, and they are off by a very specific amount: something like $\\text{R}^2-\\frac{1}{n-1}$ is being calculated here. While that formula reproduces these results it doesn't generalize to larger $k$ nor to your data though (which might use $k>1$?). There could be some continuing trend approximate to $\\sqrt k$, but frankly it's clear that (i) the Analysis ToolPak's adjusted $\\text{R}^2$ is wrong, and (ii) they won't even tell you what they implemented or intended, so I'd not spend any more time or effort on this.", "answer_url": "https://stats.stackexchange.com/a/676903", "author": "PBulls", "author_url": "https://stats.stackexchange.com/users/353280/pbulls", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-18T12:26:36+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": 676899, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "PBulls", "profile_url": "https://stats.stackexchange.com/users/353280/pbulls", "user_type": "registered"}, "created_at": "2026-08-18T12:26:36+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "93DC0B5D-18EC-4F8A-9544-5B2E3DECB58A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/93DC0B5D-18EC-4F8A-9544-5B2E3DECB58A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-08-19T13:52:03+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "B561B19E-261B-41CF-BC62-DDC6CF36ADA4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B561B19E-261B-41CF-BC62-DDC6CF36ADA4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-08-19T14:03:44+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "DA54B3B8-9E8D-4A67-AF44-D2CD2D4E4F74", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DA54B3B8-9E8D-4A67-AF44-D2CD2D4E4F74/view-source"}], "score": 9, "updated_at": "2026-08-19T14:03:44+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

There's an aphorism that "friends don't let friends use Excel for statistics". I know of two built-in ways to conduct linear regression in Excel: using the LINEST function, which does not calculate an adjusted $\\text{R}^2$, and using the Analysis ToolPak.

\n

Documentation for the latter is extremely sparse and only mentions that it uses LINEST internally. We're left guessing as to what formula is actually being used to adjust $\\text{R}^2$.

\n

Using some random examples from R -- which I would let friends use for statistics -- we can show that the Analysis ToolPak doesn't match any expected result:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Model$n$$\\text{R}^2$Correct adj. $\\text{R}^2$ToolPak adj. $\\text{R}^2$
lm(mpg~0+disp, data=mtcars)320.54121590.52641640.5089578
lm(hp~0+wt, data=mtcars)320.9011150.89792510.8688569
lm(Temp~0+Wind, data=airquality)1530.84257210.84153640.8359932
lm(weight~0+Time, data=ChickWeight)5780.91331990.91316960.9115868
\n

To be sure, these models are nonsensical & were simply chosen to provide values across a range of $n$ and $\\text{R}^2$. The correct values as calculated by R all correspond to the expected adjustment of $1-(1-\\text{R}^2)\\frac{n}{n-k}$ (these models all have $k=1$).

\n

The ToolPak values are wrong, and they are off by a very specific amount: something like $\\text{R}^2-\\frac{1}{n-1}$ is being calculated here. While that formula reproduces these results it doesn't generalize to larger $k$ nor to your data though (which might use $k>1$?). There could be some continuing trend approximate to $\\sqrt k$, but frankly it's clear that (i) the Analysis ToolPak's adjusted $\\text{R}^2$ is wrong, and (ii) they won't even tell you what they implemented or intended, so I'd not spend any more time or effort on this.

\n", "answer_id": 676903, "answer_text": "There's an aphorism that \"friends don't let friends use Excel for statistics\". I know of two built-in ways to conduct linear regression in Excel: using the LINEST (https://support.microsoft.com/en-us/excel/functions/linest-function) function, which does not calculate an adjusted $\\text{R}^2$, and using the Analysis ToolPak (https://support.microsoft.com/en-US/Excel/use-the-analysis-toolpak-to-perform-complex-data-analysis).\n\n\n\n\nDocumentation for the latter is extremely sparse and only mentions that it uses LINEST internally. We're left guessing as to what formula is actually being used to adjust $\\text{R}^2$.\n\n\n\n\nUsing some random examples from R (https://www.r-project.org/) -- which I would let friends use for statistics -- we can show that the Analysis ToolPak doesn't match any expected result:\n\n\n\n\n\n\n\n\n\nModel\n$n$\n$\\text{R}^2$\nCorrect adj. $\\text{R}^2$\nToolPak adj. $\\text{R}^2$\n\n\n\n\n\n\n\n\n\tlm(mpg~0+disp, data=mtcars)\n\t32\n\t0.5412159\n\t0.5264164\n\t0.5089578\n\n\n\n\n\n\n\tlm(hp~0+wt, data=mtcars)\n\t32\n\t0.901115\n\t0.8979251\n\t0.8688569\n\n\n\n\n\n\n\tlm(Temp~0+Wind, data=airquality)\n\t153\n\t0.8425721\n\t0.8415364\n\t0.8359932\n\n\n\n\n\n\n\tlm(weight~0+Time, data=ChickWeight)\n\t578\n\t0.9133199\n\t0.9131696\n\t0.9115868\n\n\n\n\n\n\n\n\n\nTo be sure, these models are nonsensical & were simply chosen to provide values across a range of $n$ and $\\text{R}^2$. The correct values as calculated by R all correspond to the expected adjustment of $1-(1-\\text{R}^2)\\frac{n}{n-k}$ (these models all have $k=1$).\n\n\n\n\nThe ToolPak values are wrong, and they are off by a very specific amount: something like $\\text{R}^2-\\frac{1}{n-1}$ is being calculated here. While that formula reproduces these results it doesn't generalize to larger $k$ nor to your data though (which might use $k>1$?). There could be some continuing trend approximate to $\\sqrt k$, but frankly it's clear that (i) the Analysis ToolPak's adjusted $\\text{R}^2$ is wrong, and (ii) they won't even tell you what they implemented or intended, so I'd not spend any more time or effort on this.", "answer_url": "https://stats.stackexchange.com/a/676903", "author": "PBulls", "author_url": "https://stats.stackexchange.com/users/353280/pbulls", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-18T12:26:36+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": 676899, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "PBulls", "profile_url": "https://stats.stackexchange.com/users/353280/pbulls", "user_type": "registered"}, "created_at": "2026-08-18T12:26:36+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "93DC0B5D-18EC-4F8A-9544-5B2E3DECB58A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/93DC0B5D-18EC-4F8A-9544-5B2E3DECB58A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-08-19T13:52:03+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "B561B19E-261B-41CF-BC62-DDC6CF36ADA4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B561B19E-261B-41CF-BC62-DDC6CF36ADA4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-08-19T14:03:44+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "DA54B3B8-9E8D-4A67-AF44-D2CD2D4E4F74", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DA54B3B8-9E8D-4A67-AF44-D2CD2D4E4F74/view-source"}], "score": 9, "updated_at": "2026-08-19T14:03:44+00:00"}], "domain": "statistics", "external_links": ["https://support.microsoft.com/en-US/Excel/use-the-analysis-toolpak-to-perform-complex-data-analysis", "https://support.microsoft.com/en-us/excel/functions/linest-function", "https://www.r-project.org/"], "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": "Vahid Golmah", "question_author_url": "https://stats.stackexchange.com/users/432675/vahid-golmah", "question_author_user_type": "registered", "question_created_at": "2026-08-18T05:10:55+00:00", "question_html": "

I use regression by zero intercept in Microsoft Excel that it results:

\n

Regression Statistics
\nMultiple R 0.999515949
\nR Square 0.999032132
\nAdjusted R Square 0.945993029
\nStandard Error 324445.7038
\nObservations 28

\n

Why Adjusted R Square does not consistent to formula (Adjusted R² = 1 - (1 - R²) × (df_total / df_residual)) when intercept is zero?

\n", "question_id": 676899, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I use regression by zero intercept in Microsoft Excel that it results:\n\n\n\n\nRegression Statistics\n\nMultiple R 0.999515949\n\nR Square 0.999032132\n\nAdjusted R Square 0.945993029\n\nStandard Error 324445.7038\n\nObservations 28\n\n\n\n\nWhy Adjusted R Square does not consistent to formula (Adjusted R² = 1 - (1 - R²) × (df_total / df_residual)) when intercept is zero?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Vahid Golmah", "profile_url": "https://stats.stackexchange.com/users/432675/vahid-golmah", "user_type": "registered"}, "created_at": "2026-08-18T05:10:55+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "B5F0816F-E20A-412C-AC86-58884114256D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B5F0816F-E20A-412C-AC86-58884114256D/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Vahid Golmah", "profile_url": "https://stats.stackexchange.com/users/432675/vahid-golmah", "user_type": "registered"}, "created_at": "2026-08-18T05:18:25+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "254A44E0-51CC-4F34-B789-94B6180D1A2A", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/254A44E0-51CC-4F34-B789-94B6180D1A2A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-08-18T13:14:42+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "8E06618B-A441-49CC-946D-B89AA4BD7366", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8E06618B-A441-49CC-946D-B89AA4BD7366/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-08-18T13:19:58+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "AC12AE1F-D766-40AA-8F1A-C32B8F7218A5", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AC12AE1F-D766-40AA-8F1A-C32B8F7218A5/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-18T13:57:59+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "E88BE227-73CF-4706-AA38-663E2687C87B", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/E88BE227-73CF-4706-AA38-663E2687C87B/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676899/problem-of-adjusted-r-square-when-using-zero-intercept-in-excel-regression", "split": "train", "split_group": "1676a13191cdab660c91ff5ef1ce5ec0cc275c477dee41121d708751aec562b9", "tags": ["regression", "excel"], "thread_id": "stats:676899", "title": "Problem of adjusted R square when using zero intercept in Excel regression"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "
\n

but that control has already been shown to have reduced growth compared to another genotype where that process is disrupted

\n
\n

A control can have a different baseline than the treated group. But you need to move from t-tests to regressions, eg ANCOVA. A common strategy within the world of “regression adjustments” is CUPED; you simply condition on the variable in the pre-experiment period, regardless of whether the unit is treated. Then the effect that you detect is a change relative to the baseline attributable to treatment exposure.

\n
\n

Due to time constraints and the fact that, at the time, they didn't know if this was going anywhere, these three experiments all compare to the same control.

\n
\n

This isn’t necessarily a problem if all the experiments occurred at the same time. If however the control occurred at time t as then experiment one in t+1, experiment 2 in t+2, etc. That might be the bigger red flag, especially if you’re worried about growth rates.

\n

Assuming all observed at the same time and that treatment is the same “knocking out a specific gene” then you can lump all of these experiments together in one. You may want to explore fixed effects where you effectively have one intercept per for each experimental subgroup - the baseline behavior expected for each subgroup. (This may sound like CUPED as I described earlier but they’re mechanically different.) But there shouldn’t be any correlation between experimental sub-group and treatment exposure.

\n", "answer_id": 676923, "answer_text": "but that control has already been shown to have reduced growth compared to another genotype where that process is disrupted\n\n\n\n\n\n\n\nA control can have a different baseline than the treated group. But you need to move from t-tests to regressions, eg ANCOVA. A common strategy within the world of “regression adjustments” is CUPED; you simply condition on the variable in the pre-experiment period, regardless of whether the unit is treated. Then the effect that you detect is a change relative to the baseline attributable to treatment exposure.\n\n\n\n\n\n\n\nDue to time constraints and the fact that, at the time, they didn't know if this was going anywhere, these three experiments all compare to the same control.\n\n\n\n\n\n\n\nThis isn’t necessarily a problem if all the experiments occurred at the same time. If however the control occurred at time t as then experiment one in t+1, experiment 2 in t+2, etc. That might be the bigger red flag, especially if you’re worried about growth rates.\n\n\n\n\nAssuming all observed at the same time and that treatment is the same “knocking out a specific gene” then you can lump all of these experiments together in one. You may want to explore fixed effects where you effectively have one intercept per for each experimental subgroup - the baseline behavior expected for each subgroup. (This may sound like CUPED as I described earlier but they’re mechanically different.) But there shouldn’t be any correlation between experimental sub-group and treatment exposure.", "answer_url": "https://stats.stackexchange.com/a/676923", "author": "jbuddy_13", "author_url": "https://stats.stackexchange.com/users/288172/jbuddy-13", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-20T14:16:06+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": 676922, "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-08-20T14:16:06+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "51E42C8E-9699-4236-80F4-F62842373312", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/51E42C8E-9699-4236-80F4-F62842373312/view-source"}], "score": 0, "updated_at": "2026-08-20T14:16:06+00:00"}, {"answer_html": "

The most important thing is to be very clear about what was done, and when.

\n

Many clinical or social-science reports draw conclusions that are essentially based on a single statistical analysis. For those types of reports, the details of statistical analysis are central.

\n

In contrast, basic biomedical science reports like yours typically involve multiple types of experiments. Each experiment is designed to probe a different implication of an underlying hypothesis. Even if results are reported in frequentist terms, the report as a whole has a Bayesian flavor. You start with an hypothesis for which you have some belief, and gather increasing amounts of experimental data to increase or decrease the probability that your belief is correct.

\n

In that case, it doesn't matter whether any one experimental result ends up being erroneously deemed "significant" based on the (arbitrary) $p<0.05$ criterion. The question is whether the overall evidence from the multiple types of experiments is adequate to support the conclusions.

\n

Your obligation is to make sure that your reviewers and readers understand how each experiment was conducted and interpreted. If a control from a prior experiment was reused for another statistical comparison, say so. If an intervention used as a "control" for other interventions is already known to affect growth, make sure that fact is at least acknowledged in the discussion of the results.

\n

Your clarity on those matters might lead reviewers to ask for further experiments, like those you suggest. If the paper is published without those further experiments, your clarity will allow readers to judge how much weight they should put on your results.

\n

Subject-matter issues are typically much more important than statistical analyses per se for whether a study like this is valid and reproducible. As an extreme example, tens of thousands of studies that were actually performed on the HeLa line were claimed to have been on other cell lines. See this paper by Horback and Halffman. Even if all of statistical analyses in those studies were perfect, the interpretations of their results were still wrong.

\n", "answer_id": 676926, "answer_text": "The most important thing is to be very clear about what was done, and when.\n\n\n\n\nMany clinical or social-science reports draw conclusions that are essentially based on a single statistical analysis. For those types of reports, the details of statistical analysis are central.\n\n\n\n\nIn contrast, basic biomedical science reports like yours typically involve multiple types of experiments. Each experiment is designed to probe a different implication of an underlying hypothesis. Even if results are reported in frequentist terms, the report as a whole has a Bayesian flavor. You start with an hypothesis for which you have some belief, and gather increasing amounts of experimental data to increase or decrease the probability that your belief is correct.\n\n\n\n\nIn that case, it doesn't matter whether any one experimental result ends up being erroneously deemed \"significant\" based on the (arbitrary) $p<0.05$ criterion. The question is whether the overall evidence from the multiple types of experiments is adequate to support the conclusions.\n\n\n\n\nYour obligation is to make sure that your reviewers and readers understand how each experiment was conducted and interpreted. If a control from a prior experiment was reused for another statistical comparison, say so. If an intervention used as a \"control\" for other interventions is already known to affect growth, make sure that fact is at least acknowledged in the discussion of the results.\n\n\n\n\nYour clarity on those matters might lead reviewers to ask for further experiments, like those you suggest. If the paper is published without those further experiments, your clarity will allow readers to judge how much weight they should put on your results.\n\n\n\n\nSubject-matter issues are typically much more important than statistical analyses per se for whether a study like this is valid and reproducible. As an extreme example, tens of thousands of studies that were actually performed on the HeLa line were claimed to have been on other cell lines. See this paper (https://doi.org/10.1371/journal.pone.0186281) by Horback and Halffman. Even if all of statistical analyses in those studies were perfect, the interpretations of their results were still wrong.", "answer_url": "https://stats.stackexchange.com/a/676926", "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-20T18:06:41+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676922, "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-20T18:06:41+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "5370D235-4094-4143-BE97-98AE6C0D2C4B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/5370D235-4094-4143-BE97-98AE6C0D2C4B/view-source"}], "score": 3, "updated_at": "2026-08-20T18:06:41+00:00"}], "product": "statistics_qa", "question": "I'm contributing to a paper where I am a fairly minor author. I'm concerned by the experimental design but the corresponding authors, who have decade(s) more experience in the field than I have, seem unconcerned and there's the implication that I'm being unnecessarily picky. I'm 95% sure I'm correct, but given their attitude and the fact that my remaining option is to have my name removed from the paper, I'm chasing that final 5% of sureness.\n\n\n\n\nIn the first experiment, knocking out a gene was shown to cause a significant increase in cell size (simple t-test). To confirm this phenomenon, they then knocked out another gene involved in the same biological process and showed the same effect (also using a t-test). They then tested another three or four genes more tangentially related to that process and saw a significant effect in some of them and not others (t tests). Due to time constraints and the fact that, at the time, they didn't know if this was going anywhere, these three experiments all compare to the same control. While they've built on this in later experiments, these three experiments are all in the paper and provide the base for the latter experiments.\n\n\n\n\nThis concerns me. Firstly, we know there’s a lot of variation in the experimental model over time so the control from the first experiment doesn't necessarily control for technical variations in the second two experiments. Secondly, and more importantly, in the second two experiments they compare the effects of disrupting a biological process to a \"control\", but that control has already been shown to have reduced growth compared to another genotype where that process is disrupted. To my mind, this invalidates any stats based on this experiment.\n\n\n\n\nTheir argument is that when you look at the overall results in the paper, the big picture is consistent and validates their results, and this can all be fixed with a p-value correction (in this case, Dunnett's test).\n\n\n\n\nI think presenting this data in a paper needs those experiments to be repeated with the proper controls. I think a Dunnett's test would be perfect if this was a pre-designed screen comparing knockdown of a number of genes to a single control, but not in this context.\n\n\n\n\nI'm wondering if I'm right, if they're right and I'm being picky, or if I'm right that it's a problem but they're right that it's a minor one?", "record_id": "Scientific-Statistics-QA:stats:676922", "selected_answer": {"answer_html": "

Your scenario perfectly matches an ANOVA scenario; means are compared accross multiple groups, including a control. I see nothing alarming there. Yes, you would need a multiple comparison correction (MCC) (Dunnett is indeed a good choice).
\nNow the question is, how many groups would you include in the ANOVA? It should be for all genes which were tested (not just the "significant" ones e.g.).
\nNow, could you just have gotten a very "lucky" control group? Possibly... But you say that, at least in some experiments, the results were not significant; so compare the non-significant means to the control; what is (are?) the p-value(s?)? If it is e.g. .6, then the control does not seem that extreme; if it is .06, then it may be...
\nHow difficult/time consuming is it to test a new control group? If not too bad, do it and see how it compares to the "original" control group.
\nYou also mention "technical variations in the second two experiments". That would be much more concerning. But of course if would depend on the specifics. Are you just saying this more or less out of principle, or do you have concrete details about divergences of the experimental protocols?
\nAnd note that it is quite common to be able to test only one group at a time (e.g. there is only one set of the required equipment).
\nSo, w/o more details, I do not see a cause for great alarm, if the proper test is used, with the proper MCC.

\n", "answer_id": 676925, "answer_text": "Your scenario perfectly matches an ANOVA scenario; means are compared accross multiple groups, including a control. I see nothing alarming there. Yes, you would need a multiple comparison correction (MCC) (Dunnett is indeed a good choice).\n\nNow the question is, how many groups would you include in the ANOVA? It should be for all genes which were tested (not just the \"significant\" ones e.g.).\n\nNow, could you just have gotten a very \"lucky\" control group? Possibly... But you say that, at least in some experiments, the results were not significant; so compare the non-significant means to the control; what is (are?) the p-value(s?)? If it is e.g. .6, then the control does not seem that extreme; if it is .06, then it may be...\n\nHow difficult/time consuming is it to test a new control group? If not too bad, do it and see how it compares to the \"original\" control group.\n\nYou also mention \"technical variations in the second two experiments\". That would be much more concerning. But of course if would depend on the specifics. Are you just saying this more or less out of principle, or do you have concrete details about divergences of the experimental protocols?\n\nAnd note that it is quite common to be able to test only one group at a time (e.g. there is only one set of the required equipment).\n\nSo, w/o more details, I do not see a cause for great alarm, if the proper test is used, with the proper MCC.", "answer_url": "https://stats.stackexchange.com/a/676925", "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-08-20T15:28:37+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": 676922, "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-08-20T15:28:37+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "6B4F51CB-7C7B-4DF7-AAAE-EF2A1C7E0F0A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6B4F51CB-7C7B-4DF7-AAAE-EF2A1C7E0F0A/view-source"}, {"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-08-21T01:35:35+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "9B8B7347-5896-4E6F-AC75-DEC3507B4E3A", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9B8B7347-5896-4E6F-AC75-DEC3507B4E3A/view-source"}], "score": 3, "updated_at": "2026-08-21T01:35:35+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "
\n

but that control has already been shown to have reduced growth compared to another genotype where that process is disrupted

\n
\n

A control can have a different baseline than the treated group. But you need to move from t-tests to regressions, eg ANCOVA. A common strategy within the world of “regression adjustments” is CUPED; you simply condition on the variable in the pre-experiment period, regardless of whether the unit is treated. Then the effect that you detect is a change relative to the baseline attributable to treatment exposure.

\n
\n

Due to time constraints and the fact that, at the time, they didn't know if this was going anywhere, these three experiments all compare to the same control.

\n
\n

This isn’t necessarily a problem if all the experiments occurred at the same time. If however the control occurred at time t as then experiment one in t+1, experiment 2 in t+2, etc. That might be the bigger red flag, especially if you’re worried about growth rates.

\n

Assuming all observed at the same time and that treatment is the same “knocking out a specific gene” then you can lump all of these experiments together in one. You may want to explore fixed effects where you effectively have one intercept per for each experimental subgroup - the baseline behavior expected for each subgroup. (This may sound like CUPED as I described earlier but they’re mechanically different.) But there shouldn’t be any correlation between experimental sub-group and treatment exposure.

\n", "answer_id": 676923, "answer_text": "but that control has already been shown to have reduced growth compared to another genotype where that process is disrupted\n\n\n\n\n\n\n\nA control can have a different baseline than the treated group. But you need to move from t-tests to regressions, eg ANCOVA. A common strategy within the world of “regression adjustments” is CUPED; you simply condition on the variable in the pre-experiment period, regardless of whether the unit is treated. Then the effect that you detect is a change relative to the baseline attributable to treatment exposure.\n\n\n\n\n\n\n\nDue to time constraints and the fact that, at the time, they didn't know if this was going anywhere, these three experiments all compare to the same control.\n\n\n\n\n\n\n\nThis isn’t necessarily a problem if all the experiments occurred at the same time. If however the control occurred at time t as then experiment one in t+1, experiment 2 in t+2, etc. That might be the bigger red flag, especially if you’re worried about growth rates.\n\n\n\n\nAssuming all observed at the same time and that treatment is the same “knocking out a specific gene” then you can lump all of these experiments together in one. You may want to explore fixed effects where you effectively have one intercept per for each experimental subgroup - the baseline behavior expected for each subgroup. (This may sound like CUPED as I described earlier but they’re mechanically different.) But there shouldn’t be any correlation between experimental sub-group and treatment exposure.", "answer_url": "https://stats.stackexchange.com/a/676923", "author": "jbuddy_13", "author_url": "https://stats.stackexchange.com/users/288172/jbuddy-13", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-20T14:16:06+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": 676922, "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-08-20T14:16:06+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "51E42C8E-9699-4236-80F4-F62842373312", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/51E42C8E-9699-4236-80F4-F62842373312/view-source"}], "score": 0, "updated_at": "2026-08-20T14:16:06+00:00"}, {"answer_html": "

Your scenario perfectly matches an ANOVA scenario; means are compared accross multiple groups, including a control. I see nothing alarming there. Yes, you would need a multiple comparison correction (MCC) (Dunnett is indeed a good choice).
\nNow the question is, how many groups would you include in the ANOVA? It should be for all genes which were tested (not just the "significant" ones e.g.).
\nNow, could you just have gotten a very "lucky" control group? Possibly... But you say that, at least in some experiments, the results were not significant; so compare the non-significant means to the control; what is (are?) the p-value(s?)? If it is e.g. .6, then the control does not seem that extreme; if it is .06, then it may be...
\nHow difficult/time consuming is it to test a new control group? If not too bad, do it and see how it compares to the "original" control group.
\nYou also mention "technical variations in the second two experiments". That would be much more concerning. But of course if would depend on the specifics. Are you just saying this more or less out of principle, or do you have concrete details about divergences of the experimental protocols?
\nAnd note that it is quite common to be able to test only one group at a time (e.g. there is only one set of the required equipment).
\nSo, w/o more details, I do not see a cause for great alarm, if the proper test is used, with the proper MCC.

\n", "answer_id": 676925, "answer_text": "Your scenario perfectly matches an ANOVA scenario; means are compared accross multiple groups, including a control. I see nothing alarming there. Yes, you would need a multiple comparison correction (MCC) (Dunnett is indeed a good choice).\n\nNow the question is, how many groups would you include in the ANOVA? It should be for all genes which were tested (not just the \"significant\" ones e.g.).\n\nNow, could you just have gotten a very \"lucky\" control group? Possibly... But you say that, at least in some experiments, the results were not significant; so compare the non-significant means to the control; what is (are?) the p-value(s?)? If it is e.g. .6, then the control does not seem that extreme; if it is .06, then it may be...\n\nHow difficult/time consuming is it to test a new control group? If not too bad, do it and see how it compares to the \"original\" control group.\n\nYou also mention \"technical variations in the second two experiments\". That would be much more concerning. But of course if would depend on the specifics. Are you just saying this more or less out of principle, or do you have concrete details about divergences of the experimental protocols?\n\nAnd note that it is quite common to be able to test only one group at a time (e.g. there is only one set of the required equipment).\n\nSo, w/o more details, I do not see a cause for great alarm, if the proper test is used, with the proper MCC.", "answer_url": "https://stats.stackexchange.com/a/676925", "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-08-20T15:28:37+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": 676922, "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-08-20T15:28:37+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "6B4F51CB-7C7B-4DF7-AAAE-EF2A1C7E0F0A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6B4F51CB-7C7B-4DF7-AAAE-EF2A1C7E0F0A/view-source"}, {"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-08-21T01:35:35+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "9B8B7347-5896-4E6F-AC75-DEC3507B4E3A", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9B8B7347-5896-4E6F-AC75-DEC3507B4E3A/view-source"}], "score": 3, "updated_at": "2026-08-21T01:35:35+00:00"}, {"answer_html": "

The most important thing is to be very clear about what was done, and when.

\n

Many clinical or social-science reports draw conclusions that are essentially based on a single statistical analysis. For those types of reports, the details of statistical analysis are central.

\n

In contrast, basic biomedical science reports like yours typically involve multiple types of experiments. Each experiment is designed to probe a different implication of an underlying hypothesis. Even if results are reported in frequentist terms, the report as a whole has a Bayesian flavor. You start with an hypothesis for which you have some belief, and gather increasing amounts of experimental data to increase or decrease the probability that your belief is correct.

\n

In that case, it doesn't matter whether any one experimental result ends up being erroneously deemed "significant" based on the (arbitrary) $p<0.05$ criterion. The question is whether the overall evidence from the multiple types of experiments is adequate to support the conclusions.

\n

Your obligation is to make sure that your reviewers and readers understand how each experiment was conducted and interpreted. If a control from a prior experiment was reused for another statistical comparison, say so. If an intervention used as a "control" for other interventions is already known to affect growth, make sure that fact is at least acknowledged in the discussion of the results.

\n

Your clarity on those matters might lead reviewers to ask for further experiments, like those you suggest. If the paper is published without those further experiments, your clarity will allow readers to judge how much weight they should put on your results.

\n

Subject-matter issues are typically much more important than statistical analyses per se for whether a study like this is valid and reproducible. As an extreme example, tens of thousands of studies that were actually performed on the HeLa line were claimed to have been on other cell lines. See this paper by Horback and Halffman. Even if all of statistical analyses in those studies were perfect, the interpretations of their results were still wrong.

\n", "answer_id": 676926, "answer_text": "The most important thing is to be very clear about what was done, and when.\n\n\n\n\nMany clinical or social-science reports draw conclusions that are essentially based on a single statistical analysis. For those types of reports, the details of statistical analysis are central.\n\n\n\n\nIn contrast, basic biomedical science reports like yours typically involve multiple types of experiments. Each experiment is designed to probe a different implication of an underlying hypothesis. Even if results are reported in frequentist terms, the report as a whole has a Bayesian flavor. You start with an hypothesis for which you have some belief, and gather increasing amounts of experimental data to increase or decrease the probability that your belief is correct.\n\n\n\n\nIn that case, it doesn't matter whether any one experimental result ends up being erroneously deemed \"significant\" based on the (arbitrary) $p<0.05$ criterion. The question is whether the overall evidence from the multiple types of experiments is adequate to support the conclusions.\n\n\n\n\nYour obligation is to make sure that your reviewers and readers understand how each experiment was conducted and interpreted. If a control from a prior experiment was reused for another statistical comparison, say so. If an intervention used as a \"control\" for other interventions is already known to affect growth, make sure that fact is at least acknowledged in the discussion of the results.\n\n\n\n\nYour clarity on those matters might lead reviewers to ask for further experiments, like those you suggest. If the paper is published without those further experiments, your clarity will allow readers to judge how much weight they should put on your results.\n\n\n\n\nSubject-matter issues are typically much more important than statistical analyses per se for whether a study like this is valid and reproducible. As an extreme example, tens of thousands of studies that were actually performed on the HeLa line were claimed to have been on other cell lines. See this paper (https://doi.org/10.1371/journal.pone.0186281) by Horback and Halffman. Even if all of statistical analyses in those studies were perfect, the interpretations of their results were still wrong.", "answer_url": "https://stats.stackexchange.com/a/676926", "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-20T18:06:41+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 676922, "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-20T18:06:41+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "5370D235-4094-4143-BE97-98AE6C0D2C4B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/5370D235-4094-4143-BE97-98AE6C0D2C4B/view-source"}], "score": 3, "updated_at": "2026-08-20T18:06:41+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1371/journal.pone.0186281"], "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": "kcbthe86", "question_author_url": "https://stats.stackexchange.com/users/515742/kcbthe86", "question_author_user_type": "unregistered", "question_created_at": "2026-08-20T13:47:09+00:00", "question_html": "

I'm contributing to a paper where I am a fairly minor author. I'm concerned by the experimental design but the corresponding authors, who have decade(s) more experience in the field than I have, seem unconcerned and there's the implication that I'm being unnecessarily picky. I'm 95% sure I'm correct, but given their attitude and the fact that my remaining option is to have my name removed from the paper, I'm chasing that final 5% of sureness.

\n

In the first experiment, knocking out a gene was shown to cause a significant increase in cell size (simple t-test). To confirm this phenomenon, they then knocked out another gene involved in the same biological process and showed the same effect (also using a t-test). They then tested another three or four genes more tangentially related to that process and saw a significant effect in some of them and not others (t tests). Due to time constraints and the fact that, at the time, they didn't know if this was going anywhere, these three experiments all compare to the same control. While they've built on this in later experiments, these three experiments are all in the paper and provide the base for the latter experiments.

\n

This concerns me. Firstly, we know there’s a lot of variation in the experimental model over time so the control from the first experiment doesn't necessarily control for technical variations in the second two experiments. Secondly, and more importantly, in the second two experiments they compare the effects of disrupting a biological process to a "control", but that control has already been shown to have reduced growth compared to another genotype where that process is disrupted. To my mind, this invalidates any stats based on this experiment.

\n

Their argument is that when you look at the overall results in the paper, the big picture is consistent and validates their results, and this can all be fixed with a p-value correction (in this case, Dunnett's test).

\n

I think presenting this data in a paper needs those experiments to be repeated with the proper controls. I think a Dunnett's test would be perfect if this was a pre-designed screen comparing knockdown of a number of genes to a single control, but not in this context.

\n

I'm wondering if I'm right, if they're right and I'm being picky, or if I'm right that it's a problem but they're right that it's a minor one?

\n", "question_id": 676922, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "I'm contributing to a paper where I am a fairly minor author. I'm concerned by the experimental design but the corresponding authors, who have decade(s) more experience in the field than I have, seem unconcerned and there's the implication that I'm being unnecessarily picky. I'm 95% sure I'm correct, but given their attitude and the fact that my remaining option is to have my name removed from the paper, I'm chasing that final 5% of sureness.\n\n\n\n\nIn the first experiment, knocking out a gene was shown to cause a significant increase in cell size (simple t-test). To confirm this phenomenon, they then knocked out another gene involved in the same biological process and showed the same effect (also using a t-test). They then tested another three or four genes more tangentially related to that process and saw a significant effect in some of them and not others (t tests). Due to time constraints and the fact that, at the time, they didn't know if this was going anywhere, these three experiments all compare to the same control. While they've built on this in later experiments, these three experiments are all in the paper and provide the base for the latter experiments.\n\n\n\n\nThis concerns me. Firstly, we know there’s a lot of variation in the experimental model over time so the control from the first experiment doesn't necessarily control for technical variations in the second two experiments. Secondly, and more importantly, in the second two experiments they compare the effects of disrupting a biological process to a \"control\", but that control has already been shown to have reduced growth compared to another genotype where that process is disrupted. To my mind, this invalidates any stats based on this experiment.\n\n\n\n\nTheir argument is that when you look at the overall results in the paper, the big picture is consistent and validates their results, and this can all be fixed with a p-value correction (in this case, Dunnett's test).\n\n\n\n\nI think presenting this data in a paper needs those experiments to be repeated with the proper controls. I think a Dunnett's test would be perfect if this was a pre-designed screen comparing knockdown of a number of genes to a single control, but not in this context.\n\n\n\n\nI'm wondering if I'm right, if they're right and I'm being picky, or if I'm right that it's a problem but they're right that it's a minor one?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "kcbthe86", "profile_url": "https://stats.stackexchange.com/users/515742/kcbthe86", "user_type": "unregistered"}, "created_at": "2026-08-20T13:47:09+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "86B1CE7C-C99D-4B53-A120-AB9699CE0EB9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/86B1CE7C-C99D-4B53-A120-AB9699CE0EB9/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-20T22:00:02+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "C5F41EE0-9032-4006-8D8E-14BFE6FD7C57", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/C5F41EE0-9032-4006-8D8E-14BFE6FD7C57/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676922/in-this-experimental-context-does-the-re-use-of-a-control-bias-invalidate-the-r", "split": "train", "split_group": "350e0d3ac148dee5776cb68932436eea8aaea79700d560661d32a23180c6c064", "tags": ["p-value", "experiment-design", "control-group"], "thread_id": "stats:676922", "title": "In this experimental context, does the re-use of a control bias/invalidate the result?"}} +{"accepted_answer": {"answer_html": "

TL:DR - this has sort of been asked before, but this deserves a separate answer

\n

I think that you'll find that there are several ways to derive the relationship, and yours certainly gels with others (for example see this Q & A). However, I'm answering this, primarily to point out what a few others, including textbook authors, have identified as a tricky part with any proof, or indeed, any discussion of this. From this excellent answer to a very similar, but in my opinion, not identical question to yours, we see that it's extremely important to keep track of various quantities when discussing model error. This is especially true when venturing into discussions of in-sample and out of sample error. As Matthew's answer nicely points out, Hastie, Tibshirani, and Friedman make this point explicit in the beginning of Chapter 7 of ESL:

\n
\n

Discussions of error rate estimation can be confusing, because we have to make clear which quantities are fixed and which are random

\n
\n

I actually find their discussion somewhat confusing as well since they aren't as clear as they could be throughout that chapter, especially when distinguishing in the notation they use for the various error estimates (e.g., $\\text{Err}$, $\\text{err}$, etc.).

\n

This is just a long way of saying that the Wikipedia is at least extremely thorough. It's worth pointing out that there's a very clear statement before defining everything too:

\n
\n

Finding an $\\hat {f}$ that generalizes to points outside of the training set can be done with any of the countless algorithms used for supervised learning. It turns out that whichever function $\\hat {f}$ we select, we can decompose its expected error on an unseen sample\n$x$ (i.e. conditional on $x$)...

\n
\n

That's the part that enables a lot of your shorter proof (independence and variance properties).

\n
\n

For extra credit, try following the in-sample / out-of-sample discussion in Chapter 12 of Efron & Hastie...

\n", "answer_id": 676944, "answer_text": "TL:DR - this has sort of been asked before, but this deserves a separate answer\n\n\n\n\nI think that you'll find that there are several ways to derive the relationship, and yours certainly gels with others (for example see this Q & A (https://stats.stackexchange.com/q/234251/97844)). However, I'm answering this, primarily to point out what a few others, including textbook authors, have identified as a tricky part with any proof, or indeed, any discussion of this. From this excellent answer (https://stats.stackexchange.com/a/164391/97844) to a very similar, but in my opinion, not identical question to yours, we see that it's extremely important to keep track of various quantities when discussing model error. This is especially true when venturing into discussions of in-sample and out of sample error. As Matthew's answer nicely points out, Hastie, Tibshirani, and Friedman (https://hastie.su.domains/ElemStatLearn/) make this point explicit in the beginning of Chapter 7 of ESL:\n\n\n\n\n\n\n\nDiscussions of error rate estimation can be confusing, because we have to make clear which quantities are fixed and which are random\n\n\n\n\n\n\n\nI actually find their discussion somewhat confusing as well since they aren't as clear as they could be throughout that chapter, especially when distinguishing in the notation they use for the various error estimates (e.g., $\\text{Err}$, $\\text{err}$, etc.).\n\n\n\n\nThis is just a long way of saying that the Wikipedia is at least extremely thorough. It's worth pointing out that there's a very clear statement before defining everything too:\n\n\n\n\n\n\n\nFinding an $\\hat {f}$ that generalizes to points outside of the training set can be done with any of the countless algorithms used for supervised learning. It turns out that whichever function $\\hat {f}$ we select, we can decompose its expected error on an unseen sample\n$x$ (i.e. conditional on $x$)...\n\n\n\n\n\n\n\nThat's the part that enables a lot of your shorter proof (independence and variance properties).\n\n\n\n\n\n\n\nFor extra credit, try following the in-sample / out-of-sample discussion in Chapter 12 of Efron & Hastie (https://hastie.su.domains/CASI/)...", "answer_url": "https://stats.stackexchange.com/a/676944", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-23T18:47:36+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": 676933, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-08-23T18:47:36+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "276A625E-F436-41F8-9677-7E191B41EEE7", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/276A625E-F436-41F8-9677-7E191B41EEE7/view-source"}], "score": 2, "updated_at": "2026-08-23T18:47:36+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "I am reading the proof of the bias-variance decomposition formula on Wikipedia (Bias-variance tradeoff (https://en.wikipedia.org/wiki/Bias%E2%80%93variance_tradeoff)), and it appears to me that the derivation there is uselessly complicated. I think I can derive it in a much shorter way, but I am not sure if it is a 100% correct. Suppose that $y = f(x) + \\epsilon$, where $\\epsilon$ is a random variable with mean equal to $0$ and variance $\\sigma^2$. Let $D$ be the training data, composed of $(x_i, y_i)$, for, say, $i = 1, \\dots, n$, where the set of $(x, y)$ follows a joint density function $P(x, y)$. We take a sample $(x, y)$ and denote by $\\hat{f}(x; D)$ the predicted value corresponding to $x$ using some model trained on $D$. The $\\epsilon_i$ corresponding to the $i$-th observation point is assumed to be independent of, say $\\epsilon_j$ for $j \\neq i$ ($1 \\leq i, j \\leq n$) and also independent of $\\epsilon$.\n\n\n\n\nThe bias-variance decomposition then says that\n$$ \\mathbb{E}_{D, \\epsilon}[(y - \\hat{f}(x; D))^2] = (f(x) - \\mathbf{E}_D[\\hat{f}(x; D)])^2 + \\operatorname{Var}_D[\\hat{f}(x; D)] + \\sigma^2. $$\n\n\n\n\nThe way I would proceed to prove it is as follows. Given a random variable $Z$, we have that\n\n\n\n\n$$ \\mathbb{E}[Z^2] = \\mathbb{E}[Z]^2 + \\operatorname{Var}(Z).$$\n\n\n\n\nWe apply that with $Z = y - \\hat{f}(x; D)$. We obtain that\n\n\n\n\n$$ \\mathbb{E}_{D, \\epsilon}[(y - \\hat{f}(x; D))^2] = (f(x) - \\mathbf{E}_D[\\hat{f}(x; D)])^2 + \\operatorname{Var}_{D, \\epsilon}[y - \\hat{f}(x; D)]. $$\n\n\n\n\nMoreover if $U$ and $V$ are independent random variables and $\\alpha, \\beta \\in \\mathbb{R}$, then\n\n\n\n\n$$ \\operatorname{Var}[\\alpha U + \\beta V] = \\alpha^2 \\operatorname{Var}[U] + \\beta^2 \\operatorname{Var}[V].$$\n\n\n\n\nWe apply this proposition and obtain that\n\n\n\n\n$$ \\operatorname{Var}_{D, \\epsilon}[y - \\hat{f}(x; D)] = \\operatorname{Var}_D[\\hat{f}(x; D)] + \\sigma^2. $$\n\n\n\n\nCombining this with the previous decomposition formula yields the bias-variance decomposition. I think this is correct and it is much simpler than the somewhat lengthy derivation in the wikipedia article.", "record_id": "Scientific-Statistics-QA:stats:676933", "selected_answer": {"answer_html": "

TL:DR - this has sort of been asked before, but this deserves a separate answer

\n

I think that you'll find that there are several ways to derive the relationship, and yours certainly gels with others (for example see this Q & A). However, I'm answering this, primarily to point out what a few others, including textbook authors, have identified as a tricky part with any proof, or indeed, any discussion of this. From this excellent answer to a very similar, but in my opinion, not identical question to yours, we see that it's extremely important to keep track of various quantities when discussing model error. This is especially true when venturing into discussions of in-sample and out of sample error. As Matthew's answer nicely points out, Hastie, Tibshirani, and Friedman make this point explicit in the beginning of Chapter 7 of ESL:

\n
\n

Discussions of error rate estimation can be confusing, because we have to make clear which quantities are fixed and which are random

\n
\n

I actually find their discussion somewhat confusing as well since they aren't as clear as they could be throughout that chapter, especially when distinguishing in the notation they use for the various error estimates (e.g., $\\text{Err}$, $\\text{err}$, etc.).

\n

This is just a long way of saying that the Wikipedia is at least extremely thorough. It's worth pointing out that there's a very clear statement before defining everything too:

\n
\n

Finding an $\\hat {f}$ that generalizes to points outside of the training set can be done with any of the countless algorithms used for supervised learning. It turns out that whichever function $\\hat {f}$ we select, we can decompose its expected error on an unseen sample\n$x$ (i.e. conditional on $x$)...

\n
\n

That's the part that enables a lot of your shorter proof (independence and variance properties).

\n
\n

For extra credit, try following the in-sample / out-of-sample discussion in Chapter 12 of Efron & Hastie...

\n", "answer_id": 676944, "answer_text": "TL:DR - this has sort of been asked before, but this deserves a separate answer\n\n\n\n\nI think that you'll find that there are several ways to derive the relationship, and yours certainly gels with others (for example see this Q & A (https://stats.stackexchange.com/q/234251/97844)). However, I'm answering this, primarily to point out what a few others, including textbook authors, have identified as a tricky part with any proof, or indeed, any discussion of this. From this excellent answer (https://stats.stackexchange.com/a/164391/97844) to a very similar, but in my opinion, not identical question to yours, we see that it's extremely important to keep track of various quantities when discussing model error. This is especially true when venturing into discussions of in-sample and out of sample error. As Matthew's answer nicely points out, Hastie, Tibshirani, and Friedman (https://hastie.su.domains/ElemStatLearn/) make this point explicit in the beginning of Chapter 7 of ESL:\n\n\n\n\n\n\n\nDiscussions of error rate estimation can be confusing, because we have to make clear which quantities are fixed and which are random\n\n\n\n\n\n\n\nI actually find their discussion somewhat confusing as well since they aren't as clear as they could be throughout that chapter, especially when distinguishing in the notation they use for the various error estimates (e.g., $\\text{Err}$, $\\text{err}$, etc.).\n\n\n\n\nThis is just a long way of saying that the Wikipedia is at least extremely thorough. It's worth pointing out that there's a very clear statement before defining everything too:\n\n\n\n\n\n\n\nFinding an $\\hat {f}$ that generalizes to points outside of the training set can be done with any of the countless algorithms used for supervised learning. It turns out that whichever function $\\hat {f}$ we select, we can decompose its expected error on an unseen sample\n$x$ (i.e. conditional on $x$)...\n\n\n\n\n\n\n\nThat's the part that enables a lot of your shorter proof (independence and variance properties).\n\n\n\n\n\n\n\nFor extra credit, try following the in-sample / out-of-sample discussion in Chapter 12 of Efron & Hastie (https://hastie.su.domains/CASI/)...", "answer_url": "https://stats.stackexchange.com/a/676944", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-23T18:47:36+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": 676933, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-08-23T18:47:36+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "276A625E-F436-41F8-9677-7E191B41EEE7", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/276A625E-F436-41F8-9677-7E191B41EEE7/view-source"}], "score": 2, "updated_at": "2026-08-23T18:47:36+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 676944, "answers": [{"answer_html": "

TL:DR - this has sort of been asked before, but this deserves a separate answer

\n

I think that you'll find that there are several ways to derive the relationship, and yours certainly gels with others (for example see this Q & A). However, I'm answering this, primarily to point out what a few others, including textbook authors, have identified as a tricky part with any proof, or indeed, any discussion of this. From this excellent answer to a very similar, but in my opinion, not identical question to yours, we see that it's extremely important to keep track of various quantities when discussing model error. This is especially true when venturing into discussions of in-sample and out of sample error. As Matthew's answer nicely points out, Hastie, Tibshirani, and Friedman make this point explicit in the beginning of Chapter 7 of ESL:

\n
\n

Discussions of error rate estimation can be confusing, because we have to make clear which quantities are fixed and which are random

\n
\n

I actually find their discussion somewhat confusing as well since they aren't as clear as they could be throughout that chapter, especially when distinguishing in the notation they use for the various error estimates (e.g., $\\text{Err}$, $\\text{err}$, etc.).

\n

This is just a long way of saying that the Wikipedia is at least extremely thorough. It's worth pointing out that there's a very clear statement before defining everything too:

\n
\n

Finding an $\\hat {f}$ that generalizes to points outside of the training set can be done with any of the countless algorithms used for supervised learning. It turns out that whichever function $\\hat {f}$ we select, we can decompose its expected error on an unseen sample\n$x$ (i.e. conditional on $x$)...

\n
\n

That's the part that enables a lot of your shorter proof (independence and variance properties).

\n
\n

For extra credit, try following the in-sample / out-of-sample discussion in Chapter 12 of Efron & Hastie...

\n", "answer_id": 676944, "answer_text": "TL:DR - this has sort of been asked before, but this deserves a separate answer\n\n\n\n\nI think that you'll find that there are several ways to derive the relationship, and yours certainly gels with others (for example see this Q & A (https://stats.stackexchange.com/q/234251/97844)). However, I'm answering this, primarily to point out what a few others, including textbook authors, have identified as a tricky part with any proof, or indeed, any discussion of this. From this excellent answer (https://stats.stackexchange.com/a/164391/97844) to a very similar, but in my opinion, not identical question to yours, we see that it's extremely important to keep track of various quantities when discussing model error. This is especially true when venturing into discussions of in-sample and out of sample error. As Matthew's answer nicely points out, Hastie, Tibshirani, and Friedman (https://hastie.su.domains/ElemStatLearn/) make this point explicit in the beginning of Chapter 7 of ESL:\n\n\n\n\n\n\n\nDiscussions of error rate estimation can be confusing, because we have to make clear which quantities are fixed and which are random\n\n\n\n\n\n\n\nI actually find their discussion somewhat confusing as well since they aren't as clear as they could be throughout that chapter, especially when distinguishing in the notation they use for the various error estimates (e.g., $\\text{Err}$, $\\text{err}$, etc.).\n\n\n\n\nThis is just a long way of saying that the Wikipedia is at least extremely thorough. It's worth pointing out that there's a very clear statement before defining everything too:\n\n\n\n\n\n\n\nFinding an $\\hat {f}$ that generalizes to points outside of the training set can be done with any of the countless algorithms used for supervised learning. It turns out that whichever function $\\hat {f}$ we select, we can decompose its expected error on an unseen sample\n$x$ (i.e. conditional on $x$)...\n\n\n\n\n\n\n\nThat's the part that enables a lot of your shorter proof (independence and variance properties).\n\n\n\n\n\n\n\nFor extra credit, try following the in-sample / out-of-sample discussion in Chapter 12 of Efron & Hastie (https://hastie.su.domains/CASI/)...", "answer_url": "https://stats.stackexchange.com/a/676944", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-23T18:47:36+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": 676933, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-08-23T18:47:36+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "276A625E-F436-41F8-9677-7E191B41EEE7", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/276A625E-F436-41F8-9677-7E191B41EEE7/view-source"}], "score": 2, "updated_at": "2026-08-23T18:47:36+00:00"}], "domain": "statistics", "external_links": ["https://en.wikipedia.org/wiki/Bias%E2%80%93variance_tradeoff", "https://hastie.su.domains/CASI/", "https://hastie.su.domains/ElemStatLearn/"], "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": "Malkoun", "question_author_url": "https://stats.stackexchange.com/users/445895/malkoun", "question_author_user_type": "registered", "question_created_at": "2026-08-22T10:36:57+00:00", "question_html": "

I am reading the proof of the bias-variance decomposition formula on Wikipedia (Bias-variance tradeoff), and it appears to me that the derivation there is uselessly complicated. I think I can derive it in a much shorter way, but I am not sure if it is a 100% correct. Suppose that $y = f(x) + \\epsilon$, where $\\epsilon$ is a random variable with mean equal to $0$ and variance $\\sigma^2$. Let $D$ be the training data, composed of $(x_i, y_i)$, for, say, $i = 1, \\dots, n$, where the set of $(x, y)$ follows a joint density function $P(x, y)$. We take a sample $(x, y)$ and denote by $\\hat{f}(x; D)$ the predicted value corresponding to $x$ using some model trained on $D$. The $\\epsilon_i$ corresponding to the $i$-th observation point is assumed to be independent of, say $\\epsilon_j$ for $j \\neq i$ ($1 \\leq i, j \\leq n$) and also independent of $\\epsilon$.

\n

The bias-variance decomposition then says that\n$$ \\mathbb{E}_{D, \\epsilon}[(y - \\hat{f}(x; D))^2] = (f(x) - \\mathbf{E}_D[\\hat{f}(x; D)])^2 + \\operatorname{Var}_D[\\hat{f}(x; D)] + \\sigma^2. $$

\n

The way I would proceed to prove it is as follows. Given a random variable $Z$, we have that

\n

$$ \\mathbb{E}[Z^2] = \\mathbb{E}[Z]^2 + \\operatorname{Var}(Z).$$

\n

We apply that with $Z = y - \\hat{f}(x; D)$. We obtain that

\n

$$ \\mathbb{E}_{D, \\epsilon}[(y - \\hat{f}(x; D))^2] = (f(x) - \\mathbf{E}_D[\\hat{f}(x; D)])^2 + \\operatorname{Var}_{D, \\epsilon}[y - \\hat{f}(x; D)]. $$

\n

Moreover if $U$ and $V$ are independent random variables and $\\alpha, \\beta \\in \\mathbb{R}$, then

\n

$$ \\operatorname{Var}[\\alpha U + \\beta V] = \\alpha^2 \\operatorname{Var}[U] + \\beta^2 \\operatorname{Var}[V].$$

\n

We apply this proposition and obtain that

\n

$$ \\operatorname{Var}_{D, \\epsilon}[y - \\hat{f}(x; D)] = \\operatorname{Var}_D[\\hat{f}(x; D)] + \\sigma^2. $$

\n

Combining this with the previous decomposition formula yields the bias-variance decomposition. I think this is correct and it is much simpler than the somewhat lengthy derivation in the wikipedia article.

\n", "question_id": 676933, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I am reading the proof of the bias-variance decomposition formula on Wikipedia (Bias-variance tradeoff (https://en.wikipedia.org/wiki/Bias%E2%80%93variance_tradeoff)), and it appears to me that the derivation there is uselessly complicated. I think I can derive it in a much shorter way, but I am not sure if it is a 100% correct. Suppose that $y = f(x) + \\epsilon$, where $\\epsilon$ is a random variable with mean equal to $0$ and variance $\\sigma^2$. Let $D$ be the training data, composed of $(x_i, y_i)$, for, say, $i = 1, \\dots, n$, where the set of $(x, y)$ follows a joint density function $P(x, y)$. We take a sample $(x, y)$ and denote by $\\hat{f}(x; D)$ the predicted value corresponding to $x$ using some model trained on $D$. The $\\epsilon_i$ corresponding to the $i$-th observation point is assumed to be independent of, say $\\epsilon_j$ for $j \\neq i$ ($1 \\leq i, j \\leq n$) and also independent of $\\epsilon$.\n\n\n\n\nThe bias-variance decomposition then says that\n$$ \\mathbb{E}_{D, \\epsilon}[(y - \\hat{f}(x; D))^2] = (f(x) - \\mathbf{E}_D[\\hat{f}(x; D)])^2 + \\operatorname{Var}_D[\\hat{f}(x; D)] + \\sigma^2. $$\n\n\n\n\nThe way I would proceed to prove it is as follows. Given a random variable $Z$, we have that\n\n\n\n\n$$ \\mathbb{E}[Z^2] = \\mathbb{E}[Z]^2 + \\operatorname{Var}(Z).$$\n\n\n\n\nWe apply that with $Z = y - \\hat{f}(x; D)$. We obtain that\n\n\n\n\n$$ \\mathbb{E}_{D, \\epsilon}[(y - \\hat{f}(x; D))^2] = (f(x) - \\mathbf{E}_D[\\hat{f}(x; D)])^2 + \\operatorname{Var}_{D, \\epsilon}[y - \\hat{f}(x; D)]. $$\n\n\n\n\nMoreover if $U$ and $V$ are independent random variables and $\\alpha, \\beta \\in \\mathbb{R}$, then\n\n\n\n\n$$ \\operatorname{Var}[\\alpha U + \\beta V] = \\alpha^2 \\operatorname{Var}[U] + \\beta^2 \\operatorname{Var}[V].$$\n\n\n\n\nWe apply this proposition and obtain that\n\n\n\n\n$$ \\operatorname{Var}_{D, \\epsilon}[y - \\hat{f}(x; D)] = \\operatorname{Var}_D[\\hat{f}(x; D)] + \\sigma^2. $$\n\n\n\n\nCombining this with the previous decomposition formula yields the bias-variance decomposition. I think this is correct and it is much simpler than the somewhat lengthy derivation in the wikipedia article.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Malkoun", "profile_url": "https://stats.stackexchange.com/users/445895/malkoun", "user_type": "registered"}, "created_at": "2026-08-22T10:36:57+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "8CFCF94E-A9CC-4406-BAA0-E8D52A68BCFC", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8CFCF94E-A9CC-4406-BAA0-E8D52A68BCFC/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Malkoun", "profile_url": "https://stats.stackexchange.com/users/445895/malkoun", "user_type": "registered"}, "created_at": "2026-08-22T10:42:14+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "A71B25CE-EEC3-495C-BE5A-65C03AAB27C3", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A71B25CE-EEC3-495C-BE5A-65C03AAB27C3/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-24T00:17:35+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "038576D0-1181-40B6-AF95-E83152209C3B", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/038576D0-1181-40B6-AF95-E83152209C3B/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676933/a-possibly-short-proof-of-the-bias-variance-decomposition-formula", "split": "train", "split_group": "ffa016a104db22aadad7c9059b2f98a1ce691ee91fb03f2448f52ee0430ecbf2", "tags": ["bias-variance-tradeoff"], "thread_id": "stats:676933", "title": "A possibly short proof of the bias-variance decomposition formula"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I observe 3 variables, $y_0$, $y_1$, and $y_2$, but am missing some of the observations for $y_1$, so I only have a subsample of $h$ observations of $y_1$ and all $n$ observations of $y_0$ and $y_2$. My goal is to study the relationship between $y_0$ and $y_1$ while controlling for $y_2$ while taking full advantage of all observations. Thus, instead of using only $h$ observations to run the multiple regression ${y_1}_h \\sim {y_0}_h + {y_2}_h$ where the second subscript represents whether we are using just $h$ (or all $n$) observations, I am instead first running ${y_0}_n \\sim {y_2}_n$ and ${y_1}_h \\sim {y_2}_h$ and then regressing the residuals from these two regressions on each other: $r_{y_1 \\sim y_2, h} \\sim r_{y_0 \\sim y_2, n}$. Of course, I only use the $h$ corresponding residuals from the ${y_0}_n \\sim {y_2}_n$ regression of $n$ points for the second stage regression. Now typically when all three variables have the same number of observations, the degrees of freedom in the second regression of residuals is one less than it otherwise would be, but in this case, we actually lose less than 1 degree of freedom. However, I do not know the formula (if one exists), so what I am currently doing is simulating null data, and testing different degree of freedom subtractions, to see which one either A) gives the proper 5% rejection rate or B) gives the same rejection rate as the multiple regression that uses only $h$ data points. So, I think method A is more technically correct than B, but B seems to work better. I have written some R code where $n$ is 40 and $h$ is 20, where I'm pretty sure the correction is 0.5 degrees of freedom, which matches better with method B instead of method A. Ultimately if there isn't a formula (one would be welcome), what is the \"best\" approach? Overall, is this even a valid approach to begin with or is trying to use all the data a flawed concept to begin with? Does the validity depend on the pattern of missing data?\n\n\n\n\n# R code\ndof_correction<-0.5; set.seed(0)\nnum_sims<-10^4; h<-20; n<-40\nmultiple<-stage<-numeric(num_sims) # initialize vectors for storing p-values\nfor (i in 1:num_sims) {\n y0<-rnorm(n); y0h<-y0[1:h]; y1h<-rnorm(h); y2<-rnorm(n); y2h<-y2[1:h]\n ly1ONy0y2_h<-lm(y1h ~ y0h + y2h)\n multiple[i]<-coefficients(summary(ly1ONy0y2_h))[\"y0h\",\"Pr(>|t|)\"]\n ly0ONy2_n<-lm(y0 ~ y2); r_ly0ONy2_n<-residuals(ly0ONy2_n); \n r_ly0ONy2_n_h<-r_ly0ONy2_n[1:h]\n ly1ONy2_h<-lm(y1h ~ y2h); r_ly1ONy2_h<-residuals(ly1ONy2_h)\n lrONr<-lm(r_ly1ONy2_h ~ r_ly0ONy2_n_h)\n lrONr$df.residual <- lrONr$df.residual - dof_correction\n stage[i]<-coefficients(summary(lrONr))[\"r_ly0ONy2_n_h\",\"Pr(>|t|)\"]\n}\ncat(\"Multiple: \", mean(multiple < 0.05), \"\\n\")\n# Multiple: 0.0529 \ncat(\" Stage: \", mean(stage < 0.05), \"\\n\")\n# Stage: 0.0527 \n\n\n\n\n\nObserve that using a dof correction of 0.5 gives a rejection rate (0.527) closer to that found using multiple regression (0.529) than it does to the actual theoretical rate of (0.500)\n\n\n\n\nUPDATE (1/2):\nI ran simulation code to compare some of the key models, (\"Full\") one where we actually aren't missing data, (\"Half\") one where we only use $h$ observations, (\"Estimated B\") where we regress $y_0$ on $y_2$ using all data points and then use the $h$ residuals as the independent variable in a regression with the residuals of $y_1$ regressed on $y_2$ (for the $h$ $y_1$ points we observe) and (\"Perfect A\", \"Perfect B\") then two versions where I calculate the perfect residuals of $y_0$ on $y_2$ using the exactly correct slope:\n\n\n\n\n\n# Simulation to Compare OLS and Residualized Regression Methods\n# Adjust n, h, and num_sims as needed\n\nset.seed(42)\nn <- 60\nh <- 30\nnum_sims <- 50000\n\n# Storage vectors for beta estimates\nsfm <- shm <- shpa <- shpb <- sheb <- numeric(num_sims)\n\nfor (i in 1:num_sims) {\n # 1. Generate base standard normal variables\n x0 <- rnorm(n); x1 <- rnorm(n); x2 <- rnorm(n); x3 <- rnorm(n)\n y0 <- x0 + x1; y1 <- x1 + x2; y2 <- x0 + x3\n \n # Half-sample subsets\n x0h <- x0[1:h]; x1h <- x1[1:h]; x2h <- x2[1:h]\n y0h <- y0[1:h]; y1h <- y1[1:h]; y2h <- y2[1:h]\n \n # 2. Full Model (sfm) - benchmark using full sample (N = n)\n sfm[i] <- coef(lm(y1 ~ y0 + y2))[\"y0\"]\n \n # 3. Half Model (shm) - standard multiple regression on half sample (N = h)\n shm[i] <- coef(lm(y1h ~ y0h + y2h))[\"y0h\"]\n \n # 4. Perfect A (shpa) - Y1 regressed on Y0 after partialing out Y2 using true population parameter (0.5)\n y0rph <- y0h - 0.5 * y2h\n shpa[i] <- coef(lm(y1h ~ y0rph))[\"y0rph\"]\n \n # 5. Perfect B (shpb) - Residualized Y1 (half OLS) on residualized Y0 (true parameter)\n y1rh <- residuals(lm(y1h ~ y2h))\n shpb[i] <- coef(lm(y1rh ~ y0rph))[\"y0rph\"]\n \n # 6. Estimated B (sheb) - Residualized Y1 (half OLS) on residualized Y0 (estimated on full sample)\n y0re <- residuals(lm(y0 ~ y2))\n y0reh <- y0re[1:h]\n sheb[i] <- coef(lm(y1rh ~ y0reh))[\"y0reh\"]\n}\n\n# True theoretical beta for y0 in y1 ~ y0 + y2 is 2/3 (~0.66667)\ntrue_beta <- 2/3\n\n# Evaluation function for bias, variance, and MSE\nevaluate_estimates <- function(estimates, truth) {\n est <- na.omit(estimates)\n m <- mean(est)\n v <- var(est)\n bias <- m - truth\n mse <- mean((est - truth)^2)\n c(Mean = m, Variance = v, Bias = bias, Bias_Sq = bias^2, MSE = mse)\n}\n\n# Aggregate and display results table\nmodels_list <- list(\n \"Full Model (sfm)\" = sfm,\n \"Half Model (shm)\" = shm,\n \"Perfect A (shpa)\" = shpa,\n \"Perfect B (shpb)\" = shpb,\n \"Estimated B (sheb)\" = sheb\n)\n\nresults_matrix <- t(sapply(models_list, evaluate_estimates, truth = true_beta))\nprint(round(results_matrix, 5))\n# Mean Variance Bias Bias_Sq MSE\n# Full Model (sfm) 0.66641 0.01594 -0.00025 0.00000 0.01594\n# Half Model (shm) 0.66566 0.03424 -0.00101 0.00000 0.03424\n# Perfect A (shpa) 0.66565 0.03296 -0.00101 0.00000 0.03296\n# Perfect B (shpb) 0.64255 0.03276 -0.02412 0.00058 0.03334\n# Estimated B (sheb) 0.65333 0.03325 -0.01334 0.00018 0.03342\n\n\n\n\n\nAs you can see in the results above, the \"Estimated B\" version, the one where we use all data, has a slighly lower MSE of 0.03342 than that of the multiple regression using only fully observed points (\"Half Model\"), but it does have a bias.\n\n\n\n\nUPDATE (2/2):\nPer @EdM 's comment, I used the lavaan approach from section 1.3.2 of this book (https://stefvanbuuren.name/fimd/sec-simplesolutions.html) and the bias does go away, but compared to just doing a standard multiple regression with only the points i have all data for, it appears the MSE (0.07180) is actually higher??:\n\n\n\n\n\n\n\n\n\nModel\nMean\nVariance\nBias\nBias_Sq\nMSE\nValid_Runs\n\n\n\n\n\n\n\n\n\tFull Model (N=40)\n\t0.66563\n\t0.02497\n\t-0.00103\n\t0.00000\n\t0.02497\n\t9947\n\n\n\n\n\n\n\tHalf Model (H=20)\n\t0.66289\n\t0.05542\n\t-0.00377\n\t0.00001\n\t0.05543\n\t9947\n\n\n\n\n\n\n\tEstimated B\n\t0.64330\n\t0.05259\n\t-0.02337\n\t0.00055\n\t0.05313\n\t9947\n\n\n\n\n\n\n\tLavaan Pairwise\n\t0.65849\n\t0.07174\n\t-0.00818\n\t0.00007\n\t0.07180\n\t9947\n\n\n\n\n\n\n\n\n\nI am including the code i ran below:\n\n\n\n\n# Simulation: Missing Data Regression\n# Comparing Two-Stage Residualization (Estimated B) vs Pairwise Deletion (Lavaan)\n\n# Note: If you do not have lavaan installed, run: install.packages(\"lavaan\")\nlibrary(lavaan)\n\nset.seed(123)\nn <- 40\nh <- 20\nnum_sims <- 10000 # Safe to run at scale now; failures are caught automatically\n\n# Initialize storage vectors with NA so un-run or failed iterations don't skew stats\nsfm <- rep(NA, num_sims) # Full Model\nshm <- rep(NA, num_sims) # Half Model\nsheb <- rep(NA, num_sims) # Estimated B\nslav <- rep(NA, num_sims) # Lavaan Pairwise\n\n# Define Lavaan model syntax once outside the loop\nmodel_syntax <- \"\n y1 ~ 1 + y0 + y2\n y1 ~~ y1\n\"\n\ncat(\"Running\", num_sims, \"simulations. Please wait...\\n\")\n\nfor (i in 1:num_sims) {\n # 1. Generate base standard normal variables\n x0 <- rnorm(n); x1 <- rnorm(n); x2 <- rnorm(n); x3 <- rnorm(n)\n y0 <- x0 + x1; y1 <- x1 + x2; y2 <- x0 + x3\n \n # Subsets for missing data\n y0h <- y0[1:h]; y1h <- y1[1:h]; y2h <- y2[1:h]\n \n # Setup Lavaan data and summary statistics\n y1_full <- c(y1h, rep(NA, n - h))\n df <- data.frame(y1 = y1_full, y0 = y0, y2 = y2)\n \n mu <- colMeans(df, na.rm = TRUE)\n cv <- cov(df, use = \"pairwise.complete.obs\")\n \n # 2. Try running Lavaan. If the covariance matrix is non-positive-definite, catch it.\n lav_fit <- tryCatch({\n suppressWarnings(lavaan(model_syntax, \n sample.mean = mu, \n sample.cov = cv, \n sample.nobs = h))\n }, error = function(e) {\n NULL\n })\n \n # 3. Only store estimates if Lavaan successfully converged\n if (!is.null(lav_fit)) {\n # Lavaan estimate\n params <- parameterEstimates(lav_fit)\n slav[i] <- params[params$lhs == \"y1\" & params$rhs == \"y0\", \"est\"]\n \n # Full Model (sfm)\n sfm[i] <- coef(lm(y1 ~ y0 + y2))[\"y0\"]\n \n # Half Model (shm)\n shm[i] <- coef(lm(y1h ~ y0h + y2h))[\"y0h\"]\n \n # Estimated B (sheb)\n y0re <- residuals(lm(y0 ~ y2))\n y0reh <- y0re[1:h]\n y1rh <- residuals(lm(y1h ~ y2h))\n sheb[i] <- coef(lm(y1rh ~ y0reh))[\"y0reh\"]\n }\n}\n\n# True theoretical beta for y0 in y1 ~ y0 + y2 is 2/3 (~0.66667)\ntrue_beta <- 2/3\n\n# Evaluation function for bias, variance, and MSE (automatically strips NAs)\nevaluate_estimates <- function(estimates, truth) {\n est <- na.omit(estimates)\n m <- mean(est)\n v <- var(est)\n bias <- m - truth\n mse <- mean((est - truth)^2)\n c(Mean = m, Variance = v, Bias = bias, Bias_Sq = bias^2, MSE = mse, Valid_Runs = length(est))\n}\n\n# Aggregate and display results table\nmodels_list <- list(\n \"Full Model (N=40)\" = sfm,\n \"Half Model (H=20)\" = shm,\n \"Estimated B\" = sheb,\n \"Lavaan Pairwise\" = slav\n)\n\nresults_matrix <- t(sapply(models_list, evaluate_estimates, truth = true_beta))\ncat(\"\\n--- Simulation Results ---\\n\")\nprint(round(results_matrix, 5))", "record_id": "Scientific-Statistics-QA:stats:676935", "selected_answer": {"answer_html": "
\n

is trying to use all the data a flawed concept to begin with?

\n
\n

No. On the contrary, limiting analysis only to complete-data cases is typically flawed. An exception is if the data are "missing completely at random" (MCAR), as in the data that you simulated. Then you get unbiased results, with the cost of higher standard errors than you would have if all of the data were available.

\n
\n

is this even a valid approach to begin with...?

\n
\n

Your most recent comparisons of methods show that your approach seems to trade off some increased bias against lower variance. Whether that's a good tradeoff depends on how you will apply the model in practice. As Frank Harrell noted in a comment, this type of 2-stage approach will only work for linear regression. With binary, categorical, ordinal or count outcomes, you need other methods if data are not MCAR.

\n
\n

what is the "best" approach?

\n
\n

For MCAR data, complete-case analysis is certainly simplest. The question in any application is whether the MCAR assumption is close enough to valid. If not, substantial bias can ensue.

\n

A standard general approach is multiple imputation. Imputation uses a model of the available data (based on both the outcome values and data not included in the ultimate regression model per se) to estimate the missing data values themselves.

\n

A single imputation, however, also doesn't take into account the random error inherent in making the estimates. You impute multiple complete data sets that draw from the distributions of the imputed values. You fit your ultimate regression model on each of the imputed data sets, and combine the results in a specific way that takes the random variability of the data estimates into account.

\n

Stef van Buuren's Flexible Imputation of Missing Data is a comprehensive guide to the process, which is implemented in his R mice package. Chapter 3 of Regression Modeling Strategies by Frank Harrell also covers how to handle missing data and describes the associated functions in his rms and Hmisc packages.

\n
\n

Does the validity depend on the pattern of missing data?

\n
\n

Yes, in two ways.

\n

First, multiple imputation works correctly if the data are "missing at random" (MAR) in a technical sense. MAR holds if the available data contain all the information about the probability of a value being missing. That assumption can't be tested directly, but you can evaluate how much reasonable deviations from MAR might matter.

\n

Second, the model for imputation needs to represent the patterns of association among the data values adequately.

\n

The references linked above go into much more detail.

\n", "answer_id": 676936, "answer_text": "is trying to use all the data a flawed concept to begin with?\n\n\n\n\n\n\n\nNo. On the contrary, limiting analysis only to complete-data cases is typically flawed. An exception is if the data are \"missing completely at random\" (MCAR), as in the data that you simulated. Then you get unbiased results, with the cost of higher standard errors than you would have if all of the data were available.\n\n\n\n\n\n\n\nis this even a valid approach to begin with...?\n\n\n\n\n\n\n\nYour most recent comparisons of methods show that your approach seems to trade off some increased bias against lower variance. Whether that's a good tradeoff depends on how you will apply the model in practice. As Frank Harrell noted in a comment, this type of 2-stage approach will only work for linear regression. With binary, categorical, ordinal or count outcomes, you need other methods if data are not MCAR.\n\n\n\n\n\n\n\nwhat is the \"best\" approach?\n\n\n\n\n\n\n\nFor MCAR data, complete-case analysis is certainly simplest. The question in any application is whether the MCAR assumption is close enough to valid. If not, substantial bias can ensue.\n\n\n\n\nA standard general approach is multiple imputation (https://stats.stackexchange.com/tags/multiple-imputation/info). Imputation uses a model of the available data (based on both the outcome values and data not included in the ultimate regression model per se) to estimate the missing data values themselves.\n\n\n\n\nA single imputation, however, also doesn't take into account the random error inherent in making the estimates. You impute multiple complete data sets that draw from the distributions of the imputed values. You fit your ultimate regression model on each of the imputed data sets, and combine the results in a specific way that takes the random variability of the data estimates into account.\n\n\n\n\nStef van Buuren's Flexible Imputation of Missing Data (https://stefvanbuuren.name/fimd/) is a comprehensive guide to the process, which is implemented in his R mice package (https://cran.r-project.org/package=mice). Chapter 3 of Regression Modeling Strategies (https://hbiostat.org/rmsc/missing) by Frank Harrell also covers how to handle missing data and describes the associated functions in his rms (https://cran.r-project.org/package=rms) and Hmisc (https://cran.r-project.org/package=Hmisc) packages.\n\n\n\n\n\n\n\nDoes the validity depend on the pattern of missing data?\n\n\n\n\n\n\n\nYes, in two ways.\n\n\n\n\nFirst, multiple imputation works correctly if the data are \"missing at random\" (MAR) in a technical sense. MAR holds if the available data contain all the information about the probability of a value being missing. That assumption can't be tested directly, but you can evaluate how much reasonable deviations from MAR might matter.\n\n\n\n\nSecond, the model for imputation needs to represent the patterns of association among the data values adequately.\n\n\n\n\nThe references linked above go into much more detail.", "answer_url": "https://stats.stackexchange.com/a/676936", "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-22T20:30:48+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": 676935, "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-22T20:30:48+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "3A662AF2-F298-45A5-889D-7BDCBFDD001E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3A662AF2-F298-45A5-889D-7BDCBFDD001E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-23T17:43:21+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "2EC4B878-67AD-4FF7-A28A-CBFDF9E04A10", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2EC4B878-67AD-4FF7-A28A-CBFDF9E04A10/view-source"}], "score": 5, "updated_at": "2026-08-23T17:43:21+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "
\n

is trying to use all the data a flawed concept to begin with?

\n
\n

No. On the contrary, limiting analysis only to complete-data cases is typically flawed. An exception is if the data are "missing completely at random" (MCAR), as in the data that you simulated. Then you get unbiased results, with the cost of higher standard errors than you would have if all of the data were available.

\n
\n

is this even a valid approach to begin with...?

\n
\n

Your most recent comparisons of methods show that your approach seems to trade off some increased bias against lower variance. Whether that's a good tradeoff depends on how you will apply the model in practice. As Frank Harrell noted in a comment, this type of 2-stage approach will only work for linear regression. With binary, categorical, ordinal or count outcomes, you need other methods if data are not MCAR.

\n
\n

what is the "best" approach?

\n
\n

For MCAR data, complete-case analysis is certainly simplest. The question in any application is whether the MCAR assumption is close enough to valid. If not, substantial bias can ensue.

\n

A standard general approach is multiple imputation. Imputation uses a model of the available data (based on both the outcome values and data not included in the ultimate regression model per se) to estimate the missing data values themselves.

\n

A single imputation, however, also doesn't take into account the random error inherent in making the estimates. You impute multiple complete data sets that draw from the distributions of the imputed values. You fit your ultimate regression model on each of the imputed data sets, and combine the results in a specific way that takes the random variability of the data estimates into account.

\n

Stef van Buuren's Flexible Imputation of Missing Data is a comprehensive guide to the process, which is implemented in his R mice package. Chapter 3 of Regression Modeling Strategies by Frank Harrell also covers how to handle missing data and describes the associated functions in his rms and Hmisc packages.

\n
\n

Does the validity depend on the pattern of missing data?

\n
\n

Yes, in two ways.

\n

First, multiple imputation works correctly if the data are "missing at random" (MAR) in a technical sense. MAR holds if the available data contain all the information about the probability of a value being missing. That assumption can't be tested directly, but you can evaluate how much reasonable deviations from MAR might matter.

\n

Second, the model for imputation needs to represent the patterns of association among the data values adequately.

\n

The references linked above go into much more detail.

\n", "answer_id": 676936, "answer_text": "is trying to use all the data a flawed concept to begin with?\n\n\n\n\n\n\n\nNo. On the contrary, limiting analysis only to complete-data cases is typically flawed. An exception is if the data are \"missing completely at random\" (MCAR), as in the data that you simulated. Then you get unbiased results, with the cost of higher standard errors than you would have if all of the data were available.\n\n\n\n\n\n\n\nis this even a valid approach to begin with...?\n\n\n\n\n\n\n\nYour most recent comparisons of methods show that your approach seems to trade off some increased bias against lower variance. Whether that's a good tradeoff depends on how you will apply the model in practice. As Frank Harrell noted in a comment, this type of 2-stage approach will only work for linear regression. With binary, categorical, ordinal or count outcomes, you need other methods if data are not MCAR.\n\n\n\n\n\n\n\nwhat is the \"best\" approach?\n\n\n\n\n\n\n\nFor MCAR data, complete-case analysis is certainly simplest. The question in any application is whether the MCAR assumption is close enough to valid. If not, substantial bias can ensue.\n\n\n\n\nA standard general approach is multiple imputation (https://stats.stackexchange.com/tags/multiple-imputation/info). Imputation uses a model of the available data (based on both the outcome values and data not included in the ultimate regression model per se) to estimate the missing data values themselves.\n\n\n\n\nA single imputation, however, also doesn't take into account the random error inherent in making the estimates. You impute multiple complete data sets that draw from the distributions of the imputed values. You fit your ultimate regression model on each of the imputed data sets, and combine the results in a specific way that takes the random variability of the data estimates into account.\n\n\n\n\nStef van Buuren's Flexible Imputation of Missing Data (https://stefvanbuuren.name/fimd/) is a comprehensive guide to the process, which is implemented in his R mice package (https://cran.r-project.org/package=mice). Chapter 3 of Regression Modeling Strategies (https://hbiostat.org/rmsc/missing) by Frank Harrell also covers how to handle missing data and describes the associated functions in his rms (https://cran.r-project.org/package=rms) and Hmisc (https://cran.r-project.org/package=Hmisc) packages.\n\n\n\n\n\n\n\nDoes the validity depend on the pattern of missing data?\n\n\n\n\n\n\n\nYes, in two ways.\n\n\n\n\nFirst, multiple imputation works correctly if the data are \"missing at random\" (MAR) in a technical sense. MAR holds if the available data contain all the information about the probability of a value being missing. That assumption can't be tested directly, but you can evaluate how much reasonable deviations from MAR might matter.\n\n\n\n\nSecond, the model for imputation needs to represent the patterns of association among the data values adequately.\n\n\n\n\nThe references linked above go into much more detail.", "answer_url": "https://stats.stackexchange.com/a/676936", "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-22T20:30:48+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": 676935, "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-22T20:30:48+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "3A662AF2-F298-45A5-889D-7BDCBFDD001E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3A662AF2-F298-45A5-889D-7BDCBFDD001E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-23T17:43:21+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "2EC4B878-67AD-4FF7-A28A-CBFDF9E04A10", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2EC4B878-67AD-4FF7-A28A-CBFDF9E04A10/view-source"}], "score": 5, "updated_at": "2026-08-23T17:43:21+00:00"}], "domain": "statistics", "external_links": ["https://cran.r-project.org/package=Hmisc", "https://cran.r-project.org/package=mice", "https://cran.r-project.org/package=rms", "https://hbiostat.org/rmsc/missing", "https://stefvanbuuren.name/fimd/", "https://stefvanbuuren.name/fimd/sec-simplesolutions.html"], "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": "A Friendly Fish", "question_author_url": "https://stats.stackexchange.com/users/398015/a-friendly-fish", "question_author_user_type": "registered", "question_created_at": "2026-08-22T12:39:55+00:00", "question_html": "

I observe 3 variables, $y_0$, $y_1$, and $y_2$, but am missing some of the observations for $y_1$, so I only have a subsample of $h$ observations of $y_1$ and all $n$ observations of $y_0$ and $y_2$. My goal is to study the relationship between $y_0$ and $y_1$ while controlling for $y_2$ while taking full advantage of all observations. Thus, instead of using only $h$ observations to run the multiple regression ${y_1}_h \\sim {y_0}_h + {y_2}_h$ where the second subscript represents whether we are using just $h$ (or all $n$) observations, I am instead first running ${y_0}_n \\sim {y_2}_n$ and ${y_1}_h \\sim {y_2}_h$ and then regressing the residuals from these two regressions on each other: $r_{y_1 \\sim y_2, h} \\sim r_{y_0 \\sim y_2, n}$. Of course, I only use the $h$ corresponding residuals from the ${y_0}_n \\sim {y_2}_n$ regression of $n$ points for the second stage regression. Now typically when all three variables have the same number of observations, the degrees of freedom in the second regression of residuals is one less than it otherwise would be, but in this case, we actually lose less than 1 degree of freedom. However, I do not know the formula (if one exists), so what I am currently doing is simulating null data, and testing different degree of freedom subtractions, to see which one either A) gives the proper 5% rejection rate or B) gives the same rejection rate as the multiple regression that uses only $h$ data points. So, I think method A is more technically correct than B, but B seems to work better. I have written some R code where $n$ is 40 and $h$ is 20, where I'm pretty sure the correction is 0.5 degrees of freedom, which matches better with method B instead of method A. Ultimately if there isn't a formula (one would be welcome), what is the "best" approach? Overall, is this even a valid approach to begin with or is trying to use all the data a flawed concept to begin with? Does the validity depend on the pattern of missing data?

\n
# R code\ndof_correction<-0.5; set.seed(0)\nnum_sims<-10^4; h<-20; n<-40\nmultiple<-stage<-numeric(num_sims) # initialize vectors for storing p-values\nfor (i in 1:num_sims) {\n    y0<-rnorm(n); y0h<-y0[1:h]; y1h<-rnorm(h); y2<-rnorm(n); y2h<-y2[1:h]\n    ly1ONy0y2_h<-lm(y1h ~ y0h + y2h)\n    multiple[i]<-coefficients(summary(ly1ONy0y2_h))["y0h","Pr(>|t|)"]\n    ly0ONy2_n<-lm(y0 ~ y2); r_ly0ONy2_n<-residuals(ly0ONy2_n); \n    r_ly0ONy2_n_h<-r_ly0ONy2_n[1:h]\n    ly1ONy2_h<-lm(y1h ~ y2h); r_ly1ONy2_h<-residuals(ly1ONy2_h)\n    lrONr<-lm(r_ly1ONy2_h ~ r_ly0ONy2_n_h)\n    lrONr$df.residual <- lrONr$df.residual - dof_correction\n    stage[i]<-coefficients(summary(lrONr))["r_ly0ONy2_n_h","Pr(>|t|)"]\n}\ncat("Multiple:   ", mean(multiple < 0.05), "\\n")\n# Multiple:    0.0529 \ncat("   Stage:   ", mean(stage < 0.05), "\\n")\n#    Stage:    0.0527 \n
\n

Observe that using a dof correction of 0.5 gives a rejection rate (0.527) closer to that found using multiple regression (0.529) than it does to the actual theoretical rate of (0.500)

\n

UPDATE (1/2):\nI ran simulation code to compare some of the key models, ("Full") one where we actually aren't missing data, ("Half") one where we only use $h$ observations, ("Estimated B") where we regress $y_0$ on $y_2$ using all data points and then use the $h$ residuals as the independent variable in a regression with the residuals of $y_1$ regressed on $y_2$ (for the $h$ $y_1$ points we observe) and ("Perfect A", "Perfect B") then two versions where I calculate the perfect residuals of $y_0$ on $y_2$ using the exactly correct slope:

\n
\n# Simulation to Compare OLS and Residualized Regression Methods\n# Adjust n, h, and num_sims as needed\n\nset.seed(42)\nn <- 60\nh <- 30\nnum_sims <- 50000\n\n# Storage vectors for beta estimates\nsfm <- shm <- shpa <- shpb <- sheb <- numeric(num_sims)\n\nfor (i in 1:num_sims) {\n  # 1. Generate base standard normal variables\n  x0 <- rnorm(n); x1 <- rnorm(n); x2 <- rnorm(n); x3 <- rnorm(n)\n  y0 <- x0 + x1;  y1 <- x1 + x2;  y2 <- x0 + x3\n  \n  # Half-sample subsets\n  x0h <- x0[1:h]; x1h <- x1[1:h]; x2h <- x2[1:h]\n  y0h <- y0[1:h]; y1h <- y1[1:h]; y2h <- y2[1:h]\n  \n  # 2. Full Model (sfm) - benchmark using full sample (N = n)\n  sfm[i] <- coef(lm(y1 ~ y0 + y2))["y0"]\n  \n  # 3. Half Model (shm) - standard multiple regression on half sample (N = h)\n  shm[i] <- coef(lm(y1h ~ y0h + y2h))["y0h"]\n  \n  # 4. Perfect A (shpa) - Y1 regressed on Y0 after partialing out Y2 using true population parameter (0.5)\n  y0rph <- y0h - 0.5 * y2h\n  shpa[i] <- coef(lm(y1h ~ y0rph))["y0rph"]\n  \n  # 5. Perfect B (shpb) - Residualized Y1 (half OLS) on residualized Y0 (true parameter)\n  y1rh <- residuals(lm(y1h ~ y2h))\n  shpb[i] <- coef(lm(y1rh ~ y0rph))["y0rph"]\n  \n  # 6. Estimated B (sheb) - Residualized Y1 (half OLS) on residualized Y0 (estimated on full sample)\n  y0re <- residuals(lm(y0 ~ y2))\n  y0reh <- y0re[1:h]\n  sheb[i] <- coef(lm(y1rh ~ y0reh))["y0reh"]\n}\n\n# True theoretical beta for y0 in y1 ~ y0 + y2 is 2/3 (~0.66667)\ntrue_beta <- 2/3\n\n# Evaluation function for bias, variance, and MSE\nevaluate_estimates <- function(estimates, truth) {\n  est <- na.omit(estimates)\n  m <- mean(est)\n  v <- var(est)\n  bias <- m - truth\n  mse <- mean((est - truth)^2)\n  c(Mean = m, Variance = v, Bias = bias, Bias_Sq = bias^2, MSE = mse)\n}\n\n# Aggregate and display results table\nmodels_list <- list(\n  "Full Model (sfm)"    = sfm,\n  "Half Model (shm)"    = shm,\n  "Perfect A (shpa)"    = shpa,\n  "Perfect B (shpb)"    = shpb,\n  "Estimated B (sheb)"  = sheb\n)\n\nresults_matrix <- t(sapply(models_list, evaluate_estimates, truth = true_beta))\nprint(round(results_matrix, 5))\n#                       Mean Variance     Bias Bias_Sq     MSE\n# Full Model (sfm)   0.66641  0.01594 -0.00025 0.00000 0.01594\n# Half Model (shm)   0.66566  0.03424 -0.00101 0.00000 0.03424\n# Perfect A (shpa)   0.66565  0.03296 -0.00101 0.00000 0.03296\n# Perfect B (shpb)   0.64255  0.03276 -0.02412 0.00058 0.03334\n# Estimated B (sheb) 0.65333  0.03325 -0.01334 0.00018 0.03342\n
\n

As you can see in the results above, the "Estimated B" version, the one where we use all data, has a slighly lower MSE of 0.03342 than that of the multiple regression using only fully observed points ("Half Model"), but it does have a bias.

\n

UPDATE (2/2):\nPer @EdM 's comment, I used the lavaan approach from section 1.3.2 of this book and the bias does go away, but compared to just doing a standard multiple regression with only the points i have all data for, it appears the MSE (0.07180) is actually higher??:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ModelMeanVarianceBiasBias_SqMSEValid_Runs
Full Model (N=40)0.665630.02497-0.001030.000000.024979947
Half Model (H=20)0.662890.05542-0.003770.000010.055439947
Estimated B0.643300.05259-0.023370.000550.053139947
Lavaan Pairwise0.658490.07174-0.008180.000070.071809947
\n

I am including the code i ran below:

\n
# Simulation: Missing Data Regression\n# Comparing Two-Stage Residualization (Estimated B) vs Pairwise Deletion (Lavaan)\n\n# Note: If you do not have lavaan installed, run: install.packages("lavaan")\nlibrary(lavaan)\n\nset.seed(123)\nn <- 40\nh <- 20\nnum_sims <- 10000  # Safe to run at scale now; failures are caught automatically\n\n# Initialize storage vectors with NA so un-run or failed iterations don't skew stats\nsfm  <- rep(NA, num_sims) # Full Model\nshm  <- rep(NA, num_sims) # Half Model\nsheb <- rep(NA, num_sims) # Estimated B\nslav <- rep(NA, num_sims) # Lavaan Pairwise\n\n# Define Lavaan model syntax once outside the loop\nmodel_syntax <- "\n  y1 ~ 1 + y0 + y2\n  y1 ~~ y1\n"\n\ncat("Running", num_sims, "simulations. Please wait...\\n")\n\nfor (i in 1:num_sims) {\n  # 1. Generate base standard normal variables\n  x0 <- rnorm(n); x1 <- rnorm(n); x2 <- rnorm(n); x3 <- rnorm(n)\n  y0 <- x0 + x1;  y1 <- x1 + x2;  y2 <- x0 + x3\n  \n  # Subsets for missing data\n  y0h <- y0[1:h]; y1h <- y1[1:h]; y2h <- y2[1:h]\n  \n  # Setup Lavaan data and summary statistics\n  y1_full <- c(y1h, rep(NA, n - h))\n  df <- data.frame(y1 = y1_full, y0 = y0, y2 = y2)\n  \n  mu <- colMeans(df, na.rm = TRUE)\n  cv <- cov(df, use = "pairwise.complete.obs")\n  \n  # 2. Try running Lavaan. If the covariance matrix is non-positive-definite, catch it.\n  lav_fit <- tryCatch({\n    suppressWarnings(lavaan(model_syntax, \n                            sample.mean = mu, \n                            sample.cov = cv, \n                            sample.nobs = h))\n  }, error = function(e) {\n    NULL\n  })\n  \n  # 3. Only store estimates if Lavaan successfully converged\n  if (!is.null(lav_fit)) {\n    # Lavaan estimate\n    params <- parameterEstimates(lav_fit)\n    slav[i] <- params[params$lhs == \"y1\" & params$rhs == "y0", "est"]\n    \n    # Full Model (sfm)\n    sfm[i] <- coef(lm(y1 ~ y0 + y2))["y0"]\n    \n    # Half Model (shm)\n    shm[i] <- coef(lm(y1h ~ y0h + y2h))["y0h"]\n    \n    # Estimated B (sheb)\n    y0re <- residuals(lm(y0 ~ y2))\n    y0reh <- y0re[1:h]\n    y1rh <- residuals(lm(y1h ~ y2h))\n    sheb[i] <- coef(lm(y1rh ~ y0reh))["y0reh"]\n  }\n}\n\n# True theoretical beta for y0 in y1 ~ y0 + y2 is 2/3 (~0.66667)\ntrue_beta <- 2/3\n\n# Evaluation function for bias, variance, and MSE (automatically strips NAs)\nevaluate_estimates <- function(estimates, truth) {\n  est <- na.omit(estimates)\n  m <- mean(est)\n  v <- var(est)\n  bias <- m - truth\n  mse <- mean((est - truth)^2)\n  c(Mean = m, Variance = v, Bias = bias, Bias_Sq = bias^2, MSE = mse, Valid_Runs = length(est))\n}\n\n# Aggregate and display results table\nmodels_list <- list(\n  "Full Model (N=40)"      = sfm,\n  "Half Model (H=20)"      = shm,\n  "Estimated B"            = sheb,\n  "Lavaan Pairwise"        = slav\n)\n\nresults_matrix <- t(sapply(models_list, evaluate_estimates, truth = true_beta))\ncat("\\n--- Simulation Results ---\\n")\nprint(round(results_matrix, 5))\n
\n", "question_id": 676935, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I observe 3 variables, $y_0$, $y_1$, and $y_2$, but am missing some of the observations for $y_1$, so I only have a subsample of $h$ observations of $y_1$ and all $n$ observations of $y_0$ and $y_2$. My goal is to study the relationship between $y_0$ and $y_1$ while controlling for $y_2$ while taking full advantage of all observations. Thus, instead of using only $h$ observations to run the multiple regression ${y_1}_h \\sim {y_0}_h + {y_2}_h$ where the second subscript represents whether we are using just $h$ (or all $n$) observations, I am instead first running ${y_0}_n \\sim {y_2}_n$ and ${y_1}_h \\sim {y_2}_h$ and then regressing the residuals from these two regressions on each other: $r_{y_1 \\sim y_2, h} \\sim r_{y_0 \\sim y_2, n}$. Of course, I only use the $h$ corresponding residuals from the ${y_0}_n \\sim {y_2}_n$ regression of $n$ points for the second stage regression. Now typically when all three variables have the same number of observations, the degrees of freedom in the second regression of residuals is one less than it otherwise would be, but in this case, we actually lose less than 1 degree of freedom. However, I do not know the formula (if one exists), so what I am currently doing is simulating null data, and testing different degree of freedom subtractions, to see which one either A) gives the proper 5% rejection rate or B) gives the same rejection rate as the multiple regression that uses only $h$ data points. So, I think method A is more technically correct than B, but B seems to work better. I have written some R code where $n$ is 40 and $h$ is 20, where I'm pretty sure the correction is 0.5 degrees of freedom, which matches better with method B instead of method A. Ultimately if there isn't a formula (one would be welcome), what is the \"best\" approach? Overall, is this even a valid approach to begin with or is trying to use all the data a flawed concept to begin with? Does the validity depend on the pattern of missing data?\n\n\n\n\n# R code\ndof_correction<-0.5; set.seed(0)\nnum_sims<-10^4; h<-20; n<-40\nmultiple<-stage<-numeric(num_sims) # initialize vectors for storing p-values\nfor (i in 1:num_sims) {\n y0<-rnorm(n); y0h<-y0[1:h]; y1h<-rnorm(h); y2<-rnorm(n); y2h<-y2[1:h]\n ly1ONy0y2_h<-lm(y1h ~ y0h + y2h)\n multiple[i]<-coefficients(summary(ly1ONy0y2_h))[\"y0h\",\"Pr(>|t|)\"]\n ly0ONy2_n<-lm(y0 ~ y2); r_ly0ONy2_n<-residuals(ly0ONy2_n); \n r_ly0ONy2_n_h<-r_ly0ONy2_n[1:h]\n ly1ONy2_h<-lm(y1h ~ y2h); r_ly1ONy2_h<-residuals(ly1ONy2_h)\n lrONr<-lm(r_ly1ONy2_h ~ r_ly0ONy2_n_h)\n lrONr$df.residual <- lrONr$df.residual - dof_correction\n stage[i]<-coefficients(summary(lrONr))[\"r_ly0ONy2_n_h\",\"Pr(>|t|)\"]\n}\ncat(\"Multiple: \", mean(multiple < 0.05), \"\\n\")\n# Multiple: 0.0529 \ncat(\" Stage: \", mean(stage < 0.05), \"\\n\")\n# Stage: 0.0527 \n\n\n\n\n\nObserve that using a dof correction of 0.5 gives a rejection rate (0.527) closer to that found using multiple regression (0.529) than it does to the actual theoretical rate of (0.500)\n\n\n\n\nUPDATE (1/2):\nI ran simulation code to compare some of the key models, (\"Full\") one where we actually aren't missing data, (\"Half\") one where we only use $h$ observations, (\"Estimated B\") where we regress $y_0$ on $y_2$ using all data points and then use the $h$ residuals as the independent variable in a regression with the residuals of $y_1$ regressed on $y_2$ (for the $h$ $y_1$ points we observe) and (\"Perfect A\", \"Perfect B\") then two versions where I calculate the perfect residuals of $y_0$ on $y_2$ using the exactly correct slope:\n\n\n\n\n\n# Simulation to Compare OLS and Residualized Regression Methods\n# Adjust n, h, and num_sims as needed\n\nset.seed(42)\nn <- 60\nh <- 30\nnum_sims <- 50000\n\n# Storage vectors for beta estimates\nsfm <- shm <- shpa <- shpb <- sheb <- numeric(num_sims)\n\nfor (i in 1:num_sims) {\n # 1. Generate base standard normal variables\n x0 <- rnorm(n); x1 <- rnorm(n); x2 <- rnorm(n); x3 <- rnorm(n)\n y0 <- x0 + x1; y1 <- x1 + x2; y2 <- x0 + x3\n \n # Half-sample subsets\n x0h <- x0[1:h]; x1h <- x1[1:h]; x2h <- x2[1:h]\n y0h <- y0[1:h]; y1h <- y1[1:h]; y2h <- y2[1:h]\n \n # 2. Full Model (sfm) - benchmark using full sample (N = n)\n sfm[i] <- coef(lm(y1 ~ y0 + y2))[\"y0\"]\n \n # 3. Half Model (shm) - standard multiple regression on half sample (N = h)\n shm[i] <- coef(lm(y1h ~ y0h + y2h))[\"y0h\"]\n \n # 4. Perfect A (shpa) - Y1 regressed on Y0 after partialing out Y2 using true population parameter (0.5)\n y0rph <- y0h - 0.5 * y2h\n shpa[i] <- coef(lm(y1h ~ y0rph))[\"y0rph\"]\n \n # 5. Perfect B (shpb) - Residualized Y1 (half OLS) on residualized Y0 (true parameter)\n y1rh <- residuals(lm(y1h ~ y2h))\n shpb[i] <- coef(lm(y1rh ~ y0rph))[\"y0rph\"]\n \n # 6. Estimated B (sheb) - Residualized Y1 (half OLS) on residualized Y0 (estimated on full sample)\n y0re <- residuals(lm(y0 ~ y2))\n y0reh <- y0re[1:h]\n sheb[i] <- coef(lm(y1rh ~ y0reh))[\"y0reh\"]\n}\n\n# True theoretical beta for y0 in y1 ~ y0 + y2 is 2/3 (~0.66667)\ntrue_beta <- 2/3\n\n# Evaluation function for bias, variance, and MSE\nevaluate_estimates <- function(estimates, truth) {\n est <- na.omit(estimates)\n m <- mean(est)\n v <- var(est)\n bias <- m - truth\n mse <- mean((est - truth)^2)\n c(Mean = m, Variance = v, Bias = bias, Bias_Sq = bias^2, MSE = mse)\n}\n\n# Aggregate and display results table\nmodels_list <- list(\n \"Full Model (sfm)\" = sfm,\n \"Half Model (shm)\" = shm,\n \"Perfect A (shpa)\" = shpa,\n \"Perfect B (shpb)\" = shpb,\n \"Estimated B (sheb)\" = sheb\n)\n\nresults_matrix <- t(sapply(models_list, evaluate_estimates, truth = true_beta))\nprint(round(results_matrix, 5))\n# Mean Variance Bias Bias_Sq MSE\n# Full Model (sfm) 0.66641 0.01594 -0.00025 0.00000 0.01594\n# Half Model (shm) 0.66566 0.03424 -0.00101 0.00000 0.03424\n# Perfect A (shpa) 0.66565 0.03296 -0.00101 0.00000 0.03296\n# Perfect B (shpb) 0.64255 0.03276 -0.02412 0.00058 0.03334\n# Estimated B (sheb) 0.65333 0.03325 -0.01334 0.00018 0.03342\n\n\n\n\n\nAs you can see in the results above, the \"Estimated B\" version, the one where we use all data, has a slighly lower MSE of 0.03342 than that of the multiple regression using only fully observed points (\"Half Model\"), but it does have a bias.\n\n\n\n\nUPDATE (2/2):\nPer @EdM 's comment, I used the lavaan approach from section 1.3.2 of this book (https://stefvanbuuren.name/fimd/sec-simplesolutions.html) and the bias does go away, but compared to just doing a standard multiple regression with only the points i have all data for, it appears the MSE (0.07180) is actually higher??:\n\n\n\n\n\n\n\n\n\nModel\nMean\nVariance\nBias\nBias_Sq\nMSE\nValid_Runs\n\n\n\n\n\n\n\n\n\tFull Model (N=40)\n\t0.66563\n\t0.02497\n\t-0.00103\n\t0.00000\n\t0.02497\n\t9947\n\n\n\n\n\n\n\tHalf Model (H=20)\n\t0.66289\n\t0.05542\n\t-0.00377\n\t0.00001\n\t0.05543\n\t9947\n\n\n\n\n\n\n\tEstimated B\n\t0.64330\n\t0.05259\n\t-0.02337\n\t0.00055\n\t0.05313\n\t9947\n\n\n\n\n\n\n\tLavaan Pairwise\n\t0.65849\n\t0.07174\n\t-0.00818\n\t0.00007\n\t0.07180\n\t9947\n\n\n\n\n\n\n\n\n\nI am including the code i ran below:\n\n\n\n\n# Simulation: Missing Data Regression\n# Comparing Two-Stage Residualization (Estimated B) vs Pairwise Deletion (Lavaan)\n\n# Note: If you do not have lavaan installed, run: install.packages(\"lavaan\")\nlibrary(lavaan)\n\nset.seed(123)\nn <- 40\nh <- 20\nnum_sims <- 10000 # Safe to run at scale now; failures are caught automatically\n\n# Initialize storage vectors with NA so un-run or failed iterations don't skew stats\nsfm <- rep(NA, num_sims) # Full Model\nshm <- rep(NA, num_sims) # Half Model\nsheb <- rep(NA, num_sims) # Estimated B\nslav <- rep(NA, num_sims) # Lavaan Pairwise\n\n# Define Lavaan model syntax once outside the loop\nmodel_syntax <- \"\n y1 ~ 1 + y0 + y2\n y1 ~~ y1\n\"\n\ncat(\"Running\", num_sims, \"simulations. Please wait...\\n\")\n\nfor (i in 1:num_sims) {\n # 1. Generate base standard normal variables\n x0 <- rnorm(n); x1 <- rnorm(n); x2 <- rnorm(n); x3 <- rnorm(n)\n y0 <- x0 + x1; y1 <- x1 + x2; y2 <- x0 + x3\n \n # Subsets for missing data\n y0h <- y0[1:h]; y1h <- y1[1:h]; y2h <- y2[1:h]\n \n # Setup Lavaan data and summary statistics\n y1_full <- c(y1h, rep(NA, n - h))\n df <- data.frame(y1 = y1_full, y0 = y0, y2 = y2)\n \n mu <- colMeans(df, na.rm = TRUE)\n cv <- cov(df, use = \"pairwise.complete.obs\")\n \n # 2. Try running Lavaan. If the covariance matrix is non-positive-definite, catch it.\n lav_fit <- tryCatch({\n suppressWarnings(lavaan(model_syntax, \n sample.mean = mu, \n sample.cov = cv, \n sample.nobs = h))\n }, error = function(e) {\n NULL\n })\n \n # 3. Only store estimates if Lavaan successfully converged\n if (!is.null(lav_fit)) {\n # Lavaan estimate\n params <- parameterEstimates(lav_fit)\n slav[i] <- params[params$lhs == \"y1\" & params$rhs == \"y0\", \"est\"]\n \n # Full Model (sfm)\n sfm[i] <- coef(lm(y1 ~ y0 + y2))[\"y0\"]\n \n # Half Model (shm)\n shm[i] <- coef(lm(y1h ~ y0h + y2h))[\"y0h\"]\n \n # Estimated B (sheb)\n y0re <- residuals(lm(y0 ~ y2))\n y0reh <- y0re[1:h]\n y1rh <- residuals(lm(y1h ~ y2h))\n sheb[i] <- coef(lm(y1rh ~ y0reh))[\"y0reh\"]\n }\n}\n\n# True theoretical beta for y0 in y1 ~ y0 + y2 is 2/3 (~0.66667)\ntrue_beta <- 2/3\n\n# Evaluation function for bias, variance, and MSE (automatically strips NAs)\nevaluate_estimates <- function(estimates, truth) {\n est <- na.omit(estimates)\n m <- mean(est)\n v <- var(est)\n bias <- m - truth\n mse <- mean((est - truth)^2)\n c(Mean = m, Variance = v, Bias = bias, Bias_Sq = bias^2, MSE = mse, Valid_Runs = length(est))\n}\n\n# Aggregate and display results table\nmodels_list <- list(\n \"Full Model (N=40)\" = sfm,\n \"Half Model (H=20)\" = shm,\n \"Estimated B\" = sheb,\n \"Lavaan Pairwise\" = slav\n)\n\nresults_matrix <- t(sapply(models_list, evaluate_estimates, truth = true_beta))\ncat(\"\\n--- Simulation Results ---\\n\")\nprint(round(results_matrix, 5))", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "A Friendly Fish", "profile_url": "https://stats.stackexchange.com/users/398015/a-friendly-fish", "user_type": "registered"}, "created_at": "2026-08-22T12:39:55+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "E204A8FC-AC6E-48BB-AF80-E203CBC8615E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E204A8FC-AC6E-48BB-AF80-E203CBC8615E/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-22T20:46:45+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "18F1A87E-216E-4249-8293-E060F71CC55D", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/18F1A87E-216E-4249-8293-E060F71CC55D/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "A Friendly Fish", "profile_url": "https://stats.stackexchange.com/users/398015/a-friendly-fish", "user_type": "registered"}, "created_at": "2026-08-23T15:52:35+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "70469448-256D-43B2-80C1-746F337D6247", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/70469448-256D-43B2-80C1-746F337D6247/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "A Friendly Fish", "profile_url": "https://stats.stackexchange.com/users/398015/a-friendly-fish", "user_type": "registered"}, "created_at": "2026-08-23T16:01:52+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "8C27F26B-7F68-4C8C-AF88-BCBF88FC34D5", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8C27F26B-7F68-4C8C-AF88-BCBF88FC34D5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "A Friendly Fish", "profile_url": "https://stats.stackexchange.com/users/398015/a-friendly-fish", "user_type": "registered"}, "created_at": "2026-08-23T16:53:21+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "7CE38AE1-F9CC-4D58-8A36-87CDCD90FB30", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7CE38AE1-F9CC-4D58-8A36-87CDCD90FB30/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "A Friendly Fish", "profile_url": "https://stats.stackexchange.com/users/398015/a-friendly-fish", "user_type": "registered"}, "created_at": "2026-08-23T17:02:49+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "AC468C9B-BCFF-4264-A45F-3229DC6759C1", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AC468C9B-BCFF-4264-A45F-3229DC6759C1/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676935/missing-data-break-multiple-regression-into-stages-how", "split": "train", "split_group": "0e07c1b9aeb4ed16810975d0835aae0ada37766b2c187a88bd4ee1b79bc9bf36", "tags": ["regression", "multiple-regression", "degrees-of-freedom", "type-i-and-ii-errors", "two-stage-least-squares"], "thread_id": "stats:676935", "title": "missing data: break multiple regression into stages; how?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "Hi could anyone please help me with this I would be really grateful. I am performing an mixed model ANCOVA to evaluate changes in a response variable (Height) over time and differences among treatments. The baseline measurement is included as a continuous covariate to account for initial differences among individuals. Because the same individuals were measured repeatedly over time, the repeated-measures structure is also accounted for in the model.The experiment is a block split plot experimental design of forestry experiment.\n\n\n\n\nMy model includes treatment, time, and the baseline covariate, including their interactions. I mean-centered the baseline covariate so that a value of zero represents the average baseline value.\n\n\n\n\nModel <- lme( Height_BC ~ Treatments * Years * H_2007_BC_c,\n random = ~1|Blocks/BlocksTreatments/Tree_no,\n na.action = na.omit,\n correlation = corCAR1(form=~as.numeric(Years)|Blocks/BlocksTreatments/Tree_no),\n control = lmeControl(msMaxIter=1000),\n weights = varIdent(form=~1|YearsTreatments),data = mydata)\n\n\n\n\n\nFor post-hoc comparisons, I am using the emmeans package to compare treatments within each time point while setting the centered baseline covariate to zero (my model is box cox transformed). Therefore, these comparisons represent treatment differences for individuals with an average baseline value.\n\n\n\n\nIs this an appropriate way to perform and interpret the ANCOVA? In particular, if the treatment × time × baseline covariate interaction is significant, is it still appropriate to compare treatments within each time point using emmeans at the mean baseline value? My main objective is not related to initial height effect on the performance seedlings growth over time.Thanks", "record_id": "Scientific-Statistics-QA:stats:676937", "selected_answer": {"answer_html": "

If the treatment × time × baseline covariate interaction is significant, then the association between treatment/time and outcome depends on the value of the baseline covariate. It thus would make sense to evaluate treatment effects within each time point over a range of baseline covariate values. That should be easy to do with emmeans and will document whether the "statistically significant" 3-way interaction has much practical significance.

\n

You should also consider, however, whether your model is mis-specified. Sometimes an apparently significant interaction term arises from a model that doesn't adequately capture the functional form of the association between outcome and predictors, in your case the outcome Height_BC and the baseline covariate H_2007_BC_c. A flexible fit of H_2007_BC_c with a regression spline or other generalized additive model might remove the need for the 3-way interaction.

\n

That would seem to make sense in your application; a tree that is already near some practical maximum height might be expected to have less growth or response to treatment than a short tree would. I don't see how your model linear in H_2007_BC_c would capture that.

\n", "answer_id": 676950, "answer_text": "If the treatment × time × baseline covariate interaction is significant, then the association between treatment/time and outcome depends on the value of the baseline covariate. It thus would make sense to evaluate treatment effects within each time point over a range of baseline covariate values. That should be easy to do with emmeans and will document whether the \"statistically significant\" 3-way interaction has much practical significance.\n\n\n\n\nYou should also consider, however, whether your model is mis-specified. Sometimes an apparently significant interaction term arises from a model that doesn't adequately capture the functional form of the association between outcome and predictors, in your case the outcome Height_BC and the baseline covariate H_2007_BC_c. A flexible fit of H_2007_BC_c with a regression spline or other generalized additive model might remove the need for the 3-way interaction.\n\n\n\n\nThat would seem to make sense in your application; a tree that is already near some practical maximum height might be expected to have less growth or response to treatment than a short tree would. I don't see how your model linear in H_2007_BC_c would capture that.", "answer_url": "https://stats.stackexchange.com/a/676950", "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-24T14:51:00+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": 676937, "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-24T14:51:00+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "4625872D-D7E9-488A-978D-1497265026F4", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4625872D-D7E9-488A-978D-1497265026F4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-24T15:03:38+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4367AD31-5A4E-49AB-B710-BD072DAE1542", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4367AD31-5A4E-49AB-B710-BD072DAE1542/view-source"}], "score": 3, "updated_at": "2026-08-24T15:03:38+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

If the treatment × time × baseline covariate interaction is significant, then the association between treatment/time and outcome depends on the value of the baseline covariate. It thus would make sense to evaluate treatment effects within each time point over a range of baseline covariate values. That should be easy to do with emmeans and will document whether the "statistically significant" 3-way interaction has much practical significance.

\n

You should also consider, however, whether your model is mis-specified. Sometimes an apparently significant interaction term arises from a model that doesn't adequately capture the functional form of the association between outcome and predictors, in your case the outcome Height_BC and the baseline covariate H_2007_BC_c. A flexible fit of H_2007_BC_c with a regression spline or other generalized additive model might remove the need for the 3-way interaction.

\n

That would seem to make sense in your application; a tree that is already near some practical maximum height might be expected to have less growth or response to treatment than a short tree would. I don't see how your model linear in H_2007_BC_c would capture that.

\n", "answer_id": 676950, "answer_text": "If the treatment × time × baseline covariate interaction is significant, then the association between treatment/time and outcome depends on the value of the baseline covariate. It thus would make sense to evaluate treatment effects within each time point over a range of baseline covariate values. That should be easy to do with emmeans and will document whether the \"statistically significant\" 3-way interaction has much practical significance.\n\n\n\n\nYou should also consider, however, whether your model is mis-specified. Sometimes an apparently significant interaction term arises from a model that doesn't adequately capture the functional form of the association between outcome and predictors, in your case the outcome Height_BC and the baseline covariate H_2007_BC_c. A flexible fit of H_2007_BC_c with a regression spline or other generalized additive model might remove the need for the 3-way interaction.\n\n\n\n\nThat would seem to make sense in your application; a tree that is already near some practical maximum height might be expected to have less growth or response to treatment than a short tree would. I don't see how your model linear in H_2007_BC_c would capture that.", "answer_url": "https://stats.stackexchange.com/a/676950", "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-24T14:51:00+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": 676937, "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-24T14:51:00+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "4625872D-D7E9-488A-978D-1497265026F4", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4625872D-D7E9-488A-978D-1497265026F4/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-24T15:03:38+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4367AD31-5A4E-49AB-B710-BD072DAE1542", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4367AD31-5A4E-49AB-B710-BD072DAE1542/view-source"}], "score": 3, "updated_at": "2026-08-24T15:03:38+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Birma29", "question_author_url": "https://stats.stackexchange.com/users/515697/birma29", "question_author_user_type": "registered", "question_created_at": "2026-08-22T22:19:04+00:00", "question_html": "

Hi could anyone please help me with this I would be really grateful. I am performing an mixed model ANCOVA to evaluate changes in a response variable (Height) over time and differences among treatments. The baseline measurement is included as a continuous covariate to account for initial differences among individuals. Because the same individuals were measured repeatedly over time, the repeated-measures structure is also accounted for in the model.The experiment is a block split plot experimental design of forestry experiment.

\n

My model includes treatment, time, and the baseline covariate, including their interactions. I mean-centered the baseline covariate so that a value of zero represents the average baseline value.

\n
Model <- lme( Height_BC ~ Treatments * Years * H_2007_BC_c,\n              random = ~1|Blocks/BlocksTreatments/Tree_no,\n              na.action = na.omit,\n              correlation = corCAR1(form=~as.numeric(Years)|Blocks/BlocksTreatments/Tree_no),\n        control = lmeControl(msMaxIter=1000),\n        weights = varIdent(form=~1|YearsTreatments),data = mydata)\n
\n

For post-hoc comparisons, I am using the emmeans package to compare treatments within each time point while setting the centered baseline covariate to zero (my model is box cox transformed). Therefore, these comparisons represent treatment differences for individuals with an average baseline value.

\n

Is this an appropriate way to perform and interpret the ANCOVA? In particular, if the treatment × time × baseline covariate interaction is significant, is it still appropriate to compare treatments within each time point using emmeans at the mean baseline value? My main objective is not related to initial height effect on the performance seedlings growth over time.Thanks

\n", "question_id": 676937, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "Hi could anyone please help me with this I would be really grateful. I am performing an mixed model ANCOVA to evaluate changes in a response variable (Height) over time and differences among treatments. The baseline measurement is included as a continuous covariate to account for initial differences among individuals. Because the same individuals were measured repeatedly over time, the repeated-measures structure is also accounted for in the model.The experiment is a block split plot experimental design of forestry experiment.\n\n\n\n\nMy model includes treatment, time, and the baseline covariate, including their interactions. I mean-centered the baseline covariate so that a value of zero represents the average baseline value.\n\n\n\n\nModel <- lme( Height_BC ~ Treatments * Years * H_2007_BC_c,\n random = ~1|Blocks/BlocksTreatments/Tree_no,\n na.action = na.omit,\n correlation = corCAR1(form=~as.numeric(Years)|Blocks/BlocksTreatments/Tree_no),\n control = lmeControl(msMaxIter=1000),\n weights = varIdent(form=~1|YearsTreatments),data = mydata)\n\n\n\n\n\nFor post-hoc comparisons, I am using the emmeans package to compare treatments within each time point while setting the centered baseline covariate to zero (my model is box cox transformed). Therefore, these comparisons represent treatment differences for individuals with an average baseline value.\n\n\n\n\nIs this an appropriate way to perform and interpret the ANCOVA? In particular, if the treatment × time × baseline covariate interaction is significant, is it still appropriate to compare treatments within each time point using emmeans at the mean baseline value? My main objective is not related to initial height effect on the performance seedlings growth over time.Thanks", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Birma29", "profile_url": "https://stats.stackexchange.com/users/515697/birma29", "user_type": "registered"}, "created_at": "2026-08-22T22:19:04+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "2B53CAE3-9898-4BAD-A47C-F21FC6D2CDFE", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2B53CAE3-9898-4BAD-A47C-F21FC6D2CDFE/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Birma29", "profile_url": "https://stats.stackexchange.com/users/515697/birma29", "user_type": "registered"}, "created_at": "2026-08-23T02:20:37+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "40D430F5-C4EA-404C-9500-73565E0A45AD", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/40D430F5-C4EA-404C-9500-73565E0A45AD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Birma29", "profile_url": "https://stats.stackexchange.com/users/515697/birma29", "user_type": "registered"}, "created_at": "2026-08-23T02:26:05+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "9C8ADAEC-43F3-4E44-8D85-BE8C1ABA317C", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9C8ADAEC-43F3-4E44-8D85-BE8C1ABA317C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Birma29", "profile_url": "https://stats.stackexchange.com/users/515697/birma29", "user_type": "registered"}, "created_at": "2026-08-23T02:31:15+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "F764FBDD-D5CE-4BB8-A654-2117D3C158FC", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F764FBDD-D5CE-4BB8-A654-2117D3C158FC/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Birma29", "profile_url": "https://stats.stackexchange.com/users/515697/birma29", "user_type": "registered"}, "created_at": "2026-08-23T14:48:42+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "A8739EA4-04E9-4855-B47E-7D431C971826", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A8739EA4-04E9-4855-B47E-7D431C971826/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-23T18:55:33+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "AA29DDF8-382A-4143-9646-FEE4954D97AA", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AA29DDF8-382A-4143-9646-FEE4954D97AA/view-source"}, {"content_license": null, "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-08-23T19:00:42+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "15EA9028-E0DB-4270-92D2-951EAA324FC1", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/15EA9028-E0DB-4270-92D2-951EAA324FC1/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-24T15:03:00+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DBC6C8CE-6537-48D0-B89E-53BB5FA32C91", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/DBC6C8CE-6537-48D0-B89E-53BB5FA32C91/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676937/treatment-comparisons-in-repeated-measures-mixed-model-ancova-with-a-baseline-co", "split": "train", "split_group": "39b688f3328bca92a43e0fb3eaf3d5aa37df78aa89e0d509aecbd58742da06f6", "tags": ["mixed-model", "lme4-nlme", "covariance", "ancova", "lsmeans"], "thread_id": "stats:676937", "title": "Treatment Comparisons in Repeated-Measures mixed model ANCOVA with a Baseline Covariate"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I am fitting a Gamma GAM for daily outdoor time in chickens. I have 8,395 hen-day observations, 124 hens, and 132 dates. Weather varies only by date.\n\n\n\n\nMy current temporal structure is:\n\n\n\n\ntotal_time_outside ~\n coop_id +\n s(study_day, bs = \"cr\", k = 40) +\n s(max_temp, bs = \"cr\", k = 8) +\n s(mean_dew_point, bs = \"cr\", k = 7) +\n rain_any +\n s(log_total_rain, by = rain_status, bs = \"cr\", k = 7) +\n s(date_factor, bs = \"re\") +\n s(eid, bs = \"re\")\n\n\n\n\n\nI also have an assumed laying phase, but it is not observed individually. It is defined only from calendar date, e.g.:\n\n\n\n\ndate < \"2025-06-01\" -> pre-laying\ndate >= \"2025-06-01\" -> laying period\n\n\n\n\n\nI tested three assumed onset dates: June 1, June 15, and July 1. All gave strong “laying phase” effects, with post/pre expected-time ratios of about 0.47, 0.50, and 0.56 respectively.\n\n\n\n\nHowever, adding this variable substantially changed the estimated temperature smooth, while the coop/group effect remained stable. Different onset dates also had almost identical AIC.\n\n\n\n\nMy concern is that laying_phase is just acting as an arbitrary early-vs-late time step and is confounded with study_day and seasonal temperature.\n\n\n\n\nstudy_day and date_factor are intended to represent different temporal components. s(study_day) models the smooth long-term temporal/seasonal trajectory, whereas s(date_factor, bs=\"re\") allows individual dates to deviate from that trajectory because all hens measured on a given date share weather and other day-level conditions. Adding the date random effect reduced the study-day EDF from about 33.4 to 27.8, but did not remove the smooth temporal pattern.\n\n\n\n\nWhen I add laying_phase, the study_day smooth still remains quite complex (EDF about 25–28), so the phase term does not simply replace a clear June/July jump. The main instability is instead in the temperature smooth: adding the date random effect alone leaves the max-temperature smooth fairly similar to the model without it (correlation of fitted smooth contributions ≈0.93), whereas adding the assumed laying-phase term produces a substantially different temperature smooth. Dew point and rainfall are much more stable. This is what made me concerned that the date-defined phase is competing with seasonal temperature/time rather than identifying a distinct biological effect.\n\n\n\n\nA separate derivative analysis of s(study_day) showed rapid changes around late May/early June, but not a uniquely identifiable jump at the assumed laying date. This is why I am concerned that the date-defined laying phase is competing with seasonal time/temperature structure rather than representing a separately identifiable biological effect. Biologically, I expected outdoor activity to decrease after laying begins.\n[image: enter image description here; source: https://i.sstatic.net/65O8XMLB.png] (https://i.sstatic.net/65O8XMLB.png)\n\n\n\n\nIn contrast, the temperature smooth changed much more: EDF changed from 4.36 to 2.54, and the fitted s(max_temp) contributions had correlation only 0.217.\n\n\n\n\nThis makes me think the assumed date-defined laying-phase variable is competing mainly with seasonal weather / time structure rather than identifying a distinct biological effect.\n[image: enter image description here; source: https://i.sstatic.net/OlWsvas1.png] (https://i.sstatic.net/OlWsvas1.png)\n\n\n\n\nShould I:\n\n\n\n\n\ninclude this date-defined phase alongside s(study_day),\n\n\n\n\ntreat it only as a sensitivity analysis,\n\n\n\n\nor model a possible change point in another way?", "record_id": "Scientific-Statistics-QA:stats:676947", "selected_answer": {"answer_html": "

With these data, I don't see a way to separate the associations of date and temperature with time outside from that of egg-laying phase. That phase, defined by date with whichever cutoff you use, is inextricably linked to date and to the change of temperature with date. Similarly, in a model that omits egg-laying phase, you can't rule out that some of the apparent associations of date and temperature with time outside are proxies for egg-laying season.

\n

As is often the case with observational studies, you thus can't interpret the egg-laying phase "as a separate biological effect." How best to present your results depends in part on what's expected in your field. What would make sense to me, as an outsider, would be to omit egg-laying phase from the main model and note in discussion how the large changes in outcomes with date occur around the egg-laying phase. The differences in smooths for date and temperature with and without egg-laying phase in the model might be of interest to your audience.

\n", "answer_id": 677120, "answer_text": "With these data, I don't see a way to separate the associations of date and temperature with time outside from that of egg-laying phase. That phase, defined by date with whichever cutoff you use, is inextricably linked to date and to the change of temperature with date. Similarly, in a model that omits egg-laying phase, you can't rule out that some of the apparent associations of date and temperature with time outside are proxies for egg-laying season.\n\n\n\n\nAs is often the case with observational studies, you thus can't interpret the egg-laying phase \"as a separate biological effect.\" How best to present your results depends in part on what's expected in your field. What would make sense to me, as an outsider, would be to omit egg-laying phase from the main model and note in discussion how the large changes in outcomes with date occur around the egg-laying phase. The differences in smooths for date and temperature with and without egg-laying phase in the model might be of interest to your audience.", "answer_url": "https://stats.stackexchange.com/a/677120", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T18:18:36+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": 676947, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-09T18:18:36+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "B20DB8A3-050C-4C8A-8A9B-74F236DACE23", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B20DB8A3-050C-4C8A-8A9B-74F236DACE23/view-source"}], "score": 2, "updated_at": "2026-09-09T18:18:36+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

With these data, I don't see a way to separate the associations of date and temperature with time outside from that of egg-laying phase. That phase, defined by date with whichever cutoff you use, is inextricably linked to date and to the change of temperature with date. Similarly, in a model that omits egg-laying phase, you can't rule out that some of the apparent associations of date and temperature with time outside are proxies for egg-laying season.

\n

As is often the case with observational studies, you thus can't interpret the egg-laying phase "as a separate biological effect." How best to present your results depends in part on what's expected in your field. What would make sense to me, as an outsider, would be to omit egg-laying phase from the main model and note in discussion how the large changes in outcomes with date occur around the egg-laying phase. The differences in smooths for date and temperature with and without egg-laying phase in the model might be of interest to your audience.

\n", "answer_id": 677120, "answer_text": "With these data, I don't see a way to separate the associations of date and temperature with time outside from that of egg-laying phase. That phase, defined by date with whichever cutoff you use, is inextricably linked to date and to the change of temperature with date. Similarly, in a model that omits egg-laying phase, you can't rule out that some of the apparent associations of date and temperature with time outside are proxies for egg-laying season.\n\n\n\n\nAs is often the case with observational studies, you thus can't interpret the egg-laying phase \"as a separate biological effect.\" How best to present your results depends in part on what's expected in your field. What would make sense to me, as an outsider, would be to omit egg-laying phase from the main model and note in discussion how the large changes in outcomes with date occur around the egg-laying phase. The differences in smooths for date and temperature with and without egg-laying phase in the model might be of interest to your audience.", "answer_url": "https://stats.stackexchange.com/a/677120", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T18:18:36+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": 676947, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-09T18:18:36+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "B20DB8A3-050C-4C8A-8A9B-74F236DACE23", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B20DB8A3-050C-4C8A-8A9B-74F236DACE23/view-source"}], "score": 2, "updated_at": "2026-09-09T18:18:36+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/65O8XMLB.png", "https://i.sstatic.net/OlWsvas1.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": "Lex", "question_author_url": "https://stats.stackexchange.com/users/411674/lex", "question_author_user_type": "registered", "question_created_at": "2026-08-23T22:45:44+00:00", "question_html": "

I am fitting a Gamma GAM for daily outdoor time in chickens. I have 8,395 hen-day observations, 124 hens, and 132 dates. Weather varies only by date.

\n

My current temporal structure is:

\n
total_time_outside ~\n  coop_id +\n  s(study_day, bs = "cr", k = 40) +\n  s(max_temp, bs = "cr", k = 8) +\n  s(mean_dew_point, bs = "cr", k = 7) +\n  rain_any +\n  s(log_total_rain, by = rain_status, bs = "cr", k = 7) +\n  s(date_factor, bs = "re") +\n  s(eid, bs = "re")\n
\n

I also have an assumed laying phase, but it is not observed individually. It is defined only from calendar date, e.g.:

\n
date < "2025-06-01"  -> pre-laying\ndate >= "2025-06-01" -> laying period\n
\n

I tested three assumed onset dates: June 1, June 15, and July 1. All gave strong “laying phase” effects, with post/pre expected-time ratios of about 0.47, 0.50, and 0.56 respectively.

\n

However, adding this variable substantially changed the estimated temperature smooth, while the coop/group effect remained stable. Different onset dates also had almost identical AIC.

\n

My concern is that laying_phase is just acting as an arbitrary early-vs-late time step and is confounded with study_day and seasonal temperature.

\n

study_day and date_factor are intended to represent different temporal components. s(study_day) models the smooth long-term temporal/seasonal trajectory, whereas s(date_factor, bs="re") allows individual dates to deviate from that trajectory because all hens measured on a given date share weather and other day-level conditions. Adding the date random effect reduced the study-day EDF from about 33.4 to 27.8, but did not remove the smooth temporal pattern.

\n

When I add laying_phase, the study_day smooth still remains quite complex (EDF about 25–28), so the phase term does not simply replace a clear June/July jump. The main instability is instead in the temperature smooth: adding the date random effect alone leaves the max-temperature smooth fairly similar to the model without it (correlation of fitted smooth contributions ≈0.93), whereas adding the assumed laying-phase term produces a substantially different temperature smooth. Dew point and rainfall are much more stable. This is what made me concerned that the date-defined phase is competing with seasonal temperature/time rather than identifying a distinct biological effect.

\n

A separate derivative analysis of s(study_day) showed rapid changes around late May/early June, but not a uniquely identifiable jump at the assumed laying date. This is why I am concerned that the date-defined laying phase is competing with seasonal time/temperature structure rather than representing a separately identifiable biological effect. Biologically, I expected outdoor activity to decrease after laying begins.\n\"enter

\n

In contrast, the temperature smooth changed much more: EDF changed from 4.36 to 2.54, and the fitted s(max_temp) contributions had correlation only 0.217.

\n

This makes me think the assumed date-defined laying-phase variable is competing mainly with seasonal weather / time structure rather than identifying a distinct biological effect.\n\"enter

\n

Should I:

\n\n", "question_id": 676947, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I am fitting a Gamma GAM for daily outdoor time in chickens. I have 8,395 hen-day observations, 124 hens, and 132 dates. Weather varies only by date.\n\n\n\n\nMy current temporal structure is:\n\n\n\n\ntotal_time_outside ~\n coop_id +\n s(study_day, bs = \"cr\", k = 40) +\n s(max_temp, bs = \"cr\", k = 8) +\n s(mean_dew_point, bs = \"cr\", k = 7) +\n rain_any +\n s(log_total_rain, by = rain_status, bs = \"cr\", k = 7) +\n s(date_factor, bs = \"re\") +\n s(eid, bs = \"re\")\n\n\n\n\n\nI also have an assumed laying phase, but it is not observed individually. It is defined only from calendar date, e.g.:\n\n\n\n\ndate < \"2025-06-01\" -> pre-laying\ndate >= \"2025-06-01\" -> laying period\n\n\n\n\n\nI tested three assumed onset dates: June 1, June 15, and July 1. All gave strong “laying phase” effects, with post/pre expected-time ratios of about 0.47, 0.50, and 0.56 respectively.\n\n\n\n\nHowever, adding this variable substantially changed the estimated temperature smooth, while the coop/group effect remained stable. Different onset dates also had almost identical AIC.\n\n\n\n\nMy concern is that laying_phase is just acting as an arbitrary early-vs-late time step and is confounded with study_day and seasonal temperature.\n\n\n\n\nstudy_day and date_factor are intended to represent different temporal components. s(study_day) models the smooth long-term temporal/seasonal trajectory, whereas s(date_factor, bs=\"re\") allows individual dates to deviate from that trajectory because all hens measured on a given date share weather and other day-level conditions. Adding the date random effect reduced the study-day EDF from about 33.4 to 27.8, but did not remove the smooth temporal pattern.\n\n\n\n\nWhen I add laying_phase, the study_day smooth still remains quite complex (EDF about 25–28), so the phase term does not simply replace a clear June/July jump. The main instability is instead in the temperature smooth: adding the date random effect alone leaves the max-temperature smooth fairly similar to the model without it (correlation of fitted smooth contributions ≈0.93), whereas adding the assumed laying-phase term produces a substantially different temperature smooth. Dew point and rainfall are much more stable. This is what made me concerned that the date-defined phase is competing with seasonal temperature/time rather than identifying a distinct biological effect.\n\n\n\n\nA separate derivative analysis of s(study_day) showed rapid changes around late May/early June, but not a uniquely identifiable jump at the assumed laying date. This is why I am concerned that the date-defined laying phase is competing with seasonal time/temperature structure rather than representing a separately identifiable biological effect. Biologically, I expected outdoor activity to decrease after laying begins.\n[image: enter image description here; source: https://i.sstatic.net/65O8XMLB.png] (https://i.sstatic.net/65O8XMLB.png)\n\n\n\n\nIn contrast, the temperature smooth changed much more: EDF changed from 4.36 to 2.54, and the fitted s(max_temp) contributions had correlation only 0.217.\n\n\n\n\nThis makes me think the assumed date-defined laying-phase variable is competing mainly with seasonal weather / time structure rather than identifying a distinct biological effect.\n[image: enter image description here; source: https://i.sstatic.net/OlWsvas1.png] (https://i.sstatic.net/OlWsvas1.png)\n\n\n\n\nShould I:\n\n\n\n\n\ninclude this date-defined phase alongside s(study_day),\n\n\n\n\ntreat it only as a sensitivity analysis,\n\n\n\n\nor model a possible change point in another way?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lex", "profile_url": "https://stats.stackexchange.com/users/411674/lex", "user_type": "registered"}, "created_at": "2026-08-23T22:45:44+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "207E04AA-5CA3-4024-8526-5C7DFA5BB960", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/207E04AA-5CA3-4024-8526-5C7DFA5BB960/view-source"}, {"content_license": null, "contributor": {"display_name": "kjetil b halvorsen", "profile_url": "https://stats.stackexchange.com/users/11887/kjetil-b-halvorsen", "user_type": "moderator"}, "created_at": "2026-08-24T00:09:13+00:00", "raw_file": "raw/codex_api_v1/01ff643b5e725b2402c38de261074c3bef3326820f24db4342e17e318353268e_1790825246205492400_0.json", "raw_sha256": "a0521ae83c8630be00a12499e9aaa253069e57a5e0ff902fea3e9b8e7acb810f", "revision_guid": "67C7E75E-9B13-45C5-8696-16319354EC56", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67C7E75E-9B13-45C5-8696-16319354EC56/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lex", "profile_url": "https://stats.stackexchange.com/users/411674/lex", "user_type": "registered"}, "created_at": "2026-08-24T19:08:58+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "6607F550-30C8-4DD2-B4BE-29CDCD8A2411", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6607F550-30C8-4DD2-B4BE-29CDCD8A2411/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lex", "profile_url": "https://stats.stackexchange.com/users/411674/lex", "user_type": "registered"}, "created_at": "2026-08-24T20:41:39+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "EA5A4B0A-8D56-4FFB-B50D-C4FC49370A72", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EA5A4B0A-8D56-4FFB-B50D-C4FC49370A72/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lex", "profile_url": "https://stats.stackexchange.com/users/411674/lex", "user_type": "registered"}, "created_at": "2026-08-25T23:15:25+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "65F369FE-F0DE-4359-B512-0CCF56F9CD3F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/65F369FE-F0DE-4359-B512-0CCF56F9CD3F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lex", "profile_url": "https://stats.stackexchange.com/users/411674/lex", "user_type": "registered"}, "created_at": "2026-08-25T23:31:52+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "ABB88B83-E931-4E76-B7B6-1E36C6640AC6", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/ABB88B83-E931-4E76-B7B6-1E36C6640AC6/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676947/how-should-i-handle-a-date-defined-egg-laying-phase-in-a-gam", "split": "train", "split_group": "93d899740a04ca481f468f67beb7df07178038690cce7f5962b92ff406ecdf03", "tags": ["mixed-model", "biostatistics", "generalized-additive-model"], "thread_id": "stats:676947", "title": "How should I handle a date-defined egg laying phase in a GAM?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "For homework assignment regarding stepwise regression (along with forward and backwards) the professor said to scale all the data except for the response and categorical variables.\n\n\n\n\nI suppose I somewhat can understand the categorical variables they can only be binary values. However I don't understand why the response variable was excluded.\n\n\n\n\nWhen scaling data for other models we usually scale the entire dataset so I'm confused why in this instance it's not included.", "record_id": "Scientific-Statistics-QA:stats:676958", "selected_answer": {"answer_html": "

In stepwise regression, scaling the response variable changes coefficient magnitudes but has no other meaningful effect. Here is an example in R:

\n
data(mtcars)\n\n# Fit the same model with and without scaling the response\nm1 <- lm(mpg        ~ scale(wt) + scale(hp) + scale(disp), data = mtcars)\nm2 <- lm(scale(mpg) ~ scale(wt) + scale(hp) + scale(disp), data = mtcars)\n\nround(coef(m1), 4)\n#> (Intercept)   scale(wt)   scale(hp) scale(disp) \n#>     20.0906     -3.7190     -2.1362     -0.1161\n\nround(coef(m2), 4)\n#> (Intercept)   scale(wt)   scale(hp) scale(disp) \n#>      0.0000     -0.6171     -0.3544     -0.0193\n
\n

Coefficients in m2 are simply m1 coefficients divided by sd(mpg):

\n
sd(mtcars$mpg)\n#> [1] 6.026948\n\nround(coef(m1)[-1] / coef(m2)[-1], 2)\n#>   scale(wt)   scale(hp) scale(disp) \n#>        6.03        6.03        6.03\n
\n

They carry no additional information. P-values are identical, so stepwise selection makes the same decision either way:

\n
summary(m1)$coefficients[-1, "Pr(>|t|)"]\n#>   scale(wt)   scale(hp) scale(disp) \n#> 0.001330991 0.010971032 0.928507029\n\nsummary(m2)$coefficients[-1, "Pr(>|t|)"]\n#>   scale(wt)   scale(hp) scale(disp) \n#> 0.001330991 0.010971032 0.928507029\n
\n

Moreover, the response is what we actually care about understanding. Scaling it means predictions are in standard deviations of mpg rather than miles per gallon, which is harder to interpret and communicate:

\n
predict(m1, newdata = data.frame(wt = 3, hp = 100, disp = 200))\n#>        1 \n#> 22.39978\n\npred_scaled <- predict(m2, newdata = data.frame(wt = 3, hp = 100, disp = 200))\npred_scaled\n#>         1 \n#> 0.3831378\npred_scaled * sd(mtcars$mpg) + mean(mtcars$mpg)\n#>         1 \n#> 22.39978\n
\n

Scaling predictors matters because it puts variables with different units on the same footing, making coefficient magnitudes comparable across predictors. The response does not need this. We are not comparing it to anything, we are trying to explain it.

\n

For categorical variables, scaling a 0/1 indicator loses interpretability. The coefficient of an unscaled binary variable represents the difference between groups in the original units of the response:

\n
m3 <- lm(mpg ~ scale(wt) + scale(hp) + factor(cyl), data = mtcars)\nm4 <- lm(mpg ~ scale(wt) + scale(hp) + scale(cyl),  data = mtcars)\n\ncoef(m3)\n#>  (Intercept)    scale(wt)    scale(hp) factor(cyl)6 factor(cyl)8 \n#>    22.219236    -3.112868    -1.585160    -3.359025    -3.185884\ncoef(m4)\n#> (Intercept)   scale(wt)   scale(hp)  scale(cyl) \n#>   20.090625   -3.098748   -1.236744   -1.681654\n
\n

factor(cyl) gives separate interpretable coefficients for each cylinder group relative to the 4-cylinder baseline directly answering how much mpg changes going from 4 to 6 or 8 cylinders. scale(cyl) collapses this into a single slope assuming equal spacing between cylinder counts, and the coefficient is now per standard deviation of cyl rather than per cylinder group.

\n

Created on 2026-08-25 with reprex v2.1.1

\n", "answer_id": 676959, "answer_text": "In stepwise regression, scaling the response variable changes coefficient magnitudes but has no other meaningful effect. Here is an example in R:\n\n\n\n\ndata(mtcars)\n\n# Fit the same model with and without scaling the response\nm1 <- lm(mpg ~ scale(wt) + scale(hp) + scale(disp), data = mtcars)\nm2 <- lm(scale(mpg) ~ scale(wt) + scale(hp) + scale(disp), data = mtcars)\n\nround(coef(m1), 4)\n#> (Intercept) scale(wt) scale(hp) scale(disp) \n#> 20.0906 -3.7190 -2.1362 -0.1161\n\nround(coef(m2), 4)\n#> (Intercept) scale(wt) scale(hp) scale(disp) \n#> 0.0000 -0.6171 -0.3544 -0.0193\n\n\n\n\n\nCoefficients in m2 are simply m1 coefficients divided by sd(mpg):\n\n\n\n\nsd(mtcars$mpg)\n#> [1] 6.026948\n\nround(coef(m1)[-1] / coef(m2)[-1], 2)\n#> scale(wt) scale(hp) scale(disp) \n#> 6.03 6.03 6.03\n\n\n\n\n\nThey carry no additional information. P-values are identical, so stepwise selection makes the same decision either way:\n\n\n\n\nsummary(m1)$coefficients[-1, \"Pr(>|t|)\"]\n#> scale(wt) scale(hp) scale(disp) \n#> 0.001330991 0.010971032 0.928507029\n\nsummary(m2)$coefficients[-1, \"Pr(>|t|)\"]\n#> scale(wt) scale(hp) scale(disp) \n#> 0.001330991 0.010971032 0.928507029\n\n\n\n\n\nMoreover, the response is what we actually care about understanding. Scaling it means predictions are in standard deviations of mpg rather than miles per gallon, which is harder to interpret and communicate:\n\n\n\n\npredict(m1, newdata = data.frame(wt = 3, hp = 100, disp = 200))\n#> 1 \n#> 22.39978\n\npred_scaled <- predict(m2, newdata = data.frame(wt = 3, hp = 100, disp = 200))\npred_scaled\n#> 1 \n#> 0.3831378\npred_scaled * sd(mtcars$mpg) + mean(mtcars$mpg)\n#> 1 \n#> 22.39978\n\n\n\n\n\nScaling predictors matters because it puts variables with different units on the same footing, making coefficient magnitudes comparable across predictors. The response does not need this. We are not comparing it to anything, we are trying to explain it.\n\n\n\n\nFor categorical variables, scaling a 0/1 indicator loses interpretability. The coefficient of an unscaled binary variable represents the difference between groups in the original units of the response:\n\n\n\n\nm3 <- lm(mpg ~ scale(wt) + scale(hp) + factor(cyl), data = mtcars)\nm4 <- lm(mpg ~ scale(wt) + scale(hp) + scale(cyl), data = mtcars)\n\ncoef(m3)\n#> (Intercept) scale(wt) scale(hp) factor(cyl)6 factor(cyl)8 \n#> 22.219236 -3.112868 -1.585160 -3.359025 -3.185884\ncoef(m4)\n#> (Intercept) scale(wt) scale(hp) scale(cyl) \n#> 20.090625 -3.098748 -1.236744 -1.681654\n\n\n\n\n\nfactor(cyl) gives separate interpretable coefficients for each cylinder group relative to the 4-cylinder baseline directly answering how much mpg changes going from 4 to 6 or 8 cylinders. scale(cyl) collapses this into a single slope assuming equal spacing between cylinder counts, and the coefficient is now per standard deviation of cyl rather than per cylinder group.\n\n\n\n\nCreated on 2026-08-25 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676959", "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-25T19:05:50+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": 676958, "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-25T19:05:50+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "572E3B4E-1F43-4F40-91AA-292255EC61E9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/572E3B4E-1F43-4F40-91AA-292255EC61E9/view-source"}], "score": 11, "updated_at": "2026-08-25T19:05:50+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

In stepwise regression, scaling the response variable changes coefficient magnitudes but has no other meaningful effect. Here is an example in R:

\n
data(mtcars)\n\n# Fit the same model with and without scaling the response\nm1 <- lm(mpg        ~ scale(wt) + scale(hp) + scale(disp), data = mtcars)\nm2 <- lm(scale(mpg) ~ scale(wt) + scale(hp) + scale(disp), data = mtcars)\n\nround(coef(m1), 4)\n#> (Intercept)   scale(wt)   scale(hp) scale(disp) \n#>     20.0906     -3.7190     -2.1362     -0.1161\n\nround(coef(m2), 4)\n#> (Intercept)   scale(wt)   scale(hp) scale(disp) \n#>      0.0000     -0.6171     -0.3544     -0.0193\n
\n

Coefficients in m2 are simply m1 coefficients divided by sd(mpg):

\n
sd(mtcars$mpg)\n#> [1] 6.026948\n\nround(coef(m1)[-1] / coef(m2)[-1], 2)\n#>   scale(wt)   scale(hp) scale(disp) \n#>        6.03        6.03        6.03\n
\n

They carry no additional information. P-values are identical, so stepwise selection makes the same decision either way:

\n
summary(m1)$coefficients[-1, "Pr(>|t|)"]\n#>   scale(wt)   scale(hp) scale(disp) \n#> 0.001330991 0.010971032 0.928507029\n\nsummary(m2)$coefficients[-1, "Pr(>|t|)"]\n#>   scale(wt)   scale(hp) scale(disp) \n#> 0.001330991 0.010971032 0.928507029\n
\n

Moreover, the response is what we actually care about understanding. Scaling it means predictions are in standard deviations of mpg rather than miles per gallon, which is harder to interpret and communicate:

\n
predict(m1, newdata = data.frame(wt = 3, hp = 100, disp = 200))\n#>        1 \n#> 22.39978\n\npred_scaled <- predict(m2, newdata = data.frame(wt = 3, hp = 100, disp = 200))\npred_scaled\n#>         1 \n#> 0.3831378\npred_scaled * sd(mtcars$mpg) + mean(mtcars$mpg)\n#>         1 \n#> 22.39978\n
\n

Scaling predictors matters because it puts variables with different units on the same footing, making coefficient magnitudes comparable across predictors. The response does not need this. We are not comparing it to anything, we are trying to explain it.

\n

For categorical variables, scaling a 0/1 indicator loses interpretability. The coefficient of an unscaled binary variable represents the difference between groups in the original units of the response:

\n
m3 <- lm(mpg ~ scale(wt) + scale(hp) + factor(cyl), data = mtcars)\nm4 <- lm(mpg ~ scale(wt) + scale(hp) + scale(cyl),  data = mtcars)\n\ncoef(m3)\n#>  (Intercept)    scale(wt)    scale(hp) factor(cyl)6 factor(cyl)8 \n#>    22.219236    -3.112868    -1.585160    -3.359025    -3.185884\ncoef(m4)\n#> (Intercept)   scale(wt)   scale(hp)  scale(cyl) \n#>   20.090625   -3.098748   -1.236744   -1.681654\n
\n

factor(cyl) gives separate interpretable coefficients for each cylinder group relative to the 4-cylinder baseline directly answering how much mpg changes going from 4 to 6 or 8 cylinders. scale(cyl) collapses this into a single slope assuming equal spacing between cylinder counts, and the coefficient is now per standard deviation of cyl rather than per cylinder group.

\n

Created on 2026-08-25 with reprex v2.1.1

\n", "answer_id": 676959, "answer_text": "In stepwise regression, scaling the response variable changes coefficient magnitudes but has no other meaningful effect. Here is an example in R:\n\n\n\n\ndata(mtcars)\n\n# Fit the same model with and without scaling the response\nm1 <- lm(mpg ~ scale(wt) + scale(hp) + scale(disp), data = mtcars)\nm2 <- lm(scale(mpg) ~ scale(wt) + scale(hp) + scale(disp), data = mtcars)\n\nround(coef(m1), 4)\n#> (Intercept) scale(wt) scale(hp) scale(disp) \n#> 20.0906 -3.7190 -2.1362 -0.1161\n\nround(coef(m2), 4)\n#> (Intercept) scale(wt) scale(hp) scale(disp) \n#> 0.0000 -0.6171 -0.3544 -0.0193\n\n\n\n\n\nCoefficients in m2 are simply m1 coefficients divided by sd(mpg):\n\n\n\n\nsd(mtcars$mpg)\n#> [1] 6.026948\n\nround(coef(m1)[-1] / coef(m2)[-1], 2)\n#> scale(wt) scale(hp) scale(disp) \n#> 6.03 6.03 6.03\n\n\n\n\n\nThey carry no additional information. P-values are identical, so stepwise selection makes the same decision either way:\n\n\n\n\nsummary(m1)$coefficients[-1, \"Pr(>|t|)\"]\n#> scale(wt) scale(hp) scale(disp) \n#> 0.001330991 0.010971032 0.928507029\n\nsummary(m2)$coefficients[-1, \"Pr(>|t|)\"]\n#> scale(wt) scale(hp) scale(disp) \n#> 0.001330991 0.010971032 0.928507029\n\n\n\n\n\nMoreover, the response is what we actually care about understanding. Scaling it means predictions are in standard deviations of mpg rather than miles per gallon, which is harder to interpret and communicate:\n\n\n\n\npredict(m1, newdata = data.frame(wt = 3, hp = 100, disp = 200))\n#> 1 \n#> 22.39978\n\npred_scaled <- predict(m2, newdata = data.frame(wt = 3, hp = 100, disp = 200))\npred_scaled\n#> 1 \n#> 0.3831378\npred_scaled * sd(mtcars$mpg) + mean(mtcars$mpg)\n#> 1 \n#> 22.39978\n\n\n\n\n\nScaling predictors matters because it puts variables with different units on the same footing, making coefficient magnitudes comparable across predictors. The response does not need this. We are not comparing it to anything, we are trying to explain it.\n\n\n\n\nFor categorical variables, scaling a 0/1 indicator loses interpretability. The coefficient of an unscaled binary variable represents the difference between groups in the original units of the response:\n\n\n\n\nm3 <- lm(mpg ~ scale(wt) + scale(hp) + factor(cyl), data = mtcars)\nm4 <- lm(mpg ~ scale(wt) + scale(hp) + scale(cyl), data = mtcars)\n\ncoef(m3)\n#> (Intercept) scale(wt) scale(hp) factor(cyl)6 factor(cyl)8 \n#> 22.219236 -3.112868 -1.585160 -3.359025 -3.185884\ncoef(m4)\n#> (Intercept) scale(wt) scale(hp) scale(cyl) \n#> 20.090625 -3.098748 -1.236744 -1.681654\n\n\n\n\n\nfactor(cyl) gives separate interpretable coefficients for each cylinder group relative to the 4-cylinder baseline directly answering how much mpg changes going from 4 to 6 or 8 cylinders. scale(cyl) collapses this into a single slope assuming equal spacing between cylinder counts, and the coefficient is now per standard deviation of cyl rather than per cylinder group.\n\n\n\n\nCreated on 2026-08-25 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/676959", "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-25T19:05:50+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": 676958, "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-25T19:05:50+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "572E3B4E-1F43-4F40-91AA-292255EC61E9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/572E3B4E-1F43-4F40-91AA-292255EC61E9/view-source"}], "score": 11, "updated_at": "2026-08-25T19:05:50+00:00"}], "domain": "statistics", "external_links": ["https://reprex.tidyverse.org"], "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": "Karl Suh", "question_author_url": "https://stats.stackexchange.com/users/513622/karl-suh", "question_author_user_type": "registered", "question_created_at": "2026-08-25T17:43:52+00:00", "question_html": "

For homework assignment regarding stepwise regression (along with forward and backwards) the professor said to scale all the data except for the response and categorical variables.

\n

I suppose I somewhat can understand the categorical variables they can only be binary values. However I don't understand why the response variable was excluded.

\n

When scaling data for other models we usually scale the entire dataset so I'm confused why in this instance it's not included.

\n", "question_id": 676958, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "For homework assignment regarding stepwise regression (along with forward and backwards) the professor said to scale all the data except for the response and categorical variables.\n\n\n\n\nI suppose I somewhat can understand the categorical variables they can only be binary values. However I don't understand why the response variable was excluded.\n\n\n\n\nWhen scaling data for other models we usually scale the entire dataset so I'm confused why in this instance it's not included.", "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-25T17:43:52+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "4082C60D-8D85-46BC-9D47-179A8B66E184", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4082C60D-8D85-46BC-9D47-179A8B66E184/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-26T01:49:11+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "1BA401BC-F034-41AE-8F89-81E5097845A1", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/1BA401BC-F034-41AE-8F89-81E5097845A1/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676958/for-stepwise-regression-when-scaling-the-data-why-not-scale-the-response-and-ca", "split": "train", "split_group": "4fe50e1b22b7e2f9bed9d1b79bf1ec7f398cf2d4491c96672ea2ca7f02f416ed", "tags": ["standardization", "stepwise-regression"], "thread_id": "stats:676958", "title": "For stepwise regression, when scaling the data why not scale the response and categorical variables?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I would like to ask a methodological question regarding Joinpoint regression.\n\n\n\n\nIn my study, I have annual data covering six years (2018–2023). I would like to know whether six annual data points are considered sufficient and methodologically appropriate to identify a joinpoint or significant change in trend, or whether a larger number of observations, such as monthly data, would be preferable for a more reliable analysis.", "record_id": "Scientific-Statistics-QA:stats:676961", "selected_answer": {"answer_html": "

There is no golden rule about how many time measurements are ideal, beyond issues of statistical power (which I will get to in a minute). Many analyses have only two time points to see pre-test / post-test changes. Other analyses have time series spanning years. It will depend on what your goal is with the analysis.

\n

As for if the estimates are statistically reliable (namely power), this will depend on how many observations are within each time period. If you literally only have n = 6 observations in your data, that's definitely not enough. If you have n = 1,000 observations per time period, that could be a well-powered design, depending on the analysis you are running. If you are running a simple AR1-like model of time series, then this would probably be sufficient. If you are estimating a full GAMLSS of each moment of the distribution with complex random effects, then that is something entirely different.

\n

As Kjetil mentioned, a segmented regression is a potential approach you could take, but that will depend again on what you need.

\n", "answer_id": 676963, "answer_text": "There is no golden rule about how many time measurements are ideal, beyond issues of statistical power (which I will get to in a minute). Many analyses have only two time points to see pre-test / post-test changes. Other analyses have time series spanning years. It will depend on what your goal is with the analysis.\n\n\n\n\nAs for if the estimates are statistically reliable (namely power), this will depend on how many observations are within each time period. If you literally only have n = 6 observations in your data, that's definitely not enough. If you have n = 1,000 observations per time period, that could be a well-powered design, depending on the analysis you are running. If you are running a simple AR1-like model of time series, then this would probably be sufficient. If you are estimating a full GAMLSS of each moment of the distribution with complex random effects, then that is something entirely different.\n\n\n\n\nAs Kjetil mentioned, a segmented regression is a potential approach you could take, but that will depend again on what you need.", "answer_url": "https://stats.stackexchange.com/a/676963", "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-26T04:16:10+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": 676961, "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-26T04:16:10+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3868F85E-8A28-40C2-9221-01739AD65E23", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3868F85E-8A28-40C2-9221-01739AD65E23/view-source"}], "score": 1, "updated_at": "2026-08-26T04:16:10+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

There is no golden rule about how many time measurements are ideal, beyond issues of statistical power (which I will get to in a minute). Many analyses have only two time points to see pre-test / post-test changes. Other analyses have time series spanning years. It will depend on what your goal is with the analysis.

\n

As for if the estimates are statistically reliable (namely power), this will depend on how many observations are within each time period. If you literally only have n = 6 observations in your data, that's definitely not enough. If you have n = 1,000 observations per time period, that could be a well-powered design, depending on the analysis you are running. If you are running a simple AR1-like model of time series, then this would probably be sufficient. If you are estimating a full GAMLSS of each moment of the distribution with complex random effects, then that is something entirely different.

\n

As Kjetil mentioned, a segmented regression is a potential approach you could take, but that will depend again on what you need.

\n", "answer_id": 676963, "answer_text": "There is no golden rule about how many time measurements are ideal, beyond issues of statistical power (which I will get to in a minute). Many analyses have only two time points to see pre-test / post-test changes. Other analyses have time series spanning years. It will depend on what your goal is with the analysis.\n\n\n\n\nAs for if the estimates are statistically reliable (namely power), this will depend on how many observations are within each time period. If you literally only have n = 6 observations in your data, that's definitely not enough. If you have n = 1,000 observations per time period, that could be a well-powered design, depending on the analysis you are running. If you are running a simple AR1-like model of time series, then this would probably be sufficient. If you are estimating a full GAMLSS of each moment of the distribution with complex random effects, then that is something entirely different.\n\n\n\n\nAs Kjetil mentioned, a segmented regression is a potential approach you could take, but that will depend again on what you need.", "answer_url": "https://stats.stackexchange.com/a/676963", "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-26T04:16:10+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": 676961, "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-26T04:16:10+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3868F85E-8A28-40C2-9221-01739AD65E23", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3868F85E-8A28-40C2-9221-01739AD65E23/view-source"}], "score": 1, "updated_at": "2026-08-26T04:16:10+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Marylin Mora", "question_author_url": "https://stats.stackexchange.com/users/515922/marylin-mora", "question_author_user_type": "registered", "question_created_at": "2026-08-25T21:19:16+00:00", "question_html": "

I would like to ask a methodological question regarding Joinpoint regression.

\n

In my study, I have annual data covering six years (2018–2023). I would like to know whether six annual data points are considered sufficient and methodologically appropriate to identify a joinpoint or significant change in trend, or whether a larger number of observations, such as monthly data, would be preferable for a more reliable analysis.

\n", "question_id": 676961, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "I would like to ask a methodological question regarding Joinpoint regression.\n\n\n\n\nIn my study, I have annual data covering six years (2018–2023). I would like to know whether six annual data points are considered sufficient and methodologically appropriate to identify a joinpoint or significant change in trend, or whether a larger number of observations, such as monthly data, would be preferable for a more reliable analysis.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Marylin Mora", "profile_url": "https://stats.stackexchange.com/users/515922/marylin-mora", "user_type": "registered"}, "created_at": "2026-08-25T21:19:16+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "1BB1E2DC-8DA2-466F-80FB-5F3632210F46", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1BB1E2DC-8DA2-466F-80FB-5F3632210F46/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-26T04:10:21+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "60997525-B315-43E7-9181-9000BC3FE29F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/60997525-B315-43E7-9181-9000BC3FE29F/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-26T06:49:20+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "1FDEE010-B038-4A23-9B7E-38C9A96D2A5B", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/1FDEE010-B038-4A23-9B7E-38C9A96D2A5B/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676961/minimum-number-of-annual-data-points-for-joinpoint-regression", "split": "train", "split_group": "1aebe3b15d0ce2a607f45a4d383fde0ad421dbab76760bedc6cf7507b89810ba", "tags": ["regression", "time-series", "panel-data", "sample-size", "segmented-regression"], "thread_id": "stats:676961", "title": "Minimum number of annual data points for Joinpoint regression"}} +{"accepted_answer": {"answer_html": "

If log-loss is a good choice for fitting and using the classifier has no cost, then a rule with lower log-loss is always better, no matter how small the margin.

\n

The reason that sounds wrong is likely either

\n\n

As an example: suppose you're trying to predict whether a stock price will go up or down. Very small margins can be worthwhile if you have enough money to invest, and that's how quantitative trading works.

\n

But this means any principled method of choosing a non-zero margin will force you to think about utility functions and/or the cost of using the classifier. You don't necessarily have to do this as a formal calculation, or do it yourself, but someone has to either do this or do something essentially equivalent to it.

\n

So, I think you're asking exactly the right question, but it doesn't have a tidy answer.

\n", "answer_id": 676983, "answer_text": "If log-loss is a good choice for fitting and using the classifier has no cost, then a rule with lower log-loss is always better, no matter how small the margin.\n\n\n\n\nThe reason that sounds wrong is likely either\n\n\n\n\n\nyou aren't really convinced that log-loss is the right objective function, or\n\n\n\n\nusing the classifier isn't costless.\n\n\n\n\n\nAs an example: suppose you're trying to predict whether a stock price will go up or down. Very small margins can be worthwhile if you have enough money to invest, and that's how quantitative trading works.\n\n\n\n\nBut this means any principled method of choosing a non-zero margin will force you to think about utility functions and/or the cost of using the classifier. You don't necessarily have to do this as a formal calculation, or do it yourself, but someone has to either do this or do something essentially equivalent to it.\n\n\n\n\nSo, I think you're asking exactly the right question, but it doesn't have a tidy answer.", "answer_url": "https://stats.stackexchange.com/a/676983", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T00:57:18+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": 676981, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-28T00:57:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "1116D3CD-41C5-44E3-BD7C-3C7775E3D286", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1116D3CD-41C5-44E3-BD7C-3C7775E3D286/view-source"}], "score": 6, "updated_at": "2026-08-28T00:57:18+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "I'm working on a probabilistic forecasting project for football matches. The forecasts are 1X2 probabilities (home win, draw, away win), and I want to compare new models prospectively against a fixed Simple Elo baseline.\n\n\n\n\nThe primary evaluation metric is log loss.\n\n\n\n\nBefore testing any new model, I want to define what should count as a scientifically meaningful improvement over the baseline. My concern is that it would be easy to choose this number for the wrong reason — for example, because a certain difference happens to be detectable with the available sample size, or because of results from models that have already been tested.\n\n\n\n\nI'm trying to keep those things separate.\n\n\n\n\nOne idea I'm considering is to define meaningful improvement in terms of an information advantage over the baseline.\n\n\n\n\nFor an observed outcome (y_i), if the new model assigns probability (p_M(y_i)) and Elo assigns (p_E(y_i)), then the average improvement in log loss can be written as\n\n\n\n\n[\n\\frac{1}{n}\\sum_i \\log\\left(\\frac{p_M(y_i)}{p_E(y_i)}\\right).\n]\n\n\n\n\nSo a prospectively chosen log-loss improvement can also be interpreted as an average log-information advantage, or equivalently as a geometric-average ratio of the probabilities assigned to the outcomes that actually occur.\n\n\n\n\nWhat I'm unsure about is the substantive part.\n\n\n\n\nIs there a principled way to decide, before looking at model results or power calculations, how large this information advantage would need to be before it should count as a non-trivial improvement in probabilistic forecast quality?\n\n\n\n\nMore specifically:\n\n\n\n\n\nIs an information-based interpretation like this a reasonable way to anchor a minimum meaningful effect for a proper scoring rule?\n\n\n\n\nIf there is no downstream utility or economic decision function, what kinds of independent justification can legitimately be used to choose the magnitude?\n\n\n\n\nIs there a better way to define a smallest effect of interest for differences in log loss without making the choice arbitrary?\n\n\n\n\n\nI'm deliberately not including previous observed score differences, sample-size calculations, or detectable-effect estimates because I don't want them to influence the definition of what is scientifically meaningful.\n\n\n\n\nI'm interested in the methodology rather than in choosing a particular numerical threshold.", "record_id": "Scientific-Statistics-QA:stats:676981", "selected_answer": {"answer_html": "

If log-loss is a good choice for fitting and using the classifier has no cost, then a rule with lower log-loss is always better, no matter how small the margin.

\n

The reason that sounds wrong is likely either

\n\n

As an example: suppose you're trying to predict whether a stock price will go up or down. Very small margins can be worthwhile if you have enough money to invest, and that's how quantitative trading works.

\n

But this means any principled method of choosing a non-zero margin will force you to think about utility functions and/or the cost of using the classifier. You don't necessarily have to do this as a formal calculation, or do it yourself, but someone has to either do this or do something essentially equivalent to it.

\n

So, I think you're asking exactly the right question, but it doesn't have a tidy answer.

\n", "answer_id": 676983, "answer_text": "If log-loss is a good choice for fitting and using the classifier has no cost, then a rule with lower log-loss is always better, no matter how small the margin.\n\n\n\n\nThe reason that sounds wrong is likely either\n\n\n\n\n\nyou aren't really convinced that log-loss is the right objective function, or\n\n\n\n\nusing the classifier isn't costless.\n\n\n\n\n\nAs an example: suppose you're trying to predict whether a stock price will go up or down. Very small margins can be worthwhile if you have enough money to invest, and that's how quantitative trading works.\n\n\n\n\nBut this means any principled method of choosing a non-zero margin will force you to think about utility functions and/or the cost of using the classifier. You don't necessarily have to do this as a formal calculation, or do it yourself, but someone has to either do this or do something essentially equivalent to it.\n\n\n\n\nSo, I think you're asking exactly the right question, but it doesn't have a tidy answer.", "answer_url": "https://stats.stackexchange.com/a/676983", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T00:57:18+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": 676981, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-28T00:57:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "1116D3CD-41C5-44E3-BD7C-3C7775E3D286", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1116D3CD-41C5-44E3-BD7C-3C7775E3D286/view-source"}], "score": 6, "updated_at": "2026-08-28T00:57:18+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 676983, "answers": [{"answer_html": "

If log-loss is a good choice for fitting and using the classifier has no cost, then a rule with lower log-loss is always better, no matter how small the margin.

\n

The reason that sounds wrong is likely either

\n\n

As an example: suppose you're trying to predict whether a stock price will go up or down. Very small margins can be worthwhile if you have enough money to invest, and that's how quantitative trading works.

\n

But this means any principled method of choosing a non-zero margin will force you to think about utility functions and/or the cost of using the classifier. You don't necessarily have to do this as a formal calculation, or do it yourself, but someone has to either do this or do something essentially equivalent to it.

\n

So, I think you're asking exactly the right question, but it doesn't have a tidy answer.

\n", "answer_id": 676983, "answer_text": "If log-loss is a good choice for fitting and using the classifier has no cost, then a rule with lower log-loss is always better, no matter how small the margin.\n\n\n\n\nThe reason that sounds wrong is likely either\n\n\n\n\n\nyou aren't really convinced that log-loss is the right objective function, or\n\n\n\n\nusing the classifier isn't costless.\n\n\n\n\n\nAs an example: suppose you're trying to predict whether a stock price will go up or down. Very small margins can be worthwhile if you have enough money to invest, and that's how quantitative trading works.\n\n\n\n\nBut this means any principled method of choosing a non-zero margin will force you to think about utility functions and/or the cost of using the classifier. You don't necessarily have to do this as a formal calculation, or do it yourself, but someone has to either do this or do something essentially equivalent to it.\n\n\n\n\nSo, I think you're asking exactly the right question, but it doesn't have a tidy answer.", "answer_url": "https://stats.stackexchange.com/a/676983", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-28T00:57:18+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": 676981, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-08-28T00:57:18+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "1116D3CD-41C5-44E3-BD7C-3C7775E3D286", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1116D3CD-41C5-44E3-BD7C-3C7775E3D286/view-source"}], "score": 6, "updated_at": "2026-08-28T00:57:18+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Mika Agnus", "question_author_url": "https://stats.stackexchange.com/users/516002/mika-agnus", "question_author_user_type": "registered", "question_created_at": "2026-08-27T23:04:13+00:00", "question_html": "

I'm working on a probabilistic forecasting project for football matches. The forecasts are 1X2 probabilities (home win, draw, away win), and I want to compare new models prospectively against a fixed Simple Elo baseline.

\n

The primary evaluation metric is log loss.

\n

Before testing any new model, I want to define what should count as a scientifically meaningful improvement over the baseline. My concern is that it would be easy to choose this number for the wrong reason — for example, because a certain difference happens to be detectable with the available sample size, or because of results from models that have already been tested.

\n

I'm trying to keep those things separate.

\n

One idea I'm considering is to define meaningful improvement in terms of an information advantage over the baseline.

\n

For an observed outcome (y_i), if the new model assigns probability (p_M(y_i)) and Elo assigns (p_E(y_i)), then the average improvement in log loss can be written as

\n

[\n\\frac{1}{n}\\sum_i \\log\\left(\\frac{p_M(y_i)}{p_E(y_i)}\\right).\n]

\n

So a prospectively chosen log-loss improvement can also be interpreted as an average log-information advantage, or equivalently as a geometric-average ratio of the probabilities assigned to the outcomes that actually occur.

\n

What I'm unsure about is the substantive part.

\n

Is there a principled way to decide, before looking at model results or power calculations, how large this information advantage would need to be before it should count as a non-trivial improvement in probabilistic forecast quality?

\n

More specifically:

\n\n

I'm deliberately not including previous observed score differences, sample-size calculations, or detectable-effect estimates because I don't want them to influence the definition of what is scientifically meaningful.

\n

I'm interested in the methodology rather than in choosing a particular numerical threshold.

\n", "question_id": 676981, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I'm working on a probabilistic forecasting project for football matches. The forecasts are 1X2 probabilities (home win, draw, away win), and I want to compare new models prospectively against a fixed Simple Elo baseline.\n\n\n\n\nThe primary evaluation metric is log loss.\n\n\n\n\nBefore testing any new model, I want to define what should count as a scientifically meaningful improvement over the baseline. My concern is that it would be easy to choose this number for the wrong reason — for example, because a certain difference happens to be detectable with the available sample size, or because of results from models that have already been tested.\n\n\n\n\nI'm trying to keep those things separate.\n\n\n\n\nOne idea I'm considering is to define meaningful improvement in terms of an information advantage over the baseline.\n\n\n\n\nFor an observed outcome (y_i), if the new model assigns probability (p_M(y_i)) and Elo assigns (p_E(y_i)), then the average improvement in log loss can be written as\n\n\n\n\n[\n\\frac{1}{n}\\sum_i \\log\\left(\\frac{p_M(y_i)}{p_E(y_i)}\\right).\n]\n\n\n\n\nSo a prospectively chosen log-loss improvement can also be interpreted as an average log-information advantage, or equivalently as a geometric-average ratio of the probabilities assigned to the outcomes that actually occur.\n\n\n\n\nWhat I'm unsure about is the substantive part.\n\n\n\n\nIs there a principled way to decide, before looking at model results or power calculations, how large this information advantage would need to be before it should count as a non-trivial improvement in probabilistic forecast quality?\n\n\n\n\nMore specifically:\n\n\n\n\n\nIs an information-based interpretation like this a reasonable way to anchor a minimum meaningful effect for a proper scoring rule?\n\n\n\n\nIf there is no downstream utility or economic decision function, what kinds of independent justification can legitimately be used to choose the magnitude?\n\n\n\n\nIs there a better way to define a smallest effect of interest for differences in log loss without making the choice arbitrary?\n\n\n\n\n\nI'm deliberately not including previous observed score differences, sample-size calculations, or detectable-effect estimates because I don't want them to influence the definition of what is scientifically meaningful.\n\n\n\n\nI'm interested in the methodology rather than in choosing a particular numerical threshold.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Mika Agnus", "profile_url": "https://stats.stackexchange.com/users/516002/mika-agnus", "user_type": "registered"}, "created_at": "2026-08-27T23:04:13+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "B03D3928-BCC3-4D4B-94BB-94A46248EEBE", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B03D3928-BCC3-4D4B-94BB-94A46248EEBE/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-28T07:06:04+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "6F5C07B7-019A-4952-B6F5-563BE125D485", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/6F5C07B7-019A-4952-B6F5-563BE125D485/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676981/how-can-i-define-a-substantively-meaningful-improvement-in-log-loss-without-usin", "split": "train", "split_group": "776ba189bb0ea546cc1dffafeacbd3c5b96de31792e9feed71bb39f42a79b6ed", "tags": ["forecasting", "model-evaluation", "scoring-rules"], "thread_id": "stats:676981", "title": "How can I define a substantively meaningful improvement in log loss without using the observed results or statistical power?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I am analyzing an ordinal severity score (0–3) measured on individuals from two groups in year1 and year2 across three treatments in a randomized block split-plot experiment, with repeated measurements on individuals.\n\n\n\n\nI initially fitted a cumulative link mixed model (CLMM)\n\n\n\n\nScore ~ Group * Year * Treatment + (1|Block) + (1|Block:Treatment) + (1|Individual_ID)\n\n\n\n\n\nHowever, the model had convergence problems (“Hessian is numerically singular” and relative convergence criterion not met). The higher score categories are sparse, particularly for one group.\n\n\n\n\nI am considering a Poisson GLMM treating the 0–3 score as a discrete numerical response, using the same fixed- and random-effects structure.\n\n\n\n\nMy main interest is the Group × Year × Treatment interaction. Would a Poisson GLMM be a defensible alternative for these data is this defensible as my response variable is ordinal?", "record_id": "Scientific-Statistics-QA:stats:676991", "selected_answer": {"answer_html": "

You have treatment (I assume a categorical variable) as both a fixed effect and a random effect intercept. This seems the most obvious culprit for the model not converging. You have essentially duplicated the same effect in the model, which makes it hard for the model to estimate both the adjusted conditional mean of the fixed effect along with random deviation from the conditional mean.

\n

I would advise against switching to a Poisson model because counts (which Poisson attempts to model) have equidistant measures, whereas ordinal values do not (e.g. "strongly agree" and "agree" on Likert scale ordinal measures are arbitrary and have no such distance).

\n", "answer_id": 676995, "answer_text": "You have treatment (I assume a categorical variable) as both a fixed effect and a random effect intercept. This seems the most obvious culprit for the model not converging. You have essentially duplicated the same effect in the model, which makes it hard for the model to estimate both the adjusted conditional mean of the fixed effect along with random deviation from the conditional mean.\n\n\n\n\nI would advise against switching to a Poisson model because counts (which Poisson attempts to model) have equidistant measures, whereas ordinal values do not (e.g. \"strongly agree\" and \"agree\" on Likert scale ordinal measures are arbitrary and have no such distance).", "answer_url": "https://stats.stackexchange.com/a/676995", "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-29T00:54: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": 676991, "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-29T00:54:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "01E97E2E-7FA2-4C45-A5A0-7539703A463F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/01E97E2E-7FA2-4C45-A5A0-7539703A463F/view-source"}], "score": 4, "updated_at": "2026-08-29T00:54:01+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

You have treatment (I assume a categorical variable) as both a fixed effect and a random effect intercept. This seems the most obvious culprit for the model not converging. You have essentially duplicated the same effect in the model, which makes it hard for the model to estimate both the adjusted conditional mean of the fixed effect along with random deviation from the conditional mean.

\n

I would advise against switching to a Poisson model because counts (which Poisson attempts to model) have equidistant measures, whereas ordinal values do not (e.g. "strongly agree" and "agree" on Likert scale ordinal measures are arbitrary and have no such distance).

\n", "answer_id": 676995, "answer_text": "You have treatment (I assume a categorical variable) as both a fixed effect and a random effect intercept. This seems the most obvious culprit for the model not converging. You have essentially duplicated the same effect in the model, which makes it hard for the model to estimate both the adjusted conditional mean of the fixed effect along with random deviation from the conditional mean.\n\n\n\n\nI would advise against switching to a Poisson model because counts (which Poisson attempts to model) have equidistant measures, whereas ordinal values do not (e.g. \"strongly agree\" and \"agree\" on Likert scale ordinal measures are arbitrary and have no such distance).", "answer_url": "https://stats.stackexchange.com/a/676995", "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-29T00:54: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": 676991, "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-29T00:54:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "01E97E2E-7FA2-4C45-A5A0-7539703A463F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/01E97E2E-7FA2-4C45-A5A0-7539703A463F/view-source"}], "score": 4, "updated_at": "2026-08-29T00:54:01+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Birma29", "question_author_url": "https://stats.stackexchange.com/users/515697/birma29", "question_author_user_type": "registered", "question_created_at": "2026-08-28T19:10:53+00:00", "question_html": "

I am analyzing an ordinal severity score (0–3) measured on individuals from two groups in year1 and year2 across three treatments in a randomized block split-plot experiment, with repeated measurements on individuals.

\n

I initially fitted a cumulative link mixed model (CLMM)

\n
Score ~ Group * Year * Treatment + (1|Block) + (1|Block:Treatment) + (1|Individual_ID)\n
\n

However, the model had convergence problems (“Hessian is numerically singular” and relative convergence criterion not met). The higher score categories are sparse, particularly for one group.

\n

I am considering a Poisson GLMM treating the 0–3 score as a discrete numerical response, using the same fixed- and random-effects structure.

\n

My main interest is the Group × Year × Treatment interaction. Would a Poisson GLMM be a defensible alternative for these data is this defensible as my response variable is ordinal?

\n", "question_id": 676991, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "I am analyzing an ordinal severity score (0–3) measured on individuals from two groups in year1 and year2 across three treatments in a randomized block split-plot experiment, with repeated measurements on individuals.\n\n\n\n\nI initially fitted a cumulative link mixed model (CLMM)\n\n\n\n\nScore ~ Group * Year * Treatment + (1|Block) + (1|Block:Treatment) + (1|Individual_ID)\n\n\n\n\n\nHowever, the model had convergence problems (“Hessian is numerically singular” and relative convergence criterion not met). The higher score categories are sparse, particularly for one group.\n\n\n\n\nI am considering a Poisson GLMM treating the 0–3 score as a discrete numerical response, using the same fixed- and random-effects structure.\n\n\n\n\nMy main interest is the Group × Year × Treatment interaction. Would a Poisson GLMM be a defensible alternative for these data is this defensible as my response variable is ordinal?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Birma29", "profile_url": "https://stats.stackexchange.com/users/515697/birma29", "user_type": "registered"}, "created_at": "2026-08-28T19:10:53+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2E166DFE-8E52-4E6C-AC8E-9E563A2778D5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2E166DFE-8E52-4E6C-AC8E-9E563A2778D5/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:54:56+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "3DA9F5F6-7DE8-4D91-8973-FF6249E83102", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3DA9F5F6-7DE8-4D91-8973-FF6249E83102/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-29T03:21:54+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "99973C1C-812A-46D5-8908-57887A95CE90", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/99973C1C-812A-46D5-8908-57887A95CE90/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676991/choosing-an-appropriate-mixed-effects-model-for-ordinal-data", "split": "train", "split_group": "01a51244f858fac761415988571d97f1f0194066e2e2cc48726efa4a640975a6", "tags": ["r", "mixed-model", "lme4-nlme", "repeated-measures", "glmm"], "thread_id": "stats:676991", "title": "Choosing an appropriate mixed-effects model for ordinal data"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I am doing a study on my university cats' home ranges. The tracker we are using is Damien Farine's Bluetooth Low-energy (BLE) beacons. The tags transmit a signal that can be detected by an Apple device. The phone receiving the signal captures a location from its own GPS and uploads the identity of the tag and its location to Apple's iCloud, which essentially makes up my data.\n\n\n\n\nHere is an example of how the data is collected:\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/Woh1NewX.png] (https://i.sstatic.net/Woh1NewX.png)\n\n\n\n\nFor finding home range of each cat, I am using R package ctmm to calculate Autocorrelated Kernel Density Estimator (AKDE). Before, I only removed ACCs > 100 which left me with ~14 000 rows of observations for each cat over the duration of 2.5 months, which ctmm was not able to handle. Hence, I wish to find a way to thin out the data (make it temporally less dense, since the smallest time interval I have currently is 1 second) while accounting for accuracy/ error estimates.\n\n\n\n\nWhat I did to solve the issue:\n\n\n\n\n\nDuplicated timestamps\n\n\n\n\nDuplicated location points\n\n\n\n\nACC > 50 (Accuracy estimator in metres)\n\n\n\n\n\nThis left me with ~3000 rows of data for each cat.\n\n\n\n\nUsing ctmm R package to derive home range from weighted AKDE (wAKDE) & AKDE:\n\n\n\n\ndata(summer_cat)\nputu <- summer_cat$NUS003\nGUESS <- ctmm.guess(putu,interactive=FALSE) # automated model guess\nM.OUF <- ctmm.fit(putu,GUESS)\nwAKDE <- akde(putu,M.OUF,weights=TRUE)\nAKDE <- akde(putu,M.OUF)\n\n#Plot\nEXT <- extent(AKDE,level=0.95) #DOP is missing. Assumed to be 1.\n\n#wAKDE\nplot(putu,UD=wAKDE,xlim=EXT$x,ylim=EXT$y)\ntitle(expression(\"weighted OUF AKDE\"[\"C\"]))\n\n#AKDE\nplot(putu,UD=AKDE,xlim=EXT$x,ylim=EXT$y)\ntitle(expression(\"OUF AKDE\"[\"C\"]))\n\n\n\n\n\nHere is the resulting home range plots of 1 cat:\n[image: L: Home range from wAKDE, R: Home range from AKDE ; source: https://i.sstatic.net/kXgSIQb8.png] (https://i.sstatic.net/kXgSIQb8.png)\n\n\n\n\nHere is the summary of wAKDE and AKDE respectively:\n[image: L: wAKDE, R: AKDE; source: https://i.sstatic.net/bZFkYz3U.png] (https://i.sstatic.net/bZFkYz3U.png)\n\n\n\n\nHere is the plot points of 1 cat across the campus (~2.5 months of data):\n[image: Plot points generated from R; source: https://i.sstatic.net/I6TIxhWk.png] (https://i.sstatic.net/I6TIxhWk.png)\n\n\n\n\nThe issue here is that the estimate of home range seem to be giving me a circle, when there are clear contours to the data points.\n\n\n\n\nMy questions:\n\n\n\n\n\nHow do I thin out my data? Other than removing obvious outliers, I tried to filter the data by creating new cluster points (in R I attempted to create a function to cluster points within a certain stationary threshold, and the centroid of this point would be the new point)\n\n\n\n\nHow do I account for inaccuracies, especially because this technology is quite new and the only accuracy estimator I have is ACC which I am unsure of how to calibrate it so that I can account for it in the ctmm package.\n\n\n\n\nWhy is the home range a circle?\n\n\n\n\nShould I be using AKDE to find home range or BBMM (Brownian bridge movement model)? BBMM which is better equipped to deal with auto-correlated and clustered position data than KDE home range estimator commonly used in wildlife studies. Specifically, BBMM allows estimation of probabilistic space-use, while accounting for position error and the uncertainty about paths taken between consecutive positions.\n\n\n\n\n\nApologies for the information dump, I am relatively new to movement ecology and R so any advice/ corrections for any of the points mentioned will be greatly appreciated. :)", "record_id": "Scientific-Statistics-QA:stats:676997", "selected_answer": {"answer_html": "

Welcome to CV.
\nThis will not be an answer to your direct questions, nor will it be a particularly "statistical" answer, but a series of remarks, too long to fit in comments, which I hope can help, and a final remark, which unfortunately may not "help"...

\n

First, wrt “Acc” (Accuracy), I would not put too much credibility on that metric. About the only way the receiver (phone) could make such an assessment would be based on signal strength (the stronger the signal, the closer it ought to be). But having worked with BLE, signal strength can be hampered by many factors: tag battery status, but also line of sight between sender and receiver. If there is no direct line of sight between the 2, signals can be dramatically affected:walls, and type of walls -e.g. concrete vs. sheetrock- glass, metal, body parts and location of the tag and/or receiver on the body (bodies, human or animal, with a high water content are very good absorbers of wireless signals), crowded locations (same reason), dense vegetation (again, water as an absorber), wireless interferences from other 2.4 GHz signals (which, btw, include common microwave ovens), etc. Yes, you can use it to reduce the size of your dataset, but I would not put too much trust between an estimated accuracy of 50m and, e.g. 100m, or 25m.
\nNote that the "typical" range for BLE in consumer products is around 25m to 30m; not sure what your beacon is capable of, but 100m seems challenging, even in (near) ideal conditions.
\nYou could (should?) “calibrate” your beacons; simply use a single beacon, and, e.g., your own phone, and see what kind of range you get (and what “Acc” you get). Do this in “clean” environments, and in challenging environments. This will at least give you a sense of how to interpret this “Acc”.

\n

Wrt to thinning out your data, if you are truly only interested in the range of your cats (and not in other characteristics, such as where they seem to spend most of their time), I would use location as the main tool. Once a cat has been observed more than $k$ times (e.g. 3??) in the same general location (within $\\pm u \\text { m}$ - e.g. 10m, or 20m, or??) then you can eliminate all other measurements from this cat which are within $\\pm u \\text { m}$ (because you now determined that this location is part of the range of that cat, and you do not need further measurements).
\nAnother approach is to overlay your map with a $u \\cdot u \\text { m}$ grid, and consider a particular cell being part of the range of cat $c$ if that cat is seen $k$ times in this cell. Beyond that, just use the center of the grid as a single datapoint. Using a 20m x 20m grid, you would have (roughly) at most 50x80, i.e. 4000 datapoints per cat (if they roamed over the entire map, which, from your data, they do not do).

\n

Last, unfortunately, is a bit of possibly (?) bad news. Your spread of “pings” for the cat you showed us seemed to be somehow “bound” by some topographic limits. This peaked my curiosity, so I used Google map to get a satellite view of your campus. See below:\n\"Topography\"\nThe area of greatest interest (to me at least) was the eastern bound, delimited by College Ave E (CAE). Why would cats not cross this road? Too much traffic? It turns that the area east of CAE appears to be densely wooded, with very few buildings. So is the absence of pings in that area due to the cat not crossing the road, or due to the absence of receivers in that area?
\nThe BLE beacons work if there is a relatively dense presence of phones in that area. But are there that many pedestrians (or cyclist) in that densely wooded area? I certainly do not know, but it would be legitimate concern.
\nSimilarly, to the west is a “border” made by Clementi Rd (CR), which appears much wider (hence more traffic?) than CAE. But to the west is a High School stadium, which again begs the question of the density of receivers...
\nAnd to the north, is again a wider street (Dover Road – DR). But beyond is a secondary school, and its athletic field, which may not be densely covered with Apple phones?
\nTo the south, the border is made by what appears to be a freeway, which would be a “natural” boundary for cats.\nLast, in general, feral cats are most active at dawn and dusk, times where the western high school, and the northern secondary school, would be void of students (and hence potential receivers).
\nThis last issue highlights a weakness of this “beacon” method; it depends on the presence of a dense network of phones, at all times where animals may be active. This may be the case for densely populated areas (downtowns? Or your main campus) and diurnal animals. But it gets challenged in your scenario.
\nOf course, if it is simply for a school project, I would not worry too much about this issue (I would still mention it in my final report), but if it is for a more formal project, I would definitively test this (e.g. by placing a few fixed gateways in the suspect areas).

\n", "answer_id": 677001, "answer_text": "Welcome to CV.\n\nThis will not be an answer to your direct questions, nor will it be a particularly \"statistical\" answer, but a series of remarks, too long to fit in comments, which I hope can help, and a final remark, which unfortunately may not \"help\"...\n\n\n\n\nFirst, wrt “Acc” (Accuracy), I would not put too much credibility on that metric. About the only way the receiver (phone) could make such an assessment would be based on signal strength (the stronger the signal, the closer it ought to be). But having worked with BLE, signal strength can be hampered by many factors: tag battery status, but also line of sight between sender and receiver. If there is no direct line of sight between the 2, signals can be dramatically affected:walls, and type of walls -e.g. concrete vs. sheetrock- glass, metal, body parts and location of the tag and/or receiver on the body (bodies, human or animal, with a high water content are very good absorbers of wireless signals), crowded locations (same reason), dense vegetation (again, water as an absorber), wireless interferences from other 2.4 GHz signals (which, btw, include common microwave ovens), etc. Yes, you can use it to reduce the size of your dataset, but I would not put too much trust between an estimated accuracy of 50m and, e.g. 100m, or 25m.\n\nNote that the \"typical\" range for BLE in consumer products is around 25m to 30m; not sure what your beacon is capable of, but 100m seems challenging, even in (near) ideal conditions.\n\nYou could (should?) “calibrate” your beacons; simply use a single beacon, and, e.g., your own phone, and see what kind of range you get (and what “Acc” you get). Do this in “clean” environments, and in challenging environments. This will at least give you a sense of how to interpret this “Acc”.\n\n\n\n\nWrt to thinning out your data, if you are truly only interested in the range of your cats (and not in other characteristics, such as where they seem to spend most of their time), I would use location as the main tool. Once a cat has been observed more than $k$ times (e.g. 3??) in the same general location (within $\\pm u \\text { m}$ - e.g. 10m, or 20m, or??) then you can eliminate all other measurements from this cat which are within $\\pm u \\text { m}$ (because you now determined that this location is part of the range of that cat, and you do not need further measurements).\n\nAnother approach is to overlay your map with a $u \\cdot u \\text { m}$ grid, and consider a particular cell being part of the range of cat $c$ if that cat is seen $k$ times in this cell. Beyond that, just use the center of the grid as a single datapoint. Using a 20m x 20m grid, you would have (roughly) at most 50x80, i.e. 4000 datapoints per cat (if they roamed over the entire map, which, from your data, they do not do).\n\n\n\n\nLast, unfortunately, is a bit of possibly (?) bad news. Your spread of “pings” for the cat you showed us seemed to be somehow “bound” by some topographic limits. This peaked my curiosity, so I used Google map to get a satellite view of your campus. See below:\n[image: Topography; source: https://i.sstatic.net/TjqmodJj.jpg] (https://i.sstatic.net/TjqmodJj.jpg)\nThe area of greatest interest (to me at least) was the eastern bound, delimited by College Ave E (CAE). Why would cats not cross this road? Too much traffic? It turns that the area east of CAE appears to be densely wooded, with very few buildings. So is the absence of pings in that area due to the cat not crossing the road, or due to the absence of receivers in that area?\n\nThe BLE beacons work if there is a relatively dense presence of phones in that area. But are there that many pedestrians (or cyclist) in that densely wooded area? I certainly do not know, but it would be legitimate concern.\n\nSimilarly, to the west is a “border” made by Clementi Rd (CR), which appears much wider (hence more traffic?) than CAE. But to the west is a High School stadium, which again begs the question of the density of receivers...\n\nAnd to the north, is again a wider street (Dover Road – DR). But beyond is a secondary school, and its athletic field, which may not be densely covered with Apple phones?\n\nTo the south, the border is made by what appears to be a freeway, which would be a “natural” boundary for cats.\nLast, in general, feral cats are most active at dawn and dusk, times where the western high school, and the northern secondary school, would be void of students (and hence potential receivers).\n\nThis last issue highlights a weakness of this “beacon” method; it depends on the presence of a dense network of phones, at all times where animals may be active. This may be the case for densely populated areas (downtowns? Or your main campus) and diurnal animals. But it gets challenged in your scenario.\n\nOf course, if it is simply for a school project, I would not worry too much about this issue (I would still mention it in my final report), but if it is for a more formal project, I would definitively test this (e.g. by placing a few fixed gateways in the suspect areas).", "answer_url": "https://stats.stackexchange.com/a/677001", "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-08-29T20:57:23+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": 676997, "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-08-29T20:57:23+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DAC7BF38-AE45-4623-9327-87A8C22E642C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DAC7BF38-AE45-4623-9327-87A8C22E642C/view-source"}, {"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-08-29T22:37:29+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "041DF0BE-0161-4865-A81B-94B540D8D9F9", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/041DF0BE-0161-4865-A81B-94B540D8D9F9/view-source"}, {"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-08-30T15:10:21+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "624A7F3B-1066-4608-8806-E117E3FA25A5", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/624A7F3B-1066-4608-8806-E117E3FA25A5/view-source"}], "score": 6, "updated_at": "2026-08-30T15:10:21+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Welcome to CV.
\nThis will not be an answer to your direct questions, nor will it be a particularly "statistical" answer, but a series of remarks, too long to fit in comments, which I hope can help, and a final remark, which unfortunately may not "help"...

\n

First, wrt “Acc” (Accuracy), I would not put too much credibility on that metric. About the only way the receiver (phone) could make such an assessment would be based on signal strength (the stronger the signal, the closer it ought to be). But having worked with BLE, signal strength can be hampered by many factors: tag battery status, but also line of sight between sender and receiver. If there is no direct line of sight between the 2, signals can be dramatically affected:walls, and type of walls -e.g. concrete vs. sheetrock- glass, metal, body parts and location of the tag and/or receiver on the body (bodies, human or animal, with a high water content are very good absorbers of wireless signals), crowded locations (same reason), dense vegetation (again, water as an absorber), wireless interferences from other 2.4 GHz signals (which, btw, include common microwave ovens), etc. Yes, you can use it to reduce the size of your dataset, but I would not put too much trust between an estimated accuracy of 50m and, e.g. 100m, or 25m.
\nNote that the "typical" range for BLE in consumer products is around 25m to 30m; not sure what your beacon is capable of, but 100m seems challenging, even in (near) ideal conditions.
\nYou could (should?) “calibrate” your beacons; simply use a single beacon, and, e.g., your own phone, and see what kind of range you get (and what “Acc” you get). Do this in “clean” environments, and in challenging environments. This will at least give you a sense of how to interpret this “Acc”.

\n

Wrt to thinning out your data, if you are truly only interested in the range of your cats (and not in other characteristics, such as where they seem to spend most of their time), I would use location as the main tool. Once a cat has been observed more than $k$ times (e.g. 3??) in the same general location (within $\\pm u \\text { m}$ - e.g. 10m, or 20m, or??) then you can eliminate all other measurements from this cat which are within $\\pm u \\text { m}$ (because you now determined that this location is part of the range of that cat, and you do not need further measurements).
\nAnother approach is to overlay your map with a $u \\cdot u \\text { m}$ grid, and consider a particular cell being part of the range of cat $c$ if that cat is seen $k$ times in this cell. Beyond that, just use the center of the grid as a single datapoint. Using a 20m x 20m grid, you would have (roughly) at most 50x80, i.e. 4000 datapoints per cat (if they roamed over the entire map, which, from your data, they do not do).

\n

Last, unfortunately, is a bit of possibly (?) bad news. Your spread of “pings” for the cat you showed us seemed to be somehow “bound” by some topographic limits. This peaked my curiosity, so I used Google map to get a satellite view of your campus. See below:\n\"Topography\"\nThe area of greatest interest (to me at least) was the eastern bound, delimited by College Ave E (CAE). Why would cats not cross this road? Too much traffic? It turns that the area east of CAE appears to be densely wooded, with very few buildings. So is the absence of pings in that area due to the cat not crossing the road, or due to the absence of receivers in that area?
\nThe BLE beacons work if there is a relatively dense presence of phones in that area. But are there that many pedestrians (or cyclist) in that densely wooded area? I certainly do not know, but it would be legitimate concern.
\nSimilarly, to the west is a “border” made by Clementi Rd (CR), which appears much wider (hence more traffic?) than CAE. But to the west is a High School stadium, which again begs the question of the density of receivers...
\nAnd to the north, is again a wider street (Dover Road – DR). But beyond is a secondary school, and its athletic field, which may not be densely covered with Apple phones?
\nTo the south, the border is made by what appears to be a freeway, which would be a “natural” boundary for cats.\nLast, in general, feral cats are most active at dawn and dusk, times where the western high school, and the northern secondary school, would be void of students (and hence potential receivers).
\nThis last issue highlights a weakness of this “beacon” method; it depends on the presence of a dense network of phones, at all times where animals may be active. This may be the case for densely populated areas (downtowns? Or your main campus) and diurnal animals. But it gets challenged in your scenario.
\nOf course, if it is simply for a school project, I would not worry too much about this issue (I would still mention it in my final report), but if it is for a more formal project, I would definitively test this (e.g. by placing a few fixed gateways in the suspect areas).

\n", "answer_id": 677001, "answer_text": "Welcome to CV.\n\nThis will not be an answer to your direct questions, nor will it be a particularly \"statistical\" answer, but a series of remarks, too long to fit in comments, which I hope can help, and a final remark, which unfortunately may not \"help\"...\n\n\n\n\nFirst, wrt “Acc” (Accuracy), I would not put too much credibility on that metric. About the only way the receiver (phone) could make such an assessment would be based on signal strength (the stronger the signal, the closer it ought to be). But having worked with BLE, signal strength can be hampered by many factors: tag battery status, but also line of sight between sender and receiver. If there is no direct line of sight between the 2, signals can be dramatically affected:walls, and type of walls -e.g. concrete vs. sheetrock- glass, metal, body parts and location of the tag and/or receiver on the body (bodies, human or animal, with a high water content are very good absorbers of wireless signals), crowded locations (same reason), dense vegetation (again, water as an absorber), wireless interferences from other 2.4 GHz signals (which, btw, include common microwave ovens), etc. Yes, you can use it to reduce the size of your dataset, but I would not put too much trust between an estimated accuracy of 50m and, e.g. 100m, or 25m.\n\nNote that the \"typical\" range for BLE in consumer products is around 25m to 30m; not sure what your beacon is capable of, but 100m seems challenging, even in (near) ideal conditions.\n\nYou could (should?) “calibrate” your beacons; simply use a single beacon, and, e.g., your own phone, and see what kind of range you get (and what “Acc” you get). Do this in “clean” environments, and in challenging environments. This will at least give you a sense of how to interpret this “Acc”.\n\n\n\n\nWrt to thinning out your data, if you are truly only interested in the range of your cats (and not in other characteristics, such as where they seem to spend most of their time), I would use location as the main tool. Once a cat has been observed more than $k$ times (e.g. 3??) in the same general location (within $\\pm u \\text { m}$ - e.g. 10m, or 20m, or??) then you can eliminate all other measurements from this cat which are within $\\pm u \\text { m}$ (because you now determined that this location is part of the range of that cat, and you do not need further measurements).\n\nAnother approach is to overlay your map with a $u \\cdot u \\text { m}$ grid, and consider a particular cell being part of the range of cat $c$ if that cat is seen $k$ times in this cell. Beyond that, just use the center of the grid as a single datapoint. Using a 20m x 20m grid, you would have (roughly) at most 50x80, i.e. 4000 datapoints per cat (if they roamed over the entire map, which, from your data, they do not do).\n\n\n\n\nLast, unfortunately, is a bit of possibly (?) bad news. Your spread of “pings” for the cat you showed us seemed to be somehow “bound” by some topographic limits. This peaked my curiosity, so I used Google map to get a satellite view of your campus. See below:\n[image: Topography; source: https://i.sstatic.net/TjqmodJj.jpg] (https://i.sstatic.net/TjqmodJj.jpg)\nThe area of greatest interest (to me at least) was the eastern bound, delimited by College Ave E (CAE). Why would cats not cross this road? Too much traffic? It turns that the area east of CAE appears to be densely wooded, with very few buildings. So is the absence of pings in that area due to the cat not crossing the road, or due to the absence of receivers in that area?\n\nThe BLE beacons work if there is a relatively dense presence of phones in that area. But are there that many pedestrians (or cyclist) in that densely wooded area? I certainly do not know, but it would be legitimate concern.\n\nSimilarly, to the west is a “border” made by Clementi Rd (CR), which appears much wider (hence more traffic?) than CAE. But to the west is a High School stadium, which again begs the question of the density of receivers...\n\nAnd to the north, is again a wider street (Dover Road – DR). But beyond is a secondary school, and its athletic field, which may not be densely covered with Apple phones?\n\nTo the south, the border is made by what appears to be a freeway, which would be a “natural” boundary for cats.\nLast, in general, feral cats are most active at dawn and dusk, times where the western high school, and the northern secondary school, would be void of students (and hence potential receivers).\n\nThis last issue highlights a weakness of this “beacon” method; it depends on the presence of a dense network of phones, at all times where animals may be active. This may be the case for densely populated areas (downtowns? Or your main campus) and diurnal animals. But it gets challenged in your scenario.\n\nOf course, if it is simply for a school project, I would not worry too much about this issue (I would still mention it in my final report), but if it is for a more formal project, I would definitively test this (e.g. by placing a few fixed gateways in the suspect areas).", "answer_url": "https://stats.stackexchange.com/a/677001", "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-08-29T20:57:23+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": 676997, "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-08-29T20:57:23+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "DAC7BF38-AE45-4623-9327-87A8C22E642C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DAC7BF38-AE45-4623-9327-87A8C22E642C/view-source"}, {"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-08-29T22:37:29+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "041DF0BE-0161-4865-A81B-94B540D8D9F9", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/041DF0BE-0161-4865-A81B-94B540D8D9F9/view-source"}, {"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-08-30T15:10:21+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "624A7F3B-1066-4608-8806-E117E3FA25A5", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/624A7F3B-1066-4608-8806-E117E3FA25A5/view-source"}], "score": 6, "updated_at": "2026-08-30T15:10:21+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/I6TIxhWk.png", "https://i.sstatic.net/TjqmodJj.jpg", "https://i.sstatic.net/Woh1NewX.png", "https://i.sstatic.net/bZFkYz3U.png", "https://i.sstatic.net/kXgSIQb8.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": "yuen kei", "question_author_url": "https://stats.stackexchange.com/users/516045/yuen-kei", "question_author_user_type": "registered", "question_created_at": "2026-08-29T12:41:14+00:00", "question_html": "

I am doing a study on my university cats' home ranges. The tracker we are using is Damien Farine's Bluetooth Low-energy (BLE) beacons. The tags transmit a signal that can be detected by an Apple device. The phone receiving the signal captures a location from its own GPS and uploads the identity of the tag and its location to Apple's iCloud, which essentially makes up my data.

\n

Here is an example of how the data is collected:

\n

\"enter

\n

For finding home range of each cat, I am using R package ctmm to calculate Autocorrelated Kernel Density Estimator (AKDE). Before, I only removed ACCs > 100 which left me with ~14 000 rows of observations for each cat over the duration of 2.5 months, which ctmm was not able to handle. Hence, I wish to find a way to thin out the data (make it temporally less dense, since the smallest time interval I have currently is 1 second) while accounting for accuracy/ error estimates.

\n

What I did to solve the issue:

\n
    \n
  1. Duplicated timestamps
  2. \n
  3. Duplicated location points
  4. \n
  5. ACC > 50 (Accuracy estimator in metres)
  6. \n
\n

This left me with ~3000 rows of data for each cat.

\n

Using ctmm R package to derive home range from weighted AKDE (wAKDE) & AKDE:

\n
data(summer_cat)\nputu <- summer_cat$NUS003\nGUESS <- ctmm.guess(putu,interactive=FALSE) # automated model guess\nM.OUF <- ctmm.fit(putu,GUESS)\nwAKDE <- akde(putu,M.OUF,weights=TRUE)\nAKDE <- akde(putu,M.OUF)\n\n#Plot\nEXT <- extent(AKDE,level=0.95) #DOP is missing. Assumed to be 1.\n\n#wAKDE\nplot(putu,UD=wAKDE,xlim=EXT$x,ylim=EXT$y)\ntitle(expression("weighted OUF AKDE"["C"]))\n\n#AKDE\nplot(putu,UD=AKDE,xlim=EXT$x,ylim=EXT$y)\ntitle(expression("OUF AKDE"["C"]))\n
\n

Here is the resulting home range plots of 1 cat:\n\"L:

\n

Here is the summary of wAKDE and AKDE respectively:\n\"L:

\n

Here is the plot points of 1 cat across the campus (~2.5 months of data):\n\"Plot

\n

The issue here is that the estimate of home range seem to be giving me a circle, when there are clear contours to the data points.

\n

My questions:

\n
    \n
  1. How do I thin out my data? Other than removing obvious outliers, I tried to filter the data by creating new cluster points (in R I attempted to create a function to cluster points within a certain stationary threshold, and the centroid of this point would be the new point)
  2. \n
  3. How do I account for inaccuracies, especially because this technology is quite new and the only accuracy estimator I have is ACC which I am unsure of how to calibrate it so that I can account for it in the ctmm package.
  4. \n
  5. Why is the home range a circle?
  6. \n
  7. Should I be using AKDE to find home range or BBMM (Brownian bridge movement model)? BBMM which is better equipped to deal with auto-correlated and clustered position data than KDE home range estimator commonly used in wildlife studies. Specifically, BBMM allows estimation of probabilistic space-use, while accounting for position error and the uncertainty about paths taken between consecutive positions.
  8. \n
\n

Apologies for the information dump, I am relatively new to movement ecology and R so any advice/ corrections for any of the points mentioned will be greatly appreciated. :)

\n", "question_id": 676997, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I am doing a study on my university cats' home ranges. The tracker we are using is Damien Farine's Bluetooth Low-energy (BLE) beacons. The tags transmit a signal that can be detected by an Apple device. The phone receiving the signal captures a location from its own GPS and uploads the identity of the tag and its location to Apple's iCloud, which essentially makes up my data.\n\n\n\n\nHere is an example of how the data is collected:\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/Woh1NewX.png] (https://i.sstatic.net/Woh1NewX.png)\n\n\n\n\nFor finding home range of each cat, I am using R package ctmm to calculate Autocorrelated Kernel Density Estimator (AKDE). Before, I only removed ACCs > 100 which left me with ~14 000 rows of observations for each cat over the duration of 2.5 months, which ctmm was not able to handle. Hence, I wish to find a way to thin out the data (make it temporally less dense, since the smallest time interval I have currently is 1 second) while accounting for accuracy/ error estimates.\n\n\n\n\nWhat I did to solve the issue:\n\n\n\n\n\nDuplicated timestamps\n\n\n\n\nDuplicated location points\n\n\n\n\nACC > 50 (Accuracy estimator in metres)\n\n\n\n\n\nThis left me with ~3000 rows of data for each cat.\n\n\n\n\nUsing ctmm R package to derive home range from weighted AKDE (wAKDE) & AKDE:\n\n\n\n\ndata(summer_cat)\nputu <- summer_cat$NUS003\nGUESS <- ctmm.guess(putu,interactive=FALSE) # automated model guess\nM.OUF <- ctmm.fit(putu,GUESS)\nwAKDE <- akde(putu,M.OUF,weights=TRUE)\nAKDE <- akde(putu,M.OUF)\n\n#Plot\nEXT <- extent(AKDE,level=0.95) #DOP is missing. Assumed to be 1.\n\n#wAKDE\nplot(putu,UD=wAKDE,xlim=EXT$x,ylim=EXT$y)\ntitle(expression(\"weighted OUF AKDE\"[\"C\"]))\n\n#AKDE\nplot(putu,UD=AKDE,xlim=EXT$x,ylim=EXT$y)\ntitle(expression(\"OUF AKDE\"[\"C\"]))\n\n\n\n\n\nHere is the resulting home range plots of 1 cat:\n[image: L: Home range from wAKDE, R: Home range from AKDE ; source: https://i.sstatic.net/kXgSIQb8.png] (https://i.sstatic.net/kXgSIQb8.png)\n\n\n\n\nHere is the summary of wAKDE and AKDE respectively:\n[image: L: wAKDE, R: AKDE; source: https://i.sstatic.net/bZFkYz3U.png] (https://i.sstatic.net/bZFkYz3U.png)\n\n\n\n\nHere is the plot points of 1 cat across the campus (~2.5 months of data):\n[image: Plot points generated from R; source: https://i.sstatic.net/I6TIxhWk.png] (https://i.sstatic.net/I6TIxhWk.png)\n\n\n\n\nThe issue here is that the estimate of home range seem to be giving me a circle, when there are clear contours to the data points.\n\n\n\n\nMy questions:\n\n\n\n\n\nHow do I thin out my data? Other than removing obvious outliers, I tried to filter the data by creating new cluster points (in R I attempted to create a function to cluster points within a certain stationary threshold, and the centroid of this point would be the new point)\n\n\n\n\nHow do I account for inaccuracies, especially because this technology is quite new and the only accuracy estimator I have is ACC which I am unsure of how to calibrate it so that I can account for it in the ctmm package.\n\n\n\n\nWhy is the home range a circle?\n\n\n\n\nShould I be using AKDE to find home range or BBMM (Brownian bridge movement model)? BBMM which is better equipped to deal with auto-correlated and clustered position data than KDE home range estimator commonly used in wildlife studies. Specifically, BBMM allows estimation of probabilistic space-use, while accounting for position error and the uncertainty about paths taken between consecutive positions.\n\n\n\n\n\nApologies for the information dump, I am relatively new to movement ecology and R so any advice/ corrections for any of the points mentioned will be greatly appreciated. :)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "yuen kei", "profile_url": "https://stats.stackexchange.com/users/516045/yuen-kei", "user_type": "registered"}, "created_at": "2026-08-29T12:41:14+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "D14E0134-8761-4D18-9603-809C2EE8BF6C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D14E0134-8761-4D18-9603-809C2EE8BF6C/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-30T03:37:51+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9EC2BF4F-7493-47E5-9507-BE468E30BE43", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/9EC2BF4F-7493-47E5-9507-BE468E30BE43/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676997/asking-for-advice-on-cleaning-gps-data-from-ble-trackers", "split": "train", "split_group": "e6076ac1bffe41919709726776bef5ec5e60aef3dc627347d256d7ca034cc2d9", "tags": ["r", "distributions", "ecology"], "thread_id": "stats:676997", "title": "Asking for advice on cleaning GPS data from BLE trackers"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

I agree with Christian's answer. In addition, note that to see how strong an effect is, you need to look at a measure of effect size. For regression problems, betas are such.

\n

One additional reason (perhaps Christian is including this in his (b)) is that year may have effects as a linear trend, with no significant pairwise differences. This can happen even without interactions.

\n

Also, to see what is going on, graphs can be very helpful. This is true for pretty much all statistical results, but maybe especially interactions. It looks like you have N of about 500, with one ordinal (or maybe continuous) independent variable (time) and one nominal one (category) and (I hope) a continuous dependent variable. I suggest a plot with year on the x axis, DV on the y axis, and a line for each category. You can then add the 500 points (I would use a small plotting symbol, or a transparent one).

\n", "answer_id": 677006, "answer_text": "I agree with Christian's answer. In addition, note that to see how strong an effect is, you need to look at a measure of effect size. For regression problems, betas are such.\n\n\n\n\nOne additional reason (perhaps Christian is including this in his (b)) is that year may have effects as a linear trend, with no significant pairwise differences. This can happen even without interactions.\n\n\n\n\nAlso, to see what is going on, graphs can be very helpful. This is true for pretty much all statistical results, but maybe especially interactions. It looks like you have N of about 500, with one ordinal (or maybe continuous) independent variable (time) and one nominal one (category) and (I hope) a continuous dependent variable. I suggest a plot with year on the x axis, DV on the y axis, and a line for each category. You can then add the 500 points (I would use a small plotting symbol, or a transparent one).", "answer_url": "https://stats.stackexchange.com/a/677006", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-30T10:03:20+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": 676999, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-08-30T10:03:20+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "C331109F-9307-4A79-95FC-EC369E9FB2C7", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C331109F-9307-4A79-95FC-EC369E9FB2C7/view-source"}], "score": 5, "updated_at": "2026-08-30T10:03:20+00:00"}, {"answer_html": "

I agree with Christian and Peter's answers here, but there is a critically missed component to this question that wasn't touched upon in their answers. That is, you really shouldn't interpret main effects anymore if they are part of an interaction. I provide a visual depiction of a simple categorical x continuous interaction here. Here the main effects are a bit pointless to interpret on their own. You can use them to understand the conditional mean change in a response or what the linear effect is before changing by-category, sure. But if the interaction is what you care about, particularly if you care about significance, then the main effects are less important. In the example above, you are simply testing if the regression line pivots enough that the types of car influences the relationship between the predictor and response.

\n

I also write here about how theoretically these things don't always make sense. Sometimes an interaction will be significant with main effects not and vice versa. It will depend a lot on the nature of the data generating process, the type of interaction, how statistically powerful the design is, and other factors.

\n", "answer_id": 677016, "answer_text": "I agree with Christian and Peter's answers here, but there is a critically missed component to this question that wasn't touched upon in their answers. That is, you really shouldn't interpret main effects anymore if they are part of an interaction. I provide a visual depiction (https://stats.stackexchange.com/questions/636571/interpreting-main-effects-with-dummy-coded-and-continuous-predictors-in-regressi/636588#636588) of a simple categorical x continuous interaction here. Here the main effects are a bit pointless to interpret on their own. You can use them to understand the conditional mean change in a response or what the linear effect is before changing by-category, sure. But if the interaction is what you care about, particularly if you care about significance, then the main effects are less important. In the example above, you are simply testing if the regression line pivots enough that the types of car influences the relationship between the predictor and response.\n\n\n\n\nI also write here (https://stats.stackexchange.com/questions/636391/comparing-models-with-main-effects-and-interactions/636448#636448) about how theoretically these things don't always make sense. Sometimes an interaction will be significant with main effects not and vice versa. It will depend a lot on the nature of the data generating process, the type of interaction, how statistically powerful the design is, and other factors.", "answer_url": "https://stats.stackexchange.com/a/677016", "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-31T04:38:58+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": 676999, "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-31T04:38:58+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "96A6B18E-56B1-4E3F-80CE-7C9D59B87ACC", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/96A6B18E-56B1-4E3F-80CE-7C9D59B87ACC/view-source"}], "score": 1, "updated_at": "2026-08-31T04:38:58+00:00"}], "product": "statistics_qa", "question": "I am new into statistics so asking a lot of questions (je suis vraiment desoléé).\nI fitted a linear mixed-effects model for repeated measurements with treatment, year, baseline value, and treatment × year as fixed effects. The treatment × year interaction was significant (F(8, 481.31) = 2.14, p = 0.031), while the treatment main effect was not (p = 0.674) but the years p= <0.001.\n\n\n\n\nI then compared treatments within each year using emmeans with Tukey adjustment, but none of the pairwise comparisons was significant (all p > 0.05).\n\n\n\n\nIs this combination of results statistically reasonable? Thanks in advance!", "record_id": "Scientific-Statistics-QA:stats:676999", "selected_answer": {"answer_html": "

It is important here to not think about effects in a binary manner (as if the statistical message were just that an effect is "significant" vs. "not significant"; in particular, "not significant" doesn't mean that an effect doesn't really exist, it just means the data don't provide much evidence that it does). Chances are you are aware that the significance level is something that can be chosen, for example p=0.031 is significant using a 5% significance level but insignificant using a 1% level, meaning that it provides you some evidence, but the evidence is not that strong.

\n

The problem of binary thinking becomes worse once multiple tests are involved, because if nothing goes on and you run several tests, it may easily happen due to random variation that one of the tests is significant. For example, if you run 5 tests at significance level 0.05, the probability for every single test to give you a type I error (significance if in fact nothing is going on) is 0.05 (this is the definition of the significance level), but the probability that a type I error happens in any one of your 5 tests is clearly larger (as there are 5 chances to reach significance) and can be up to 5*0.05=0.25, which means that if you see one 5% significant result in 5 tests, it doesn't mean that much (if anything at all).

\n

In order to deal with this issue, there are multiple testing adjustments that basically run the involved tests in such a way that it becomes harder for a single test to be significant (this could be translated into saying that the tests are implicitly run at a lower significance level) but where the overall type I error of finding even a single significance if all null hypotheses are true (nothing is going on) is your prespecified level, here 0.05. Tukey's adjustment is such a procedure.

\n

The problem with this is that, because it makes it harder for the individual tests to become significant, it will also be harder to avoid a type II error, i.e., not finding significance even if something is going on.

\n

Chances are you feel confused by the fact that there is a significant interaction but you don't find significant treatment differences within the years, which you may expect if there were an interaction. One possible explanation of this is that 0.031 is not a very small p-value indicating that the treatment/year interaction, if existing, may not be very strong, and this will also mean that the Tukey adjusted individual tests have a hard time to find any specific difference as significant. As these are several tests adjusted, it may well happen that looking at the overall situation an interaction looks quite plausible, however the "signal" is too weak to nail down where exactly it comes from running lots of tests with adjustment.

\n

There are actually two possible explanations behind this, namely (a) this is because of the adjustment (but this doesn't mean you shouldn't adjust - Tukey called the adjustment "honest" for a reason, we should be honest about what is not so clear from our data and accept this kind of ambiguous result), and/or (b) the evidence for interaction comes from putting together what goes on in several individual differences that altogether look like something is going on, but every single one, looked at in isolated manner, is too weak to be significant.

\n", "answer_id": 677005, "answer_text": "It is important here to not think about effects in a binary manner (as if the statistical message were just that an effect is \"significant\" vs. \"not significant\"; in particular, \"not significant\" doesn't mean that an effect doesn't really exist, it just means the data don't provide much evidence that it does). Chances are you are aware that the significance level is something that can be chosen, for example p=0.031 is significant using a 5% significance level but insignificant using a 1% level, meaning that it provides you some evidence, but the evidence is not that strong.\n\n\n\n\nThe problem of binary thinking becomes worse once multiple tests are involved, because if nothing goes on and you run several tests, it may easily happen due to random variation that one of the tests is significant. For example, if you run 5 tests at significance level 0.05, the probability for every single test to give you a type I error (significance if in fact nothing is going on) is 0.05 (this is the definition of the significance level), but the probability that a type I error happens in any one of your 5 tests is clearly larger (as there are 5 chances to reach significance) and can be up to 5*0.05=0.25, which means that if you see one 5% significant result in 5 tests, it doesn't mean that much (if anything at all).\n\n\n\n\nIn order to deal with this issue, there are multiple testing adjustments that basically run the involved tests in such a way that it becomes harder for a single test to be significant (this could be translated into saying that the tests are implicitly run at a lower significance level) but where the overall type I error of finding even a single significance if all null hypotheses are true (nothing is going on) is your prespecified level, here 0.05. Tukey's adjustment is such a procedure.\n\n\n\n\nThe problem with this is that, because it makes it harder for the individual tests to become significant, it will also be harder to avoid a type II error, i.e., not finding significance even if something is going on.\n\n\n\n\nChances are you feel confused by the fact that there is a significant interaction but you don't find significant treatment differences within the years, which you may expect if there were an interaction. One possible explanation of this is that 0.031 is not a very small p-value indicating that the treatment/year interaction, if existing, may not be very strong, and this will also mean that the Tukey adjusted individual tests have a hard time to find any specific difference as significant. As these are several tests adjusted, it may well happen that looking at the overall situation an interaction looks quite plausible, however the \"signal\" is too weak to nail down where exactly it comes from running lots of tests with adjustment.\n\n\n\n\nThere are actually two possible explanations behind this, namely (a) this is because of the adjustment (but this doesn't mean you shouldn't adjust - Tukey called the adjustment \"honest\" for a reason, we should be honest about what is not so clear from our data and accept this kind of ambiguous result), and/or (b) the evidence for interaction comes from putting together what goes on in several individual differences that altogether look like something is going on, but every single one, looked at in isolated manner, is too weak to be significant.", "answer_url": "https://stats.stackexchange.com/a/677005", "author": "Christian Hennig", "author_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-30T09:36:51+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": 676999, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-08-30T09:36:51+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "866FFC9A-2B2C-4C94-B1DE-CB438F7F1E68", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/866FFC9A-2B2C-4C94-B1DE-CB438F7F1E68/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-08-30T09:42:52+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "03912F67-F795-4E4B-9265-DFBBF59389DB", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/03912F67-F795-4E4B-9265-DFBBF59389DB/view-source"}], "score": 5, "updated_at": "2026-08-30T09:42:52+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

It is important here to not think about effects in a binary manner (as if the statistical message were just that an effect is "significant" vs. "not significant"; in particular, "not significant" doesn't mean that an effect doesn't really exist, it just means the data don't provide much evidence that it does). Chances are you are aware that the significance level is something that can be chosen, for example p=0.031 is significant using a 5% significance level but insignificant using a 1% level, meaning that it provides you some evidence, but the evidence is not that strong.

\n

The problem of binary thinking becomes worse once multiple tests are involved, because if nothing goes on and you run several tests, it may easily happen due to random variation that one of the tests is significant. For example, if you run 5 tests at significance level 0.05, the probability for every single test to give you a type I error (significance if in fact nothing is going on) is 0.05 (this is the definition of the significance level), but the probability that a type I error happens in any one of your 5 tests is clearly larger (as there are 5 chances to reach significance) and can be up to 5*0.05=0.25, which means that if you see one 5% significant result in 5 tests, it doesn't mean that much (if anything at all).

\n

In order to deal with this issue, there are multiple testing adjustments that basically run the involved tests in such a way that it becomes harder for a single test to be significant (this could be translated into saying that the tests are implicitly run at a lower significance level) but where the overall type I error of finding even a single significance if all null hypotheses are true (nothing is going on) is your prespecified level, here 0.05. Tukey's adjustment is such a procedure.

\n

The problem with this is that, because it makes it harder for the individual tests to become significant, it will also be harder to avoid a type II error, i.e., not finding significance even if something is going on.

\n

Chances are you feel confused by the fact that there is a significant interaction but you don't find significant treatment differences within the years, which you may expect if there were an interaction. One possible explanation of this is that 0.031 is not a very small p-value indicating that the treatment/year interaction, if existing, may not be very strong, and this will also mean that the Tukey adjusted individual tests have a hard time to find any specific difference as significant. As these are several tests adjusted, it may well happen that looking at the overall situation an interaction looks quite plausible, however the "signal" is too weak to nail down where exactly it comes from running lots of tests with adjustment.

\n

There are actually two possible explanations behind this, namely (a) this is because of the adjustment (but this doesn't mean you shouldn't adjust - Tukey called the adjustment "honest" for a reason, we should be honest about what is not so clear from our data and accept this kind of ambiguous result), and/or (b) the evidence for interaction comes from putting together what goes on in several individual differences that altogether look like something is going on, but every single one, looked at in isolated manner, is too weak to be significant.

\n", "answer_id": 677005, "answer_text": "It is important here to not think about effects in a binary manner (as if the statistical message were just that an effect is \"significant\" vs. \"not significant\"; in particular, \"not significant\" doesn't mean that an effect doesn't really exist, it just means the data don't provide much evidence that it does). Chances are you are aware that the significance level is something that can be chosen, for example p=0.031 is significant using a 5% significance level but insignificant using a 1% level, meaning that it provides you some evidence, but the evidence is not that strong.\n\n\n\n\nThe problem of binary thinking becomes worse once multiple tests are involved, because if nothing goes on and you run several tests, it may easily happen due to random variation that one of the tests is significant. For example, if you run 5 tests at significance level 0.05, the probability for every single test to give you a type I error (significance if in fact nothing is going on) is 0.05 (this is the definition of the significance level), but the probability that a type I error happens in any one of your 5 tests is clearly larger (as there are 5 chances to reach significance) and can be up to 5*0.05=0.25, which means that if you see one 5% significant result in 5 tests, it doesn't mean that much (if anything at all).\n\n\n\n\nIn order to deal with this issue, there are multiple testing adjustments that basically run the involved tests in such a way that it becomes harder for a single test to be significant (this could be translated into saying that the tests are implicitly run at a lower significance level) but where the overall type I error of finding even a single significance if all null hypotheses are true (nothing is going on) is your prespecified level, here 0.05. Tukey's adjustment is such a procedure.\n\n\n\n\nThe problem with this is that, because it makes it harder for the individual tests to become significant, it will also be harder to avoid a type II error, i.e., not finding significance even if something is going on.\n\n\n\n\nChances are you feel confused by the fact that there is a significant interaction but you don't find significant treatment differences within the years, which you may expect if there were an interaction. One possible explanation of this is that 0.031 is not a very small p-value indicating that the treatment/year interaction, if existing, may not be very strong, and this will also mean that the Tukey adjusted individual tests have a hard time to find any specific difference as significant. As these are several tests adjusted, it may well happen that looking at the overall situation an interaction looks quite plausible, however the \"signal\" is too weak to nail down where exactly it comes from running lots of tests with adjustment.\n\n\n\n\nThere are actually two possible explanations behind this, namely (a) this is because of the adjustment (but this doesn't mean you shouldn't adjust - Tukey called the adjustment \"honest\" for a reason, we should be honest about what is not so clear from our data and accept this kind of ambiguous result), and/or (b) the evidence for interaction comes from putting together what goes on in several individual differences that altogether look like something is going on, but every single one, looked at in isolated manner, is too weak to be significant.", "answer_url": "https://stats.stackexchange.com/a/677005", "author": "Christian Hennig", "author_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-30T09:36:51+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": 676999, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-08-30T09:36:51+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "866FFC9A-2B2C-4C94-B1DE-CB438F7F1E68", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/866FFC9A-2B2C-4C94-B1DE-CB438F7F1E68/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-08-30T09:42:52+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "03912F67-F795-4E4B-9265-DFBBF59389DB", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/03912F67-F795-4E4B-9265-DFBBF59389DB/view-source"}], "score": 5, "updated_at": "2026-08-30T09:42:52+00:00"}, {"answer_html": "

I agree with Christian's answer. In addition, note that to see how strong an effect is, you need to look at a measure of effect size. For regression problems, betas are such.

\n

One additional reason (perhaps Christian is including this in his (b)) is that year may have effects as a linear trend, with no significant pairwise differences. This can happen even without interactions.

\n

Also, to see what is going on, graphs can be very helpful. This is true for pretty much all statistical results, but maybe especially interactions. It looks like you have N of about 500, with one ordinal (or maybe continuous) independent variable (time) and one nominal one (category) and (I hope) a continuous dependent variable. I suggest a plot with year on the x axis, DV on the y axis, and a line for each category. You can then add the 500 points (I would use a small plotting symbol, or a transparent one).

\n", "answer_id": 677006, "answer_text": "I agree with Christian's answer. In addition, note that to see how strong an effect is, you need to look at a measure of effect size. For regression problems, betas are such.\n\n\n\n\nOne additional reason (perhaps Christian is including this in his (b)) is that year may have effects as a linear trend, with no significant pairwise differences. This can happen even without interactions.\n\n\n\n\nAlso, to see what is going on, graphs can be very helpful. This is true for pretty much all statistical results, but maybe especially interactions. It looks like you have N of about 500, with one ordinal (or maybe continuous) independent variable (time) and one nominal one (category) and (I hope) a continuous dependent variable. I suggest a plot with year on the x axis, DV on the y axis, and a line for each category. You can then add the 500 points (I would use a small plotting symbol, or a transparent one).", "answer_url": "https://stats.stackexchange.com/a/677006", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-30T10:03:20+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": 676999, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-08-30T10:03:20+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "C331109F-9307-4A79-95FC-EC369E9FB2C7", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C331109F-9307-4A79-95FC-EC369E9FB2C7/view-source"}], "score": 5, "updated_at": "2026-08-30T10:03:20+00:00"}, {"answer_html": "

I agree with Christian and Peter's answers here, but there is a critically missed component to this question that wasn't touched upon in their answers. That is, you really shouldn't interpret main effects anymore if they are part of an interaction. I provide a visual depiction of a simple categorical x continuous interaction here. Here the main effects are a bit pointless to interpret on their own. You can use them to understand the conditional mean change in a response or what the linear effect is before changing by-category, sure. But if the interaction is what you care about, particularly if you care about significance, then the main effects are less important. In the example above, you are simply testing if the regression line pivots enough that the types of car influences the relationship between the predictor and response.

\n

I also write here about how theoretically these things don't always make sense. Sometimes an interaction will be significant with main effects not and vice versa. It will depend a lot on the nature of the data generating process, the type of interaction, how statistically powerful the design is, and other factors.

\n", "answer_id": 677016, "answer_text": "I agree with Christian and Peter's answers here, but there is a critically missed component to this question that wasn't touched upon in their answers. That is, you really shouldn't interpret main effects anymore if they are part of an interaction. I provide a visual depiction (https://stats.stackexchange.com/questions/636571/interpreting-main-effects-with-dummy-coded-and-continuous-predictors-in-regressi/636588#636588) of a simple categorical x continuous interaction here. Here the main effects are a bit pointless to interpret on their own. You can use them to understand the conditional mean change in a response or what the linear effect is before changing by-category, sure. But if the interaction is what you care about, particularly if you care about significance, then the main effects are less important. In the example above, you are simply testing if the regression line pivots enough that the types of car influences the relationship between the predictor and response.\n\n\n\n\nI also write here (https://stats.stackexchange.com/questions/636391/comparing-models-with-main-effects-and-interactions/636448#636448) about how theoretically these things don't always make sense. Sometimes an interaction will be significant with main effects not and vice versa. It will depend a lot on the nature of the data generating process, the type of interaction, how statistically powerful the design is, and other factors.", "answer_url": "https://stats.stackexchange.com/a/677016", "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-31T04:38:58+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": 676999, "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-31T04:38:58+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "96A6B18E-56B1-4E3F-80CE-7C9D59B87ACC", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/96A6B18E-56B1-4E3F-80CE-7C9D59B87ACC/view-source"}], "score": 1, "updated_at": "2026-08-31T04:38:58+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Birma29", "question_author_url": "https://stats.stackexchange.com/users/515697/birma29", "question_author_user_type": "registered", "question_created_at": "2026-08-29T16:08:31+00:00", "question_html": "

I am new into statistics so asking a lot of questions (je suis vraiment desoléé).\nI fitted a linear mixed-effects model for repeated measurements with treatment, year, baseline value, and treatment × year as fixed effects. The treatment × year interaction was significant (F(8, 481.31) = 2.14, p = 0.031), while the treatment main effect was not (p = 0.674) but the years p= <0.001.

\n

I then compared treatments within each year using emmeans with Tukey adjustment, but none of the pairwise comparisons was significant (all p > 0.05).

\n

Is this combination of results statistically reasonable? Thanks in advance!

\n", "question_id": 676999, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "I am new into statistics so asking a lot of questions (je suis vraiment desoléé).\nI fitted a linear mixed-effects model for repeated measurements with treatment, year, baseline value, and treatment × year as fixed effects. The treatment × year interaction was significant (F(8, 481.31) = 2.14, p = 0.031), while the treatment main effect was not (p = 0.674) but the years p= <0.001.\n\n\n\n\nI then compared treatments within each year using emmeans with Tukey adjustment, but none of the pairwise comparisons was significant (all p > 0.05).\n\n\n\n\nIs this combination of results statistically reasonable? Thanks in advance!", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Birma29", "profile_url": "https://stats.stackexchange.com/users/515697/birma29", "user_type": "registered"}, "created_at": "2026-08-29T16:08:31+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "B2B4EAF9-2AAA-48F4-98F0-D111351FE815", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B2B4EAF9-2AAA-48F4-98F0-D111351FE815/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-08-30T09:53:07+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "38EE132E-DF0E-4DAA-B191-97E114AC770D", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/38EE132E-DF0E-4DAA-B191-97E114AC770D/view-source"}, {"content_license": null, "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-08-30T09:59:30+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "CE71F047-65B6-4F70-9E0C-269A8E6BCD02", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CE71F047-65B6-4F70-9E0C-269A8E6BCD02/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Birma29", "profile_url": "https://stats.stackexchange.com/users/515697/birma29", "user_type": "registered"}, "created_at": "2026-08-30T18:41:01+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "724A3266-9119-452A-9113-C87906B7D39C", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/724A3266-9119-452A-9113-C87906B7D39C/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/676999/significant-treatment-%c3%97-year-interaction-but-no-significant-pairwise-comparisons", "split": "train", "split_group": "a9cb603b23356afbdfe5c2e6867ee30371fd98119cdc07399de79cfe9fc81caa", "tags": ["regression", "mixed-model", "repeated-measures", "multiple-comparisons", "ancova"], "thread_id": "stats:676999", "title": "Significant treatment × year interaction but no significant pairwise comparisons in a repeated-measures ANCOVA using lmer"}} +{"accepted_answer": {"answer_html": "

Because it can be difficult or impossible to analyze numerical solutions mathematically, one would naturally resort to simulation. This amounts to selecting parameter values of interest and repeatedly creating a random sample determined by those parameters and recording the estimates (using MLE or any other method you might choose to study). The distribution of these simulated estimates, relative to the chosen parameter values, shows you just about everything you might want to know about how your estimator behaves for these parameter values. To understand the estimator generally, repeat for a spectrum of parameter values.

\n

As an example, here is a summary of one thousand Maximum Likelihood estimates made for samples of size $30$ from a Beta$(2, 3)$ distribution.

\n

\"enter

\n

The leftmost panel plots all one thousand $(\\hat\\alpha,\\hat\\beta)$ pairs on log-log axes (because the distributions of the estimates are positively skewed). The red dot indicates the true parameter value $(\\alpha,\\beta)$ while the block triangle indicates the arithmetic means of the estimates: those will approximate the expectation $E[(\\hat\\alpha,\\hat\\beta)].$

\n

The displacement of the black triangle from the red circle depicts the bias in $(\\hat\\alpha,\\hat\\beta).$

\n

The histograms display the univariate distributions of the estimates and, likewise, plot the true values in red and the approximate expectations in black (dotted lines).

\n

This simulation was large enough to establish there is a bias in both estimates: the ratios $E[\\hat\\alpha]/\\alpha$ and $E[\\hat\\beta]/\\beta$ are both approximately $1.10.$ That is, the estimates tend to be ten percent too large. This positive bias persists for all the combinations of $(\\alpha,\\beta)$ I have examined, covering a range from $1/2$ to $100.$ The amount of bias does vary with the parameters. It varies with the sample size, growing smaller as the sample size increases. The relative biases tend to be about equal, regardless.

\n

These biases nearly cancel in the ratios used to compute $\\hat\\mu$ and $\\hat\\sigma^2.$ They are important only for small sample sizes and small values of the parameters, where the biases in $\\hat\\alpha$ and $\\hat\\beta$ can be enormous. But we would expect that when applying Maximum Likelihood to small samples, anyway.

\n
\n

R code for the simulation

\n

The implementation of the ML estimator MLE.beta is quick and dirty; it might perform poorly or fail when one or both parameters are less than $1.$ See the Wikipedia article on the Beta distribution for suggestions on improving this.

\n
#\n# Negative log likelihood of the Beta distribution.\n# `lgm` is the log geometric mean of the data;\n# `lgm1` is the log geometric mean of the complements of the data.\n#\nLambda <- function(theta, lgm, lgm1) {\n  alpha <- exp(theta[1])\n  beta <- exp(theta[2])\n  lbeta(alpha, beta) - (alpha - 1) * lgm - (beta - 1) * lgm1\n}\n#\n# MLE for the Beta distribution.\n#\nMLE.beta <- function(x) {\n  obj <- nlm(Lambda, log(theta), lgm = mean(log(x)), lgm1 = mean(log(1 - x)))\n  exp(obj$estimate)\n}\n#------------------------------------------------------------------------------#\n#\n# Estimate the bias through simulation.\n#\ntheta <- c(alpha = 2, beta = 3)\nn <- 30\nset.seed(17)\nSim <- replicate(1e4, {\n  x <- rbeta(n, theta[1], theta[2])\n  MLE.beta(x)\n})\n#\n# Summarize the simulation.\n#\n# Rho <- cor(t(Sim))\nmeans <- rowMeans(Sim)\ndelta <- means - theta\nsigma <- apply(Sim, 1, sd) / sqrt(ncol(Sim)); names(sigma) <- names(delta)\nZ <- delta / sigma\n#\n# Compute more estimates.\n#\nf <- function(a, b) {\n  mu <- a / (a + b)\n  sigma2 <- a * b / ((a + b)^2 * (a + b + 1))\n  rowMeans(rbind(mu, sigma2))\n}\nmusigma.hat <- f(Sim[1, ], Sim[2, ])\nmusigma <- f(theta[1], theta[2])\n#\n# Display the estimates.\n#\nround(rbind(`True value` = theta,\n             `Relative bias` = (delta + theta) / theta,\n             `Relative SE` = sigma / theta,\n             `Z score` = Z,\n            `mu and sigma^2` = musigma,\n            `hat(mu) and hat(sigma^2)` = musigma.hat), 4)\n\n\npar(mfrow = c(1, 3))\nplot(t(Sim), asp = 1, log = "xy", col = gray(3/4),\n     main = "Joint estimates",\n     xlab = expression(hat(alpha)), ylab = expression(hat(beta)))\npoints(theta[1], theta[2], pch = 21, cex = 1.5, bg = "Red")\npoints(means[1], means[2], pch = 24, cex = 1.5, bg = "Black")\n\nhist(log(Sim[1, ]), main = "", xlab = expression(log(hat(alpha))))\nabline(v = log(theta[1]), col = "Red", lwd = 2)\nabline(v = log(mean(Sim[1, ])), lwd = 2, lty = 3)\nhist(log(Sim[2, ]), main = "", xlab = expression(log(hat(beta))))\nabline(v = log(theta[2]), col = "Red", lwd = 2)\nabline(v = log(mean(Sim[2, ])), lwd = 2, lty = 3)\npar(mfrow = c(1, 1))\n
\n", "answer_id": 677036, "answer_text": "Because it can be difficult or impossible to analyze numerical solutions mathematically, one would naturally resort to simulation. This amounts to selecting parameter values of interest and repeatedly creating a random sample determined by those parameters and recording the estimates (using MLE or any other method you might choose to study). The distribution of these simulated estimates, relative to the chosen parameter values, shows you just about everything you might want to know about how your estimator behaves for these parameter values. To understand the estimator generally, repeat for a spectrum of parameter values.\n\n\n\n\nAs an example, here is a summary of one thousand Maximum Likelihood estimates made for samples of size $30$ from a Beta$(2, 3)$ distribution.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/tCnpe77y.png] (https://i.sstatic.net/tCnpe77y.png)\n\n\n\n\nThe leftmost panel plots all one thousand $(\\hat\\alpha,\\hat\\beta)$ pairs on log-log axes (because the distributions of the estimates are positively skewed). The red dot indicates the true parameter value $(\\alpha,\\beta)$ while the block triangle indicates the arithmetic means of the estimates: those will approximate the expectation $E[(\\hat\\alpha,\\hat\\beta)].$\n\n\n\n\nThe displacement of the black triangle from the red circle depicts the bias in $(\\hat\\alpha,\\hat\\beta).$\n\n\n\n\nThe histograms display the univariate distributions of the estimates and, likewise, plot the true values in red and the approximate expectations in black (dotted lines).\n\n\n\n\nThis simulation was large enough to establish there is a bias in both estimates: the ratios $E[\\hat\\alpha]/\\alpha$ and $E[\\hat\\beta]/\\beta$ are both approximately $1.10.$ That is, the estimates tend to be ten percent too large. This positive bias persists for all the combinations of $(\\alpha,\\beta)$ I have examined, covering a range from $1/2$ to $100.$ The amount of bias does vary with the parameters. It varies with the sample size, growing smaller as the sample size increases. The relative biases tend to be about equal, regardless.\n\n\n\n\nThese biases nearly cancel in the ratios used to compute $\\hat\\mu$ and $\\hat\\sigma^2.$ They are important only for small sample sizes and small values of the parameters, where the biases in $\\hat\\alpha$ and $\\hat\\beta$ can be enormous. But we would expect that when applying Maximum Likelihood to small samples, anyway.\n\n\n\n\n\n\n\nR code for the simulation\n\n\n\n\nThe implementation of the ML estimator MLE.beta is quick and dirty; it might perform poorly or fail when one or both parameters are less than $1.$ See the Wikipedia article on the Beta distribution (https://en.wikipedia.org/wiki/Beta_distribution#Two_unknown_parameters_2) for suggestions on improving this.\n\n\n\n\n#\n# Negative log likelihood of the Beta distribution.\n# `lgm` is the log geometric mean of the data;\n# `lgm1` is the log geometric mean of the complements of the data.\n#\nLambda <- function(theta, lgm, lgm1) {\n alpha <- exp(theta[1])\n beta <- exp(theta[2])\n lbeta(alpha, beta) - (alpha - 1) * lgm - (beta - 1) * lgm1\n}\n#\n# MLE for the Beta distribution.\n#\nMLE.beta <- function(x) {\n obj <- nlm(Lambda, log(theta), lgm = mean(log(x)), lgm1 = mean(log(1 - x)))\n exp(obj$estimate)\n}\n#------------------------------------------------------------------------------#\n#\n# Estimate the bias through simulation.\n#\ntheta <- c(alpha = 2, beta = 3)\nn <- 30\nset.seed(17)\nSim <- replicate(1e4, {\n x <- rbeta(n, theta[1], theta[2])\n MLE.beta(x)\n})\n#\n# Summarize the simulation.\n#\n# Rho <- cor(t(Sim))\nmeans <- rowMeans(Sim)\ndelta <- means - theta\nsigma <- apply(Sim, 1, sd) / sqrt(ncol(Sim)); names(sigma) <- names(delta)\nZ <- delta / sigma\n#\n# Compute more estimates.\n#\nf <- function(a, b) {\n mu <- a / (a + b)\n sigma2 <- a * b / ((a + b)^2 * (a + b + 1))\n rowMeans(rbind(mu, sigma2))\n}\nmusigma.hat <- f(Sim[1, ], Sim[2, ])\nmusigma <- f(theta[1], theta[2])\n#\n# Display the estimates.\n#\nround(rbind(`True value` = theta,\n `Relative bias` = (delta + theta) / theta,\n `Relative SE` = sigma / theta,\n `Z score` = Z,\n `mu and sigma^2` = musigma,\n `hat(mu) and hat(sigma^2)` = musigma.hat), 4)\n\n\npar(mfrow = c(1, 3))\nplot(t(Sim), asp = 1, log = \"xy\", col = gray(3/4),\n main = \"Joint estimates\",\n xlab = expression(hat(alpha)), ylab = expression(hat(beta)))\npoints(theta[1], theta[2], pch = 21, cex = 1.5, bg = \"Red\")\npoints(means[1], means[2], pch = 24, cex = 1.5, bg = \"Black\")\n\nhist(log(Sim[1, ]), main = \"\", xlab = expression(log(hat(alpha))))\nabline(v = log(theta[1]), col = \"Red\", lwd = 2)\nabline(v = log(mean(Sim[1, ])), lwd = 2, lty = 3)\nhist(log(Sim[2, ]), main = \"\", xlab = expression(log(hat(beta))))\nabline(v = log(theta[2]), col = \"Red\", lwd = 2)\nabline(v = log(mean(Sim[2, ])), lwd = 2, lty = 3)\npar(mfrow = c(1, 1))", "answer_url": "https://stats.stackexchange.com/a/677036", "author": "whuber", "author_url": "https://stats.stackexchange.com/users/919/whuber", "author_user_type": "moderator", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T15:28:17+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": 677021, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-01T15:28:17+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "562F742D-E466-46BD-8A9B-E3CC5920C263", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/562F742D-E466-46BD-8A9B-E3CC5920C263/view-source"}], "score": 8, "updated_at": "2026-09-01T15:28:17+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "Suppose $X_1, \\dots, X_n \\overset{\\text{iid}}{\\sim} \\text{Beta}(\\alpha, \\beta)$, and I want to estimate the parameters by maximum likelihood.\n\n\n\n\nI know that:\n$$\\hat\\mu = \\frac{\\hat\\alpha}{\\hat\\alpha + \\hat\\beta}, \\qquad \\hat\\sigma^2 = \\frac{\\hat\\alpha\\hat\\beta}{(\\hat\\alpha+\\hat\\beta)^2(\\hat\\alpha+\\hat\\beta+1)}.$$\n\n\n\n\nIf $\\hat\\alpha$ and $\\hat\\beta$ can only be found numerically, how do we know if $\\hat\\alpha, \\hat\\beta, \\hat\\mu, \\hat\\sigma^2$ are biased or unbiased? (and how large is the bias)", "record_id": "Scientific-Statistics-QA:stats:677021", "selected_answer": {"answer_html": "

Because it can be difficult or impossible to analyze numerical solutions mathematically, one would naturally resort to simulation. This amounts to selecting parameter values of interest and repeatedly creating a random sample determined by those parameters and recording the estimates (using MLE or any other method you might choose to study). The distribution of these simulated estimates, relative to the chosen parameter values, shows you just about everything you might want to know about how your estimator behaves for these parameter values. To understand the estimator generally, repeat for a spectrum of parameter values.

\n

As an example, here is a summary of one thousand Maximum Likelihood estimates made for samples of size $30$ from a Beta$(2, 3)$ distribution.

\n

\"enter

\n

The leftmost panel plots all one thousand $(\\hat\\alpha,\\hat\\beta)$ pairs on log-log axes (because the distributions of the estimates are positively skewed). The red dot indicates the true parameter value $(\\alpha,\\beta)$ while the block triangle indicates the arithmetic means of the estimates: those will approximate the expectation $E[(\\hat\\alpha,\\hat\\beta)].$

\n

The displacement of the black triangle from the red circle depicts the bias in $(\\hat\\alpha,\\hat\\beta).$

\n

The histograms display the univariate distributions of the estimates and, likewise, plot the true values in red and the approximate expectations in black (dotted lines).

\n

This simulation was large enough to establish there is a bias in both estimates: the ratios $E[\\hat\\alpha]/\\alpha$ and $E[\\hat\\beta]/\\beta$ are both approximately $1.10.$ That is, the estimates tend to be ten percent too large. This positive bias persists for all the combinations of $(\\alpha,\\beta)$ I have examined, covering a range from $1/2$ to $100.$ The amount of bias does vary with the parameters. It varies with the sample size, growing smaller as the sample size increases. The relative biases tend to be about equal, regardless.

\n

These biases nearly cancel in the ratios used to compute $\\hat\\mu$ and $\\hat\\sigma^2.$ They are important only for small sample sizes and small values of the parameters, where the biases in $\\hat\\alpha$ and $\\hat\\beta$ can be enormous. But we would expect that when applying Maximum Likelihood to small samples, anyway.

\n
\n

R code for the simulation

\n

The implementation of the ML estimator MLE.beta is quick and dirty; it might perform poorly or fail when one or both parameters are less than $1.$ See the Wikipedia article on the Beta distribution for suggestions on improving this.

\n
#\n# Negative log likelihood of the Beta distribution.\n# `lgm` is the log geometric mean of the data;\n# `lgm1` is the log geometric mean of the complements of the data.\n#\nLambda <- function(theta, lgm, lgm1) {\n  alpha <- exp(theta[1])\n  beta <- exp(theta[2])\n  lbeta(alpha, beta) - (alpha - 1) * lgm - (beta - 1) * lgm1\n}\n#\n# MLE for the Beta distribution.\n#\nMLE.beta <- function(x) {\n  obj <- nlm(Lambda, log(theta), lgm = mean(log(x)), lgm1 = mean(log(1 - x)))\n  exp(obj$estimate)\n}\n#------------------------------------------------------------------------------#\n#\n# Estimate the bias through simulation.\n#\ntheta <- c(alpha = 2, beta = 3)\nn <- 30\nset.seed(17)\nSim <- replicate(1e4, {\n  x <- rbeta(n, theta[1], theta[2])\n  MLE.beta(x)\n})\n#\n# Summarize the simulation.\n#\n# Rho <- cor(t(Sim))\nmeans <- rowMeans(Sim)\ndelta <- means - theta\nsigma <- apply(Sim, 1, sd) / sqrt(ncol(Sim)); names(sigma) <- names(delta)\nZ <- delta / sigma\n#\n# Compute more estimates.\n#\nf <- function(a, b) {\n  mu <- a / (a + b)\n  sigma2 <- a * b / ((a + b)^2 * (a + b + 1))\n  rowMeans(rbind(mu, sigma2))\n}\nmusigma.hat <- f(Sim[1, ], Sim[2, ])\nmusigma <- f(theta[1], theta[2])\n#\n# Display the estimates.\n#\nround(rbind(`True value` = theta,\n             `Relative bias` = (delta + theta) / theta,\n             `Relative SE` = sigma / theta,\n             `Z score` = Z,\n            `mu and sigma^2` = musigma,\n            `hat(mu) and hat(sigma^2)` = musigma.hat), 4)\n\n\npar(mfrow = c(1, 3))\nplot(t(Sim), asp = 1, log = "xy", col = gray(3/4),\n     main = "Joint estimates",\n     xlab = expression(hat(alpha)), ylab = expression(hat(beta)))\npoints(theta[1], theta[2], pch = 21, cex = 1.5, bg = "Red")\npoints(means[1], means[2], pch = 24, cex = 1.5, bg = "Black")\n\nhist(log(Sim[1, ]), main = "", xlab = expression(log(hat(alpha))))\nabline(v = log(theta[1]), col = "Red", lwd = 2)\nabline(v = log(mean(Sim[1, ])), lwd = 2, lty = 3)\nhist(log(Sim[2, ]), main = "", xlab = expression(log(hat(beta))))\nabline(v = log(theta[2]), col = "Red", lwd = 2)\nabline(v = log(mean(Sim[2, ])), lwd = 2, lty = 3)\npar(mfrow = c(1, 1))\n
\n", "answer_id": 677036, "answer_text": "Because it can be difficult or impossible to analyze numerical solutions mathematically, one would naturally resort to simulation. This amounts to selecting parameter values of interest and repeatedly creating a random sample determined by those parameters and recording the estimates (using MLE or any other method you might choose to study). The distribution of these simulated estimates, relative to the chosen parameter values, shows you just about everything you might want to know about how your estimator behaves for these parameter values. To understand the estimator generally, repeat for a spectrum of parameter values.\n\n\n\n\nAs an example, here is a summary of one thousand Maximum Likelihood estimates made for samples of size $30$ from a Beta$(2, 3)$ distribution.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/tCnpe77y.png] (https://i.sstatic.net/tCnpe77y.png)\n\n\n\n\nThe leftmost panel plots all one thousand $(\\hat\\alpha,\\hat\\beta)$ pairs on log-log axes (because the distributions of the estimates are positively skewed). The red dot indicates the true parameter value $(\\alpha,\\beta)$ while the block triangle indicates the arithmetic means of the estimates: those will approximate the expectation $E[(\\hat\\alpha,\\hat\\beta)].$\n\n\n\n\nThe displacement of the black triangle from the red circle depicts the bias in $(\\hat\\alpha,\\hat\\beta).$\n\n\n\n\nThe histograms display the univariate distributions of the estimates and, likewise, plot the true values in red and the approximate expectations in black (dotted lines).\n\n\n\n\nThis simulation was large enough to establish there is a bias in both estimates: the ratios $E[\\hat\\alpha]/\\alpha$ and $E[\\hat\\beta]/\\beta$ are both approximately $1.10.$ That is, the estimates tend to be ten percent too large. This positive bias persists for all the combinations of $(\\alpha,\\beta)$ I have examined, covering a range from $1/2$ to $100.$ The amount of bias does vary with the parameters. It varies with the sample size, growing smaller as the sample size increases. The relative biases tend to be about equal, regardless.\n\n\n\n\nThese biases nearly cancel in the ratios used to compute $\\hat\\mu$ and $\\hat\\sigma^2.$ They are important only for small sample sizes and small values of the parameters, where the biases in $\\hat\\alpha$ and $\\hat\\beta$ can be enormous. But we would expect that when applying Maximum Likelihood to small samples, anyway.\n\n\n\n\n\n\n\nR code for the simulation\n\n\n\n\nThe implementation of the ML estimator MLE.beta is quick and dirty; it might perform poorly or fail when one or both parameters are less than $1.$ See the Wikipedia article on the Beta distribution (https://en.wikipedia.org/wiki/Beta_distribution#Two_unknown_parameters_2) for suggestions on improving this.\n\n\n\n\n#\n# Negative log likelihood of the Beta distribution.\n# `lgm` is the log geometric mean of the data;\n# `lgm1` is the log geometric mean of the complements of the data.\n#\nLambda <- function(theta, lgm, lgm1) {\n alpha <- exp(theta[1])\n beta <- exp(theta[2])\n lbeta(alpha, beta) - (alpha - 1) * lgm - (beta - 1) * lgm1\n}\n#\n# MLE for the Beta distribution.\n#\nMLE.beta <- function(x) {\n obj <- nlm(Lambda, log(theta), lgm = mean(log(x)), lgm1 = mean(log(1 - x)))\n exp(obj$estimate)\n}\n#------------------------------------------------------------------------------#\n#\n# Estimate the bias through simulation.\n#\ntheta <- c(alpha = 2, beta = 3)\nn <- 30\nset.seed(17)\nSim <- replicate(1e4, {\n x <- rbeta(n, theta[1], theta[2])\n MLE.beta(x)\n})\n#\n# Summarize the simulation.\n#\n# Rho <- cor(t(Sim))\nmeans <- rowMeans(Sim)\ndelta <- means - theta\nsigma <- apply(Sim, 1, sd) / sqrt(ncol(Sim)); names(sigma) <- names(delta)\nZ <- delta / sigma\n#\n# Compute more estimates.\n#\nf <- function(a, b) {\n mu <- a / (a + b)\n sigma2 <- a * b / ((a + b)^2 * (a + b + 1))\n rowMeans(rbind(mu, sigma2))\n}\nmusigma.hat <- f(Sim[1, ], Sim[2, ])\nmusigma <- f(theta[1], theta[2])\n#\n# Display the estimates.\n#\nround(rbind(`True value` = theta,\n `Relative bias` = (delta + theta) / theta,\n `Relative SE` = sigma / theta,\n `Z score` = Z,\n `mu and sigma^2` = musigma,\n `hat(mu) and hat(sigma^2)` = musigma.hat), 4)\n\n\npar(mfrow = c(1, 3))\nplot(t(Sim), asp = 1, log = \"xy\", col = gray(3/4),\n main = \"Joint estimates\",\n xlab = expression(hat(alpha)), ylab = expression(hat(beta)))\npoints(theta[1], theta[2], pch = 21, cex = 1.5, bg = \"Red\")\npoints(means[1], means[2], pch = 24, cex = 1.5, bg = \"Black\")\n\nhist(log(Sim[1, ]), main = \"\", xlab = expression(log(hat(alpha))))\nabline(v = log(theta[1]), col = \"Red\", lwd = 2)\nabline(v = log(mean(Sim[1, ])), lwd = 2, lty = 3)\nhist(log(Sim[2, ]), main = \"\", xlab = expression(log(hat(beta))))\nabline(v = log(theta[2]), col = \"Red\", lwd = 2)\nabline(v = log(mean(Sim[2, ])), lwd = 2, lty = 3)\npar(mfrow = c(1, 1))", "answer_url": "https://stats.stackexchange.com/a/677036", "author": "whuber", "author_url": "https://stats.stackexchange.com/users/919/whuber", "author_user_type": "moderator", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T15:28:17+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": 677021, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-01T15:28:17+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "562F742D-E466-46BD-8A9B-E3CC5920C263", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/562F742D-E466-46BD-8A9B-E3CC5920C263/view-source"}], "score": 8, "updated_at": "2026-09-01T15:28:17+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677036, "answers": [{"answer_html": "

Because it can be difficult or impossible to analyze numerical solutions mathematically, one would naturally resort to simulation. This amounts to selecting parameter values of interest and repeatedly creating a random sample determined by those parameters and recording the estimates (using MLE or any other method you might choose to study). The distribution of these simulated estimates, relative to the chosen parameter values, shows you just about everything you might want to know about how your estimator behaves for these parameter values. To understand the estimator generally, repeat for a spectrum of parameter values.

\n

As an example, here is a summary of one thousand Maximum Likelihood estimates made for samples of size $30$ from a Beta$(2, 3)$ distribution.

\n

\"enter

\n

The leftmost panel plots all one thousand $(\\hat\\alpha,\\hat\\beta)$ pairs on log-log axes (because the distributions of the estimates are positively skewed). The red dot indicates the true parameter value $(\\alpha,\\beta)$ while the block triangle indicates the arithmetic means of the estimates: those will approximate the expectation $E[(\\hat\\alpha,\\hat\\beta)].$

\n

The displacement of the black triangle from the red circle depicts the bias in $(\\hat\\alpha,\\hat\\beta).$

\n

The histograms display the univariate distributions of the estimates and, likewise, plot the true values in red and the approximate expectations in black (dotted lines).

\n

This simulation was large enough to establish there is a bias in both estimates: the ratios $E[\\hat\\alpha]/\\alpha$ and $E[\\hat\\beta]/\\beta$ are both approximately $1.10.$ That is, the estimates tend to be ten percent too large. This positive bias persists for all the combinations of $(\\alpha,\\beta)$ I have examined, covering a range from $1/2$ to $100.$ The amount of bias does vary with the parameters. It varies with the sample size, growing smaller as the sample size increases. The relative biases tend to be about equal, regardless.

\n

These biases nearly cancel in the ratios used to compute $\\hat\\mu$ and $\\hat\\sigma^2.$ They are important only for small sample sizes and small values of the parameters, where the biases in $\\hat\\alpha$ and $\\hat\\beta$ can be enormous. But we would expect that when applying Maximum Likelihood to small samples, anyway.

\n
\n

R code for the simulation

\n

The implementation of the ML estimator MLE.beta is quick and dirty; it might perform poorly or fail when one or both parameters are less than $1.$ See the Wikipedia article on the Beta distribution for suggestions on improving this.

\n
#\n# Negative log likelihood of the Beta distribution.\n# `lgm` is the log geometric mean of the data;\n# `lgm1` is the log geometric mean of the complements of the data.\n#\nLambda <- function(theta, lgm, lgm1) {\n  alpha <- exp(theta[1])\n  beta <- exp(theta[2])\n  lbeta(alpha, beta) - (alpha - 1) * lgm - (beta - 1) * lgm1\n}\n#\n# MLE for the Beta distribution.\n#\nMLE.beta <- function(x) {\n  obj <- nlm(Lambda, log(theta), lgm = mean(log(x)), lgm1 = mean(log(1 - x)))\n  exp(obj$estimate)\n}\n#------------------------------------------------------------------------------#\n#\n# Estimate the bias through simulation.\n#\ntheta <- c(alpha = 2, beta = 3)\nn <- 30\nset.seed(17)\nSim <- replicate(1e4, {\n  x <- rbeta(n, theta[1], theta[2])\n  MLE.beta(x)\n})\n#\n# Summarize the simulation.\n#\n# Rho <- cor(t(Sim))\nmeans <- rowMeans(Sim)\ndelta <- means - theta\nsigma <- apply(Sim, 1, sd) / sqrt(ncol(Sim)); names(sigma) <- names(delta)\nZ <- delta / sigma\n#\n# Compute more estimates.\n#\nf <- function(a, b) {\n  mu <- a / (a + b)\n  sigma2 <- a * b / ((a + b)^2 * (a + b + 1))\n  rowMeans(rbind(mu, sigma2))\n}\nmusigma.hat <- f(Sim[1, ], Sim[2, ])\nmusigma <- f(theta[1], theta[2])\n#\n# Display the estimates.\n#\nround(rbind(`True value` = theta,\n             `Relative bias` = (delta + theta) / theta,\n             `Relative SE` = sigma / theta,\n             `Z score` = Z,\n            `mu and sigma^2` = musigma,\n            `hat(mu) and hat(sigma^2)` = musigma.hat), 4)\n\n\npar(mfrow = c(1, 3))\nplot(t(Sim), asp = 1, log = "xy", col = gray(3/4),\n     main = "Joint estimates",\n     xlab = expression(hat(alpha)), ylab = expression(hat(beta)))\npoints(theta[1], theta[2], pch = 21, cex = 1.5, bg = "Red")\npoints(means[1], means[2], pch = 24, cex = 1.5, bg = "Black")\n\nhist(log(Sim[1, ]), main = "", xlab = expression(log(hat(alpha))))\nabline(v = log(theta[1]), col = "Red", lwd = 2)\nabline(v = log(mean(Sim[1, ])), lwd = 2, lty = 3)\nhist(log(Sim[2, ]), main = "", xlab = expression(log(hat(beta))))\nabline(v = log(theta[2]), col = "Red", lwd = 2)\nabline(v = log(mean(Sim[2, ])), lwd = 2, lty = 3)\npar(mfrow = c(1, 1))\n
\n", "answer_id": 677036, "answer_text": "Because it can be difficult or impossible to analyze numerical solutions mathematically, one would naturally resort to simulation. This amounts to selecting parameter values of interest and repeatedly creating a random sample determined by those parameters and recording the estimates (using MLE or any other method you might choose to study). The distribution of these simulated estimates, relative to the chosen parameter values, shows you just about everything you might want to know about how your estimator behaves for these parameter values. To understand the estimator generally, repeat for a spectrum of parameter values.\n\n\n\n\nAs an example, here is a summary of one thousand Maximum Likelihood estimates made for samples of size $30$ from a Beta$(2, 3)$ distribution.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/tCnpe77y.png] (https://i.sstatic.net/tCnpe77y.png)\n\n\n\n\nThe leftmost panel plots all one thousand $(\\hat\\alpha,\\hat\\beta)$ pairs on log-log axes (because the distributions of the estimates are positively skewed). The red dot indicates the true parameter value $(\\alpha,\\beta)$ while the block triangle indicates the arithmetic means of the estimates: those will approximate the expectation $E[(\\hat\\alpha,\\hat\\beta)].$\n\n\n\n\nThe displacement of the black triangle from the red circle depicts the bias in $(\\hat\\alpha,\\hat\\beta).$\n\n\n\n\nThe histograms display the univariate distributions of the estimates and, likewise, plot the true values in red and the approximate expectations in black (dotted lines).\n\n\n\n\nThis simulation was large enough to establish there is a bias in both estimates: the ratios $E[\\hat\\alpha]/\\alpha$ and $E[\\hat\\beta]/\\beta$ are both approximately $1.10.$ That is, the estimates tend to be ten percent too large. This positive bias persists for all the combinations of $(\\alpha,\\beta)$ I have examined, covering a range from $1/2$ to $100.$ The amount of bias does vary with the parameters. It varies with the sample size, growing smaller as the sample size increases. The relative biases tend to be about equal, regardless.\n\n\n\n\nThese biases nearly cancel in the ratios used to compute $\\hat\\mu$ and $\\hat\\sigma^2.$ They are important only for small sample sizes and small values of the parameters, where the biases in $\\hat\\alpha$ and $\\hat\\beta$ can be enormous. But we would expect that when applying Maximum Likelihood to small samples, anyway.\n\n\n\n\n\n\n\nR code for the simulation\n\n\n\n\nThe implementation of the ML estimator MLE.beta is quick and dirty; it might perform poorly or fail when one or both parameters are less than $1.$ See the Wikipedia article on the Beta distribution (https://en.wikipedia.org/wiki/Beta_distribution#Two_unknown_parameters_2) for suggestions on improving this.\n\n\n\n\n#\n# Negative log likelihood of the Beta distribution.\n# `lgm` is the log geometric mean of the data;\n# `lgm1` is the log geometric mean of the complements of the data.\n#\nLambda <- function(theta, lgm, lgm1) {\n alpha <- exp(theta[1])\n beta <- exp(theta[2])\n lbeta(alpha, beta) - (alpha - 1) * lgm - (beta - 1) * lgm1\n}\n#\n# MLE for the Beta distribution.\n#\nMLE.beta <- function(x) {\n obj <- nlm(Lambda, log(theta), lgm = mean(log(x)), lgm1 = mean(log(1 - x)))\n exp(obj$estimate)\n}\n#------------------------------------------------------------------------------#\n#\n# Estimate the bias through simulation.\n#\ntheta <- c(alpha = 2, beta = 3)\nn <- 30\nset.seed(17)\nSim <- replicate(1e4, {\n x <- rbeta(n, theta[1], theta[2])\n MLE.beta(x)\n})\n#\n# Summarize the simulation.\n#\n# Rho <- cor(t(Sim))\nmeans <- rowMeans(Sim)\ndelta <- means - theta\nsigma <- apply(Sim, 1, sd) / sqrt(ncol(Sim)); names(sigma) <- names(delta)\nZ <- delta / sigma\n#\n# Compute more estimates.\n#\nf <- function(a, b) {\n mu <- a / (a + b)\n sigma2 <- a * b / ((a + b)^2 * (a + b + 1))\n rowMeans(rbind(mu, sigma2))\n}\nmusigma.hat <- f(Sim[1, ], Sim[2, ])\nmusigma <- f(theta[1], theta[2])\n#\n# Display the estimates.\n#\nround(rbind(`True value` = theta,\n `Relative bias` = (delta + theta) / theta,\n `Relative SE` = sigma / theta,\n `Z score` = Z,\n `mu and sigma^2` = musigma,\n `hat(mu) and hat(sigma^2)` = musigma.hat), 4)\n\n\npar(mfrow = c(1, 3))\nplot(t(Sim), asp = 1, log = \"xy\", col = gray(3/4),\n main = \"Joint estimates\",\n xlab = expression(hat(alpha)), ylab = expression(hat(beta)))\npoints(theta[1], theta[2], pch = 21, cex = 1.5, bg = \"Red\")\npoints(means[1], means[2], pch = 24, cex = 1.5, bg = \"Black\")\n\nhist(log(Sim[1, ]), main = \"\", xlab = expression(log(hat(alpha))))\nabline(v = log(theta[1]), col = \"Red\", lwd = 2)\nabline(v = log(mean(Sim[1, ])), lwd = 2, lty = 3)\nhist(log(Sim[2, ]), main = \"\", xlab = expression(log(hat(beta))))\nabline(v = log(theta[2]), col = \"Red\", lwd = 2)\nabline(v = log(mean(Sim[2, ])), lwd = 2, lty = 3)\npar(mfrow = c(1, 1))", "answer_url": "https://stats.stackexchange.com/a/677036", "author": "whuber", "author_url": "https://stats.stackexchange.com/users/919/whuber", "author_user_type": "moderator", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T15:28:17+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": 677021, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-01T15:28:17+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "562F742D-E466-46BD-8A9B-E3CC5920C263", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/562F742D-E466-46BD-8A9B-E3CC5920C263/view-source"}], "score": 8, "updated_at": "2026-09-01T15:28:17+00:00"}], "domain": "statistics", "external_links": ["https://en.wikipedia.org/wiki/Beta_distribution#Two_unknown_parameters_2", "https://i.sstatic.net/tCnpe77y.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "adamkostanov", "question_author_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "question_author_user_type": "registered", "question_created_at": "2026-08-31T15:30:58+00:00", "question_html": "

Suppose $X_1, \\dots, X_n \\overset{\\text{iid}}{\\sim} \\text{Beta}(\\alpha, \\beta)$, and I want to estimate the parameters by maximum likelihood.

\n

I know that:\n$$\\hat\\mu = \\frac{\\hat\\alpha}{\\hat\\alpha + \\hat\\beta}, \\qquad \\hat\\sigma^2 = \\frac{\\hat\\alpha\\hat\\beta}{(\\hat\\alpha+\\hat\\beta)^2(\\hat\\alpha+\\hat\\beta+1)}.$$

\n

If $\\hat\\alpha$ and $\\hat\\beta$ can only be found numerically, how do we know if $\\hat\\alpha, \\hat\\beta, \\hat\\mu, \\hat\\sigma^2$ are biased or unbiased? (and how large is the bias)

\n", "question_id": 677021, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Suppose $X_1, \\dots, X_n \\overset{\\text{iid}}{\\sim} \\text{Beta}(\\alpha, \\beta)$, and I want to estimate the parameters by maximum likelihood.\n\n\n\n\nI know that:\n$$\\hat\\mu = \\frac{\\hat\\alpha}{\\hat\\alpha + \\hat\\beta}, \\qquad \\hat\\sigma^2 = \\frac{\\hat\\alpha\\hat\\beta}{(\\hat\\alpha+\\hat\\beta)^2(\\hat\\alpha+\\hat\\beta+1)}.$$\n\n\n\n\nIf $\\hat\\alpha$ and $\\hat\\beta$ can only be found numerically, how do we know if $\\hat\\alpha, \\hat\\beta, \\hat\\mu, \\hat\\sigma^2$ are biased or unbiased? (and how large is the bias)", "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-31T15:30:58+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "9E0825ED-D3A3-4B9D-A473-EAAC6F1F776C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9E0825ED-D3A3-4B9D-A473-EAAC6F1F776C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-01T15:34:43+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "E40FFCDD-0DA9-4AD3-8F2B-156FC54FF70B", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E40FFCDD-0DA9-4AD3-8F2B-156FC54FF70B/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-01T15:40:03+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "B40F8A52-F9E0-4EFC-B9EE-1256CB7E1E1B", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/B40F8A52-F9E0-4EFC-B9EE-1256CB7E1E1B/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677021/if-an-mle-can-only-be-solved-numerically-how-do-we-know-if-it-is-biased-or-unbi", "split": "train", "split_group": "e281e2df35e214047c71a76e665e03cfecfa605e1301c0b2625e62afa44ac194", "tags": ["maximum-likelihood"], "thread_id": "stats:677021", "title": "If an MLE can only be solved numerically, how do we know if it is biased or unbiased?"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

The regression coefficients for variables not in the interaction are main effects, conditional on all the other variables, including the interaction.

\n

I don't know of a book that states this, but you can either a) Do the math and show it or b) Plug in different values of X, Z, C1, and C2 and show it that way.

\n", "answer_id": 677028, "answer_text": "The regression coefficients for variables not in the interaction are main effects, conditional on all the other variables, including the interaction.\n\n\n\n\nI don't know of a book that states this, but you can either a) Do the math and show it or b) Plug in different values of X, Z, C1, and C2 and show it that way.", "answer_url": "https://stats.stackexchange.com/a/677028", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-31T18:43:35+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": 677023, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-08-31T18:43:35+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "02A19662-7877-4049-B5F5-406036C72096", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/02A19662-7877-4049-B5F5-406036C72096/view-source"}], "score": 0, "updated_at": "2026-08-31T18:43:35+00:00"}], "product": "statistics_qa", "question": "Logistic regression:\n\n\n\n\nglm(Y ~ X * Z + C1 + C2, family = binomial)\n\n\n\n\n\nI know β_X and β_Z are conditional (effect when the other is 0) and shouldn't be read as main effects.\n\n\n\n\nDoes this also apply to C1, which isn't in the interaction? Or is exp(β_C1) still the ordinary adjusted OR, with the p value testing the ordinary null?\n\n\n\n\nAny textbook or paper that states this explicitly?", "record_id": "Scientific-Statistics-QA:stats:677023", "selected_answer": {"answer_html": "

Edit:

\n

The original answer focused more on OLS, when the question is about the logistic case. I'm leaving the commenters' suggested citations but added on another to mine and revamped the example

\n
\n\n
    \n
  1. Ordinary regression, and general issues with GLMS: Weisberg: Applied Linear Regression; Fox: Applied Regression Analysis and Generalized Linear Models
  2. \n
  3. Specific to logistic regression: Hosmer and Lemeshow: Applied Logistic Regression
  4. \n
\n

In Fox's Chapter 7, he discusses the interpretation of coefficients in the presence of interactions, quoting Nelder's principle of marginality as well (which is a nice bonus). Even though the quote is in the context of his discussion of OLS with dummy variables, Nelder's principle is important across generalized linear modeling. Hosmer and Lemeshow (p. 64 - 77) give much more detail on your question. I'll try to briefly summarize using one of their examples.

\n

Let's consider a logistic model with a indicator "exposure" variable for sex ($X_1 = 1 \\text{, if Female}$), a continuous covariate $Z = \\text{Age}$, the interaction variable $X_{1}Z$ and a separate covariate $X_2$ (say the patient's BMI). The outcome is $Y = 1$ if a patient develops coronary heart disease (CHD), and $Y = 0$ otherwise.

\n

On the log-odds scale, if we assume the $\\text{Age} \\sim \\text{CHD}$ relationship is linear in both sexes, and we introduce an interaction along with additional adjustment for BMI, we have:

\n

$$\n\\text{logit}(Y_i) = \\alpha + \\beta_1 X_{i1} + \\gamma Z_i + \\delta (X_1Z)_i + \\beta_2 X_{i2}\n$$

\n

Now write down the model separately for the two sexes substituting $0$ and $1$ accordingly for $X_1$ in each case and moving things around algebraically:

\n

$$\n\\begin{align}\n\\text{Female: } & \\text{logit}Y_i = (\\alpha + \\beta_1) + (\\gamma + \\delta)Z_i + \\beta_2 X_{i2}\\\\\n\\text{Male: } & \\text{logit}Y_i = \\alpha + \\gamma Z_i + \\beta_2 X_{i2}\n\\end{align}\n$$

\n

Though it is easier to see if we had actual estimates for $\\alpha$, $\\beta_1$, $\\beta_2$, and $\\gamma$, we have a different intercept and $\\text{logit}(Y) \\sim \\text{Age}$ slope between Males and Females, but $\\beta_2$, the slope relating BMI to $\\text{logit}(Y)$ stays the same in both cases.

\n

So on the logit scale, you can still interpret the marginal effect of educational attainment in the same way, though of course it is conditional on the rest of the terms in the model. That is, the “main effect” of age remains interpretable, unlike the main effects for treatment and whatever lab value you're interested in.

\n

This changes a bit when we exponentiate, as we must estimate odds-ratios involving the interaction terms at specific values of each of the interacting variables. However, since the additional covariate (BMI in this case) is not involved in that messiness, we can still exponentiate and do well with that odds-ratio, but still keeping in mind that we've got an interaction in our model. In many cases, however, we may be uninterested in the BMI odds ratio (i.e., the covariate), and only include it to better reduce confounding of the other effects (perhaps the exposure). This gets us into advanced territory, so I'll leave it here.

\n", "answer_id": 677039, "answer_text": "Edit:\n\n\n\n\nThe original answer focused more on OLS, when the question is about the logistic case. I'm leaving the commenters' suggested citations but added on another to mine and revamped the example\n\n\n\n\n\n\n\n\nfrom Whuber: F. Mosteller and J. Tukey, Data Analysis and Regression (https://archive.org/details/dataanalysisregr0000most)\n\n\n\n\nfrom M--: P. Roback and J. Legler: Beyond Multiple Linear Regression (https://bookdown.org/roback/bookdown-BeyondMLR/)\n\n\n\n\nMy picks:\n\n\n\n\n\n\nOrdinary regression, and general issues with GLMS: Weisberg: Applied Linear Regression (https://www.wiley.com/en-br/shop/general-introductory-statistics/applied-linear-regression-4th-edition-p-9781118386088); Fox: Applied Regression Analysis and Generalized Linear Models (https://collegepublishing.sagepub.com/products/applied-regression-analysis-and-generalized-linear-models-3-237254)\n\n\n\n\nSpecific to logistic regression: Hosmer and Lemeshow: Applied Logistic Regression (https://onlinelibrary.wiley.com/doi/book/10.1002/9781118548387)\n\n\n\n\n\nIn Fox's Chapter 7, he discusses the interpretation of coefficients in the presence of interactions, quoting Nelder's principle of marginality as well (which is a nice bonus). Even though the quote is in the context of his discussion of OLS with dummy variables, Nelder's principle is important across generalized linear modeling. Hosmer and Lemeshow (p. 64 - 77) give much more detail on your question. I'll try to briefly summarize using one of their examples.\n\n\n\n\nLet's consider a logistic model with a indicator \"exposure\" variable for sex ($X_1 = 1 \\text{, if Female}$), a continuous covariate $Z = \\text{Age}$, the interaction variable $X_{1}Z$ and a separate covariate $X_2$ (say the patient's BMI). The outcome is $Y = 1$ if a patient develops coronary heart disease (CHD), and $Y = 0$ otherwise.\n\n\n\n\nOn the log-odds scale, if we assume the $\\text{Age} \\sim \\text{CHD}$ relationship is linear in both sexes, and we introduce an interaction along with additional adjustment for BMI, we have:\n\n\n\n\n$$\n\\text{logit}(Y_i) = \\alpha + \\beta_1 X_{i1} + \\gamma Z_i + \\delta (X_1Z)_i + \\beta_2 X_{i2}\n$$\n\n\n\n\nNow write down the model separately for the two sexes substituting $0$ and $1$ accordingly for $X_1$ in each case and moving things around algebraically:\n\n\n\n\n$$\n\\begin{align}\n\\text{Female: } & \\text{logit}Y_i = (\\alpha + \\beta_1) + (\\gamma + \\delta)Z_i + \\beta_2 X_{i2}\\\\\n\\text{Male: } & \\text{logit}Y_i = \\alpha + \\gamma Z_i + \\beta_2 X_{i2}\n\\end{align}\n$$\n\n\n\n\nThough it is easier to see if we had actual estimates for $\\alpha$, $\\beta_1$, $\\beta_2$, and $\\gamma$, we have a different intercept and $\\text{logit}(Y) \\sim \\text{Age}$ slope between Males and Females, but $\\beta_2$, the slope relating BMI to $\\text{logit}(Y)$ stays the same in both cases.\n\n\n\n\nSo on the logit scale, you can still interpret the marginal effect of educational attainment in the same way, though of course it is conditional on the rest of the terms in the model. That is, the “main effect” of age remains interpretable, unlike the main effects for treatment and whatever lab value you're interested in.\n\n\n\n\nThis changes a bit when we exponentiate, as we must estimate odds-ratios involving the interaction terms at specific values of each of the interacting variables. However, since the additional covariate (BMI in this case) is not involved in that messiness, we can still exponentiate and do well with that odds-ratio, but still keeping in mind that we've got an interaction in our model. In many cases, however, we may be uninterested in the BMI odds ratio (i.e., the covariate), and only include it to better reduce confounding of the other effects (perhaps the exposure). This gets us into advanced territory, so I'll leave it here.", "answer_url": "https://stats.stackexchange.com/a/677039", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T18:54:15+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": 677023, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-01T18:54:15+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "1C96DBED-01C4-408D-8ADC-73D384ED5F3D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1C96DBED-01C4-408D-8ADC-73D384ED5F3D/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-02T01:11:13+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "EB91F46E-AE98-4B27-B146-70EE8551482D", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EB91F46E-AE98-4B27-B146-70EE8551482D/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "mastropi", "profile_url": "https://stats.stackexchange.com/users/217355/mastropi", "user_type": "registered"}, "created_at": "2026-09-02T11:36:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "EB25A932-6CB9-4775-9305-5FA8CA11BEE5", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EB25A932-6CB9-4775-9305-5FA8CA11BEE5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-02T19:56:28+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0C25F4DB-255E-4A29-8217-4F07665C4131", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0C25F4DB-255E-4A29-8217-4F07665C4131/view-source"}], "score": 5, "updated_at": "2026-09-02T19:56:28+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

The regression coefficients for variables not in the interaction are main effects, conditional on all the other variables, including the interaction.

\n

I don't know of a book that states this, but you can either a) Do the math and show it or b) Plug in different values of X, Z, C1, and C2 and show it that way.

\n", "answer_id": 677028, "answer_text": "The regression coefficients for variables not in the interaction are main effects, conditional on all the other variables, including the interaction.\n\n\n\n\nI don't know of a book that states this, but you can either a) Do the math and show it or b) Plug in different values of X, Z, C1, and C2 and show it that way.", "answer_url": "https://stats.stackexchange.com/a/677028", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-08-31T18:43:35+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": 677023, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-08-31T18:43:35+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "02A19662-7877-4049-B5F5-406036C72096", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/02A19662-7877-4049-B5F5-406036C72096/view-source"}], "score": 0, "updated_at": "2026-08-31T18:43:35+00:00"}, {"answer_html": "

Edit:

\n

The original answer focused more on OLS, when the question is about the logistic case. I'm leaving the commenters' suggested citations but added on another to mine and revamped the example

\n
\n\n
    \n
  1. Ordinary regression, and general issues with GLMS: Weisberg: Applied Linear Regression; Fox: Applied Regression Analysis and Generalized Linear Models
  2. \n
  3. Specific to logistic regression: Hosmer and Lemeshow: Applied Logistic Regression
  4. \n
\n

In Fox's Chapter 7, he discusses the interpretation of coefficients in the presence of interactions, quoting Nelder's principle of marginality as well (which is a nice bonus). Even though the quote is in the context of his discussion of OLS with dummy variables, Nelder's principle is important across generalized linear modeling. Hosmer and Lemeshow (p. 64 - 77) give much more detail on your question. I'll try to briefly summarize using one of their examples.

\n

Let's consider a logistic model with a indicator "exposure" variable for sex ($X_1 = 1 \\text{, if Female}$), a continuous covariate $Z = \\text{Age}$, the interaction variable $X_{1}Z$ and a separate covariate $X_2$ (say the patient's BMI). The outcome is $Y = 1$ if a patient develops coronary heart disease (CHD), and $Y = 0$ otherwise.

\n

On the log-odds scale, if we assume the $\\text{Age} \\sim \\text{CHD}$ relationship is linear in both sexes, and we introduce an interaction along with additional adjustment for BMI, we have:

\n

$$\n\\text{logit}(Y_i) = \\alpha + \\beta_1 X_{i1} + \\gamma Z_i + \\delta (X_1Z)_i + \\beta_2 X_{i2}\n$$

\n

Now write down the model separately for the two sexes substituting $0$ and $1$ accordingly for $X_1$ in each case and moving things around algebraically:

\n

$$\n\\begin{align}\n\\text{Female: } & \\text{logit}Y_i = (\\alpha + \\beta_1) + (\\gamma + \\delta)Z_i + \\beta_2 X_{i2}\\\\\n\\text{Male: } & \\text{logit}Y_i = \\alpha + \\gamma Z_i + \\beta_2 X_{i2}\n\\end{align}\n$$

\n

Though it is easier to see if we had actual estimates for $\\alpha$, $\\beta_1$, $\\beta_2$, and $\\gamma$, we have a different intercept and $\\text{logit}(Y) \\sim \\text{Age}$ slope between Males and Females, but $\\beta_2$, the slope relating BMI to $\\text{logit}(Y)$ stays the same in both cases.

\n

So on the logit scale, you can still interpret the marginal effect of educational attainment in the same way, though of course it is conditional on the rest of the terms in the model. That is, the “main effect” of age remains interpretable, unlike the main effects for treatment and whatever lab value you're interested in.

\n

This changes a bit when we exponentiate, as we must estimate odds-ratios involving the interaction terms at specific values of each of the interacting variables. However, since the additional covariate (BMI in this case) is not involved in that messiness, we can still exponentiate and do well with that odds-ratio, but still keeping in mind that we've got an interaction in our model. In many cases, however, we may be uninterested in the BMI odds ratio (i.e., the covariate), and only include it to better reduce confounding of the other effects (perhaps the exposure). This gets us into advanced territory, so I'll leave it here.

\n", "answer_id": 677039, "answer_text": "Edit:\n\n\n\n\nThe original answer focused more on OLS, when the question is about the logistic case. I'm leaving the commenters' suggested citations but added on another to mine and revamped the example\n\n\n\n\n\n\n\n\nfrom Whuber: F. Mosteller and J. Tukey, Data Analysis and Regression (https://archive.org/details/dataanalysisregr0000most)\n\n\n\n\nfrom M--: P. Roback and J. Legler: Beyond Multiple Linear Regression (https://bookdown.org/roback/bookdown-BeyondMLR/)\n\n\n\n\nMy picks:\n\n\n\n\n\n\nOrdinary regression, and general issues with GLMS: Weisberg: Applied Linear Regression (https://www.wiley.com/en-br/shop/general-introductory-statistics/applied-linear-regression-4th-edition-p-9781118386088); Fox: Applied Regression Analysis and Generalized Linear Models (https://collegepublishing.sagepub.com/products/applied-regression-analysis-and-generalized-linear-models-3-237254)\n\n\n\n\nSpecific to logistic regression: Hosmer and Lemeshow: Applied Logistic Regression (https://onlinelibrary.wiley.com/doi/book/10.1002/9781118548387)\n\n\n\n\n\nIn Fox's Chapter 7, he discusses the interpretation of coefficients in the presence of interactions, quoting Nelder's principle of marginality as well (which is a nice bonus). Even though the quote is in the context of his discussion of OLS with dummy variables, Nelder's principle is important across generalized linear modeling. Hosmer and Lemeshow (p. 64 - 77) give much more detail on your question. I'll try to briefly summarize using one of their examples.\n\n\n\n\nLet's consider a logistic model with a indicator \"exposure\" variable for sex ($X_1 = 1 \\text{, if Female}$), a continuous covariate $Z = \\text{Age}$, the interaction variable $X_{1}Z$ and a separate covariate $X_2$ (say the patient's BMI). The outcome is $Y = 1$ if a patient develops coronary heart disease (CHD), and $Y = 0$ otherwise.\n\n\n\n\nOn the log-odds scale, if we assume the $\\text{Age} \\sim \\text{CHD}$ relationship is linear in both sexes, and we introduce an interaction along with additional adjustment for BMI, we have:\n\n\n\n\n$$\n\\text{logit}(Y_i) = \\alpha + \\beta_1 X_{i1} + \\gamma Z_i + \\delta (X_1Z)_i + \\beta_2 X_{i2}\n$$\n\n\n\n\nNow write down the model separately for the two sexes substituting $0$ and $1$ accordingly for $X_1$ in each case and moving things around algebraically:\n\n\n\n\n$$\n\\begin{align}\n\\text{Female: } & \\text{logit}Y_i = (\\alpha + \\beta_1) + (\\gamma + \\delta)Z_i + \\beta_2 X_{i2}\\\\\n\\text{Male: } & \\text{logit}Y_i = \\alpha + \\gamma Z_i + \\beta_2 X_{i2}\n\\end{align}\n$$\n\n\n\n\nThough it is easier to see if we had actual estimates for $\\alpha$, $\\beta_1$, $\\beta_2$, and $\\gamma$, we have a different intercept and $\\text{logit}(Y) \\sim \\text{Age}$ slope between Males and Females, but $\\beta_2$, the slope relating BMI to $\\text{logit}(Y)$ stays the same in both cases.\n\n\n\n\nSo on the logit scale, you can still interpret the marginal effect of educational attainment in the same way, though of course it is conditional on the rest of the terms in the model. That is, the “main effect” of age remains interpretable, unlike the main effects for treatment and whatever lab value you're interested in.\n\n\n\n\nThis changes a bit when we exponentiate, as we must estimate odds-ratios involving the interaction terms at specific values of each of the interacting variables. However, since the additional covariate (BMI in this case) is not involved in that messiness, we can still exponentiate and do well with that odds-ratio, but still keeping in mind that we've got an interaction in our model. In many cases, however, we may be uninterested in the BMI odds ratio (i.e., the covariate), and only include it to better reduce confounding of the other effects (perhaps the exposure). This gets us into advanced territory, so I'll leave it here.", "answer_url": "https://stats.stackexchange.com/a/677039", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T18:54:15+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": 677023, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-01T18:54:15+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "1C96DBED-01C4-408D-8ADC-73D384ED5F3D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1C96DBED-01C4-408D-8ADC-73D384ED5F3D/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-02T01:11:13+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "EB91F46E-AE98-4B27-B146-70EE8551482D", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EB91F46E-AE98-4B27-B146-70EE8551482D/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "mastropi", "profile_url": "https://stats.stackexchange.com/users/217355/mastropi", "user_type": "registered"}, "created_at": "2026-09-02T11:36:08+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "EB25A932-6CB9-4775-9305-5FA8CA11BEE5", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EB25A932-6CB9-4775-9305-5FA8CA11BEE5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-02T19:56:28+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "0C25F4DB-255E-4A29-8217-4F07665C4131", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0C25F4DB-255E-4A29-8217-4F07665C4131/view-source"}], "score": 5, "updated_at": "2026-09-02T19:56:28+00:00"}], "domain": "statistics", "external_links": ["https://archive.org/details/dataanalysisregr0000most", "https://bookdown.org/roback/bookdown-BeyondMLR/", "https://collegepublishing.sagepub.com/products/applied-regression-analysis-and-generalized-linear-models-3-237254", "https://onlinelibrary.wiley.com/doi/book/10.1002/9781118548387", "https://www.wiley.com/en-br/shop/general-introductory-statistics/applied-linear-regression-4th-edition-p-9781118386088"], "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": "Konstantinos Gkirgkiris", "question_author_url": "https://stats.stackexchange.com/users/466987/konstantinos-gkirgkiris", "question_author_user_type": "registered", "question_created_at": "2026-08-31T16:28:24+00:00", "question_html": "

Logistic regression:

\n
glm(Y ~ X * Z + C1 + C2, family = binomial)\n
\n

I know β_X and β_Z are conditional (effect when the other is 0) and shouldn't be read as main effects.

\n

Does this also apply to C1, which isn't in the interaction? Or is exp(β_C1) still the ordinary adjusted OR, with the p value testing the ordinary null?

\n

Any textbook or paper that states this explicitly?

\n", "question_id": 677023, "question_license": "CC BY-SA 4.0", "question_score": 6, "question_text": "Logistic regression:\n\n\n\n\nglm(Y ~ X * Z + C1 + C2, family = binomial)\n\n\n\n\n\nI know β_X and β_Z are conditional (effect when the other is 0) and shouldn't be read as main effects.\n\n\n\n\nDoes this also apply to C1, which isn't in the interaction? Or is exp(β_C1) still the ordinary adjusted OR, with the p value testing the ordinary null?\n\n\n\n\nAny textbook or paper that states this explicitly?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Konstantinos Gkirgkiris", "profile_url": "https://stats.stackexchange.com/users/466987/konstantinos-gkirgkiris", "user_type": "registered"}, "created_at": "2026-08-31T16:28:24+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "625D283B-6E8B-49CC-9D39-A419938D290E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/625D283B-6E8B-49CC-9D39-A419938D290E/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-01T00:39:35+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "7B7DEF62-2D77-4CB5-B284-7203069E17E3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/7B7DEF62-2D77-4CB5-B284-7203069E17E3/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677023/does-an-interaction-term-affect-the-interpretation-of-the-other-covariates", "split": "train", "split_group": "0a1bcd73d1b98426209a0c28354537686e3002366acc568482c8aa33acc3129f", "tags": ["regression", "r", "interaction"], "thread_id": "stats:677023", "title": "Does an interaction term affect the interpretation of the other covariates?"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

RMSE = 3.82e-13\n=> Model is getting a perfect score.\n=> Red Flag

\n

You put Store is the data.\nTotal Purchases = Store + Web + Catalog\n=> OLS Regressor didn't bother to learn about the customer behavior.\nIt is actually solving an eqn : Store = Total Purchases - Web - Catalog

\n

Do a quick check on features like MntWines or MntMeatProducts.\nMake sure those totals don't accidentally contain the physical store purchase counts we are trying to predict.

\n

If We are trying to predict NumStorePurchases (Let's say, how many times a man visited the physical store).

\n

The danger is that features like MntWines (Total dollars spent on wine) or MntMeatProducts(Total dollars spent on meat) might be acting like a Wines or Meat bought from this physical store receipt.\nThen the machine will cheat saying "He bought wines from this physical store, therefore he went to the physical store."

\n

All I am saying is If MntWines includes physical store purchases, we have to drop it. It gives away the answer.\nBut Why am I saying this? Let's say we want to predict the human behavior.
\nIf you put this model into the real world to predict what customers will do tomorrow, it will crash.

\n

Why? Because tomorrow hasn't happened yet. You don't have tomorrow's meat receipts. You only have MntMeatProducts after the target (NumStorePurchases) has already occurred.

\n

Hence, it will crash.\nIf the correlation is suspiciously high, you must drop that Mnt... feature. It is giving the model a shortcut which we don't want.\nI have tried my best to make you understand. If you still have any doubt then please leave a comment.

\n", "answer_id": 677069, "answer_text": "RMSE = 3.82e-13\n=> Model is getting a perfect score.\n=> Red Flag\n\n\n\n\nYou put Store is the data.\nTotal Purchases = Store + Web + Catalog\n=> OLS Regressor didn't bother to learn about the customer behavior.\nIt is actually solving an eqn : Store = Total Purchases - Web - Catalog\n\n\n\n\nDo a quick check on features like MntWines or MntMeatProducts.\nMake sure those totals don't accidentally contain the physical store purchase counts we are trying to predict.\n\n\n\n\nIf We are trying to predict NumStorePurchases (Let's say, how many times a man visited the physical store).\n\n\n\n\nThe danger is that features like MntWines (Total dollars spent on wine) or MntMeatProducts(Total dollars spent on meat) might be acting like a Wines or Meat bought from this physical store receipt.\nThen the machine will cheat saying \"He bought wines from this physical store, therefore he went to the physical store.\"\n\n\n\n\nAll I am saying is If MntWines includes physical store purchases, we have to drop it. It gives away the answer.\nBut Why am I saying this? Let's say we want to predict the human behavior.\n\nIf you put this model into the real world to predict what customers will do tomorrow, it will crash.\n\n\n\n\nWhy? Because tomorrow hasn't happened yet. You don't have tomorrow's meat receipts. You only have MntMeatProducts after the target (NumStorePurchases) has already occurred.\n\n\n\n\nHence, it will crash.\nIf the correlation is suspiciously high, you must drop that Mnt... feature. It is giving the model a shortcut which we don't want.\nI have tried my best to make you understand. If you still have any doubt then please leave a comment.", "answer_url": "https://stats.stackexchange.com/a/677069", "author": "Soudipta Dutta", "author_url": "https://stats.stackexchange.com/users/207636/soudipta-dutta", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-04T12:10:41+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677033, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Soudipta Dutta", "profile_url": "https://stats.stackexchange.com/users/207636/soudipta-dutta", "user_type": "registered"}, "created_at": "2026-09-04T12:10:41+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "8E0BAE17-D514-43DD-8915-7D6D1D11997B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8E0BAE17-D514-43DD-8915-7D6D1D11997B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Soudipta Dutta", "profile_url": "https://stats.stackexchange.com/users/207636/soudipta-dutta", "user_type": "registered"}, "created_at": "2026-09-04T12:17:06+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "3ED08E0D-FFB4-4E46-AB7E-8287BD20CF14", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3ED08E0D-FFB4-4E46-AB7E-8287BD20CF14/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Soudipta Dutta", "profile_url": "https://stats.stackexchange.com/users/207636/soudipta-dutta", "user_type": "registered"}, "created_at": "2026-09-08T09:35:00+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "EADD6F80-51D8-488C-90A1-B951DAE79867", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EADD6F80-51D8-488C-90A1-B951DAE79867/view-source"}], "score": 1, "updated_at": "2026-09-08T09:35:00+00:00"}], "product": "statistics_qa", "question": "I am doing a project to understand the predictive viability of different regressors on the dependent variable(NumStorePurchases). In the feature space, we have a feature called Total Purchases- Sum of (NumStorePurchases,WebPurchases,CatalogPurchases) along with other variables Income, Kidhome, Teenhome, Recency, MntWines, MntFruits, MntMeatProducts, MntFishProducts, MntSweetProducts, MntGoldProds, NumDealsPurchases, NumWebPurchases, NumCatalogPurchases, NumStorePurchases, NumWebVisitsMonth, AcceptedCmp3, AcceptedCmp4, AcceptedCmp5, AcceptedCmp1, AcceptedCmp2, Response, Complain, Country. When we are doing an OLS regression by splitting out test-train data by 70-30% & finding out RMSE(Root Mean Squared Error), value is a minuscule number-3.8200863988425333e-13.\nSo, I am little bit skeptical with this number, although according to my understanding Multicollinearity do not impact predictive viability of a model, it's just impact the significance of each regressors.\n\n\n\n\nIs it somehow impacting the model predictive accuracy or maybe some other factors like data leakage can reduce the RMSE as well due to the presence of Y on X(Feature space) itself or maybe this small RMSE value can be possible?\n\n\n\n\nLooking for your reply community members.\n\n\n\n\nThanks.", "record_id": "Scientific-Statistics-QA:stats:677033", "selected_answer": {"answer_html": "

Welcome to CV. It's not clear why you think there is multicollinearity. That is a relation among independent variables and has nothing to do with the DV. You've only listed one IV. However, collinearity does not affect prediction very much.

\n

One problem is surely what @RickHass said: Your IV contains your DV. You are then asking "can we predict number of store purchases from number of store purchases".

\n

One way around this is to take out "Num store purchases" from the feature set.

\n

You may have other problems as well. Purchasing data is often highly skewed, and, while regression does not require normal data, it does assume normal error, and that may be violated. You might want to take logs.

\n

However, if all the numbers of purchases are small (as might be the case for 'big ticket' items) then you might consider a count model.

\n

I'd consider hiring a statistician.

\n", "answer_id": 677034, "answer_text": "Welcome to CV. It's not clear why you think there is multicollinearity. That is a relation among independent variables and has nothing to do with the DV. You've only listed one IV. However, collinearity does not affect prediction very much.\n\n\n\n\nOne problem is surely what @RickHass said: Your IV contains your DV. You are then asking \"can we predict number of store purchases from number of store purchases\".\n\n\n\n\nOne way around this is to take out \"Num store purchases\" from the feature set.\n\n\n\n\nYou may have other problems as well. Purchasing data is often highly skewed, and, while regression does not require normal data, it does assume normal error, and that may be violated. You might want to take logs.\n\n\n\n\nHowever, if all the numbers of purchases are small (as might be the case for 'big ticket' items) then you might consider a count model.\n\n\n\n\nI'd consider hiring a statistician.", "answer_url": "https://stats.stackexchange.com/a/677034", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T11:41:58+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": 677033, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-09-01T11:41:58+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "D7BDB0E7-7A8C-438F-84B8-BD6B7817B150", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D7BDB0E7-7A8C-438F-84B8-BD6B7817B150/view-source"}], "score": 3, "updated_at": "2026-09-01T11:41:58+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Welcome to CV. It's not clear why you think there is multicollinearity. That is a relation among independent variables and has nothing to do with the DV. You've only listed one IV. However, collinearity does not affect prediction very much.

\n

One problem is surely what @RickHass said: Your IV contains your DV. You are then asking "can we predict number of store purchases from number of store purchases".

\n

One way around this is to take out "Num store purchases" from the feature set.

\n

You may have other problems as well. Purchasing data is often highly skewed, and, while regression does not require normal data, it does assume normal error, and that may be violated. You might want to take logs.

\n

However, if all the numbers of purchases are small (as might be the case for 'big ticket' items) then you might consider a count model.

\n

I'd consider hiring a statistician.

\n", "answer_id": 677034, "answer_text": "Welcome to CV. It's not clear why you think there is multicollinearity. That is a relation among independent variables and has nothing to do with the DV. You've only listed one IV. However, collinearity does not affect prediction very much.\n\n\n\n\nOne problem is surely what @RickHass said: Your IV contains your DV. You are then asking \"can we predict number of store purchases from number of store purchases\".\n\n\n\n\nOne way around this is to take out \"Num store purchases\" from the feature set.\n\n\n\n\nYou may have other problems as well. Purchasing data is often highly skewed, and, while regression does not require normal data, it does assume normal error, and that may be violated. You might want to take logs.\n\n\n\n\nHowever, if all the numbers of purchases are small (as might be the case for 'big ticket' items) then you might consider a count model.\n\n\n\n\nI'd consider hiring a statistician.", "answer_url": "https://stats.stackexchange.com/a/677034", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-01T11:41:58+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": 677033, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-09-01T11:41:58+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "D7BDB0E7-7A8C-438F-84B8-BD6B7817B150", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D7BDB0E7-7A8C-438F-84B8-BD6B7817B150/view-source"}], "score": 3, "updated_at": "2026-09-01T11:41:58+00:00"}, {"answer_html": "

RMSE = 3.82e-13\n=> Model is getting a perfect score.\n=> Red Flag

\n

You put Store is the data.\nTotal Purchases = Store + Web + Catalog\n=> OLS Regressor didn't bother to learn about the customer behavior.\nIt is actually solving an eqn : Store = Total Purchases - Web - Catalog

\n

Do a quick check on features like MntWines or MntMeatProducts.\nMake sure those totals don't accidentally contain the physical store purchase counts we are trying to predict.

\n

If We are trying to predict NumStorePurchases (Let's say, how many times a man visited the physical store).

\n

The danger is that features like MntWines (Total dollars spent on wine) or MntMeatProducts(Total dollars spent on meat) might be acting like a Wines or Meat bought from this physical store receipt.\nThen the machine will cheat saying "He bought wines from this physical store, therefore he went to the physical store."

\n

All I am saying is If MntWines includes physical store purchases, we have to drop it. It gives away the answer.\nBut Why am I saying this? Let's say we want to predict the human behavior.
\nIf you put this model into the real world to predict what customers will do tomorrow, it will crash.

\n

Why? Because tomorrow hasn't happened yet. You don't have tomorrow's meat receipts. You only have MntMeatProducts after the target (NumStorePurchases) has already occurred.

\n

Hence, it will crash.\nIf the correlation is suspiciously high, you must drop that Mnt... feature. It is giving the model a shortcut which we don't want.\nI have tried my best to make you understand. If you still have any doubt then please leave a comment.

\n", "answer_id": 677069, "answer_text": "RMSE = 3.82e-13\n=> Model is getting a perfect score.\n=> Red Flag\n\n\n\n\nYou put Store is the data.\nTotal Purchases = Store + Web + Catalog\n=> OLS Regressor didn't bother to learn about the customer behavior.\nIt is actually solving an eqn : Store = Total Purchases - Web - Catalog\n\n\n\n\nDo a quick check on features like MntWines or MntMeatProducts.\nMake sure those totals don't accidentally contain the physical store purchase counts we are trying to predict.\n\n\n\n\nIf We are trying to predict NumStorePurchases (Let's say, how many times a man visited the physical store).\n\n\n\n\nThe danger is that features like MntWines (Total dollars spent on wine) or MntMeatProducts(Total dollars spent on meat) might be acting like a Wines or Meat bought from this physical store receipt.\nThen the machine will cheat saying \"He bought wines from this physical store, therefore he went to the physical store.\"\n\n\n\n\nAll I am saying is If MntWines includes physical store purchases, we have to drop it. It gives away the answer.\nBut Why am I saying this? Let's say we want to predict the human behavior.\n\nIf you put this model into the real world to predict what customers will do tomorrow, it will crash.\n\n\n\n\nWhy? Because tomorrow hasn't happened yet. You don't have tomorrow's meat receipts. You only have MntMeatProducts after the target (NumStorePurchases) has already occurred.\n\n\n\n\nHence, it will crash.\nIf the correlation is suspiciously high, you must drop that Mnt... feature. It is giving the model a shortcut which we don't want.\nI have tried my best to make you understand. If you still have any doubt then please leave a comment.", "answer_url": "https://stats.stackexchange.com/a/677069", "author": "Soudipta Dutta", "author_url": "https://stats.stackexchange.com/users/207636/soudipta-dutta", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-04T12:10:41+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677033, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Soudipta Dutta", "profile_url": "https://stats.stackexchange.com/users/207636/soudipta-dutta", "user_type": "registered"}, "created_at": "2026-09-04T12:10:41+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "8E0BAE17-D514-43DD-8915-7D6D1D11997B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8E0BAE17-D514-43DD-8915-7D6D1D11997B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Soudipta Dutta", "profile_url": "https://stats.stackexchange.com/users/207636/soudipta-dutta", "user_type": "registered"}, "created_at": "2026-09-04T12:17:06+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "3ED08E0D-FFB4-4E46-AB7E-8287BD20CF14", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3ED08E0D-FFB4-4E46-AB7E-8287BD20CF14/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Soudipta Dutta", "profile_url": "https://stats.stackexchange.com/users/207636/soudipta-dutta", "user_type": "registered"}, "created_at": "2026-09-08T09:35:00+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "EADD6F80-51D8-488C-90A1-B951DAE79867", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EADD6F80-51D8-488C-90A1-B951DAE79867/view-source"}], "score": 1, "updated_at": "2026-09-08T09:35:00+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Abir Kar", "question_author_url": "https://stats.stackexchange.com/users/510955/abir-kar", "question_author_user_type": "registered", "question_created_at": "2026-09-01T09:40:16+00:00", "question_html": "

I am doing a project to understand the predictive viability of different regressors on the dependent variable(NumStorePurchases). In the feature space, we have a feature called Total Purchases- Sum of (NumStorePurchases,WebPurchases,CatalogPurchases) along with other variables Income, Kidhome, Teenhome, Recency, MntWines, MntFruits, MntMeatProducts, MntFishProducts, MntSweetProducts, MntGoldProds, NumDealsPurchases, NumWebPurchases, NumCatalogPurchases, NumStorePurchases, NumWebVisitsMonth, AcceptedCmp3, AcceptedCmp4, AcceptedCmp5, AcceptedCmp1, AcceptedCmp2, Response, Complain, Country. When we are doing an OLS regression by splitting out test-train data by 70-30% & finding out RMSE(Root Mean Squared Error), value is a minuscule number-3.8200863988425333e-13.\nSo, I am little bit skeptical with this number, although according to my understanding Multicollinearity do not impact predictive viability of a model, it's just impact the significance of each regressors.

\n

Is it somehow impacting the model predictive accuracy or maybe some other factors like data leakage can reduce the RMSE as well due to the presence of Y on X(Feature space) itself or maybe this small RMSE value can be possible?

\n

Looking for your reply community members.

\n

Thanks.

\n", "question_id": 677033, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I am doing a project to understand the predictive viability of different regressors on the dependent variable(NumStorePurchases). In the feature space, we have a feature called Total Purchases- Sum of (NumStorePurchases,WebPurchases,CatalogPurchases) along with other variables Income, Kidhome, Teenhome, Recency, MntWines, MntFruits, MntMeatProducts, MntFishProducts, MntSweetProducts, MntGoldProds, NumDealsPurchases, NumWebPurchases, NumCatalogPurchases, NumStorePurchases, NumWebVisitsMonth, AcceptedCmp3, AcceptedCmp4, AcceptedCmp5, AcceptedCmp1, AcceptedCmp2, Response, Complain, Country. When we are doing an OLS regression by splitting out test-train data by 70-30% & finding out RMSE(Root Mean Squared Error), value is a minuscule number-3.8200863988425333e-13.\nSo, I am little bit skeptical with this number, although according to my understanding Multicollinearity do not impact predictive viability of a model, it's just impact the significance of each regressors.\n\n\n\n\nIs it somehow impacting the model predictive accuracy or maybe some other factors like data leakage can reduce the RMSE as well due to the presence of Y on X(Feature space) itself or maybe this small RMSE value can be possible?\n\n\n\n\nLooking for your reply community members.\n\n\n\n\nThanks.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Abir Kar", "profile_url": "https://stats.stackexchange.com/users/510955/abir-kar", "user_type": "registered"}, "created_at": "2026-09-01T09:40:16+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "B8FA9293-7F0F-46F6-96CD-BA3F1590F973", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B8FA9293-7F0F-46F6-96CD-BA3F1590F973/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Abir Kar", "profile_url": "https://stats.stackexchange.com/users/510955/abir-kar", "user_type": "registered"}, "created_at": "2026-09-03T17:20:40+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "8EF25545-061A-4014-BC66-7C810301BD57", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8EF25545-061A-4014-BC66-7C810301BD57/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677033/is-removing-multicollinear-variable-necessary-to-get-a-proper-predictive-analysi", "split": "train", "split_group": "5ef7d0b2c8d8e20f5752a48c7b260f89d5ebe8ba17b51ba46fc94a6e041cd728", "tags": ["regression", "machine-learning", "python", "least-squares", "multicollinearity"], "thread_id": "stats:677033", "title": "Is removing multicollinear variable necessary to get a proper predictive analysis of RMSE(Root Mean Squared Error) of OLS regression in test data?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I want to find out the following: given a Beta distribution, for the same sample size $n$, are certain combination of $a,b$ harder to estimate than others?\n\n\n\n\nI designed the following simulation in R involving the Beta distribution.\n\n\n\n\n\nDefine a grid of $(a, b, n)$ where $a$ goes from 0.3 to 5 in steps of 0.15, $b$ goes from 0.3 to 5 in steps of 0.15, and $n$ takes values in $\\{5, 10, 15, 20, 25, 30, 50, 75, 100\\}$\n\n\n\n\nFor each $(a, b, n)$ in the grid:\n\n\n\nCompute the true mean and true variance of Beta$(a, b)$\n\n\n\n\nSimulate 100 datasets, each a sample of size $n$ from Beta$(a, b)$\n\n\n\n\nFor each dataset:\n\n\n\nEstimate $\\hat a$ and $\\hat b$ by maximum likelihood\n\n\n\n\nCompute the estimated mean and estimated variance from $\\hat a, \\hat b$\n\n\n\n\nRecord the absolute percentage error of $\\hat a$, $\\hat b$, the mean, and the variance against their true values\n\n\n\n\n\n\n\n\nAverage each of the four errors over the 100 datasets\n\n\n\n\n\n\n\n\nReturn the averaged errors for every $(a, b, n)$ cell\n\n\n\n\n\nHere are the results - I used two different plotting axis: (true a, true b) and (true mean, true variance), resulting in 8 plots:\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/A2PFO7A8.png] (https://i.sstatic.net/A2PFO7A8.png)\n[image: enter image description here; source: https://i.sstatic.net/iy79u8j8.png] (https://i.sstatic.net/iy79u8j8.png)\n[image: enter image description here; source: https://i.sstatic.net/GP2Hj45Q.png] (https://i.sstatic.net/GP2Hj45Q.png)\n[image: enter image description here; source: https://i.sstatic.net/FyuH512V.png] (https://i.sstatic.net/FyuH512V.png)\n[image: enter image description here; source: https://i.sstatic.net/t7tu9Uyf.png] (https://i.sstatic.net/t7tu9Uyf.png)\n[image: enter image description here; source: https://i.sstatic.net/Oe6sxe18.png] (https://i.sstatic.net/Oe6sxe18.png)\n[image: enter image description here; source: https://i.sstatic.net/JED0Ev2C.png] (https://i.sstatic.net/JED0Ev2C.png)\n[image: enter image description here; source: https://i.sstatic.net/fzJdboR6.png] (https://i.sstatic.net/fzJdboR6.png)\n\n\n\n\nSome general findings:\n\n\n\n\n\nIn general, $n$ increase, estimation error decreases\n\n\n\n\nIn general, there seems to be less error in estimates of $a$ compared to $b$\n\n\n\n\nIn general, there seems to be less error in the estimates of mean compared to variance\n\n\n\n\nWhen the true $a$ is small and true $b$ is large, there is less estimation error in the mean\n\n\n\n\nFor some reason, it seems that estimates for $a$ and $b$ have less error than the estimates for mean and variance (even though the estimates for mean and variance rely on the estimates of $a$ and $b$ )\n\n\n\n\nWhen the true mean and true variance are both small, there is larger estimation error in the mean\n\n\n\n\nWhen true mean is small and true variance is large, or when true mean is small and true variance is large - estimation error in variance is higher\n\n\n\n\nWhen true $a$ is large and true $b$ is small or wen true $a$ is small and true $b$ is large, there seems to be more error when estimating the variance\n\n\n\n\n\nIs there any way to come to these conclusions without simulation? For example, can you derive the Fisher Information, theoretically analyze the surface of the likelihood and see which regions within the parameter space are more challenging to estimate? Or is it simply not worth it and better to use simulation?", "record_id": "Scientific-Statistics-QA:stats:677041", "selected_answer": {"answer_html": "

The thing to look up to analyse things like this is the Delta method.\nSimply put it states that functions of asymptotically normal estimators are themselves asymptotically normal and gives you a method for computing the limiting variance.

\n

One application is in the computation of the absolute percentage error.\nFor example, given a $\\sqrt{n}$-consistent estimator $\\hat{\\theta}$ of some parameter $\\theta$, we can use the Delta method to conclude from\n$$\n\\sqrt{n}(\\hat{\\theta} - \\theta)\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, \\sigma^2)\n$$\nthat\n$$\n\\sqrt{n}\\Bigl(\\frac{\\hat{\\theta}}{\\theta} - 1\\Bigr) \n\\stackrel{\\mathrm{d}}{\\rightarrow}N\\Bigl(0, \\frac{\\sigma^2}{\\theta^2}\\Bigr),\n$$\nand so that the mean absolute percentage error satisfies, for $Z\\sim N(0, 1)$ a standard Gaussian,\n$$\n\\mathbf{E}\\biggl|\\frac{\\hat{\\theta}}{\\theta} - 1\\biggr|\n\\approx \\frac{\\sigma}{\\theta \\sqrt{n}} \\mathbf{E}|Z|\n=\\frac{\\sigma}{\\theta \\sqrt{n}} \\sqrt{\\frac{2}{\\pi}}.\n$$

\n

That is, analysis of the mean absolute percentage error reduced back to analysis of the limiting variance $\\sigma^2$.

\n

But now, this is where the Fisher information is useful, since we have\n$$\n\\sqrt{n}((\\hat{a}, \\hat{b}) - (a, b))\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, I(a, b)^{-1}),\n$$\nwhere $I(a, b)$ is the Fisher information matrix of $(a, b)$.\nAn application of the Delta method thus allows us to compute the limiting behaviour of functions like the plug-in estimator of the sample mean;\nif $\\mu(a, b) = a/(a+b)$, we get\n$$\n\\sqrt{n}\\biggl(\\frac{\\hat{a}}{\\hat{a} + \\hat{b}} - \\frac{a}{a + b}\\biggr)\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, \\nabla \\mu(a, b)^T I(a, b)^{-1} \\nabla \\mu(a, b)),\n$$\nso the limiting variance in terms of the Fisher information is\n$$\n\\nabla \\mu(a, b)^T I(a, b)^{-1} \\nabla \\mu(a, b))\n= \\frac{1}{(a+b)^4} (b, -a) I(a, b)^{-1} \\begin{pmatrix} b \\\\ -a \\end{pmatrix},\n$$\nfrom which the mean absolute percentage error is approximately\n$$\n\\sqrt{\\frac{2}{n\\pi}}\\frac{\\sqrt{(b, -a) I(a, b)^{-1} \\begin{pmatrix} b \\\\ -a \\end{pmatrix}}}{a(a+b)}.\n$$

\n

Now, unfortunately the Beta distribution is a pretty bad example of this because its Fisher information is defined in terms of the trigamma function $\\psi'$, which is the derivative of the logarithm of the Gamma function - a complicated object.\nNevertheless, it can be computed in your favourite mathematical computing package, and should produce plots similar to those you found empirically, as shown here (with $n=1$, because larger $n$ values simply scale the whole plot by a constant):\n\"Heatmap

\n

The analysis of the plug-in variance estimator is similar, but more complicated due to the beta variance's more complex form.

\n", "answer_id": 677063, "answer_text": "The thing to look up to analyse things like this is the Delta method.\nSimply put it states that functions of asymptotically normal estimators are themselves asymptotically normal and gives you a method for computing the limiting variance.\n\n\n\n\nOne application is in the computation of the absolute percentage error.\nFor example, given a $\\sqrt{n}$-consistent estimator $\\hat{\\theta}$ of some parameter $\\theta$, we can use the Delta method to conclude from\n$$\n\\sqrt{n}(\\hat{\\theta} - \\theta)\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, \\sigma^2)\n$$\nthat\n$$\n\\sqrt{n}\\Bigl(\\frac{\\hat{\\theta}}{\\theta} - 1\\Bigr) \n\\stackrel{\\mathrm{d}}{\\rightarrow}N\\Bigl(0, \\frac{\\sigma^2}{\\theta^2}\\Bigr),\n$$\nand so that the mean absolute percentage error satisfies, for $Z\\sim N(0, 1)$ a standard Gaussian,\n$$\n\\mathbf{E}\\biggl|\\frac{\\hat{\\theta}}{\\theta} - 1\\biggr|\n\\approx \\frac{\\sigma}{\\theta \\sqrt{n}} \\mathbf{E}|Z|\n=\\frac{\\sigma}{\\theta \\sqrt{n}} \\sqrt{\\frac{2}{\\pi}}.\n$$\n\n\n\n\nThat is, analysis of the mean absolute percentage error reduced back to analysis of the limiting variance $\\sigma^2$.\n\n\n\n\nBut now, this is where the Fisher information is useful, since we have\n$$\n\\sqrt{n}((\\hat{a}, \\hat{b}) - (a, b))\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, I(a, b)^{-1}),\n$$\nwhere $I(a, b)$ is the Fisher information matrix of $(a, b)$.\nAn application of the Delta method thus allows us to compute the limiting behaviour of functions like the plug-in estimator of the sample mean;\nif $\\mu(a, b) = a/(a+b)$, we get\n$$\n\\sqrt{n}\\biggl(\\frac{\\hat{a}}{\\hat{a} + \\hat{b}} - \\frac{a}{a + b}\\biggr)\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, \\nabla \\mu(a, b)^T I(a, b)^{-1} \\nabla \\mu(a, b)),\n$$\nso the limiting variance in terms of the Fisher information is\n$$\n\\nabla \\mu(a, b)^T I(a, b)^{-1} \\nabla \\mu(a, b))\n= \\frac{1}{(a+b)^4} (b, -a) I(a, b)^{-1} \\begin{pmatrix} b \\\\ -a \\end{pmatrix},\n$$\nfrom which the mean absolute percentage error is approximately\n$$\n\\sqrt{\\frac{2}{n\\pi}}\\frac{\\sqrt{(b, -a) I(a, b)^{-1} \\begin{pmatrix} b \\\\ -a \\end{pmatrix}}}{a(a+b)}.\n$$\n\n\n\n\nNow, unfortunately the Beta distribution is a pretty bad example of this because its Fisher information is defined in terms of the trigamma function $\\psi'$, which is the derivative of the logarithm of the Gamma function - a complicated object.\nNevertheless, it can be computed in your favourite mathematical computing package, and should produce plots similar to those you found empirically, as shown here (with $n=1$, because larger $n$ values simply scale the whole plot by a constant):\n[image: Heatmap of limiting mean absolute percentage error of Beta mean estimate; source: https://i.sstatic.net/IvoRdhWk.png] (https://i.sstatic.net/IvoRdhWk.png)\n\n\n\n\nThe analysis of the plug-in variance estimator is similar, but more complicated due to the beta variance's more complex form.", "answer_url": "https://stats.stackexchange.com/a/677063", "author": "Damian Pavlyshyn", "author_url": "https://stats.stackexchange.com/users/335519/damian-pavlyshyn", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-03T18:06:57+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": 677041, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Damian Pavlyshyn", "profile_url": "https://stats.stackexchange.com/users/335519/damian-pavlyshyn", "user_type": "registered"}, "created_at": "2026-09-03T18:06:57+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "19FA051A-A616-4367-89EC-93E374CA68E9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/19FA051A-A616-4367-89EC-93E374CA68E9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Damian Pavlyshyn", "profile_url": "https://stats.stackexchange.com/users/335519/damian-pavlyshyn", "user_type": "registered"}, "created_at": "2026-09-03T18:18:11+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "1D27285B-1AD4-409A-9022-40E4AA3FCF9A", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1D27285B-1AD4-409A-9022-40E4AA3FCF9A/view-source"}], "score": 1, "updated_at": "2026-09-03T18:18:11+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

The thing to look up to analyse things like this is the Delta method.\nSimply put it states that functions of asymptotically normal estimators are themselves asymptotically normal and gives you a method for computing the limiting variance.

\n

One application is in the computation of the absolute percentage error.\nFor example, given a $\\sqrt{n}$-consistent estimator $\\hat{\\theta}$ of some parameter $\\theta$, we can use the Delta method to conclude from\n$$\n\\sqrt{n}(\\hat{\\theta} - \\theta)\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, \\sigma^2)\n$$\nthat\n$$\n\\sqrt{n}\\Bigl(\\frac{\\hat{\\theta}}{\\theta} - 1\\Bigr) \n\\stackrel{\\mathrm{d}}{\\rightarrow}N\\Bigl(0, \\frac{\\sigma^2}{\\theta^2}\\Bigr),\n$$\nand so that the mean absolute percentage error satisfies, for $Z\\sim N(0, 1)$ a standard Gaussian,\n$$\n\\mathbf{E}\\biggl|\\frac{\\hat{\\theta}}{\\theta} - 1\\biggr|\n\\approx \\frac{\\sigma}{\\theta \\sqrt{n}} \\mathbf{E}|Z|\n=\\frac{\\sigma}{\\theta \\sqrt{n}} \\sqrt{\\frac{2}{\\pi}}.\n$$

\n

That is, analysis of the mean absolute percentage error reduced back to analysis of the limiting variance $\\sigma^2$.

\n

But now, this is where the Fisher information is useful, since we have\n$$\n\\sqrt{n}((\\hat{a}, \\hat{b}) - (a, b))\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, I(a, b)^{-1}),\n$$\nwhere $I(a, b)$ is the Fisher information matrix of $(a, b)$.\nAn application of the Delta method thus allows us to compute the limiting behaviour of functions like the plug-in estimator of the sample mean;\nif $\\mu(a, b) = a/(a+b)$, we get\n$$\n\\sqrt{n}\\biggl(\\frac{\\hat{a}}{\\hat{a} + \\hat{b}} - \\frac{a}{a + b}\\biggr)\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, \\nabla \\mu(a, b)^T I(a, b)^{-1} \\nabla \\mu(a, b)),\n$$\nso the limiting variance in terms of the Fisher information is\n$$\n\\nabla \\mu(a, b)^T I(a, b)^{-1} \\nabla \\mu(a, b))\n= \\frac{1}{(a+b)^4} (b, -a) I(a, b)^{-1} \\begin{pmatrix} b \\\\ -a \\end{pmatrix},\n$$\nfrom which the mean absolute percentage error is approximately\n$$\n\\sqrt{\\frac{2}{n\\pi}}\\frac{\\sqrt{(b, -a) I(a, b)^{-1} \\begin{pmatrix} b \\\\ -a \\end{pmatrix}}}{a(a+b)}.\n$$

\n

Now, unfortunately the Beta distribution is a pretty bad example of this because its Fisher information is defined in terms of the trigamma function $\\psi'$, which is the derivative of the logarithm of the Gamma function - a complicated object.\nNevertheless, it can be computed in your favourite mathematical computing package, and should produce plots similar to those you found empirically, as shown here (with $n=1$, because larger $n$ values simply scale the whole plot by a constant):\n\"Heatmap

\n

The analysis of the plug-in variance estimator is similar, but more complicated due to the beta variance's more complex form.

\n", "answer_id": 677063, "answer_text": "The thing to look up to analyse things like this is the Delta method.\nSimply put it states that functions of asymptotically normal estimators are themselves asymptotically normal and gives you a method for computing the limiting variance.\n\n\n\n\nOne application is in the computation of the absolute percentage error.\nFor example, given a $\\sqrt{n}$-consistent estimator $\\hat{\\theta}$ of some parameter $\\theta$, we can use the Delta method to conclude from\n$$\n\\sqrt{n}(\\hat{\\theta} - \\theta)\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, \\sigma^2)\n$$\nthat\n$$\n\\sqrt{n}\\Bigl(\\frac{\\hat{\\theta}}{\\theta} - 1\\Bigr) \n\\stackrel{\\mathrm{d}}{\\rightarrow}N\\Bigl(0, \\frac{\\sigma^2}{\\theta^2}\\Bigr),\n$$\nand so that the mean absolute percentage error satisfies, for $Z\\sim N(0, 1)$ a standard Gaussian,\n$$\n\\mathbf{E}\\biggl|\\frac{\\hat{\\theta}}{\\theta} - 1\\biggr|\n\\approx \\frac{\\sigma}{\\theta \\sqrt{n}} \\mathbf{E}|Z|\n=\\frac{\\sigma}{\\theta \\sqrt{n}} \\sqrt{\\frac{2}{\\pi}}.\n$$\n\n\n\n\nThat is, analysis of the mean absolute percentage error reduced back to analysis of the limiting variance $\\sigma^2$.\n\n\n\n\nBut now, this is where the Fisher information is useful, since we have\n$$\n\\sqrt{n}((\\hat{a}, \\hat{b}) - (a, b))\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, I(a, b)^{-1}),\n$$\nwhere $I(a, b)$ is the Fisher information matrix of $(a, b)$.\nAn application of the Delta method thus allows us to compute the limiting behaviour of functions like the plug-in estimator of the sample mean;\nif $\\mu(a, b) = a/(a+b)$, we get\n$$\n\\sqrt{n}\\biggl(\\frac{\\hat{a}}{\\hat{a} + \\hat{b}} - \\frac{a}{a + b}\\biggr)\n\\stackrel{\\mathrm{d}}{\\rightarrow} N(0, \\nabla \\mu(a, b)^T I(a, b)^{-1} \\nabla \\mu(a, b)),\n$$\nso the limiting variance in terms of the Fisher information is\n$$\n\\nabla \\mu(a, b)^T I(a, b)^{-1} \\nabla \\mu(a, b))\n= \\frac{1}{(a+b)^4} (b, -a) I(a, b)^{-1} \\begin{pmatrix} b \\\\ -a \\end{pmatrix},\n$$\nfrom which the mean absolute percentage error is approximately\n$$\n\\sqrt{\\frac{2}{n\\pi}}\\frac{\\sqrt{(b, -a) I(a, b)^{-1} \\begin{pmatrix} b \\\\ -a \\end{pmatrix}}}{a(a+b)}.\n$$\n\n\n\n\nNow, unfortunately the Beta distribution is a pretty bad example of this because its Fisher information is defined in terms of the trigamma function $\\psi'$, which is the derivative of the logarithm of the Gamma function - a complicated object.\nNevertheless, it can be computed in your favourite mathematical computing package, and should produce plots similar to those you found empirically, as shown here (with $n=1$, because larger $n$ values simply scale the whole plot by a constant):\n[image: Heatmap of limiting mean absolute percentage error of Beta mean estimate; source: https://i.sstatic.net/IvoRdhWk.png] (https://i.sstatic.net/IvoRdhWk.png)\n\n\n\n\nThe analysis of the plug-in variance estimator is similar, but more complicated due to the beta variance's more complex form.", "answer_url": "https://stats.stackexchange.com/a/677063", "author": "Damian Pavlyshyn", "author_url": "https://stats.stackexchange.com/users/335519/damian-pavlyshyn", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-03T18:06:57+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": 677041, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Damian Pavlyshyn", "profile_url": "https://stats.stackexchange.com/users/335519/damian-pavlyshyn", "user_type": "registered"}, "created_at": "2026-09-03T18:06:57+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "19FA051A-A616-4367-89EC-93E374CA68E9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/19FA051A-A616-4367-89EC-93E374CA68E9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Damian Pavlyshyn", "profile_url": "https://stats.stackexchange.com/users/335519/damian-pavlyshyn", "user_type": "registered"}, "created_at": "2026-09-03T18:18:11+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "1D27285B-1AD4-409A-9022-40E4AA3FCF9A", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1D27285B-1AD4-409A-9022-40E4AA3FCF9A/view-source"}], "score": 1, "updated_at": "2026-09-03T18:18:11+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/A2PFO7A8.png", "https://i.sstatic.net/FyuH512V.png", "https://i.sstatic.net/GP2Hj45Q.png", "https://i.sstatic.net/IvoRdhWk.png", "https://i.sstatic.net/JED0Ev2C.png", "https://i.sstatic.net/Oe6sxe18.png", "https://i.sstatic.net/fzJdboR6.png", "https://i.sstatic.net/iy79u8j8.png", "https://i.sstatic.net/t7tu9Uyf.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "adamkostanov", "question_author_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "question_author_user_type": "registered", "question_created_at": "2026-09-01T20:39:17+00:00", "question_html": "

I want to find out the following: given a Beta distribution, for the same sample size $n$, are certain combination of $a,b$ harder to estimate than others?

\n

I designed the following simulation in R involving the Beta distribution.

\n\n

Here are the results - I used two different plotting axis: (true a, true b) and (true mean, true variance), resulting in 8 plots:

\n

\"enter\n\"enter\n\"enter\n\"enter\n\"enter\n\"enter\n\"enter\n\"enter

\n

Some general findings:

\n\n

Is there any way to come to these conclusions without simulation? For example, can you derive the Fisher Information, theoretically analyze the surface of the likelihood and see which regions within the parameter space are more challenging to estimate? Or is it simply not worth it and better to use simulation?

\n", "question_id": 677041, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "I want to find out the following: given a Beta distribution, for the same sample size $n$, are certain combination of $a,b$ harder to estimate than others?\n\n\n\n\nI designed the following simulation in R involving the Beta distribution.\n\n\n\n\n\nDefine a grid of $(a, b, n)$ where $a$ goes from 0.3 to 5 in steps of 0.15, $b$ goes from 0.3 to 5 in steps of 0.15, and $n$ takes values in $\\{5, 10, 15, 20, 25, 30, 50, 75, 100\\}$\n\n\n\n\nFor each $(a, b, n)$ in the grid:\n\n\n\nCompute the true mean and true variance of Beta$(a, b)$\n\n\n\n\nSimulate 100 datasets, each a sample of size $n$ from Beta$(a, b)$\n\n\n\n\nFor each dataset:\n\n\n\nEstimate $\\hat a$ and $\\hat b$ by maximum likelihood\n\n\n\n\nCompute the estimated mean and estimated variance from $\\hat a, \\hat b$\n\n\n\n\nRecord the absolute percentage error of $\\hat a$, $\\hat b$, the mean, and the variance against their true values\n\n\n\n\n\n\n\n\nAverage each of the four errors over the 100 datasets\n\n\n\n\n\n\n\n\nReturn the averaged errors for every $(a, b, n)$ cell\n\n\n\n\n\nHere are the results - I used two different plotting axis: (true a, true b) and (true mean, true variance), resulting in 8 plots:\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/A2PFO7A8.png] (https://i.sstatic.net/A2PFO7A8.png)\n[image: enter image description here; source: https://i.sstatic.net/iy79u8j8.png] (https://i.sstatic.net/iy79u8j8.png)\n[image: enter image description here; source: https://i.sstatic.net/GP2Hj45Q.png] (https://i.sstatic.net/GP2Hj45Q.png)\n[image: enter image description here; source: https://i.sstatic.net/FyuH512V.png] (https://i.sstatic.net/FyuH512V.png)\n[image: enter image description here; source: https://i.sstatic.net/t7tu9Uyf.png] (https://i.sstatic.net/t7tu9Uyf.png)\n[image: enter image description here; source: https://i.sstatic.net/Oe6sxe18.png] (https://i.sstatic.net/Oe6sxe18.png)\n[image: enter image description here; source: https://i.sstatic.net/JED0Ev2C.png] (https://i.sstatic.net/JED0Ev2C.png)\n[image: enter image description here; source: https://i.sstatic.net/fzJdboR6.png] (https://i.sstatic.net/fzJdboR6.png)\n\n\n\n\nSome general findings:\n\n\n\n\n\nIn general, $n$ increase, estimation error decreases\n\n\n\n\nIn general, there seems to be less error in estimates of $a$ compared to $b$\n\n\n\n\nIn general, there seems to be less error in the estimates of mean compared to variance\n\n\n\n\nWhen the true $a$ is small and true $b$ is large, there is less estimation error in the mean\n\n\n\n\nFor some reason, it seems that estimates for $a$ and $b$ have less error than the estimates for mean and variance (even though the estimates for mean and variance rely on the estimates of $a$ and $b$ )\n\n\n\n\nWhen the true mean and true variance are both small, there is larger estimation error in the mean\n\n\n\n\nWhen true mean is small and true variance is large, or when true mean is small and true variance is large - estimation error in variance is higher\n\n\n\n\nWhen true $a$ is large and true $b$ is small or wen true $a$ is small and true $b$ is large, there seems to be more error when estimating the variance\n\n\n\n\n\nIs there any way to come to these conclusions without simulation? For example, can you derive the Fisher Information, theoretically analyze the surface of the likelihood and see which regions within the parameter space are more challenging to estimate? Or is it simply not worth it and better to use simulation?", "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-01T20:39:17+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "2D229546-DD72-4D89-9A44-EBF731EEC454", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2D229546-DD72-4D89-9A44-EBF731EEC454/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-01T21:05:16+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "362CE01E-5DCD-4DCC-B183-9624FDC32676", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/362CE01E-5DCD-4DCC-B183-9624FDC32676/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-03T13:55:34+00:00", "raw_file": "raw/codex_api_v1/84bb317e707465a80f008019404ef1f770e152d74ef692d3b81c48903ec855cc_1790825232001984700_0.json", "raw_sha256": "75778d86d5325e15f4b491a748dc70ae6ac6ee98840d584e01ed28416cb71fbe", "revision_guid": "6E132F5C-EEFB-43B1-94EC-C25EB4C9F6FA", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6E132F5C-EEFB-43B1-94EC-C25EB4C9F6FA/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677041/determining-which-areas-of-a-likelihood-surface-are-harder-to-estimate", "split": "train", "split_group": "980272d8e40c67b44a155e755b4f534a959338373dfb5be1185d4391d068480c", "tags": ["r", "maximum-likelihood", "simulation"], "thread_id": "stats:677041", "title": "Determining which areas of a likelihood surface are harder to estimate"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "Suppose\n\n\n\n\n$$ y = g_\\theta(X_1,X_2,...,X_n) + \\varepsilon $$\n\n\n\n\nwhere $X$s are extremely weak predictors and estimation of $\\theta$s are dominated by error. Luckily we have other predictors\n\n\n\n\n$$ y = f_\\varphi(Z_1,Z_2,...,Z_m) + \\zeta $$\n\n\n\n\nwhere $Z$s are very strong, but unfortunately not causal. We can assume $f$ to be linear function if that will help.\n\n\n\n\nMy aim is to estimate $g_\\theta$ better. We can use $Z$s to reduce the estimation error. If we are lucky we can handpick $Z$s that are orthogonal to $X$s (better independent but a stricter requirement), then\n\n\n\n\n$$ y = g_\\theta(X_1,X_2,...,X_n) + f_\\varphi(Z_1,Z_2,...,Z_m) + \\gamma $$\n\n\n\n\nis a standard machine learning procedure, and in practice works pretty well as we get much stricter bounds on $\\theta$s.\n\n\n\n\nHowever I wish to have more freedom and include $Zs$ that are also weakly correlated to $Xs$. At this point estimation becomes not so identifiable as strong $Zs$ dominate $Xs$. Orthogonalization doesn't seem to help due to two issues: 1) $Xs$ are also very weakly predictable for $Zs$ 2) $Z$s overfit and don't leave much for $X$s.\n\n\n\n\nThis is not an estimation procedure I am familiar with as there are conflicting objectives. I checked the literature and couldn't find a de facto solution. Looking for ideas.", "record_id": "Scientific-Statistics-QA:stats:677045", "selected_answer": {"answer_html": "

I don't think this is possible. Consider the simplest possible case, where $g_\\theta(X_1)=\\alpha+\\theta X_1$ and $f_\\psi(Z_1)=\\psi Z_1$, and the combined procedure is to estimate

\n

$$E[Y|X,Z]=\\tilde\\alpha+\\tilde\\theta X_1+\\tilde\\psi Z_1$$\nIf $Z_1$ and $X_1$ are orthogonal then $\\tilde\\theta=\\theta$ so you estimate the same quantity with less error. But if $Z_1$ and $X_1$ are not orthogonal,\n$$\\theta=\\tilde\\theta+\\tilde\\psi E[X_1|Z_1]$$\nand we know the model with just $X_1$ gives an asymptotically efficient estimator of $\\theta$.

\n

Pre-asymptotically, $\\tilde\\theta$ is only better if $\\tilde\\psi E[X_1|Z_1]$ is small compared to the standard error of $\\hat\\theta$, which has to stop being true in large enough samples and is not reliably testable.

\n

If you know $f_\\psi$ is non-linear you don't get exact non-identifiability but also it isn't enough that $Z$ and $X$ are orthogonal: you need the true $g$ and $f$ to be orthogonal and I'm not sure how you would know that without knowing they were independent.

\n", "answer_id": 677055, "answer_text": "I don't think this is possible. Consider the simplest possible case, where $g_\\theta(X_1)=\\alpha+\\theta X_1$ and $f_\\psi(Z_1)=\\psi Z_1$, and the combined procedure is to estimate\n\n\n\n\n$$E[Y|X,Z]=\\tilde\\alpha+\\tilde\\theta X_1+\\tilde\\psi Z_1$$\nIf $Z_1$ and $X_1$ are orthogonal then $\\tilde\\theta=\\theta$ so you estimate the same quantity with less error. But if $Z_1$ and $X_1$ are not orthogonal,\n$$\\theta=\\tilde\\theta+\\tilde\\psi E[X_1|Z_1]$$\nand we know the model with just $X_1$ gives an asymptotically efficient estimator of $\\theta$.\n\n\n\n\nPre-asymptotically, $\\tilde\\theta$ is only better if $\\tilde\\psi E[X_1|Z_1]$ is small compared to the standard error of $\\hat\\theta$, which has to stop being true in large enough samples and is not reliably testable.\n\n\n\n\nIf you know $f_\\psi$ is non-linear you don't get exact non-identifiability but also it isn't enough that $Z$ and $X$ are orthogonal: you need the true $g$ and $f$ to be orthogonal and I'm not sure how you would know that without knowing they were independent.", "answer_url": "https://stats.stackexchange.com/a/677055", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-03T08:43:33+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": 677045, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-09-03T08:43:33+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "F957F022-161F-478B-BBDB-56D484D42954", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F957F022-161F-478B-BBDB-56D484D42954/view-source"}], "score": 3, "updated_at": "2026-09-03T08:43:33+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

I don't think this is possible. Consider the simplest possible case, where $g_\\theta(X_1)=\\alpha+\\theta X_1$ and $f_\\psi(Z_1)=\\psi Z_1$, and the combined procedure is to estimate

\n

$$E[Y|X,Z]=\\tilde\\alpha+\\tilde\\theta X_1+\\tilde\\psi Z_1$$\nIf $Z_1$ and $X_1$ are orthogonal then $\\tilde\\theta=\\theta$ so you estimate the same quantity with less error. But if $Z_1$ and $X_1$ are not orthogonal,\n$$\\theta=\\tilde\\theta+\\tilde\\psi E[X_1|Z_1]$$\nand we know the model with just $X_1$ gives an asymptotically efficient estimator of $\\theta$.

\n

Pre-asymptotically, $\\tilde\\theta$ is only better if $\\tilde\\psi E[X_1|Z_1]$ is small compared to the standard error of $\\hat\\theta$, which has to stop being true in large enough samples and is not reliably testable.

\n

If you know $f_\\psi$ is non-linear you don't get exact non-identifiability but also it isn't enough that $Z$ and $X$ are orthogonal: you need the true $g$ and $f$ to be orthogonal and I'm not sure how you would know that without knowing they were independent.

\n", "answer_id": 677055, "answer_text": "I don't think this is possible. Consider the simplest possible case, where $g_\\theta(X_1)=\\alpha+\\theta X_1$ and $f_\\psi(Z_1)=\\psi Z_1$, and the combined procedure is to estimate\n\n\n\n\n$$E[Y|X,Z]=\\tilde\\alpha+\\tilde\\theta X_1+\\tilde\\psi Z_1$$\nIf $Z_1$ and $X_1$ are orthogonal then $\\tilde\\theta=\\theta$ so you estimate the same quantity with less error. But if $Z_1$ and $X_1$ are not orthogonal,\n$$\\theta=\\tilde\\theta+\\tilde\\psi E[X_1|Z_1]$$\nand we know the model with just $X_1$ gives an asymptotically efficient estimator of $\\theta$.\n\n\n\n\nPre-asymptotically, $\\tilde\\theta$ is only better if $\\tilde\\psi E[X_1|Z_1]$ is small compared to the standard error of $\\hat\\theta$, which has to stop being true in large enough samples and is not reliably testable.\n\n\n\n\nIf you know $f_\\psi$ is non-linear you don't get exact non-identifiability but also it isn't enough that $Z$ and $X$ are orthogonal: you need the true $g$ and $f$ to be orthogonal and I'm not sure how you would know that without knowing they were independent.", "answer_url": "https://stats.stackexchange.com/a/677055", "author": "Thomas Lumley", "author_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-03T08:43:33+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": 677045, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Lumley", "profile_url": "https://stats.stackexchange.com/users/249135/thomas-lumley", "user_type": "registered"}, "created_at": "2026-09-03T08:43:33+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "F957F022-161F-478B-BBDB-56D484D42954", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F957F022-161F-478B-BBDB-56D484D42954/view-source"}], "score": 3, "updated_at": "2026-09-03T08:43:33+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Cagdas Ozgenc", "question_author_url": "https://stats.stackexchange.com/users/20980/cagdas-ozgenc", "question_author_user_type": "registered", "question_created_at": "2026-09-02T10:41:26+00:00", "question_html": "

Suppose

\n

$$ y = g_\\theta(X_1,X_2,...,X_n) + \\varepsilon $$

\n

where $X$s are extremely weak predictors and estimation of $\\theta$s are dominated by error. Luckily we have other predictors

\n

$$ y = f_\\varphi(Z_1,Z_2,...,Z_m) + \\zeta $$

\n

where $Z$s are very strong, but unfortunately not causal. We can assume $f$ to be linear function if that will help.

\n

My aim is to estimate $g_\\theta$ better. We can use $Z$s to reduce the estimation error. If we are lucky we can handpick $Z$s that are orthogonal to $X$s (better independent but a stricter requirement), then

\n

$$ y = g_\\theta(X_1,X_2,...,X_n) + f_\\varphi(Z_1,Z_2,...,Z_m) + \\gamma $$

\n

is a standard machine learning procedure, and in practice works pretty well as we get much stricter bounds on $\\theta$s.

\n

However I wish to have more freedom and include $Zs$ that are also weakly correlated to $Xs$. At this point estimation becomes not so identifiable as strong $Zs$ dominate $Xs$. Orthogonalization doesn't seem to help due to two issues: 1) $Xs$ are also very weakly predictable for $Zs$ 2) $Z$s overfit and don't leave much for $X$s.

\n

This is not an estimation procedure I am familiar with as there are conflicting objectives. I checked the literature and couldn't find a de facto solution. Looking for ideas.

\n", "question_id": 677045, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "Suppose\n\n\n\n\n$$ y = g_\\theta(X_1,X_2,...,X_n) + \\varepsilon $$\n\n\n\n\nwhere $X$s are extremely weak predictors and estimation of $\\theta$s are dominated by error. Luckily we have other predictors\n\n\n\n\n$$ y = f_\\varphi(Z_1,Z_2,...,Z_m) + \\zeta $$\n\n\n\n\nwhere $Z$s are very strong, but unfortunately not causal. We can assume $f$ to be linear function if that will help.\n\n\n\n\nMy aim is to estimate $g_\\theta$ better. We can use $Z$s to reduce the estimation error. If we are lucky we can handpick $Z$s that are orthogonal to $X$s (better independent but a stricter requirement), then\n\n\n\n\n$$ y = g_\\theta(X_1,X_2,...,X_n) + f_\\varphi(Z_1,Z_2,...,Z_m) + \\gamma $$\n\n\n\n\nis a standard machine learning procedure, and in practice works pretty well as we get much stricter bounds on $\\theta$s.\n\n\n\n\nHowever I wish to have more freedom and include $Zs$ that are also weakly correlated to $Xs$. At this point estimation becomes not so identifiable as strong $Zs$ dominate $Xs$. Orthogonalization doesn't seem to help due to two issues: 1) $Xs$ are also very weakly predictable for $Zs$ 2) $Z$s overfit and don't leave much for $X$s.\n\n\n\n\nThis is not an estimation procedure I am familiar with as there are conflicting objectives. I checked the literature and couldn't find a de facto solution. Looking for ideas.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Cagdas Ozgenc", "profile_url": "https://stats.stackexchange.com/users/20980/cagdas-ozgenc", "user_type": "registered"}, "created_at": "2026-09-02T10:41:26+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "28160610-BC0B-485C-9C92-FF309CD674ED", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/28160610-BC0B-485C-9C92-FF309CD674ED/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael Hardy", "profile_url": "https://stats.stackexchange.com/users/5176/michael-hardy", "user_type": "registered"}, "created_at": "2026-09-03T02:18:11+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "64475924-A048-4763-8D38-CDCBF7CB1FFE", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/64475924-A048-4763-8D38-CDCBF7CB1FFE/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Cagdas Ozgenc", "profile_url": "https://stats.stackexchange.com/users/20980/cagdas-ozgenc", "user_type": "registered"}, "created_at": "2026-09-03T12:57:10+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "22664194-0CEB-4D35-8ABF-AC2ECDEFA181", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/22664194-0CEB-4D35-8ABF-AC2ECDEFA181/view-source"}, {"content_license": null, "contributor": {"display_name": "Cagdas Ozgenc", "profile_url": "https://stats.stackexchange.com/users/20980/cagdas-ozgenc", "user_type": "registered"}, "created_at": "2026-09-04T12:05:20+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "4F09351B-1055-4BC8-91C0-F7991C5D72CD", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4F09351B-1055-4BC8-91C0-F7991C5D72CD/view-source"}, {"content_license": null, "contributor": {"display_name": "Cagdas Ozgenc", "profile_url": "https://stats.stackexchange.com/users/20980/cagdas-ozgenc", "user_type": "registered"}, "created_at": "2026-09-04T12:05:20+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "D47D49D9-4D57-4591-8DF3-79E97C6459A5", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/D47D49D9-4D57-4591-8DF3-79E97C6459A5/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://stats.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2026-09-12T13:10:30+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "228FEC28-EC27-4EFA-B0DE-50840ACB86C3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/228FEC28-EC27-4EFA-B0DE-50840ACB86C3/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://stats.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2026-09-12T13:10:30+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "E6BB1695-A3C8-4955-8FA7-9F2196BE45C3", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/E6BB1695-A3C8-4955-8FA7-9F2196BE45C3/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677045/estimation-with-weak-predictors", "split": "train", "split_group": "ad206078ccfa013176aacdc82db79879b57b5a9a1de229fe8cda7e765ccc1be4", "tags": ["estimation"], "thread_id": "stats:677045", "title": "Estimation with weak predictors"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "While trying the gap statistics for K-Means to determine the number of clusters in the Iris dataset, I have noticed that the results are random. I have tried the following:\n\n\n\n\nlibrary(cluster)\nN <- 20\nfor (n in 1:N) {\n res <- clusGap(iris[,-5], function(x, k){kmeans(x,k,nstart=50)}, K.max=6, B=500, verbose=F, d.power=2)\n gs[n] <- maxSE(res$Tab[,\"gap\"],res$Tab[,\"SE.sim\"], method=\"Tibs2001SEmax\")\n}\ntable(gs)\n\n\n\n\n\nNote that I have increased the number of initial random configurations (nstart) in kmeans() to 50 in order to remove the randomness from the clustering and I have set d.power=2 as recommended in the documentation of clusGap(). I turns out that the results are quite random and that the true number of clusters is never found:\n\n\n\n\ngs\n 4 5 \n10 10\n\n\n\n\n\nIs this a well-known behavior of the gap statistics? What can be recommended instead that has a less random behavior?", "record_id": "Scientific-Statistics-QA:stats:677058", "selected_answer": {"answer_html": "

The gap statistic will indeed be the more stable the larger you choose nstart and the larger you choose B, but you seem to be aware of this, and the values you chose don't seem critically low.

\n

Other potential issues: Note that kmeans implicitly looks for clusters that are spherical and have the same within-cluster variation. This is not the case for the true groups in the Iris dataset. I'd indeed think that if you want to cluster this dataset into clusters according to the implicit kmeans assumptions, you'll do better with 4 or 5 clusters than with 3 or 2. It may go ever higher up when raising K.max. This explains why the "true" number of clusters is not found, but it doesn't explain the instability. However, the gap decision between 4 and 5 may be very ambiguous so that small changes in the random B datasets generated by the "parametric bootstrap" that gap uses may easily change the decision between 4 and 5. You could check this looking at the detailed output of several runs, checking how tight the decision between 4 and 5 actually is according to the "Tib2001SEmax" criterion.

\n

Also the function maxSE has implemented 5 different methods for deciding the number of clusters from the clusGap output. "Tib2001SEmax" is the one proposed in the original paper. The reason why there are four criteria offered on top of it is probably that a number of people (myself included) have found that "Tib2001SEmax" has issues in certain situations. The possibility of instability may be there for all five criteria, but personally I prefer "globalSEmax" and SE.factor=2, the latter at least when being worried more about overfitting than about putting together clusters that are not quite as homogeneous as you'd get when sticking more rigorously to "spherical and same within-cluster variation".

\n

At the end of the day kmeans is just not that good a clustering method for the Iris data when aiming at recovering the given groups. A Gaussian mixture with more flexible within-cluster covariance structure will do better.

\n", "answer_id": 677059, "answer_text": "The gap statistic will indeed be the more stable the larger you choose nstart and the larger you choose B, but you seem to be aware of this, and the values you chose don't seem critically low.\n\n\n\n\nOther potential issues: Note that kmeans implicitly looks for clusters that are spherical and have the same within-cluster variation. This is not the case for the true groups in the Iris dataset. I'd indeed think that if you want to cluster this dataset into clusters according to the implicit kmeans assumptions, you'll do better with 4 or 5 clusters than with 3 or 2. It may go ever higher up when raising K.max. This explains why the \"true\" number of clusters is not found, but it doesn't explain the instability. However, the gap decision between 4 and 5 may be very ambiguous so that small changes in the random B datasets generated by the \"parametric bootstrap\" that gap uses may easily change the decision between 4 and 5. You could check this looking at the detailed output of several runs, checking how tight the decision between 4 and 5 actually is according to the \"Tib2001SEmax\" criterion.\n\n\n\n\nAlso the function maxSE has implemented 5 different methods for deciding the number of clusters from the clusGap output. \"Tib2001SEmax\" is the one proposed in the original paper. The reason why there are four criteria offered on top of it is probably that a number of people (myself included) have found that \"Tib2001SEmax\" has issues in certain situations. The possibility of instability may be there for all five criteria, but personally I prefer \"globalSEmax\" and SE.factor=2, the latter at least when being worried more about overfitting than about putting together clusters that are not quite as homogeneous as you'd get when sticking more rigorously to \"spherical and same within-cluster variation\".\n\n\n\n\nAt the end of the day kmeans is just not that good a clustering method for the Iris data when aiming at recovering the given groups. A Gaussian mixture with more flexible within-cluster covariance structure will do better.", "answer_url": "https://stats.stackexchange.com/a/677059", "author": "Christian Hennig", "author_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-03T12:08:52+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": 677058, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-03T12:08:52+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "14E907BD-0137-4FA2-93E2-A5C3763E1F24", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/14E907BD-0137-4FA2-93E2-A5C3763E1F24/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-03T12:19:59+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "892FF292-2C1A-4474-9F3F-50E0D978AB75", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/892FF292-2C1A-4474-9F3F-50E0D978AB75/view-source"}], "score": 5, "updated_at": "2026-09-03T12:19:59+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

The gap statistic will indeed be the more stable the larger you choose nstart and the larger you choose B, but you seem to be aware of this, and the values you chose don't seem critically low.

\n

Other potential issues: Note that kmeans implicitly looks for clusters that are spherical and have the same within-cluster variation. This is not the case for the true groups in the Iris dataset. I'd indeed think that if you want to cluster this dataset into clusters according to the implicit kmeans assumptions, you'll do better with 4 or 5 clusters than with 3 or 2. It may go ever higher up when raising K.max. This explains why the "true" number of clusters is not found, but it doesn't explain the instability. However, the gap decision between 4 and 5 may be very ambiguous so that small changes in the random B datasets generated by the "parametric bootstrap" that gap uses may easily change the decision between 4 and 5. You could check this looking at the detailed output of several runs, checking how tight the decision between 4 and 5 actually is according to the "Tib2001SEmax" criterion.

\n

Also the function maxSE has implemented 5 different methods for deciding the number of clusters from the clusGap output. "Tib2001SEmax" is the one proposed in the original paper. The reason why there are four criteria offered on top of it is probably that a number of people (myself included) have found that "Tib2001SEmax" has issues in certain situations. The possibility of instability may be there for all five criteria, but personally I prefer "globalSEmax" and SE.factor=2, the latter at least when being worried more about overfitting than about putting together clusters that are not quite as homogeneous as you'd get when sticking more rigorously to "spherical and same within-cluster variation".

\n

At the end of the day kmeans is just not that good a clustering method for the Iris data when aiming at recovering the given groups. A Gaussian mixture with more flexible within-cluster covariance structure will do better.

\n", "answer_id": 677059, "answer_text": "The gap statistic will indeed be the more stable the larger you choose nstart and the larger you choose B, but you seem to be aware of this, and the values you chose don't seem critically low.\n\n\n\n\nOther potential issues: Note that kmeans implicitly looks for clusters that are spherical and have the same within-cluster variation. This is not the case for the true groups in the Iris dataset. I'd indeed think that if you want to cluster this dataset into clusters according to the implicit kmeans assumptions, you'll do better with 4 or 5 clusters than with 3 or 2. It may go ever higher up when raising K.max. This explains why the \"true\" number of clusters is not found, but it doesn't explain the instability. However, the gap decision between 4 and 5 may be very ambiguous so that small changes in the random B datasets generated by the \"parametric bootstrap\" that gap uses may easily change the decision between 4 and 5. You could check this looking at the detailed output of several runs, checking how tight the decision between 4 and 5 actually is according to the \"Tib2001SEmax\" criterion.\n\n\n\n\nAlso the function maxSE has implemented 5 different methods for deciding the number of clusters from the clusGap output. \"Tib2001SEmax\" is the one proposed in the original paper. The reason why there are four criteria offered on top of it is probably that a number of people (myself included) have found that \"Tib2001SEmax\" has issues in certain situations. The possibility of instability may be there for all five criteria, but personally I prefer \"globalSEmax\" and SE.factor=2, the latter at least when being worried more about overfitting than about putting together clusters that are not quite as homogeneous as you'd get when sticking more rigorously to \"spherical and same within-cluster variation\".\n\n\n\n\nAt the end of the day kmeans is just not that good a clustering method for the Iris data when aiming at recovering the given groups. A Gaussian mixture with more flexible within-cluster covariance structure will do better.", "answer_url": "https://stats.stackexchange.com/a/677059", "author": "Christian Hennig", "author_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-03T12:08:52+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": 677058, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-03T12:08:52+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "14E907BD-0137-4FA2-93E2-A5C3763E1F24", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/14E907BD-0137-4FA2-93E2-A5C3763E1F24/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-03T12:19:59+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "892FF292-2C1A-4474-9F3F-50E0D978AB75", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/892FF292-2C1A-4474-9F3F-50E0D978AB75/view-source"}], "score": 5, "updated_at": "2026-09-03T12:19:59+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "cdalitz", "question_author_url": "https://stats.stackexchange.com/users/244807/cdalitz", "question_author_user_type": "registered", "question_created_at": "2026-09-03T11:39:13+00:00", "question_html": "

While trying the gap statistics for K-Means to determine the number of clusters in the Iris dataset, I have noticed that the results are random. I have tried the following:

\n
library(cluster)\nN <- 20\nfor (n in 1:N) {\n  res <- clusGap(iris[,-5], function(x, k){kmeans(x,k,nstart=50)}, K.max=6, B=500, verbose=F, d.power=2)\n  gs[n] <- maxSE(res$Tab[,"gap"],res$Tab[,"SE.sim"], method="Tibs2001SEmax")\n}\ntable(gs)\n
\n

Note that I have increased the number of initial random configurations (nstart) in kmeans() to 50 in order to remove the randomness from the clustering and I have set d.power=2 as recommended in the documentation of clusGap(). I turns out that the results are quite random and that the true number of clusters is never found:

\n
gs\n 4  5 \n10 10\n
\n

Is this a well-known behavior of the gap statistics? What can be recommended instead that has a less random behavior?

\n", "question_id": 677058, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "While trying the gap statistics for K-Means to determine the number of clusters in the Iris dataset, I have noticed that the results are random. I have tried the following:\n\n\n\n\nlibrary(cluster)\nN <- 20\nfor (n in 1:N) {\n res <- clusGap(iris[,-5], function(x, k){kmeans(x,k,nstart=50)}, K.max=6, B=500, verbose=F, d.power=2)\n gs[n] <- maxSE(res$Tab[,\"gap\"],res$Tab[,\"SE.sim\"], method=\"Tibs2001SEmax\")\n}\ntable(gs)\n\n\n\n\n\nNote that I have increased the number of initial random configurations (nstart) in kmeans() to 50 in order to remove the randomness from the clustering and I have set d.power=2 as recommended in the documentation of clusGap(). I turns out that the results are quite random and that the true number of clusters is never found:\n\n\n\n\ngs\n 4 5 \n10 10\n\n\n\n\n\nIs this a well-known behavior of the gap statistics? What can be recommended instead that has a less random behavior?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "cdalitz", "profile_url": "https://stats.stackexchange.com/users/244807/cdalitz", "user_type": "registered"}, "created_at": "2026-09-03T11:39:13+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "3E9F6246-CC0F-4366-81BC-A6A0C78ED5A6", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3E9F6246-CC0F-4366-81BC-A6A0C78ED5A6/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-09-03T16:10:42+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "59954FB6-BFDE-42B7-830F-F7F99AFF9B21", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/59954FB6-BFDE-42B7-830F-F7F99AFF9B21/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-03T19:42:12+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "BF52DD34-5A10-4522-BC49-DDE61AD72E0C", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/BF52DD34-5A10-4522-BC49-DDE61AD72E0C/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677058/instability-of-gap-statistics", "split": "train", "split_group": "9571fdd41c91a5063c5d50dd6546728a0beeeb9ea033a144996338e69417909e", "tags": ["clustering"], "thread_id": "stats:677058", "title": "Instability of gap statistics"}} +{"accepted_answer": {"answer_html": "

The AI-generated code manually slices {DHARMa}'s internal arrays, which is fragile. The cleaner approach would be to use recalculateResiduals() with NA for the other season's rows, letting DHARMa's NA handling drop them during grouping:

\n
library(mgcv)\nlibrary(DHARMa)\nlibrary(dplyr)\n\nshiny_toad <- read.csv("https://raw.githubusercontent.com/NateLaS/Toadfish/main/share_version%20-%20toadfish.csv") |>\n  mutate(\n    fSeason = factor(Season),\n    fSite   = factor(Site),\n    Date    = as.Date(Date)\n  )\n
\n
fit <- gam(total_count ~\n             s(CYR, by = fSeason) +\n             fSeason +\n             s(fSite, bs = "re"),\n           data   = shiny_toad,\n           method = "REML",\n           family = nb(link = "log"))\n\nres <- simulateResiduals(fit)\n\nused_idx <- as.integer(rownames(fit$model))\n\nfor (season in levels(shiny_toad$fSeason)) {\n  cat("--- Temporal Autocorrelation Test for Season:", season, "---\\n")\n  \n  idx       <- shiny_toad$fSeason[used_idx] == season\n  group_vec <- ifelse(idx, shiny_toad$CYR[used_idx], NA)\n  \n  res_grouped <- recalculateResiduals(res, group = group_vec)\n  \n  testTemporalAutocorrelation(res_grouped,\n                              time = unique(sort(shiny_toad$CYR[used_idx][idx])),\n                              plot = TRUE)\n  title(paste("Season:", season))\n}\n\n#> --- Temporal Autocorrelation Test for Season: DRY ---\n
\n

\"\"

\n
#> --- Temporal Autocorrelation Test for Season: WET ---\n
\n

\"\"

\n

This is essentially the same as what you got from your code, but without manual slicing and whatnot. The wet season shows significant temporal autocorrelation (Durbin-Watson p = 0.005) with an alternating high/low pattern in the residuals, suggesting the model is over- and under-predicting in alternating years. The dry season shows no significant autocorrelation (p = 0.41). But, you should note that the DRY season has no observations in 2021, so the test treats 2022 as immediately following 2020 and would not detect autocorrelation if there is any across that gap.

\n

For general advice, take a look at these posts (tbh, I'm reaching the end of my rope on this topic):

\n
    \n
  1. How to account for temporal autocorrelation in logistic regression with longitudinal data?

    \n
  2. \n
  3. R: How to test for, or visualize, autocorrelation in irregularly spaced count data?

    \n
  4. \n
\n

Created on 2026-09-03 with reprex v2.1.1

\n", "answer_id": 677064, "answer_text": "The AI-generated code manually slices {DHARMa}'s internal arrays, which is fragile. The cleaner approach would be to use recalculateResiduals() with NA for the other season's rows, letting DHARMa's NA handling drop them during grouping:\n\n\n\n\nlibrary(mgcv)\nlibrary(DHARMa)\nlibrary(dplyr)\n\nshiny_toad <- read.csv(\"https://raw.githubusercontent.com/NateLaS/Toadfish/main/share_version%20-%20toadfish.csv\") |>\n mutate(\n fSeason = factor(Season),\n fSite = factor(Site),\n Date = as.Date(Date)\n )\n\n\n\n\n\nfit <- gam(total_count ~\n s(CYR, by = fSeason) +\n fSeason +\n s(fSite, bs = \"re\"),\n data = shiny_toad,\n method = \"REML\",\n family = nb(link = \"log\"))\n\nres <- simulateResiduals(fit)\n\nused_idx <- as.integer(rownames(fit$model))\n\nfor (season in levels(shiny_toad$fSeason)) {\n cat(\"--- Temporal Autocorrelation Test for Season:\", season, \"---\\n\")\n \n idx <- shiny_toad$fSeason[used_idx] == season\n group_vec <- ifelse(idx, shiny_toad$CYR[used_idx], NA)\n \n res_grouped <- recalculateResiduals(res, group = group_vec)\n \n testTemporalAutocorrelation(res_grouped,\n time = unique(sort(shiny_toad$CYR[used_idx][idx])),\n plot = TRUE)\n title(paste(\"Season:\", season))\n}\n\n#> --- Temporal Autocorrelation Test for Season: DRY ---\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/6r3XH8BM.png]\n\n\n\n\n#> --- Temporal Autocorrelation Test for Season: WET ---\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/LfmXWxdr.png]\n\n\n\n\nThis is essentially the same as what you got from your code, but without manual slicing and whatnot. The wet season shows significant temporal autocorrelation (Durbin-Watson p = 0.005) with an alternating high/low pattern in the residuals, suggesting the model is over- and under-predicting in alternating years. The dry season shows no significant autocorrelation (p = 0.41). But, you should note that the DRY season has no observations in 2021, so the test treats 2022 as immediately following 2020 and would not detect autocorrelation if there is any across that gap.\n\n\n\n\nFor general advice, take a look at these posts (tbh, I'm reaching the end of my rope on this topic):\n\n\n\n\n\n\n\nHow to account for temporal autocorrelation in logistic regression with longitudinal data? (https://stats.stackexchange.com/q/395445)\n\n\n\n\n\n\n\n\n\nR: How to test for, or visualize, autocorrelation in irregularly spaced count data? (https://stats.stackexchange.com/q/664160)\n\n\n\n\n\n\n\n\nCreated on 2026-09-03 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/677064", "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-09-04T03:00:41+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": 677062, "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-09-04T03:00:41+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "33E2BC86-F580-4F03-B6B5-57A2E864905B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/33E2BC86-F580-4F03-B6B5-57A2E864905B/view-source"}], "score": 2, "updated_at": "2026-09-04T03:00:41+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "I have 2 time series in abundance that I'm modeling by a 2-level factor in mgcv , by \"fSeason\" (wet/dry), and following advice here (https://stackoverflow.com/questions/78182559/autocorrelation-in-gam-r), I should be splitting a test for auto-correlation by each factor level. I'm just not sure how to do that. Apologies for posting ChatGPT code, but I've been unsuccessful in my search everywhere else. DHARMa does have a test, but I was told it's only for a single time series. I don't think I can use the traditional AR(1) as the data are irregularly-spaced and I've never taken Bayesian statistics. Anyway, for now I'm just asking if the code AI generated is correctly identifying that I do have some, albeit weak, but significant temporal auto-correlation in the wet season. Any general advice is also welcome!\n\n\n\n\nData here (https://github.com/NateLaS/Toadfish/blob/main/share_version%20-%20toadfish.csv).\n\n\n\n\nlibrary(mgcv)\nlibrary(gratia)\nlibrary(DHARMa)\n\nsystem.time(\n by <- gam(total_count ~ \n \n offset(log(area_sampled)) +\n \n s(CYR, by = fSeason) +\n fSeason + \n \n s(sal, bs=\"ts\", k=5) + \n s(DO, bs=\"ts\", k=5) +\n \n s(ave_sav, by = fDiet_presence) +\n fDiet_presence + \n \n s(fSite, bs=\"re\"),\n \n data = shiny_toad,\n method = \"REML\", \n family = nb(link = \"log\"),\n select = FALSE, \n \n drop.unused.levels = FALSE, \n control = list(trace = TRUE))\n)\n\n##################\n\ndf <- sort(diff(sort(as.Date(shiny_toad$Date))), decreasing = TRUE)\n\n# 1. Generate the base simulated residuals once\nres <- simulateResiduals(by)\n\n# 2. Loop through each Season safely by manually subsetting the DHARMa object\nfor (Season in unique(shiny_toad$fSeason)) {\n \n cat(\"\\n--- Temporal Autocorrelation Test for Season:\", Season, \"---\\n\")\n \n # Create a logical index for the current Season\n Season_idx <- shiny_toad$fSeason == Season\n \n # Copy the base DHARMa object structure\n res_Season <- res\n \n # Manually slice all internal arrays to match only this Season's rows\n res_Season$scaledResiduals <- res$scaledResiduals[Season_idx]\n res_Season$simulatedResponse <- res$simulatedResponse[Season_idx, , drop = FALSE]\n res_Season$observedResponse <- res$observedResponse[Season_idx]\n res_Season$fittedPredictedResponse <- res$fittedPredictedResponse[Season_idx]\n res_Season$nObs <- sum(Season_idx)\n \n # Group the Season's residuals by CYR\n res_grouped <- recalculateResiduals(res_Season, group = shiny_toad$CYR[Season_idx])\n \n # Open a new plot window so they don't overwrite each other\n dev.new() \n \n # Run the test and plot\n testTemporalAutocorrelation(res_grouped, time = unique(shiny_toad$CYR[Season_idx]))\n \n # Add a title to the plot window to identify the Season\n mtext(paste(\"Season:\", Season), side = 3, line = -2, outer = TRUE, font = 2, cex = 1.2)\n}\n\n\n\n\n\n\nSite locations were haphazardly chosen (before my time) to monitor changes in fish abundance due to the construction of new canals (data posted here not collected with this statistical model/set of hypotheses in mind - its just available). Timing of surveys is based on tide level (need at least 60 cm/2 ft of water to survey near shore during the day (during reg. working hours). It takes about 4-7 days to survey every site start-to-finish. Timing is also weather dependant. Also it takes 4-5 months to sort, ID, weigh and measure everything we catch. March/Sept is just avoid swimming in really cold water and give time between sample processesing of new data.\n\n\n\n\n[image: ChatGPT result; source: https://i.sstatic.net/XIgn1m2c.png]", "record_id": "Scientific-Statistics-QA:stats:677062", "selected_answer": {"answer_html": "

The AI-generated code manually slices {DHARMa}'s internal arrays, which is fragile. The cleaner approach would be to use recalculateResiduals() with NA for the other season's rows, letting DHARMa's NA handling drop them during grouping:

\n
library(mgcv)\nlibrary(DHARMa)\nlibrary(dplyr)\n\nshiny_toad <- read.csv("https://raw.githubusercontent.com/NateLaS/Toadfish/main/share_version%20-%20toadfish.csv") |>\n  mutate(\n    fSeason = factor(Season),\n    fSite   = factor(Site),\n    Date    = as.Date(Date)\n  )\n
\n
fit <- gam(total_count ~\n             s(CYR, by = fSeason) +\n             fSeason +\n             s(fSite, bs = "re"),\n           data   = shiny_toad,\n           method = "REML",\n           family = nb(link = "log"))\n\nres <- simulateResiduals(fit)\n\nused_idx <- as.integer(rownames(fit$model))\n\nfor (season in levels(shiny_toad$fSeason)) {\n  cat("--- Temporal Autocorrelation Test for Season:", season, "---\\n")\n  \n  idx       <- shiny_toad$fSeason[used_idx] == season\n  group_vec <- ifelse(idx, shiny_toad$CYR[used_idx], NA)\n  \n  res_grouped <- recalculateResiduals(res, group = group_vec)\n  \n  testTemporalAutocorrelation(res_grouped,\n                              time = unique(sort(shiny_toad$CYR[used_idx][idx])),\n                              plot = TRUE)\n  title(paste("Season:", season))\n}\n\n#> --- Temporal Autocorrelation Test for Season: DRY ---\n
\n

\"\"

\n
#> --- Temporal Autocorrelation Test for Season: WET ---\n
\n

\"\"

\n

This is essentially the same as what you got from your code, but without manual slicing and whatnot. The wet season shows significant temporal autocorrelation (Durbin-Watson p = 0.005) with an alternating high/low pattern in the residuals, suggesting the model is over- and under-predicting in alternating years. The dry season shows no significant autocorrelation (p = 0.41). But, you should note that the DRY season has no observations in 2021, so the test treats 2022 as immediately following 2020 and would not detect autocorrelation if there is any across that gap.

\n

For general advice, take a look at these posts (tbh, I'm reaching the end of my rope on this topic):

\n
    \n
  1. How to account for temporal autocorrelation in logistic regression with longitudinal data?

    \n
  2. \n
  3. R: How to test for, or visualize, autocorrelation in irregularly spaced count data?

    \n
  4. \n
\n

Created on 2026-09-03 with reprex v2.1.1

\n", "answer_id": 677064, "answer_text": "The AI-generated code manually slices {DHARMa}'s internal arrays, which is fragile. The cleaner approach would be to use recalculateResiduals() with NA for the other season's rows, letting DHARMa's NA handling drop them during grouping:\n\n\n\n\nlibrary(mgcv)\nlibrary(DHARMa)\nlibrary(dplyr)\n\nshiny_toad <- read.csv(\"https://raw.githubusercontent.com/NateLaS/Toadfish/main/share_version%20-%20toadfish.csv\") |>\n mutate(\n fSeason = factor(Season),\n fSite = factor(Site),\n Date = as.Date(Date)\n )\n\n\n\n\n\nfit <- gam(total_count ~\n s(CYR, by = fSeason) +\n fSeason +\n s(fSite, bs = \"re\"),\n data = shiny_toad,\n method = \"REML\",\n family = nb(link = \"log\"))\n\nres <- simulateResiduals(fit)\n\nused_idx <- as.integer(rownames(fit$model))\n\nfor (season in levels(shiny_toad$fSeason)) {\n cat(\"--- Temporal Autocorrelation Test for Season:\", season, \"---\\n\")\n \n idx <- shiny_toad$fSeason[used_idx] == season\n group_vec <- ifelse(idx, shiny_toad$CYR[used_idx], NA)\n \n res_grouped <- recalculateResiduals(res, group = group_vec)\n \n testTemporalAutocorrelation(res_grouped,\n time = unique(sort(shiny_toad$CYR[used_idx][idx])),\n plot = TRUE)\n title(paste(\"Season:\", season))\n}\n\n#> --- Temporal Autocorrelation Test for Season: DRY ---\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/6r3XH8BM.png]\n\n\n\n\n#> --- Temporal Autocorrelation Test for Season: WET ---\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/LfmXWxdr.png]\n\n\n\n\nThis is essentially the same as what you got from your code, but without manual slicing and whatnot. The wet season shows significant temporal autocorrelation (Durbin-Watson p = 0.005) with an alternating high/low pattern in the residuals, suggesting the model is over- and under-predicting in alternating years. The dry season shows no significant autocorrelation (p = 0.41). But, you should note that the DRY season has no observations in 2021, so the test treats 2022 as immediately following 2020 and would not detect autocorrelation if there is any across that gap.\n\n\n\n\nFor general advice, take a look at these posts (tbh, I'm reaching the end of my rope on this topic):\n\n\n\n\n\n\n\nHow to account for temporal autocorrelation in logistic regression with longitudinal data? (https://stats.stackexchange.com/q/395445)\n\n\n\n\n\n\n\n\n\nR: How to test for, or visualize, autocorrelation in irregularly spaced count data? (https://stats.stackexchange.com/q/664160)\n\n\n\n\n\n\n\n\nCreated on 2026-09-03 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/677064", "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-09-04T03:00:41+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": 677062, "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-09-04T03:00:41+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "33E2BC86-F580-4F03-B6B5-57A2E864905B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/33E2BC86-F580-4F03-B6B5-57A2E864905B/view-source"}], "score": 2, "updated_at": "2026-09-04T03:00:41+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677064, "answers": [{"answer_html": "

The AI-generated code manually slices {DHARMa}'s internal arrays, which is fragile. The cleaner approach would be to use recalculateResiduals() with NA for the other season's rows, letting DHARMa's NA handling drop them during grouping:

\n
library(mgcv)\nlibrary(DHARMa)\nlibrary(dplyr)\n\nshiny_toad <- read.csv("https://raw.githubusercontent.com/NateLaS/Toadfish/main/share_version%20-%20toadfish.csv") |>\n  mutate(\n    fSeason = factor(Season),\n    fSite   = factor(Site),\n    Date    = as.Date(Date)\n  )\n
\n
fit <- gam(total_count ~\n             s(CYR, by = fSeason) +\n             fSeason +\n             s(fSite, bs = "re"),\n           data   = shiny_toad,\n           method = "REML",\n           family = nb(link = "log"))\n\nres <- simulateResiduals(fit)\n\nused_idx <- as.integer(rownames(fit$model))\n\nfor (season in levels(shiny_toad$fSeason)) {\n  cat("--- Temporal Autocorrelation Test for Season:", season, "---\\n")\n  \n  idx       <- shiny_toad$fSeason[used_idx] == season\n  group_vec <- ifelse(idx, shiny_toad$CYR[used_idx], NA)\n  \n  res_grouped <- recalculateResiduals(res, group = group_vec)\n  \n  testTemporalAutocorrelation(res_grouped,\n                              time = unique(sort(shiny_toad$CYR[used_idx][idx])),\n                              plot = TRUE)\n  title(paste("Season:", season))\n}\n\n#> --- Temporal Autocorrelation Test for Season: DRY ---\n
\n

\"\"

\n
#> --- Temporal Autocorrelation Test for Season: WET ---\n
\n

\"\"

\n

This is essentially the same as what you got from your code, but without manual slicing and whatnot. The wet season shows significant temporal autocorrelation (Durbin-Watson p = 0.005) with an alternating high/low pattern in the residuals, suggesting the model is over- and under-predicting in alternating years. The dry season shows no significant autocorrelation (p = 0.41). But, you should note that the DRY season has no observations in 2021, so the test treats 2022 as immediately following 2020 and would not detect autocorrelation if there is any across that gap.

\n

For general advice, take a look at these posts (tbh, I'm reaching the end of my rope on this topic):

\n
    \n
  1. How to account for temporal autocorrelation in logistic regression with longitudinal data?

    \n
  2. \n
  3. R: How to test for, or visualize, autocorrelation in irregularly spaced count data?

    \n
  4. \n
\n

Created on 2026-09-03 with reprex v2.1.1

\n", "answer_id": 677064, "answer_text": "The AI-generated code manually slices {DHARMa}'s internal arrays, which is fragile. The cleaner approach would be to use recalculateResiduals() with NA for the other season's rows, letting DHARMa's NA handling drop them during grouping:\n\n\n\n\nlibrary(mgcv)\nlibrary(DHARMa)\nlibrary(dplyr)\n\nshiny_toad <- read.csv(\"https://raw.githubusercontent.com/NateLaS/Toadfish/main/share_version%20-%20toadfish.csv\") |>\n mutate(\n fSeason = factor(Season),\n fSite = factor(Site),\n Date = as.Date(Date)\n )\n\n\n\n\n\nfit <- gam(total_count ~\n s(CYR, by = fSeason) +\n fSeason +\n s(fSite, bs = \"re\"),\n data = shiny_toad,\n method = \"REML\",\n family = nb(link = \"log\"))\n\nres <- simulateResiduals(fit)\n\nused_idx <- as.integer(rownames(fit$model))\n\nfor (season in levels(shiny_toad$fSeason)) {\n cat(\"--- Temporal Autocorrelation Test for Season:\", season, \"---\\n\")\n \n idx <- shiny_toad$fSeason[used_idx] == season\n group_vec <- ifelse(idx, shiny_toad$CYR[used_idx], NA)\n \n res_grouped <- recalculateResiduals(res, group = group_vec)\n \n testTemporalAutocorrelation(res_grouped,\n time = unique(sort(shiny_toad$CYR[used_idx][idx])),\n plot = TRUE)\n title(paste(\"Season:\", season))\n}\n\n#> --- Temporal Autocorrelation Test for Season: DRY ---\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/6r3XH8BM.png]\n\n\n\n\n#> --- Temporal Autocorrelation Test for Season: WET ---\n\n\n\n\n\n[image: ; source: https://i.sstatic.net/LfmXWxdr.png]\n\n\n\n\nThis is essentially the same as what you got from your code, but without manual slicing and whatnot. The wet season shows significant temporal autocorrelation (Durbin-Watson p = 0.005) with an alternating high/low pattern in the residuals, suggesting the model is over- and under-predicting in alternating years. The dry season shows no significant autocorrelation (p = 0.41). But, you should note that the DRY season has no observations in 2021, so the test treats 2022 as immediately following 2020 and would not detect autocorrelation if there is any across that gap.\n\n\n\n\nFor general advice, take a look at these posts (tbh, I'm reaching the end of my rope on this topic):\n\n\n\n\n\n\n\nHow to account for temporal autocorrelation in logistic regression with longitudinal data? (https://stats.stackexchange.com/q/395445)\n\n\n\n\n\n\n\n\n\nR: How to test for, or visualize, autocorrelation in irregularly spaced count data? (https://stats.stackexchange.com/q/664160)\n\n\n\n\n\n\n\n\nCreated on 2026-09-03 with reprex v2.1.1 (https://reprex.tidyverse.org)", "answer_url": "https://stats.stackexchange.com/a/677064", "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-09-04T03:00:41+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": 677062, "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-09-04T03:00:41+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "33E2BC86-F580-4F03-B6B5-57A2E864905B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/33E2BC86-F580-4F03-B6B5-57A2E864905B/view-source"}], "score": 2, "updated_at": "2026-09-04T03:00:41+00:00"}], "domain": "statistics", "external_links": ["https://github.com/NateLaS/Toadfish/blob/main/share_version%20-%20toadfish.csv", "https://i.sstatic.net/6r3XH8BM.png", "https://i.sstatic.net/LfmXWxdr.png", "https://i.sstatic.net/XIgn1m2c.png", "https://raw.githubusercontent.com/NateLaS/Toadfish/main/share_version%20-%20toadfish.csv", "https://reprex.tidyverse.org"], "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": "Nate", "question_author_url": "https://stats.stackexchange.com/users/337106/nate", "question_author_user_type": "registered", "question_created_at": "2026-09-03T14:57:31+00:00", "question_html": "

I have 2 time series in abundance that I'm modeling by a 2-level factor in mgcv , by "fSeason" (wet/dry), and following advice here, I should be splitting a test for auto-correlation by each factor level. I'm just not sure how to do that. Apologies for posting ChatGPT code, but I've been unsuccessful in my search everywhere else. DHARMa does have a test, but I was told it's only for a single time series. I don't think I can use the traditional AR(1) as the data are irregularly-spaced and I've never taken Bayesian statistics. Anyway, for now I'm just asking if the code AI generated is correctly identifying that I do have some, albeit weak, but significant temporal auto-correlation in the wet season. Any general advice is also welcome!

\n

Data here.

\n
library(mgcv)\nlibrary(gratia)\nlibrary(DHARMa)\n\nsystem.time(\n  by <- gam(total_count ~ \n               \n               offset(log(area_sampled)) +\n               \n               s(CYR, by = fSeason) +\n               fSeason + \n                 \n               s(sal, bs="ts", k=5) + \n               s(DO, bs="ts", k=5) +\n               \n               s(ave_sav, by = fDiet_presence) +\n               fDiet_presence + \n               \n               s(fSite, bs="re"),\n             \n             data = shiny_toad,\n             method = "REML", \n             family = nb(link = "log"),\n             select = FALSE, \n             \n             drop.unused.levels = FALSE, \n             control = list(trace = TRUE))\n)\n\n##################\n\ndf <- sort(diff(sort(as.Date(shiny_toad$Date))), decreasing = TRUE)\n\n# 1. Generate the base simulated residuals once\nres <- simulateResiduals(by)\n\n# 2. Loop through each Season safely by manually subsetting the DHARMa object\nfor (Season in unique(shiny_toad$fSeason)) {\n  \n  cat("\\n--- Temporal Autocorrelation Test for Season:", Season, "---\\n")\n  \n  # Create a logical index for the current Season\n  Season_idx <- shiny_toad$fSeason == Season\n  \n  # Copy the base DHARMa object structure\n  res_Season <- res\n  \n  # Manually slice all internal arrays to match only this Season's rows\n  res_Season$scaledResiduals       <- res$scaledResiduals[Season_idx]\n  res_Season$simulatedResponse     <- res$simulatedResponse[Season_idx, , drop = FALSE]\n  res_Season$observedResponse       <- res$observedResponse[Season_idx]\n  res_Season$fittedPredictedResponse <- res$fittedPredictedResponse[Season_idx]\n  res_Season$nObs                  <- sum(Season_idx)\n  \n  # Group the Season's residuals by CYR\n  res_grouped <- recalculateResiduals(res_Season, group = shiny_toad$CYR[Season_idx])\n  \n  # Open a new plot window so they don't overwrite each other\n  dev.new() \n  \n  # Run the test and plot\n  testTemporalAutocorrelation(res_grouped, time = unique(shiny_toad$CYR[Season_idx]))\n  \n  # Add a title to the plot window to identify the Season\n  mtext(paste("Season:", Season), side = 3, line = -2, outer = TRUE, font = 2, cex = 1.2)\n}\n\n
\n

Site locations were haphazardly chosen (before my time) to monitor changes in fish abundance due to the construction of new canals (data posted here not collected with this statistical model/set of hypotheses in mind - its just available). Timing of surveys is based on tide level (need at least 60 cm/2 ft of water to survey near shore during the day (during reg. working hours). It takes about 4-7 days to survey every site start-to-finish. Timing is also weather dependant. Also it takes 4-5 months to sort, ID, weigh and measure everything we catch. March/Sept is just avoid swimming in really cold water and give time between sample processesing of new data.

\n

\"ChatGPT

\n", "question_id": 677062, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I have 2 time series in abundance that I'm modeling by a 2-level factor in mgcv , by \"fSeason\" (wet/dry), and following advice here (https://stackoverflow.com/questions/78182559/autocorrelation-in-gam-r), I should be splitting a test for auto-correlation by each factor level. I'm just not sure how to do that. Apologies for posting ChatGPT code, but I've been unsuccessful in my search everywhere else. DHARMa does have a test, but I was told it's only for a single time series. I don't think I can use the traditional AR(1) as the data are irregularly-spaced and I've never taken Bayesian statistics. Anyway, for now I'm just asking if the code AI generated is correctly identifying that I do have some, albeit weak, but significant temporal auto-correlation in the wet season. Any general advice is also welcome!\n\n\n\n\nData here (https://github.com/NateLaS/Toadfish/blob/main/share_version%20-%20toadfish.csv).\n\n\n\n\nlibrary(mgcv)\nlibrary(gratia)\nlibrary(DHARMa)\n\nsystem.time(\n by <- gam(total_count ~ \n \n offset(log(area_sampled)) +\n \n s(CYR, by = fSeason) +\n fSeason + \n \n s(sal, bs=\"ts\", k=5) + \n s(DO, bs=\"ts\", k=5) +\n \n s(ave_sav, by = fDiet_presence) +\n fDiet_presence + \n \n s(fSite, bs=\"re\"),\n \n data = shiny_toad,\n method = \"REML\", \n family = nb(link = \"log\"),\n select = FALSE, \n \n drop.unused.levels = FALSE, \n control = list(trace = TRUE))\n)\n\n##################\n\ndf <- sort(diff(sort(as.Date(shiny_toad$Date))), decreasing = TRUE)\n\n# 1. Generate the base simulated residuals once\nres <- simulateResiduals(by)\n\n# 2. Loop through each Season safely by manually subsetting the DHARMa object\nfor (Season in unique(shiny_toad$fSeason)) {\n \n cat(\"\\n--- Temporal Autocorrelation Test for Season:\", Season, \"---\\n\")\n \n # Create a logical index for the current Season\n Season_idx <- shiny_toad$fSeason == Season\n \n # Copy the base DHARMa object structure\n res_Season <- res\n \n # Manually slice all internal arrays to match only this Season's rows\n res_Season$scaledResiduals <- res$scaledResiduals[Season_idx]\n res_Season$simulatedResponse <- res$simulatedResponse[Season_idx, , drop = FALSE]\n res_Season$observedResponse <- res$observedResponse[Season_idx]\n res_Season$fittedPredictedResponse <- res$fittedPredictedResponse[Season_idx]\n res_Season$nObs <- sum(Season_idx)\n \n # Group the Season's residuals by CYR\n res_grouped <- recalculateResiduals(res_Season, group = shiny_toad$CYR[Season_idx])\n \n # Open a new plot window so they don't overwrite each other\n dev.new() \n \n # Run the test and plot\n testTemporalAutocorrelation(res_grouped, time = unique(shiny_toad$CYR[Season_idx]))\n \n # Add a title to the plot window to identify the Season\n mtext(paste(\"Season:\", Season), side = 3, line = -2, outer = TRUE, font = 2, cex = 1.2)\n}\n\n\n\n\n\n\nSite locations were haphazardly chosen (before my time) to monitor changes in fish abundance due to the construction of new canals (data posted here not collected with this statistical model/set of hypotheses in mind - its just available). Timing of surveys is based on tide level (need at least 60 cm/2 ft of water to survey near shore during the day (during reg. working hours). It takes about 4-7 days to survey every site start-to-finish. Timing is also weather dependant. Also it takes 4-5 months to sort, ID, weigh and measure everything we catch. March/Sept is just avoid swimming in really cold water and give time between sample processesing of new data.\n\n\n\n\n[image: ChatGPT result; source: https://i.sstatic.net/XIgn1m2c.png]", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nate", "profile_url": "https://stats.stackexchange.com/users/337106/nate", "user_type": "registered"}, "created_at": "2026-09-03T14:57:31+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "4CC69CE1-E097-4AB2-BD0F-E74B07B62065", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4CC69CE1-E097-4AB2-BD0F-E74B07B62065/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://stats.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2026-09-03T17:44:22+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "9848AE18-49EA-4B5D-B569-BAF75FBC494F", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/9848AE18-49EA-4B5D-B569-BAF75FBC494F/view-source"}, {"content_license": null, "contributor": {"display_name": "Nate", "profile_url": "https://stats.stackexchange.com/users/337106/nate", "user_type": "registered"}, "created_at": "2026-09-03T18:40:43+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "8C808727-A175-4734-A486-C6FD89ACE250", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8C808727-A175-4734-A486-C6FD89ACE250/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nate", "profile_url": "https://stats.stackexchange.com/users/337106/nate", "user_type": "registered"}, "created_at": "2026-09-03T21:30:12+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "9B9EE227-ED20-456A-AC10-F2058FB67AA8", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9B9EE227-ED20-456A-AC10-F2058FB67AA8/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-04T08:12:44+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "664C0B4F-AD79-4901-ADB1-9E9DA984B90C", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/664C0B4F-AD79-4901-ADB1-9E9DA984B90C/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677062/how-to-check-for-temporal-auto-correlation-for-each-time-series-separately", "split": "train", "split_group": "8f180356d685609bbd341c35911366e55e5fb30729a62e110baf2955c6331c20", "tags": ["r", "autocorrelation", "unevenly-spaced-time-series"], "thread_id": "stats:677062", "title": "How to check for temporal auto-correlation for each time series separately?"}} +{"accepted_answer": {"answer_html": "

If you have three items $Y_1,Y_2, Y_3$ with variance 1 each, say, and $Y_2=-Y_1$, $Y_3$ independent of $Y_1, Y_2$ so that $X=Y_1+Y_2+Y_3=Y_3$, you have $\\sum\\sigma^2_{Y_j}=3$ and $\\sigma^2_{X}=1$. Then $\\alpha=\\frac{3}{2}(1-3)=-3$.

\n

The variances are all positive as is $\\frac{k}{k-1}$, but $1-\\frac{\\sum \\sigma^2_{Y_j}}{\\sigma^2_X}$ can well be negative.

\n

If your items are negatively correlated, the variance of $X$ may be small and the sum of the item variances can be large. If just $X=Y_1+Y_2$, you even have $\\sigma^2_X=0$ and $\\alpha=-\\infty$.

\n", "answer_id": 677067, "answer_text": "If you have three items $Y_1,Y_2, Y_3$ with variance 1 each, say, and $Y_2=-Y_1$, $Y_3$ independent of $Y_1, Y_2$ so that $X=Y_1+Y_2+Y_3=Y_3$, you have $\\sum\\sigma^2_{Y_j}=3$ and $\\sigma^2_{X}=1$. Then $\\alpha=\\frac{3}{2}(1-3)=-3$.\n\n\n\n\nThe variances are all positive as is $\\frac{k}{k-1}$, but $1-\\frac{\\sum \\sigma^2_{Y_j}}{\\sigma^2_X}$ can well be negative.\n\n\n\n\nIf your items are negatively correlated, the variance of $X$ may be small and the sum of the item variances can be large. If just $X=Y_1+Y_2$, you even have $\\sigma^2_X=0$ and $\\alpha=-\\infty$.", "answer_url": "https://stats.stackexchange.com/a/677067", "author": "Christian Hennig", "author_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-04T10:50:37+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": 677066, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-04T10:50:37+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "CFC09865-5603-48A3-A5A5-6087F1CF7234", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CFC09865-5603-48A3-A5A5-6087F1CF7234/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-04T10:56:29+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "92520B75-5858-4AF4-BFF0-E3925FDC41F7", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/92520B75-5858-4AF4-BFF0-E3925FDC41F7/view-source"}], "score": 11, "updated_at": "2026-09-04T10:56:29+00:00"}, "other_answers": [{"answer_html": "
\n

It should not be possible for those variance terms to be negative.

\n
\n

Note that there is a negative sign. (marked red below)

\n

$${\\displaystyle \\alpha ={k \\over k-1}\\left(1\\color{red}{\\mathbf{-}}{\\sum _{i=1}^{k}\\sigma _{y_{i}}^{2} \\over \\sigma _{X}^{2}}\\right)}$$

\n

The important question is whether we can have

\n

$$\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} > 1$$

\n
\n

The minimal value is easy to understand. If all items are fully correlated and have equal variance ($\\forall i : \\sigma_{y_i}^2 = \\sigma_{Y}^2$), then $\\sigma_X^2 = k^2 \\sigma_{Y}^2$. Hence the maximum value of $$1-\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} = 1 - \\frac{k \\sigma_Y^2}{k^2 \\sigma_Y^2}$$ is equal to $1-\\frac{1}{k} = \\frac{k-1}{k}$.

\n

(with different but fully correlates variances $\\sigma_{y_i}^2$ the maximum value will be a bit lower. E.g. if $y_1 = 0.5 y_2$, then $\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} = 1.25/1.5^2 = 5/9 > 1/2$)

\n
\n

For the maximum value we can get a lot above $1$ and even up to infinite. This is what Christian Hennig explained. His approach can even work with only two negatively correlated variables. Consider the following example

\n
                y_1      y_2      x\n                item 1   item 2   total score\nParticipant A   1        4        5\nParticipant B   2        3        5\nParticipant C   3        2        5\nParticipant D   4        1        5\n
\n

The population variance of the item scores is 1.25, but for the total it is 0

\n", "answer_id": 677068, "answer_text": "It should not be possible for those variance terms to be negative.\n\n\n\n\n\n\n\nNote that there is a negative sign. (marked red below)\n\n\n\n\n$${\\displaystyle \\alpha ={k \\over k-1}\\left(1\\color{red}{\\mathbf{-}}{\\sum _{i=1}^{k}\\sigma _{y_{i}}^{2} \\over \\sigma _{X}^{2}}\\right)}$$\n\n\n\n\nThe important question is whether we can have\n\n\n\n\n$$\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} > 1$$\n\n\n\n\n\n\n\nThe minimal value is easy to understand. If all items are fully correlated and have equal variance ($\\forall i : \\sigma_{y_i}^2 = \\sigma_{Y}^2$), then $\\sigma_X^2 = k^2 \\sigma_{Y}^2$. Hence the maximum value of $$1-\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} = 1 - \\frac{k \\sigma_Y^2}{k^2 \\sigma_Y^2}$$ is equal to $1-\\frac{1}{k} = \\frac{k-1}{k}$.\n\n\n\n\n(with different but fully correlates variances $\\sigma_{y_i}^2$ the maximum value will be a bit lower. E.g. if $y_1 = 0.5 y_2$, then $\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} = 1.25/1.5^2 = 5/9 > 1/2$)\n\n\n\n\n\n\n\nFor the maximum value we can get a lot above $1$ and even up to infinite. This is what Christian Hennig explained. His approach can even work with only two negatively correlated variables. Consider the following example\n\n\n\n\n y_1 y_2 x\n item 1 item 2 total score\nParticipant A 1 4 5\nParticipant B 2 3 5\nParticipant C 3 2 5\nParticipant D 4 1 5\n\n\n\n\n\nThe population variance of the item scores is 1.25, but for the total it is 0", "answer_url": "https://stats.stackexchange.com/a/677068", "author": "Sextus Empiricus", "author_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-04T12:07:06+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": 677066, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sextus Empiricus", "profile_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "user_type": "registered"}, "created_at": "2026-09-04T12:07:06+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "C11330D7-FE09-4007-BED2-7A5FA5F3DC0B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C11330D7-FE09-4007-BED2-7A5FA5F3DC0B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sextus Empiricus", "profile_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "user_type": "registered"}, "created_at": "2026-09-04T12:14:59+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "323BC7F4-6304-4932-9B41-BD55AF50F212", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/323BC7F4-6304-4932-9B41-BD55AF50F212/view-source"}], "score": 7, "updated_at": "2026-09-04T12:14:59+00:00"}], "product": "statistics_qa", "question": "I'm trying to get my head around how a negative result from Cronbach's alpha is even mathematically possible. When I look at the formula, it's defined entirely in terms of variances of the individual items (the following from wikipedia):\n\n\n\n\n$$\n{\\displaystyle \\alpha ={k \\over k-1}\\left(1-{\\sum _{i=1}^{k}\\sigma _{y_{i}}^{2} \\over \\sigma _{X}^{2}}\\right)}\n$$\n\n\n\n\nwhere:\n\n\n\n\n\n${\\displaystyle k}$ represents the number of \"parts\" (items, test parts, etc.) in the measure;\n\n\n\n\nthe ${\\displaystyle k/(k-1)}$ term causes alpha to be an unbiased estimate of reliability when the parts are parallel or essentially tau equivalent;\n\n\n\n\n${\\displaystyle \\sigma _{y_{i}}^{2}}$ the variance associated with each part i;\n\n\n\n\nand ${\\displaystyle \\sigma _{X}^{2}}$ the observed score variance (the\nvariance associated with the total test scores).\n\n\n\n\n\nIt should not be possible for those variance terms to be negative. Variances can't be negative. They're derived from sums of squares, which are always positive, because you square the deviances before summing them. (mathematically, if the summed individual item variances were larger than the variance of the entire data set, then the ratio would be larger than 1, so subtracting that ratio from 1 would be negative. But is that even possible in a data set, that the summed variances of its subparts end up greater than the variance of the whole? That smells fishy to me, although I can't produce a proof that it's impossible.)\n\n\n\n\nHowever, all the questions I see here about negative Cronbach's alpha have answers to the effect of 'your response scales need to be adjusted', and they often implicate covariances, not variances. Covariances can be negative, sure. But I don't see where covariances feature in the Cronbach's alpha formula.\n\n\n\n\nCan someone please explain, mathematically, how a negative Cronbach's alpha might be calculated based on the formula? Not the real-world situation that can give rise to it -- I understand that conceptually -- but the actual calculation steps that produce it?", "record_id": "Scientific-Statistics-QA:stats:677066", "selected_answer": {"answer_html": "

If you have three items $Y_1,Y_2, Y_3$ with variance 1 each, say, and $Y_2=-Y_1$, $Y_3$ independent of $Y_1, Y_2$ so that $X=Y_1+Y_2+Y_3=Y_3$, you have $\\sum\\sigma^2_{Y_j}=3$ and $\\sigma^2_{X}=1$. Then $\\alpha=\\frac{3}{2}(1-3)=-3$.

\n

The variances are all positive as is $\\frac{k}{k-1}$, but $1-\\frac{\\sum \\sigma^2_{Y_j}}{\\sigma^2_X}$ can well be negative.

\n

If your items are negatively correlated, the variance of $X$ may be small and the sum of the item variances can be large. If just $X=Y_1+Y_2$, you even have $\\sigma^2_X=0$ and $\\alpha=-\\infty$.

\n", "answer_id": 677067, "answer_text": "If you have three items $Y_1,Y_2, Y_3$ with variance 1 each, say, and $Y_2=-Y_1$, $Y_3$ independent of $Y_1, Y_2$ so that $X=Y_1+Y_2+Y_3=Y_3$, you have $\\sum\\sigma^2_{Y_j}=3$ and $\\sigma^2_{X}=1$. Then $\\alpha=\\frac{3}{2}(1-3)=-3$.\n\n\n\n\nThe variances are all positive as is $\\frac{k}{k-1}$, but $1-\\frac{\\sum \\sigma^2_{Y_j}}{\\sigma^2_X}$ can well be negative.\n\n\n\n\nIf your items are negatively correlated, the variance of $X$ may be small and the sum of the item variances can be large. If just $X=Y_1+Y_2$, you even have $\\sigma^2_X=0$ and $\\alpha=-\\infty$.", "answer_url": "https://stats.stackexchange.com/a/677067", "author": "Christian Hennig", "author_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-04T10:50:37+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": 677066, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-04T10:50:37+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "CFC09865-5603-48A3-A5A5-6087F1CF7234", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CFC09865-5603-48A3-A5A5-6087F1CF7234/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-04T10:56:29+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "92520B75-5858-4AF4-BFF0-E3925FDC41F7", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/92520B75-5858-4AF4-BFF0-E3925FDC41F7/view-source"}], "score": 11, "updated_at": "2026-09-04T10:56:29+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677067, "answers": [{"answer_html": "

If you have three items $Y_1,Y_2, Y_3$ with variance 1 each, say, and $Y_2=-Y_1$, $Y_3$ independent of $Y_1, Y_2$ so that $X=Y_1+Y_2+Y_3=Y_3$, you have $\\sum\\sigma^2_{Y_j}=3$ and $\\sigma^2_{X}=1$. Then $\\alpha=\\frac{3}{2}(1-3)=-3$.

\n

The variances are all positive as is $\\frac{k}{k-1}$, but $1-\\frac{\\sum \\sigma^2_{Y_j}}{\\sigma^2_X}$ can well be negative.

\n

If your items are negatively correlated, the variance of $X$ may be small and the sum of the item variances can be large. If just $X=Y_1+Y_2$, you even have $\\sigma^2_X=0$ and $\\alpha=-\\infty$.

\n", "answer_id": 677067, "answer_text": "If you have three items $Y_1,Y_2, Y_3$ with variance 1 each, say, and $Y_2=-Y_1$, $Y_3$ independent of $Y_1, Y_2$ so that $X=Y_1+Y_2+Y_3=Y_3$, you have $\\sum\\sigma^2_{Y_j}=3$ and $\\sigma^2_{X}=1$. Then $\\alpha=\\frac{3}{2}(1-3)=-3$.\n\n\n\n\nThe variances are all positive as is $\\frac{k}{k-1}$, but $1-\\frac{\\sum \\sigma^2_{Y_j}}{\\sigma^2_X}$ can well be negative.\n\n\n\n\nIf your items are negatively correlated, the variance of $X$ may be small and the sum of the item variances can be large. If just $X=Y_1+Y_2$, you even have $\\sigma^2_X=0$ and $\\alpha=-\\infty$.", "answer_url": "https://stats.stackexchange.com/a/677067", "author": "Christian Hennig", "author_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-04T10:50:37+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": 677066, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-04T10:50:37+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "CFC09865-5603-48A3-A5A5-6087F1CF7234", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CFC09865-5603-48A3-A5A5-6087F1CF7234/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-04T10:56:29+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "92520B75-5858-4AF4-BFF0-E3925FDC41F7", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/92520B75-5858-4AF4-BFF0-E3925FDC41F7/view-source"}], "score": 11, "updated_at": "2026-09-04T10:56:29+00:00"}, {"answer_html": "
\n

It should not be possible for those variance terms to be negative.

\n
\n

Note that there is a negative sign. (marked red below)

\n

$${\\displaystyle \\alpha ={k \\over k-1}\\left(1\\color{red}{\\mathbf{-}}{\\sum _{i=1}^{k}\\sigma _{y_{i}}^{2} \\over \\sigma _{X}^{2}}\\right)}$$

\n

The important question is whether we can have

\n

$$\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} > 1$$

\n
\n

The minimal value is easy to understand. If all items are fully correlated and have equal variance ($\\forall i : \\sigma_{y_i}^2 = \\sigma_{Y}^2$), then $\\sigma_X^2 = k^2 \\sigma_{Y}^2$. Hence the maximum value of $$1-\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} = 1 - \\frac{k \\sigma_Y^2}{k^2 \\sigma_Y^2}$$ is equal to $1-\\frac{1}{k} = \\frac{k-1}{k}$.

\n

(with different but fully correlates variances $\\sigma_{y_i}^2$ the maximum value will be a bit lower. E.g. if $y_1 = 0.5 y_2$, then $\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} = 1.25/1.5^2 = 5/9 > 1/2$)

\n
\n

For the maximum value we can get a lot above $1$ and even up to infinite. This is what Christian Hennig explained. His approach can even work with only two negatively correlated variables. Consider the following example

\n
                y_1      y_2      x\n                item 1   item 2   total score\nParticipant A   1        4        5\nParticipant B   2        3        5\nParticipant C   3        2        5\nParticipant D   4        1        5\n
\n

The population variance of the item scores is 1.25, but for the total it is 0

\n", "answer_id": 677068, "answer_text": "It should not be possible for those variance terms to be negative.\n\n\n\n\n\n\n\nNote that there is a negative sign. (marked red below)\n\n\n\n\n$${\\displaystyle \\alpha ={k \\over k-1}\\left(1\\color{red}{\\mathbf{-}}{\\sum _{i=1}^{k}\\sigma _{y_{i}}^{2} \\over \\sigma _{X}^{2}}\\right)}$$\n\n\n\n\nThe important question is whether we can have\n\n\n\n\n$$\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} > 1$$\n\n\n\n\n\n\n\nThe minimal value is easy to understand. If all items are fully correlated and have equal variance ($\\forall i : \\sigma_{y_i}^2 = \\sigma_{Y}^2$), then $\\sigma_X^2 = k^2 \\sigma_{Y}^2$. Hence the maximum value of $$1-\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} = 1 - \\frac{k \\sigma_Y^2}{k^2 \\sigma_Y^2}$$ is equal to $1-\\frac{1}{k} = \\frac{k-1}{k}$.\n\n\n\n\n(with different but fully correlates variances $\\sigma_{y_i}^2$ the maximum value will be a bit lower. E.g. if $y_1 = 0.5 y_2$, then $\\frac{\\sum_{i=1}^{k}\\sigma_{y_{i}}^2}{ \\sigma_X^2} = 1.25/1.5^2 = 5/9 > 1/2$)\n\n\n\n\n\n\n\nFor the maximum value we can get a lot above $1$ and even up to infinite. This is what Christian Hennig explained. His approach can even work with only two negatively correlated variables. Consider the following example\n\n\n\n\n y_1 y_2 x\n item 1 item 2 total score\nParticipant A 1 4 5\nParticipant B 2 3 5\nParticipant C 3 2 5\nParticipant D 4 1 5\n\n\n\n\n\nThe population variance of the item scores is 1.25, but for the total it is 0", "answer_url": "https://stats.stackexchange.com/a/677068", "author": "Sextus Empiricus", "author_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-04T12:07:06+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": 677066, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sextus Empiricus", "profile_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "user_type": "registered"}, "created_at": "2026-09-04T12:07:06+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "C11330D7-FE09-4007-BED2-7A5FA5F3DC0B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C11330D7-FE09-4007-BED2-7A5FA5F3DC0B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sextus Empiricus", "profile_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "user_type": "registered"}, "created_at": "2026-09-04T12:14:59+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "323BC7F4-6304-4932-9B41-BD55AF50F212", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/323BC7F4-6304-4932-9B41-BD55AF50F212/view-source"}], "score": 7, "updated_at": "2026-09-04T12:14:59+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Ergative Absolutive", "question_author_url": "https://stats.stackexchange.com/users/516278/ergative-absolutive", "question_author_user_type": "registered", "question_created_at": "2026-09-04T10:12:49+00:00", "question_html": "

I'm trying to get my head around how a negative result from Cronbach's alpha is even mathematically possible. When I look at the formula, it's defined entirely in terms of variances of the individual items (the following from wikipedia):

\n

$$\n{\\displaystyle \\alpha ={k \\over k-1}\\left(1-{\\sum _{i=1}^{k}\\sigma _{y_{i}}^{2} \\over \\sigma _{X}^{2}}\\right)}\n$$

\n

where:

\n\n

It should not be possible for those variance terms to be negative. Variances can't be negative. They're derived from sums of squares, which are always positive, because you square the deviances before summing them. (mathematically, if the summed individual item variances were larger than the variance of the entire data set, then the ratio would be larger than 1, so subtracting that ratio from 1 would be negative. But is that even possible in a data set, that the summed variances of its subparts end up greater than the variance of the whole? That smells fishy to me, although I can't produce a proof that it's impossible.)

\n

However, all the questions I see here about negative Cronbach's alpha have answers to the effect of 'your response scales need to be adjusted', and they often implicate covariances, not variances. Covariances can be negative, sure. But I don't see where covariances feature in the Cronbach's alpha formula.

\n

Can someone please explain, mathematically, how a negative Cronbach's alpha might be calculated based on the formula? Not the real-world situation that can give rise to it -- I understand that conceptually -- but the actual calculation steps that produce it?

\n", "question_id": 677066, "question_license": "CC BY-SA 4.0", "question_score": 7, "question_text": "I'm trying to get my head around how a negative result from Cronbach's alpha is even mathematically possible. When I look at the formula, it's defined entirely in terms of variances of the individual items (the following from wikipedia):\n\n\n\n\n$$\n{\\displaystyle \\alpha ={k \\over k-1}\\left(1-{\\sum _{i=1}^{k}\\sigma _{y_{i}}^{2} \\over \\sigma _{X}^{2}}\\right)}\n$$\n\n\n\n\nwhere:\n\n\n\n\n\n${\\displaystyle k}$ represents the number of \"parts\" (items, test parts, etc.) in the measure;\n\n\n\n\nthe ${\\displaystyle k/(k-1)}$ term causes alpha to be an unbiased estimate of reliability when the parts are parallel or essentially tau equivalent;\n\n\n\n\n${\\displaystyle \\sigma _{y_{i}}^{2}}$ the variance associated with each part i;\n\n\n\n\nand ${\\displaystyle \\sigma _{X}^{2}}$ the observed score variance (the\nvariance associated with the total test scores).\n\n\n\n\n\nIt should not be possible for those variance terms to be negative. Variances can't be negative. They're derived from sums of squares, which are always positive, because you square the deviances before summing them. (mathematically, if the summed individual item variances were larger than the variance of the entire data set, then the ratio would be larger than 1, so subtracting that ratio from 1 would be negative. But is that even possible in a data set, that the summed variances of its subparts end up greater than the variance of the whole? That smells fishy to me, although I can't produce a proof that it's impossible.)\n\n\n\n\nHowever, all the questions I see here about negative Cronbach's alpha have answers to the effect of 'your response scales need to be adjusted', and they often implicate covariances, not variances. Covariances can be negative, sure. But I don't see where covariances feature in the Cronbach's alpha formula.\n\n\n\n\nCan someone please explain, mathematically, how a negative Cronbach's alpha might be calculated based on the formula? Not the real-world situation that can give rise to it -- I understand that conceptually -- but the actual calculation steps that produce it?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ergative Absolutive", "profile_url": "https://stats.stackexchange.com/users/516278/ergative-absolutive", "user_type": "registered"}, "created_at": "2026-09-04T10:12:49+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "23657ED0-0F1D-4E6A-8A86-F2B020D31472", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/23657ED0-0F1D-4E6A-8A86-F2B020D31472/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-04T18:13:09+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "BCD1B720-C749-4466-9063-A77290447A49", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/BCD1B720-C749-4466-9063-A77290447A49/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677066/cronbachs-alpha-variance-vs-covariance-and-how-are-negative-values-mathemati", "split": "train", "split_group": "b86b633f37a97a115e7f9ffb39a30158c2c1d60a4110ad06762af38037188b3a", "tags": ["cronbachs-alpha"], "thread_id": "stats:677066", "title": "Cronbach's alpha, variance vs. covariance, and how are negative values mathematically possible?"}} +{"accepted_answer": {"answer_html": "

Yes, that equivalence holds

\n

From the definition of $p$ we have:

\n

$$\\begin{align}\np\n&= \\mathbb{P}(X_1<X_2) + \\frac{1}{2} \\cdot \\mathbb{P}(X_1=X_2), \\\\[6pt]\n1-p\n&= \\mathbb{P}(X_1>X_2) + \\frac{1}{2} \\cdot \\mathbb{P}(X_1=X_2). \\\\[6pt]\n\\end{align}$$

\n

Consequently, we have:

\n

$$1-2p = (1-p) - p = \\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1<X_2),$$

\n

which implies that:

\n

$$p = \\tfrac{1}{2}\n\\quad \\quad \\iff \\quad \\quad \n1-2p=0\n\\quad \\quad \\iff \\quad \\quad \n\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2).$$

\n

Since the distributions of $X_1$ and $X_2$ vary only by a location shift, it is also simple to establish (see below) that:

\n

$$\\delta = 0\n\\quad \\quad \\iff \\quad \\quad \n\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2).$$

\n

Consequently, the equivalence between $p=\\tfrac{1}{2}$ and $\\delta=0$ holds.

\n
\n

Proving the latter equivalence: Since $X_1$ and $X_2$ are independent we have:

\n

$$\\begin{align}\n\\mathbb{P}(X_1 < X_2) \n&= 1- \\int \\limits_0^\\infty F_2(x) \\ dF_1(x) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x) \\ dF_2(x-\\delta) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x+\\delta) \\ dF_2(x), \\\\[6pt]\n\\mathbb{P}(X_1 > X_2) \n&= 1- \\int \\limits_0^\\infty F_1(x) dF_2(x) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x-\\delta) dF_2(x), \\\\[6pt]\n\\end{align}$$

\n

which gives:

\n

$$\\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1<X_2)\n= \\int \\limits_0^\\infty [ F_2(x-\\delta) - F_2(x+\\delta)] \\ dF_2(x).$$

\n

The integrand is zero when $\\delta=0$ and is non-negative or non-positive if $\\delta \\neq 0$. If $\\delta=0$ then we obtain $\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2)$ directly. If $\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2)$ then the integrand in the above expression must be zero almost surely over the range of integration, which can only occur if $\\delta=0$.

\n", "answer_id": 677074, "answer_text": "Yes, that equivalence holds\n\n\n\n\nFrom the definition of $p$ we have:\n\n\n\n\n$$\\begin{align}\np\n&= \\mathbb{P}(X_1X_2) + \\frac{1}{2} \\cdot \\mathbb{P}(X_1=X_2). \\\\[6pt]\n\\end{align}$$\n\n\n\n\nConsequently, we have:\n\n\n\n\n$$1-2p = (1-p) - p = \\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1 X_2) \n&= 1- \\int \\limits_0^\\infty F_1(x) dF_2(x) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x-\\delta) dF_2(x), \\\\[6pt]\n\\end{align}$$\n\n\n\n\nwhich gives:\n\n\n\n\n$$\\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1I think that my colleague was right. However, even Brunner's book does not address this issue, so I wrote the following proof:

\n

Theorem: Suppose that $X_1\\sim X_2+\\delta$, then\n$$p=1/2\\Leftrightarrow \\delta=0.$$

\n

Proof: Set $X_1-X_2=D+\\delta$, then\n$$p=P(X_1<X_2)+\\frac{1}{2}P(X_1=X_2)=P(D<\\delta)+\\frac{1}{2}P(D=\\delta)=F(\\delta),$$\nwhere $F$ is the CDF of $D$. That being said, the Theorem follows from the following Proposition:

\n

Proposition:\nLet $Y_1$ and $Y_2$ be iid, $D:=Y_1-Y_2$ and $F$ the CDF of $D$, i.e.,\n$$\\forall x\\in\\mathbb R:F(x)=P(D<x)+\\frac{1}{2}P(D=x).$$\nThen $F(x)=1/2$ if and only if $x=0$.

\n

Proof: Clearly, $F(0)=1/2$. So suppose that $x\\in\\mathbb R$ and $F(x)=1/2$. We want to show that $x=0$. WLOG, suppose that $0\\leq x$ (indeed, $F(-x)=1-F(x)=1/2$, see the Lemmas further below). Then\n$$0=F(x)-F(0)=P(0<D<x)+\\frac{1}{2}(P(D=0)+P(D=x))$$\nand hence $P(0\\leq D\\leq x)$. By symmetry, $P(-|x|\\leq D\\leq +|x|)=0$. But this is equivalent to $x=0$: Indeed, if $x\\neq 0$, then $|x|>0$ and there must exists an interval $I$ with $|I|=2|x|$ such that $P(Y_i\\in I)>0$. But then\n$$P(-|x|\\leq D\\leq +|x|)=P(|Y_1-Y_2|\\leq 2|x|)\\geq P(Y_1\\in I,Y_2\\in I)=P(Y\\in I)^2>0.$$

\n
\n

Lemma 1: If $Y_1$ and $Y_2$ are iid, then $D:=Y_1-Y_2$ is symmetric, i.e., $D$ and $-D$ have the same distribution: Indeed, this follows from the fact that $(Y_1,Y_2)\\sim (Y_2,Y_1)$.

\n

Lemma 2: Let $X\\sim F$ and $X\\sim -X$, then $\\forall x: F(-x)=1-F(x)$:\n$$F(-x)=P(X<-x)+\\frac{1}{2}P(X=-x)=P(x<X)+\\frac{1}{2}P(X=x)=1-P(X<x)-P(X=x)+\\frac{1}{2}P(X=x)=1-F(x)$$

\n", "answer_id": 677072, "answer_text": "I think that my colleague was right. However, even Brunner's book (https://doi.org/10.1007/978-3-030-02914-2) does not address this issue, so I wrote the following proof:\n\n\n\n\nTheorem: Suppose that $X_1\\sim X_2+\\delta$, then\n$$p=1/2\\Leftrightarrow \\delta=0.$$\n\n\n\n\nProof: Set $X_1-X_2=D+\\delta$, then\n$$p=P(X_10$ and there must exists an interval $I$ with $|I|=2|x|$ such that $P(Y_i\\in I)>0$. But then\n$$P(-|x|\\leq D\\leq +|x|)=P(|Y_1-Y_2|\\leq 2|x|)\\geq P(Y_1\\in I,Y_2\\in I)=P(Y\\in I)^2>0.$$\n\n\n\n\n\n\n\nLemma 1: If $Y_1$ and $Y_2$ are iid, then $D:=Y_1-Y_2$ is symmetric, i.e., $D$ and $-D$ have the same distribution: Indeed, this follows from the fact that $(Y_1,Y_2)\\sim (Y_2,Y_1)$.\n\n\n\n\nLemma 2: Let $X\\sim F$ and $X\\sim -X$, then $\\forall x: F(-x)=1-F(x)$:\n$$F(-x)=P(X<-x)+\\frac{1}{2}P(X=-x)=P(xThe Mann-Whitney U test (MWUt) tests stochastic homogeneity (also sometimes called stochastic equality). The alternative hypothesis being stochastic superiority. After all, Mann & Whitney titled their paper

\n
\n

Mann, H. B., Whitney, D. R. (1947) “On a test of whether one of two\nrandom variables is stochastically larger than the other”

\n
\n

The MWUt is consistent (i.e. “the outcome of the procedure converges to the correct outcome as sample size goes to infinity”) only under the following null hypothesis\n$$p=P(X_1<X_2)+\\frac{1}{2}P(X_1=X_2) = 0.5$$\nWhich can also be written as\n$$P(X_1<X_2) = P(X_2<X_1)$$ (ignoring the “ties”)

\n

That null is true under only 2 scenarios;

\n
    \n
  1. the 2 samples come from the exact same distribution (i.e. $F_1=F_2$); all moments, including mean, are the same, or
  2. \n
  3. the 2 samples come from symmetric, but possibly different, distributions, symmetric around the same median (and hence mean).
  4. \n
\n

These are the only 2 cases where there is no stochastic ordering; otherwise, one distribution is stochastically superior to the other, and the rejection rate will increase with sample size, as it should.\\

\n

So, if you assume that $\\exists \\delta:\\forall x:F_2(x)=F_1(x+\\delta)$, then indeed $\\delta = 0$ and $p=1/2$ are equivalent.

\n

However, this assumption is a very bold assumption, and the MWUt is absolutely not robust to departures from this assumption.\nMoreover, you could get $p=1/2$ w/o a shift model, e.g. in the case of 2 symmetric distributions around the same mean/median (e.g. $N(0,1)$ and $Unif(-1,1)$). You will have $p=1/2$, but you certainly will not have $F_2(x)=F_1(x+\\delta)$.

\n

So, in general, the null hypothesis of the MWUt is not $F_1=F_2$ (it is instead $p=1/2$). It can become $F_1=F_2$ if you can rule out symmetry of at least one of the 2 distributions. And the location shift assumption is so unlikely (and the test not robust to it) as to invalidate any results based on it.

\n

Last, even if the MWUt could be used as a test of $F_1=F_2$, what would you do if you have a significant result? So what if $F_1 \\ne F_2$? Which is the "best", which decision do you make? Whereas knowing which distribution is stochastically superior is useful, and has practical implications (a randomly selected observation from one distribution is more likely than not to be greater than a randomnly selected observation from the other). By contrast, knowing that the 2 distributions are not identical is not actionable. So even if one could find assumptions under which that null was valid, it would be of no practical value...

\n", "answer_id": 677073, "answer_text": "The Mann-Whitney U test (MWUt) tests stochastic homogeneity (also sometimes called stochastic equality). The alternative hypothesis being stochastic superiority. After all, Mann & Whitney titled their paper\n\n\n\n\n\n\n\nMann, H. B., Whitney, D. R. (1947) “On a test of whether one of two\nrandom variables is stochastically larger than the other”\n\n\n\n\n\n\n\nThe MWUt is consistent (i.e. “the outcome of the procedure converges to the correct outcome as sample size goes to infinity (https://en.wikipedia.org/wiki/Consistency_(statistics))”) only under the following null hypothesis\n$$p=P(X_1There are good answers to the main point as the question now stands. Here I will address where restriction to a location-shift alternative (on the observed variable) may make sense, or might not.

\n
    \n
  1. A continuous variable defined over $\\mathbb{R}$. There's no immediate issue there, and I think pure shift alternatives may make sense in some applications (at least as approximate descriptions).

    \n
  2. \n
  3. A continous variable with a lower bound (e.g. a variate with support on $\\mathbb{R}^+$) or with an upper bound, or both. Here the support shifts. For example, if a variate has some lowest possible value then either you must assume only positive shifts are possible or that there is no possibility of any values larger than an allowed left shift can occur (i.e. you need to begin by positing that the actual support of the unshifted variable is different from the stated support). Otherwise you can't make $F$'s correspond in the stated fashion.

    \n

    For most continuous distributions with a bound that are in common use, and also with many real world variables, the idea of a pure location shift doesn't really work - but the Mann-Whitney works fine beyond that case. Indeed they state in the 1947 paper "The test is shown to be consistent with respect to the class of alternatives $f(x)>g(x)$ for every $x$" where here $f$ and $g$ have been defined to be continuous cdfs (side note: $f>g$ means values drawn from $f$ tend to be smaller). It would be consistent for a somewhat broader class of alternatives but I don't want to head off on a side issue just now.

    \n

    For many continuous variables on $\\mathbb{R}^+$ a scale shift alternative would make more sense, and for many variables on a bounded interval, a change of shape is to be expected (if the actual and stated support correspond it's going to be hard to avoid it).

    \n
  4. \n
  5. A discrete random variate with support on a lattice. Here only shifts of multiples of the lattice interval (that also respect any bounds) are possible (unless we also shift the support by $\\delta$, of course, but this rarely makes sense).

    \n
  6. \n
  7. A discrete random variate with support on a countable set that is not on a lattice (e.g. imagine a test where we have applied a square-root transformation to a count). Here it doesn't seem to work at all without changing the support.

    \n
  8. \n
  9. An ordinal variable*. Now we have a problem of even defining an $F$, but let us assume we can define some set of (unknown, not equally-spaced) values or intervals between them on which it has support, where we have then given the unknown values or intervals arbitrary (but order-preserving) labels. This situation has all the difficulties of case 4 but worse - here we can't define a shift of $\\delta$ on the labels that makes sense, and we don't have access to the unknown values they stand for, but if we could solve that, we still have the issue with the support we had in point 4.

    \n
  10. \n
\n
\n

* The original question posited an ordinal variable. It doesn't do so now (to the better, since case 5 is problematic), but I leave discussion of this case in my answer because it seems to be a very common situation for people to use the Wilcoxon-Mann-Whitney test on ordinal responses and then very often talk about (or at least imply at some point) a location shift alternative.

\n", "answer_id": 677076, "answer_text": "There are good answers to the main point as the question now stands. Here I will address where restriction to a location-shift alternative (on the observed variable) may make sense, or might not.\n\n\n\n\n\n\n\nA continuous variable defined over $\\mathbb{R}$. There's no immediate issue there, and I think pure shift alternatives may make sense in some applications (at least as approximate descriptions).\n\n\n\n\n\n\n\n\n\nA continous variable with a lower bound (e.g. a variate with support on $\\mathbb{R}^+$) or with an upper bound, or both. Here the support shifts. For example, if a variate has some lowest possible value then either you must assume only positive shifts are possible or that there is no possibility of any values larger than an allowed left shift can occur (i.e. you need to begin by positing that the actual support of the unshifted variable is different from the stated support). Otherwise you can't make $F$'s correspond in the stated fashion.\n\n\n\n\nFor most continuous distributions with a bound that are in common use, and also with many real world variables, the idea of a pure location shift doesn't really work - but the Mann-Whitney works fine beyond that case. Indeed they state in the 1947 paper \"The test is shown to be consistent with respect to the class of alternatives $f(x)>g(x)$ for every $x$\" where here $f$ and $g$ have been defined to be continuous cdfs (side note: $f>g$ means values drawn from $f$ tend to be smaller). It would be consistent for a somewhat broader class of alternatives but I don't want to head off on a side issue just now.\n\n\n\n\nFor many continuous variables on $\\mathbb{R}^+$ a scale shift alternative would make more sense, and for many variables on a bounded interval, a change of shape is to be expected (if the actual and stated support correspond it's going to be hard to avoid it).\n\n\n\n\n\n\n\n\n\nA discrete random variate with support on a lattice. Here only shifts of multiples of the lattice interval (that also respect any bounds) are possible (unless we also shift the support by $\\delta$, of course, but this rarely makes sense).\n\n\n\n\n\n\n\n\n\nA discrete random variate with support on a countable set that is not on a lattice (e.g. imagine a test where we have applied a square-root transformation to a count). Here it doesn't seem to work at all without changing the support.\n\n\n\n\n\n\n\n\n\nAn ordinal variable*. Now we have a problem of even defining an $F$, but let us assume we can define some set of (unknown, not equally-spaced) values or intervals between them on which it has support, where we have then given the unknown values or intervals arbitrary (but order-preserving) labels. This situation has all the difficulties of case 4 but worse - here we can't define a shift of $\\delta$ on the labels that makes sense, and we don't have access to the unknown values they stand for, but if we could solve that, we still have the issue with the support we had in point 4.\n\n\n\n\n\n\n\n\n\n\n\n* The original question posited an ordinal variable. It doesn't do so now (to the better, since case 5 is problematic), but I leave discussion of this case in my answer because it seems to be a very common situation for people to use the Wilcoxon-Mann-Whitney test on ordinal responses and then very often talk about (or at least imply at some point) a location shift alternative.", "answer_url": "https://stats.stackexchange.com/a/677076", "author": "Glen_b", "author_url": "https://stats.stackexchange.com/users/805/glen-b", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-05T02:08:47+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": 677071, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-05T02:08:47+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "19744E33-32C1-42E6-8B19-EF45E4EFB08C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/19744E33-32C1-42E6-8B19-EF45E4EFB08C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-05T02:15:47+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "CF826F38-A814-44FE-98C7-7558264B9395", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CF826F38-A814-44FE-98C7-7558264B9395/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-05T09:13:58+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "3504ADB8-E74F-4904-A022-B3D8AF1388A2", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3504ADB8-E74F-4904-A022-B3D8AF1388A2/view-source"}], "score": 4, "updated_at": "2026-09-05T09:13:58+00:00"}], "product": "statistics_qa", "question": "Suppose that $X_1$ and $X_2$ are real-valued random variables and $X_i\\sim F_i$, i.e., $F_i$ is the CDF of $X_i$. Furthermore, assume the Location shift model:\n$$\\exists \\delta:\\forall x:F_2(x)=F_1(x+\\delta)$$\nFinally, consider the probabilistic index\n$$p=P(X_1Yes, that equivalence holds\n

From the definition of $p$ we have:

\n

$$\\begin{align}\np\n&= \\mathbb{P}(X_1<X_2) + \\frac{1}{2} \\cdot \\mathbb{P}(X_1=X_2), \\\\[6pt]\n1-p\n&= \\mathbb{P}(X_1>X_2) + \\frac{1}{2} \\cdot \\mathbb{P}(X_1=X_2). \\\\[6pt]\n\\end{align}$$

\n

Consequently, we have:

\n

$$1-2p = (1-p) - p = \\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1<X_2),$$

\n

which implies that:

\n

$$p = \\tfrac{1}{2}\n\\quad \\quad \\iff \\quad \\quad \n1-2p=0\n\\quad \\quad \\iff \\quad \\quad \n\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2).$$

\n

Since the distributions of $X_1$ and $X_2$ vary only by a location shift, it is also simple to establish (see below) that:

\n

$$\\delta = 0\n\\quad \\quad \\iff \\quad \\quad \n\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2).$$

\n

Consequently, the equivalence between $p=\\tfrac{1}{2}$ and $\\delta=0$ holds.

\n
\n

Proving the latter equivalence: Since $X_1$ and $X_2$ are independent we have:

\n

$$\\begin{align}\n\\mathbb{P}(X_1 < X_2) \n&= 1- \\int \\limits_0^\\infty F_2(x) \\ dF_1(x) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x) \\ dF_2(x-\\delta) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x+\\delta) \\ dF_2(x), \\\\[6pt]\n\\mathbb{P}(X_1 > X_2) \n&= 1- \\int \\limits_0^\\infty F_1(x) dF_2(x) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x-\\delta) dF_2(x), \\\\[6pt]\n\\end{align}$$

\n

which gives:

\n

$$\\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1<X_2)\n= \\int \\limits_0^\\infty [ F_2(x-\\delta) - F_2(x+\\delta)] \\ dF_2(x).$$

\n

The integrand is zero when $\\delta=0$ and is non-negative or non-positive if $\\delta \\neq 0$. If $\\delta=0$ then we obtain $\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2)$ directly. If $\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2)$ then the integrand in the above expression must be zero almost surely over the range of integration, which can only occur if $\\delta=0$.

\n", "answer_id": 677074, "answer_text": "Yes, that equivalence holds\n\n\n\n\nFrom the definition of $p$ we have:\n\n\n\n\n$$\\begin{align}\np\n&= \\mathbb{P}(X_1X_2) + \\frac{1}{2} \\cdot \\mathbb{P}(X_1=X_2). \\\\[6pt]\n\\end{align}$$\n\n\n\n\nConsequently, we have:\n\n\n\n\n$$1-2p = (1-p) - p = \\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1 X_2) \n&= 1- \\int \\limits_0^\\infty F_1(x) dF_2(x) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x-\\delta) dF_2(x), \\\\[6pt]\n\\end{align}$$\n\n\n\n\nwhich gives:\n\n\n\n\n$$\\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677074, "answers": [{"answer_html": "

I think that my colleague was right. However, even Brunner's book does not address this issue, so I wrote the following proof:

\n

Theorem: Suppose that $X_1\\sim X_2+\\delta$, then\n$$p=1/2\\Leftrightarrow \\delta=0.$$

\n

Proof: Set $X_1-X_2=D+\\delta$, then\n$$p=P(X_1<X_2)+\\frac{1}{2}P(X_1=X_2)=P(D<\\delta)+\\frac{1}{2}P(D=\\delta)=F(\\delta),$$\nwhere $F$ is the CDF of $D$. That being said, the Theorem follows from the following Proposition:

\n

Proposition:\nLet $Y_1$ and $Y_2$ be iid, $D:=Y_1-Y_2$ and $F$ the CDF of $D$, i.e.,\n$$\\forall x\\in\\mathbb R:F(x)=P(D<x)+\\frac{1}{2}P(D=x).$$\nThen $F(x)=1/2$ if and only if $x=0$.

\n

Proof: Clearly, $F(0)=1/2$. So suppose that $x\\in\\mathbb R$ and $F(x)=1/2$. We want to show that $x=0$. WLOG, suppose that $0\\leq x$ (indeed, $F(-x)=1-F(x)=1/2$, see the Lemmas further below). Then\n$$0=F(x)-F(0)=P(0<D<x)+\\frac{1}{2}(P(D=0)+P(D=x))$$\nand hence $P(0\\leq D\\leq x)$. By symmetry, $P(-|x|\\leq D\\leq +|x|)=0$. But this is equivalent to $x=0$: Indeed, if $x\\neq 0$, then $|x|>0$ and there must exists an interval $I$ with $|I|=2|x|$ such that $P(Y_i\\in I)>0$. But then\n$$P(-|x|\\leq D\\leq +|x|)=P(|Y_1-Y_2|\\leq 2|x|)\\geq P(Y_1\\in I,Y_2\\in I)=P(Y\\in I)^2>0.$$

\n
\n

Lemma 1: If $Y_1$ and $Y_2$ are iid, then $D:=Y_1-Y_2$ is symmetric, i.e., $D$ and $-D$ have the same distribution: Indeed, this follows from the fact that $(Y_1,Y_2)\\sim (Y_2,Y_1)$.

\n

Lemma 2: Let $X\\sim F$ and $X\\sim -X$, then $\\forall x: F(-x)=1-F(x)$:\n$$F(-x)=P(X<-x)+\\frac{1}{2}P(X=-x)=P(x<X)+\\frac{1}{2}P(X=x)=1-P(X<x)-P(X=x)+\\frac{1}{2}P(X=x)=1-F(x)$$

\n", "answer_id": 677072, "answer_text": "I think that my colleague was right. However, even Brunner's book (https://doi.org/10.1007/978-3-030-02914-2) does not address this issue, so I wrote the following proof:\n\n\n\n\nTheorem: Suppose that $X_1\\sim X_2+\\delta$, then\n$$p=1/2\\Leftrightarrow \\delta=0.$$\n\n\n\n\nProof: Set $X_1-X_2=D+\\delta$, then\n$$p=P(X_10$ and there must exists an interval $I$ with $|I|=2|x|$ such that $P(Y_i\\in I)>0$. But then\n$$P(-|x|\\leq D\\leq +|x|)=P(|Y_1-Y_2|\\leq 2|x|)\\geq P(Y_1\\in I,Y_2\\in I)=P(Y\\in I)^2>0.$$\n\n\n\n\n\n\n\nLemma 1: If $Y_1$ and $Y_2$ are iid, then $D:=Y_1-Y_2$ is symmetric, i.e., $D$ and $-D$ have the same distribution: Indeed, this follows from the fact that $(Y_1,Y_2)\\sim (Y_2,Y_1)$.\n\n\n\n\nLemma 2: Let $X\\sim F$ and $X\\sim -X$, then $\\forall x: F(-x)=1-F(x)$:\n$$F(-x)=P(X<-x)+\\frac{1}{2}P(X=-x)=P(xThe Mann-Whitney U test (MWUt) tests stochastic homogeneity (also sometimes called stochastic equality). The alternative hypothesis being stochastic superiority. After all, Mann & Whitney titled their paper

\n
\n

Mann, H. B., Whitney, D. R. (1947) “On a test of whether one of two\nrandom variables is stochastically larger than the other”

\n
\n

The MWUt is consistent (i.e. “the outcome of the procedure converges to the correct outcome as sample size goes to infinity”) only under the following null hypothesis\n$$p=P(X_1<X_2)+\\frac{1}{2}P(X_1=X_2) = 0.5$$\nWhich can also be written as\n$$P(X_1<X_2) = P(X_2<X_1)$$ (ignoring the “ties”)

\n

That null is true under only 2 scenarios;

\n
    \n
  1. the 2 samples come from the exact same distribution (i.e. $F_1=F_2$); all moments, including mean, are the same, or
  2. \n
  3. the 2 samples come from symmetric, but possibly different, distributions, symmetric around the same median (and hence mean).
  4. \n
\n

These are the only 2 cases where there is no stochastic ordering; otherwise, one distribution is stochastically superior to the other, and the rejection rate will increase with sample size, as it should.\\

\n

So, if you assume that $\\exists \\delta:\\forall x:F_2(x)=F_1(x+\\delta)$, then indeed $\\delta = 0$ and $p=1/2$ are equivalent.

\n

However, this assumption is a very bold assumption, and the MWUt is absolutely not robust to departures from this assumption.\nMoreover, you could get $p=1/2$ w/o a shift model, e.g. in the case of 2 symmetric distributions around the same mean/median (e.g. $N(0,1)$ and $Unif(-1,1)$). You will have $p=1/2$, but you certainly will not have $F_2(x)=F_1(x+\\delta)$.

\n

So, in general, the null hypothesis of the MWUt is not $F_1=F_2$ (it is instead $p=1/2$). It can become $F_1=F_2$ if you can rule out symmetry of at least one of the 2 distributions. And the location shift assumption is so unlikely (and the test not robust to it) as to invalidate any results based on it.

\n

Last, even if the MWUt could be used as a test of $F_1=F_2$, what would you do if you have a significant result? So what if $F_1 \\ne F_2$? Which is the "best", which decision do you make? Whereas knowing which distribution is stochastically superior is useful, and has practical implications (a randomly selected observation from one distribution is more likely than not to be greater than a randomnly selected observation from the other). By contrast, knowing that the 2 distributions are not identical is not actionable. So even if one could find assumptions under which that null was valid, it would be of no practical value...

\n", "answer_id": 677073, "answer_text": "The Mann-Whitney U test (MWUt) tests stochastic homogeneity (also sometimes called stochastic equality). The alternative hypothesis being stochastic superiority. After all, Mann & Whitney titled their paper\n\n\n\n\n\n\n\nMann, H. B., Whitney, D. R. (1947) “On a test of whether one of two\nrandom variables is stochastically larger than the other”\n\n\n\n\n\n\n\nThe MWUt is consistent (i.e. “the outcome of the procedure converges to the correct outcome as sample size goes to infinity (https://en.wikipedia.org/wiki/Consistency_(statistics))”) only under the following null hypothesis\n$$p=P(X_1Yes, that equivalence holds\n

From the definition of $p$ we have:

\n

$$\\begin{align}\np\n&= \\mathbb{P}(X_1<X_2) + \\frac{1}{2} \\cdot \\mathbb{P}(X_1=X_2), \\\\[6pt]\n1-p\n&= \\mathbb{P}(X_1>X_2) + \\frac{1}{2} \\cdot \\mathbb{P}(X_1=X_2). \\\\[6pt]\n\\end{align}$$

\n

Consequently, we have:

\n

$$1-2p = (1-p) - p = \\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1<X_2),$$

\n

which implies that:

\n

$$p = \\tfrac{1}{2}\n\\quad \\quad \\iff \\quad \\quad \n1-2p=0\n\\quad \\quad \\iff \\quad \\quad \n\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2).$$

\n

Since the distributions of $X_1$ and $X_2$ vary only by a location shift, it is also simple to establish (see below) that:

\n

$$\\delta = 0\n\\quad \\quad \\iff \\quad \\quad \n\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2).$$

\n

Consequently, the equivalence between $p=\\tfrac{1}{2}$ and $\\delta=0$ holds.

\n
\n

Proving the latter equivalence: Since $X_1$ and $X_2$ are independent we have:

\n

$$\\begin{align}\n\\mathbb{P}(X_1 < X_2) \n&= 1- \\int \\limits_0^\\infty F_2(x) \\ dF_1(x) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x) \\ dF_2(x-\\delta) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x+\\delta) \\ dF_2(x), \\\\[6pt]\n\\mathbb{P}(X_1 > X_2) \n&= 1- \\int \\limits_0^\\infty F_1(x) dF_2(x) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x-\\delta) dF_2(x), \\\\[6pt]\n\\end{align}$$

\n

which gives:

\n

$$\\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1<X_2)\n= \\int \\limits_0^\\infty [ F_2(x-\\delta) - F_2(x+\\delta)] \\ dF_2(x).$$

\n

The integrand is zero when $\\delta=0$ and is non-negative or non-positive if $\\delta \\neq 0$. If $\\delta=0$ then we obtain $\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2)$ directly. If $\\mathbb{P}(X_1>X_2) = \\mathbb{P}(X_1<X_2)$ then the integrand in the above expression must be zero almost surely over the range of integration, which can only occur if $\\delta=0$.

\n", "answer_id": 677074, "answer_text": "Yes, that equivalence holds\n\n\n\n\nFrom the definition of $p$ we have:\n\n\n\n\n$$\\begin{align}\np\n&= \\mathbb{P}(X_1X_2) + \\frac{1}{2} \\cdot \\mathbb{P}(X_1=X_2). \\\\[6pt]\n\\end{align}$$\n\n\n\n\nConsequently, we have:\n\n\n\n\n$$1-2p = (1-p) - p = \\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1 X_2) \n&= 1- \\int \\limits_0^\\infty F_1(x) dF_2(x) \\\\[6pt]\n&= 1- \\int \\limits_0^\\infty F_2(x-\\delta) dF_2(x), \\\\[6pt]\n\\end{align}$$\n\n\n\n\nwhich gives:\n\n\n\n\n$$\\mathbb{P}(X_1>X_2) - \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1X_2) = \\mathbb{P}(X_1There are good answers to the main point as the question now stands. Here I will address where restriction to a location-shift alternative (on the observed variable) may make sense, or might not.

\n
    \n
  1. A continuous variable defined over $\\mathbb{R}$. There's no immediate issue there, and I think pure shift alternatives may make sense in some applications (at least as approximate descriptions).

    \n
  2. \n
  3. A continous variable with a lower bound (e.g. a variate with support on $\\mathbb{R}^+$) or with an upper bound, or both. Here the support shifts. For example, if a variate has some lowest possible value then either you must assume only positive shifts are possible or that there is no possibility of any values larger than an allowed left shift can occur (i.e. you need to begin by positing that the actual support of the unshifted variable is different from the stated support). Otherwise you can't make $F$'s correspond in the stated fashion.

    \n

    For most continuous distributions with a bound that are in common use, and also with many real world variables, the idea of a pure location shift doesn't really work - but the Mann-Whitney works fine beyond that case. Indeed they state in the 1947 paper "The test is shown to be consistent with respect to the class of alternatives $f(x)>g(x)$ for every $x$" where here $f$ and $g$ have been defined to be continuous cdfs (side note: $f>g$ means values drawn from $f$ tend to be smaller). It would be consistent for a somewhat broader class of alternatives but I don't want to head off on a side issue just now.

    \n

    For many continuous variables on $\\mathbb{R}^+$ a scale shift alternative would make more sense, and for many variables on a bounded interval, a change of shape is to be expected (if the actual and stated support correspond it's going to be hard to avoid it).

    \n
  4. \n
  5. A discrete random variate with support on a lattice. Here only shifts of multiples of the lattice interval (that also respect any bounds) are possible (unless we also shift the support by $\\delta$, of course, but this rarely makes sense).

    \n
  6. \n
  7. A discrete random variate with support on a countable set that is not on a lattice (e.g. imagine a test where we have applied a square-root transformation to a count). Here it doesn't seem to work at all without changing the support.

    \n
  8. \n
  9. An ordinal variable*. Now we have a problem of even defining an $F$, but let us assume we can define some set of (unknown, not equally-spaced) values or intervals between them on which it has support, where we have then given the unknown values or intervals arbitrary (but order-preserving) labels. This situation has all the difficulties of case 4 but worse - here we can't define a shift of $\\delta$ on the labels that makes sense, and we don't have access to the unknown values they stand for, but if we could solve that, we still have the issue with the support we had in point 4.

    \n
  10. \n
\n
\n

* The original question posited an ordinal variable. It doesn't do so now (to the better, since case 5 is problematic), but I leave discussion of this case in my answer because it seems to be a very common situation for people to use the Wilcoxon-Mann-Whitney test on ordinal responses and then very often talk about (or at least imply at some point) a location shift alternative.

\n", "answer_id": 677076, "answer_text": "There are good answers to the main point as the question now stands. Here I will address where restriction to a location-shift alternative (on the observed variable) may make sense, or might not.\n\n\n\n\n\n\n\nA continuous variable defined over $\\mathbb{R}$. There's no immediate issue there, and I think pure shift alternatives may make sense in some applications (at least as approximate descriptions).\n\n\n\n\n\n\n\n\n\nA continous variable with a lower bound (e.g. a variate with support on $\\mathbb{R}^+$) or with an upper bound, or both. Here the support shifts. For example, if a variate has some lowest possible value then either you must assume only positive shifts are possible or that there is no possibility of any values larger than an allowed left shift can occur (i.e. you need to begin by positing that the actual support of the unshifted variable is different from the stated support). Otherwise you can't make $F$'s correspond in the stated fashion.\n\n\n\n\nFor most continuous distributions with a bound that are in common use, and also with many real world variables, the idea of a pure location shift doesn't really work - but the Mann-Whitney works fine beyond that case. Indeed they state in the 1947 paper \"The test is shown to be consistent with respect to the class of alternatives $f(x)>g(x)$ for every $x$\" where here $f$ and $g$ have been defined to be continuous cdfs (side note: $f>g$ means values drawn from $f$ tend to be smaller). It would be consistent for a somewhat broader class of alternatives but I don't want to head off on a side issue just now.\n\n\n\n\nFor many continuous variables on $\\mathbb{R}^+$ a scale shift alternative would make more sense, and for many variables on a bounded interval, a change of shape is to be expected (if the actual and stated support correspond it's going to be hard to avoid it).\n\n\n\n\n\n\n\n\n\nA discrete random variate with support on a lattice. Here only shifts of multiples of the lattice interval (that also respect any bounds) are possible (unless we also shift the support by $\\delta$, of course, but this rarely makes sense).\n\n\n\n\n\n\n\n\n\nA discrete random variate with support on a countable set that is not on a lattice (e.g. imagine a test where we have applied a square-root transformation to a count). Here it doesn't seem to work at all without changing the support.\n\n\n\n\n\n\n\n\n\nAn ordinal variable*. Now we have a problem of even defining an $F$, but let us assume we can define some set of (unknown, not equally-spaced) values or intervals between them on which it has support, where we have then given the unknown values or intervals arbitrary (but order-preserving) labels. This situation has all the difficulties of case 4 but worse - here we can't define a shift of $\\delta$ on the labels that makes sense, and we don't have access to the unknown values they stand for, but if we could solve that, we still have the issue with the support we had in point 4.\n\n\n\n\n\n\n\n\n\n\n\n* The original question posited an ordinal variable. It doesn't do so now (to the better, since case 5 is problematic), but I leave discussion of this case in my answer because it seems to be a very common situation for people to use the Wilcoxon-Mann-Whitney test on ordinal responses and then very often talk about (or at least imply at some point) a location shift alternative.", "answer_url": "https://stats.stackexchange.com/a/677076", "author": "Glen_b", "author_url": "https://stats.stackexchange.com/users/805/glen-b", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-05T02:08:47+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": 677071, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-05T02:08:47+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "19744E33-32C1-42E6-8B19-EF45E4EFB08C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/19744E33-32C1-42E6-8B19-EF45E4EFB08C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-05T02:15:47+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "CF826F38-A814-44FE-98C7-7558264B9395", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CF826F38-A814-44FE-98C7-7558264B9395/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-05T09:13:58+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "3504ADB8-E74F-4904-A022-B3D8AF1388A2", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3504ADB8-E74F-4904-A022-B3D8AF1388A2/view-source"}], "score": 4, "updated_at": "2026-09-05T09:13:58+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1007/978-3-030-02914-2", "https://en.wikipedia.org/wiki/Consistency_(statistics"], "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": "Filippo", "question_author_url": "https://stats.stackexchange.com/users/461971/filippo", "question_author_user_type": "registered", "question_created_at": "2026-09-04T18:49:42+00:00", "question_html": "

Suppose that $X_1$ and $X_2$ are real-valued random variables and $X_i\\sim F_i$, i.e., $F_i$ is the CDF of $X_i$. Furthermore, assume the Location shift model:\n$$\\exists \\delta:\\forall x:F_2(x)=F_1(x+\\delta)$$\nFinally, consider the probabilistic index\n$$p=P(X_1<X_2)+\\frac{1}{2}P(X_1=X_2).$$\nIs it true that $\\delta = 0$ if and only if $p=1/2$?

\n

Context: This question arose while discussing a statistical analysis plan, a collegue wanted to test the hypothesis $H_0:p=1/2$ using the WMW-test, so I pointed that the WMW-test actually tests the hypothesis $H_0:F_1=F_2$. So my colleague conjectured that the hypotheses are equal under the Location shift model.

\n", "question_id": 677071, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "Suppose that $X_1$ and $X_2$ are real-valued random variables and $X_i\\sim F_i$, i.e., $F_i$ is the CDF of $X_i$. Furthermore, assume the Location shift model:\n$$\\exists \\delta:\\forall x:F_2(x)=F_1(x+\\delta)$$\nFinally, consider the probabilistic index\n$$p=P(X_1I see what's going on here. When refit = F DHARMa uses raw residuals and your raw response values are kind of crazy. 90% are zero, the second biggest number is 7 and then it maxes out at 18:

\n
# library(tidyverse)\n> shiny_toad %>%  group_by(total_count) %>% \n+   summarise(n()) #%>% \n# A tibble: 8 × 2\n  total_count `n()`\n        <dbl> <int>\n1           0   985\n2           1   102\n3           2    34\n4           3    10\n5           4    10\n6           5     2\n7           7     1\n8          18     1\n
\n

As a Pearson residual, which DHARMa uses at refit = T, the 18 is just a bit over 2, so "fine". I maintain that your negative binomial model is perfectly compatible with your data, but you just don't have much data in the range where 18 is evidently possible, at least not compared with how rare they are.\nSimulations/forecasts will therefore be very uncertain. Inference about means might not be.

\n

I couldn't run your model directly (variables like fDiet_presence are missing) but this is something you could replicate:

\n
x <- predict(full_model)\nplot(x, shiny_toad$total_count, ylim = c(0, 25), xlim = c(-2, 1.1))\n# takes a few seconds\nfor (i in 1:250)\n  points(x, simulationOutput$simulatedResponse[, i], col = rgb(1,0,0, alpha = 0.05), pch = 19)\npoints(x, shiny_toad$total_count)\ncurve(exp(x), add = T)\ncurve(qnbinom(0.99, size = 0.582, mu = exp(x)), add = T \n
\n

\"plotting

\n", "answer_id": 677089, "answer_text": "I see what's going on here. When refit = F DHARMa uses raw residuals and your raw response values are kind of crazy. 90% are zero, the second biggest number is 7 and then it maxes out at 18:\n\n\n\n\n# library(tidyverse)\n> shiny_toad %>% group_by(total_count) %>% \n+ summarise(n()) #%>% \n# A tibble: 8 × 2\n total_count `n()`\n \n1 0 985\n2 1 102\n3 2 34\n4 3 10\n5 4 10\n6 5 2\n7 7 1\n8 18 1\n\n\n\n\n\nAs a Pearson residual, which DHARMa uses at refit = T, the 18 is just a bit over 2, so \"fine\". I maintain that your negative binomial model is perfectly compatible with your data, but you just don't have much data in the range where 18 is evidently possible, at least not compared with how rare they are.\nSimulations/forecasts will therefore be very uncertain. Inference about means might not be.\n\n\n\n\nI couldn't run your model directly (variables like fDiet_presence are missing) but this is something you could replicate:\n\n\n\n\nx <- predict(full_model)\nplot(x, shiny_toad$total_count, ylim = c(0, 25), xlim = c(-2, 1.1))\n# takes a few seconds\nfor (i in 1:250)\n points(x, simulationOutput$simulatedResponse[, i], col = rgb(1,0,0, alpha = 0.05), pch = 19)\npoints(x, shiny_toad$total_count)\ncurve(exp(x), add = T)\ncurve(qnbinom(0.99, size = 0.582, mu = exp(x)), add = T \n\n\n\n\n\n[image: plotting total counts vs model prediction underlayed with the red simulations from DHARMa. Hard to describe what we see exactly. ; source: https://i.sstatic.net/MLdk1fpB.png] (https://i.sstatic.net/MLdk1fpB.png)", "answer_url": "https://stats.stackexchange.com/a/677089", "author": "Lukas Lohse", "author_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-06T14:51:53+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": 677079, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lukas Lohse", "profile_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "user_type": "registered"}, "created_at": "2026-09-06T14:51:53+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "B8B4DF5B-86F9-405A-8C4F-7FB2BEF69F45", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B8B4DF5B-86F9-405A-8C4F-7FB2BEF69F45/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-06T17:41:01+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "5F1F9165-30E6-48DD-BBC0-9D1AC05FFE35", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/5F1F9165-30E6-48DD-BBC0-9D1AC05FFE35/view-source"}], "score": 5, "updated_at": "2026-09-06T17:41:01+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "Are long tails in a fitted vs. simulated residuals plot from DHARMa a sign of over-fitting (or any other issues)? Do they make the test for dispersion overly optimistic (p-value > 0.05)? I'm not sure if this is a problem simply because it's not significant, but are there ways to model theta in mgcv? Is it necessary here? No zero-inflation: ratioObsSim = 0.9977, p-value = 0.864, and only 1 outlier more than expected: outliers at both margin(s) = 1, observations = 1145, p-value = 0.36.\n\n\n\n\nData here (https://github.com/NateLaS/Toadfish/blob/main/share_version%20-%20toadfish.csv)\n\n\n\n\nshiny_toad$fSeason <- as.factor(shiny_toad$fSeason)\nshiny_toad$fSite <- as.factor(shiny_toad$fSite)\nshiny_toad$fCYR <- as.factor(shiny_toad$fCYR)\n\nshiny_toad$fDiet_presence <- as.factor(shiny_toad$fDiet_presence)\nshiny_toad$fDiet_presence <- relevel(shiny_toad$fDiet_presence, ref = \"no food\")\n\nlibrary(mgcv)\nlibrary(DHARMa)\n\nsystem.time(\n full_model <- gam(total_count ~ \n \n offset(log(area_sampled)) +\n \n s(CYR, by = fSeason) +\n fSeason + \n \n s(sal, bs=\"ts\", k=5) +\n s(DO, bs=\"ts\", k=5) +\n\n s(ave_sav, by = fDiet_presence) +\n fDiet_presence +\n \n s(fSite, bs=\"re\"),\n \n data = shiny_toad,\n method = \"REML\", \n family = nb(link = \"log\"),\n select = FALSE, \n \n drop.unused.levels = FALSE, \n control = list(trace = TRUE))\n)\n\n> simulationOutput <- simulateResiduals(fittedModel = full_model)\n> testDispersion(simulationOutput)\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs.\n simulated\n\ndata: simulationOutput\ndispersion = 1.151, p-value = 0.44\nalternative hypothesis: two.sided\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/JpiINT52.png] (https://i.sstatic.net/JpiINT52.png)", "record_id": "Scientific-Statistics-QA:stats:677079", "selected_answer": {"answer_html": "

I see what's going on here. When refit = F DHARMa uses raw residuals and your raw response values are kind of crazy. 90% are zero, the second biggest number is 7 and then it maxes out at 18:

\n
# library(tidyverse)\n> shiny_toad %>%  group_by(total_count) %>% \n+   summarise(n()) #%>% \n# A tibble: 8 × 2\n  total_count `n()`\n        <dbl> <int>\n1           0   985\n2           1   102\n3           2    34\n4           3    10\n5           4    10\n6           5     2\n7           7     1\n8          18     1\n
\n

As a Pearson residual, which DHARMa uses at refit = T, the 18 is just a bit over 2, so "fine". I maintain that your negative binomial model is perfectly compatible with your data, but you just don't have much data in the range where 18 is evidently possible, at least not compared with how rare they are.\nSimulations/forecasts will therefore be very uncertain. Inference about means might not be.

\n

I couldn't run your model directly (variables like fDiet_presence are missing) but this is something you could replicate:

\n
x <- predict(full_model)\nplot(x, shiny_toad$total_count, ylim = c(0, 25), xlim = c(-2, 1.1))\n# takes a few seconds\nfor (i in 1:250)\n  points(x, simulationOutput$simulatedResponse[, i], col = rgb(1,0,0, alpha = 0.05), pch = 19)\npoints(x, shiny_toad$total_count)\ncurve(exp(x), add = T)\ncurve(qnbinom(0.99, size = 0.582, mu = exp(x)), add = T \n
\n

\"plotting

\n", "answer_id": 677089, "answer_text": "I see what's going on here. When refit = F DHARMa uses raw residuals and your raw response values are kind of crazy. 90% are zero, the second biggest number is 7 and then it maxes out at 18:\n\n\n\n\n# library(tidyverse)\n> shiny_toad %>% group_by(total_count) %>% \n+ summarise(n()) #%>% \n# A tibble: 8 × 2\n total_count `n()`\n \n1 0 985\n2 1 102\n3 2 34\n4 3 10\n5 4 10\n6 5 2\n7 7 1\n8 18 1\n\n\n\n\n\nAs a Pearson residual, which DHARMa uses at refit = T, the 18 is just a bit over 2, so \"fine\". I maintain that your negative binomial model is perfectly compatible with your data, but you just don't have much data in the range where 18 is evidently possible, at least not compared with how rare they are.\nSimulations/forecasts will therefore be very uncertain. Inference about means might not be.\n\n\n\n\nI couldn't run your model directly (variables like fDiet_presence are missing) but this is something you could replicate:\n\n\n\n\nx <- predict(full_model)\nplot(x, shiny_toad$total_count, ylim = c(0, 25), xlim = c(-2, 1.1))\n# takes a few seconds\nfor (i in 1:250)\n points(x, simulationOutput$simulatedResponse[, i], col = rgb(1,0,0, alpha = 0.05), pch = 19)\npoints(x, shiny_toad$total_count)\ncurve(exp(x), add = T)\ncurve(qnbinom(0.99, size = 0.582, mu = exp(x)), add = T \n\n\n\n\n\n[image: plotting total counts vs model prediction underlayed with the red simulations from DHARMa. Hard to describe what we see exactly. ; source: https://i.sstatic.net/MLdk1fpB.png] (https://i.sstatic.net/MLdk1fpB.png)", "answer_url": "https://stats.stackexchange.com/a/677089", "author": "Lukas Lohse", "author_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-06T14:51:53+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": 677079, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lukas Lohse", "profile_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "user_type": "registered"}, "created_at": "2026-09-06T14:51:53+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "B8B4DF5B-86F9-405A-8C4F-7FB2BEF69F45", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B8B4DF5B-86F9-405A-8C4F-7FB2BEF69F45/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-06T17:41:01+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "5F1F9165-30E6-48DD-BBC0-9D1AC05FFE35", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/5F1F9165-30E6-48DD-BBC0-9D1AC05FFE35/view-source"}], "score": 5, "updated_at": "2026-09-06T17:41:01+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677089, "answers": [{"answer_html": "

I see what's going on here. When refit = F DHARMa uses raw residuals and your raw response values are kind of crazy. 90% are zero, the second biggest number is 7 and then it maxes out at 18:

\n
# library(tidyverse)\n> shiny_toad %>%  group_by(total_count) %>% \n+   summarise(n()) #%>% \n# A tibble: 8 × 2\n  total_count `n()`\n        <dbl> <int>\n1           0   985\n2           1   102\n3           2    34\n4           3    10\n5           4    10\n6           5     2\n7           7     1\n8          18     1\n
\n

As a Pearson residual, which DHARMa uses at refit = T, the 18 is just a bit over 2, so "fine". I maintain that your negative binomial model is perfectly compatible with your data, but you just don't have much data in the range where 18 is evidently possible, at least not compared with how rare they are.\nSimulations/forecasts will therefore be very uncertain. Inference about means might not be.

\n

I couldn't run your model directly (variables like fDiet_presence are missing) but this is something you could replicate:

\n
x <- predict(full_model)\nplot(x, shiny_toad$total_count, ylim = c(0, 25), xlim = c(-2, 1.1))\n# takes a few seconds\nfor (i in 1:250)\n  points(x, simulationOutput$simulatedResponse[, i], col = rgb(1,0,0, alpha = 0.05), pch = 19)\npoints(x, shiny_toad$total_count)\ncurve(exp(x), add = T)\ncurve(qnbinom(0.99, size = 0.582, mu = exp(x)), add = T \n
\n

\"plotting

\n", "answer_id": 677089, "answer_text": "I see what's going on here. When refit = F DHARMa uses raw residuals and your raw response values are kind of crazy. 90% are zero, the second biggest number is 7 and then it maxes out at 18:\n\n\n\n\n# library(tidyverse)\n> shiny_toad %>% group_by(total_count) %>% \n+ summarise(n()) #%>% \n# A tibble: 8 × 2\n total_count `n()`\n \n1 0 985\n2 1 102\n3 2 34\n4 3 10\n5 4 10\n6 5 2\n7 7 1\n8 18 1\n\n\n\n\n\nAs a Pearson residual, which DHARMa uses at refit = T, the 18 is just a bit over 2, so \"fine\". I maintain that your negative binomial model is perfectly compatible with your data, but you just don't have much data in the range where 18 is evidently possible, at least not compared with how rare they are.\nSimulations/forecasts will therefore be very uncertain. Inference about means might not be.\n\n\n\n\nI couldn't run your model directly (variables like fDiet_presence are missing) but this is something you could replicate:\n\n\n\n\nx <- predict(full_model)\nplot(x, shiny_toad$total_count, ylim = c(0, 25), xlim = c(-2, 1.1))\n# takes a few seconds\nfor (i in 1:250)\n points(x, simulationOutput$simulatedResponse[, i], col = rgb(1,0,0, alpha = 0.05), pch = 19)\npoints(x, shiny_toad$total_count)\ncurve(exp(x), add = T)\ncurve(qnbinom(0.99, size = 0.582, mu = exp(x)), add = T \n\n\n\n\n\n[image: plotting total counts vs model prediction underlayed with the red simulations from DHARMa. Hard to describe what we see exactly. ; source: https://i.sstatic.net/MLdk1fpB.png] (https://i.sstatic.net/MLdk1fpB.png)", "answer_url": "https://stats.stackexchange.com/a/677089", "author": "Lukas Lohse", "author_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-06T14:51:53+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": 677079, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lukas Lohse", "profile_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "user_type": "registered"}, "created_at": "2026-09-06T14:51:53+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "B8B4DF5B-86F9-405A-8C4F-7FB2BEF69F45", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B8B4DF5B-86F9-405A-8C4F-7FB2BEF69F45/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-06T17:41:01+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "5F1F9165-30E6-48DD-BBC0-9D1AC05FFE35", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/5F1F9165-30E6-48DD-BBC0-9D1AC05FFE35/view-source"}], "score": 5, "updated_at": "2026-09-06T17:41:01+00:00"}], "domain": "statistics", "external_links": ["https://github.com/NateLaS/Toadfish/blob/main/share_version%20-%20toadfish.csv", "https://i.sstatic.net/JpiINT52.png", "https://i.sstatic.net/MLdk1fpB.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": "Nate", "question_author_url": "https://stats.stackexchange.com/users/337106/nate", "question_author_user_type": "registered", "question_created_at": "2026-09-05T17:50:46+00:00", "question_html": "

Are long tails in a fitted vs. simulated residuals plot from DHARMa a sign of over-fitting (or any other issues)? Do they make the test for dispersion overly optimistic (p-value > 0.05)? I'm not sure if this is a problem simply because it's not significant, but are there ways to model theta in mgcv? Is it necessary here? No zero-inflation: ratioObsSim = 0.9977, p-value = 0.864, and only 1 outlier more than expected: outliers at both margin(s) = 1, observations = 1145, p-value = 0.36.

\n

Data here

\n
shiny_toad$fSeason <- as.factor(shiny_toad$fSeason)\nshiny_toad$fSite <- as.factor(shiny_toad$fSite)\nshiny_toad$fCYR <- as.factor(shiny_toad$fCYR)\n\nshiny_toad$fDiet_presence <- as.factor(shiny_toad$fDiet_presence)\nshiny_toad$fDiet_presence <- relevel(shiny_toad$fDiet_presence, ref = "no food")\n\nlibrary(mgcv)\nlibrary(DHARMa)\n\nsystem.time(\n  full_model <- gam(total_count ~ \n              \n              offset(log(area_sampled)) +\n              \n              s(CYR, by = fSeason) +\n              fSeason + \n              \n              s(sal, bs="ts", k=5) +\n              s(DO, bs="ts", k=5) +\n\n              s(ave_sav, by = fDiet_presence) +\n              fDiet_presence +\n              \n              s(fSite, bs="re"),\n            \n            data = shiny_toad,\n            method = "REML", \n            family = nb(link = "log"),\n            select = FALSE, \n            \n            drop.unused.levels = FALSE, \n            control = list(trace = TRUE))\n)\n\n> simulationOutput <- simulateResiduals(fittedModel = full_model)\n> testDispersion(simulationOutput)\n\n    DHARMa nonparametric dispersion test via sd of residuals fitted vs.\n    simulated\n\ndata:  simulationOutput\ndispersion = 1.151, p-value = 0.44\nalternative hypothesis: two.sided\n
\n

\"enter

\n", "question_id": 677079, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "Are long tails in a fitted vs. simulated residuals plot from DHARMa a sign of over-fitting (or any other issues)? Do they make the test for dispersion overly optimistic (p-value > 0.05)? I'm not sure if this is a problem simply because it's not significant, but are there ways to model theta in mgcv? Is it necessary here? No zero-inflation: ratioObsSim = 0.9977, p-value = 0.864, and only 1 outlier more than expected: outliers at both margin(s) = 1, observations = 1145, p-value = 0.36.\n\n\n\n\nData here (https://github.com/NateLaS/Toadfish/blob/main/share_version%20-%20toadfish.csv)\n\n\n\n\nshiny_toad$fSeason <- as.factor(shiny_toad$fSeason)\nshiny_toad$fSite <- as.factor(shiny_toad$fSite)\nshiny_toad$fCYR <- as.factor(shiny_toad$fCYR)\n\nshiny_toad$fDiet_presence <- as.factor(shiny_toad$fDiet_presence)\nshiny_toad$fDiet_presence <- relevel(shiny_toad$fDiet_presence, ref = \"no food\")\n\nlibrary(mgcv)\nlibrary(DHARMa)\n\nsystem.time(\n full_model <- gam(total_count ~ \n \n offset(log(area_sampled)) +\n \n s(CYR, by = fSeason) +\n fSeason + \n \n s(sal, bs=\"ts\", k=5) +\n s(DO, bs=\"ts\", k=5) +\n\n s(ave_sav, by = fDiet_presence) +\n fDiet_presence +\n \n s(fSite, bs=\"re\"),\n \n data = shiny_toad,\n method = \"REML\", \n family = nb(link = \"log\"),\n select = FALSE, \n \n drop.unused.levels = FALSE, \n control = list(trace = TRUE))\n)\n\n> simulationOutput <- simulateResiduals(fittedModel = full_model)\n> testDispersion(simulationOutput)\n\n DHARMa nonparametric dispersion test via sd of residuals fitted vs.\n simulated\n\ndata: simulationOutput\ndispersion = 1.151, p-value = 0.44\nalternative hypothesis: two.sided\n\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/JpiINT52.png] (https://i.sstatic.net/JpiINT52.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nate", "profile_url": "https://stats.stackexchange.com/users/337106/nate", "user_type": "registered"}, "created_at": "2026-09-05T17:50:46+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "62485478-1E70-4507-A25A-EFD7CF98BE71", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/62485478-1E70-4507-A25A-EFD7CF98BE71/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nate", "profile_url": "https://stats.stackexchange.com/users/337106/nate", "user_type": "registered"}, "created_at": "2026-09-05T18:00:15+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "20C1E059-9409-4237-A047-3AC90CDF12F1", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/20C1E059-9409-4237-A047-3AC90CDF12F1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nate", "profile_url": "https://stats.stackexchange.com/users/337106/nate", "user_type": "registered"}, "created_at": "2026-09-06T11:10:30+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "218741D1-87E1-45D3-9356-2175B506F115", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/218741D1-87E1-45D3-9356-2175B506F115/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nate", "profile_url": "https://stats.stackexchange.com/users/337106/nate", "user_type": "registered"}, "created_at": "2026-09-06T16:02:30+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "68679B7E-46AA-465C-8DEB-E7300F26A45C", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/68679B7E-46AA-465C-8DEB-E7300F26A45C/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-06T16:44:53+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "FCE33A0B-2FF0-443A-AAE5-C039C64F1D4A", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/FCE33A0B-2FF0-443A-AAE5-C039C64F1D4A/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677079/dharma-are-long-tails-in-dispersion-plot-a-problem", "split": "train", "split_group": "04a77f3456ebfb67020241072d2e6012e18b8e493f7d3df8ca4d468735284bb3", "tags": ["overfitting", "mgcv", "overdispersion", "dharma"], "thread_id": "stats:677079", "title": "DHARMa: Are long tails in dispersion plot a problem?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I'm a student writing a research proposal using data from a longitudinal larger project. I have childhood abuse (IV) measured once in 2022, intimacy aversion (DV) measured once in 2026, and partner's responsiveness (moderator?) measured longitudinally since 2019-2026.\n\n\n\n\nCan I run a longitudinal moderation to examine the influence of IV on DV, in which partner's responsiveness across time will be included as a longitudinal moderator? How would that work and how would that be explained in words?\n\n\n\n\nOr does it make more sense to compare people who have experienced childhood abuse vs those who haven't?", "record_id": "Scientific-Statistics-QA:stats:677083", "selected_answer": {"answer_html": "

I don’t think the repeated measures of responsiveness need to be kept that way for this particular design. If your dependent variable was also measured from 2019-2026, then it would make more sense to have a time-dependent covariate. But you don’t have a true longitudinal model since your DV is only measured once.

\n

The simplest thing to do would be to pick some summary of the responsiveness measure for each person and use that to moderate the $\\text{Aversion} \\sim \\text{Abuse}$ relationship. Depending on your question it could be mean responsiveness, change in responsiveness etc.

\n

All of this still allows you to test whether aversion is different between those with and without abuse histories and then allows you to ask if that difference depends on responsiveness.

\n", "answer_id": 677091, "answer_text": "I don’t think the repeated measures of responsiveness need to be kept that way for this particular design. If your dependent variable was also measured from 2019-2026, then it would make more sense to have a time-dependent covariate. But you don’t have a true longitudinal model since your DV is only measured once.\n\n\n\n\nThe simplest thing to do would be to pick some summary of the responsiveness measure for each person and use that to moderate the $\\text{Aversion} \\sim \\text{Abuse}$ relationship. Depending on your question it could be mean responsiveness, change in responsiveness etc.\n\n\n\n\nAll of this still allows you to test whether aversion is different between those with and without abuse histories and then allows you to ask if that difference depends on responsiveness.", "answer_url": "https://stats.stackexchange.com/a/677091", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-06T17:15:25+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": 677083, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-06T17:15:25+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "1038A4E9-3670-470E-A23F-A3EAAC938289", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1038A4E9-3670-470E-A23F-A3EAAC938289/view-source"}], "score": 5, "updated_at": "2026-09-06T17:15:25+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

I don’t think the repeated measures of responsiveness need to be kept that way for this particular design. If your dependent variable was also measured from 2019-2026, then it would make more sense to have a time-dependent covariate. But you don’t have a true longitudinal model since your DV is only measured once.

\n

The simplest thing to do would be to pick some summary of the responsiveness measure for each person and use that to moderate the $\\text{Aversion} \\sim \\text{Abuse}$ relationship. Depending on your question it could be mean responsiveness, change in responsiveness etc.

\n

All of this still allows you to test whether aversion is different between those with and without abuse histories and then allows you to ask if that difference depends on responsiveness.

\n", "answer_id": 677091, "answer_text": "I don’t think the repeated measures of responsiveness need to be kept that way for this particular design. If your dependent variable was also measured from 2019-2026, then it would make more sense to have a time-dependent covariate. But you don’t have a true longitudinal model since your DV is only measured once.\n\n\n\n\nThe simplest thing to do would be to pick some summary of the responsiveness measure for each person and use that to moderate the $\\text{Aversion} \\sim \\text{Abuse}$ relationship. Depending on your question it could be mean responsiveness, change in responsiveness etc.\n\n\n\n\nAll of this still allows you to test whether aversion is different between those with and without abuse histories and then allows you to ask if that difference depends on responsiveness.", "answer_url": "https://stats.stackexchange.com/a/677091", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-06T17:15:25+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": 677083, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-06T17:15:25+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "1038A4E9-3670-470E-A23F-A3EAAC938289", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1038A4E9-3670-470E-A23F-A3EAAC938289/view-source"}], "score": 5, "updated_at": "2026-09-06T17:15:25+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "user516319", "question_author_url": "https://stats.stackexchange.com/users/516319/user516319", "question_author_user_type": "unregistered", "question_created_at": "2026-09-05T21:48:18+00:00", "question_html": "

I'm a student writing a research proposal using data from a longitudinal larger project. I have childhood abuse (IV) measured once in 2022, intimacy aversion (DV) measured once in 2026, and partner's responsiveness (moderator?) measured longitudinally since 2019-2026.

\n

Can I run a longitudinal moderation to examine the influence of IV on DV, in which partner's responsiveness across time will be included as a longitudinal moderator? How would that work and how would that be explained in words?

\n

Or does it make more sense to compare people who have experienced childhood abuse vs those who haven't?

\n", "question_id": 677083, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "I'm a student writing a research proposal using data from a longitudinal larger project. I have childhood abuse (IV) measured once in 2022, intimacy aversion (DV) measured once in 2026, and partner's responsiveness (moderator?) measured longitudinally since 2019-2026.\n\n\n\n\nCan I run a longitudinal moderation to examine the influence of IV on DV, in which partner's responsiveness across time will be included as a longitudinal moderator? How would that work and how would that be explained in words?\n\n\n\n\nOr does it make more sense to compare people who have experienced childhood abuse vs those who haven't?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "user516319", "profile_url": "https://stats.stackexchange.com/users/516319/user516319", "user_type": "unregistered"}, "created_at": "2026-09-05T21:48:18+00:00", "raw_file": "raw/codex_api_v1/64ee278f47b21ead17c9e9fc156835d607f15cff0518af0117a527463a68df8a_1790825256327661600_0.json", "raw_sha256": "18d894000304f6d836d0b21a9f2f35d37c183b3d25e32a897338c6dff012df04", "revision_guid": "306D99C3-CCDC-4A04-B23D-F232041FC086", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/306D99C3-CCDC-4A04-B23D-F232041FC086/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-06T17:29:54+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "BC8B6652-B408-49AF-BA18-7155EF04C644", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/BC8B6652-B408-49AF-BA18-7155EF04C644/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677083/can-you-have-cross-sectional-iv-and-dv-with-a-longitudinal-moderator", "split": "train", "split_group": "eb330f69c07c455c7d1737af98d029f32286e253be12755cdd71c6af1a17492b", "tags": ["regression", "interaction", "mediation"], "thread_id": "stats:677083", "title": "Can you have cross-sectional IV and DV with a longitudinal moderator?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I have records of student grades for some university courses. I want to investigate whether any of these courses award significantly different proportions of the best (A) or worst (F) grades, compared to the other courses.\n\n\n\n\nI have individual student data, but some aggregated dummy data would be:\n\n\n\n\nmodules <- c(\n \"MA101\",\"MA102\",\"MA103\",\"MA201\",\"MA202\",\"MA301\",\"MA302\",\n \"FR101\",\"FR102\",\"FR104\",\"FR201\",\"FR202\",\"FR203\",\"FR301\",\n \"EN101\",\"EN102\",\"EN201\",\"EN202\",\"EN203\",\"EN301\",\"EN302\"\n)\ntotals <- sample(30:400, length(modules), replace = TRUE)\ngrade_counts <- t(\n sapply(totals, function(n) {\n as.vector(rmultinom(1, n, rep(1, 5)))\n })\n)\ncolnames(grade_counts) <- LETTERS[1:5]\n\ndummy_data <- data.frame(\n Module = modules,\n grade_counts,\n Total = totals\n)\n\n\n\n\n\nAnd the questions I would like to ask are\n\n\n\n\n\nIs the proportion of students who receive an A grade in MA101 the same as the proportion of students who receive an A grade in all other MA courses?\n\n\n\n\nIs the proportion of students who get an F grade in FR202 the same as the proportion of students who get an F grade in other xx200 level courses?\n\n\n\n\n\nI did some reading and from Chapter 8 Bootstrapping and Confidence Intervals | Statistical Inference via Data Science (https://moderndive.com/8-confidence-intervals.html) started out by calculating bootstrap confidence intervals around the proportion of A/F grades awarded in each course, and seeing if these overlapped with the proportion of A/F grades awarded for other courses (e.g. all other MA courses, all other xx200 courses).\n\n\n\n\nHowever, having dug a bit further (e.g. Bootstrapping a Proportion - Probably Overthinking It, (https://www.allendowney.com/blog/2024/10/15/bootstrapping-a-proportion/) Bootstrap intervals for the single proportion – corp.ling.stats (https://corplingstats.wordpress.com/2024/12/12/bootstrap-intervals/)) it seems that bootstrapping probably wasn’t the way, and I should have instead calculated Wilson CIs.\n\n\n\n\nBefore I go down the wrong path again, I’d love a sense check from some more experienced hands.\n\n\n\n\n\nAre Wilson intervals the right approach for these sorts of questions?\n\n\n\n\nGiven that I sometimes have small numbers (<30 students on a course) and rare outcomes (F grades are not common!) I think I should use a continuity correction (Correcting for continuity – corp.ling.stats (https://corplingstats.wordpress.com/2019/04/27/correcting-for-continuity/)), is that right?\n\n\n\n\nAny pointers on how to adjust for multiple comparisons, given that I’ll be calculating two CIs each (prop A and prop F) for multiple courses (e.g. each of 7 MA courses against the other 6 MA courses)?\n\n\n\n\n\nI have some formal stats training, but not done much that isn't regression for a while. I understand I could run a regression of prop A/prop F with module dummy variables, but I'd like to try branching out to some other skills, where appropriate.\n\n\n\n\nThank you.", "record_id": "Scientific-Statistics-QA:stats:677095", "selected_answer": {"answer_html": "

Welcome to CV!

\n

So you want to compare 2 proportions; e.g. “Is the proportion of students who receive an A grade in MA101 the same as the proportion of students who receive an A grade in all other MA courses?”.

\n

Well, the “canonical” way to compare 2 proportions is via a 2x2 contingency table (aka crosstab). And the “canonical” tests are either a chi-square test, or a Fisher-exact test (aka Fisher-0Irwin test).
\nNow, using binomial CI’s will not really answer your 2 questions, unless the answer is obvious” if the 2 CI’s do not overlap, you have a significant difference. And if they overlap to a large extent, you do not have a significant difference. But in between, you can not simply eyeball the CI’s.
\nNow, given that you are dealing with (very?) low proportions or counts (how many F’s in a given class? Maybe 2-3?), the chi-square test is not recommended (it is based on a normal approximation, which is not warranted for such low proportions/counts). Nor for that matter are CI’s based on normal approximations, a group the Wilson CI belongs to. And forget about continuity corrections, they do not work properly with very small proportions.
\nSo you are left with the Fisher-exact test, or some newer versions of it (which are less “conservative, while remaining “exact”, that is based on exactly the binomial distribution), such as the Blaker test.

\n

But there is a subtlety in what you are trying to compare. On one hand, you have the proportion of A’s in one class: easy. On the other hand you have the proportion of A’s in all other MA courses (the scenario is the same for the other question, so I will only address the first). How do you express that 2nd proportion?
\nOne option is to simply take the count of all A grades in all other MA courses, and the count of all students enrolled in all other MA classes. And then you can/should indeed use a Fisher-exact (or a Blaker-exact) test. But this will weight each student equally, but not each class (the classes with a large enrollment are more heavily weighted than the classes with a low enrollment). That may be what you want (as it reflects the experience of all students enrolled in all other MA classes), but it may not.\nAn alternative would be to look at all the proportions in all other MA classes, and take the average of these proportions. This weights all classes equally (but not all students). In that case, your test can be done with a single CI. You compute an binomial CI (again using an exact method given your possibly low proportions/counts), and simply see if the average proportion in included in that CI. If it is not, you have established a significant difference (at what ever significance level you chose for the CI).

\n

Last, you ask about multiple comparisons. The fact that you compute multiple CI’s is not relevant; multiple comparisons only occur when you are making a comparison to a significance level (or checking if a CI contains 0, or 1).. And since you seem to only have 2 questions, then you are only making 2 comparisons.
\nThe cautious thing to do would be to use a multiple comparison correction (MCC). Given only 2 comparisons, just use Bonferroni, and halve your significance level.
\nBut bolder statisticians could argue that your 2 hypotheses are different, and independent. And therefore, a MCC is not warranted... (should a researcher correct for all the various hypotheses he/she will test in their career?). So depending on your ultimate goal (why only these 2 questions? what are you really trying to show), you may be able to dispense with a MCC.

\n", "answer_id": 677108, "answer_text": "Welcome to CV!\n\n\n\n\nSo you want to compare 2 proportions; e.g. “Is the proportion of students who receive an A grade in MA101 the same as the proportion of students who receive an A grade in all other MA courses?”.\n\n\n\n\nWell, the “canonical” way to compare 2 proportions is via a 2x2 contingency table (https://en.wikipedia.org/wiki/Contingency_table) (aka crosstab). And the “canonical” tests are either a chi-square (https://en.wikipedia.org/wiki/Chi-squared_test) test, or a Fisher-exact (https://en.wikipedia.org/wiki/Fisher%27s_exact_test) test (aka Fisher-0Irwin test).\n\nNow, using binomial CI’s will not really answer your 2 questions, unless the answer is obvious” if the 2 CI’s do not overlap, you have a significant difference. And if they overlap to a large extent, you do not have a significant difference. But in between, you can not simply eyeball the CI’s.\n\nNow, given that you are dealing with (very?) low proportions or counts (how many F’s in a given class? Maybe 2-3?), the chi-square test is not recommended (it is based on a normal approximation, which is not warranted for such low proportions/counts). Nor for that matter are CI’s based on normal approximations, a group the Wilson CI belongs to. And forget about continuity corrections, they do not work properly with very small proportions.\n\nSo you are left with the Fisher-exact test, or some newer versions of it (which are less “conservative, while remaining “exact”, that is based on exactly the binomial distribution), such as the Blaker test (https://cran.r-universe.dev/exact2x2/doc/exact2x2.pdf).\n\n\n\n\nBut there is a subtlety in what you are trying to compare. On one hand, you have the proportion of A’s in one class: easy. On the other hand you have the proportion of A’s in all other MA courses (the scenario is the same for the other question, so I will only address the first). How do you express that 2nd proportion?\n\nOne option is to simply take the count of all A grades in all other MA courses, and the count of all students enrolled in all other MA classes. And then you can/should indeed use a Fisher-exact (or a Blaker-exact) test. But this will weight each student equally, but not each class (the classes with a large enrollment are more heavily weighted than the classes with a low enrollment). That may be what you want (as it reflects the experience of all students enrolled in all other MA classes), but it may not.\nAn alternative would be to look at all the proportions in all other MA classes, and take the average of these proportions. This weights all classes equally (but not all students). In that case, your test can be done with a single CI. You compute an binomial CI (again using an exact method given your possibly low proportions/counts), and simply see if the average proportion in included in that CI. If it is not, you have established a significant difference (at what ever significance level you chose for the CI).\n\n\n\n\nLast, you ask about multiple comparisons. The fact that you compute multiple CI’s is not relevant; multiple comparisons only occur when you are making a comparison to a significance level (or checking if a CI contains 0, or 1).. And since you seem to only have 2 questions, then you are only making 2 comparisons.\n\nThe cautious thing to do would be to use a multiple comparison correction (MCC). Given only 2 comparisons, just use Bonferroni, and halve your significance level.\n\nBut bolder statisticians could argue that your 2 hypotheses are different, and independent. And therefore, a MCC is not warranted... (should a researcher correct for all the various hypotheses he/she will test in their career?). So depending on your ultimate goal (why only these 2 questions? what are you really trying to show), you may be able to dispense with a MCC.", "answer_url": "https://stats.stackexchange.com/a/677108", "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-09T02:03:39+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": 677095, "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-09T02:03:39+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "CCDFB1CA-F81D-4A03-BE27-16DD0ED2D9AE", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CCDFB1CA-F81D-4A03-BE27-16DD0ED2D9AE/view-source"}], "score": 1, "updated_at": "2026-09-09T02:03:39+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Welcome to CV!

\n

So you want to compare 2 proportions; e.g. “Is the proportion of students who receive an A grade in MA101 the same as the proportion of students who receive an A grade in all other MA courses?”.

\n

Well, the “canonical” way to compare 2 proportions is via a 2x2 contingency table (aka crosstab). And the “canonical” tests are either a chi-square test, or a Fisher-exact test (aka Fisher-0Irwin test).
\nNow, using binomial CI’s will not really answer your 2 questions, unless the answer is obvious” if the 2 CI’s do not overlap, you have a significant difference. And if they overlap to a large extent, you do not have a significant difference. But in between, you can not simply eyeball the CI’s.
\nNow, given that you are dealing with (very?) low proportions or counts (how many F’s in a given class? Maybe 2-3?), the chi-square test is not recommended (it is based on a normal approximation, which is not warranted for such low proportions/counts). Nor for that matter are CI’s based on normal approximations, a group the Wilson CI belongs to. And forget about continuity corrections, they do not work properly with very small proportions.
\nSo you are left with the Fisher-exact test, or some newer versions of it (which are less “conservative, while remaining “exact”, that is based on exactly the binomial distribution), such as the Blaker test.

\n

But there is a subtlety in what you are trying to compare. On one hand, you have the proportion of A’s in one class: easy. On the other hand you have the proportion of A’s in all other MA courses (the scenario is the same for the other question, so I will only address the first). How do you express that 2nd proportion?
\nOne option is to simply take the count of all A grades in all other MA courses, and the count of all students enrolled in all other MA classes. And then you can/should indeed use a Fisher-exact (or a Blaker-exact) test. But this will weight each student equally, but not each class (the classes with a large enrollment are more heavily weighted than the classes with a low enrollment). That may be what you want (as it reflects the experience of all students enrolled in all other MA classes), but it may not.\nAn alternative would be to look at all the proportions in all other MA classes, and take the average of these proportions. This weights all classes equally (but not all students). In that case, your test can be done with a single CI. You compute an binomial CI (again using an exact method given your possibly low proportions/counts), and simply see if the average proportion in included in that CI. If it is not, you have established a significant difference (at what ever significance level you chose for the CI).

\n

Last, you ask about multiple comparisons. The fact that you compute multiple CI’s is not relevant; multiple comparisons only occur when you are making a comparison to a significance level (or checking if a CI contains 0, or 1).. And since you seem to only have 2 questions, then you are only making 2 comparisons.
\nThe cautious thing to do would be to use a multiple comparison correction (MCC). Given only 2 comparisons, just use Bonferroni, and halve your significance level.
\nBut bolder statisticians could argue that your 2 hypotheses are different, and independent. And therefore, a MCC is not warranted... (should a researcher correct for all the various hypotheses he/she will test in their career?). So depending on your ultimate goal (why only these 2 questions? what are you really trying to show), you may be able to dispense with a MCC.

\n", "answer_id": 677108, "answer_text": "Welcome to CV!\n\n\n\n\nSo you want to compare 2 proportions; e.g. “Is the proportion of students who receive an A grade in MA101 the same as the proportion of students who receive an A grade in all other MA courses?”.\n\n\n\n\nWell, the “canonical” way to compare 2 proportions is via a 2x2 contingency table (https://en.wikipedia.org/wiki/Contingency_table) (aka crosstab). And the “canonical” tests are either a chi-square (https://en.wikipedia.org/wiki/Chi-squared_test) test, or a Fisher-exact (https://en.wikipedia.org/wiki/Fisher%27s_exact_test) test (aka Fisher-0Irwin test).\n\nNow, using binomial CI’s will not really answer your 2 questions, unless the answer is obvious” if the 2 CI’s do not overlap, you have a significant difference. And if they overlap to a large extent, you do not have a significant difference. But in between, you can not simply eyeball the CI’s.\n\nNow, given that you are dealing with (very?) low proportions or counts (how many F’s in a given class? Maybe 2-3?), the chi-square test is not recommended (it is based on a normal approximation, which is not warranted for such low proportions/counts). Nor for that matter are CI’s based on normal approximations, a group the Wilson CI belongs to. And forget about continuity corrections, they do not work properly with very small proportions.\n\nSo you are left with the Fisher-exact test, or some newer versions of it (which are less “conservative, while remaining “exact”, that is based on exactly the binomial distribution), such as the Blaker test (https://cran.r-universe.dev/exact2x2/doc/exact2x2.pdf).\n\n\n\n\nBut there is a subtlety in what you are trying to compare. On one hand, you have the proportion of A’s in one class: easy. On the other hand you have the proportion of A’s in all other MA courses (the scenario is the same for the other question, so I will only address the first). How do you express that 2nd proportion?\n\nOne option is to simply take the count of all A grades in all other MA courses, and the count of all students enrolled in all other MA classes. And then you can/should indeed use a Fisher-exact (or a Blaker-exact) test. But this will weight each student equally, but not each class (the classes with a large enrollment are more heavily weighted than the classes with a low enrollment). That may be what you want (as it reflects the experience of all students enrolled in all other MA classes), but it may not.\nAn alternative would be to look at all the proportions in all other MA classes, and take the average of these proportions. This weights all classes equally (but not all students). In that case, your test can be done with a single CI. You compute an binomial CI (again using an exact method given your possibly low proportions/counts), and simply see if the average proportion in included in that CI. If it is not, you have established a significant difference (at what ever significance level you chose for the CI).\n\n\n\n\nLast, you ask about multiple comparisons. The fact that you compute multiple CI’s is not relevant; multiple comparisons only occur when you are making a comparison to a significance level (or checking if a CI contains 0, or 1).. And since you seem to only have 2 questions, then you are only making 2 comparisons.\n\nThe cautious thing to do would be to use a multiple comparison correction (MCC). Given only 2 comparisons, just use Bonferroni, and halve your significance level.\n\nBut bolder statisticians could argue that your 2 hypotheses are different, and independent. And therefore, a MCC is not warranted... (should a researcher correct for all the various hypotheses he/she will test in their career?). So depending on your ultimate goal (why only these 2 questions? what are you really trying to show), you may be able to dispense with a MCC.", "answer_url": "https://stats.stackexchange.com/a/677108", "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-09T02:03:39+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": 677095, "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-09T02:03:39+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "CCDFB1CA-F81D-4A03-BE27-16DD0ED2D9AE", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CCDFB1CA-F81D-4A03-BE27-16DD0ED2D9AE/view-source"}], "score": 1, "updated_at": "2026-09-09T02:03:39+00:00"}], "domain": "statistics", "external_links": ["https://corplingstats.wordpress.com/2019/04/27/correcting-for-continuity/", "https://corplingstats.wordpress.com/2024/12/12/bootstrap-intervals/", "https://cran.r-universe.dev/exact2x2/doc/exact2x2.pdf", "https://en.wikipedia.org/wiki/Chi-squared_test", "https://en.wikipedia.org/wiki/Contingency_table", "https://en.wikipedia.org/wiki/Fisher%27s_exact_test", "https://moderndive.com/8-confidence-intervals.html", "https://www.allendowney.com/blog/2024/10/15/bootstrapping-a-proportion/"], "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": "LST", "question_author_url": "https://stats.stackexchange.com/users/516373/lst", "question_author_user_type": "registered", "question_created_at": "2026-09-07T16:47:08+00:00", "question_html": "

I have records of student grades for some university courses. I want to investigate whether any of these courses award significantly different proportions of the best (A) or worst (F) grades, compared to the other courses.

\n

I have individual student data, but some aggregated dummy data would be:

\n
modules <- c(\n  "MA101","MA102","MA103","MA201","MA202","MA301","MA302",\n  "FR101","FR102","FR104","FR201","FR202","FR203","FR301",\n  "EN101","EN102","EN201","EN202","EN203","EN301","EN302"\n)\ntotals <- sample(30:400, length(modules), replace = TRUE)\ngrade_counts <- t(\n  sapply(totals, function(n) {\n    as.vector(rmultinom(1, n, rep(1, 5)))\n  })\n)\ncolnames(grade_counts) <- LETTERS[1:5]\n\ndummy_data <- data.frame(\n  Module = modules,\n  grade_counts,\n  Total = totals\n)\n
\n

And the questions I would like to ask are

\n
    \n
  • Is the proportion of students who receive an A grade in MA101 the same as the proportion of students who receive an A grade in all other MA courses?
  • \n
  • Is the proportion of students who get an F grade in FR202 the same as the proportion of students who get an F grade in other xx200 level courses?
  • \n
\n

I did some reading and from Chapter 8 Bootstrapping and Confidence Intervals | Statistical Inference via Data Science started out by calculating bootstrap confidence intervals around the proportion of A/F grades awarded in each course, and seeing if these overlapped with the proportion of A/F grades awarded for other courses (e.g. all other MA courses, all other xx200 courses).

\n

However, having dug a bit further (e.g. Bootstrapping a Proportion - Probably Overthinking It, Bootstrap intervals for the single proportion – corp.ling.stats) it seems that bootstrapping probably wasn’t the way, and I should have instead calculated Wilson CIs.

\n

Before I go down the wrong path again, I’d love a sense check from some more experienced hands.

\n
    \n
  • Are Wilson intervals the right approach for these sorts of questions?
  • \n
  • Given that I sometimes have small numbers (<30 students on a course) and rare outcomes (F grades are not common!) I think I should use a continuity correction (Correcting for continuity – corp.ling.stats), is that right?
  • \n
  • Any pointers on how to adjust for multiple comparisons, given that I’ll be calculating two CIs each (prop A and prop F) for multiple courses (e.g. each of 7 MA courses against the other 6 MA courses)?
  • \n
\n

I have some formal stats training, but not done much that isn't regression for a while. I understand I could run a regression of prop A/prop F with module dummy variables, but I'd like to try branching out to some other skills, where appropriate.

\n

Thank you.

\n", "question_id": 677095, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "I have records of student grades for some university courses. I want to investigate whether any of these courses award significantly different proportions of the best (A) or worst (F) grades, compared to the other courses.\n\n\n\n\nI have individual student data, but some aggregated dummy data would be:\n\n\n\n\nmodules <- c(\n \"MA101\",\"MA102\",\"MA103\",\"MA201\",\"MA202\",\"MA301\",\"MA302\",\n \"FR101\",\"FR102\",\"FR104\",\"FR201\",\"FR202\",\"FR203\",\"FR301\",\n \"EN101\",\"EN102\",\"EN201\",\"EN202\",\"EN203\",\"EN301\",\"EN302\"\n)\ntotals <- sample(30:400, length(modules), replace = TRUE)\ngrade_counts <- t(\n sapply(totals, function(n) {\n as.vector(rmultinom(1, n, rep(1, 5)))\n })\n)\ncolnames(grade_counts) <- LETTERS[1:5]\n\ndummy_data <- data.frame(\n Module = modules,\n grade_counts,\n Total = totals\n)\n\n\n\n\n\nAnd the questions I would like to ask are\n\n\n\n\n\nIs the proportion of students who receive an A grade in MA101 the same as the proportion of students who receive an A grade in all other MA courses?\n\n\n\n\nIs the proportion of students who get an F grade in FR202 the same as the proportion of students who get an F grade in other xx200 level courses?\n\n\n\n\n\nI did some reading and from Chapter 8 Bootstrapping and Confidence Intervals | Statistical Inference via Data Science (https://moderndive.com/8-confidence-intervals.html) started out by calculating bootstrap confidence intervals around the proportion of A/F grades awarded in each course, and seeing if these overlapped with the proportion of A/F grades awarded for other courses (e.g. all other MA courses, all other xx200 courses).\n\n\n\n\nHowever, having dug a bit further (e.g. Bootstrapping a Proportion - Probably Overthinking It, (https://www.allendowney.com/blog/2024/10/15/bootstrapping-a-proportion/) Bootstrap intervals for the single proportion – corp.ling.stats (https://corplingstats.wordpress.com/2024/12/12/bootstrap-intervals/)) it seems that bootstrapping probably wasn’t the way, and I should have instead calculated Wilson CIs.\n\n\n\n\nBefore I go down the wrong path again, I’d love a sense check from some more experienced hands.\n\n\n\n\n\nAre Wilson intervals the right approach for these sorts of questions?\n\n\n\n\nGiven that I sometimes have small numbers (<30 students on a course) and rare outcomes (F grades are not common!) I think I should use a continuity correction (Correcting for continuity – corp.ling.stats (https://corplingstats.wordpress.com/2019/04/27/correcting-for-continuity/)), is that right?\n\n\n\n\nAny pointers on how to adjust for multiple comparisons, given that I’ll be calculating two CIs each (prop A and prop F) for multiple courses (e.g. each of 7 MA courses against the other 6 MA courses)?\n\n\n\n\n\nI have some formal stats training, but not done much that isn't regression for a while. I understand I could run a regression of prop A/prop F with module dummy variables, but I'd like to try branching out to some other skills, where appropriate.\n\n\n\n\nThank you.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "LST", "profile_url": "https://stats.stackexchange.com/users/516373/lst", "user_type": "registered"}, "created_at": "2026-09-07T16:47:08+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "77370A41-A452-40D5-9FE9-E2D1C2A53F6B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/77370A41-A452-40D5-9FE9-E2D1C2A53F6B/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677095/testing-differences-in-proportions-wilson-cis-continuity-corrections-and-mult", "split": "train", "split_group": "539d92a20e4941595f8fd87a1112f78fb0bb6db32af014f84a6cccc0e55d9727", "tags": ["confidence-interval", "proportion"], "thread_id": "stats:677095", "title": "Testing differences in proportions - Wilson CIs, continuity corrections and multiple comparisons"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I'm a PhD student and I've been working on the same thing for some time now and feeling just as confused and lost as I did when I began. I need some help with some statistical modelling that I am doing and cannot find straight answers (or when I do, these are immediately contradicted by my supervisor or someone else).\n\n\n\n\nI am running coxme analyses. For my largest main model (pre-backwards selection), I have 28 fixed effects (I know...) including interactions and quadratics, and four random effects. I am usually running two versions of the model, separated by sex (see more below...).\n\n\n\n\nFirst question: what is the minimum sample size I would need to run this model? I get told a) minimum is 10 events per covariate and less than that is an abomination, or, B) as long as the model converges it's fine.\n\n\n\n\nSecond question: I am including quadratics of all main terms except two (which are 2 level factors). Can I include interactions between two quadratic terms? Currently my model looks like this: y = a + b + a^2 + b^2 + ab + a^2b^2\nMy justification was that, we expect these terms to be quadratic, we also expect them to interact, so their interaction could be on a quadratic shape. However, this is obviously really hard to interpret...\n\n\n\n\nThird question: when I ran the model as above, I got a significant p value for some of the interactions (including some of the quadratics). However, after discussions with my supervisor, he wants me to run the model and remove the two factorial covariates (and their associated interactions) and also the individuals which are positive for those factors (which are the minority). Is this a valid approach? The justification is to reduce model complexity/aid interpretability and to prevent over-parameterisation. However, doing this reduces my sample size to the extent that I have to merge both sexes into one model, so then I have to include sex and other interactions as covariates too. Someone else suggested to me that I just remove the covariates from the model, but keep in the individuals in the data. However, considering there is a significant result there, wouldn't doing this over- and underestimate the effects for individuals with different values in the factorial covariates?\n\n\n\n\nSorry for the length, please ask if I need to clarify something.\n\n\n\n\nThanks\n\n\n\n\nEdit: additional information\n\n\n\n\nfor the largest main model (before removing two covariates):\nmales only model n = 172 events out of 227, maximal model has 28 parameters, post selection: 19 parameters\n\n\n\n\nWhen removing the two covariates discussed in Q3:\n\n\n\n\ncombined sexes model n = 289 events out of 386, maximal model has 25 parameters, post selection: 10 parameters\n\n\n\n\nmales only model n = 136 events out of 183, maximal model has 18 parameters, post selection: 14 parameters\n\n\n\n\nfemales only model n = 153 events out of 203, maximal model has 18 parameters, post selection, 15 parameters\n\n\n\n\nRandom effects are mum ID, dominant male ID, genetic father ID and birth year.", "record_id": "Scientific-Statistics-QA:stats:677101", "selected_answer": {"answer_html": "

I'll start by addressing the questions, then finish with some thoughts based on the added study details.

\n
\n

what is the minimum sample size I would need ...?

\n
\n

Rules of thumb about the event/coefficient ratio help avoid overfitting. Yes, you can get a model that converges with a low ratio. That model, however, is likely to pick up idiosyncrasies of the current data sample and thus unlikely to work well on a new sample from the same population.

\n

You can estimate the amount of overfitting with the "optimism bootstrap."\nRepeat the entire modeling process (including your backward selection) on a bootstrap sample of the full data set (of the same size as the full data, but sampled with replacement). Think of that as fitting a model to a new sample from the original population, with the full data set your best representation of the original population. Then compare the performance of that model between the bootstrap sample and the full data set. The amount of better performance on the bootstrap sample versus the full data set represents the amount of overfitting for the model of that bootstrap sample.

\n

Repeat on multiple bootstrapped samples and average the overfitting estimates. This page goes into a bit more detail. In my experience with clinical survival data, when you get below 10-15 events per coefficient you can start to get substantial overfitting.

\n
\n

I am including quadratics of all main terms except two (which are 2 level factors). Can I include interactions between two quadratic terms?

\n
\n

First, quadratics don't always capture the correct nonlinear associations between continuous predictors and outcomes. They force a particular functional form over the entire range of predictor values. Consider generalized additive models (e.g., restricted cubic splines), which can work better in many circumstances.

\n

Second, there's no prohibition against interactions between quadratic or cubic-spline terms. You are correct, however, that interpretation becomes difficult and the number of coefficients to estimate increases. Frank Harrell provides a compromise with the %ia% transformation in his rms package; it "represents restricted interactions in which products involving nonlinear effects on both variables are not included in the model." (Emphasis added.) You could similarly omit double-nonlinear terms from your model.

\n
\n

... after discussions with my supervisor, he wants me to run the model and remove the two factorial covariates (and their associated interactions) and also the individuals which are positive for those factors (which are the minority). Is this a valid approach?

\n
\n

That's changing the population from which you are sampling. You are then excluding individuals "positive for those factors" from your population of interest. The model could still be "valid" for that more limited population, but it shouldn't be applied to those who are "positive for those factors."

\n
\n

... doing this reduces my sample size to the extent that I have to merge both sexes into one model, so then I have to include sex and other interactions as covariates too.

\n
\n

It's typically better anyway to start with a model that includes both sexes. The increased number of events pretty much cancels out the increased number of coefficients you need to estimate, even if you include interactions of sex with all the other predictors. You can then reduce the number of coefficients if you omit interactions of sex with covariates already known to be associated with outcome independently of sex. A single model lets you evaluate the magnitude and significance of differences between sexes more reliably than separate models, via coefficient estimates for interaction terms of the remaining covariates with sex.

\n
\n

Someone else suggested to me that I just remove the covariates from the model, but keep in the individuals in the data... wouldn't doing this over- and underestimate the effects for individuals with different values in the factorial covariates?

\n
\n

Yes, that could lead to omitted-variable bias, the technical term for what you fear. That's a particular problem in survival analysis. Unlike in linear regression, omitting an outcome-associated predictor from a survival model can lead to bias in coefficient estimates even if the omitted predictor is uncorrelated with the included predictors. It's the same phenomenon as in binary regression, as explained here.

\n

Thoughts on your study

\n

Frank Harrell's Regression Modeling Strategies (RMS) is a freely available reference, written by an expert in clinical data analysis. For example: Chapter 2 discusses both general principles and fitting continuous predictors flexibly with splines; Chapter 4 covers modeling strategies to match the number of coefficients to the number of cases, with cautions on overfitting; Chapter 5 shows how to simplify the model if desired; Chapters 17-21 and 25 address different types of survival modeling.

\n

His overall philosophy, from Section 4.11 of RMS:

\n
\n
    \n
  • Decide how may d.f. [degrees of freedom] can be spent
  • \n
  • Decide where to spend them
  • \n
  • Spend them
  • \n
  • Don’t reconsider, especially if inference needed
  • \n
\n
\n

Apply those principles to your study. As you don't seem to be using any penalization (e.g., LASSO or ridge regression), you can think of the "degrees of freedom [that] can be spent" as the number of coefficients you can estimate reliably.

\n

For survival analysis, he recommends that you can spend about 1 d.f per 15 events. Combining both sexes and all covariates, you have about 350-400 events. If you analyze all the data together instead of splitting by sex and omitting some classes of patients, you have about 25 d.f. to apply to your model. That's not so far from the number of coefficients in you "maximal" models.

\n

Backward selection is like throwing a large number of predictors and interactions into a model, to "see what sticks" as "significant" in the end. It might be least objectionable of automated model selection methods, but it's likely to be misleading. This page, many others on this site, and Section 4.3 of RMS discuss why. If you use backward selection and perform the "optimism bootstrap," examine the (lack of) agreement among the separate bootstrap models in terms of the retained predictors.

\n

Start instead with the 25 d.f. available to you. Use your subject-matter knowledge to make intelligent decisions about what coefficients are most critical to include. It's OK to use information from prior studies for those decisions, but don't consider outcomes in your particular data set. If you fit all the data in a single model (as would generally be best), decide which predictors might require an interaction with sex. Omit doubly nonlinear interactions between continuous predictors. Perhaps use "data reduction" to combine closely related predictors into a smaller number, based on subject-matter knowledge or techniques like sparse principal component analysis.

\n

That process should provide a model that isn't badly overfit and for which p-values and inference are reliable, unlike with backward selection. Check overfitting with the optimism bootstrap. Once you have that "gold standard" model, you can simplify if you wish. At that point, as Harrell puts it in Section 4.12.1 of RMS, you can

\n
\n

do limited backwards step-down variable selection if parsimony is more important than accuracy... But confidence limits, etc., must account for variable selection (e.g., bootstrap).

\n
\n

Chapter 5 of RMS provides more details on simplification. Section 19.5 shows simplification of a parametric survival model.

\n", "answer_id": 677119, "answer_text": "I'll start by addressing the questions, then finish with some thoughts based on the added study details.\n\n\n\n\n\n\n\nwhat is the minimum sample size I would need ...?\n\n\n\n\n\n\n\nRules of thumb about the event/coefficient ratio help avoid overfitting. Yes, you can get a model that converges with a low ratio. That model, however, is likely to pick up idiosyncrasies of the current data sample and thus unlikely to work well on a new sample from the same population.\n\n\n\n\nYou can estimate the amount of overfitting with the \"optimism bootstrap.\"\nRepeat the entire modeling process (https://stats.stackexchange.com/a/64853/28500) (including your backward selection) on a bootstrap sample of the full data set (of the same size as the full data, but sampled with replacement). Think of that as fitting a model to a new sample from the original population, with the full data set your best representation of the original population. Then compare the performance of that model between the bootstrap sample and the full data set. The amount of better performance on the bootstrap sample versus the full data set represents the amount of overfitting for the model of that bootstrap sample.\n\n\n\n\nRepeat on multiple bootstrapped samples and average the overfitting estimates. This page (https://stats.stackexchange.com/q/373171/28500) goes into a bit more detail. In my experience with clinical survival data, when you get below 10-15 events per coefficient you can start to get substantial overfitting.\n\n\n\n\n\n\n\nI am including quadratics of all main terms except two (which are 2 level factors). Can I include interactions between two quadratic terms?\n\n\n\n\n\n\n\nFirst, quadratics don't always capture the correct nonlinear associations between continuous predictors and outcomes. They force a particular functional form over the entire range of predictor values. Consider generalized additive models (e.g., restricted cubic splines), which can work better in many circumstances.\n\n\n\n\nSecond, there's no prohibition against interactions between quadratic or cubic-spline terms. You are correct, however, that interpretation becomes difficult and the number of coefficients to estimate increases. Frank Harrell provides a compromise with the %ia% transformation in his rms package (https://cran.r-project.org/package=rms); it \"represents restricted interactions in which products involving nonlinear effects on both variables are not included in the model.\" (Emphasis added.) You could similarly omit double-nonlinear terms from your model.\n\n\n\n\n\n\n\n... after discussions with my supervisor, he wants me to run the model and remove the two factorial covariates (and their associated interactions) and also the individuals which are positive for those factors (which are the minority). Is this a valid approach?\n\n\n\n\n\n\n\nThat's changing the population from which you are sampling. You are then excluding individuals \"positive for those factors\" from your population of interest. The model could still be \"valid\" for that more limited population, but it shouldn't be applied to those who are \"positive for those factors.\"\n\n\n\n\n\n\n\n... doing this reduces my sample size to the extent that I have to merge both sexes into one model, so then I have to include sex and other interactions as covariates too.\n\n\n\n\n\n\n\nIt's typically better anyway to start with a model that includes both sexes. The increased number of events pretty much cancels out the increased number of coefficients you need to estimate, even if you include interactions of sex with all the other predictors. You can then reduce the number of coefficients if you omit interactions of sex with covariates already known to be associated with outcome independently of sex. A single model lets you evaluate the magnitude and significance of differences between sexes more reliably than separate models, via coefficient estimates for interaction terms of the remaining covariates with sex.\n\n\n\n\n\n\n\nSomeone else suggested to me that I just remove the covariates from the model, but keep in the individuals in the data... wouldn't doing this over- and underestimate the effects for individuals with different values in the factorial covariates?\n\n\n\n\n\n\n\nYes, that could lead to omitted-variable bias (https://en.wikipedia.org/wiki/Omitted-variable_bias), the technical term for what you fear. That's a particular problem in survival analysis. Unlike in linear regression, omitting an outcome-associated predictor from a survival model can lead to bias in coefficient estimates even if the omitted predictor is uncorrelated with the included predictors. It's the same phenomenon as in binary regression, as explained here (https://stats.stackexchange.com/q/113766/28500).\n\n\n\n\nThoughts on your study\n\n\n\n\nFrank Harrell's Regression Modeling Strategies (https://hbiostat.org/rmsc/) (RMS) is a freely available reference, written by an expert in clinical data analysis. For example: Chapter 2 discusses both general principles and fitting continuous predictors flexibly with splines; Chapter 4 covers modeling strategies to match the number of coefficients to the number of cases, with cautions on overfitting; Chapter 5 shows how to simplify the model if desired; Chapters 17-21 and 25 address different types of survival modeling.\n\n\n\n\nHis overall philosophy, from Section 4.11 of RMS:\n\n\n\n\n\n\n\n\nDecide how may d.f. [degrees of freedom] can be spent\n\n\n\n\nDecide where to spend them\n\n\n\n\nSpend them\n\n\n\n\nDon’t reconsider, especially if inference needed\n\n\n\n\n\n\n\n\nApply those principles to your study. As you don't seem to be using any penalization (e.g., LASSO or ridge regression), you can think of the \"degrees of freedom [that] can be spent\" as the number of coefficients you can estimate reliably.\n\n\n\n\nFor survival analysis, he recommends that you can spend about 1 d.f per 15 events. Combining both sexes and all covariates, you have about 350-400 events. If you analyze all the data together instead of splitting by sex and omitting some classes of patients, you have about 25 d.f. to apply to your model. That's not so far from the number of coefficients in you \"maximal\" models.\n\n\n\n\nBackward selection is like throwing a large number of predictors and interactions into a model, to \"see what sticks\" as \"significant\" in the end. It might be least objectionable of automated model selection methods, but it's likely to be misleading. This page (https://stats.stackexchange.com/q/20836/28500), many others on this site, and Section 4.3 of RMS discuss why. If you use backward selection and perform the \"optimism bootstrap,\" examine the (lack of) agreement among the separate bootstrap models in terms of the retained predictors.\n\n\n\n\nStart instead with the 25 d.f. available to you. Use your subject-matter knowledge to make intelligent decisions about what coefficients are most critical to include. It's OK to use information from prior studies for those decisions, but don't consider outcomes in your particular data set. If you fit all the data in a single model (as would generally be best), decide which predictors might require an interaction with sex. Omit doubly nonlinear interactions between continuous predictors. Perhaps use \"data reduction\" to combine closely related predictors into a smaller number, based on subject-matter knowledge or techniques like sparse principal component analysis.\n\n\n\n\nThat process should provide a model that isn't badly overfit and for which p-values and inference are reliable, unlike with backward selection. Check overfitting with the optimism bootstrap. Once you have that \"gold standard\" model, you can simplify if you wish. At that point, as Harrell puts it in Section 4.12.1 of RMS, you can\n\n\n\n\n\n\n\ndo limited backwards step-down variable selection if parsimony is more important than accuracy... But confidence limits, etc., must account for variable selection (e.g., bootstrap).\n\n\n\n\n\n\n\nChapter 5 of RMS provides more details on simplification. Section 19.5 shows simplification of a parametric survival model.", "answer_url": "https://stats.stackexchange.com/a/677119", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T17:22:04+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677101, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-09T17:22:04+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "09E3B6CD-A4F2-4322-A977-8131B8B1EC0A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/09E3B6CD-A4F2-4322-A977-8131B8B1EC0A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-10T14:38:14+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "E772AFBC-9EDC-4DCC-B4EC-EFD49DF0383B", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E772AFBC-9EDC-4DCC-B4EC-EFD49DF0383B/view-source"}], "score": 1, "updated_at": "2026-09-10T14:38:14+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

I'll start by addressing the questions, then finish with some thoughts based on the added study details.

\n
\n

what is the minimum sample size I would need ...?

\n
\n

Rules of thumb about the event/coefficient ratio help avoid overfitting. Yes, you can get a model that converges with a low ratio. That model, however, is likely to pick up idiosyncrasies of the current data sample and thus unlikely to work well on a new sample from the same population.

\n

You can estimate the amount of overfitting with the "optimism bootstrap."\nRepeat the entire modeling process (including your backward selection) on a bootstrap sample of the full data set (of the same size as the full data, but sampled with replacement). Think of that as fitting a model to a new sample from the original population, with the full data set your best representation of the original population. Then compare the performance of that model between the bootstrap sample and the full data set. The amount of better performance on the bootstrap sample versus the full data set represents the amount of overfitting for the model of that bootstrap sample.

\n

Repeat on multiple bootstrapped samples and average the overfitting estimates. This page goes into a bit more detail. In my experience with clinical survival data, when you get below 10-15 events per coefficient you can start to get substantial overfitting.

\n
\n

I am including quadratics of all main terms except two (which are 2 level factors). Can I include interactions between two quadratic terms?

\n
\n

First, quadratics don't always capture the correct nonlinear associations between continuous predictors and outcomes. They force a particular functional form over the entire range of predictor values. Consider generalized additive models (e.g., restricted cubic splines), which can work better in many circumstances.

\n

Second, there's no prohibition against interactions between quadratic or cubic-spline terms. You are correct, however, that interpretation becomes difficult and the number of coefficients to estimate increases. Frank Harrell provides a compromise with the %ia% transformation in his rms package; it "represents restricted interactions in which products involving nonlinear effects on both variables are not included in the model." (Emphasis added.) You could similarly omit double-nonlinear terms from your model.

\n
\n

... after discussions with my supervisor, he wants me to run the model and remove the two factorial covariates (and their associated interactions) and also the individuals which are positive for those factors (which are the minority). Is this a valid approach?

\n
\n

That's changing the population from which you are sampling. You are then excluding individuals "positive for those factors" from your population of interest. The model could still be "valid" for that more limited population, but it shouldn't be applied to those who are "positive for those factors."

\n
\n

... doing this reduces my sample size to the extent that I have to merge both sexes into one model, so then I have to include sex and other interactions as covariates too.

\n
\n

It's typically better anyway to start with a model that includes both sexes. The increased number of events pretty much cancels out the increased number of coefficients you need to estimate, even if you include interactions of sex with all the other predictors. You can then reduce the number of coefficients if you omit interactions of sex with covariates already known to be associated with outcome independently of sex. A single model lets you evaluate the magnitude and significance of differences between sexes more reliably than separate models, via coefficient estimates for interaction terms of the remaining covariates with sex.

\n
\n

Someone else suggested to me that I just remove the covariates from the model, but keep in the individuals in the data... wouldn't doing this over- and underestimate the effects for individuals with different values in the factorial covariates?

\n
\n

Yes, that could lead to omitted-variable bias, the technical term for what you fear. That's a particular problem in survival analysis. Unlike in linear regression, omitting an outcome-associated predictor from a survival model can lead to bias in coefficient estimates even if the omitted predictor is uncorrelated with the included predictors. It's the same phenomenon as in binary regression, as explained here.

\n

Thoughts on your study

\n

Frank Harrell's Regression Modeling Strategies (RMS) is a freely available reference, written by an expert in clinical data analysis. For example: Chapter 2 discusses both general principles and fitting continuous predictors flexibly with splines; Chapter 4 covers modeling strategies to match the number of coefficients to the number of cases, with cautions on overfitting; Chapter 5 shows how to simplify the model if desired; Chapters 17-21 and 25 address different types of survival modeling.

\n

His overall philosophy, from Section 4.11 of RMS:

\n
\n
    \n
  • Decide how may d.f. [degrees of freedom] can be spent
  • \n
  • Decide where to spend them
  • \n
  • Spend them
  • \n
  • Don’t reconsider, especially if inference needed
  • \n
\n
\n

Apply those principles to your study. As you don't seem to be using any penalization (e.g., LASSO or ridge regression), you can think of the "degrees of freedom [that] can be spent" as the number of coefficients you can estimate reliably.

\n

For survival analysis, he recommends that you can spend about 1 d.f per 15 events. Combining both sexes and all covariates, you have about 350-400 events. If you analyze all the data together instead of splitting by sex and omitting some classes of patients, you have about 25 d.f. to apply to your model. That's not so far from the number of coefficients in you "maximal" models.

\n

Backward selection is like throwing a large number of predictors and interactions into a model, to "see what sticks" as "significant" in the end. It might be least objectionable of automated model selection methods, but it's likely to be misleading. This page, many others on this site, and Section 4.3 of RMS discuss why. If you use backward selection and perform the "optimism bootstrap," examine the (lack of) agreement among the separate bootstrap models in terms of the retained predictors.

\n

Start instead with the 25 d.f. available to you. Use your subject-matter knowledge to make intelligent decisions about what coefficients are most critical to include. It's OK to use information from prior studies for those decisions, but don't consider outcomes in your particular data set. If you fit all the data in a single model (as would generally be best), decide which predictors might require an interaction with sex. Omit doubly nonlinear interactions between continuous predictors. Perhaps use "data reduction" to combine closely related predictors into a smaller number, based on subject-matter knowledge or techniques like sparse principal component analysis.

\n

That process should provide a model that isn't badly overfit and for which p-values and inference are reliable, unlike with backward selection. Check overfitting with the optimism bootstrap. Once you have that "gold standard" model, you can simplify if you wish. At that point, as Harrell puts it in Section 4.12.1 of RMS, you can

\n
\n

do limited backwards step-down variable selection if parsimony is more important than accuracy... But confidence limits, etc., must account for variable selection (e.g., bootstrap).

\n
\n

Chapter 5 of RMS provides more details on simplification. Section 19.5 shows simplification of a parametric survival model.

\n", "answer_id": 677119, "answer_text": "I'll start by addressing the questions, then finish with some thoughts based on the added study details.\n\n\n\n\n\n\n\nwhat is the minimum sample size I would need ...?\n\n\n\n\n\n\n\nRules of thumb about the event/coefficient ratio help avoid overfitting. Yes, you can get a model that converges with a low ratio. That model, however, is likely to pick up idiosyncrasies of the current data sample and thus unlikely to work well on a new sample from the same population.\n\n\n\n\nYou can estimate the amount of overfitting with the \"optimism bootstrap.\"\nRepeat the entire modeling process (https://stats.stackexchange.com/a/64853/28500) (including your backward selection) on a bootstrap sample of the full data set (of the same size as the full data, but sampled with replacement). Think of that as fitting a model to a new sample from the original population, with the full data set your best representation of the original population. Then compare the performance of that model between the bootstrap sample and the full data set. The amount of better performance on the bootstrap sample versus the full data set represents the amount of overfitting for the model of that bootstrap sample.\n\n\n\n\nRepeat on multiple bootstrapped samples and average the overfitting estimates. This page (https://stats.stackexchange.com/q/373171/28500) goes into a bit more detail. In my experience with clinical survival data, when you get below 10-15 events per coefficient you can start to get substantial overfitting.\n\n\n\n\n\n\n\nI am including quadratics of all main terms except two (which are 2 level factors). Can I include interactions between two quadratic terms?\n\n\n\n\n\n\n\nFirst, quadratics don't always capture the correct nonlinear associations between continuous predictors and outcomes. They force a particular functional form over the entire range of predictor values. Consider generalized additive models (e.g., restricted cubic splines), which can work better in many circumstances.\n\n\n\n\nSecond, there's no prohibition against interactions between quadratic or cubic-spline terms. You are correct, however, that interpretation becomes difficult and the number of coefficients to estimate increases. Frank Harrell provides a compromise with the %ia% transformation in his rms package (https://cran.r-project.org/package=rms); it \"represents restricted interactions in which products involving nonlinear effects on both variables are not included in the model.\" (Emphasis added.) You could similarly omit double-nonlinear terms from your model.\n\n\n\n\n\n\n\n... after discussions with my supervisor, he wants me to run the model and remove the two factorial covariates (and their associated interactions) and also the individuals which are positive for those factors (which are the minority). Is this a valid approach?\n\n\n\n\n\n\n\nThat's changing the population from which you are sampling. You are then excluding individuals \"positive for those factors\" from your population of interest. The model could still be \"valid\" for that more limited population, but it shouldn't be applied to those who are \"positive for those factors.\"\n\n\n\n\n\n\n\n... doing this reduces my sample size to the extent that I have to merge both sexes into one model, so then I have to include sex and other interactions as covariates too.\n\n\n\n\n\n\n\nIt's typically better anyway to start with a model that includes both sexes. The increased number of events pretty much cancels out the increased number of coefficients you need to estimate, even if you include interactions of sex with all the other predictors. You can then reduce the number of coefficients if you omit interactions of sex with covariates already known to be associated with outcome independently of sex. A single model lets you evaluate the magnitude and significance of differences between sexes more reliably than separate models, via coefficient estimates for interaction terms of the remaining covariates with sex.\n\n\n\n\n\n\n\nSomeone else suggested to me that I just remove the covariates from the model, but keep in the individuals in the data... wouldn't doing this over- and underestimate the effects for individuals with different values in the factorial covariates?\n\n\n\n\n\n\n\nYes, that could lead to omitted-variable bias (https://en.wikipedia.org/wiki/Omitted-variable_bias), the technical term for what you fear. That's a particular problem in survival analysis. Unlike in linear regression, omitting an outcome-associated predictor from a survival model can lead to bias in coefficient estimates even if the omitted predictor is uncorrelated with the included predictors. It's the same phenomenon as in binary regression, as explained here (https://stats.stackexchange.com/q/113766/28500).\n\n\n\n\nThoughts on your study\n\n\n\n\nFrank Harrell's Regression Modeling Strategies (https://hbiostat.org/rmsc/) (RMS) is a freely available reference, written by an expert in clinical data analysis. For example: Chapter 2 discusses both general principles and fitting continuous predictors flexibly with splines; Chapter 4 covers modeling strategies to match the number of coefficients to the number of cases, with cautions on overfitting; Chapter 5 shows how to simplify the model if desired; Chapters 17-21 and 25 address different types of survival modeling.\n\n\n\n\nHis overall philosophy, from Section 4.11 of RMS:\n\n\n\n\n\n\n\n\nDecide how may d.f. [degrees of freedom] can be spent\n\n\n\n\nDecide where to spend them\n\n\n\n\nSpend them\n\n\n\n\nDon’t reconsider, especially if inference needed\n\n\n\n\n\n\n\n\nApply those principles to your study. As you don't seem to be using any penalization (e.g., LASSO or ridge regression), you can think of the \"degrees of freedom [that] can be spent\" as the number of coefficients you can estimate reliably.\n\n\n\n\nFor survival analysis, he recommends that you can spend about 1 d.f per 15 events. Combining both sexes and all covariates, you have about 350-400 events. If you analyze all the data together instead of splitting by sex and omitting some classes of patients, you have about 25 d.f. to apply to your model. That's not so far from the number of coefficients in you \"maximal\" models.\n\n\n\n\nBackward selection is like throwing a large number of predictors and interactions into a model, to \"see what sticks\" as \"significant\" in the end. It might be least objectionable of automated model selection methods, but it's likely to be misleading. This page (https://stats.stackexchange.com/q/20836/28500), many others on this site, and Section 4.3 of RMS discuss why. If you use backward selection and perform the \"optimism bootstrap,\" examine the (lack of) agreement among the separate bootstrap models in terms of the retained predictors.\n\n\n\n\nStart instead with the 25 d.f. available to you. Use your subject-matter knowledge to make intelligent decisions about what coefficients are most critical to include. It's OK to use information from prior studies for those decisions, but don't consider outcomes in your particular data set. If you fit all the data in a single model (as would generally be best), decide which predictors might require an interaction with sex. Omit doubly nonlinear interactions between continuous predictors. Perhaps use \"data reduction\" to combine closely related predictors into a smaller number, based on subject-matter knowledge or techniques like sparse principal component analysis.\n\n\n\n\nThat process should provide a model that isn't badly overfit and for which p-values and inference are reliable, unlike with backward selection. Check overfitting with the optimism bootstrap. Once you have that \"gold standard\" model, you can simplify if you wish. At that point, as Harrell puts it in Section 4.12.1 of RMS, you can\n\n\n\n\n\n\n\ndo limited backwards step-down variable selection if parsimony is more important than accuracy... But confidence limits, etc., must account for variable selection (e.g., bootstrap).\n\n\n\n\n\n\n\nChapter 5 of RMS provides more details on simplification. Section 19.5 shows simplification of a parametric survival model.", "answer_url": "https://stats.stackexchange.com/a/677119", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T17:22:04+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677101, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-09T17:22:04+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "09E3B6CD-A4F2-4322-A977-8131B8B1EC0A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/09E3B6CD-A4F2-4322-A977-8131B8B1EC0A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-10T14:38:14+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "E772AFBC-9EDC-4DCC-B4EC-EFD49DF0383B", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E772AFBC-9EDC-4DCC-B4EC-EFD49DF0383B/view-source"}], "score": 1, "updated_at": "2026-09-10T14:38:14+00:00"}], "domain": "statistics", "external_links": ["https://cran.r-project.org/package=rms", "https://en.wikipedia.org/wiki/Omitted-variable_bias", "https://hbiostat.org/rmsc/"], "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": "user29485477", "question_author_url": "https://stats.stackexchange.com/users/516400/user29485477", "question_author_user_type": "registered", "question_created_at": "2026-09-08T13:20:34+00:00", "question_html": "

I'm a PhD student and I've been working on the same thing for some time now and feeling just as confused and lost as I did when I began. I need some help with some statistical modelling that I am doing and cannot find straight answers (or when I do, these are immediately contradicted by my supervisor or someone else).

\n

I am running coxme analyses. For my largest main model (pre-backwards selection), I have 28 fixed effects (I know...) including interactions and quadratics, and four random effects. I am usually running two versions of the model, separated by sex (see more below...).

\n

First question: what is the minimum sample size I would need to run this model? I get told a) minimum is 10 events per covariate and less than that is an abomination, or, B) as long as the model converges it's fine.

\n

Second question: I am including quadratics of all main terms except two (which are 2 level factors). Can I include interactions between two quadratic terms? Currently my model looks like this: y = a + b + a^2 + b^2 + ab + a^2b^2\nMy justification was that, we expect these terms to be quadratic, we also expect them to interact, so their interaction could be on a quadratic shape. However, this is obviously really hard to interpret...

\n

Third question: when I ran the model as above, I got a significant p value for some of the interactions (including some of the quadratics). However, after discussions with my supervisor, he wants me to run the model and remove the two factorial covariates (and their associated interactions) and also the individuals which are positive for those factors (which are the minority). Is this a valid approach? The justification is to reduce model complexity/aid interpretability and to prevent over-parameterisation. However, doing this reduces my sample size to the extent that I have to merge both sexes into one model, so then I have to include sex and other interactions as covariates too. Someone else suggested to me that I just remove the covariates from the model, but keep in the individuals in the data. However, considering there is a significant result there, wouldn't doing this over- and underestimate the effects for individuals with different values in the factorial covariates?

\n

Sorry for the length, please ask if I need to clarify something.

\n

Thanks

\n

Edit: additional information

\n

for the largest main model (before removing two covariates):\nmales only model n = 172 events out of 227, maximal model has 28 parameters, post selection: 19 parameters

\n

When removing the two covariates discussed in Q3:

\n

combined sexes model n = 289 events out of 386, maximal model has 25 parameters, post selection: 10 parameters

\n

males only model n = 136 events out of 183, maximal model has 18 parameters, post selection: 14 parameters

\n

females only model n = 153 events out of 203, maximal model has 18 parameters, post selection, 15 parameters

\n

Random effects are mum ID, dominant male ID, genetic father ID and birth year.

\n", "question_id": 677101, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I'm a PhD student and I've been working on the same thing for some time now and feeling just as confused and lost as I did when I began. I need some help with some statistical modelling that I am doing and cannot find straight answers (or when I do, these are immediately contradicted by my supervisor or someone else).\n\n\n\n\nI am running coxme analyses. For my largest main model (pre-backwards selection), I have 28 fixed effects (I know...) including interactions and quadratics, and four random effects. I am usually running two versions of the model, separated by sex (see more below...).\n\n\n\n\nFirst question: what is the minimum sample size I would need to run this model? I get told a) minimum is 10 events per covariate and less than that is an abomination, or, B) as long as the model converges it's fine.\n\n\n\n\nSecond question: I am including quadratics of all main terms except two (which are 2 level factors). Can I include interactions between two quadratic terms? Currently my model looks like this: y = a + b + a^2 + b^2 + ab + a^2b^2\nMy justification was that, we expect these terms to be quadratic, we also expect them to interact, so their interaction could be on a quadratic shape. However, this is obviously really hard to interpret...\n\n\n\n\nThird question: when I ran the model as above, I got a significant p value for some of the interactions (including some of the quadratics). However, after discussions with my supervisor, he wants me to run the model and remove the two factorial covariates (and their associated interactions) and also the individuals which are positive for those factors (which are the minority). Is this a valid approach? The justification is to reduce model complexity/aid interpretability and to prevent over-parameterisation. However, doing this reduces my sample size to the extent that I have to merge both sexes into one model, so then I have to include sex and other interactions as covariates too. Someone else suggested to me that I just remove the covariates from the model, but keep in the individuals in the data. However, considering there is a significant result there, wouldn't doing this over- and underestimate the effects for individuals with different values in the factorial covariates?\n\n\n\n\nSorry for the length, please ask if I need to clarify something.\n\n\n\n\nThanks\n\n\n\n\nEdit: additional information\n\n\n\n\nfor the largest main model (before removing two covariates):\nmales only model n = 172 events out of 227, maximal model has 28 parameters, post selection: 19 parameters\n\n\n\n\nWhen removing the two covariates discussed in Q3:\n\n\n\n\ncombined sexes model n = 289 events out of 386, maximal model has 25 parameters, post selection: 10 parameters\n\n\n\n\nmales only model n = 136 events out of 183, maximal model has 18 parameters, post selection: 14 parameters\n\n\n\n\nfemales only model n = 153 events out of 203, maximal model has 18 parameters, post selection, 15 parameters\n\n\n\n\nRandom effects are mum ID, dominant male ID, genetic father ID and birth year.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "user29485477", "profile_url": "https://stats.stackexchange.com/users/516400/user29485477", "user_type": "registered"}, "created_at": "2026-09-08T13:20:34+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "F65BFEA4-5133-45F2-87BF-AC7114617786", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F65BFEA4-5133-45F2-87BF-AC7114617786/view-source"}, {"content_license": null, "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-08T19:34:39+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "3A35098E-6252-4D42-98BF-7EE6B2929FB5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3A35098E-6252-4D42-98BF-7EE6B2929FB5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "user29485477", "profile_url": "https://stats.stackexchange.com/users/516400/user29485477", "user_type": "registered"}, "created_at": "2026-09-09T15:01:19+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "4478C820-E915-447D-A401-7218BE7B0A8A", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4478C820-E915-447D-A401-7218BE7B0A8A/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677101/coxme-modelling-with-quadratics", "split": "train", "split_group": "a19c315da10f23aef5750c4ca2525cab420d55b124dae1795e657b86a2de9a4f", "tags": ["survival", "interaction", "modeling", "quadratic"], "thread_id": "stats:677101", "title": "Coxme Modelling with Quadratics"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

Everything is dependent on your second C. Even random things like rolling dice (someone has to roll the dice, if there are no humans, no dice) so that seems a bit overdone.

\n

I guess you could argue that every pair of variables is only conditionally independent, and just seek conditions that are very weak, or easy to meet.

\n

Once you do that, you can have interesting discussions about how to measure the weakness of the condition, and then what variables really are independent.

\n

E.g. The last digit of your phone number and the number of letters in your first name.

\n

But you could also discuss pairs of variables that seem independent (at least conditionally) ut really aren't.

\n

Given that you are teaching this, I think discussions are going to be more valuable than just giving examples.

\n", "answer_id": 677113, "answer_text": "Everything is dependent on your second C. Even random things like rolling dice (someone has to roll the dice, if there are no humans, no dice) so that seems a bit overdone.\n\n\n\n\nI guess you could argue that every pair of variables is only conditionally independent, and just seek conditions that are very weak, or easy to meet.\n\n\n\n\nOnce you do that, you can have interesting discussions about how to measure the weakness of the condition, and then what variables really are independent.\n\n\n\n\nE.g. The last digit of your phone number and the number of letters in your first name.\n\n\n\n\nBut you could also discuss pairs of variables that seem independent (at least conditionally) ut really aren't.\n\n\n\n\nGiven that you are teaching this, I think discussions are going to be more valuable than just giving examples.", "answer_url": "https://stats.stackexchange.com/a/677113", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T11:46:26+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-09-09T11:46:26+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "FCBDA039-4581-4D66-8992-B53869AB3A9C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FCBDA039-4581-4D66-8992-B53869AB3A9C/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "28B8AA75-8BA8-464B-97B6-18FD394C8843", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/28B8AA75-8BA8-464B-97B6-18FD394C8843/view-source"}], "score": 5, "updated_at": "2026-09-09T11:46:26+00:00"}, {"answer_html": "

Coin flips always worked for undergraduate health science majors. They also understand cards. The reason these work well is that they are uncomplicated and easy to apply simple models to (e.g., fair coin gives $P(\\text{Heads}) = \\frac{1}{2}$). More importantly, it's pretty simple to use both to explain the informal and formal versions of independence:

\n
    \n
  • Informal: two events are independent if knowing that one event happened doesn't change the probability of the second event happening.
  • \n
  • Formal: two events are independent if their joint probability, $P(A,B)$ factors into the product of the two marginal probabilities: $P(A)P(B)$.
  • \n
\n

You could even try demonstrating it or by simulation of flips or rolls of die. I think a good demonstration, à la physics class, is as good as any relatable example.

\n

I even think discussing conditional independence can be helpful to explain the concept. That even sets up later discussion where conditional independence is super important: e.g., in controlling for variables in regression or any other analysis with multiple confounding variables.

\n

Finally, I wonder if it is really true that such an event $C$ in your second example truly affects the dependence of $A$ and $B$ in that example. You could even use this as a discussion point:

\n
    \n
  • Given that we know that everything is "dependent" on background conditions in the universe, does knowing that add anything to the way we might show independence of $A = \\text{liking cats}$ and $B = \\text{eating a hot dog on day Y}$? Does the joint probability $P(A,B)$ still factor into $P(A)P(B)$ in this case? It should be fairly easy to come up with numerical examples here, yes?
  • \n
\n", "answer_id": 677116, "answer_text": "Coin flips always worked for undergraduate health science majors. They also understand cards. The reason these work well is that they are uncomplicated and easy to apply simple models to (e.g., fair coin gives $P(\\text{Heads}) = \\frac{1}{2}$). More importantly, it's pretty simple to use both to explain the informal and formal versions of independence:\n\n\n\n\n\nInformal: two events are independent if knowing that one event happened doesn't change the probability of the second event happening.\n\n\n\n\nFormal: two events are independent if their joint probability, $P(A,B)$ factors into the product of the two marginal probabilities: $P(A)P(B)$.\n\n\n\n\n\nYou could even try demonstrating it or by simulation of flips or rolls of die. I think a good demonstration, à la physics class, is as good as any relatable example.\n\n\n\n\nI even think discussing conditional independence can be helpful to explain the concept. That even sets up later discussion where conditional independence is super important: e.g., in controlling for variables in regression or any other analysis with multiple confounding variables.\n\n\n\n\nFinally, I wonder if it is really true that such an event $C$ in your second example truly affects the dependence of $A$ and $B$ in that example. You could even use this as a discussion point:\n\n\n\n\n\nGiven that we know that everything is \"dependent\" on background conditions in the universe, does knowing that add anything to the way we might show independence of $A = \\text{liking cats}$ and $B = \\text{eating a hot dog on day Y}$? Does the joint probability $P(A,B)$ still factor into $P(A)P(B)$ in this case? It should be fairly easy to come up with numerical examples here, yes?", "answer_url": "https://stats.stackexchange.com/a/677116", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T12:37: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": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-09T12:37:01+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "1C64B9F8-E0B2-427F-B96D-3A8318021628", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1C64B9F8-E0B2-427F-B96D-3A8318021628/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-09T13:55:27+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "22760A03-7CC9-428E-BBC0-5B00B4369DED", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/22760A03-7CC9-428E-BBC0-5B00B4369DED/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-09T16:02:03+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "3A14A650-69D7-4AD7-9F34-29E76822560F", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3A14A650-69D7-4AD7-9F34-29E76822560F/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B9B12584-278F-47C4-8A71-6175AA1870C9", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/B9B12584-278F-47C4-8A71-6175AA1870C9/view-source"}], "score": 4, "updated_at": "2026-09-09T16:02:03+00:00"}, {"answer_html": "

The amount of rainfall in a certain place on a day is independent of what day of the week it is. Thursdays aren't rainier/less rainy on average than other days of the week.

\n", "answer_id": 677125, "answer_text": "The amount of rainfall in a certain place on a day is independent of what day of the week it is. Thursdays aren't rainier/less rainy on average than other days of the week.", "answer_url": "https://stats.stackexchange.com/a/677125", "author": "Rosie F", "author_url": "https://stats.stackexchange.com/users/325551/rosie-f", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-10T06:09:47+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": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rosie F", "profile_url": "https://stats.stackexchange.com/users/325551/rosie-f", "user_type": "registered"}, "created_at": "2026-09-10T06:09:47+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "36C5D523-618B-4773-B6DC-6126E002AED3", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/36C5D523-618B-4773-B6DC-6126E002AED3/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "D13D5A49-991C-4952-B437-7483D7E92988", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/D13D5A49-991C-4952-B437-7483D7E92988/view-source"}], "score": -1, "updated_at": "2026-09-10T06:09:47+00:00"}, {"answer_html": "

Thich Nhat Hanh says "Everything depends on everything else". I tend to agree with this. Statistical modelling of processes in the world always involves simplification. We model things as independent if we think that "any dependence is probably either so weak as to be irrelevant to what we are interested in" or "so complex that putting together a good model for it is so hard that it isn't worth the hassle" (or both). Given that this is so, rolling a die twice is probably about as good as it gets. Many other things fit the bill, but none of these are examples for being really independent but rather starting points for saying, intuitively we may model these as independent. But then, what could be problems with it, (how) could we model them, and do we think this will help matters?

\n

Note also that we need to rely on some kind of simplification if we want to learn systematically from experience at all, because how can we use observations from the past to learn about the future if whatever happens in the future can depend on all kinds of stuff, observed and unobserved, in all kinds of weird ways that we can neither observe nor control?

\n", "answer_id": 677158, "answer_text": "Thich Nhat Hanh says \"Everything depends on everything else\". I tend to agree with this. Statistical modelling of processes in the world always involves simplification. We model things as independent if we think that \"any dependence is probably either so weak as to be irrelevant to what we are interested in\" or \"so complex that putting together a good model for it is so hard that it isn't worth the hassle\" (or both). Given that this is so, rolling a die twice is probably about as good as it gets. Many other things fit the bill, but none of these are examples for being really independent but rather starting points for saying, intuitively we may model these as independent. But then, what could be problems with it, (how) could we model them, and do we think this will help matters?\n\n\n\n\nNote also that we need to rely on some kind of simplification if we want to learn systematically from experience at all, because how can we use observations from the past to learn about the future if whatever happens in the future can depend on all kinds of stuff, observed and unobserved, in all kinds of weird ways that we can neither observe nor control?", "answer_url": "https://stats.stackexchange.com/a/677158", "author": "Christian Hennig", "author_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T10:23:34+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": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-13T10:23:34+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "05925295-B472-4DA0-A137-B61CAFF1CC1D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/05925295-B472-4DA0-A137-B61CAFF1CC1D/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "FD8F320F-74B7-4835-A873-9DBC84F39764", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/FD8F320F-74B7-4835-A873-9DBC84F39764/view-source"}], "score": 1, "updated_at": "2026-09-13T10:23:34+00:00"}, {"answer_html": "
\n
    \n
  • $A$: Bob liking cats, $B$: Enrique eating a hotdog on Saturday 9/5/2026.\n- $C$: these are both dependent on the human race existing 4 billion years after the Earth's formation
  • \n
\n
\n

This example shows that we can get independence by conditioning on related variables.

\n

In the quoted example, nobody will consider the probability of the event A by including the state space where C can be true or false, or considering where Bob can live in different worlds.

\n

Expressing the probability of Bob liking cats, presupposes that Bob exists and conditions on our world. It is considering the probability that any person called Bob would like cats. E.g. if out of the 1216912 Bob's living in the world, 784110 like cats, then we can say that for any randomly selected Bob, the probability of liking cats is approximately 64%. The issue whether the human race exists doesn't matter.

\n", "answer_id": 677159, "answer_text": "$A$: Bob liking cats, $B$: Enrique eating a hotdog on Saturday 9/5/2026.\n- $C$: these are both dependent on the human race existing 4 billion years after the Earth's formation\n\n\n\n\n\n\n\n\nThis example shows that we can get independence by conditioning on related variables.\n\n\n\n\nIn the quoted example, nobody will consider the probability of the event A by including the state space where C can be true or false, or considering where Bob can live in different worlds.\n\n\n\n\nExpressing the probability of Bob liking cats, presupposes that Bob exists and conditions on our world. It is considering the probability that any person called Bob would like cats. E.g. if out of the 1216912 Bob's living in the world, 784110 like cats, then we can say that for any randomly selected Bob, the probability of liking cats is approximately 64%. The issue whether the human race exists doesn't matter.", "answer_url": "https://stats.stackexchange.com/a/677159", "author": "Sextus Empiricus", "author_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T11:23:05+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": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sextus Empiricus", "profile_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "user_type": "registered"}, "created_at": "2026-09-13T11:23:05+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "4D4882E8-A3E7-4B18-A2A1-EBCD304BD135", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4D4882E8-A3E7-4B18-A2A1-EBCD304BD135/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7A0D168D-47D2-4CC6-B1EA-213CEB836C84", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/7A0D168D-47D2-4CC6-B1EA-213CEB836C84/view-source"}], "score": 0, "updated_at": "2026-09-13T11:23:05+00:00"}], "product": "statistics_qa", "question": "I'm trying to come up with relatable examples to teach the concept of independence/orthogonality of two random variables $A$ and $B$. But my Bayes-Net-rotted brain keeps coming up with scenarios of how the two quantities/RVs could possibly not be independent (usually because of a common factor $C$).\n\n\n\n\nSome ANTI-examples of independence:\n\n\n\n\n\nBob being $A$ (able to jump high) and Bob being $B$ (good at chess).\n\n\n\nif Bob had $C$ (a good childhood with a happy family), then he is more likely to be $A$ and $B$.\n\n\n\n\n\n\n\n\n$A$: Bob liking cats, $B$: Enrique eating a hotdog on Saturday 9/5/2026.\n\n\n\n$C$: these are both dependent on the human race existing 4 billion years after the Earth's formation\n\n\n\n\n\n\n\n\n\nI intuitively understand independence. But I'm trying to come up with a more full-proof method to explain it. Note that the explanation has to be RELATABLE. It's trivial to define mathematically.\n\n\n\n\nAlso, note that I understand that this question may be more philosophical, and less hard stats. I'm just trying to figure out effective analogies to teach the concept of independence/orthogonality.", "record_id": "Scientific-Statistics-QA:stats:677110", "selected_answer": {"answer_html": "

What seems to be tripping you up here is a terminology issue. When scientists try to give names to new abstract concepts, they often, and in all disciplines (not just statistics and probability), hijack words from the common vocabulary, as inventing a new name for every new concept would be impractical (people would not understand what we are saying, and would try to find a common word which, more or less, covers the concept).

\n

This is what happened here with independence. Statisticians use this word to describe a much narrower concept than the customary meaning. Looking up independence statistics in Wikipedia, you obtain the following definition.

\n
\n

Two events are independent, statistically independent, or\nstochastically independent if, informally speaking, the occurrence\nof one does not affect the probability of occurrence of the other or,\nequivalently, does not affect the odds.

\n
\n

Your first counter-example is perfectly valid: many personal traits can be, at least loosely, correlated, based on other factors such as upbringing, education, social status, etc.\nHowever, your second counter-example is off the mark. Factor $C$ does not affect the probability of event $B$ happening. Yes, both events depend on $C$ (if $C$ did not happen, then neither would $A$ or $B$). But once you know that $A$ happened, you know nothing more about whether $B$ will occur, or not, and with which probability. Here, you took the meaning of independence well beyond its meaning in statistics. So, statistically speaking, in your 2nd example, $A$ and $B$ are in fact independent.

\n

And yes, this hijacking of common terms trips us up (and students of statistics) all the time; significance, coverage, likelihood vs. probability, unit, consistent, degrees of freedom -one of my "favorites"-, etc.

\n

So, wrt what independence means in statistics, allow me to quote Inigo Montoya: “I do not think it means what you think it means”.

\n

An example of “perfect” dependence would be a single fair coin flip: if it falls head, then you know, with 100% certainty, what the face is which is facing the ground. A “perfect” independent example would be the flip of 2 fair coins; the fact that one of them fell head does not affect in any way how the 2nd coin will land.

\n

Another example of independence would be drawing a single card from a 52 cards deck. The suit of the first card you draw does not in any way affect the probability of the suit of the 2nd card you draw (iff you draw with replacement!). But if you do not draw with replacement, then that first card will influence (weakly) the probabilities for the suit of the 2nd card. And after you drew the 51st card (w/o replacement), you can predict with absolute certainty the suit of the last card.

\n

The same Wikipedia page gives the following good examples:

\n
\n

The event of getting a 6 the first time a die is rolled and the event of getting a 6 the second\ntime are independent. By contrast, the event of getting a 6 the first time a die is rolled and the\nevent that the sum of the numbers seen on the first and second trial is 8 are not independent.

\n
\n

Now, all these examples assume fair coins, or fair decks of cards. But even then, there still is independence: say the coin flips head 75% of the time, and tail 25%. The fact that it landed head on the 1st toss in no way changes the probabilities of the 2nd toss: they will remain .75/.25, and the first toss did not influence the probabilities of 2nd one.

\n", "answer_id": 677118, "answer_text": "What seems to be tripping you up here is a terminology issue. When scientists try to give names to new abstract concepts, they often, and in all disciplines (not just statistics and probability), hijack words from the common vocabulary, as inventing a new name for every new concept would be impractical (people would not understand what we are saying, and would try to find a common word which, more or less, covers the concept).\n\n\n\n\nThis is what happened here with independence. Statisticians use this word to describe a much narrower concept than the customary meaning. Looking up independence statistics in Wikipedia (https://en.wikipedia.org/wiki/Independence_(probability_theory)), you obtain the following definition.\n\n\n\n\n\n\n\nTwo events are independent, statistically independent, or\nstochastically independent if, informally speaking, the occurrence\nof one does not affect the probability of occurrence of the other or,\nequivalently, does not affect the odds.\n\n\n\n\n\n\n\nYour first counter-example is perfectly valid: many personal traits can be, at least loosely, correlated, based on other factors such as upbringing, education, social status, etc.\nHowever, your second counter-example is off the mark. Factor $C$ does not affect the probability of event $B$ happening. Yes, both events depend on $C$ (if $C$ did not happen, then neither would $A$ or $B$). But once you know that $A$ happened, you know nothing more about whether $B$ will occur, or not, and with which probability. Here, you took the meaning of independence well beyond its meaning in statistics. So, statistically speaking, in your 2nd example, $A$ and $B$ are in fact independent.\n\n\n\n\nAnd yes, this hijacking of common terms trips us up (and students of statistics) all the time; significance, coverage, likelihood vs. probability, unit, consistent, degrees of freedom -one of my \"favorites\"-, etc.\n\n\n\n\nSo, wrt what independence means in statistics, allow me to quote Inigo Montoya: “I do not think it means what you think it means”.\n\n\n\n\nAn example of “perfect” dependence would be a single fair coin flip: if it falls head, then you know, with 100% certainty, what the face is which is facing the ground. A “perfect” independent example would be the flip of 2 fair coins; the fact that one of them fell head does not affect in any way how the 2nd coin will land.\n\n\n\n\nAnother example of independence would be drawing a single card from a 52 cards deck. The suit of the first card you draw does not in any way affect the probability of the suit of the 2nd card you draw (iff you draw with replacement!). But if you do not draw with replacement, then that first card will influence (weakly) the probabilities for the suit of the 2nd card. And after you drew the 51st card (w/o replacement), you can predict with absolute certainty the suit of the last card.\n\n\n\n\nThe same Wikipedia page gives the following good examples:\n\n\n\n\n\n\n\nThe event of getting a 6 the first time a die is rolled and the event of getting a 6 the second\ntime are independent. By contrast, the event of getting a 6 the first time a die is rolled and the\nevent that the sum of the numbers seen on the first and second trial is 8 are not independent.\n\n\n\n\n\n\n\nNow, all these examples assume fair coins, or fair decks of cards. But even then, there still is independence: say the coin flips head 75% of the time, and tail 25%. The fact that it landed head on the 1st toss in no way changes the probabilities of the 2nd toss: they will remain .75/.25, and the first toss did not influence the probabilities of 2nd one.", "answer_url": "https://stats.stackexchange.com/a/677118", "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-09T15:41:47+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": 677110, "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-09T15:41:47+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "95084292-C973-4128-9914-5B5C589E44C8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/95084292-C973-4128-9914-5B5C589E44C8/view-source"}, {"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-09T16:06:44+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "67C3A108-1229-423E-9C9B-BD41CC0D66B5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67C3A108-1229-423E-9C9B-BD41CC0D66B5/view-source"}, {"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-09T16:16:49+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "2785F5A7-398F-4C71-823A-143D526A9493", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2785F5A7-398F-4C71-823A-143D526A9493/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-09T16:20:43+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "72508573-D0A1-4718-B981-8955EE7BE70C", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/72508573-D0A1-4718-B981-8955EE7BE70C/view-source"}, {"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-09T22:15:48+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "9EFB0FB0-DF11-4E9C-B82F-BB9D9118C1A4", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9EFB0FB0-DF11-4E9C-B82F-BB9D9118C1A4/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "981B2887-B856-42CC-B6B6-905DED7C9504", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/981B2887-B856-42CC-B6B6-905DED7C9504/view-source"}], "score": 12, "updated_at": "2026-09-09T22:15:48+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Everything is dependent on your second C. Even random things like rolling dice (someone has to roll the dice, if there are no humans, no dice) so that seems a bit overdone.

\n

I guess you could argue that every pair of variables is only conditionally independent, and just seek conditions that are very weak, or easy to meet.

\n

Once you do that, you can have interesting discussions about how to measure the weakness of the condition, and then what variables really are independent.

\n

E.g. The last digit of your phone number and the number of letters in your first name.

\n

But you could also discuss pairs of variables that seem independent (at least conditionally) ut really aren't.

\n

Given that you are teaching this, I think discussions are going to be more valuable than just giving examples.

\n", "answer_id": 677113, "answer_text": "Everything is dependent on your second C. Even random things like rolling dice (someone has to roll the dice, if there are no humans, no dice) so that seems a bit overdone.\n\n\n\n\nI guess you could argue that every pair of variables is only conditionally independent, and just seek conditions that are very weak, or easy to meet.\n\n\n\n\nOnce you do that, you can have interesting discussions about how to measure the weakness of the condition, and then what variables really are independent.\n\n\n\n\nE.g. The last digit of your phone number and the number of letters in your first name.\n\n\n\n\nBut you could also discuss pairs of variables that seem independent (at least conditionally) ut really aren't.\n\n\n\n\nGiven that you are teaching this, I think discussions are going to be more valuable than just giving examples.", "answer_url": "https://stats.stackexchange.com/a/677113", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T11:46:26+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-09-09T11:46:26+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "FCBDA039-4581-4D66-8992-B53869AB3A9C", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FCBDA039-4581-4D66-8992-B53869AB3A9C/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "28B8AA75-8BA8-464B-97B6-18FD394C8843", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/28B8AA75-8BA8-464B-97B6-18FD394C8843/view-source"}], "score": 5, "updated_at": "2026-09-09T11:46:26+00:00"}, {"answer_html": "

Coin flips always worked for undergraduate health science majors. They also understand cards. The reason these work well is that they are uncomplicated and easy to apply simple models to (e.g., fair coin gives $P(\\text{Heads}) = \\frac{1}{2}$). More importantly, it's pretty simple to use both to explain the informal and formal versions of independence:

\n
    \n
  • Informal: two events are independent if knowing that one event happened doesn't change the probability of the second event happening.
  • \n
  • Formal: two events are independent if their joint probability, $P(A,B)$ factors into the product of the two marginal probabilities: $P(A)P(B)$.
  • \n
\n

You could even try demonstrating it or by simulation of flips or rolls of die. I think a good demonstration, à la physics class, is as good as any relatable example.

\n

I even think discussing conditional independence can be helpful to explain the concept. That even sets up later discussion where conditional independence is super important: e.g., in controlling for variables in regression or any other analysis with multiple confounding variables.

\n

Finally, I wonder if it is really true that such an event $C$ in your second example truly affects the dependence of $A$ and $B$ in that example. You could even use this as a discussion point:

\n
    \n
  • Given that we know that everything is "dependent" on background conditions in the universe, does knowing that add anything to the way we might show independence of $A = \\text{liking cats}$ and $B = \\text{eating a hot dog on day Y}$? Does the joint probability $P(A,B)$ still factor into $P(A)P(B)$ in this case? It should be fairly easy to come up with numerical examples here, yes?
  • \n
\n", "answer_id": 677116, "answer_text": "Coin flips always worked for undergraduate health science majors. They also understand cards. The reason these work well is that they are uncomplicated and easy to apply simple models to (e.g., fair coin gives $P(\\text{Heads}) = \\frac{1}{2}$). More importantly, it's pretty simple to use both to explain the informal and formal versions of independence:\n\n\n\n\n\nInformal: two events are independent if knowing that one event happened doesn't change the probability of the second event happening.\n\n\n\n\nFormal: two events are independent if their joint probability, $P(A,B)$ factors into the product of the two marginal probabilities: $P(A)P(B)$.\n\n\n\n\n\nYou could even try demonstrating it or by simulation of flips or rolls of die. I think a good demonstration, à la physics class, is as good as any relatable example.\n\n\n\n\nI even think discussing conditional independence can be helpful to explain the concept. That even sets up later discussion where conditional independence is super important: e.g., in controlling for variables in regression or any other analysis with multiple confounding variables.\n\n\n\n\nFinally, I wonder if it is really true that such an event $C$ in your second example truly affects the dependence of $A$ and $B$ in that example. You could even use this as a discussion point:\n\n\n\n\n\nGiven that we know that everything is \"dependent\" on background conditions in the universe, does knowing that add anything to the way we might show independence of $A = \\text{liking cats}$ and $B = \\text{eating a hot dog on day Y}$? Does the joint probability $P(A,B)$ still factor into $P(A)P(B)$ in this case? It should be fairly easy to come up with numerical examples here, yes?", "answer_url": "https://stats.stackexchange.com/a/677116", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-09T12:37: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": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-09T12:37:01+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "1C64B9F8-E0B2-427F-B96D-3A8318021628", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1C64B9F8-E0B2-427F-B96D-3A8318021628/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-09T13:55:27+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "22760A03-7CC9-428E-BBC0-5B00B4369DED", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/22760A03-7CC9-428E-BBC0-5B00B4369DED/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-09T16:02:03+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "3A14A650-69D7-4AD7-9F34-29E76822560F", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3A14A650-69D7-4AD7-9F34-29E76822560F/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B9B12584-278F-47C4-8A71-6175AA1870C9", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/B9B12584-278F-47C4-8A71-6175AA1870C9/view-source"}], "score": 4, "updated_at": "2026-09-09T16:02:03+00:00"}, {"answer_html": "

What seems to be tripping you up here is a terminology issue. When scientists try to give names to new abstract concepts, they often, and in all disciplines (not just statistics and probability), hijack words from the common vocabulary, as inventing a new name for every new concept would be impractical (people would not understand what we are saying, and would try to find a common word which, more or less, covers the concept).

\n

This is what happened here with independence. Statisticians use this word to describe a much narrower concept than the customary meaning. Looking up independence statistics in Wikipedia, you obtain the following definition.

\n
\n

Two events are independent, statistically independent, or\nstochastically independent if, informally speaking, the occurrence\nof one does not affect the probability of occurrence of the other or,\nequivalently, does not affect the odds.

\n
\n

Your first counter-example is perfectly valid: many personal traits can be, at least loosely, correlated, based on other factors such as upbringing, education, social status, etc.\nHowever, your second counter-example is off the mark. Factor $C$ does not affect the probability of event $B$ happening. Yes, both events depend on $C$ (if $C$ did not happen, then neither would $A$ or $B$). But once you know that $A$ happened, you know nothing more about whether $B$ will occur, or not, and with which probability. Here, you took the meaning of independence well beyond its meaning in statistics. So, statistically speaking, in your 2nd example, $A$ and $B$ are in fact independent.

\n

And yes, this hijacking of common terms trips us up (and students of statistics) all the time; significance, coverage, likelihood vs. probability, unit, consistent, degrees of freedom -one of my "favorites"-, etc.

\n

So, wrt what independence means in statistics, allow me to quote Inigo Montoya: “I do not think it means what you think it means”.

\n

An example of “perfect” dependence would be a single fair coin flip: if it falls head, then you know, with 100% certainty, what the face is which is facing the ground. A “perfect” independent example would be the flip of 2 fair coins; the fact that one of them fell head does not affect in any way how the 2nd coin will land.

\n

Another example of independence would be drawing a single card from a 52 cards deck. The suit of the first card you draw does not in any way affect the probability of the suit of the 2nd card you draw (iff you draw with replacement!). But if you do not draw with replacement, then that first card will influence (weakly) the probabilities for the suit of the 2nd card. And after you drew the 51st card (w/o replacement), you can predict with absolute certainty the suit of the last card.

\n

The same Wikipedia page gives the following good examples:

\n
\n

The event of getting a 6 the first time a die is rolled and the event of getting a 6 the second\ntime are independent. By contrast, the event of getting a 6 the first time a die is rolled and the\nevent that the sum of the numbers seen on the first and second trial is 8 are not independent.

\n
\n

Now, all these examples assume fair coins, or fair decks of cards. But even then, there still is independence: say the coin flips head 75% of the time, and tail 25%. The fact that it landed head on the 1st toss in no way changes the probabilities of the 2nd toss: they will remain .75/.25, and the first toss did not influence the probabilities of 2nd one.

\n", "answer_id": 677118, "answer_text": "What seems to be tripping you up here is a terminology issue. When scientists try to give names to new abstract concepts, they often, and in all disciplines (not just statistics and probability), hijack words from the common vocabulary, as inventing a new name for every new concept would be impractical (people would not understand what we are saying, and would try to find a common word which, more or less, covers the concept).\n\n\n\n\nThis is what happened here with independence. Statisticians use this word to describe a much narrower concept than the customary meaning. Looking up independence statistics in Wikipedia (https://en.wikipedia.org/wiki/Independence_(probability_theory)), you obtain the following definition.\n\n\n\n\n\n\n\nTwo events are independent, statistically independent, or\nstochastically independent if, informally speaking, the occurrence\nof one does not affect the probability of occurrence of the other or,\nequivalently, does not affect the odds.\n\n\n\n\n\n\n\nYour first counter-example is perfectly valid: many personal traits can be, at least loosely, correlated, based on other factors such as upbringing, education, social status, etc.\nHowever, your second counter-example is off the mark. Factor $C$ does not affect the probability of event $B$ happening. Yes, both events depend on $C$ (if $C$ did not happen, then neither would $A$ or $B$). But once you know that $A$ happened, you know nothing more about whether $B$ will occur, or not, and with which probability. Here, you took the meaning of independence well beyond its meaning in statistics. So, statistically speaking, in your 2nd example, $A$ and $B$ are in fact independent.\n\n\n\n\nAnd yes, this hijacking of common terms trips us up (and students of statistics) all the time; significance, coverage, likelihood vs. probability, unit, consistent, degrees of freedom -one of my \"favorites\"-, etc.\n\n\n\n\nSo, wrt what independence means in statistics, allow me to quote Inigo Montoya: “I do not think it means what you think it means”.\n\n\n\n\nAn example of “perfect” dependence would be a single fair coin flip: if it falls head, then you know, with 100% certainty, what the face is which is facing the ground. A “perfect” independent example would be the flip of 2 fair coins; the fact that one of them fell head does not affect in any way how the 2nd coin will land.\n\n\n\n\nAnother example of independence would be drawing a single card from a 52 cards deck. The suit of the first card you draw does not in any way affect the probability of the suit of the 2nd card you draw (iff you draw with replacement!). But if you do not draw with replacement, then that first card will influence (weakly) the probabilities for the suit of the 2nd card. And after you drew the 51st card (w/o replacement), you can predict with absolute certainty the suit of the last card.\n\n\n\n\nThe same Wikipedia page gives the following good examples:\n\n\n\n\n\n\n\nThe event of getting a 6 the first time a die is rolled and the event of getting a 6 the second\ntime are independent. By contrast, the event of getting a 6 the first time a die is rolled and the\nevent that the sum of the numbers seen on the first and second trial is 8 are not independent.\n\n\n\n\n\n\n\nNow, all these examples assume fair coins, or fair decks of cards. But even then, there still is independence: say the coin flips head 75% of the time, and tail 25%. The fact that it landed head on the 1st toss in no way changes the probabilities of the 2nd toss: they will remain .75/.25, and the first toss did not influence the probabilities of 2nd one.", "answer_url": "https://stats.stackexchange.com/a/677118", "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-09T15:41:47+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": 677110, "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-09T15:41:47+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "95084292-C973-4128-9914-5B5C589E44C8", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/95084292-C973-4128-9914-5B5C589E44C8/view-source"}, {"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-09T16:06:44+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "67C3A108-1229-423E-9C9B-BD41CC0D66B5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/67C3A108-1229-423E-9C9B-BD41CC0D66B5/view-source"}, {"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-09T16:16:49+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "2785F5A7-398F-4C71-823A-143D526A9493", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2785F5A7-398F-4C71-823A-143D526A9493/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-09T16:20:43+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "72508573-D0A1-4718-B981-8955EE7BE70C", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/72508573-D0A1-4718-B981-8955EE7BE70C/view-source"}, {"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-09T22:15:48+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "9EFB0FB0-DF11-4E9C-B82F-BB9D9118C1A4", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9EFB0FB0-DF11-4E9C-B82F-BB9D9118C1A4/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "981B2887-B856-42CC-B6B6-905DED7C9504", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/981B2887-B856-42CC-B6B6-905DED7C9504/view-source"}], "score": 12, "updated_at": "2026-09-09T22:15:48+00:00"}, {"answer_html": "

The amount of rainfall in a certain place on a day is independent of what day of the week it is. Thursdays aren't rainier/less rainy on average than other days of the week.

\n", "answer_id": 677125, "answer_text": "The amount of rainfall in a certain place on a day is independent of what day of the week it is. Thursdays aren't rainier/less rainy on average than other days of the week.", "answer_url": "https://stats.stackexchange.com/a/677125", "author": "Rosie F", "author_url": "https://stats.stackexchange.com/users/325551/rosie-f", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-10T06:09:47+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": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rosie F", "profile_url": "https://stats.stackexchange.com/users/325551/rosie-f", "user_type": "registered"}, "created_at": "2026-09-10T06:09:47+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "36C5D523-618B-4773-B6DC-6126E002AED3", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/36C5D523-618B-4773-B6DC-6126E002AED3/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "D13D5A49-991C-4952-B437-7483D7E92988", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/D13D5A49-991C-4952-B437-7483D7E92988/view-source"}], "score": -1, "updated_at": "2026-09-10T06:09:47+00:00"}, {"answer_html": "

Thich Nhat Hanh says "Everything depends on everything else". I tend to agree with this. Statistical modelling of processes in the world always involves simplification. We model things as independent if we think that "any dependence is probably either so weak as to be irrelevant to what we are interested in" or "so complex that putting together a good model for it is so hard that it isn't worth the hassle" (or both). Given that this is so, rolling a die twice is probably about as good as it gets. Many other things fit the bill, but none of these are examples for being really independent but rather starting points for saying, intuitively we may model these as independent. But then, what could be problems with it, (how) could we model them, and do we think this will help matters?

\n

Note also that we need to rely on some kind of simplification if we want to learn systematically from experience at all, because how can we use observations from the past to learn about the future if whatever happens in the future can depend on all kinds of stuff, observed and unobserved, in all kinds of weird ways that we can neither observe nor control?

\n", "answer_id": 677158, "answer_text": "Thich Nhat Hanh says \"Everything depends on everything else\". I tend to agree with this. Statistical modelling of processes in the world always involves simplification. We model things as independent if we think that \"any dependence is probably either so weak as to be irrelevant to what we are interested in\" or \"so complex that putting together a good model for it is so hard that it isn't worth the hassle\" (or both). Given that this is so, rolling a die twice is probably about as good as it gets. Many other things fit the bill, but none of these are examples for being really independent but rather starting points for saying, intuitively we may model these as independent. But then, what could be problems with it, (how) could we model them, and do we think this will help matters?\n\n\n\n\nNote also that we need to rely on some kind of simplification if we want to learn systematically from experience at all, because how can we use observations from the past to learn about the future if whatever happens in the future can depend on all kinds of stuff, observed and unobserved, in all kinds of weird ways that we can neither observe nor control?", "answer_url": "https://stats.stackexchange.com/a/677158", "author": "Christian Hennig", "author_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T10:23:34+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": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Christian Hennig", "profile_url": "https://stats.stackexchange.com/users/247165/christian-hennig", "user_type": "registered"}, "created_at": "2026-09-13T10:23:34+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "05925295-B472-4DA0-A137-B61CAFF1CC1D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/05925295-B472-4DA0-A137-B61CAFF1CC1D/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "FD8F320F-74B7-4835-A873-9DBC84F39764", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/FD8F320F-74B7-4835-A873-9DBC84F39764/view-source"}], "score": 1, "updated_at": "2026-09-13T10:23:34+00:00"}, {"answer_html": "
\n
    \n
  • $A$: Bob liking cats, $B$: Enrique eating a hotdog on Saturday 9/5/2026.\n- $C$: these are both dependent on the human race existing 4 billion years after the Earth's formation
  • \n
\n
\n

This example shows that we can get independence by conditioning on related variables.

\n

In the quoted example, nobody will consider the probability of the event A by including the state space where C can be true or false, or considering where Bob can live in different worlds.

\n

Expressing the probability of Bob liking cats, presupposes that Bob exists and conditions on our world. It is considering the probability that any person called Bob would like cats. E.g. if out of the 1216912 Bob's living in the world, 784110 like cats, then we can say that for any randomly selected Bob, the probability of liking cats is approximately 64%. The issue whether the human race exists doesn't matter.

\n", "answer_id": 677159, "answer_text": "$A$: Bob liking cats, $B$: Enrique eating a hotdog on Saturday 9/5/2026.\n- $C$: these are both dependent on the human race existing 4 billion years after the Earth's formation\n\n\n\n\n\n\n\n\nThis example shows that we can get independence by conditioning on related variables.\n\n\n\n\nIn the quoted example, nobody will consider the probability of the event A by including the state space where C can be true or false, or considering where Bob can live in different worlds.\n\n\n\n\nExpressing the probability of Bob liking cats, presupposes that Bob exists and conditions on our world. It is considering the probability that any person called Bob would like cats. E.g. if out of the 1216912 Bob's living in the world, 784110 like cats, then we can say that for any randomly selected Bob, the probability of liking cats is approximately 64%. The issue whether the human race exists doesn't matter.", "answer_url": "https://stats.stackexchange.com/a/677159", "author": "Sextus Empiricus", "author_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T11:23:05+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": 677110, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Sextus Empiricus", "profile_url": "https://stats.stackexchange.com/users/164061/sextus-empiricus", "user_type": "registered"}, "created_at": "2026-09-13T11:23:05+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "4D4882E8-A3E7-4B18-A2A1-EBCD304BD135", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4D4882E8-A3E7-4B18-A2A1-EBCD304BD135/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7A0D168D-47D2-4CC6-B1EA-213CEB836C84", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/7A0D168D-47D2-4CC6-B1EA-213CEB836C84/view-source"}], "score": 0, "updated_at": "2026-09-13T11:23:05+00:00"}], "domain": "statistics", "external_links": ["https://en.wikipedia.org/wiki/Independence_(probability_theory"], "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": "chausies", "question_author_url": "https://stats.stackexchange.com/users/106978/chausies", "question_author_user_type": "registered", "question_created_at": "2026-09-09T07:51:56+00:00", "question_html": "

I'm trying to come up with relatable examples to teach the concept of independence/orthogonality of two random variables $A$ and $B$. But my Bayes-Net-rotted brain keeps coming up with scenarios of how the two quantities/RVs could possibly not be independent (usually because of a common factor $C$).

\n

Some ANTI-examples of independence:

\n
    \n
  • Bob being $A$ (able to jump high) and Bob being $B$ (good at chess).\n
      \n
    • if Bob had $C$ (a good childhood with a happy family), then he is more likely to be $A$ and $B$.
    • \n
    \n
  • \n
  • $A$: Bob liking cats, $B$: Enrique eating a hotdog on Saturday 9/5/2026.\n
      \n
    • $C$: these are both dependent on the human race existing 4 billion years after the Earth's formation
    • \n
    \n
  • \n
\n

I intuitively understand independence. But I'm trying to come up with a more full-proof method to explain it. Note that the explanation has to be RELATABLE. It's trivial to define mathematically.

\n

Also, note that I understand that this question may be more philosophical, and less hard stats. I'm just trying to figure out effective analogies to teach the concept of independence/orthogonality.

\n", "question_id": 677110, "question_license": "CC BY-SA 4.0", "question_score": 7, "question_text": "I'm trying to come up with relatable examples to teach the concept of independence/orthogonality of two random variables $A$ and $B$. But my Bayes-Net-rotted brain keeps coming up with scenarios of how the two quantities/RVs could possibly not be independent (usually because of a common factor $C$).\n\n\n\n\nSome ANTI-examples of independence:\n\n\n\n\n\nBob being $A$ (able to jump high) and Bob being $B$ (good at chess).\n\n\n\nif Bob had $C$ (a good childhood with a happy family), then he is more likely to be $A$ and $B$.\n\n\n\n\n\n\n\n\n$A$: Bob liking cats, $B$: Enrique eating a hotdog on Saturday 9/5/2026.\n\n\n\n$C$: these are both dependent on the human race existing 4 billion years after the Earth's formation\n\n\n\n\n\n\n\n\n\nI intuitively understand independence. But I'm trying to come up with a more full-proof method to explain it. Note that the explanation has to be RELATABLE. It's trivial to define mathematically.\n\n\n\n\nAlso, note that I understand that this question may be more philosophical, and less hard stats. I'm just trying to figure out effective analogies to teach the concept of independence/orthogonality.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "chausies", "profile_url": "https://stats.stackexchange.com/users/106978/chausies", "user_type": "registered"}, "created_at": "2026-09-09T07:51:56+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "09AA6116-10EF-4598-A356-673887E08F9F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/09AA6116-10EF-4598-A356-673887E08F9F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "chausies", "profile_url": "https://stats.stackexchange.com/users/106978/chausies", "user_type": "registered"}, "created_at": "2026-09-09T08:09:28+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "E02B00BA-7EB4-4006-B7DC-05AEBD786FB2", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E02B00BA-7EB4-4006-B7DC-05AEBD786FB2/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-09T08:38:48+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "A0CC35A7-3551-4E23-987C-D3D75825B0C6", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A0CC35A7-3551-4E23-987C-D3D75825B0C6/view-source"}, {"content_license": null, "contributor": {"display_name": "kjetil b halvorsen", "profile_url": "https://stats.stackexchange.com/users/11887/kjetil-b-halvorsen", "user_type": "moderator"}, "created_at": "2026-09-09T15:45:42+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "AE89F7AC-F6FF-4169-8238-81C4A28C9D51", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AE89F7AC-F6FF-4169-8238-81C4A28C9D51/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-09T16:02:18+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "328469B4-8DBA-4605-9657-CC3EEC90198E", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/328469B4-8DBA-4605-9657-CC3EEC90198E/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-24T15:47:50+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "F2BFAA50-7963-4160-AF0B-9FD8DF0FD5A4", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/F2BFAA50-7963-4160-AF0B-9FD8DF0FD5A4/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677110/what-are-some-examples-of-truly-independent-things-that-are-relatable-to-people", "split": "train", "split_group": "37c3b7a374d2a52326d18ea26b83cb670f304c3b4ba0a500893af03f7b915087", "tags": ["independence", "intuition", "bayesian-network", "teaching"], "thread_id": "stats:677110", "title": "What are some examples of truly independent things that are relatable to people?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I have been working on analysing ecological data for different countries (within each country there are two groups (grazed/ungrazed) and plots (5 per group) which contain subplots (pseudoreplicates)\n\n\n\n\nMy sample size: 9 countries with each 2 groups of 5 plots with 4 subplots, so 20 measurepoints per group, 40 measure points per country\n\n\n\n\nI want to know what the effect of grazers are for each measurement at each study site (country). And have decided to go for a mixed model, since I have pseudoreplicates to account for.\n\n\n\n\nI started with a Linear Mixed Model, but the residuals were not normally distributed. I have now log transformed my data.\n\n\n\n\nlibrary(lme4)\n\nmodel <- lmer(log(sd_depth) ~ Grazing * Country + (1|PlotID), data = sd_data)\n\n\n\n\n\nI made a qqnorm plot for the residuals and it looked a lot better, but the shapiro.test gave a p-value of 0.01.\n\n\n\n\nsd_depth = standard deviation values (I calculated soil depth for 50 steps, each step a separate measurement, and calculated the standard deviation per subplot of these measurements).\n\n\n\n\nMy question is:\n\n\n\n\n\nIs that p-value enough to fit the Linear mixed model anyway?\n\n\n\n\nDo I need to use another model, for example GLMM? Which distribution do I need to choose then? And do I need to check for any other assumptions if I go for GLMM (or any other mixed effect model?)\n\n\n\n\nWhat are the considerations for choosing families for distribution models (because I have other data that I need to analyse in a similar way), tips for websites/articles that explain this in a clear way are welcome too!", "record_id": "Scientific-Statistics-QA:stats:677129", "selected_answer": {"answer_html": "

Putting together the comments:

\n
\n

Is that p-value enough to fit the Linear mixed model anyway?

\n
\n

Don't rely on such p-values for making decisions about the model to use. As @mastropi notes, with large data sets it's possible to get "statistically significant" deviations from the hypothesized distribution that don't matter in practice. With small data sets, you typically don't have the power to find substantial deviations that pass the "statistical significance" criterion. See this page.

\n

Furthermore, there's a strong argument that the whole process of checking distributions of errors from a model and then changing the model is inappropriate if you want to do inference based on the results. The p-values you get from a model rely on the assumption that you didn't use the outcomes to choose the model. That two-step process necessarily uses the outcomes.

\n
\n

Do I need to use another model, for example GLMM? ...

\n
\n

Standard linear regression assumes a single normal distribution of errors around model predictions. If the nature of your outcome variable suggests that isn't a reasonable assumption, a generalized linear model is more appropriate.

\n

If your outcome is a standard deviation (your choice of the outcome of variability measure) or variance (as @Roland suggests), the values are necessarily non-negative. If you are sampling from normal distributions, variance estimates have chi-square distributions, while the standard deviation estimates have chi distributions. Chi-square distributions may approach normal distributions, but your number of samples per (sub)plot might not be adequate for a normal approximation to the distribution of variance estimates. Furthermore, your measurements of soil depth might not have normally distributed errors.

\n
\n

Which distribution do I need to choose then? ... What are the considerations for choosing families for distribution models...?

\n
\n

The type of outcome variable helps determine the choice. What's critical is the nature of the random variability around the mean values the model predicts from the covariates. This answer succinctly summarizes major possibilities.

\n

As a variance or standard deviation is continuous and non-negative, the gamma family would be one standard choice. The choice of family has to be accompanied by a choice of link function; a log link* is often used with a gamma model. The gamma family is directly relevant in your case, as the chi-square distribution is a special case of the gamma family.

\n
\n

And do I need to check for any other assumptions if I go for GLMM (or any other mixed effect model?)

\n
\n

Checking model fit for generalized linear mixed models isn't as simple as for standard linear regression. As @RickHass noted, the R DHARMa package provides useful tools for that, based on simulations from the model and the observed data.

\n
\n

*There's an important difference between using a log link in a GL(M)M and the log transformation of outcomes that you used. That GLM models the log of the mean outcome value as a function of covariates. A log transformation followed by linear regression models the mean of the log of the outcome values. If you know that your variance values come from samples of normal distributions, you could use a Gamma family with the identity link.

\n", "answer_id": 677144, "answer_text": "Putting together the comments:\n\n\n\n\n\n\n\nIs that p-value enough to fit the Linear mixed model anyway?\n\n\n\n\n\n\n\nDon't rely on such p-values for making decisions about the model to use. As @mastropi notes, with large data sets it's possible to get \"statistically significant\" deviations from the hypothesized distribution that don't matter in practice. With small data sets, you typically don't have the power to find substantial deviations that pass the \"statistical significance\" criterion. See this page (https://stats.stackexchange.com/q/2492/28500).\n\n\n\n\nFurthermore, there's a strong argument that the whole process of checking distributions of errors from a model and then changing the model is inappropriate if you want to do inference based on the results. The p-values you get from a model rely on the assumption that you didn't use the outcomes to choose the model. That two-step process necessarily uses the outcomes.\n\n\n\n\n\n\n\nDo I need to use another model, for example GLMM? ...\n\n\n\n\n\n\n\nStandard linear regression assumes a single normal distribution of errors around model predictions. If the nature of your outcome variable suggests that isn't a reasonable assumption, a generalized linear model is more appropriate.\n\n\n\n\nIf your outcome is a standard deviation (your choice of the outcome of variability measure) or variance (as @Roland suggests), the values are necessarily non-negative. If you are sampling from normal distributions, variance estimates have chi-square distributions (https://en.wikipedia.org/wiki/Chi-squared_distribution#Occurrence_and_applications), while the standard deviation estimates have chi distributions (https://en.wikipedia.org/wiki/Chi_distribution#). Chi-square distributions may approach normal distributions, but your number of samples per (sub)plot might not be adequate for a normal approximation (https://en.wikipedia.org/wiki/Chi-squared_distribution#Asymptotic_properties) to the distribution of variance estimates. Furthermore, your measurements of soil depth might not have normally distributed errors.\n\n\n\n\n\n\n\nWhich distribution do I need to choose then? ... What are the considerations for choosing families for distribution models...?\n\n\n\n\n\n\n\nThe type of outcome variable helps determine the choice. What's critical is the nature of the random variability around the mean values the model predicts from the covariates. This answer (https://stats.stackexchange.com/a/303592/28500) succinctly summarizes major possibilities.\n\n\n\n\nAs a variance or standard deviation is continuous and non-negative, the gamma family would be one standard choice. The choice of family has to be accompanied by a choice of link function; a log link* is often used with a gamma model. The gamma family is directly relevant in your case, as the chi-square distribution is a special case of the gamma family (https://en.wikipedia.org/wiki/Gamma_distribution#General).\n\n\n\n\n\n\n\nAnd do I need to check for any other assumptions if I go for GLMM (or any other mixed effect model?)\n\n\n\n\n\n\n\nChecking model fit for generalized linear mixed models isn't as simple as for standard linear regression. As @RickHass noted, the R DHARMa package (https://cran.r-project.org/package=DHARMa) provides useful tools for that, based on simulations from the model and the observed data.\n\n\n\n\n\n\n\n*There's an important difference between using a log link in a GL(M)M and the log transformation of outcomes that you used. That GLM models the log of the mean outcome value as a function of covariates. A log transformation followed by linear regression models the mean of the log of the outcome values. If you know that your variance values come from samples of normal distributions, you could use a Gamma family with the identity link.", "answer_url": "https://stats.stackexchange.com/a/677144", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-11T15:41:29+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677129, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-11T15:41:29+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "75DAD87A-C4FD-4864-A9E0-3DDADD861A78", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/75DAD87A-C4FD-4864-A9E0-3DDADD861A78/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-11T16:40:36+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "9AD56685-4998-4F06-A9D3-E7CA7A2C653C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9AD56685-4998-4F06-A9D3-E7CA7A2C653C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-11T17:27:30+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "1778ADB3-A83B-49CF-BDE1-AD32AC57C294", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1778ADB3-A83B-49CF-BDE1-AD32AC57C294/view-source"}], "score": 2, "updated_at": "2026-09-11T17:27:30+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Putting together the comments:

\n
\n

Is that p-value enough to fit the Linear mixed model anyway?

\n
\n

Don't rely on such p-values for making decisions about the model to use. As @mastropi notes, with large data sets it's possible to get "statistically significant" deviations from the hypothesized distribution that don't matter in practice. With small data sets, you typically don't have the power to find substantial deviations that pass the "statistical significance" criterion. See this page.

\n

Furthermore, there's a strong argument that the whole process of checking distributions of errors from a model and then changing the model is inappropriate if you want to do inference based on the results. The p-values you get from a model rely on the assumption that you didn't use the outcomes to choose the model. That two-step process necessarily uses the outcomes.

\n
\n

Do I need to use another model, for example GLMM? ...

\n
\n

Standard linear regression assumes a single normal distribution of errors around model predictions. If the nature of your outcome variable suggests that isn't a reasonable assumption, a generalized linear model is more appropriate.

\n

If your outcome is a standard deviation (your choice of the outcome of variability measure) or variance (as @Roland suggests), the values are necessarily non-negative. If you are sampling from normal distributions, variance estimates have chi-square distributions, while the standard deviation estimates have chi distributions. Chi-square distributions may approach normal distributions, but your number of samples per (sub)plot might not be adequate for a normal approximation to the distribution of variance estimates. Furthermore, your measurements of soil depth might not have normally distributed errors.

\n
\n

Which distribution do I need to choose then? ... What are the considerations for choosing families for distribution models...?

\n
\n

The type of outcome variable helps determine the choice. What's critical is the nature of the random variability around the mean values the model predicts from the covariates. This answer succinctly summarizes major possibilities.

\n

As a variance or standard deviation is continuous and non-negative, the gamma family would be one standard choice. The choice of family has to be accompanied by a choice of link function; a log link* is often used with a gamma model. The gamma family is directly relevant in your case, as the chi-square distribution is a special case of the gamma family.

\n
\n

And do I need to check for any other assumptions if I go for GLMM (or any other mixed effect model?)

\n
\n

Checking model fit for generalized linear mixed models isn't as simple as for standard linear regression. As @RickHass noted, the R DHARMa package provides useful tools for that, based on simulations from the model and the observed data.

\n
\n

*There's an important difference between using a log link in a GL(M)M and the log transformation of outcomes that you used. That GLM models the log of the mean outcome value as a function of covariates. A log transformation followed by linear regression models the mean of the log of the outcome values. If you know that your variance values come from samples of normal distributions, you could use a Gamma family with the identity link.

\n", "answer_id": 677144, "answer_text": "Putting together the comments:\n\n\n\n\n\n\n\nIs that p-value enough to fit the Linear mixed model anyway?\n\n\n\n\n\n\n\nDon't rely on such p-values for making decisions about the model to use. As @mastropi notes, with large data sets it's possible to get \"statistically significant\" deviations from the hypothesized distribution that don't matter in practice. With small data sets, you typically don't have the power to find substantial deviations that pass the \"statistical significance\" criterion. See this page (https://stats.stackexchange.com/q/2492/28500).\n\n\n\n\nFurthermore, there's a strong argument that the whole process of checking distributions of errors from a model and then changing the model is inappropriate if you want to do inference based on the results. The p-values you get from a model rely on the assumption that you didn't use the outcomes to choose the model. That two-step process necessarily uses the outcomes.\n\n\n\n\n\n\n\nDo I need to use another model, for example GLMM? ...\n\n\n\n\n\n\n\nStandard linear regression assumes a single normal distribution of errors around model predictions. If the nature of your outcome variable suggests that isn't a reasonable assumption, a generalized linear model is more appropriate.\n\n\n\n\nIf your outcome is a standard deviation (your choice of the outcome of variability measure) or variance (as @Roland suggests), the values are necessarily non-negative. If you are sampling from normal distributions, variance estimates have chi-square distributions (https://en.wikipedia.org/wiki/Chi-squared_distribution#Occurrence_and_applications), while the standard deviation estimates have chi distributions (https://en.wikipedia.org/wiki/Chi_distribution#). Chi-square distributions may approach normal distributions, but your number of samples per (sub)plot might not be adequate for a normal approximation (https://en.wikipedia.org/wiki/Chi-squared_distribution#Asymptotic_properties) to the distribution of variance estimates. Furthermore, your measurements of soil depth might not have normally distributed errors.\n\n\n\n\n\n\n\nWhich distribution do I need to choose then? ... What are the considerations for choosing families for distribution models...?\n\n\n\n\n\n\n\nThe type of outcome variable helps determine the choice. What's critical is the nature of the random variability around the mean values the model predicts from the covariates. This answer (https://stats.stackexchange.com/a/303592/28500) succinctly summarizes major possibilities.\n\n\n\n\nAs a variance or standard deviation is continuous and non-negative, the gamma family would be one standard choice. The choice of family has to be accompanied by a choice of link function; a log link* is often used with a gamma model. The gamma family is directly relevant in your case, as the chi-square distribution is a special case of the gamma family (https://en.wikipedia.org/wiki/Gamma_distribution#General).\n\n\n\n\n\n\n\nAnd do I need to check for any other assumptions if I go for GLMM (or any other mixed effect model?)\n\n\n\n\n\n\n\nChecking model fit for generalized linear mixed models isn't as simple as for standard linear regression. As @RickHass noted, the R DHARMa package (https://cran.r-project.org/package=DHARMa) provides useful tools for that, based on simulations from the model and the observed data.\n\n\n\n\n\n\n\n*There's an important difference between using a log link in a GL(M)M and the log transformation of outcomes that you used. That GLM models the log of the mean outcome value as a function of covariates. A log transformation followed by linear regression models the mean of the log of the outcome values. If you know that your variance values come from samples of normal distributions, you could use a Gamma family with the identity link.", "answer_url": "https://stats.stackexchange.com/a/677144", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-11T15:41:29+00:00", "is_accepted": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:06.169765+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/9155f81b0f1dac4b0f83fad58469033af46ad34ee8d731e569d063b41b3df6b6_1790825226563497500_0.json", "raw_sha256": "cbac4b1b24e2159f1c17ea9902eaf89a0a5260344e6dba6f75790ba955f0d04b", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/questions/677298;677295;677280;677279;677278;677275;677269;677266;677262;677256;677245;677243;677242;677226;677225;677217;677211;677201;677194;677193;677186;677183;677179;677177;677171;677169;677168;677151;677149;677147;677137;677135;677131;677129;677115;677110;677109;677101;677099;677098;677096;677095;677094;677085;677083;677079;677078;677075;677071;677066;677065;677062;677058;677045;677041;677035;677033;677023;677021;676999;676997;676991;676982;676981;676979;676977;676975;676971;676966;676961;676958;676956;676952;676947;676945;676937;676935;676933;676924;676922;676899;676898;676893;676889;676888;676879;676874;676873;676870;676867;676865;676858;676855;676850;676842;676832;676830;676824;676823;676821/answers?filter=withbody&order=asc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_id": 677129, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-11T15:41:29+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "75DAD87A-C4FD-4864-A9E0-3DDADD861A78", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/75DAD87A-C4FD-4864-A9E0-3DDADD861A78/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-11T16:40:36+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "9AD56685-4998-4F06-A9D3-E7CA7A2C653C", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9AD56685-4998-4F06-A9D3-E7CA7A2C653C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-11T17:27:30+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "1778ADB3-A83B-49CF-BDE1-AD32AC57C294", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1778ADB3-A83B-49CF-BDE1-AD32AC57C294/view-source"}], "score": 2, "updated_at": "2026-09-11T17:27:30+00:00"}], "domain": "statistics", "external_links": ["https://cran.r-project.org/package=DHARMa", "https://en.wikipedia.org/wiki/Chi-squared_distribution#Asymptotic_properties", "https://en.wikipedia.org/wiki/Chi-squared_distribution#Occurrence_and_applications", "https://en.wikipedia.org/wiki/Chi_distribution#", "https://en.wikipedia.org/wiki/Gamma_distribution#General"], "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": "S.E123", "question_author_url": "https://stats.stackexchange.com/users/516500/s-e123", "question_author_user_type": "unregistered", "question_created_at": "2026-09-10T14:34:54+00:00", "question_html": "

I have been working on analysing ecological data for different countries (within each country there are two groups (grazed/ungrazed) and plots (5 per group) which contain subplots (pseudoreplicates)

\n

My sample size: 9 countries with each 2 groups of 5 plots with 4 subplots, so 20 measurepoints per group, 40 measure points per country

\n

I want to know what the effect of grazers are for each measurement at each study site (country). And have decided to go for a mixed model, since I have pseudoreplicates to account for.

\n

I started with a Linear Mixed Model, but the residuals were not normally distributed. I have now log transformed my data.

\n
library(lme4)\n\nmodel <- lmer(log(sd_depth) ~ Grazing * Country + (1|PlotID), data = sd_data)\n
\n

I made a qqnorm plot for the residuals and it looked a lot better, but the shapiro.test gave a p-value of 0.01.

\n

sd_depth = standard deviation values (I calculated soil depth for 50 steps, each step a separate measurement, and calculated the standard deviation per subplot of these measurements).

\n

My question is:

\n
    \n
  • Is that p-value enough to fit the Linear mixed model anyway?
  • \n
  • Do I need to use another model, for example GLMM? Which distribution do I need to choose then? And do I need to check for any other assumptions if I go for GLMM (or any other mixed effect model?)
  • \n
  • What are the considerations for choosing families for distribution models (because I have other data that I need to analyse in a similar way), tips for websites/articles that explain this in a clear way are welcome too!
  • \n
\n", "question_id": 677129, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I have been working on analysing ecological data for different countries (within each country there are two groups (grazed/ungrazed) and plots (5 per group) which contain subplots (pseudoreplicates)\n\n\n\n\nMy sample size: 9 countries with each 2 groups of 5 plots with 4 subplots, so 20 measurepoints per group, 40 measure points per country\n\n\n\n\nI want to know what the effect of grazers are for each measurement at each study site (country). And have decided to go for a mixed model, since I have pseudoreplicates to account for.\n\n\n\n\nI started with a Linear Mixed Model, but the residuals were not normally distributed. I have now log transformed my data.\n\n\n\n\nlibrary(lme4)\n\nmodel <- lmer(log(sd_depth) ~ Grazing * Country + (1|PlotID), data = sd_data)\n\n\n\n\n\nI made a qqnorm plot for the residuals and it looked a lot better, but the shapiro.test gave a p-value of 0.01.\n\n\n\n\nsd_depth = standard deviation values (I calculated soil depth for 50 steps, each step a separate measurement, and calculated the standard deviation per subplot of these measurements).\n\n\n\n\nMy question is:\n\n\n\n\n\nIs that p-value enough to fit the Linear mixed model anyway?\n\n\n\n\nDo I need to use another model, for example GLMM? Which distribution do I need to choose then? And do I need to check for any other assumptions if I go for GLMM (or any other mixed effect model?)\n\n\n\n\nWhat are the considerations for choosing families for distribution models (because I have other data that I need to analyse in a similar way), tips for websites/articles that explain this in a clear way are welcome too!", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "S.E123", "profile_url": "https://stats.stackexchange.com/users/516500/s-e123", "user_type": "unregistered"}, "created_at": "2026-09-10T14:34:54+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "AD2A8DA1-35FC-47A5-B20F-CDC46814BB95", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD2A8DA1-35FC-47A5-B20F-CDC46814BB95/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-10T14:41:52+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "3DBFEC7D-6B1F-498E-BEBC-2E910A21DF1B", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3DBFEC7D-6B1F-498E-BEBC-2E910A21DF1B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "S.E123", "profile_url": "https://stats.stackexchange.com/users/516500/s-e123", "user_type": "unregistered"}, "created_at": "2026-09-10T19:07:55+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "6114B485-886C-4FB2-BEE4-C0C7D67B910F", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6114B485-886C-4FB2-BEE4-C0C7D67B910F/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677129/what-mixed-model-do-i-need-to-use-for-my-analysis", "split": "train", "split_group": "c239fef82622c878feb643f00f90ab07897553875dab56b9869f72eb7fee842f", "tags": ["r", "mixed-model", "glmm", "assumptions"], "thread_id": "stats:677129", "title": "What Mixed Model do I need to use for my analysis?"}} +{"accepted_answer": {"answer_html": "

You are using R version 4.6.1. Well, since R 4.6.0, from R News:

\n
\n

wilcox.test() can now perform exact (conditional) inference in case\nof ties. Based on contributions by Torsten Hothorn.

\n
\n

Therefore, it seems there's no longer a reason to throw a warning. The wilcox.test() documentation says:

\n
\n

If there are ties, exact inference is performed using the\nconditional/permutation distribution given the observed ranks, using\nan implementation of the Streitberg–Röhmel shift algorithm (Streitberg\nand Röhmel 1986; Streitberg and Röhmel 1987) contributed by Torsten\nHothorn.

\n
\n

[...]

\n
\n

Streitberg B, Röhmel J (1986). “Exact Distributions for Permutation\nand Rank Tests: An Introduction to Some Recently Published\nAlgorithms.” Statistical Software Newsletter, 12(1), 10–17. ISSN\n0173-5896.

\n

Streitberg B, Röhmel J (1987). “Exakte Verteilungen für Rang- und\nRandomisierungstests im allgemeinen c-Stichprobenfall.” EDV in Medizin\nund Biologie, 18(1), 12–19. ISSN 0300-8282.\nhttps://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/.

\n
\n", "answer_id": 677139, "answer_text": "You are using R version 4.6.1. Well, since R 4.6.0, from R News (https://cran.r-project.org/doc/manuals/r-release/NEWS.html):\n\n\n\n\n\n\n\nwilcox.test() can now perform exact (conditional) inference in case\nof ties. Based on contributions by Torsten Hothorn.\n\n\n\n\n\n\n\nTherefore, it seems there's no longer a reason to throw a warning. The wilcox.test() documentation says:\n\n\n\n\n\n\n\nIf there are ties, exact inference is performed using the\nconditional/permutation distribution given the observed ranks, using\nan implementation of the Streitberg–Röhmel shift algorithm (Streitberg\nand Röhmel 1986; Streitberg and Röhmel 1987) contributed by Torsten\nHothorn.\n\n\n\n\n\n\n\n[...]\n\n\n\n\n\n\n\nStreitberg B, Röhmel J (1986). “Exact Distributions for Permutation\nand Rank Tests: An Introduction to Some Recently Published\nAlgorithms.” Statistical Software Newsletter, 12(1), 10–17. ISSN\n0173-5896.\n\n\n\n\nStreitberg B, Röhmel J (1987). “Exakte Verteilungen für Rang- und\nRandomisierungstests im allgemeinen c-Stichprobenfall.” EDV in Medizin\nund Biologie, 18(1), 12–19. ISSN 0300-8282.\nhttps://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/ (https://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/).", "answer_url": "https://stats.stackexchange.com/a/677139", "author": "J-J-J", "author_url": "https://stats.stackexchange.com/users/164936/j-j-j", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-11T07:32:22+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": 677135, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J-J-J", "profile_url": "https://stats.stackexchange.com/users/164936/j-j-j", "user_type": "registered"}, "created_at": "2026-09-11T07:32:22+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "23216BD3-49D3-422F-8020-02B7D9CD2B5A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/23216BD3-49D3-422F-8020-02B7D9CD2B5A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J-J-J", "profile_url": "https://stats.stackexchange.com/users/164936/j-j-j", "user_type": "registered"}, "created_at": "2026-09-11T08:09:51+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "CB4779A0-4EA1-4BB0-99F8-7FFB266F646D", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB4779A0-4EA1-4BB0-99F8-7FFB266F646D/view-source"}], "score": 16, "updated_at": "2026-09-11T08:09:51+00:00"}, "other_answers": [{"answer_html": "

Can you provide a {reprex}? I'm getting a warning when I run your code

\n
df <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n                                  26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n                                                                 30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c("tbl_df", \n                                                                                                                          "tbl", "data.frame"))\n\nwilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE)\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact p-value with ties\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact confidence interval with ties\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact p-value with zeroes\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact confidence interval with zeroes\n#> \n#>  Wilcoxon signed rank test with continuity correction\n#> \n#> data:  df$PostScore and df$PreScore\n#> V = 77, p-value = 0.00324\n#> alternative hypothesis: true location shift is not equal to 0\n#> 95 percent confidence interval:\n#>  4.500064 9.499992\n#> sample estimates:\n#> (pseudo)median \n#>       7.000049\n
\n

Created on 2026-09-10 with reprex v2.1.1

\n

EDIT: I was using an old version of R. Here is the reprex from using 4.6

\n
(R.version.string)\n#> [1] "R version 4.6.0 (2026-04-24)"\n\ndf <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n                                  26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n                                                                 30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c("tbl_df", \n                                                                                                                          "tbl", "data.frame"))\n\nwilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE)\n#> \n#>  Wilcoxon signed rank exact test\n#> \n#> data:  df$PostScore and df$PreScore\n#> V = 88, p-value = 0.0009766\n#> alternative hypothesis: true location shift is not equal to 0\n#> 96.7 percent confidence interval:\n#>  4 9\n#> sample estimates:\n#> (pseudo)median \n#>            6.5\n
\n

Created on 2026-09-11 with reprex v2.1.1

\n

Note, no warning. See J-J-J's comment for an explanation.

\n", "answer_id": 677136, "answer_text": "Can you provide a {reprex} (https://reprex.tidyverse.org/)? I'm getting a warning when I run your code\n\n\n\n\ndf <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n 26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n 30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c(\"tbl_df\", \n \"tbl\", \"data.frame\"))\n\nwilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE)\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact p-value with ties\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact confidence interval with ties\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact p-value with zeroes\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact confidence interval with zeroes\n#> \n#> Wilcoxon signed rank test with continuity correction\n#> \n#> data: df$PostScore and df$PreScore\n#> V = 77, p-value = 0.00324\n#> alternative hypothesis: true location shift is not equal to 0\n#> 95 percent confidence interval:\n#> 4.500064 9.499992\n#> sample estimates:\n#> (pseudo)median \n#> 7.000049\n\n\n\n\n\nCreated on 2026-09-10 with reprex v2.1.1 (https://reprex.tidyverse.org)\n\n\n\n\nEDIT: I was using an old version of R. Here is the reprex from using 4.6\n\n\n\n\n(R.version.string)\n#> [1] \"R version 4.6.0 (2026-04-24)\"\n\ndf <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n 26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n 30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c(\"tbl_df\", \n \"tbl\", \"data.frame\"))\n\nwilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE)\n#> \n#> Wilcoxon signed rank exact test\n#> \n#> data: df$PostScore and df$PreScore\n#> V = 88, p-value = 0.0009766\n#> alternative hypothesis: true location shift is not equal to 0\n#> 96.7 percent confidence interval:\n#> 4 9\n#> sample estimates:\n#> (pseudo)median \n#> 6.5\n\n\n\n\n\nCreated on 2026-09-11 with reprex v2.1.1 (https://reprex.tidyverse.org)\n\n\n\n\nNote, no warning. See J-J-J's comment for an explanation.", "answer_url": "https://stats.stackexchange.com/a/677136", "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-11T01:34:59+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": 677135, "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-11T01:34:59+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "3461E410-C604-4E94-BBD3-042259374DDF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3461E410-C604-4E94-BBD3-042259374DDF/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-11T17:41:38+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "C692081B-A074-4F0B-985E-9AECEBE88DE5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C692081B-A074-4F0B-985E-9AECEBE88DE5/view-source"}], "score": 5, "updated_at": "2026-09-11T17:41:38+00:00"}, {"answer_html": "

This arguably should at most be a comment as it doesn't attempt to answer the question at all. But I have a graph, and my comment also pertains to many applications of such tests that are likely not very helpful in data analysis. I am presuming that the data are serious from somewhere. If that isn't so, then this reply loses some of its force.

\n

Here is a scatter plot of Post versus Pre. Ties on Pre or Post are naturally shown by vertical or horizontal alignment; ties on both are shown by text 2 rather than text 1 on the graph.

\n

\"enter

\n

Here we range from evident to speculative:

\n
    \n
  1. Integer scores, so ties are more likely than otherwise.

    \n
  2. \n
  3. Is there an upper limit of 32?

    \n
  4. \n
  5. The observations seem to fall into two groups, those whose Post score is quite good, and those whose Post score is about the same as their Pre.

    \n
  6. \n
\n

A Wilcoxon test can't pay direct attention to such details emerging from a very simple graphical analysis. Sure, 11/13 had higher Post, 1 the same, 1 lower. But does the test really help?

\n", "answer_id": 677141, "answer_text": "This arguably should at most be a comment as it doesn't attempt to answer the question at all. But I have a graph, and my comment also pertains to many applications of such tests that are likely not very helpful in data analysis. I am presuming that the data are serious from somewhere. If that isn't so, then this reply loses some of its force.\n\n\n\n\nHere is a scatter plot of Post versus Pre. Ties on Pre or Post are naturally shown by vertical or horizontal alignment; ties on both are shown by text 2 rather than text 1 on the graph.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/7o9W87he.png] (https://i.sstatic.net/7o9W87he.png)\n\n\n\n\nHere we range from evident to speculative:\n\n\n\n\n\n\n\nInteger scores, so ties are more likely than otherwise.\n\n\n\n\n\n\n\n\n\nIs there an upper limit of 32?\n\n\n\n\n\n\n\n\n\nThe observations seem to fall into two groups, those whose Post score is quite good, and those whose Post score is about the same as their Pre.\n\n\n\n\n\n\n\n\nA Wilcoxon test can't pay direct attention to such details emerging from a very simple graphical analysis. Sure, 11/13 had higher Post, 1 the same, 1 lower. But does the test really help?", "answer_url": "https://stats.stackexchange.com/a/677141", "author": "Nick Cox", "author_url": "https://stats.stackexchange.com/users/22047/nick-cox", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-11T08:47:46+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": 677135, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-11T08:47:46+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "F5E781A6-F63A-4F3B-897E-03303213674F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F5E781A6-F63A-4F3B-897E-03303213674F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-11T09:20:25+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "2F24FDA3-AB03-426F-84C2-A097A0D37730", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2F24FDA3-AB03-426F-84C2-A097A0D37730/view-source"}], "score": 7, "updated_at": "2026-09-11T09:20:25+00:00"}], "product": "statistics_qa", "question": "I ran wilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE) on the following data set:\n\n\n\n\ndf <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c(\"tbl_df\", \n\"tbl\", \"data.frame\"))\n\n\n\n\n\nAs there are ties in the data I would have expected wilcox.test() to produce a warning. Why is there no warning in this case?\n\n\n\n\nHere is the reprex. I have tested it in an online IDE and obtained the same result as in my environment. I still do not see why ties are not reported.\n\n\n\n\n\nprepost <- structure(\n list(\n PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, 26, 25, 23, 18),\n PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, 30, 32, 30, 31, 17)\n ),\n row.names = c(NA, -13L),\n class = c(\"tbl_df\", \"tbl\", \"data.frame\")\n)\n\nwilcox.test(\n prepost$PostScore,\n prepost$PreScore,\n conf.int = TRUE,\n paired = TRUE,\n exact = TRUE\n)\n#> \n#> Wilcoxon signed rank exact test\n#> \n#> data: prepost$PostScore and prepost$PreScore\n#> V = 88, p-value = 0.0009766\n#> alternative hypothesis: true location shift is not equal to 0\n#> 96.7 percent confidence interval:\n#> 4 9\n#> sample estimates:\n#> (pseudo)median \n#> 6.5\n\nsessionInfo()\n#> R version 4.6.1 (2026-06-24)\n#> Platform: x86_64-pc-linux-gnu\n#> Running under: Garuda Linux\n#> \n#> Matrix products: default\n#> BLAS: /usr/lib/libblas.so.3.12.0 \n#> LAPACK: /usr/lib/liblapack.so.3.12.0 LAPACK version 3.12.0\n#> \n#> locale:\n#> [1] LC_CTYPE=en_SG.UTF-8 LC_NUMERIC=C \n#> [3] LC_TIME=en_SG.UTF-8 LC_COLLATE=en_SG.UTF-8 \n#> [5] LC_MONETARY=en_SG.UTF-8 LC_MESSAGES=en_SG.UTF-8 \n#> [7] LC_PAPER=en_SG.UTF-8 LC_NAME=C \n#> [9] LC_ADDRESS=C LC_TELEPHONE=C \n#> [11] LC_MEASUREMENT=en_SG.UTF-8 LC_IDENTIFICATION=C \n#> \n#> time zone: Asia/Kuala_Lumpur\n#> tzcode source: system (glibc)\n#> \n#> attached base packages:\n#> [1] stats graphics grDevices utils datasets methods base \n#> \n#> loaded via a namespace (and not attached):\n#> [1] digest_0.6.39 fastmap_1.2.0 xfun_0.60 glue_1.8.1 \n#> [5] knitr_1.51 htmltools_0.5.9 rmarkdown_2.32 lifecycle_1.0.5 \n#> [9] cli_3.6.6 reprex_2.1.1 withr_3.0.2 compiler_4.6.1 \n#> [13] rstudioapi_0.19.0 tools_4.6.1 evaluate_1.0.5 yaml_2.3.12 \n#> [17] otel_0.2.0 rlang_1.2.0 fs_2.1.0\n```", "record_id": "Scientific-Statistics-QA:stats:677135", "selected_answer": {"answer_html": "

You are using R version 4.6.1. Well, since R 4.6.0, from R News:

\n
\n

wilcox.test() can now perform exact (conditional) inference in case\nof ties. Based on contributions by Torsten Hothorn.

\n
\n

Therefore, it seems there's no longer a reason to throw a warning. The wilcox.test() documentation says:

\n
\n

If there are ties, exact inference is performed using the\nconditional/permutation distribution given the observed ranks, using\nan implementation of the Streitberg–Röhmel shift algorithm (Streitberg\nand Röhmel 1986; Streitberg and Röhmel 1987) contributed by Torsten\nHothorn.

\n
\n

[...]

\n
\n

Streitberg B, Röhmel J (1986). “Exact Distributions for Permutation\nand Rank Tests: An Introduction to Some Recently Published\nAlgorithms.” Statistical Software Newsletter, 12(1), 10–17. ISSN\n0173-5896.

\n

Streitberg B, Röhmel J (1987). “Exakte Verteilungen für Rang- und\nRandomisierungstests im allgemeinen c-Stichprobenfall.” EDV in Medizin\nund Biologie, 18(1), 12–19. ISSN 0300-8282.\nhttps://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/.

\n
\n", "answer_id": 677139, "answer_text": "You are using R version 4.6.1. Well, since R 4.6.0, from R News (https://cran.r-project.org/doc/manuals/r-release/NEWS.html):\n\n\n\n\n\n\n\nwilcox.test() can now perform exact (conditional) inference in case\nof ties. Based on contributions by Torsten Hothorn.\n\n\n\n\n\n\n\nTherefore, it seems there's no longer a reason to throw a warning. The wilcox.test() documentation says:\n\n\n\n\n\n\n\nIf there are ties, exact inference is performed using the\nconditional/permutation distribution given the observed ranks, using\nan implementation of the Streitberg–Röhmel shift algorithm (Streitberg\nand Röhmel 1986; Streitberg and Röhmel 1987) contributed by Torsten\nHothorn.\n\n\n\n\n\n\n\n[...]\n\n\n\n\n\n\n\nStreitberg B, Röhmel J (1986). “Exact Distributions for Permutation\nand Rank Tests: An Introduction to Some Recently Published\nAlgorithms.” Statistical Software Newsletter, 12(1), 10–17. ISSN\n0173-5896.\n\n\n\n\nStreitberg B, Röhmel J (1987). “Exakte Verteilungen für Rang- und\nRandomisierungstests im allgemeinen c-Stichprobenfall.” EDV in Medizin\nund Biologie, 18(1), 12–19. ISSN 0300-8282.\nhttps://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/ (https://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/).", "answer_url": "https://stats.stackexchange.com/a/677139", "author": "J-J-J", "author_url": "https://stats.stackexchange.com/users/164936/j-j-j", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-11T07:32:22+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": 677135, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J-J-J", "profile_url": "https://stats.stackexchange.com/users/164936/j-j-j", "user_type": "registered"}, "created_at": "2026-09-11T07:32:22+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "23216BD3-49D3-422F-8020-02B7D9CD2B5A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/23216BD3-49D3-422F-8020-02B7D9CD2B5A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J-J-J", "profile_url": "https://stats.stackexchange.com/users/164936/j-j-j", "user_type": "registered"}, "created_at": "2026-09-11T08:09:51+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "CB4779A0-4EA1-4BB0-99F8-7FFB266F646D", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB4779A0-4EA1-4BB0-99F8-7FFB266F646D/view-source"}], "score": 16, "updated_at": "2026-09-11T08:09:51+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677139, "answers": [{"answer_html": "

Can you provide a {reprex}? I'm getting a warning when I run your code

\n
df <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n                                  26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n                                                                 30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c("tbl_df", \n                                                                                                                          "tbl", "data.frame"))\n\nwilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE)\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact p-value with ties\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact confidence interval with ties\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact p-value with zeroes\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact confidence interval with zeroes\n#> \n#>  Wilcoxon signed rank test with continuity correction\n#> \n#> data:  df$PostScore and df$PreScore\n#> V = 77, p-value = 0.00324\n#> alternative hypothesis: true location shift is not equal to 0\n#> 95 percent confidence interval:\n#>  4.500064 9.499992\n#> sample estimates:\n#> (pseudo)median \n#>       7.000049\n
\n

Created on 2026-09-10 with reprex v2.1.1

\n

EDIT: I was using an old version of R. Here is the reprex from using 4.6

\n
(R.version.string)\n#> [1] "R version 4.6.0 (2026-04-24)"\n\ndf <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n                                  26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n                                                                 30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c("tbl_df", \n                                                                                                                          "tbl", "data.frame"))\n\nwilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE)\n#> \n#>  Wilcoxon signed rank exact test\n#> \n#> data:  df$PostScore and df$PreScore\n#> V = 88, p-value = 0.0009766\n#> alternative hypothesis: true location shift is not equal to 0\n#> 96.7 percent confidence interval:\n#>  4 9\n#> sample estimates:\n#> (pseudo)median \n#>            6.5\n
\n

Created on 2026-09-11 with reprex v2.1.1

\n

Note, no warning. See J-J-J's comment for an explanation.

\n", "answer_id": 677136, "answer_text": "Can you provide a {reprex} (https://reprex.tidyverse.org/)? I'm getting a warning when I run your code\n\n\n\n\ndf <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n 26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n 30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c(\"tbl_df\", \n \"tbl\", \"data.frame\"))\n\nwilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE)\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact p-value with ties\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact confidence interval with ties\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact p-value with zeroes\n#> Warning in wilcox.test.default(df$PostScore, df$PreScore, conf.int = TRUE, :\n#> cannot compute exact confidence interval with zeroes\n#> \n#> Wilcoxon signed rank test with continuity correction\n#> \n#> data: df$PostScore and df$PreScore\n#> V = 77, p-value = 0.00324\n#> alternative hypothesis: true location shift is not equal to 0\n#> 95 percent confidence interval:\n#> 4.500064 9.499992\n#> sample estimates:\n#> (pseudo)median \n#> 7.000049\n\n\n\n\n\nCreated on 2026-09-10 with reprex v2.1.1 (https://reprex.tidyverse.org)\n\n\n\n\nEDIT: I was using an old version of R. Here is the reprex from using 4.6\n\n\n\n\n(R.version.string)\n#> [1] \"R version 4.6.0 (2026-04-24)\"\n\ndf <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n 26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n 30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c(\"tbl_df\", \n \"tbl\", \"data.frame\"))\n\nwilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE)\n#> \n#> Wilcoxon signed rank exact test\n#> \n#> data: df$PostScore and df$PreScore\n#> V = 88, p-value = 0.0009766\n#> alternative hypothesis: true location shift is not equal to 0\n#> 96.7 percent confidence interval:\n#> 4 9\n#> sample estimates:\n#> (pseudo)median \n#> 6.5\n\n\n\n\n\nCreated on 2026-09-11 with reprex v2.1.1 (https://reprex.tidyverse.org)\n\n\n\n\nNote, no warning. See J-J-J's comment for an explanation.", "answer_url": "https://stats.stackexchange.com/a/677136", "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-11T01:34:59+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": 677135, "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-11T01:34:59+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "3461E410-C604-4E94-BBD3-042259374DDF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3461E410-C604-4E94-BBD3-042259374DDF/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-11T17:41:38+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "C692081B-A074-4F0B-985E-9AECEBE88DE5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C692081B-A074-4F0B-985E-9AECEBE88DE5/view-source"}], "score": 5, "updated_at": "2026-09-11T17:41:38+00:00"}, {"answer_html": "

You are using R version 4.6.1. Well, since R 4.6.0, from R News:

\n
\n

wilcox.test() can now perform exact (conditional) inference in case\nof ties. Based on contributions by Torsten Hothorn.

\n
\n

Therefore, it seems there's no longer a reason to throw a warning. The wilcox.test() documentation says:

\n
\n

If there are ties, exact inference is performed using the\nconditional/permutation distribution given the observed ranks, using\nan implementation of the Streitberg–Röhmel shift algorithm (Streitberg\nand Röhmel 1986; Streitberg and Röhmel 1987) contributed by Torsten\nHothorn.

\n
\n

[...]

\n
\n

Streitberg B, Röhmel J (1986). “Exact Distributions for Permutation\nand Rank Tests: An Introduction to Some Recently Published\nAlgorithms.” Statistical Software Newsletter, 12(1), 10–17. ISSN\n0173-5896.

\n

Streitberg B, Röhmel J (1987). “Exakte Verteilungen für Rang- und\nRandomisierungstests im allgemeinen c-Stichprobenfall.” EDV in Medizin\nund Biologie, 18(1), 12–19. ISSN 0300-8282.\nhttps://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/.

\n
\n", "answer_id": 677139, "answer_text": "You are using R version 4.6.1. Well, since R 4.6.0, from R News (https://cran.r-project.org/doc/manuals/r-release/NEWS.html):\n\n\n\n\n\n\n\nwilcox.test() can now perform exact (conditional) inference in case\nof ties. Based on contributions by Torsten Hothorn.\n\n\n\n\n\n\n\nTherefore, it seems there's no longer a reason to throw a warning. The wilcox.test() documentation says:\n\n\n\n\n\n\n\nIf there are ties, exact inference is performed using the\nconditional/permutation distribution given the observed ranks, using\nan implementation of the Streitberg–Röhmel shift algorithm (Streitberg\nand Röhmel 1986; Streitberg and Röhmel 1987) contributed by Torsten\nHothorn.\n\n\n\n\n\n\n\n[...]\n\n\n\n\n\n\n\nStreitberg B, Röhmel J (1986). “Exact Distributions for Permutation\nand Rank Tests: An Introduction to Some Recently Published\nAlgorithms.” Statistical Software Newsletter, 12(1), 10–17. ISSN\n0173-5896.\n\n\n\n\nStreitberg B, Röhmel J (1987). “Exakte Verteilungen für Rang- und\nRandomisierungstests im allgemeinen c-Stichprobenfall.” EDV in Medizin\nund Biologie, 18(1), 12–19. ISSN 0300-8282.\nhttps://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/ (https://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/).", "answer_url": "https://stats.stackexchange.com/a/677139", "author": "J-J-J", "author_url": "https://stats.stackexchange.com/users/164936/j-j-j", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-11T07:32:22+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": 677135, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J-J-J", "profile_url": "https://stats.stackexchange.com/users/164936/j-j-j", "user_type": "registered"}, "created_at": "2026-09-11T07:32:22+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "23216BD3-49D3-422F-8020-02B7D9CD2B5A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/23216BD3-49D3-422F-8020-02B7D9CD2B5A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "J-J-J", "profile_url": "https://stats.stackexchange.com/users/164936/j-j-j", "user_type": "registered"}, "created_at": "2026-09-11T08:09:51+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "CB4779A0-4EA1-4BB0-99F8-7FFB266F646D", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB4779A0-4EA1-4BB0-99F8-7FFB266F646D/view-source"}], "score": 16, "updated_at": "2026-09-11T08:09:51+00:00"}, {"answer_html": "

This arguably should at most be a comment as it doesn't attempt to answer the question at all. But I have a graph, and my comment also pertains to many applications of such tests that are likely not very helpful in data analysis. I am presuming that the data are serious from somewhere. If that isn't so, then this reply loses some of its force.

\n

Here is a scatter plot of Post versus Pre. Ties on Pre or Post are naturally shown by vertical or horizontal alignment; ties on both are shown by text 2 rather than text 1 on the graph.

\n

\"enter

\n

Here we range from evident to speculative:

\n
    \n
  1. Integer scores, so ties are more likely than otherwise.

    \n
  2. \n
  3. Is there an upper limit of 32?

    \n
  4. \n
  5. The observations seem to fall into two groups, those whose Post score is quite good, and those whose Post score is about the same as their Pre.

    \n
  6. \n
\n

A Wilcoxon test can't pay direct attention to such details emerging from a very simple graphical analysis. Sure, 11/13 had higher Post, 1 the same, 1 lower. But does the test really help?

\n", "answer_id": 677141, "answer_text": "This arguably should at most be a comment as it doesn't attempt to answer the question at all. But I have a graph, and my comment also pertains to many applications of such tests that are likely not very helpful in data analysis. I am presuming that the data are serious from somewhere. If that isn't so, then this reply loses some of its force.\n\n\n\n\nHere is a scatter plot of Post versus Pre. Ties on Pre or Post are naturally shown by vertical or horizontal alignment; ties on both are shown by text 2 rather than text 1 on the graph.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/7o9W87he.png] (https://i.sstatic.net/7o9W87he.png)\n\n\n\n\nHere we range from evident to speculative:\n\n\n\n\n\n\n\nInteger scores, so ties are more likely than otherwise.\n\n\n\n\n\n\n\n\n\nIs there an upper limit of 32?\n\n\n\n\n\n\n\n\n\nThe observations seem to fall into two groups, those whose Post score is quite good, and those whose Post score is about the same as their Pre.\n\n\n\n\n\n\n\n\nA Wilcoxon test can't pay direct attention to such details emerging from a very simple graphical analysis. Sure, 11/13 had higher Post, 1 the same, 1 lower. But does the test really help?", "answer_url": "https://stats.stackexchange.com/a/677141", "author": "Nick Cox", "author_url": "https://stats.stackexchange.com/users/22047/nick-cox", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-11T08:47:46+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": 677135, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-11T08:47:46+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "F5E781A6-F63A-4F3B-897E-03303213674F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F5E781A6-F63A-4F3B-897E-03303213674F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-11T09:20:25+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "2F24FDA3-AB03-426F-84C2-A097A0D37730", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2F24FDA3-AB03-426F-84C2-A097A0D37730/view-source"}], "score": 7, "updated_at": "2026-09-11T09:20:25+00:00"}], "domain": "statistics", "external_links": ["https://cran.r-project.org/doc/manuals/r-release/NEWS.html", "https://i.sstatic.net/7o9W87he.png", "https://reprex.tidyverse.org", "https://reprex.tidyverse.org/", "https://ul.qucosa.de/api/qucosa%3A12624/attachment/ATT-0/"], "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": "DAVID PAUL CAPELLE", "question_author_url": "https://stats.stackexchange.com/users/386267/david-paul-capelle", "question_author_user_type": "registered", "question_created_at": "2026-09-11T01:14:02+00:00", "question_html": "

I ran wilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE) on the following data set:

\n
df <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c("tbl_df", \n"tbl", "data.frame"))\n
\n

As there are ties in the data I would have expected wilcox.test() to produce a warning. Why is there no warning in this case?

\n

Here is the reprex. I have tested it in an online IDE and obtained the same result as in my environment. I still do not see why ties are not reported.

\n
\nprepost <- structure(\n  list(\n    PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, 26, 25, 23, 18),\n    PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, 30, 32, 30, 31, 17)\n  ),\n  row.names = c(NA, -13L),\n  class = c("tbl_df", "tbl", "data.frame")\n)\n\nwilcox.test(\n  prepost$PostScore,\n  prepost$PreScore,\n  conf.int = TRUE,\n  paired = TRUE,\n  exact = TRUE\n)\n#> \n#>  Wilcoxon signed rank exact test\n#> \n#> data:  prepost$PostScore and prepost$PreScore\n#> V = 88, p-value = 0.0009766\n#> alternative hypothesis: true location shift is not equal to 0\n#> 96.7 percent confidence interval:\n#>  4 9\n#> sample estimates:\n#> (pseudo)median \n#>            6.5\n\nsessionInfo()\n#> R version 4.6.1 (2026-06-24)\n#> Platform: x86_64-pc-linux-gnu\n#> Running under: Garuda Linux\n#> \n#> Matrix products: default\n#> BLAS:   /usr/lib/libblas.so.3.12.0 \n#> LAPACK: /usr/lib/liblapack.so.3.12.0  LAPACK version 3.12.0\n#> \n#> locale:\n#>  [1] LC_CTYPE=en_SG.UTF-8       LC_NUMERIC=C              \n#>  [3] LC_TIME=en_SG.UTF-8        LC_COLLATE=en_SG.UTF-8    \n#>  [5] LC_MONETARY=en_SG.UTF-8    LC_MESSAGES=en_SG.UTF-8   \n#>  [7] LC_PAPER=en_SG.UTF-8       LC_NAME=C                 \n#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            \n#> [11] LC_MEASUREMENT=en_SG.UTF-8 LC_IDENTIFICATION=C       \n#> \n#> time zone: Asia/Kuala_Lumpur\n#> tzcode source: system (glibc)\n#> \n#> attached base packages:\n#> [1] stats     graphics  grDevices utils     datasets  methods   base     \n#> \n#> loaded via a namespace (and not attached):\n#>  [1] digest_0.6.39     fastmap_1.2.0     xfun_0.60         glue_1.8.1       \n#>  [5] knitr_1.51        htmltools_0.5.9   rmarkdown_2.32    lifecycle_1.0.5  \n#>  [9] cli_3.6.6         reprex_2.1.1      withr_3.0.2       compiler_4.6.1   \n#> [13] rstudioapi_0.19.0 tools_4.6.1       evaluate_1.0.5    yaml_2.3.12      \n#> [17] otel_0.2.0        rlang_1.2.0       fs_2.1.0\n```\n
\n", "question_id": 677135, "question_license": "CC BY-SA 4.0", "question_score": 10, "question_text": "I ran wilcox.test(df$PostScore, df$PreScore, conf.int = TRUE, paired=TRUE, exact = TRUE) on the following data set:\n\n\n\n\ndf <- structure(list(PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, \n26, 25, 23, 18), PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, \n30, 32, 30, 31, 17)), row.names = c(NA, -13L), class = c(\"tbl_df\", \n\"tbl\", \"data.frame\"))\n\n\n\n\n\nAs there are ties in the data I would have expected wilcox.test() to produce a warning. Why is there no warning in this case?\n\n\n\n\nHere is the reprex. I have tested it in an online IDE and obtained the same result as in my environment. I still do not see why ties are not reported.\n\n\n\n\n\nprepost <- structure(\n list(\n PreScore = c(16, 23, 17, 24, 22, 27, 20, 18, 21, 26, 25, 23, 18),\n PostScore = c(20, 31, 17, 31, 32, 31, 31, 30, 30, 32, 30, 31, 17)\n ),\n row.names = c(NA, -13L),\n class = c(\"tbl_df\", \"tbl\", \"data.frame\")\n)\n\nwilcox.test(\n prepost$PostScore,\n prepost$PreScore,\n conf.int = TRUE,\n paired = TRUE,\n exact = TRUE\n)\n#> \n#> Wilcoxon signed rank exact test\n#> \n#> data: prepost$PostScore and prepost$PreScore\n#> V = 88, p-value = 0.0009766\n#> alternative hypothesis: true location shift is not equal to 0\n#> 96.7 percent confidence interval:\n#> 4 9\n#> sample estimates:\n#> (pseudo)median \n#> 6.5\n\nsessionInfo()\n#> R version 4.6.1 (2026-06-24)\n#> Platform: x86_64-pc-linux-gnu\n#> Running under: Garuda Linux\n#> \n#> Matrix products: default\n#> BLAS: /usr/lib/libblas.so.3.12.0 \n#> LAPACK: /usr/lib/liblapack.so.3.12.0 LAPACK version 3.12.0\n#> \n#> locale:\n#> [1] LC_CTYPE=en_SG.UTF-8 LC_NUMERIC=C \n#> [3] LC_TIME=en_SG.UTF-8 LC_COLLATE=en_SG.UTF-8 \n#> [5] LC_MONETARY=en_SG.UTF-8 LC_MESSAGES=en_SG.UTF-8 \n#> [7] LC_PAPER=en_SG.UTF-8 LC_NAME=C \n#> [9] LC_ADDRESS=C LC_TELEPHONE=C \n#> [11] LC_MEASUREMENT=en_SG.UTF-8 LC_IDENTIFICATION=C \n#> \n#> time zone: Asia/Kuala_Lumpur\n#> tzcode source: system (glibc)\n#> \n#> attached base packages:\n#> [1] stats graphics grDevices utils datasets methods base \n#> \n#> loaded via a namespace (and not attached):\n#> [1] digest_0.6.39 fastmap_1.2.0 xfun_0.60 glue_1.8.1 \n#> [5] knitr_1.51 htmltools_0.5.9 rmarkdown_2.32 lifecycle_1.0.5 \n#> [9] cli_3.6.6 reprex_2.1.1 withr_3.0.2 compiler_4.6.1 \n#> [13] rstudioapi_0.19.0 tools_4.6.1 evaluate_1.0.5 yaml_2.3.12 \n#> [17] otel_0.2.0 rlang_1.2.0 fs_2.1.0\n```", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "DAVID PAUL CAPELLE", "profile_url": "https://stats.stackexchange.com/users/386267/david-paul-capelle", "user_type": "registered"}, "created_at": "2026-09-11T01:14:02+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "93652C25-9FE3-4C77-B0E9-CF7DD58DC50A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/93652C25-9FE3-4C77-B0E9-CF7DD58DC50A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "DAVID PAUL CAPELLE", "profile_url": "https://stats.stackexchange.com/users/386267/david-paul-capelle", "user_type": "registered"}, "created_at": "2026-09-11T06:13:00+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "C7E16D39-DC10-460F-B943-B7547B90F63D", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C7E16D39-DC10-460F-B943-B7547B90F63D/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-11T09:18:50+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "BC7129B7-4E28-49C0-8308-97D09DE31CA9", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/BC7129B7-4E28-49C0-8308-97D09DE31CA9/view-source"}, {"content_license": null, "contributor": {"display_name": "M--", "profile_url": "https://stats.stackexchange.com/users/154449/m", "user_type": "registered"}, "created_at": "2026-09-13T11:06:51+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "052E2710-AD21-4AFE-992F-D9FB54C17A14", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/052E2710-AD21-4AFE-992F-D9FB54C17A14/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677135/why-does-r-not-warn-about-ties-in-wilcox-test", "split": "train", "split_group": "fb4920dde6ede8f339350f0d34d985d9c1dcf8eb8ac2beea3857cb378c76b04b", "tags": ["r", "ties"], "thread_id": "stats:677135", "title": "Why does R not warn about ties in wilcox.test()"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

Amplifying @Glen_b's answer and @whuber's comment: here's the plot of the basis elements (for $-3 \\lt x \\lt 6$), with the ones that are non-zero at $x=1.5$ highlighted:

\n

\"plot

\n
library(splines)\nx_i <- 1.5\nx_all <- seq(-3, 6, length.out = 150)\nbasis_matrix <- splines::bs(x_all,\n                             knots = -2:5, \n                             Boundary.knots = c(-3, 6),\n                             degree = 3)\npos_el <- rep(c(1,2,1), c(3,4,3))\npar(las=1, bty = "l") ## cosmetic\nmatplot(x_all, basis_matrix, type = "l", lty = 3-pos_el, lwd = pos_el)\nabline(v=1.5, lty = 2)\n
\n", "answer_id": 677164, "answer_text": "Amplifying @Glen_b's answer and @whuber's comment: here's the plot of the basis elements (for $-3 \\lt x \\lt 6$), with the ones that are non-zero at $x=1.5$ highlighted:\n\n\n\n\n[image: plot of the basis elements of a spline, with the elements that are non-zero at x=1.5 highlighted (solid, thick lines); source: https://i.sstatic.net/7o5ja3We.png] (https://i.sstatic.net/7o5ja3We.png)\n\n\n\n\nlibrary(splines)\nx_i <- 1.5\nx_all <- seq(-3, 6, length.out = 150)\nbasis_matrix <- splines::bs(x_all,\n knots = -2:5, \n Boundary.knots = c(-3, 6),\n degree = 3)\npos_el <- rep(c(1,2,1), c(3,4,3))\npar(las=1, bty = \"l\") ## cosmetic\nmatplot(x_all, basis_matrix, type = \"l\", lty = 3-pos_el, lwd = pos_el)\nabline(v=1.5, lty = 2)", "answer_url": "https://stats.stackexchange.com/a/677164", "author": "Ben Bolker", "author_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T20:32:49+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": 677137, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-09-13T20:32:49+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "EBF57CF7-0E40-482E-A05C-136F42F17A79", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EBF57CF7-0E40-482E-A05C-136F42F17A79/view-source"}], "score": 6, "updated_at": "2026-09-13T20:32:49+00:00"}], "product": "statistics_qa", "question": "I've been studying how splines::bs() builds its basis matrix, and I'm trying to fully understand why the returned matrix has so many zero entries.\n\n\n\n\nThe worked example in Ken Koon Wong's blog post \"Understanding Basis Spline (B-spline) By Working Through Cox-deBoor Algorithm\", reproduced below:\n\n\n\n\nlibrary(splines)\nx_i <- 1.5\nbasis_matrix <- splines::bs(x_i,\n knots = c(-2, -1, 0, 1, 2, 3, 4, 5), # interior knots\n Boundary.knots = c(-3, 6), # boundary knots\n degree = 3)\nbasis_matrix\n\n\n\n\n\nResult:\n\n\n\n\n## 1 2 3 4 5 6 7 8 9 10 11\n## [1,] 0 0 0 0.02083333 0.4791667 0.4791667 0.02083333 0 0 0 0\n## attr(,\"degree\")\n## [1] 3\n## attr(,\"knots\")\n## [1] -2 -1 0 1 2 3 4 5\n## attr(,\"Boundary.knots\")\n## [1] -3 6\n## attr(,\"intercept\")\n## [1] FALSE\n## attr(,\"class\")\n## [1] \"bs\" \"basis\" \"matrix\"\n\n\n\n\n\nWong explained:\n\n\n\n\n\n\n\nAwesome!!! We have very similar numbers !!! But why are there so many columns? And they’re filled with zeros, reminds me almost like padding. Apparently this is mainly to ensure no issues when x is very close to boundary knots is my understanding. And the way they add these padding depends on degrees + 1 if you use degree = 3, add 1 to it and that would be how many repeats of the numbers of your boundary knots.\n\n\n\n\n\n\n\nBut why are the number of leading and trailing zeros different?\n\n\n\n\nFrom wiki of De Boor's algorithm,\n\n\n\n\n\n\n\nIt follows from i≥0 that k≥p. Similarly, we see in the recursion that the highest queried knot location is at index k+1+p. This means that any knot interval [tk,tk+1) which is actually used must have at least p additional knots before and after. In a computer program, this is typically achieved by repeating the first and last used knot location p times. For example, for p=3 and real knot locations (0,1,2), one would pad the knot vector to (0,0,0,0,1,2,2,2,2).\n\n\n\n\n\n\n\n{which is actually used must have at least p additional knots before and after}<- Then the number of leading and trailing zeros should be the same? i.e. 3+1 = 4\n\n\n\n\n\n\n\nUpdate:\nAccording to the calculation by Ken Koon Wong,\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/v4LeyMo7.png] (https://i.sstatic.net/v4LeyMo7.png)\n\n\n\n\nThe position of knots should be c(-3,-3,-3,-3,-2, -1, 0, 1, 2,2,2,2)?\nAm I correct?", "record_id": "Scientific-Statistics-QA:stats:677137", "selected_answer": {"answer_html": "

B-splines are designed to be local* (only nearby x-values affect the relevant predictor, and hence the fitted response).

\n

Consequently the predictor columns will be zero out of the local interval (described in terms of the nearby few knots), and hence for small such intervals will be mostly-zero.

\n
\n

* This locality is mathematically and graphically explicit in the wikipedia article, which is worth reading.

\n", "answer_id": 677156, "answer_text": "B-splines are designed to be local* (only nearby x-values affect the relevant predictor, and hence the fitted response).\n\n\n\n\nConsequently the predictor columns will be zero out of the local interval (described in terms of the nearby few knots), and hence for small such intervals will be mostly-zero.\n\n\n\n\n\n\n\n* This locality is mathematically and graphically explicit in the wikipedia article, which is worth reading.", "answer_url": "https://stats.stackexchange.com/a/677156", "author": "Glen_b", "author_url": "https://stats.stackexchange.com/users/805/glen-b", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T02:41:43+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": 677137, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T02:41:43+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "F103E6FE-AD3D-4F47-A179-708950A92E6A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F103E6FE-AD3D-4F47-A179-708950A92E6A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T03:16:34+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "323EB6A5-54C4-485A-910C-C896C850F031", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/323EB6A5-54C4-485A-910C-C896C850F031/view-source"}], "score": 10, "updated_at": "2026-09-13T03:16:34+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

B-splines are designed to be local* (only nearby x-values affect the relevant predictor, and hence the fitted response).

\n

Consequently the predictor columns will be zero out of the local interval (described in terms of the nearby few knots), and hence for small such intervals will be mostly-zero.

\n
\n

* This locality is mathematically and graphically explicit in the wikipedia article, which is worth reading.

\n", "answer_id": 677156, "answer_text": "B-splines are designed to be local* (only nearby x-values affect the relevant predictor, and hence the fitted response).\n\n\n\n\nConsequently the predictor columns will be zero out of the local interval (described in terms of the nearby few knots), and hence for small such intervals will be mostly-zero.\n\n\n\n\n\n\n\n* This locality is mathematically and graphically explicit in the wikipedia article, which is worth reading.", "answer_url": "https://stats.stackexchange.com/a/677156", "author": "Glen_b", "author_url": "https://stats.stackexchange.com/users/805/glen-b", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T02:41:43+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": 677137, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T02:41:43+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "F103E6FE-AD3D-4F47-A179-708950A92E6A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F103E6FE-AD3D-4F47-A179-708950A92E6A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T03:16:34+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "323EB6A5-54C4-485A-910C-C896C850F031", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/323EB6A5-54C4-485A-910C-C896C850F031/view-source"}], "score": 10, "updated_at": "2026-09-13T03:16:34+00:00"}, {"answer_html": "

Amplifying @Glen_b's answer and @whuber's comment: here's the plot of the basis elements (for $-3 \\lt x \\lt 6$), with the ones that are non-zero at $x=1.5$ highlighted:

\n

\"plot

\n
library(splines)\nx_i <- 1.5\nx_all <- seq(-3, 6, length.out = 150)\nbasis_matrix <- splines::bs(x_all,\n                             knots = -2:5, \n                             Boundary.knots = c(-3, 6),\n                             degree = 3)\npos_el <- rep(c(1,2,1), c(3,4,3))\npar(las=1, bty = "l") ## cosmetic\nmatplot(x_all, basis_matrix, type = "l", lty = 3-pos_el, lwd = pos_el)\nabline(v=1.5, lty = 2)\n
\n", "answer_id": 677164, "answer_text": "Amplifying @Glen_b's answer and @whuber's comment: here's the plot of the basis elements (for $-3 \\lt x \\lt 6$), with the ones that are non-zero at $x=1.5$ highlighted:\n\n\n\n\n[image: plot of the basis elements of a spline, with the elements that are non-zero at x=1.5 highlighted (solid, thick lines); source: https://i.sstatic.net/7o5ja3We.png] (https://i.sstatic.net/7o5ja3We.png)\n\n\n\n\nlibrary(splines)\nx_i <- 1.5\nx_all <- seq(-3, 6, length.out = 150)\nbasis_matrix <- splines::bs(x_all,\n knots = -2:5, \n Boundary.knots = c(-3, 6),\n degree = 3)\npos_el <- rep(c(1,2,1), c(3,4,3))\npar(las=1, bty = \"l\") ## cosmetic\nmatplot(x_all, basis_matrix, type = \"l\", lty = 3-pos_el, lwd = pos_el)\nabline(v=1.5, lty = 2)", "answer_url": "https://stats.stackexchange.com/a/677164", "author": "Ben Bolker", "author_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T20:32:49+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": 677137, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-09-13T20:32:49+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "EBF57CF7-0E40-482E-A05C-136F42F17A79", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EBF57CF7-0E40-482E-A05C-136F42F17A79/view-source"}], "score": 6, "updated_at": "2026-09-13T20:32:49+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/7o5ja3We.png", "https://i.sstatic.net/v4LeyMo7.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": "doraemon", "question_author_url": "https://stats.stackexchange.com/users/368723/doraemon", "question_author_user_type": "registered", "question_created_at": "2026-09-11T07:17:25+00:00", "question_html": "

I've been studying how splines::bs() builds its basis matrix, and I'm trying to fully understand why the returned matrix has so many zero entries.

\n

The worked example in Ken Koon Wong's blog post "Understanding Basis Spline (B-spline) By Working Through Cox-deBoor Algorithm", reproduced below:

\n
library(splines)\nx_i <- 1.5\nbasis_matrix <- splines::bs(x_i,\n                             knots = c(-2, -1, 0, 1, 2, 3, 4, 5),  # interior knots\n                             Boundary.knots = c(-3, 6),            # boundary knots\n                             degree = 3)\nbasis_matrix\n
\n

Result:

\n
##      1 2 3          4         5         6          7 8 9 10 11\n## [1,] 0 0 0 0.02083333 0.4791667 0.4791667 0.02083333 0 0  0  0\n## attr(,"degree")\n## [1] 3\n## attr(,"knots")\n## [1] -2 -1  0  1  2  3  4  5\n## attr(,"Boundary.knots")\n## [1] -3  6\n## attr(,"intercept")\n## [1] FALSE\n## attr(,"class")\n## [1] "bs"     "basis"  "matrix"\n
\n

Wong explained:

\n
\n

Awesome!!! We have very similar numbers !!! But why are there so many columns? And they’re filled with zeros, reminds me almost like padding. Apparently this is mainly to ensure no issues when x is very close to boundary knots is my understanding. And the way they add these padding depends on degrees + 1 if you use degree = 3, add 1 to it and that would be how many repeats of the numbers of your boundary knots.

\n
\n

But why are the number of leading and trailing zeros different?

\n

From wiki of De Boor's algorithm,

\n
\n

It follows from i≥0 that k≥p. Similarly, we see in the recursion that the highest queried knot location is at index k+1+p. This means that any knot interval [tk,tk+1) which is actually used must have at least p additional knots before and after. In a computer program, this is typically achieved by repeating the first and last used knot location p times. For example, for p=3 and real knot locations (0,1,2), one would pad the knot vector to (0,0,0,0,1,2,2,2,2).

\n
\n

{which is actually used must have at least p additional knots before and after}<- Then the number of leading and trailing zeros should be the same? i.e. 3+1 = 4

\n
\n

Update:\nAccording to the calculation by Ken Koon Wong,

\n

\"enter

\n

The position of knots should be c(-3,-3,-3,-3,-2, -1, 0, 1, 2,2,2,2)?\nAm I correct?

\n", "question_id": 677137, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I've been studying how splines::bs() builds its basis matrix, and I'm trying to fully understand why the returned matrix has so many zero entries.\n\n\n\n\nThe worked example in Ken Koon Wong's blog post \"Understanding Basis Spline (B-spline) By Working Through Cox-deBoor Algorithm\", reproduced below:\n\n\n\n\nlibrary(splines)\nx_i <- 1.5\nbasis_matrix <- splines::bs(x_i,\n knots = c(-2, -1, 0, 1, 2, 3, 4, 5), # interior knots\n Boundary.knots = c(-3, 6), # boundary knots\n degree = 3)\nbasis_matrix\n\n\n\n\n\nResult:\n\n\n\n\n## 1 2 3 4 5 6 7 8 9 10 11\n## [1,] 0 0 0 0.02083333 0.4791667 0.4791667 0.02083333 0 0 0 0\n## attr(,\"degree\")\n## [1] 3\n## attr(,\"knots\")\n## [1] -2 -1 0 1 2 3 4 5\n## attr(,\"Boundary.knots\")\n## [1] -3 6\n## attr(,\"intercept\")\n## [1] FALSE\n## attr(,\"class\")\n## [1] \"bs\" \"basis\" \"matrix\"\n\n\n\n\n\nWong explained:\n\n\n\n\n\n\n\nAwesome!!! We have very similar numbers !!! But why are there so many columns? And they’re filled with zeros, reminds me almost like padding. Apparently this is mainly to ensure no issues when x is very close to boundary knots is my understanding. And the way they add these padding depends on degrees + 1 if you use degree = 3, add 1 to it and that would be how many repeats of the numbers of your boundary knots.\n\n\n\n\n\n\n\nBut why are the number of leading and trailing zeros different?\n\n\n\n\nFrom wiki of De Boor's algorithm,\n\n\n\n\n\n\n\nIt follows from i≥0 that k≥p. Similarly, we see in the recursion that the highest queried knot location is at index k+1+p. This means that any knot interval [tk,tk+1) which is actually used must have at least p additional knots before and after. In a computer program, this is typically achieved by repeating the first and last used knot location p times. For example, for p=3 and real knot locations (0,1,2), one would pad the knot vector to (0,0,0,0,1,2,2,2,2).\n\n\n\n\n\n\n\n{which is actually used must have at least p additional knots before and after}<- Then the number of leading and trailing zeros should be the same? i.e. 3+1 = 4\n\n\n\n\n\n\n\nUpdate:\nAccording to the calculation by Ken Koon Wong,\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/v4LeyMo7.png] (https://i.sstatic.net/v4LeyMo7.png)\n\n\n\n\nThe position of knots should be c(-3,-3,-3,-3,-2, -1, 0, 1, 2,2,2,2)?\nAm I correct?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "doraemon", "profile_url": "https://stats.stackexchange.com/users/368723/doraemon", "user_type": "registered"}, "created_at": "2026-09-11T07:17:25+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "44C9B612-E48F-45D8-A87E-134A15427F2A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/44C9B612-E48F-45D8-A87E-134A15427F2A/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-13T06:50:29+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7FDC6F64-699C-45D6-AD65-42C2EB6E9601", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/7FDC6F64-699C-45D6-AD65-42C2EB6E9601/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-09-15T03:24:20+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "26A7DFFA-3772-4615-A75D-4773FFF3DA34", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/26A7DFFA-3772-4615-A75D-4773FFF3DA34/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "doraemon", "profile_url": "https://stats.stackexchange.com/users/368723/doraemon", "user_type": "registered"}, "created_at": "2026-09-18T09:00:22+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "DF8093CD-0CC4-47CA-A76A-429E20D88E33", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DF8093CD-0CC4-47CA-A76A-429E20D88E33/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677137/why-does-a-cubic-b-spline-basis-matrix-contain-so-many-zero-columns", "split": "train", "split_group": "a3b9bc15521973baeed3260891b4d75567f430c5afd7368e49e8db8c587dd1a5", "tags": ["r", "splines", "mgcv", "gamlss"], "thread_id": "stats:677137", "title": "Why does a cubic B-spline basis matrix contain so many zero columns?"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

The inflated type-1 errors in that example are due to the $p$-values being calculated based on asymptotic ($Z$-score) Wald statistics, rather than using some form of finite-size 'denominator degrees of freedom' correction (between-within/Sattherwaite/Kenward-Roger) to get $p$-values based on Student-$t$ distributions. I redid the analysis with ddf corrections (code here, here), with the following results (the binom.test p column tests whether the type-I error is significantly different from $\\alpha=0.05$, for 5000 simulations).

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
methodtestType‑I errorbinom.test p
glmmTMB_wald (asymptotic Wald χ², uncorrected — original post's test)anova0.0909e-32
glmmTMB_none (asymptotic LRT, uncorrected)anova0.0683e-8
glmmTMB_satterthwaiteanova0.0520.48
glmmTMB_kenward-rogeranova0.0530.40
lme_varIdentanova0.0520.44
lmerTest (no heteroscedasticity accommodation, baseline)anova0.0550.10
\n

So things look fine as long as you ddf-correct (specify summary(..., ddf = "satterthwaite")); the theory is a little shaky — it was developed for Gaussian models — but it should probably be OK. At the very least, you can compare asymptotic $p$-values (the default) with these results to see whether this is something you should be concerned about.

\n

For what it's worth I'm not sure there's much theory about the sampling distribution of GLM-type models with estimated scale parameters (e.g. Beta) ...

\n

@EdM is also right that with such large $t$-statistics, you probably don't need to worry — if for instance you were mainly concerned with whether $p<0.05$ or not, you would be fine as long as the denominator df was above 3: the two-tailed test for $t=-3.172, \\textrm{df}=3$ is 2*pt(-3.712, df = 3) $\\approx$ 0.03 ...

\n", "answer_id": 677165, "answer_text": "The inflated type-1 errors in that example are due to the $p$-values being calculated based on asymptotic ($Z$-score) Wald statistics, rather than using some form of finite-size 'denominator degrees of freedom' correction (between-within/Sattherwaite/Kenward-Roger) to get $p$-values based on Student-$t$ distributions. I redid the analysis with ddf corrections (code here (https://github.com/glmmTMB/glmmTMB/blob/master/misc/hetero_ddf_sim.R), here (https://github.com/glmmTMB/glmmTMB/blob/master/misc/hetero_ddf_sim_analysis.R)), with the following results (the binom.test p column tests whether the type-I error is significantly different from $\\alpha=0.05$, for 5000 simulations).\n\n\n\n\n\n\n\n\n\nmethod\ntest\nType‑I error\nbinom.test p\n\n\n\n\n\n\n\n\n\tglmmTMB_wald (asymptotic Wald χ², uncorrected — original post's test)\n\tanova\n\t0.090\n\t9e-32\n\n\n\n\n\n\n\tglmmTMB_none (asymptotic LRT, uncorrected)\n\tanova\n\t0.068\n\t3e-8\n\n\n\n\n\n\n\tglmmTMB_satterthwaite\n\tanova\n\t0.052\n\t0.48\n\n\n\n\n\n\n\tglmmTMB_kenward-roger\n\tanova\n\t0.053\n\t0.40\n\n\n\n\n\n\n\tlme_varIdent\n\tanova\n\t0.052\n\t0.44\n\n\n\n\n\n\n\tlmerTest (no heteroscedasticity accommodation, baseline)\n\tanova\n\t0.055\n\t0.10\n\n\n\n\n\n\n\n\n\nSo things look fine as long as you ddf-correct (specify summary(..., ddf = \"satterthwaite\")); the theory is a little shaky — it was developed for Gaussian models — but it should probably be OK. At the very least, you can compare asymptotic $p$-values (the default) with these results to see whether this is something you should be concerned about.\n\n\n\n\nFor what it's worth I'm not sure there's much theory about the sampling distribution of GLM-type models with estimated scale parameters (e.g. Beta) ...\n\n\n\n\n@EdM is also right that with such large $t$-statistics, you probably don't need to worry — if for instance you were mainly concerned with whether $p<0.05$ or not, you would be fine as long as the denominator df was above 3: the two-tailed test for $t=-3.172, \\textrm{df}=3$ is 2*pt(-3.712, df = 3) $\\approx$ 0.03 ...", "answer_url": "https://stats.stackexchange.com/a/677165", "author": "Ben Bolker", "author_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T20:48:08+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": 677147, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-09-13T20:48:08+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "EF34FC87-9BFC-4047-982E-58C916319B81", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EF34FC87-9BFC-4047-982E-58C916319B81/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-09-14T13:13:51+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "825AC844-EA44-413D-A096-4C2D9BFC6EB4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/825AC844-EA44-413D-A096-4C2D9BFC6EB4/view-source"}], "score": 2, "updated_at": "2026-09-14T13:13:51+00:00"}], "product": "statistics_qa", "question": "I need a mixed effects beta regression. I have used glmmTMB with beta distribution, logit link, to assess the relation between hit scores and threshold of a few observers repeated across three backgrounds (a fourth background was used, but it presented the stimuli differently, so I am running a betareg on it instead). Hit scores are proportions in the open interval (0,1), without 0 or 1.\nI read in a previous question that dispformula from glmmTMB inflates Type I error, making the p-values not valid. Does this still hold for the current glmmTMB package version?\n\n\n\n\nQuestion: Varying dispersion parameter (=dispformula) in glmmTMB in R to account for heteroscedasticity that originates from one predictor (https://stats.stackexchange.com/questions/518013/varying-dispersion-parameter-dispformula-in-glmmtmb-in-r-to-account-for-heter)\n\n\n\n\nBlog Post: https://lgraz.com/posts/lmm-heteroskedastic/ (https://lgraz.com/posts/lmm-heteroskedastic/)\n\n\n\n\nCurrent Model output:\n\n\n\n\nmod_disp_constant: hs ~ thr + bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: hs ~ thr + bd + (1 | obs), zi=~0, disp=~bd\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 6 -421.04 -402.63 216.52 -433.04 \nmod_disp_background 8 -437.64 -413.09 226.82 -453.64 20.593 2 3.374e-05 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n df AICc\nmod_disp_constant 6 -420.4919\nmod_disp_background 8 -436.6780\n----------------------------------------------------------------------\n Family: beta ( logit )\nFormula: hs ~ thr + bd + (1 | obs)\nDispersion: ~bd\nData: data_long\n\n\nRandom effects:\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.04374 0.2091 \nNumber of obs: 159, groups: obs, 53\n\nConditional model:\n Estimate Std. Error z value Pr(>|z|) \n(Intercept) 1.30199 0.05762 22.598 < 2e-16 ***\nthd -0.06437 0.00294 -21.899 < 2e-16 ***\nbdG -0.32972 0.05668 -5.817 6e-09 ***\nbdS -0.15651 0.04216 -3.712 0.000206 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n\nDispersion model:\n Estimate Std. Error z value Pr(>|z|) \n(Intercept) 4.0702 0.2139 19.031 < 2e-16 ***\nbdG -0.1452 0.3023 -0.480 0.63113 \nbdS 1.9828 0.7153 2.772 0.00557 ** \n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1", "record_id": "Scientific-Statistics-QA:stats:677147", "selected_answer": {"answer_html": "

Except for the comparison between mod_disp_constant and mod_disp_background, the p-values you show are based on Wald tests, which hold asymptotically in the limit of large numbers of cases. If you have only "a few observers," I'd first worry about that. Likelihood-ratio tests would be more reliable.

\n

That said, most of those p-values are so small (or so large) that some minor inflation of Type I error wouldn't seem likely to change any "statistical significance" conclusions. If you want to provide more evidence for "significant" results, you could consider some type of resampling test.

\n

I couldn't find that the post about elevated Type I errors specified the glmmTMB version used. I also haven't taken the time to see exactly which types of p-values were collected. I did note that the post seems to indicate elevated Type I error even with homoskedastic data and no dispformula.

\n

In terms of changes with software versions, that post provides code with specified random seeds. You thus could repeat the code with the latest glmmTMB version and see whether the results differ (first with the same seeds, then maybe with different seeds).

\n", "answer_id": 677163, "answer_text": "Except for the comparison between mod_disp_constant and mod_disp_background, the p-values you show are based on Wald tests, which hold asymptotically in the limit of large numbers of cases. If you have only \"a few observers,\" I'd first worry about that. Likelihood-ratio tests would be more reliable.\n\n\n\n\nThat said, most of those p-values are so small (or so large) that some minor inflation of Type I error wouldn't seem likely to change any \"statistical significance\" conclusions. If you want to provide more evidence for \"significant\" results, you could consider some type of resampling test (https://stats.stackexchange.com/a/104746/28500).\n\n\n\n\nI couldn't find that the post about elevated Type I errors (https://lgraz.com/posts/lmm-heteroskedastic/) specified the glmmTMB version used. I also haven't taken the time to see exactly which types of p-values were collected. I did note that the post seems to indicate elevated Type I error even with homoskedastic data and no dispformula (https://lgraz.com/posts/lmm-heteroskedastic/#glmmtmby-trt-1id-1).\n\n\n\n\nIn terms of changes with software versions, that post (https://lgraz.com/posts/lmm-heteroskedastic/) provides code with specified random seeds. You thus could repeat the code with the latest glmmTMB version and see whether the results differ (first with the same seeds, then maybe with different seeds).", "answer_url": "https://stats.stackexchange.com/a/677163", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T17:48:51+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": 677147, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-13T17:48:51+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "3B7C67F5-C6E0-49EA-9E1D-9A76F8372905", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3B7C67F5-C6E0-49EA-9E1D-9A76F8372905/view-source"}], "score": 2, "updated_at": "2026-09-13T17:48:51+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Except for the comparison between mod_disp_constant and mod_disp_background, the p-values you show are based on Wald tests, which hold asymptotically in the limit of large numbers of cases. If you have only "a few observers," I'd first worry about that. Likelihood-ratio tests would be more reliable.

\n

That said, most of those p-values are so small (or so large) that some minor inflation of Type I error wouldn't seem likely to change any "statistical significance" conclusions. If you want to provide more evidence for "significant" results, you could consider some type of resampling test.

\n

I couldn't find that the post about elevated Type I errors specified the glmmTMB version used. I also haven't taken the time to see exactly which types of p-values were collected. I did note that the post seems to indicate elevated Type I error even with homoskedastic data and no dispformula.

\n

In terms of changes with software versions, that post provides code with specified random seeds. You thus could repeat the code with the latest glmmTMB version and see whether the results differ (first with the same seeds, then maybe with different seeds).

\n", "answer_id": 677163, "answer_text": "Except for the comparison between mod_disp_constant and mod_disp_background, the p-values you show are based on Wald tests, which hold asymptotically in the limit of large numbers of cases. If you have only \"a few observers,\" I'd first worry about that. Likelihood-ratio tests would be more reliable.\n\n\n\n\nThat said, most of those p-values are so small (or so large) that some minor inflation of Type I error wouldn't seem likely to change any \"statistical significance\" conclusions. If you want to provide more evidence for \"significant\" results, you could consider some type of resampling test (https://stats.stackexchange.com/a/104746/28500).\n\n\n\n\nI couldn't find that the post about elevated Type I errors (https://lgraz.com/posts/lmm-heteroskedastic/) specified the glmmTMB version used. I also haven't taken the time to see exactly which types of p-values were collected. I did note that the post seems to indicate elevated Type I error even with homoskedastic data and no dispformula (https://lgraz.com/posts/lmm-heteroskedastic/#glmmtmby-trt-1id-1).\n\n\n\n\nIn terms of changes with software versions, that post (https://lgraz.com/posts/lmm-heteroskedastic/) provides code with specified random seeds. You thus could repeat the code with the latest glmmTMB version and see whether the results differ (first with the same seeds, then maybe with different seeds).", "answer_url": "https://stats.stackexchange.com/a/677163", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T17:48:51+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": 677147, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-13T17:48:51+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "3B7C67F5-C6E0-49EA-9E1D-9A76F8372905", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3B7C67F5-C6E0-49EA-9E1D-9A76F8372905/view-source"}], "score": 2, "updated_at": "2026-09-13T17:48:51+00:00"}, {"answer_html": "

The inflated type-1 errors in that example are due to the $p$-values being calculated based on asymptotic ($Z$-score) Wald statistics, rather than using some form of finite-size 'denominator degrees of freedom' correction (between-within/Sattherwaite/Kenward-Roger) to get $p$-values based on Student-$t$ distributions. I redid the analysis with ddf corrections (code here, here), with the following results (the binom.test p column tests whether the type-I error is significantly different from $\\alpha=0.05$, for 5000 simulations).

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
methodtestType‑I errorbinom.test p
glmmTMB_wald (asymptotic Wald χ², uncorrected — original post's test)anova0.0909e-32
glmmTMB_none (asymptotic LRT, uncorrected)anova0.0683e-8
glmmTMB_satterthwaiteanova0.0520.48
glmmTMB_kenward-rogeranova0.0530.40
lme_varIdentanova0.0520.44
lmerTest (no heteroscedasticity accommodation, baseline)anova0.0550.10
\n

So things look fine as long as you ddf-correct (specify summary(..., ddf = "satterthwaite")); the theory is a little shaky — it was developed for Gaussian models — but it should probably be OK. At the very least, you can compare asymptotic $p$-values (the default) with these results to see whether this is something you should be concerned about.

\n

For what it's worth I'm not sure there's much theory about the sampling distribution of GLM-type models with estimated scale parameters (e.g. Beta) ...

\n

@EdM is also right that with such large $t$-statistics, you probably don't need to worry — if for instance you were mainly concerned with whether $p<0.05$ or not, you would be fine as long as the denominator df was above 3: the two-tailed test for $t=-3.172, \\textrm{df}=3$ is 2*pt(-3.712, df = 3) $\\approx$ 0.03 ...

\n", "answer_id": 677165, "answer_text": "The inflated type-1 errors in that example are due to the $p$-values being calculated based on asymptotic ($Z$-score) Wald statistics, rather than using some form of finite-size 'denominator degrees of freedom' correction (between-within/Sattherwaite/Kenward-Roger) to get $p$-values based on Student-$t$ distributions. I redid the analysis with ddf corrections (code here (https://github.com/glmmTMB/glmmTMB/blob/master/misc/hetero_ddf_sim.R), here (https://github.com/glmmTMB/glmmTMB/blob/master/misc/hetero_ddf_sim_analysis.R)), with the following results (the binom.test p column tests whether the type-I error is significantly different from $\\alpha=0.05$, for 5000 simulations).\n\n\n\n\n\n\n\n\n\nmethod\ntest\nType‑I error\nbinom.test p\n\n\n\n\n\n\n\n\n\tglmmTMB_wald (asymptotic Wald χ², uncorrected — original post's test)\n\tanova\n\t0.090\n\t9e-32\n\n\n\n\n\n\n\tglmmTMB_none (asymptotic LRT, uncorrected)\n\tanova\n\t0.068\n\t3e-8\n\n\n\n\n\n\n\tglmmTMB_satterthwaite\n\tanova\n\t0.052\n\t0.48\n\n\n\n\n\n\n\tglmmTMB_kenward-roger\n\tanova\n\t0.053\n\t0.40\n\n\n\n\n\n\n\tlme_varIdent\n\tanova\n\t0.052\n\t0.44\n\n\n\n\n\n\n\tlmerTest (no heteroscedasticity accommodation, baseline)\n\tanova\n\t0.055\n\t0.10\n\n\n\n\n\n\n\n\n\nSo things look fine as long as you ddf-correct (specify summary(..., ddf = \"satterthwaite\")); the theory is a little shaky — it was developed for Gaussian models — but it should probably be OK. At the very least, you can compare asymptotic $p$-values (the default) with these results to see whether this is something you should be concerned about.\n\n\n\n\nFor what it's worth I'm not sure there's much theory about the sampling distribution of GLM-type models with estimated scale parameters (e.g. Beta) ...\n\n\n\n\n@EdM is also right that with such large $t$-statistics, you probably don't need to worry — if for instance you were mainly concerned with whether $p<0.05$ or not, you would be fine as long as the denominator df was above 3: the two-tailed test for $t=-3.172, \\textrm{df}=3$ is 2*pt(-3.712, df = 3) $\\approx$ 0.03 ...", "answer_url": "https://stats.stackexchange.com/a/677165", "author": "Ben Bolker", "author_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T20:48:08+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": 677147, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-09-13T20:48:08+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "EF34FC87-9BFC-4047-982E-58C916319B81", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/EF34FC87-9BFC-4047-982E-58C916319B81/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-09-14T13:13:51+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "825AC844-EA44-413D-A096-4C2D9BFC6EB4", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/825AC844-EA44-413D-A096-4C2D9BFC6EB4/view-source"}], "score": 2, "updated_at": "2026-09-14T13:13:51+00:00"}], "domain": "statistics", "external_links": ["https://github.com/glmmTMB/glmmTMB/blob/master/misc/hetero_ddf_sim.R", "https://github.com/glmmTMB/glmmTMB/blob/master/misc/hetero_ddf_sim_analysis.R", "https://lgraz.com/posts/lmm-heteroskedastic/", "https://lgraz.com/posts/lmm-heteroskedastic/#glmmtmby-trt-1id-1"], "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": "Dodo", "question_author_url": "https://stats.stackexchange.com/users/516003/dodo", "question_author_user_type": "registered", "question_created_at": "2026-09-12T01:15:13+00:00", "question_html": "

I need a mixed effects beta regression. I have used glmmTMB with beta distribution, logit link, to assess the relation between hit scores and threshold of a few observers repeated across three backgrounds (a fourth background was used, but it presented the stimuli differently, so I am running a betareg on it instead). Hit scores are proportions in the open interval (0,1), without 0 or 1.\nI read in a previous question that dispformula from glmmTMB inflates Type I error, making the p-values not valid. Does this still hold for the current glmmTMB package version?

\n

Question: Varying dispersion parameter (=dispformula) in glmmTMB in R to account for heteroscedasticity that originates from one predictor

\n

Blog Post: https://lgraz.com/posts/lmm-heteroskedastic/

\n

Current Model output:

\n
mod_disp_constant: hs ~ thr + bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: hs ~ thr + bd + (1 | obs), zi=~0, disp=~bd\n                    Df     AIC     BIC logLik deviance  Chisq Chi Df Pr(>Chisq)    \nmod_disp_constant    6 -421.04 -402.63 216.52  -433.04                             \nmod_disp_background  8 -437.64 -413.09 226.82  -453.64 20.593      2  3.374e-05 ***\n---\nSignif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n                    df      AICc\nmod_disp_constant    6 -420.4919\nmod_disp_background  8 -436.6780\n----------------------------------------------------------------------\n Family: beta  ( logit )\nFormula:          hs ~ thr + bd + (1 | obs)\nDispersion:                ~bd\nData: data_long\n\n\nRandom effects:\n\nConditional model:\n Groups Name        Variance Std.Dev.\n obs    (Intercept) 0.04374  0.2091  \nNumber of obs: 159, groups:  obs, 53\n\nConditional model:\n                    Estimate Std. Error z value Pr(>|z|)    \n(Intercept)          1.30199    0.05762  22.598  < 2e-16 ***\nthd                 -0.06437    0.00294 -21.899  < 2e-16 ***\nbdG                 -0.32972    0.05668  -5.817    6e-09 ***\nbdS                 -0.15651    0.04216  -3.712 0.000206 ***\n---\nSignif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n\nDispersion model:\n                    Estimate Std. Error z value Pr(>|z|)    \n(Intercept)           4.0702     0.2139  19.031  < 2e-16 ***\nbdG                   -0.1452     0.3023  -0.480  0.63113    \nbdS                   1.9828     0.7153   2.772  0.00557 ** \n---\nSignif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n
\n", "question_id": 677147, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I need a mixed effects beta regression. I have used glmmTMB with beta distribution, logit link, to assess the relation between hit scores and threshold of a few observers repeated across three backgrounds (a fourth background was used, but it presented the stimuli differently, so I am running a betareg on it instead). Hit scores are proportions in the open interval (0,1), without 0 or 1.\nI read in a previous question that dispformula from glmmTMB inflates Type I error, making the p-values not valid. Does this still hold for the current glmmTMB package version?\n\n\n\n\nQuestion: Varying dispersion parameter (=dispformula) in glmmTMB in R to account for heteroscedasticity that originates from one predictor (https://stats.stackexchange.com/questions/518013/varying-dispersion-parameter-dispformula-in-glmmtmb-in-r-to-account-for-heter)\n\n\n\n\nBlog Post: https://lgraz.com/posts/lmm-heteroskedastic/ (https://lgraz.com/posts/lmm-heteroskedastic/)\n\n\n\n\nCurrent Model output:\n\n\n\n\nmod_disp_constant: hs ~ thr + bd + (1 | obs), zi=~0, disp=~1\nmod_disp_background: hs ~ thr + bd + (1 | obs), zi=~0, disp=~bd\n Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) \nmod_disp_constant 6 -421.04 -402.63 216.52 -433.04 \nmod_disp_background 8 -437.64 -413.09 226.82 -453.64 20.593 2 3.374e-05 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n df AICc\nmod_disp_constant 6 -420.4919\nmod_disp_background 8 -436.6780\n----------------------------------------------------------------------\n Family: beta ( logit )\nFormula: hs ~ thr + bd + (1 | obs)\nDispersion: ~bd\nData: data_long\n\n\nRandom effects:\n\nConditional model:\n Groups Name Variance Std.Dev.\n obs (Intercept) 0.04374 0.2091 \nNumber of obs: 159, groups: obs, 53\n\nConditional model:\n Estimate Std. Error z value Pr(>|z|) \n(Intercept) 1.30199 0.05762 22.598 < 2e-16 ***\nthd -0.06437 0.00294 -21.899 < 2e-16 ***\nbdG -0.32972 0.05668 -5.817 6e-09 ***\nbdS -0.15651 0.04216 -3.712 0.000206 ***\n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n\nDispersion model:\n Estimate Std. Error z value Pr(>|z|) \n(Intercept) 4.0702 0.2139 19.031 < 2e-16 ***\nbdG -0.1452 0.3023 -0.480 0.63113 \nbdS 1.9828 0.7153 2.772 0.00557 ** \n---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1", "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-09-12T01:15:13+00:00", "raw_file": "raw/codex_api_v1/3f959895a29b33d83894e5370d82e1c0cf87f20ac57fa423ebc923738357c657_1790825253957066500_0.json", "raw_sha256": "ddd8808039e410ca99f97e2a7f12c307f046c4e5c3e184683bc12f816e6f49fc", "revision_guid": "6B585FAD-32F7-4AB7-8609-8A14FD5C6F8A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6B585FAD-32F7-4AB7-8609-8A14FD5C6F8A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lukas Lohse", "profile_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "user_type": "registered"}, "created_at": "2026-09-12T16:14:36+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "C41A8C0D-BD77-4EB7-849E-FEBEFC1EFBE3", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C41A8C0D-BD77-4EB7-849E-FEBEFC1EFBE3/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-09-12T17:07:05+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "DE7C429C-8ACF-4C04-86D2-C436353A28D0", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DE7C429C-8ACF-4C04-86D2-C436353A28D0/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-14T01:21:02+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "CC727907-664B-41EC-A824-0AEB29F60F2C", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/CC727907-664B-41EC-A824-0AEB29F60F2C/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-09-18T15:29:25+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "8B78E92E-9DD1-49AD-B92C-A0DE26764BD4", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8B78E92E-9DD1-49AD-B92C-A0DE26764BD4/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677147/glmmtmb-with-beta-distribution-for-repeated-measures-with-varying-dispersion-a", "split": "train", "split_group": "1a195428e2f8363aa23e4bda45d98eecf5f10465c2148748aa9c5fb17c0c0370", "tags": ["beta-distribution", "glmmtmb", "dispersion"], "thread_id": "stats:677147", "title": "glmmTMB with beta distribution for repeated measures with varying dispersion - Are p-values from dispersion model unreliable?"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

I presume that you are interested in comparing medians of paired data, and that somehow you felt that your data was not “normal enough” to warrant a paired t-test? Hence your choice to use a Wilcoxon-signed-Rank test (WSRt).

\n

The first issue is that the WSRt is not a test of the median (I assume this is what you thought)! I know most textbooks, and stats classes, present it as a test of the median. This is a sad commentary on the state of statistical education. The WSRt is a test of the pseudomedian, aka Hodges-Lehman estimator.
\nTake your 2 samples, compute the paired differences, then compute all possible paired averages $(\\frac {(x_i + x_j)} {2} \\text{ ,} i \\le j)$, then compute the median of these paired averages.
\nNow, if you want to explain to your audience what the pseudomedian is, why it matters, and what the intuition behind it is, feel free...\nAnd yes, under some very strict conditions (namely, symmetry), the pseudomedian will coincide with the median, and, for that matter, with the mean; so, you may as well call it a test of the mean.
\nHowever, the WSRt is not robust (at all!) to departures from symmetry. So much so that, if you reject the null, you will never know if it is because the pseudomedian was different from $0$, or because the paired differences’ distribution is not symmetric, or both...In fact, the WSRT can be used as a pretty good test of symmetry (comparing to the observed median).

\n

The fact that you ran some tests for symmetry does not ensure "exact" symmetry. It just fails to reject it... But uinless the p-value of these tests is $1$, there is some non-symmetry, which means that the pseudomedian no longer coincide with the median, and hence that you can no longer draw conclusions about the medians...

\n

The further irony is that if the paired differences are symmetric, then the CLT will ensure convergence of the sampling distribution of the mean, with very reasonable sample sizes (e.g. ~ 20). See e.g. here for a nice simulation, starting with a very non-normal, but symmetric, bimodal distribution. So under that symmetry assumption, you might as well have used a paired t-test (which has more power...).

\n

I am in fact curious about why you did not use a paired t-test? If it is because some of your 4 marginal distributions were not normally distributed, that would be incorrect. The only distribution which matters is that of the paired differences (which is often normal “enough”, when the 2 “parent” distributions are skewed). Moreover, depending on your sample sizes (?), and specific non-normality of the paired differences (did you run a normality test?), the CLT could come to your rescue and allow you to use a paired t-test.

\n

And if you truly wanted to test medians, w/o any consideration to lack (or not) of normality, then you can use a Sign test (available for paired data, and which is basically a binomial test).

\n

So in the end, I can not see any good reason why you (or other researchers) would ever want to use a WSRt, unless they (and their audience) truly care about the pseudomedian...

\n", "answer_id": 677153, "answer_text": "I presume that you are interested in comparing medians of paired data, and that somehow you felt that your data was not “normal enough” to warrant a paired t-test? Hence your choice to use a Wilcoxon-signed-Rank test (WSRt).\n\n\n\n\nThe first issue is that the WSRt is not a test of the median (I assume this is what you thought)! I know most textbooks, and stats classes, present it as a test of the median. This is a sad commentary on the state of statistical education. The WSRt is a test of the pseudomedian (https://en.wikipedia.org/wiki/Pseudomedian), aka Hodges-Lehman estimator (https://en.wikipedia.org/wiki/Hodges%E2%80%93Lehmann_estimator).\n\nTake your 2 samples, compute the paired differences, then compute all possible paired averages $(\\frac {(x_i + x_j)} {2} \\text{ ,} i \\le j)$, then compute the median of these paired averages.\n\nNow, if you want to explain to your audience what the pseudomedian is, why it matters, and what the intuition behind it is, feel free...\nAnd yes, under some very strict conditions (namely, symmetry), the pseudomedian will coincide with the median, and, for that matter, with the mean; so, you may as well call it a test of the mean.\n\nHowever, the WSRt is not robust (at all!) to departures from symmetry. So much so that, if you reject the null, you will never know if it is because the pseudomedian was different from $0$, or because the paired differences’ distribution is not symmetric, or both...In fact, the WSRT can be used as a pretty good test of symmetry (comparing to the observed median).\n\n\n\n\nThe fact that you ran some tests for symmetry does not ensure \"exact\" symmetry. It just fails to reject it... But uinless the p-value of these tests is $1$, there is some non-symmetry, which means that the pseudomedian no longer coincide with the median, and hence that you can no longer draw conclusions about the medians...\n\n\n\n\nThe further irony is that if the paired differences are symmetric, then the CLT will ensure convergence of the sampling distribution of the mean, with very reasonable sample sizes (e.g. ~ 20). See e.g. here (https://statistical-engineering.com/clt-summary/clt-bimodal-distribution/) for a nice simulation, starting with a very non-normal, but symmetric, bimodal distribution. So under that symmetry assumption, you might as well have used a paired t-test (which has more power...).\n\n\n\n\nI am in fact curious about why you did not use a paired t-test? If it is because some of your 4 marginal distributions were not normally distributed, that would be incorrect. The only distribution which matters is that of the paired differences (which is often normal “enough”, when the 2 “parent” distributions are skewed). Moreover, depending on your sample sizes (?), and specific non-normality of the paired differences (did you run a normality test?), the CLT could come to your rescue and allow you to use a paired t-test.\n\n\n\n\nAnd if you truly wanted to test medians, w/o any consideration to lack (or not) of normality, then you can use a Sign test (https://en.wikipedia.org/wiki/Sign_test) (available for paired data, and which is basically a binomial test).\n\n\n\n\nSo in the end, I can not see any good reason why you (or other researchers) would ever want to use a WSRt, unless they (and their audience) truly care about the pseudomedian...", "answer_url": "https://stats.stackexchange.com/a/677153", "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-12T23:18:59+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": 677151, "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-12T23:18:59+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "3C2DE467-9902-4F8B-A1EE-C1E5683A293D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3C2DE467-9902-4F8B-A1EE-C1E5683A293D/view-source"}, {"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-12T23:26:54+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "05A3FC9C-D387-42EC-8A32-229030F8C23F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/05A3FC9C-D387-42EC-8A32-229030F8C23F/view-source"}], "score": 2, "updated_at": "2026-09-12T23:26:54+00:00"}, {"answer_html": "

The signed-rank test, as said by others, requires a symmetry assumption. Also it is not invariant to transformations of the variable. For those reasons I consider the signed-rank test as obsolete and always use Kornbrot's rank difference test as exemplified here.

\n

Regarding assumptions of the Wilcoxon test (original and rank difference version) it doesn't assume anything in terms of giving the right answer about which group has better outcomes. But for Wilcoxon to have optimum power, the proportional odds assumption must hold.

\n", "answer_id": 677160, "answer_text": "The signed-rank test, as said by others, requires a symmetry assumption. Also it is not invariant to transformations of the variable. For those reasons I consider the signed-rank test as obsolete and always use Kornbrot's rank difference test as exemplified here (https://hbiostat.org/bbr/nonpar).\n\n\n\n\nRegarding assumptions of the Wilcoxon test (original and rank difference version) it doesn't assume anything in terms of giving the right answer about which group has better outcomes. But for Wilcoxon to have optimum power, the proportional odds assumption must hold (https://fharrell.com/post/powilcoxon).", "answer_url": "https://stats.stackexchange.com/a/677160", "author": "Frank Harrell", "author_url": "https://stats.stackexchange.com/users/4253/frank-harrell", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T13:03:32+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": 677151, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Frank Harrell", "profile_url": "https://stats.stackexchange.com/users/4253/frank-harrell", "user_type": "registered"}, "created_at": "2026-09-13T13:03:32+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "4F4DF722-93BC-48C5-921A-5B46CA5F5750", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F4DF722-93BC-48C5-921A-5B46CA5F5750/view-source"}], "score": 4, "updated_at": "2026-09-13T13:03:32+00:00"}], "product": "statistics_qa", "question": "We are trying to ensure that we satisfy the assumptions for Wilcoxon. We have the 15 healthy subjects doing basic movements using sensors and markers, with and without compensation i.e. mimicking unhealthy subjects. For example, they do a movement A (shoulder adduction/abduction) with and without any hiking of the shoulder.\n\n\n\n\nWe simply want to show that we properly detect (forced) compensation\n\n\n\n\nOur data point for ith subject is X_i= ROM_with compensation minus ROM_without compensation. So I think we do have independence.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/wMwItQY8.png] (https://i.sstatic.net/wMwItQY8.png)\n\n\n\n\nFor the symmetry assumption, the data points were ordered around their median as required by the test by having a p-value bigger than 0.05.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/AqvWf28J.png] (https://i.sstatic.net/AqvWf28J.png)", "record_id": "Scientific-Statistics-QA:stats:677151", "selected_answer": {"answer_html": "

When we speak of the assumptions of a test, people typically mean the assumptions used to derive the null distribution of the test statistic. If the relevant assumptions hold, that should lead to rejection rates which don't exceed the desired significance level when $H_0$ is true.

\n

For the signed rank test, the distribution-related assumption you're looking for (given, at least for paired data, the set of ranks assigned to the absolute differences) with which you can derive the null distribution of the test statistic would be exchangeability of within-pair labels (so under $H_0$, if $+$ and $-$ signs on the differences are flipped to the opposite sign, the distribution of differences would be unaffected).

\n

Symmetry of differences and independence across differences should be sufficient for distribution-related assumptions under $H_0$ (giving the required exchangeability), albeit this is slightly more than necessary.

\n

One fairly natural way this symmetry would be expected to occur is if the bivariate distribution for pair-members was itself exchangeable, so that for any given pair, say pair $i$, the bivariate distribution of $(Y_{i,1},Y_{i,2})$ would be the same as for $(Y_{i,2},Y_{i,1})$. That is, interchanging the within-pair labels makes no difference. For example: if initial assignment of label 1 and 2 was random, and some treatment was applied to the second pair-members that did nothing at all, you should expect to see such exchangeability of within-pair labels.

\n

One of several problems with the widespread practice of only trying to look at the data you're using in the test (let alone using a formal test) to decide if an assumption — such as symmetry — applies is that the null is very likely not actually true in the population-process your data are drawn from, and that assumption might not be required under the alternative for the test to work well. In this case, symmetry under the alternative is not required for the signed rank test to function correctly. Consequently, the data at hand might not be particularly relevant to an assumption about a counterfactual circumstance.

\n

An example where you could expect symmetry might well apply under $H_0$ but not to apply under $H_1$ is when the original pairs of variables have support on a bounded interval, although there are many more cases where you should reasonably anticipate that scale or shape may change across pairs under the alternative (resulting in loss of symmetry of differences under the alternative, without any harm to significance level). I would not usually be inclined to expect symmetry under the alternative to be the case with these kinds of angular values, for example, although it might not be easy to detect in very small samples.

\n

For example, imagine (in that above treatment scenario) that under a completely absent treatment effect the measured responses of both pair members both have some skewed distribution on positive values but were independent conditional on the pair-index $i$ (independence is stronger than needed here, but simplifies description). The differences would be symmetric about 0, and the null distribution in such a scenario will be as derived. Further, let us say that an effective treatment increases the score by some percentage (with some noise), let's say on average by 15%. Then pair differences will not be symmetric in general but the test still works perfectly well - under this alternative, the test statistic will have larger ('treated $-$ untreated') difference values than under the null, and further, larger absolute differences (and so their ranks) will tend to be more associated with positive signs. If you are under the second scenario you would in larger samples frequently reject symmetry of differences in the data, but that asymmetry is not relevant to when the assumption would need to hold for the test to work.

\n
\n

There are other reasons why you should be wary of the practice of trying to use the sample you're testing to consider assumptions even when they should also apply under the alternative, and why testing them presents some additional concerns. I will discuss a few of the issues.

\n

First, you should not expect assumed models to be perfect descriptions — they are convenient approximations. In practice they almost never hold exactly. The relevant question, then, is not "is this assumption true?" (very likely not) but "is the potential impact of its failure large enough to matter?". That's an issue of a kind of effect size, rather than significance, and tests of assumptions don't answer it. They will miss potentially important effects at small sample sizes (like yours) and will find what you already know to be the case (that the assumption was not exactly true) at large sample size, even if the impact on the properties of the original test was minuscule, leading you to be more relaxed about large effects with small samples and to avoid using a test because of a small effect with a large sample.

\n

Second, there is the fact that the properties of the signed rank test were not derived for the actual testing procedure you're applying: (i) check assumptions on these data, then (ii) conditionally on the outcome of that, either use the original test you had in mind, or do something else. Applying the originally planned test (such as the signed rank test) to such filtered data will no longer have the nominal properties. In short, significance levels and p-values will be different from what they were claimed to be.

\n

(I may add more issues in a later edit).

\n

You may gain the impression that I am suggesting assumptions should be ignored. On the contrary, I believe they require a deal more effort, not less. They need very careful and thoughtful consideration, but with proper care about what is being assumed about which things when, in the context of their potential impact on inference. To consider reasonableness and potential kinds and degree of violation of assumptions, I'd more often be looking at things like expert knowledge, other data, models/theory of the mechanics, including what makes sense for the alternative, and careful consideration of the behaviour of the test under required assumptions each of (i) the null (in particular, available significance levels) and (ii) the alternative (power curves at potential choices of significance level) and violations of them (seeing potential impact on those properties, for example via simulation studies).

\n

At that stage, if it turns out that some properties may be substantively affected by potential violations of assumptions, you're in a position to consider other, more robust analyses (or, given that this consideration occurs before data collection, at study design time) perhaps even different variables or different protocols.

\n

Post hoc examination of assumptions would still be useful as a way of seeing whether the kinds and degrees of violations considered were sufficient, which - if they were not - might then throw doubt on the conclusions (hence the need for care and thoughtful consideration of them).

\n
\n

Assumptions aside, I'd tend to worry a good deal about power here, especially if you're doing multiple testing correction. Effect sizes would likely need to be quite substantial under such conditions. What were your effect sizes of interest at study design stage, and what sample sizes would be needed to reliably detect them?

\n

Is there a particular reason you chose this test? I'd have expected that in relation to variables like these, there should already have been a decent body of work collecting distributional information sufficient to formulate reasonable distributional models - albeit with such small sample sizes I'd be inclined to add some further protection on the significance level if possible (such as using a likelihood ratio type statistic as the basis of a permutation test, perhaps).

\n", "answer_id": 677154, "answer_text": "When we speak of the assumptions of a test, people typically mean the assumptions used to derive the null distribution of the test statistic. If the relevant assumptions hold, that should lead to rejection rates which don't exceed the desired significance level when $H_0$ is true.\n\n\n\n\nFor the signed rank test, the distribution-related assumption you're looking for (given, at least for paired data, the set of ranks assigned to the absolute differences) with which you can derive the null distribution of the test statistic would be exchangeability of within-pair labels (so under $H_0$, if $+$ and $-$ signs on the differences are flipped to the opposite sign, the distribution of differences would be unaffected).\n\n\n\n\nSymmetry of differences and independence across differences should be sufficient for distribution-related assumptions under $H_0$ (giving the required exchangeability), albeit this is slightly more than necessary.\n\n\n\n\nOne fairly natural way this symmetry would be expected to occur is if the bivariate distribution for pair-members was itself exchangeable, so that for any given pair, say pair $i$, the bivariate distribution of $(Y_{i,1},Y_{i,2})$ would be the same as for $(Y_{i,2},Y_{i,1})$. That is, interchanging the within-pair labels makes no difference. For example: if initial assignment of label 1 and 2 was random, and some treatment was applied to the second pair-members that did nothing at all, you should expect to see such exchangeability of within-pair labels.\n\n\n\n\nOne of several problems with the widespread practice of only trying to look at the data you're using in the test (let alone using a formal test) to decide if an assumption — such as symmetry — applies is that the null is very likely not actually true in the population-process your data are drawn from, and that assumption might not be required under the alternative for the test to work well. In this case, symmetry under the alternative is not required for the signed rank test to function correctly. Consequently, the data at hand might not be particularly relevant to an assumption about a counterfactual circumstance.\n\n\n\n\nAn example where you could expect symmetry might well apply under $H_0$ but not to apply under $H_1$ is when the original pairs of variables have support on a bounded interval, although there are many more cases where you should reasonably anticipate that scale or shape may change across pairs under the alternative (resulting in loss of symmetry of differences under the alternative, without any harm to significance level). I would not usually be inclined to expect symmetry under the alternative to be the case with these kinds of angular values, for example, although it might not be easy to detect in very small samples.\n\n\n\n\nFor example, imagine (in that above treatment scenario) that under a completely absent treatment effect the measured responses of both pair members both have some skewed distribution on positive values but were independent conditional on the pair-index $i$ (independence is stronger than needed here, but simplifies description). The differences would be symmetric about 0, and the null distribution in such a scenario will be as derived. Further, let us say that an effective treatment increases the score by some percentage (with some noise), let's say on average by 15%. Then pair differences will not be symmetric in general but the test still works perfectly well - under this alternative, the test statistic will have larger ('treated $-$ untreated') difference values than under the null, and further, larger absolute differences (and so their ranks) will tend to be more associated with positive signs. If you are under the second scenario you would in larger samples frequently reject symmetry of differences in the data, but that asymmetry is not relevant to when the assumption would need to hold for the test to work.\n\n\n\n\n\n\n\nThere are other reasons why you should be wary of the practice of trying to use the sample you're testing to consider assumptions even when they should also apply under the alternative, and why testing them presents some additional concerns. I will discuss a few of the issues.\n\n\n\n\nFirst, you should not expect assumed models to be perfect descriptions — they are convenient approximations. In practice they almost never hold exactly. The relevant question, then, is not \"is this assumption true?\" (very likely not) but \"is the potential impact of its failure large enough to matter?\". That's an issue of a kind of effect size, rather than significance, and tests of assumptions don't answer it. They will miss potentially important effects at small sample sizes (like yours) and will find what you already know to be the case (that the assumption was not exactly true) at large sample size, even if the impact on the properties of the original test was minuscule, leading you to be more relaxed about large effects with small samples and to avoid using a test because of a small effect with a large sample.\n\n\n\n\nSecond, there is the fact that the properties of the signed rank test were not derived for the actual testing procedure you're applying: (i) check assumptions on these data, then (ii) conditionally on the outcome of that, either use the original test you had in mind, or do something else. Applying the originally planned test (such as the signed rank test) to such filtered data will no longer have the nominal properties. In short, significance levels and p-values will be different from what they were claimed to be.\n\n\n\n\n(I may add more issues in a later edit).\n\n\n\n\nYou may gain the impression that I am suggesting assumptions should be ignored. On the contrary, I believe they require a deal more effort, not less. They need very careful and thoughtful consideration, but with proper care about what is being assumed about which things when, in the context of their potential impact on inference. To consider reasonableness and potential kinds and degree of violation of assumptions, I'd more often be looking at things like expert knowledge, other data, models/theory of the mechanics, including what makes sense for the alternative, and careful consideration of the behaviour of the test under required assumptions each of (i) the null (in particular, available significance levels) and (ii) the alternative (power curves at potential choices of significance level) and violations of them (seeing potential impact on those properties, for example via simulation studies).\n\n\n\n\nAt that stage, if it turns out that some properties may be substantively affected by potential violations of assumptions, you're in a position to consider other, more robust analyses (or, given that this consideration occurs before data collection, at study design time) perhaps even different variables or different protocols.\n\n\n\n\nPost hoc examination of assumptions would still be useful as a way of seeing whether the kinds and degrees of violations considered were sufficient, which - if they were not - might then throw doubt on the conclusions (hence the need for care and thoughtful consideration of them).\n\n\n\n\n\n\n\nAssumptions aside, I'd tend to worry a good deal about power here, especially if you're doing multiple testing correction. Effect sizes would likely need to be quite substantial under such conditions. What were your effect sizes of interest at study design stage, and what sample sizes would be needed to reliably detect them?\n\n\n\n\nIs there a particular reason you chose this test? I'd have expected that in relation to variables like these, there should already have been a decent body of work collecting distributional information sufficient to formulate reasonable distributional models - albeit with such small sample sizes I'd be inclined to add some further protection on the significance level if possible (such as using a likelihood ratio type statistic as the basis of a permutation test, perhaps).", "answer_url": "https://stats.stackexchange.com/a/677154", "author": "Glen_b", "author_url": "https://stats.stackexchange.com/users/805/glen-b", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-12T23:43:30+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": 677151, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-12T23:43:30+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "62F12774-D8F8-4C82-9461-0081EA3B7680", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/62F12774-D8F8-4C82-9461-0081EA3B7680/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-12T23:50:43+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "23E95A83-7587-40AD-990D-E45001144F34", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/23E95A83-7587-40AD-990D-E45001144F34/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T00:01:28+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "894E8962-A0A1-4552-94AA-FB8358333C6F", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/894E8962-A0A1-4552-94AA-FB8358333C6F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T00:13:51+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "DC825BD9-24E3-4E05-9A2F-F8E8251C3738", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DC825BD9-24E3-4E05-9A2F-F8E8251C3738/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T00:20:22+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "A32BE78F-A0A6-410A-B159-F03158F18817", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A32BE78F-A0A6-410A-B159-F03158F18817/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T00:59:43+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "A633813B-2768-4A48-A63B-259C6FD3575A", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A633813B-2768-4A48-A63B-259C6FD3575A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T01:06:57+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7BE0590E-5BEE-462F-80F5-56379C6713FC", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7BE0590E-5BEE-462F-80F5-56379C6713FC/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T01:29:01+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "0007ADE3-CBEE-4726-95D9-D1189607D258", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0007ADE3-CBEE-4726-95D9-D1189607D258/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T01:39:01+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "E13B98B9-3EFE-4971-8B4B-9B3A61073C6C", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E13B98B9-3EFE-4971-8B4B-9B3A61073C6C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T01:44:18+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "CB56B979-81DB-4905-8209-F8457366027B", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB56B979-81DB-4905-8209-F8457366027B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T07:33:41+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "9774D478-72F8-4E04-86F1-C604C00BF2D6", "revision_number": 11, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9774D478-72F8-4E04-86F1-C604C00BF2D6/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T23:26:32+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7BAB854F-462C-49BB-85A2-0D8E40A6D942", "revision_number": 12, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7BAB854F-462C-49BB-85A2-0D8E40A6D942/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-14T04:27:44+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "150B68AD-1C1F-45FE-B721-E0451567395E", "revision_number": 13, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/150B68AD-1C1F-45FE-B721-E0451567395E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-15T10:27:52+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B6854EBE-3BF4-4571-BFB2-9C476D2160F0", "revision_number": 14, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B6854EBE-3BF4-4571-BFB2-9C476D2160F0/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-15T15:01:34+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "E99122AD-481E-4371-BF94-D061728520D9", "revision_number": 15, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E99122AD-481E-4371-BF94-D061728520D9/view-source"}], "score": 4, "updated_at": "2026-09-15T15:01:34+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

I presume that you are interested in comparing medians of paired data, and that somehow you felt that your data was not “normal enough” to warrant a paired t-test? Hence your choice to use a Wilcoxon-signed-Rank test (WSRt).

\n

The first issue is that the WSRt is not a test of the median (I assume this is what you thought)! I know most textbooks, and stats classes, present it as a test of the median. This is a sad commentary on the state of statistical education. The WSRt is a test of the pseudomedian, aka Hodges-Lehman estimator.
\nTake your 2 samples, compute the paired differences, then compute all possible paired averages $(\\frac {(x_i + x_j)} {2} \\text{ ,} i \\le j)$, then compute the median of these paired averages.
\nNow, if you want to explain to your audience what the pseudomedian is, why it matters, and what the intuition behind it is, feel free...\nAnd yes, under some very strict conditions (namely, symmetry), the pseudomedian will coincide with the median, and, for that matter, with the mean; so, you may as well call it a test of the mean.
\nHowever, the WSRt is not robust (at all!) to departures from symmetry. So much so that, if you reject the null, you will never know if it is because the pseudomedian was different from $0$, or because the paired differences’ distribution is not symmetric, or both...In fact, the WSRT can be used as a pretty good test of symmetry (comparing to the observed median).

\n

The fact that you ran some tests for symmetry does not ensure "exact" symmetry. It just fails to reject it... But uinless the p-value of these tests is $1$, there is some non-symmetry, which means that the pseudomedian no longer coincide with the median, and hence that you can no longer draw conclusions about the medians...

\n

The further irony is that if the paired differences are symmetric, then the CLT will ensure convergence of the sampling distribution of the mean, with very reasonable sample sizes (e.g. ~ 20). See e.g. here for a nice simulation, starting with a very non-normal, but symmetric, bimodal distribution. So under that symmetry assumption, you might as well have used a paired t-test (which has more power...).

\n

I am in fact curious about why you did not use a paired t-test? If it is because some of your 4 marginal distributions were not normally distributed, that would be incorrect. The only distribution which matters is that of the paired differences (which is often normal “enough”, when the 2 “parent” distributions are skewed). Moreover, depending on your sample sizes (?), and specific non-normality of the paired differences (did you run a normality test?), the CLT could come to your rescue and allow you to use a paired t-test.

\n

And if you truly wanted to test medians, w/o any consideration to lack (or not) of normality, then you can use a Sign test (available for paired data, and which is basically a binomial test).

\n

So in the end, I can not see any good reason why you (or other researchers) would ever want to use a WSRt, unless they (and their audience) truly care about the pseudomedian...

\n", "answer_id": 677153, "answer_text": "I presume that you are interested in comparing medians of paired data, and that somehow you felt that your data was not “normal enough” to warrant a paired t-test? Hence your choice to use a Wilcoxon-signed-Rank test (WSRt).\n\n\n\n\nThe first issue is that the WSRt is not a test of the median (I assume this is what you thought)! I know most textbooks, and stats classes, present it as a test of the median. This is a sad commentary on the state of statistical education. The WSRt is a test of the pseudomedian (https://en.wikipedia.org/wiki/Pseudomedian), aka Hodges-Lehman estimator (https://en.wikipedia.org/wiki/Hodges%E2%80%93Lehmann_estimator).\n\nTake your 2 samples, compute the paired differences, then compute all possible paired averages $(\\frac {(x_i + x_j)} {2} \\text{ ,} i \\le j)$, then compute the median of these paired averages.\n\nNow, if you want to explain to your audience what the pseudomedian is, why it matters, and what the intuition behind it is, feel free...\nAnd yes, under some very strict conditions (namely, symmetry), the pseudomedian will coincide with the median, and, for that matter, with the mean; so, you may as well call it a test of the mean.\n\nHowever, the WSRt is not robust (at all!) to departures from symmetry. So much so that, if you reject the null, you will never know if it is because the pseudomedian was different from $0$, or because the paired differences’ distribution is not symmetric, or both...In fact, the WSRT can be used as a pretty good test of symmetry (comparing to the observed median).\n\n\n\n\nThe fact that you ran some tests for symmetry does not ensure \"exact\" symmetry. It just fails to reject it... But uinless the p-value of these tests is $1$, there is some non-symmetry, which means that the pseudomedian no longer coincide with the median, and hence that you can no longer draw conclusions about the medians...\n\n\n\n\nThe further irony is that if the paired differences are symmetric, then the CLT will ensure convergence of the sampling distribution of the mean, with very reasonable sample sizes (e.g. ~ 20). See e.g. here (https://statistical-engineering.com/clt-summary/clt-bimodal-distribution/) for a nice simulation, starting with a very non-normal, but symmetric, bimodal distribution. So under that symmetry assumption, you might as well have used a paired t-test (which has more power...).\n\n\n\n\nI am in fact curious about why you did not use a paired t-test? If it is because some of your 4 marginal distributions were not normally distributed, that would be incorrect. The only distribution which matters is that of the paired differences (which is often normal “enough”, when the 2 “parent” distributions are skewed). Moreover, depending on your sample sizes (?), and specific non-normality of the paired differences (did you run a normality test?), the CLT could come to your rescue and allow you to use a paired t-test.\n\n\n\n\nAnd if you truly wanted to test medians, w/o any consideration to lack (or not) of normality, then you can use a Sign test (https://en.wikipedia.org/wiki/Sign_test) (available for paired data, and which is basically a binomial test).\n\n\n\n\nSo in the end, I can not see any good reason why you (or other researchers) would ever want to use a WSRt, unless they (and their audience) truly care about the pseudomedian...", "answer_url": "https://stats.stackexchange.com/a/677153", "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-12T23:18:59+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": 677151, "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-12T23:18:59+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "3C2DE467-9902-4F8B-A1EE-C1E5683A293D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3C2DE467-9902-4F8B-A1EE-C1E5683A293D/view-source"}, {"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-12T23:26:54+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "05A3FC9C-D387-42EC-8A32-229030F8C23F", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/05A3FC9C-D387-42EC-8A32-229030F8C23F/view-source"}], "score": 2, "updated_at": "2026-09-12T23:26:54+00:00"}, {"answer_html": "

When we speak of the assumptions of a test, people typically mean the assumptions used to derive the null distribution of the test statistic. If the relevant assumptions hold, that should lead to rejection rates which don't exceed the desired significance level when $H_0$ is true.

\n

For the signed rank test, the distribution-related assumption you're looking for (given, at least for paired data, the set of ranks assigned to the absolute differences) with which you can derive the null distribution of the test statistic would be exchangeability of within-pair labels (so under $H_0$, if $+$ and $-$ signs on the differences are flipped to the opposite sign, the distribution of differences would be unaffected).

\n

Symmetry of differences and independence across differences should be sufficient for distribution-related assumptions under $H_0$ (giving the required exchangeability), albeit this is slightly more than necessary.

\n

One fairly natural way this symmetry would be expected to occur is if the bivariate distribution for pair-members was itself exchangeable, so that for any given pair, say pair $i$, the bivariate distribution of $(Y_{i,1},Y_{i,2})$ would be the same as for $(Y_{i,2},Y_{i,1})$. That is, interchanging the within-pair labels makes no difference. For example: if initial assignment of label 1 and 2 was random, and some treatment was applied to the second pair-members that did nothing at all, you should expect to see such exchangeability of within-pair labels.

\n

One of several problems with the widespread practice of only trying to look at the data you're using in the test (let alone using a formal test) to decide if an assumption — such as symmetry — applies is that the null is very likely not actually true in the population-process your data are drawn from, and that assumption might not be required under the alternative for the test to work well. In this case, symmetry under the alternative is not required for the signed rank test to function correctly. Consequently, the data at hand might not be particularly relevant to an assumption about a counterfactual circumstance.

\n

An example where you could expect symmetry might well apply under $H_0$ but not to apply under $H_1$ is when the original pairs of variables have support on a bounded interval, although there are many more cases where you should reasonably anticipate that scale or shape may change across pairs under the alternative (resulting in loss of symmetry of differences under the alternative, without any harm to significance level). I would not usually be inclined to expect symmetry under the alternative to be the case with these kinds of angular values, for example, although it might not be easy to detect in very small samples.

\n

For example, imagine (in that above treatment scenario) that under a completely absent treatment effect the measured responses of both pair members both have some skewed distribution on positive values but were independent conditional on the pair-index $i$ (independence is stronger than needed here, but simplifies description). The differences would be symmetric about 0, and the null distribution in such a scenario will be as derived. Further, let us say that an effective treatment increases the score by some percentage (with some noise), let's say on average by 15%. Then pair differences will not be symmetric in general but the test still works perfectly well - under this alternative, the test statistic will have larger ('treated $-$ untreated') difference values than under the null, and further, larger absolute differences (and so their ranks) will tend to be more associated with positive signs. If you are under the second scenario you would in larger samples frequently reject symmetry of differences in the data, but that asymmetry is not relevant to when the assumption would need to hold for the test to work.

\n
\n

There are other reasons why you should be wary of the practice of trying to use the sample you're testing to consider assumptions even when they should also apply under the alternative, and why testing them presents some additional concerns. I will discuss a few of the issues.

\n

First, you should not expect assumed models to be perfect descriptions — they are convenient approximations. In practice they almost never hold exactly. The relevant question, then, is not "is this assumption true?" (very likely not) but "is the potential impact of its failure large enough to matter?". That's an issue of a kind of effect size, rather than significance, and tests of assumptions don't answer it. They will miss potentially important effects at small sample sizes (like yours) and will find what you already know to be the case (that the assumption was not exactly true) at large sample size, even if the impact on the properties of the original test was minuscule, leading you to be more relaxed about large effects with small samples and to avoid using a test because of a small effect with a large sample.

\n

Second, there is the fact that the properties of the signed rank test were not derived for the actual testing procedure you're applying: (i) check assumptions on these data, then (ii) conditionally on the outcome of that, either use the original test you had in mind, or do something else. Applying the originally planned test (such as the signed rank test) to such filtered data will no longer have the nominal properties. In short, significance levels and p-values will be different from what they were claimed to be.

\n

(I may add more issues in a later edit).

\n

You may gain the impression that I am suggesting assumptions should be ignored. On the contrary, I believe they require a deal more effort, not less. They need very careful and thoughtful consideration, but with proper care about what is being assumed about which things when, in the context of their potential impact on inference. To consider reasonableness and potential kinds and degree of violation of assumptions, I'd more often be looking at things like expert knowledge, other data, models/theory of the mechanics, including what makes sense for the alternative, and careful consideration of the behaviour of the test under required assumptions each of (i) the null (in particular, available significance levels) and (ii) the alternative (power curves at potential choices of significance level) and violations of them (seeing potential impact on those properties, for example via simulation studies).

\n

At that stage, if it turns out that some properties may be substantively affected by potential violations of assumptions, you're in a position to consider other, more robust analyses (or, given that this consideration occurs before data collection, at study design time) perhaps even different variables or different protocols.

\n

Post hoc examination of assumptions would still be useful as a way of seeing whether the kinds and degrees of violations considered were sufficient, which - if they were not - might then throw doubt on the conclusions (hence the need for care and thoughtful consideration of them).

\n
\n

Assumptions aside, I'd tend to worry a good deal about power here, especially if you're doing multiple testing correction. Effect sizes would likely need to be quite substantial under such conditions. What were your effect sizes of interest at study design stage, and what sample sizes would be needed to reliably detect them?

\n

Is there a particular reason you chose this test? I'd have expected that in relation to variables like these, there should already have been a decent body of work collecting distributional information sufficient to formulate reasonable distributional models - albeit with such small sample sizes I'd be inclined to add some further protection on the significance level if possible (such as using a likelihood ratio type statistic as the basis of a permutation test, perhaps).

\n", "answer_id": 677154, "answer_text": "When we speak of the assumptions of a test, people typically mean the assumptions used to derive the null distribution of the test statistic. If the relevant assumptions hold, that should lead to rejection rates which don't exceed the desired significance level when $H_0$ is true.\n\n\n\n\nFor the signed rank test, the distribution-related assumption you're looking for (given, at least for paired data, the set of ranks assigned to the absolute differences) with which you can derive the null distribution of the test statistic would be exchangeability of within-pair labels (so under $H_0$, if $+$ and $-$ signs on the differences are flipped to the opposite sign, the distribution of differences would be unaffected).\n\n\n\n\nSymmetry of differences and independence across differences should be sufficient for distribution-related assumptions under $H_0$ (giving the required exchangeability), albeit this is slightly more than necessary.\n\n\n\n\nOne fairly natural way this symmetry would be expected to occur is if the bivariate distribution for pair-members was itself exchangeable, so that for any given pair, say pair $i$, the bivariate distribution of $(Y_{i,1},Y_{i,2})$ would be the same as for $(Y_{i,2},Y_{i,1})$. That is, interchanging the within-pair labels makes no difference. For example: if initial assignment of label 1 and 2 was random, and some treatment was applied to the second pair-members that did nothing at all, you should expect to see such exchangeability of within-pair labels.\n\n\n\n\nOne of several problems with the widespread practice of only trying to look at the data you're using in the test (let alone using a formal test) to decide if an assumption — such as symmetry — applies is that the null is very likely not actually true in the population-process your data are drawn from, and that assumption might not be required under the alternative for the test to work well. In this case, symmetry under the alternative is not required for the signed rank test to function correctly. Consequently, the data at hand might not be particularly relevant to an assumption about a counterfactual circumstance.\n\n\n\n\nAn example where you could expect symmetry might well apply under $H_0$ but not to apply under $H_1$ is when the original pairs of variables have support on a bounded interval, although there are many more cases where you should reasonably anticipate that scale or shape may change across pairs under the alternative (resulting in loss of symmetry of differences under the alternative, without any harm to significance level). I would not usually be inclined to expect symmetry under the alternative to be the case with these kinds of angular values, for example, although it might not be easy to detect in very small samples.\n\n\n\n\nFor example, imagine (in that above treatment scenario) that under a completely absent treatment effect the measured responses of both pair members both have some skewed distribution on positive values but were independent conditional on the pair-index $i$ (independence is stronger than needed here, but simplifies description). The differences would be symmetric about 0, and the null distribution in such a scenario will be as derived. Further, let us say that an effective treatment increases the score by some percentage (with some noise), let's say on average by 15%. Then pair differences will not be symmetric in general but the test still works perfectly well - under this alternative, the test statistic will have larger ('treated $-$ untreated') difference values than under the null, and further, larger absolute differences (and so their ranks) will tend to be more associated with positive signs. If you are under the second scenario you would in larger samples frequently reject symmetry of differences in the data, but that asymmetry is not relevant to when the assumption would need to hold for the test to work.\n\n\n\n\n\n\n\nThere are other reasons why you should be wary of the practice of trying to use the sample you're testing to consider assumptions even when they should also apply under the alternative, and why testing them presents some additional concerns. I will discuss a few of the issues.\n\n\n\n\nFirst, you should not expect assumed models to be perfect descriptions — they are convenient approximations. In practice they almost never hold exactly. The relevant question, then, is not \"is this assumption true?\" (very likely not) but \"is the potential impact of its failure large enough to matter?\". That's an issue of a kind of effect size, rather than significance, and tests of assumptions don't answer it. They will miss potentially important effects at small sample sizes (like yours) and will find what you already know to be the case (that the assumption was not exactly true) at large sample size, even if the impact on the properties of the original test was minuscule, leading you to be more relaxed about large effects with small samples and to avoid using a test because of a small effect with a large sample.\n\n\n\n\nSecond, there is the fact that the properties of the signed rank test were not derived for the actual testing procedure you're applying: (i) check assumptions on these data, then (ii) conditionally on the outcome of that, either use the original test you had in mind, or do something else. Applying the originally planned test (such as the signed rank test) to such filtered data will no longer have the nominal properties. In short, significance levels and p-values will be different from what they were claimed to be.\n\n\n\n\n(I may add more issues in a later edit).\n\n\n\n\nYou may gain the impression that I am suggesting assumptions should be ignored. On the contrary, I believe they require a deal more effort, not less. They need very careful and thoughtful consideration, but with proper care about what is being assumed about which things when, in the context of their potential impact on inference. To consider reasonableness and potential kinds and degree of violation of assumptions, I'd more often be looking at things like expert knowledge, other data, models/theory of the mechanics, including what makes sense for the alternative, and careful consideration of the behaviour of the test under required assumptions each of (i) the null (in particular, available significance levels) and (ii) the alternative (power curves at potential choices of significance level) and violations of them (seeing potential impact on those properties, for example via simulation studies).\n\n\n\n\nAt that stage, if it turns out that some properties may be substantively affected by potential violations of assumptions, you're in a position to consider other, more robust analyses (or, given that this consideration occurs before data collection, at study design time) perhaps even different variables or different protocols.\n\n\n\n\nPost hoc examination of assumptions would still be useful as a way of seeing whether the kinds and degrees of violations considered were sufficient, which - if they were not - might then throw doubt on the conclusions (hence the need for care and thoughtful consideration of them).\n\n\n\n\n\n\n\nAssumptions aside, I'd tend to worry a good deal about power here, especially if you're doing multiple testing correction. Effect sizes would likely need to be quite substantial under such conditions. What were your effect sizes of interest at study design stage, and what sample sizes would be needed to reliably detect them?\n\n\n\n\nIs there a particular reason you chose this test? I'd have expected that in relation to variables like these, there should already have been a decent body of work collecting distributional information sufficient to formulate reasonable distributional models - albeit with such small sample sizes I'd be inclined to add some further protection on the significance level if possible (such as using a likelihood ratio type statistic as the basis of a permutation test, perhaps).", "answer_url": "https://stats.stackexchange.com/a/677154", "author": "Glen_b", "author_url": "https://stats.stackexchange.com/users/805/glen-b", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-12T23:43:30+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": 677151, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-12T23:43:30+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "62F12774-D8F8-4C82-9461-0081EA3B7680", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/62F12774-D8F8-4C82-9461-0081EA3B7680/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-12T23:50:43+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "23E95A83-7587-40AD-990D-E45001144F34", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/23E95A83-7587-40AD-990D-E45001144F34/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T00:01:28+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "894E8962-A0A1-4552-94AA-FB8358333C6F", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/894E8962-A0A1-4552-94AA-FB8358333C6F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T00:13:51+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "DC825BD9-24E3-4E05-9A2F-F8E8251C3738", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DC825BD9-24E3-4E05-9A2F-F8E8251C3738/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T00:20:22+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "A32BE78F-A0A6-410A-B159-F03158F18817", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A32BE78F-A0A6-410A-B159-F03158F18817/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T00:59:43+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "A633813B-2768-4A48-A63B-259C6FD3575A", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A633813B-2768-4A48-A63B-259C6FD3575A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T01:06:57+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7BE0590E-5BEE-462F-80F5-56379C6713FC", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7BE0590E-5BEE-462F-80F5-56379C6713FC/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T01:29:01+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "0007ADE3-CBEE-4726-95D9-D1189607D258", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0007ADE3-CBEE-4726-95D9-D1189607D258/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T01:39:01+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "E13B98B9-3EFE-4971-8B4B-9B3A61073C6C", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E13B98B9-3EFE-4971-8B4B-9B3A61073C6C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T01:44:18+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "CB56B979-81DB-4905-8209-F8457366027B", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CB56B979-81DB-4905-8209-F8457366027B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T07:33:41+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "9774D478-72F8-4E04-86F1-C604C00BF2D6", "revision_number": 11, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/9774D478-72F8-4E04-86F1-C604C00BF2D6/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-13T23:26:32+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7BAB854F-462C-49BB-85A2-0D8E40A6D942", "revision_number": 12, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7BAB854F-462C-49BB-85A2-0D8E40A6D942/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-14T04:27:44+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "150B68AD-1C1F-45FE-B721-E0451567395E", "revision_number": 13, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/150B68AD-1C1F-45FE-B721-E0451567395E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Glen_b", "profile_url": "https://stats.stackexchange.com/users/805/glen-b", "user_type": "registered"}, "created_at": "2026-09-15T10:27:52+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B6854EBE-3BF4-4571-BFB2-9C476D2160F0", "revision_number": 14, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B6854EBE-3BF4-4571-BFB2-9C476D2160F0/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-15T15:01:34+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "E99122AD-481E-4371-BF94-D061728520D9", "revision_number": 15, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E99122AD-481E-4371-BF94-D061728520D9/view-source"}], "score": 4, "updated_at": "2026-09-15T15:01:34+00:00"}, {"answer_html": "

The signed-rank test, as said by others, requires a symmetry assumption. Also it is not invariant to transformations of the variable. For those reasons I consider the signed-rank test as obsolete and always use Kornbrot's rank difference test as exemplified here.

\n

Regarding assumptions of the Wilcoxon test (original and rank difference version) it doesn't assume anything in terms of giving the right answer about which group has better outcomes. But for Wilcoxon to have optimum power, the proportional odds assumption must hold.

\n", "answer_id": 677160, "answer_text": "The signed-rank test, as said by others, requires a symmetry assumption. Also it is not invariant to transformations of the variable. For those reasons I consider the signed-rank test as obsolete and always use Kornbrot's rank difference test as exemplified here (https://hbiostat.org/bbr/nonpar).\n\n\n\n\nRegarding assumptions of the Wilcoxon test (original and rank difference version) it doesn't assume anything in terms of giving the right answer about which group has better outcomes. But for Wilcoxon to have optimum power, the proportional odds assumption must hold (https://fharrell.com/post/powilcoxon).", "answer_url": "https://stats.stackexchange.com/a/677160", "author": "Frank Harrell", "author_url": "https://stats.stackexchange.com/users/4253/frank-harrell", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-13T13:03:32+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": 677151, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Frank Harrell", "profile_url": "https://stats.stackexchange.com/users/4253/frank-harrell", "user_type": "registered"}, "created_at": "2026-09-13T13:03:32+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "4F4DF722-93BC-48C5-921A-5B46CA5F5750", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4F4DF722-93BC-48C5-921A-5B46CA5F5750/view-source"}], "score": 4, "updated_at": "2026-09-13T13:03:32+00:00"}], "domain": "statistics", "external_links": ["https://en.wikipedia.org/wiki/Hodges%E2%80%93Lehmann_estimator", "https://en.wikipedia.org/wiki/Pseudomedian", "https://en.wikipedia.org/wiki/Sign_test", "https://fharrell.com/post/powilcoxon", "https://hbiostat.org/bbr/nonpar", "https://i.sstatic.net/AqvWf28J.png", "https://i.sstatic.net/wMwItQY8.png", "https://statistical-engineering.com/clt-summary/clt-bimodal-distribution/"], "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 Kojar", "question_author_url": "https://stats.stackexchange.com/users/66533/thomas-kojar", "question_author_user_type": "registered", "question_created_at": "2026-09-12T19:45:10+00:00", "question_html": "

We are trying to ensure that we satisfy the assumptions for Wilcoxon. We have the 15 healthy subjects doing basic movements using sensors and markers, with and without compensation i.e. mimicking unhealthy subjects. For example, they do a movement A (shoulder adduction/abduction) with and without any hiking of the shoulder.

\n

We simply want to show that we properly detect (forced) compensation

\n

Our data point for ith subject is X_i= ROM_with compensation minus ROM_without compensation. So I think we do have independence.

\n

\"enter

\n

For the symmetry assumption, the data points were ordered around their median as required by the test by having a p-value bigger than 0.05.

\n

\"enter

\n", "question_id": 677151, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "We are trying to ensure that we satisfy the assumptions for Wilcoxon. We have the 15 healthy subjects doing basic movements using sensors and markers, with and without compensation i.e. mimicking unhealthy subjects. For example, they do a movement A (shoulder adduction/abduction) with and without any hiking of the shoulder.\n\n\n\n\nWe simply want to show that we properly detect (forced) compensation\n\n\n\n\nOur data point for ith subject is X_i= ROM_with compensation minus ROM_without compensation. So I think we do have independence.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/wMwItQY8.png] (https://i.sstatic.net/wMwItQY8.png)\n\n\n\n\nFor the symmetry assumption, the data points were ordered around their median as required by the test by having a p-value bigger than 0.05.\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/AqvWf28J.png] (https://i.sstatic.net/AqvWf28J.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Thomas Kojar", "profile_url": "https://stats.stackexchange.com/users/66533/thomas-kojar", "user_type": "registered"}, "created_at": "2026-09-12T19:45:10+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "C6F0AF68-DF30-4C89-B624-2608F0C7F39A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C6F0AF68-DF30-4C89-B624-2608F0C7F39A/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-14T10:21:19+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "BB53ACFD-4DF9-4BCE-AF37-983C54CF95BC", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/BB53ACFD-4DF9-4BCE-AF37-983C54CF95BC/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677151/wilcoxon-test-assumptions", "split": "train", "split_group": "4607dc17a6b552ad0cbb77305f2d9dbb6a85532ce9c286c2669c4d9f80252ccf", "tags": ["wilcoxon-signed-rank", "bonferroni"], "thread_id": "stats:677151", "title": "Wilcoxon test assumptions"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

I do think you have way more than 3 replicates. Each cell you observed is an independent observation: yes, they may come from the same preparation/flask/dish/??, but they are different cells, which while prepared under the same conditions, are nevertheless different and independent observations. Thus, you in fact have a very large sample size.

\n

Your scenario is that of a 2-way Anova. You have 2 categorical factors: the drug concentration, and the source of the cells. And you observed every combination of these 2 factors, and have a lot (“thousands”) of observations for each of these combinations. You could also describe your scenario as a full factorial design (same engine under the hood. And that engine is a regression).
\nNow, for a 2-way Anova/factorial design, it is the residuals which need to be “not too non-normal”. Will that be the case with your data? Hard to tell from the plots, but it is often the case that marginal distributions which appear quite skewed end up giving you normal-ish residuals: you can find such examples here on CV, or here.

\n

Now, this ANOVA may tell you that the culture to culture variability has more effect than the drug concentration... And that would be a problem as you could not generalize your findings. But if the drug is mainly responsible for the effect, then you have something...

\n

But what if your residuals are also very non-normal?

\n

There were some suggestions for you to use the log of your response (fluorescence intensity). I am not (at all?) convinced that it would be a good idea. For one, what you are interested in (binding ability of antibodies) is strictly linear with the fluorescence intensity: twice the binding results in twice the observed fluorescence intensity. So using the log does not correspond to any biological or physical property of the phenomenon you are investigating. In addition, if you observe (or fail to observe) a statistically significant difference on the log of the intensity, it absolutely does not mean that you would have had the same significant (or not) result on the original intensity (because a log transformation compresses the data, hence reduces the differences, but also reduces the variability. Hence, you can not extrapolate a result on the logs to a result on the original data).
\nNote also that running some regression (e.g. mixed effects) would have the same issue with non-normal residuals (for the p-values of your regression to be valid, the residuals here too need to be “normal-ish”).

\n

Now, depending on what you will do with the results of your analysis, you could simply use the IOTT (Inter Ocular Trauma Test) (see here: when the answer hits you between the eyes. It should be clear that one preparation (HO163) behaves radically differently from the other 2. And it may be that this is all you need to make your decision?

\n

If the IOTT does not serve your purpose, you can then fall back on non-parametric tests. Again, with the large sample sizes you have, you should have good power.
\nOne could use a Kruskal-Wallis test (KWt). You could compare all possible combinations to each others, or some subset. But the KWt has a few flaws: one is that it requires homoscedasticity of the marginal distributions, and that does not look at all to be your case (heteroscedasticity leads to Type I error inflation). It also suffers from being affected by circularity (the KWt tests for stochastic superiority, and that property is not transitive: see this paper for an excellent discussion).
\nSo I would rather use a series of Mann-Whitney U tests (MWUt): a series (as opposed to all possible comparisons) to reduce the effect of multiple comparisons corrections (MCC), and because you are mostly interested in the comparison to the control situation. Note that the MWUt also has issues with heteroscedasticity, but it has a version, the Brunner-Munzel test (BMt) which does not require homoscedasticity (see this paper).
\nYou could also use a median test: it supports comparing multiple samples, and makes no distributional (or other such) assumption (it is basically a binomial test). Again, with your large sample sizes, it should have good power. Use the median test as an omnibus test, and then make only the paired comparisons you are truly interested in (to reduce the impact of the MCC).

\n

Just to be safe, let me point out that the various tests I mentioned here test different nulls: 2-way Anova tests equality of the means, MWUt and KWt test stochastic homogeneity, and the median test tests equality of the medians (and the IOTT tests your visual acuity?). So you will need to formulate your conclusions accordingly.

\n", "answer_id": 677197, "answer_text": "I do think you have way more than 3 replicates. Each cell you observed is an independent observation: yes, they may come from the same preparation/flask/dish/??, but they are different cells, which while prepared under the same conditions, are nevertheless different and independent observations. Thus, you in fact have a very large sample size.\n\n\n\n\nYour scenario is that of a 2-way Anova. You have 2 categorical factors: the drug concentration, and the source of the cells. And you observed every combination of these 2 factors, and have a lot (“thousands”) of observations for each of these combinations. You could also describe your scenario as a full factorial design (same engine under the hood. And that engine is a regression).\n\nNow, for a 2-way Anova/factorial design, it is the residuals which need to be “not too non-normal”. Will that be the case with your data? Hard to tell from the plots, but it is often the case that marginal distributions which appear quite skewed end up giving you normal-ish residuals: you can find such examples here on CV (https://stats.stackexchange.com/a/33320/380096), or here (https://www.youtube.com/watch?v=1ft8v7PlNKQ).\n\n\n\n\nNow, this ANOVA may tell you that the culture to culture variability has more effect than the drug concentration... And that would be a problem as you could not generalize your findings. But if the drug is mainly responsible for the effect, then you have something...\n\n\n\n\nBut what if your residuals are also very non-normal?\n\n\n\n\nThere were some suggestions for you to use the log of your response (fluorescence intensity). I am not (at all?) convinced that it would be a good idea. For one, what you are interested in (binding ability of antibodies) is strictly linear with the fluorescence intensity: twice the binding results in twice the observed fluorescence intensity. So using the log does not correspond to any biological or physical property of the phenomenon you are investigating. In addition, if you observe (or fail to observe) a statistically significant difference on the log of the intensity, it absolutely does not mean that you would have had the same significant (or not) result on the original intensity (because a log transformation compresses the data, hence reduces the differences, but also reduces the variability. Hence, you can not extrapolate a result on the logs to a result on the original data).\n\nNote also that running some regression (e.g. mixed effects) would have the same issue with non-normal residuals (for the p-values of your regression to be valid, the residuals here too need to be “normal-ish”).\n\n\n\n\nNow, depending on what you will do with the results of your analysis, you could simply use the IOTT (Inter Ocular Trauma Test) (see here (https://www.r-bloggers.com/2016/11/inter-ocular-trauma-test/): when the answer hits you between the eyes. It should be clear that one preparation (HO163) behaves radically differently from the other 2. And it may be that this is all you need to make your decision?\n\n\n\n\nIf the IOTT does not serve your purpose, you can then fall back on non-parametric tests. Again, with the large sample sizes you have, you should have good power. \n\nOne could use a Kruskal-Wallis test (KWt). You could compare all possible combinations to each others, or some subset. But the KWt has a few flaws: one is that it requires homoscedasticity of the marginal distributions, and that does not look at all to be your case (heteroscedasticity leads to Type I error inflation). It also suffers from being affected by circularity (the KWt tests for stochastic superiority, and that property is not transitive: see this paper (https://www.semanticscholar.org/paper/Kruskal%E2%80%93Wallis%2C-Multiple-Comparisons-and-Efron-Dice-Brown-Hettmansperger/6d6866ffb4ad03cef4c46a044ab096c498d09567) for an excellent discussion).\n\nSo I would rather use a series of Mann-Whitney U tests (MWUt): a series (as opposed to all possible comparisons) to reduce the effect of multiple comparisons corrections (MCC), and because you are mostly interested in the comparison to the control situation. Note that the MWUt also has issues with heteroscedasticity, but it has a version, the Brunner-Munzel test (BMt) which does not require homoscedasticity (see this paper (https://journals.sagepub.com/doi/full/10.1177/2515245921999602)).\n\nYou could also use a median test (https://en.wikipedia.org/wiki/Median_test): it supports comparing multiple samples, and makes no distributional (or other such) assumption (it is basically a binomial test). Again, with your large sample sizes, it should have good power. Use the median test as an omnibus test, and then make only the paired comparisons you are truly interested in (to reduce the impact of the MCC).\n\n\n\n\nJust to be safe, let me point out that the various tests I mentioned here test different nulls: 2-way Anova tests equality of the means, MWUt and KWt test stochastic homogeneity, and the median test tests equality of the medians (and the IOTT tests your visual acuity?). So you will need to formulate your conclusions accordingly.", "answer_url": "https://stats.stackexchange.com/a/677197", "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-17T20:11:08+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": 677168, "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-17T20:11:08+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "0598B5D3-6667-41E6-AD00-022541F50453", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0598B5D3-6667-41E6-AD00-022541F50453/view-source"}, {"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-18T22:54:22+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "6D155F63-4414-4C5B-86F7-B3F496416B99", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6D155F63-4414-4C5B-86F7-B3F496416B99/view-source"}, {"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-18T23:11:40+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "31636490-35B8-4E12-AE63-2EB28805B1F8", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/31636490-35B8-4E12-AE63-2EB28805B1F8/view-source"}, {"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-18T23:26:40+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "FDBE9BC2-7381-46F3-9F5B-0A074D4850E5", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FDBE9BC2-7381-46F3-9F5B-0A074D4850E5/view-source"}], "score": 0, "updated_at": "2026-09-18T23:26:40+00:00"}, {"answer_html": "

The answer from @MichaelLew (+1) nicely gets to the main points. Here are a few extra thoughts that are more than can fit into comments.

\n

First, single-cell fluorescence data typically are log transformed before analysis. Even in the range where fluorescence intensity is proportional to the number of fluorescent molecules, a cellular protein that is labeled with a fluorescent marker often has something close to a log-normal distribution among the individual cells. See, for example, the Wikipedia entry on transformations of flow cytometry data. Your data seem consistent with such a distribution.

\n

Second, "correct" practice would treat your situation as having 3 biological replicates with many technical replicates each. See the Technical Perspective in Molecular Biology of the Cell by D.A., T.D., and K.S. Pollard. A possible exception would be if the distribution among cells was of primary interest, but even then you would need biological replicates to convince your audience of your conclusions (and, I hope, yourself).

\n

Third, there are at least three major ways to handle highly skewed outcome data that have something close to a log-normal distribution.

\n
    \n
  • Do a log transformation and model the means of the log-transformed values. That seems to be the favorite among cellular and molecular biologists. As the simplest to explain to your audience, it would be my choice provided that the transformation led to reasonably symmetric distributions of the observations within each batch/treatment combination.

    \n
  • \n
  • Fit a generalized linear model with a logarithmic link function. That models the logs of the mean values instead.

    \n
  • \n
  • Use ordinal regression, which you can think of as an extension of "Kruskal-Wallis or similar" that can accommodate multiple predictors in regression models. That trades off assumptions about the distribution of outcome values for an assumption about how predictors are associated with increasing ranks of outcome values. Frank Harrell provides extensive resources for that approach. I have used it for single-cell fluorescence data, although I don't think it has come into frequent current use in cellular/molecular biology. I'd suggest learning more about its possibilities, as it can be applied widely.

    \n
  • \n
\n

Fourth, a mixed model is one way to handle a combination of biological and technical replicates. Your suggestion of a (1|cell) random-effect term, however, is not correct in your situation. Think of the "random effects" as the groups within which the observations are clustered. With only one observation per cell, those groups would be the 3 batches (perhaps also the images within the batches). A (1|cell) term would be correct if you had multiple observations over time on the same cells.

\n

The problem is that mixed models typically aren't recommended with fewer than 6-10 groups. You only have 3 batches of fungi. One might instead use a fixed-effect term for the batches, if you want to build a model of the individual observations that takes batch-to-batch differences into account.

\n

Finally, there are several tool sets for post-modeling comparisons of all against all or of each treatment against control. I find the emmeans package to be comprehensive and well documented. As @MichaelLew notes, you should document the dose-response curve.

\n", "answer_id": 677209, "answer_text": "The answer from @MichaelLew (+1) nicely gets to the main points. Here are a few extra thoughts that are more than can fit into comments.\n\n\n\n\nFirst, single-cell fluorescence data typically are log transformed before analysis. Even in the range where fluorescence intensity is proportional to the number of fluorescent molecules, a cellular protein that is labeled with a fluorescent marker often has something close to a log-normal distribution among the individual cells. See, for example, the Wikipedia entry on transformations of flow cytometry data (https://en.wikipedia.org/wiki/Flow_cytometry_bioinformatics#Transformation). Your data seem consistent with such a distribution.\n\n\n\n\nSecond, \"correct\" practice would treat your situation as having 3 biological replicates with many technical replicates each. See the Technical Perspective in Molecular Biology of the Cell (https://doi.org/10.1091/mbc.E15-02-0076) by D.A., T.D., and K.S. Pollard. A possible exception would be if the distribution among cells was of primary interest, but even then you would need biological replicates to convince your audience of your conclusions (and, I hope, yourself).\n\n\n\n\nThird, there are at least three major ways to handle highly skewed outcome data that have something close to a log-normal distribution.\n\n\n\n\n\n\n\nDo a log transformation and model the means of the log-transformed values. That seems to be the favorite among cellular and molecular biologists. As the simplest to explain to your audience, it would be my choice provided that the transformation led to reasonably symmetric distributions of the observations within each batch/treatment combination.\n\n\n\n\n\n\n\n\n\nFit a generalized linear model (https://stats.stackexchange.com/tags/generalized-linear-model/info) with a logarithmic link function. That models the logs of the mean values instead.\n\n\n\n\n\n\n\n\n\nUse ordinal regression (https://en.wikipedia.org/wiki/Ordinal_regression), which you can think of as an extension of \"Kruskal-Wallis or similar\" that can accommodate multiple predictors in regression models. That trades off assumptions about the distribution of outcome values for an assumption about how predictors are associated with increasing ranks of outcome values. Frank Harrell provides extensive resources (https://www.fharrell.com/post/rpo/) for that approach. I have used it for single-cell fluorescence data, although I don't think it has come into frequent current use in cellular/molecular biology. I'd suggest learning more about its possibilities, as it can be applied widely.\n\n\n\n\n\n\n\n\nFourth, a mixed model is one way to handle a combination of biological and technical replicates. Your suggestion of a (1|cell) random-effect term, however, is not correct in your situation. Think of the \"random effects\" as the groups within which the observations are clustered. With only one observation per cell, those groups would be the 3 batches (perhaps also the images within the batches). A (1|cell) term would be correct if you had multiple observations over time on the same cells.\n\n\n\n\nThe problem is that mixed models typically aren't recommended with fewer than 6-10 groups (https://stats.stackexchange.com/q/37647/28500). You only have 3 batches of fungi. One might instead use a fixed-effect term for the batches, if you want to build a model of the individual observations that takes batch-to-batch differences into account.\n\n\n\n\nFinally, there are several tool sets for post-modeling comparisons of all against all or of each treatment against control. I find the emmeans package (https://cran.r-project.org/package=emmeans) to be comprehensive and well documented. As @MichaelLew notes, you should document the dose-response curve.", "answer_url": "https://stats.stackexchange.com/a/677209", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-18T15:52:12+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": 677168, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-18T15:52:12+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "7BF0827F-A834-4B61-87FF-BAC0D253DA34", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7BF0827F-A834-4B61-87FF-BAC0D253DA34/view-source"}], "score": 3, "updated_at": "2026-09-18T15:52:12+00:00"}], "product": "statistics_qa", "question": "I have performed experiments where I am looking at how treating a fungus with an antifungal drug alters the binding of antibodies through fluorescent microscopy. I captured 4-6 images per conditions, in biological triplicate reps (and thus my n = 3), and performed single-cell analysis to quantify the fluorescence intensity of each cell. For each rep, cells analysed fall in the thousands.\n\n\n\n\nI’ve provided an example graph to show the sort of data I’m looking at. Here, as drug concentration increases, we get a trend of increased intensity ≈ increased binding. The statistical analysis is where I am struggling.\n\n\n\n\nWith only 3 reps (and from the visual distribution of the data) I believe normality assumptions can be thrown out the window so I believe I’ll need to do a non-parametric in some capacity. I also think that the random variation that arises on a cell-cell basis needs to be accounted for; whilst in the plot I’ve shown the means for each biorep, I don't think comparing the means in this case is an appropriate way to analyse the population, given the spread of the data?\n\n\n\n\nI'm working in R for the purpose of this work. The closest I’ve come to what I ‘should’ do is a mixed-effects model, whereby the model would look something like:\nIntensity ~ drug concentration + (1│cell)\n\n\n\n\nHowever, I am not sure exactly if this is an appropriate approach in this instance. Questions I have:\n\n\n\n\ni) Am I over-thinking this and I simply need to just do a Kruskal-wallis or similar?\n\n\n\n\nii) Whilst I’m mostly interested in comparing with control (0 drug), comparing between all is also\ninteresting; how would I approach this for any of the possible options?\n\n\n\n\niii) Is trying to account for the distribution actually required?\n\n\n\n\n[image: ; source: https://i.sstatic.net/zOGT7c65.png] (https://i.sstatic.net/zOGT7c65.png)\n\n\n\n\n\n\n\n\n\n\nEDIT 22/09/26\n\n\n\n\nI've looked at log of the data, and just providing an example here for those interested. I do think you would argue in this instance that the difference is clear, and whilst I would probably be happy with that I am certain my supervisor would at least want some statistical analysis that may suggest significant statistically speaking.\n\n\n\n\n(For those interested, we have seen a level of biological significance of the changes we are seeing here, so whether it actually matters if there is a 'statistical' significance is probably by-the-by. Nonetheless, big boss likes seeing a p value :/ )\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/opGUh8A4.png] (https://i.sstatic.net/opGUh8A4.png)", "record_id": "Scientific-Statistics-QA:stats:677168", "selected_answer": {"answer_html": "

(i) Yes, I think that you are over-thinking it. If you plot the data with a logarithmic scale for the fluorescence density you will very likely find that the does-response relationship is sufficiently clear that no statistical analysis is going to be needed. If you want to test the hypothesis that the drug can increase antibody binding then a clear dose-response relationship should be enough evidence to accept the biological hypothesis even without any test of a statistical hypothesis.

\n

(ii) On the other hand, you might want to characterise the relationship between drug concentration and effect, and the usual ways to do that also involve a dose-response relationship by way of finding the range of the effect (i.e. maximal effect of a maximally- or supramaximally-effective concentration of the drug) and the EC50 which is the concentration of the drug needed to elicit a half-maximal response. Those things are typically done by way of fitting a curve through the data. For those things your range of tested concentrations and number of replications might be a bit limited, but plot the curve and see how it looks before deciding on how to proceed (with a new experiment, perhaps).

\n

(iii) Yes, if there is a bad mismatch between the statistical model's version of population distribution and the real data distribution then there can be problems, particularly with small sample size. Using the logarithm of the fluorescence density as your measures is, in a way, taking the distribution into account. (There are many situations where a log-transform of biological data makes things clearer and is, at least arguably, 'natural'. See here: When are Log scales appropriate?)

\n", "answer_id": 677172, "answer_text": "(i) Yes, I think that you are over-thinking it. If you plot the data with a logarithmic scale for the fluorescence density you will very likely find that the does-response relationship is sufficiently clear that no statistical analysis is going to be needed. If you want to test the hypothesis that the drug can increase antibody binding then a clear dose-response relationship should be enough evidence to accept the biological hypothesis even without any test of a statistical hypothesis.\n\n\n\n\n(ii) On the other hand, you might want to characterise the relationship between drug concentration and effect, and the usual ways to do that also involve a dose-response relationship by way of finding the range of the effect (i.e. maximal effect of a maximally- or supramaximally-effective concentration of the drug) and the EC50 which is the concentration of the drug needed to elicit a half-maximal response. Those things are typically done by way of fitting a curve through the data. For those things your range of tested concentrations and number of replications might be a bit limited, but plot the curve and see how it looks before deciding on how to proceed (with a new experiment, perhaps).\n\n\n\n\n(iii) Yes, if there is a bad mismatch between the statistical model's version of population distribution and the real data distribution then there can be problems, particularly with small sample size. Using the logarithm of the fluorescence density as your measures is, in a way, taking the distribution into account. (There are many situations where a log-transform of biological data makes things clearer and is, at least arguably, 'natural'. See here: When are Log scales appropriate? (https://stats.stackexchange.com/questions/27951/when-are-log-scales-appropriate))", "answer_url": "https://stats.stackexchange.com/a/677172", "author": "Michael Lew", "author_url": "https://stats.stackexchange.com/users/1679/michael-lew", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-14T20:58:17+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": 677168, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael Lew", "profile_url": "https://stats.stackexchange.com/users/1679/michael-lew", "user_type": "registered"}, "created_at": "2026-09-14T20:58:17+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "0B9C87FB-0EF7-4AD3-A586-F7D58D0D2F8B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0B9C87FB-0EF7-4AD3-A586-F7D58D0D2F8B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-23T09:14:30+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "CFD4CAE3-2F50-4849-84A1-861C28109C75", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CFD4CAE3-2F50-4849-84A1-861C28109C75/view-source"}], "score": 5, "updated_at": "2026-09-23T09:14:30+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

(i) Yes, I think that you are over-thinking it. If you plot the data with a logarithmic scale for the fluorescence density you will very likely find that the does-response relationship is sufficiently clear that no statistical analysis is going to be needed. If you want to test the hypothesis that the drug can increase antibody binding then a clear dose-response relationship should be enough evidence to accept the biological hypothesis even without any test of a statistical hypothesis.

\n

(ii) On the other hand, you might want to characterise the relationship between drug concentration and effect, and the usual ways to do that also involve a dose-response relationship by way of finding the range of the effect (i.e. maximal effect of a maximally- or supramaximally-effective concentration of the drug) and the EC50 which is the concentration of the drug needed to elicit a half-maximal response. Those things are typically done by way of fitting a curve through the data. For those things your range of tested concentrations and number of replications might be a bit limited, but plot the curve and see how it looks before deciding on how to proceed (with a new experiment, perhaps).

\n

(iii) Yes, if there is a bad mismatch between the statistical model's version of population distribution and the real data distribution then there can be problems, particularly with small sample size. Using the logarithm of the fluorescence density as your measures is, in a way, taking the distribution into account. (There are many situations where a log-transform of biological data makes things clearer and is, at least arguably, 'natural'. See here: When are Log scales appropriate?)

\n", "answer_id": 677172, "answer_text": "(i) Yes, I think that you are over-thinking it. If you plot the data with a logarithmic scale for the fluorescence density you will very likely find that the does-response relationship is sufficiently clear that no statistical analysis is going to be needed. If you want to test the hypothesis that the drug can increase antibody binding then a clear dose-response relationship should be enough evidence to accept the biological hypothesis even without any test of a statistical hypothesis.\n\n\n\n\n(ii) On the other hand, you might want to characterise the relationship between drug concentration and effect, and the usual ways to do that also involve a dose-response relationship by way of finding the range of the effect (i.e. maximal effect of a maximally- or supramaximally-effective concentration of the drug) and the EC50 which is the concentration of the drug needed to elicit a half-maximal response. Those things are typically done by way of fitting a curve through the data. For those things your range of tested concentrations and number of replications might be a bit limited, but plot the curve and see how it looks before deciding on how to proceed (with a new experiment, perhaps).\n\n\n\n\n(iii) Yes, if there is a bad mismatch between the statistical model's version of population distribution and the real data distribution then there can be problems, particularly with small sample size. Using the logarithm of the fluorescence density as your measures is, in a way, taking the distribution into account. (There are many situations where a log-transform of biological data makes things clearer and is, at least arguably, 'natural'. See here: When are Log scales appropriate? (https://stats.stackexchange.com/questions/27951/when-are-log-scales-appropriate))", "answer_url": "https://stats.stackexchange.com/a/677172", "author": "Michael Lew", "author_url": "https://stats.stackexchange.com/users/1679/michael-lew", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-14T20:58:17+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": 677168, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael Lew", "profile_url": "https://stats.stackexchange.com/users/1679/michael-lew", "user_type": "registered"}, "created_at": "2026-09-14T20:58:17+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "0B9C87FB-0EF7-4AD3-A586-F7D58D0D2F8B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0B9C87FB-0EF7-4AD3-A586-F7D58D0D2F8B/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-23T09:14:30+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "CFD4CAE3-2F50-4849-84A1-861C28109C75", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CFD4CAE3-2F50-4849-84A1-861C28109C75/view-source"}], "score": 5, "updated_at": "2026-09-23T09:14:30+00:00"}, {"answer_html": "

I do think you have way more than 3 replicates. Each cell you observed is an independent observation: yes, they may come from the same preparation/flask/dish/??, but they are different cells, which while prepared under the same conditions, are nevertheless different and independent observations. Thus, you in fact have a very large sample size.

\n

Your scenario is that of a 2-way Anova. You have 2 categorical factors: the drug concentration, and the source of the cells. And you observed every combination of these 2 factors, and have a lot (“thousands”) of observations for each of these combinations. You could also describe your scenario as a full factorial design (same engine under the hood. And that engine is a regression).
\nNow, for a 2-way Anova/factorial design, it is the residuals which need to be “not too non-normal”. Will that be the case with your data? Hard to tell from the plots, but it is often the case that marginal distributions which appear quite skewed end up giving you normal-ish residuals: you can find such examples here on CV, or here.

\n

Now, this ANOVA may tell you that the culture to culture variability has more effect than the drug concentration... And that would be a problem as you could not generalize your findings. But if the drug is mainly responsible for the effect, then you have something...

\n

But what if your residuals are also very non-normal?

\n

There were some suggestions for you to use the log of your response (fluorescence intensity). I am not (at all?) convinced that it would be a good idea. For one, what you are interested in (binding ability of antibodies) is strictly linear with the fluorescence intensity: twice the binding results in twice the observed fluorescence intensity. So using the log does not correspond to any biological or physical property of the phenomenon you are investigating. In addition, if you observe (or fail to observe) a statistically significant difference on the log of the intensity, it absolutely does not mean that you would have had the same significant (or not) result on the original intensity (because a log transformation compresses the data, hence reduces the differences, but also reduces the variability. Hence, you can not extrapolate a result on the logs to a result on the original data).
\nNote also that running some regression (e.g. mixed effects) would have the same issue with non-normal residuals (for the p-values of your regression to be valid, the residuals here too need to be “normal-ish”).

\n

Now, depending on what you will do with the results of your analysis, you could simply use the IOTT (Inter Ocular Trauma Test) (see here: when the answer hits you between the eyes. It should be clear that one preparation (HO163) behaves radically differently from the other 2. And it may be that this is all you need to make your decision?

\n

If the IOTT does not serve your purpose, you can then fall back on non-parametric tests. Again, with the large sample sizes you have, you should have good power.
\nOne could use a Kruskal-Wallis test (KWt). You could compare all possible combinations to each others, or some subset. But the KWt has a few flaws: one is that it requires homoscedasticity of the marginal distributions, and that does not look at all to be your case (heteroscedasticity leads to Type I error inflation). It also suffers from being affected by circularity (the KWt tests for stochastic superiority, and that property is not transitive: see this paper for an excellent discussion).
\nSo I would rather use a series of Mann-Whitney U tests (MWUt): a series (as opposed to all possible comparisons) to reduce the effect of multiple comparisons corrections (MCC), and because you are mostly interested in the comparison to the control situation. Note that the MWUt also has issues with heteroscedasticity, but it has a version, the Brunner-Munzel test (BMt) which does not require homoscedasticity (see this paper).
\nYou could also use a median test: it supports comparing multiple samples, and makes no distributional (or other such) assumption (it is basically a binomial test). Again, with your large sample sizes, it should have good power. Use the median test as an omnibus test, and then make only the paired comparisons you are truly interested in (to reduce the impact of the MCC).

\n

Just to be safe, let me point out that the various tests I mentioned here test different nulls: 2-way Anova tests equality of the means, MWUt and KWt test stochastic homogeneity, and the median test tests equality of the medians (and the IOTT tests your visual acuity?). So you will need to formulate your conclusions accordingly.

\n", "answer_id": 677197, "answer_text": "I do think you have way more than 3 replicates. Each cell you observed is an independent observation: yes, they may come from the same preparation/flask/dish/??, but they are different cells, which while prepared under the same conditions, are nevertheless different and independent observations. Thus, you in fact have a very large sample size.\n\n\n\n\nYour scenario is that of a 2-way Anova. You have 2 categorical factors: the drug concentration, and the source of the cells. And you observed every combination of these 2 factors, and have a lot (“thousands”) of observations for each of these combinations. You could also describe your scenario as a full factorial design (same engine under the hood. And that engine is a regression).\n\nNow, for a 2-way Anova/factorial design, it is the residuals which need to be “not too non-normal”. Will that be the case with your data? Hard to tell from the plots, but it is often the case that marginal distributions which appear quite skewed end up giving you normal-ish residuals: you can find such examples here on CV (https://stats.stackexchange.com/a/33320/380096), or here (https://www.youtube.com/watch?v=1ft8v7PlNKQ).\n\n\n\n\nNow, this ANOVA may tell you that the culture to culture variability has more effect than the drug concentration... And that would be a problem as you could not generalize your findings. But if the drug is mainly responsible for the effect, then you have something...\n\n\n\n\nBut what if your residuals are also very non-normal?\n\n\n\n\nThere were some suggestions for you to use the log of your response (fluorescence intensity). I am not (at all?) convinced that it would be a good idea. For one, what you are interested in (binding ability of antibodies) is strictly linear with the fluorescence intensity: twice the binding results in twice the observed fluorescence intensity. So using the log does not correspond to any biological or physical property of the phenomenon you are investigating. In addition, if you observe (or fail to observe) a statistically significant difference on the log of the intensity, it absolutely does not mean that you would have had the same significant (or not) result on the original intensity (because a log transformation compresses the data, hence reduces the differences, but also reduces the variability. Hence, you can not extrapolate a result on the logs to a result on the original data).\n\nNote also that running some regression (e.g. mixed effects) would have the same issue with non-normal residuals (for the p-values of your regression to be valid, the residuals here too need to be “normal-ish”).\n\n\n\n\nNow, depending on what you will do with the results of your analysis, you could simply use the IOTT (Inter Ocular Trauma Test) (see here (https://www.r-bloggers.com/2016/11/inter-ocular-trauma-test/): when the answer hits you between the eyes. It should be clear that one preparation (HO163) behaves radically differently from the other 2. And it may be that this is all you need to make your decision?\n\n\n\n\nIf the IOTT does not serve your purpose, you can then fall back on non-parametric tests. Again, with the large sample sizes you have, you should have good power. \n\nOne could use a Kruskal-Wallis test (KWt). You could compare all possible combinations to each others, or some subset. But the KWt has a few flaws: one is that it requires homoscedasticity of the marginal distributions, and that does not look at all to be your case (heteroscedasticity leads to Type I error inflation). It also suffers from being affected by circularity (the KWt tests for stochastic superiority, and that property is not transitive: see this paper (https://www.semanticscholar.org/paper/Kruskal%E2%80%93Wallis%2C-Multiple-Comparisons-and-Efron-Dice-Brown-Hettmansperger/6d6866ffb4ad03cef4c46a044ab096c498d09567) for an excellent discussion).\n\nSo I would rather use a series of Mann-Whitney U tests (MWUt): a series (as opposed to all possible comparisons) to reduce the effect of multiple comparisons corrections (MCC), and because you are mostly interested in the comparison to the control situation. Note that the MWUt also has issues with heteroscedasticity, but it has a version, the Brunner-Munzel test (BMt) which does not require homoscedasticity (see this paper (https://journals.sagepub.com/doi/full/10.1177/2515245921999602)).\n\nYou could also use a median test (https://en.wikipedia.org/wiki/Median_test): it supports comparing multiple samples, and makes no distributional (or other such) assumption (it is basically a binomial test). Again, with your large sample sizes, it should have good power. Use the median test as an omnibus test, and then make only the paired comparisons you are truly interested in (to reduce the impact of the MCC).\n\n\n\n\nJust to be safe, let me point out that the various tests I mentioned here test different nulls: 2-way Anova tests equality of the means, MWUt and KWt test stochastic homogeneity, and the median test tests equality of the medians (and the IOTT tests your visual acuity?). So you will need to formulate your conclusions accordingly.", "answer_url": "https://stats.stackexchange.com/a/677197", "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-17T20:11:08+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": 677168, "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-17T20:11:08+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "0598B5D3-6667-41E6-AD00-022541F50453", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0598B5D3-6667-41E6-AD00-022541F50453/view-source"}, {"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-18T22:54:22+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "6D155F63-4414-4C5B-86F7-B3F496416B99", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/6D155F63-4414-4C5B-86F7-B3F496416B99/view-source"}, {"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-18T23:11:40+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "31636490-35B8-4E12-AE63-2EB28805B1F8", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/31636490-35B8-4E12-AE63-2EB28805B1F8/view-source"}, {"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-18T23:26:40+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "FDBE9BC2-7381-46F3-9F5B-0A074D4850E5", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FDBE9BC2-7381-46F3-9F5B-0A074D4850E5/view-source"}], "score": 0, "updated_at": "2026-09-18T23:26:40+00:00"}, {"answer_html": "

The answer from @MichaelLew (+1) nicely gets to the main points. Here are a few extra thoughts that are more than can fit into comments.

\n

First, single-cell fluorescence data typically are log transformed before analysis. Even in the range where fluorescence intensity is proportional to the number of fluorescent molecules, a cellular protein that is labeled with a fluorescent marker often has something close to a log-normal distribution among the individual cells. See, for example, the Wikipedia entry on transformations of flow cytometry data. Your data seem consistent with such a distribution.

\n

Second, "correct" practice would treat your situation as having 3 biological replicates with many technical replicates each. See the Technical Perspective in Molecular Biology of the Cell by D.A., T.D., and K.S. Pollard. A possible exception would be if the distribution among cells was of primary interest, but even then you would need biological replicates to convince your audience of your conclusions (and, I hope, yourself).

\n

Third, there are at least three major ways to handle highly skewed outcome data that have something close to a log-normal distribution.

\n
    \n
  • Do a log transformation and model the means of the log-transformed values. That seems to be the favorite among cellular and molecular biologists. As the simplest to explain to your audience, it would be my choice provided that the transformation led to reasonably symmetric distributions of the observations within each batch/treatment combination.

    \n
  • \n
  • Fit a generalized linear model with a logarithmic link function. That models the logs of the mean values instead.

    \n
  • \n
  • Use ordinal regression, which you can think of as an extension of "Kruskal-Wallis or similar" that can accommodate multiple predictors in regression models. That trades off assumptions about the distribution of outcome values for an assumption about how predictors are associated with increasing ranks of outcome values. Frank Harrell provides extensive resources for that approach. I have used it for single-cell fluorescence data, although I don't think it has come into frequent current use in cellular/molecular biology. I'd suggest learning more about its possibilities, as it can be applied widely.

    \n
  • \n
\n

Fourth, a mixed model is one way to handle a combination of biological and technical replicates. Your suggestion of a (1|cell) random-effect term, however, is not correct in your situation. Think of the "random effects" as the groups within which the observations are clustered. With only one observation per cell, those groups would be the 3 batches (perhaps also the images within the batches). A (1|cell) term would be correct if you had multiple observations over time on the same cells.

\n

The problem is that mixed models typically aren't recommended with fewer than 6-10 groups. You only have 3 batches of fungi. One might instead use a fixed-effect term for the batches, if you want to build a model of the individual observations that takes batch-to-batch differences into account.

\n

Finally, there are several tool sets for post-modeling comparisons of all against all or of each treatment against control. I find the emmeans package to be comprehensive and well documented. As @MichaelLew notes, you should document the dose-response curve.

\n", "answer_id": 677209, "answer_text": "The answer from @MichaelLew (+1) nicely gets to the main points. Here are a few extra thoughts that are more than can fit into comments.\n\n\n\n\nFirst, single-cell fluorescence data typically are log transformed before analysis. Even in the range where fluorescence intensity is proportional to the number of fluorescent molecules, a cellular protein that is labeled with a fluorescent marker often has something close to a log-normal distribution among the individual cells. See, for example, the Wikipedia entry on transformations of flow cytometry data (https://en.wikipedia.org/wiki/Flow_cytometry_bioinformatics#Transformation). Your data seem consistent with such a distribution.\n\n\n\n\nSecond, \"correct\" practice would treat your situation as having 3 biological replicates with many technical replicates each. See the Technical Perspective in Molecular Biology of the Cell (https://doi.org/10.1091/mbc.E15-02-0076) by D.A., T.D., and K.S. Pollard. A possible exception would be if the distribution among cells was of primary interest, but even then you would need biological replicates to convince your audience of your conclusions (and, I hope, yourself).\n\n\n\n\nThird, there are at least three major ways to handle highly skewed outcome data that have something close to a log-normal distribution.\n\n\n\n\n\n\n\nDo a log transformation and model the means of the log-transformed values. That seems to be the favorite among cellular and molecular biologists. As the simplest to explain to your audience, it would be my choice provided that the transformation led to reasonably symmetric distributions of the observations within each batch/treatment combination.\n\n\n\n\n\n\n\n\n\nFit a generalized linear model (https://stats.stackexchange.com/tags/generalized-linear-model/info) with a logarithmic link function. That models the logs of the mean values instead.\n\n\n\n\n\n\n\n\n\nUse ordinal regression (https://en.wikipedia.org/wiki/Ordinal_regression), which you can think of as an extension of \"Kruskal-Wallis or similar\" that can accommodate multiple predictors in regression models. That trades off assumptions about the distribution of outcome values for an assumption about how predictors are associated with increasing ranks of outcome values. Frank Harrell provides extensive resources (https://www.fharrell.com/post/rpo/) for that approach. I have used it for single-cell fluorescence data, although I don't think it has come into frequent current use in cellular/molecular biology. I'd suggest learning more about its possibilities, as it can be applied widely.\n\n\n\n\n\n\n\n\nFourth, a mixed model is one way to handle a combination of biological and technical replicates. Your suggestion of a (1|cell) random-effect term, however, is not correct in your situation. Think of the \"random effects\" as the groups within which the observations are clustered. With only one observation per cell, those groups would be the 3 batches (perhaps also the images within the batches). A (1|cell) term would be correct if you had multiple observations over time on the same cells.\n\n\n\n\nThe problem is that mixed models typically aren't recommended with fewer than 6-10 groups (https://stats.stackexchange.com/q/37647/28500). You only have 3 batches of fungi. One might instead use a fixed-effect term for the batches, if you want to build a model of the individual observations that takes batch-to-batch differences into account.\n\n\n\n\nFinally, there are several tool sets for post-modeling comparisons of all against all or of each treatment against control. I find the emmeans package (https://cran.r-project.org/package=emmeans) to be comprehensive and well documented. As @MichaelLew notes, you should document the dose-response curve.", "answer_url": "https://stats.stackexchange.com/a/677209", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-18T15:52:12+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": 677168, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-18T15:52:12+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "7BF0827F-A834-4B61-87FF-BAC0D253DA34", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7BF0827F-A834-4B61-87FF-BAC0D253DA34/view-source"}], "score": 3, "updated_at": "2026-09-18T15:52:12+00:00"}], "domain": "statistics", "external_links": ["https://cran.r-project.org/package=emmeans", "https://doi.org/10.1091/mbc.E15-02-0076", "https://en.wikipedia.org/wiki/Flow_cytometry_bioinformatics#Transformation", "https://en.wikipedia.org/wiki/Median_test", "https://en.wikipedia.org/wiki/Ordinal_regression", "https://i.sstatic.net/opGUh8A4.png", "https://i.sstatic.net/zOGT7c65.png", "https://journals.sagepub.com/doi/full/10.1177/2515245921999602", "https://www.fharrell.com/post/rpo/", "https://www.r-bloggers.com/2016/11/inter-ocular-trauma-test/", "https://www.semanticscholar.org/paper/Kruskal%E2%80%93Wallis%2C-Multiple-Comparisons-and-Efron-Dice-Brown-Hettmansperger/6d6866ffb4ad03cef4c46a044ab096c498d09567", "https://www.youtube.com/watch?v=1ft8v7PlNKQ"], "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": "Harry Osborne", "question_author_url": "https://stats.stackexchange.com/users/516650/harry-osborne", "question_author_user_type": "registered", "question_created_at": "2026-09-14T14:31:44+00:00", "question_html": "

I have performed experiments where I am looking at how treating a fungus with an antifungal drug alters the binding of antibodies through fluorescent microscopy. I captured 4-6 images per conditions, in biological triplicate reps (and thus my n = 3), and performed single-cell analysis to quantify the fluorescence intensity of each cell. For each rep, cells analysed fall in the thousands.

\n

I’ve provided an example graph to show the sort of data I’m looking at. Here, as drug concentration increases, we get a trend of increased intensity ≈ increased binding. The statistical analysis is where I am struggling.

\n

With only 3 reps (and from the visual distribution of the data) I believe normality assumptions can be thrown out the window so I believe I’ll need to do a non-parametric in some capacity. I also think that the random variation that arises on a cell-cell basis needs to be accounted for; whilst in the plot I’ve shown the means for each biorep, I don't think comparing the means in this case is an appropriate way to analyse the population, given the spread of the data?

\n

I'm working in R for the purpose of this work. The closest I’ve come to what I ‘should’ do is a mixed-effects model, whereby the model would look something like:\nIntensity ~ drug concentration + (1│cell)

\n

However, I am not sure exactly if this is an appropriate approach in this instance. Questions I have:

\n

i) Am I over-thinking this and I simply need to just do a Kruskal-wallis or similar?

\n

ii) Whilst I’m mostly interested in comparing with control (0 drug), comparing between all is also\ninteresting; how would I approach this for any of the possible options?

\n

iii) Is trying to account for the distribution actually required?

\n

\"\"

\n
\n
\n

EDIT 22/09/26

\n

I've looked at log of the data, and just providing an example here for those interested. I do think you would argue in this instance that the difference is clear, and whilst I would probably be happy with that I am certain my supervisor would at least want some statistical analysis that may suggest significant statistically speaking.

\n

(For those interested, we have seen a level of biological significance of the changes we are seeing here, so whether it actually matters if there is a 'statistical' significance is probably by-the-by. Nonetheless, big boss likes seeing a p value :/ )

\n

\"enter

\n", "question_id": 677168, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I have performed experiments where I am looking at how treating a fungus with an antifungal drug alters the binding of antibodies through fluorescent microscopy. I captured 4-6 images per conditions, in biological triplicate reps (and thus my n = 3), and performed single-cell analysis to quantify the fluorescence intensity of each cell. For each rep, cells analysed fall in the thousands.\n\n\n\n\nI’ve provided an example graph to show the sort of data I’m looking at. Here, as drug concentration increases, we get a trend of increased intensity ≈ increased binding. The statistical analysis is where I am struggling.\n\n\n\n\nWith only 3 reps (and from the visual distribution of the data) I believe normality assumptions can be thrown out the window so I believe I’ll need to do a non-parametric in some capacity. I also think that the random variation that arises on a cell-cell basis needs to be accounted for; whilst in the plot I’ve shown the means for each biorep, I don't think comparing the means in this case is an appropriate way to analyse the population, given the spread of the data?\n\n\n\n\nI'm working in R for the purpose of this work. The closest I’ve come to what I ‘should’ do is a mixed-effects model, whereby the model would look something like:\nIntensity ~ drug concentration + (1│cell)\n\n\n\n\nHowever, I am not sure exactly if this is an appropriate approach in this instance. Questions I have:\n\n\n\n\ni) Am I over-thinking this and I simply need to just do a Kruskal-wallis or similar?\n\n\n\n\nii) Whilst I’m mostly interested in comparing with control (0 drug), comparing between all is also\ninteresting; how would I approach this for any of the possible options?\n\n\n\n\niii) Is trying to account for the distribution actually required?\n\n\n\n\n[image: ; source: https://i.sstatic.net/zOGT7c65.png] (https://i.sstatic.net/zOGT7c65.png)\n\n\n\n\n\n\n\n\n\n\nEDIT 22/09/26\n\n\n\n\nI've looked at log of the data, and just providing an example here for those interested. I do think you would argue in this instance that the difference is clear, and whilst I would probably be happy with that I am certain my supervisor would at least want some statistical analysis that may suggest significant statistically speaking.\n\n\n\n\n(For those interested, we have seen a level of biological significance of the changes we are seeing here, so whether it actually matters if there is a 'statistical' significance is probably by-the-by. Nonetheless, big boss likes seeing a p value :/ )\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/opGUh8A4.png] (https://i.sstatic.net/opGUh8A4.png)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Harry Osborne", "profile_url": "https://stats.stackexchange.com/users/516650/harry-osborne", "user_type": "registered"}, "created_at": "2026-09-14T14:31:44+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B4E4E7F4-7071-4893-9E17-31B7D6D44405", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B4E4E7F4-7071-4893-9E17-31B7D6D44405/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-14T22:36:45+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "5DA0A189-D1E8-4476-8C1D-0A3B8A85C459", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/5DA0A189-D1E8-4476-8C1D-0A3B8A85C459/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Harry Osborne", "profile_url": "https://stats.stackexchange.com/users/516650/harry-osborne", "user_type": "registered"}, "created_at": "2026-09-22T12:26:16+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "ADB1C3A2-04F4-4A1A-BDAC-63D8A2B7BDCC", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/ADB1C3A2-04F4-4A1A-BDAC-63D8A2B7BDCC/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-23T09:12:01+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "0532E1B5-F622-4E59-A1BE-2C6BD4A2C6DF", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0532E1B5-F622-4E59-A1BE-2C6BD4A2C6DF/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677168/performing-correct-statistical-analysis-on-fluorescent-intensity-data", "split": "train", "split_group": "aeee5d56c55539be690a9261cf07b23e2a6dc49ccc231769c30fea65b2b2a5d9", "tags": ["r", "mixed-model", "statistical-significance", "normality-assumption"], "thread_id": "stats:677168", "title": "Performing 'correct' statistical analysis on fluorescent intensity data"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

You should try one or more kinds of regularizers: e.g. Ridge Regression (L2 penalty on the coefficients) or Lasso Regression (L1 penalties on the coefficients); or some of both together. Playing with the regularization penalties essentially converts your question to a model selection problem. Fit as many things as you like, and the Lasso will zero out the coefficients for the less relevant ones. The more data you have, the more coefficients it makes sense to keep, or the smaller penalties you can use and still get meaningful results. If reducing your penalties a little changes your coefficients much, you should go the other way.

\n", "answer_id": 677198, "answer_text": "You should try one or more kinds of regularizers: e.g. Ridge Regression (L2 penalty on the coefficients) or Lasso Regression (L1 penalties on the coefficients); or some of both together. Playing with the regularization penalties essentially converts your question to a model selection problem. Fit as many things as you like, and the Lasso will zero out the coefficients for the less relevant ones. The more data you have, the more coefficients it makes sense to keep, or the smaller penalties you can use and still get meaningful results. If reducing your penalties a little changes your coefficients much, you should go the other way.", "answer_url": "https://stats.stackexchange.com/a/677198", "author": "Richard Lyon", "author_url": "https://stats.stackexchange.com/users/516789/richard-lyon", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T23:10:31+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": 677169, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Richard Lyon", "profile_url": "https://stats.stackexchange.com/users/516789/richard-lyon", "user_type": "registered"}, "created_at": "2026-09-17T23:10:31+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "725FFA89-6A2B-4A9F-8AA5-26CA4C77EAC1", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/725FFA89-6A2B-4A9F-8AA5-26CA4C77EAC1/view-source"}], "score": 2, "updated_at": "2026-09-17T23:10:31+00:00"}], "product": "statistics_qa", "question": "In my intro to biostats classes I was taught that one shouldn’t adjust for more than 10 variables in a regression model because it would overfit the data. However, what if you were working with a dataset that has for instance 50 variables and around 40 of them are variables that you would adjust for, how would you prevent overfitting?\n\n\n\n\nWould it be okay to adjust for more than 10 variables in the same model?\n\n\n\n\nI would greatly appreciate an easy to understand answer.\n\n\n\n\nMy outcome is either categorical or continuous but I don’t think it matters for the explanation I need.", "record_id": "Scientific-Statistics-QA:stats:677169", "selected_answer": {"answer_html": "

First: That is much too simple a rule. A better rule of thumb is one regressor for every ten observations, so if you have a really big data set, you could use more variables without overfitting.

\n

Second, it does matter whether your outcome is categorical. For categorical outcomes, a common rule of thumb is 10 observations in the least common category for each regressor. This can be much more restrictive, if some categories are rare.

\n

Third, overfitting is not the only problem. When you have many variables, it can be hard to interpret the model. Mathematically, it's straightforward: You're controlling for all the other variables. But what that means, substantively, can be tricky.

\n

Fourth, with a lot of regressors, collinearity is often a problem, at least if you want to interpret the model (it doesn't affect prediction).

\n

Finally, choosing a good model is a huge subject, with many threads here. Browse the model-selection tag for lots of material.

\n", "answer_id": 677170, "answer_text": "First: That is much too simple a rule. A better rule of thumb is one regressor for every ten observations, so if you have a really big data set, you could use more variables without overfitting.\n\n\n\n\nSecond, it does matter whether your outcome is categorical. For categorical outcomes, a common rule of thumb is 10 observations in the least common category for each regressor. This can be much more restrictive, if some categories are rare.\n\n\n\n\nThird, overfitting is not the only problem. When you have many variables, it can be hard to interpret the model. Mathematically, it's straightforward: You're controlling for all the other variables. But what that means, substantively, can be tricky.\n\n\n\n\nFourth, with a lot of regressors, collinearity is often a problem, at least if you want to interpret the model (it doesn't affect prediction).\n\n\n\n\nFinally, choosing a good model is a huge subject, with many threads here. Browse the model-selection tag for lots of material.", "answer_url": "https://stats.stackexchange.com/a/677170", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-14T19:41:01+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": 677169, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-09-14T19:41:01+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "24267A3D-EFFC-4C8A-BBD5-56E85D075DAA", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/24267A3D-EFFC-4C8A-BBD5-56E85D075DAA/view-source"}], "score": 9, "updated_at": "2026-09-14T19:41:01+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

First: That is much too simple a rule. A better rule of thumb is one regressor for every ten observations, so if you have a really big data set, you could use more variables without overfitting.

\n

Second, it does matter whether your outcome is categorical. For categorical outcomes, a common rule of thumb is 10 observations in the least common category for each regressor. This can be much more restrictive, if some categories are rare.

\n

Third, overfitting is not the only problem. When you have many variables, it can be hard to interpret the model. Mathematically, it's straightforward: You're controlling for all the other variables. But what that means, substantively, can be tricky.

\n

Fourth, with a lot of regressors, collinearity is often a problem, at least if you want to interpret the model (it doesn't affect prediction).

\n

Finally, choosing a good model is a huge subject, with many threads here. Browse the model-selection tag for lots of material.

\n", "answer_id": 677170, "answer_text": "First: That is much too simple a rule. A better rule of thumb is one regressor for every ten observations, so if you have a really big data set, you could use more variables without overfitting.\n\n\n\n\nSecond, it does matter whether your outcome is categorical. For categorical outcomes, a common rule of thumb is 10 observations in the least common category for each regressor. This can be much more restrictive, if some categories are rare.\n\n\n\n\nThird, overfitting is not the only problem. When you have many variables, it can be hard to interpret the model. Mathematically, it's straightforward: You're controlling for all the other variables. But what that means, substantively, can be tricky.\n\n\n\n\nFourth, with a lot of regressors, collinearity is often a problem, at least if you want to interpret the model (it doesn't affect prediction).\n\n\n\n\nFinally, choosing a good model is a huge subject, with many threads here. Browse the model-selection tag for lots of material.", "answer_url": "https://stats.stackexchange.com/a/677170", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-14T19:41:01+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": 677169, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-09-14T19:41:01+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "24267A3D-EFFC-4C8A-BBD5-56E85D075DAA", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/24267A3D-EFFC-4C8A-BBD5-56E85D075DAA/view-source"}], "score": 9, "updated_at": "2026-09-14T19:41:01+00:00"}, {"answer_html": "

You should try one or more kinds of regularizers: e.g. Ridge Regression (L2 penalty on the coefficients) or Lasso Regression (L1 penalties on the coefficients); or some of both together. Playing with the regularization penalties essentially converts your question to a model selection problem. Fit as many things as you like, and the Lasso will zero out the coefficients for the less relevant ones. The more data you have, the more coefficients it makes sense to keep, or the smaller penalties you can use and still get meaningful results. If reducing your penalties a little changes your coefficients much, you should go the other way.

\n", "answer_id": 677198, "answer_text": "You should try one or more kinds of regularizers: e.g. Ridge Regression (L2 penalty on the coefficients) or Lasso Regression (L1 penalties on the coefficients); or some of both together. Playing with the regularization penalties essentially converts your question to a model selection problem. Fit as many things as you like, and the Lasso will zero out the coefficients for the less relevant ones. The more data you have, the more coefficients it makes sense to keep, or the smaller penalties you can use and still get meaningful results. If reducing your penalties a little changes your coefficients much, you should go the other way.", "answer_url": "https://stats.stackexchange.com/a/677198", "author": "Richard Lyon", "author_url": "https://stats.stackexchange.com/users/516789/richard-lyon", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T23:10:31+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": 677169, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Richard Lyon", "profile_url": "https://stats.stackexchange.com/users/516789/richard-lyon", "user_type": "registered"}, "created_at": "2026-09-17T23:10:31+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "725FFA89-6A2B-4A9F-8AA5-26CA4C77EAC1", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/725FFA89-6A2B-4A9F-8AA5-26CA4C77EAC1/view-source"}], "score": 2, "updated_at": "2026-09-17T23:10:31+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "ineedhelp", "question_author_url": "https://stats.stackexchange.com/users/328519/ineedhelp", "question_author_user_type": "registered", "question_created_at": "2026-09-14T19:13:21+00:00", "question_html": "

In my intro to biostats classes I was taught that one shouldn’t adjust for more than 10 variables in a regression model because it would overfit the data. However, what if you were working with a dataset that has for instance 50 variables and around 40 of them are variables that you would adjust for, how would you prevent overfitting?

\n

Would it be okay to adjust for more than 10 variables in the same model?

\n

I would greatly appreciate an easy to understand answer.

\n

My outcome is either categorical or continuous but I don’t think it matters for the explanation I need.

\n", "question_id": 677169, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "In my intro to biostats classes I was taught that one shouldn’t adjust for more than 10 variables in a regression model because it would overfit the data. However, what if you were working with a dataset that has for instance 50 variables and around 40 of them are variables that you would adjust for, how would you prevent overfitting?\n\n\n\n\nWould it be okay to adjust for more than 10 variables in the same model?\n\n\n\n\nI would greatly appreciate an easy to understand answer.\n\n\n\n\nMy outcome is either categorical or continuous but I don’t think it matters for the explanation I need.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "ineedhelp", "profile_url": "https://stats.stackexchange.com/users/328519/ineedhelp", "user_type": "registered"}, "created_at": "2026-09-14T19:13:21+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "2972E220-ADB4-4C69-843D-CFAFF417E7A3", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2972E220-ADB4-4C69-843D-CFAFF417E7A3/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-15T03:21:56+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7F9A7C91-F9E9-41BB-B0D1-513212A717A8", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/7F9A7C91-F9E9-41BB-B0D1-513212A717A8/view-source"}, {"content_license": null, "contributor": {"display_name": "Richard Hardy", "profile_url": "https://stats.stackexchange.com/users/53690/richard-hardy", "user_type": "registered"}, "created_at": "2026-09-16T19:18:53+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "A5EF3AEF-D5BC-422F-926A-4E678B350FE2", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A5EF3AEF-D5BC-422F-926A-4E678B350FE2/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677169/how-do-you-prevent-overfitting-regression-models-when-you-adjust-for-more-than-1", "split": "train", "split_group": "be6f130d0b7c65dde44fa26090c83898d7df6a37fcfdcdcf2607652ac5c87a3b", "tags": ["regression", "multiple-regression", "overfitting", "high-dimensional"], "thread_id": "stats:677169", "title": "How do you prevent overfitting regression models when you adjust for more than 10 variables?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "Suppose we have a measurement (a \"response\") as a vector $Y$, that is, a $Y_i$ for $i=1,2,3,...n$ and an estimator of that measurement (a \"predictor\") $X$. Then one can define a proportional (or relative) error as\n\n\n\n\n\n\n\n$\\frac{X-Y}{Y}$, which is the most commonly used definition of proportional error. This assumes that the measured quantity is the proper reference for relative error calculation. It has the property that the proportions become large magnitude for $Y$ in the neighborhood of zero.\n\n\n\n\n\n\n\n\n\n$\\frac{X-Y}{X}$, which is a measure of proportional error that assumes that the predictor quantity is the reference for that relative error calculation. It has the property that the proportions become large magnitude for $X$ in the neighborhood of zero.\n\n\n\n\n\n\n\n\n\n$\\frac{X-Y}{\\left(\\frac{X+Y}{2}\\right)}$ is a measure of proportional error relative to the mean possibly having a better assurance of no inflated magnitude values when $X$ or $Y$ (but not $X$ AND $Y$) and are in the neighborhood of zero. This assumes that there is some error in measuring $Y$ as well as in the estimator $X$. This estimator is similar to the assumptions made on Bland-Altman plotting (https://doi.org/10.1136/bmj.313.7049.106), with the notable difference that Bland-Altman examined absolute error, that is plotting $\\frac{X+Y}{2}$ versus $|{X-Y}|$. Thus, this form of proportional error has some implied value for methods comparisons when we have no clear indication of which method is more reliable. In other words, it is a bit like orthogonal regression (https://en.wikipedia.org/wiki/Deming_regression#Orthogonal_regression), a poor cousin of Deming regression. That is, if we cannot measure the exact variances for two methods, it is in some cases best to assume that both measures have equal variance. This contrasts with 1. and 2. above where we choose whether $Y$ or $X$ is the more appropriate reference.\n\n\n\n\n\n\n\n\nQ: Are there comments on the above or other measures of proportional error worthy of mention?\n\n\n\n\nEdit BTW, there is a non-negativity constraint. The above is useful, for example, for density function modeling of drug concentrations to look for proportional error of regression residuals therein. Statistics for this include mean, standard deviation, distribution of proportional error of residuals, and homoscedasticity of proportional residuals, and others. Another example is that \"so-called\" $1/Y^2$ weighted least squares is proportional modelling because we then are minimizing the L2 norm, that is $\\left\\|\\frac{X-Y}{Y}\\right\\|_2$", "record_id": "Scientific-Statistics-QA:stats:677171", "selected_answer": {"answer_html": "

Not sure whether these are worthy of mention, but here goes.

\n

In the forecasting community, these are typically used with absolute values. (Usually one assumes that the denominator is positive. If the denominator can become zero, interesting gyrations by the error calculator ensue.)

\n

Once we then take averages over multiple pairs $(X_i,Y_i)$, your first alternative turns into the MAPE, which should be avoided.

\n

The second alternative turns into a MAPE-with-the-forecast-in-the-denominator, which has been touted as one way of dealing with actuals that can be zero, as long as the forecast cannot. It can be gamed similarly to the MAPE. Green & Tashman (2009) surveyed practitioners on whether they preferred the regular MAPE or this variant.

\n

The third alternative is known in the forecasting community as the Mean Absolute Symmetric Error (MASE), because it exhibits a particular kind of symmetry, namely of being invariant if forecast and actual are interchanged. That is actually not a kind of symmetry we are very interested in - symmetry with respect to over- and underprediction would be more interesting (Goodwin & Lawson, 1999). The MASE has also been proposed as a way to address possible zero actuals. There happens to be a recent paper (Kolassa, 2026) arguing against it. Yes, it's published in an MDPI journal. I still think it's a worthy point to make... but now we are back to worthiness...

\n

Forecasters also like to look at other kinds of proportional or relative errors, where you calculate an error (MAE or MSE - I don't think MAE is useful) and report it as a proportion either (a) to the mean of the time series itself, or (b) to the error achieved by a benchmark forecasting method. People are divided on whether a (or b) makes sense for nonstationary time series. But b at least immediately shows whether a new forecasting method is better than the benchmark, or not.

\n", "answer_id": 677174, "answer_text": "Not sure whether these are worthy of mention, but here goes.\n\n\n\n\nIn the forecasting community, these are typically used with absolute values. (Usually one assumes that the denominator is positive. If the denominator can become zero, interesting gyrations by the error calculator ensue.)\n\n\n\n\nOnce we then take averages over multiple pairs $(X_i,Y_i)$, your first alternative turns into the MAPE, which should be avoided (https://stats.stackexchange.com/q/299712/1352).\n\n\n\n\nThe second alternative turns into a MAPE-with-the-forecast-in-the-denominator, which has been touted as one way of dealing with actuals that can be zero, as long as the forecast cannot. It can be gamed similarly to the MAPE. Green & Tashman (2009) (https://ideas.repec.org/a/for/ijafaa/y2009i12p36-40.html) surveyed practitioners on whether they preferred the regular MAPE or this variant.\n\n\n\n\nThe third alternative is known in the forecasting community as the Mean Absolute Symmetric Error (MASE), because it exhibits a particular kind of symmetry, namely of being invariant if forecast and actual are interchanged. That is actually not a kind of symmetry we are very interested in - symmetry with respect to over- and underprediction would be more interesting (Goodwin & Lawson, 1999 (https://doi.org/10.1016/S0169-2070(99)00007-2)). The MASE has also been proposed as a way to address possible zero actuals. There happens to be a recent paper (Kolassa, 2026 (https://www.mdpi.com/2571-9394/8/2/24)) arguing against it. Yes, it's published in an MDPI journal. I still think it's a worthy point to make... but now we are back to worthiness...\n\n\n\n\nForecasters also like to look at other kinds of proportional or relative errors, where you calculate an error (MAE or MSE - I don't think MAE is useful) and report it as a proportion either (a) to the mean of the time series itself, or (b) to the error achieved by a benchmark forecasting method. People are divided on whether a (or b) makes sense for nonstationary time series. But b at least immediately shows whether a new forecasting method is better than the benchmark, or not.", "answer_url": "https://stats.stackexchange.com/a/677174", "author": "Stephan Kolassa", "author_url": "https://stats.stackexchange.com/users/1352/stephan-kolassa", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-14T21:31:19+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": 677171, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Stephan Kolassa", "profile_url": "https://stats.stackexchange.com/users/1352/stephan-kolassa", "user_type": "registered"}, "created_at": "2026-09-14T21:31:19+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "3B77BAD7-9D73-4C40-9344-586D98001566", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3B77BAD7-9D73-4C40-9344-586D98001566/view-source"}], "score": 2, "updated_at": "2026-09-14T21:31:19+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Not sure whether these are worthy of mention, but here goes.

\n

In the forecasting community, these are typically used with absolute values. (Usually one assumes that the denominator is positive. If the denominator can become zero, interesting gyrations by the error calculator ensue.)

\n

Once we then take averages over multiple pairs $(X_i,Y_i)$, your first alternative turns into the MAPE, which should be avoided.

\n

The second alternative turns into a MAPE-with-the-forecast-in-the-denominator, which has been touted as one way of dealing with actuals that can be zero, as long as the forecast cannot. It can be gamed similarly to the MAPE. Green & Tashman (2009) surveyed practitioners on whether they preferred the regular MAPE or this variant.

\n

The third alternative is known in the forecasting community as the Mean Absolute Symmetric Error (MASE), because it exhibits a particular kind of symmetry, namely of being invariant if forecast and actual are interchanged. That is actually not a kind of symmetry we are very interested in - symmetry with respect to over- and underprediction would be more interesting (Goodwin & Lawson, 1999). The MASE has also been proposed as a way to address possible zero actuals. There happens to be a recent paper (Kolassa, 2026) arguing against it. Yes, it's published in an MDPI journal. I still think it's a worthy point to make... but now we are back to worthiness...

\n

Forecasters also like to look at other kinds of proportional or relative errors, where you calculate an error (MAE or MSE - I don't think MAE is useful) and report it as a proportion either (a) to the mean of the time series itself, or (b) to the error achieved by a benchmark forecasting method. People are divided on whether a (or b) makes sense for nonstationary time series. But b at least immediately shows whether a new forecasting method is better than the benchmark, or not.

\n", "answer_id": 677174, "answer_text": "Not sure whether these are worthy of mention, but here goes.\n\n\n\n\nIn the forecasting community, these are typically used with absolute values. (Usually one assumes that the denominator is positive. If the denominator can become zero, interesting gyrations by the error calculator ensue.)\n\n\n\n\nOnce we then take averages over multiple pairs $(X_i,Y_i)$, your first alternative turns into the MAPE, which should be avoided (https://stats.stackexchange.com/q/299712/1352).\n\n\n\n\nThe second alternative turns into a MAPE-with-the-forecast-in-the-denominator, which has been touted as one way of dealing with actuals that can be zero, as long as the forecast cannot. It can be gamed similarly to the MAPE. Green & Tashman (2009) (https://ideas.repec.org/a/for/ijafaa/y2009i12p36-40.html) surveyed practitioners on whether they preferred the regular MAPE or this variant.\n\n\n\n\nThe third alternative is known in the forecasting community as the Mean Absolute Symmetric Error (MASE), because it exhibits a particular kind of symmetry, namely of being invariant if forecast and actual are interchanged. That is actually not a kind of symmetry we are very interested in - symmetry with respect to over- and underprediction would be more interesting (Goodwin & Lawson, 1999 (https://doi.org/10.1016/S0169-2070(99)00007-2)). The MASE has also been proposed as a way to address possible zero actuals. There happens to be a recent paper (Kolassa, 2026 (https://www.mdpi.com/2571-9394/8/2/24)) arguing against it. Yes, it's published in an MDPI journal. I still think it's a worthy point to make... but now we are back to worthiness...\n\n\n\n\nForecasters also like to look at other kinds of proportional or relative errors, where you calculate an error (MAE or MSE - I don't think MAE is useful) and report it as a proportion either (a) to the mean of the time series itself, or (b) to the error achieved by a benchmark forecasting method. People are divided on whether a (or b) makes sense for nonstationary time series. But b at least immediately shows whether a new forecasting method is better than the benchmark, or not.", "answer_url": "https://stats.stackexchange.com/a/677174", "author": "Stephan Kolassa", "author_url": "https://stats.stackexchange.com/users/1352/stephan-kolassa", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-14T21:31:19+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": 677171, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Stephan Kolassa", "profile_url": "https://stats.stackexchange.com/users/1352/stephan-kolassa", "user_type": "registered"}, "created_at": "2026-09-14T21:31:19+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "3B77BAD7-9D73-4C40-9344-586D98001566", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3B77BAD7-9D73-4C40-9344-586D98001566/view-source"}], "score": 2, "updated_at": "2026-09-14T21:31:19+00:00"}], "domain": "statistics", "external_links": ["https://doi.org/10.1016/S0169-2070(99)00007-2", "https://doi.org/10.1136/bmj.313.7049.106", "https://en.wikipedia.org/wiki/Deming_regression#Orthogonal_regression", "https://ideas.repec.org/a/for/ijafaa/y2009i12p36-40.html", "https://www.mdpi.com/2571-9394/8/2/24"], "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": "Carl", "question_author_url": "https://stats.stackexchange.com/users/99274/carl", "question_author_user_type": "registered", "question_created_at": "2026-09-14T19:59:30+00:00", "question_html": "

Suppose we have a measurement (a "response") as a vector $Y$, that is, a $Y_i$ for $i=1,2,3,...n$ and an estimator of that measurement (a "predictor") $X$. Then one can define a proportional (or relative) error as

\n
    \n
  1. $\\frac{X-Y}{Y}$, which is the most commonly used definition of proportional error. This assumes that the measured quantity is the proper reference for relative error calculation. It has the property that the proportions become large magnitude for $Y$ in the neighborhood of zero.

    \n
  2. \n
  3. $\\frac{X-Y}{X}$, which is a measure of proportional error that assumes that the predictor quantity is the reference for that relative error calculation. It has the property that the proportions become large magnitude for $X$ in the neighborhood of zero.

    \n
  4. \n
  5. $\\frac{X-Y}{\\left(\\frac{X+Y}{2}\\right)}$ is a measure of proportional error relative to the mean possibly having a better assurance of no inflated magnitude values when $X$ or $Y$ (but not $X$ AND $Y$) and are in the neighborhood of zero. This assumes that there is some error in measuring $Y$ as well as in the estimator $X$. This estimator is similar to the assumptions made on Bland-Altman plotting, with the notable difference that Bland-Altman examined absolute error, that is plotting $\\frac{X+Y}{2}$ versus $|{X-Y}|$. Thus, this form of proportional error has some implied value for methods comparisons when we have no clear indication of which method is more reliable. In other words, it is a bit like orthogonal regression, a poor cousin of Deming regression. That is, if we cannot measure the exact variances for two methods, it is in some cases best to assume that both measures have equal variance. This contrasts with 1. and 2. above where we choose whether $Y$ or $X$ is the more appropriate reference.

    \n
  6. \n
\n

Q: Are there comments on the above or other measures of proportional error worthy of mention?

\n

Edit BTW, there is a non-negativity constraint. The above is useful, for example, for density function modeling of drug concentrations to look for proportional error of regression residuals therein. Statistics for this include mean, standard deviation, distribution of proportional error of residuals, and homoscedasticity of proportional residuals, and others. Another example is that "so-called" $1/Y^2$ weighted least squares is proportional modelling because we then are minimizing the L2 norm, that is $\\left\\|\\frac{X-Y}{Y}\\right\\|_2$

\n", "question_id": 677171, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "Suppose we have a measurement (a \"response\") as a vector $Y$, that is, a $Y_i$ for $i=1,2,3,...n$ and an estimator of that measurement (a \"predictor\") $X$. Then one can define a proportional (or relative) error as\n\n\n\n\n\n\n\n$\\frac{X-Y}{Y}$, which is the most commonly used definition of proportional error. This assumes that the measured quantity is the proper reference for relative error calculation. It has the property that the proportions become large magnitude for $Y$ in the neighborhood of zero.\n\n\n\n\n\n\n\n\n\n$\\frac{X-Y}{X}$, which is a measure of proportional error that assumes that the predictor quantity is the reference for that relative error calculation. It has the property that the proportions become large magnitude for $X$ in the neighborhood of zero.\n\n\n\n\n\n\n\n\n\n$\\frac{X-Y}{\\left(\\frac{X+Y}{2}\\right)}$ is a measure of proportional error relative to the mean possibly having a better assurance of no inflated magnitude values when $X$ or $Y$ (but not $X$ AND $Y$) and are in the neighborhood of zero. This assumes that there is some error in measuring $Y$ as well as in the estimator $X$. This estimator is similar to the assumptions made on Bland-Altman plotting (https://doi.org/10.1136/bmj.313.7049.106), with the notable difference that Bland-Altman examined absolute error, that is plotting $\\frac{X+Y}{2}$ versus $|{X-Y}|$. Thus, this form of proportional error has some implied value for methods comparisons when we have no clear indication of which method is more reliable. In other words, it is a bit like orthogonal regression (https://en.wikipedia.org/wiki/Deming_regression#Orthogonal_regression), a poor cousin of Deming regression. That is, if we cannot measure the exact variances for two methods, it is in some cases best to assume that both measures have equal variance. This contrasts with 1. and 2. above where we choose whether $Y$ or $X$ is the more appropriate reference.\n\n\n\n\n\n\n\n\nQ: Are there comments on the above or other measures of proportional error worthy of mention?\n\n\n\n\nEdit BTW, there is a non-negativity constraint. The above is useful, for example, for density function modeling of drug concentrations to look for proportional error of regression residuals therein. Statistics for this include mean, standard deviation, distribution of proportional error of residuals, and homoscedasticity of proportional residuals, and others. Another example is that \"so-called\" $1/Y^2$ weighted least squares is proportional modelling because we then are minimizing the L2 norm, that is $\\left\\|\\frac{X-Y}{Y}\\right\\|_2$", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Carl", "profile_url": "https://stats.stackexchange.com/users/99274/carl", "user_type": "registered"}, "created_at": "2026-09-14T19:59:30+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "50650216-F9BB-41C4-ADDF-3B86CBDAC1E1", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/50650216-F9BB-41C4-ADDF-3B86CBDAC1E1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Carl", "profile_url": "https://stats.stackexchange.com/users/99274/carl", "user_type": "registered"}, "created_at": "2026-09-14T21:57:38+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "459FA967-0F34-45E1-A1EA-3C4AD0773882", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/459FA967-0F34-45E1-A1EA-3C4AD0773882/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Carl", "profile_url": "https://stats.stackexchange.com/users/99274/carl", "user_type": "registered"}, "created_at": "2026-09-14T22:35:15+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "3ECA09C1-AC84-44B7-B782-789DDE651719", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3ECA09C1-AC84-44B7-B782-789DDE651719/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Carl", "profile_url": "https://stats.stackexchange.com/users/99274/carl", "user_type": "registered"}, "created_at": "2026-09-14T22:56:39+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "4525EAC9-AFA4-4FC3-B7C9-2FCC57F25421", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4525EAC9-AFA4-4FC3-B7C9-2FCC57F25421/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-15T04:06:58+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "C154C2D1-DBEA-4C1F-A969-3B7783C32CE1", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/C154C2D1-DBEA-4C1F-A969-3B7783C32CE1/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677171/what-are-the-alternatives-for-calculating-proportional-errors-not-absolute-erro", "split": "train", "split_group": "f0886226b4519fc2d07a25fbd87c5d7ed0ad392bec880d48453bb8af791a1b47", "tags": ["regression", "model-selection", "proportion", "error", "measurement-error"], "thread_id": "stats:677171", "title": "What are the alternatives for calculating proportional errors (not absolute errors)?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I am a beginner in Ordinal Models looking for some help. I am doing a 3-factor model, primarily interested in the effect of the 3 way interaction on the results. I have to say that I come from making Linear mixed effect models and initially assumed it would largerly transfer. However, I do not know how to report the results I got, nor how to visualize it in a easy, straighforward manner.\nHere is the model I'm using in R:\n\n\n\n\nmodelOrdinalWordCat <- clmm(Rating_Resp ~ WordCat * Group * Session + (1|participant) + (1|Word), data = completed, link = \"logit\")\n\n\n\n\n\nRating_Resp is 5 levels; WordCat, Session and Group are all categorical with 2 levels, with Session being within group factor. Participant and word/item are random intercepts.\nI then used summary(modelOrdinalWordCat) to look at the model in a more \"ANOVA\" like manner, and got this print out.\n\n\n\n\n Estimate Std. Error z value Pr(>|z|) \nWordCat[S.NonWord] -0.38012 0.04136 -9.190 < 2e-16 ***\nGroupL2 Exposure -0.17397 0.08151 -2.134 0.03282 *\nSession2 -0.05367 0.03627 -1.480 0.13896 \nWordCat[S.NonWord]:GroupL2 Exposure 0.04777 0.03412 1.400 0.16141 \nWordCat[S.NonWord]:Session2 0.05404 0.03623 1.492 0.13579 \nGroupL2 Exposure:Session2 0.13310 0.04820 2.761 0.00576 ** \nWordCat[S.NonWord]:GroupL2 Exposure:Session2 -0.10393 0.04815 -2.159 0.03089 * \n\n\n\n\n\nUsing just the default print out, I get this:\n\n\n\n\nWordCat[S.NonWord] GroupL2 Exposure \n-0.38012 -0.17397 \nSession2 WordCat[S.NonWord]:GroupL2 Exposure \n-0.05367 0.04777 \nWordCat[S.NonWord]:Session2 GroupL2 Exposure:Session2 \n0.05404 0.13310 \nWordCat[S.NonWord]:GroupL2 Exposure:Session2 \n-0.10393 \n\n\n\n\n\nI can't make heads of tails of this table.\nHow do I report the results of this? Is it just : Word Type x Session x Group: estimate = -0.10, SE = 0.048, z value = -2.16, p = .031\nThanks in advance!\n(If I am completely wrong, let me have it!)", "record_id": "Scientific-Statistics-QA:stats:677183", "selected_answer": {"answer_html": "

Ordinal models pose (at least) two difficulties in interpretation beyond standard linear models.

\n

First, the coefficients are in log-odds scales, which can be hard to think about even in logistic regression. A log-odds coefficient in ordinal regression is for the change of one outcome level per change in a predictor or interaction.

\n

You should show the model summary, but visualization of model predictions and their confidence intervals or standard errors is more useful for your audience (and probably for yourself). As you used the standard R treatment coding of the factors, each coefficient thus represents the difference in log-odds associated with a predictor or interaction term, beyond what would be predicted from lower-level intercepts or single-predictor coefficients or interactions.

\n

Second, instead of having a single intercept as in logistic regression, there is a separate intercept for each transition between outcome levels. To get model predictions, it's simplest to use post-modeling tools like those in the emmeans package recommended by @Sointu in a comment.

\n

Your 3-way interaction is thus the difference in log-odds for changing one outcome level between the situation with none of the 3 factors at reference levels and the situation with only 1 of them at the reference level. The coefficient of -0.10393 in log-odds scale represents odds of about 0.9. Whether its statistical significance is important in practice depends on your understanding of the subject matter.

\n

This site has several entries that provide more detail and links, including Interpretation of ordinal logistic regression and How to understand output from R's polr function (ordered logistic regression)?. UCLA Advanced Research Computing has pages on Ordinal Logistic Regression | R Data Analysis Examples and How Do I Interpret the Coefficients in an Ordinal Logistic Regression in R?. Frank Harrell provides extensive Resources for Ordinal Regression Models, recommending their widespread use even with data that would often be considered continuous.

\n

One additional warning: there are two different ways to set up the ordinal regression. Read the documentation to know which is being used. One models the probability of having an outcome less than or equal to a specified outcome level. That seems to be used in most R implementations. The other, used in Frank Harrell's rms package, models the probability of having an outcome greater than or equal to a specified outcome level. You'll find differences in signs of intercepts depending on which is used. The emmeans package can work with either to get model predictions.

\n", "answer_id": 677210, "answer_text": "Ordinal models pose (at least) two difficulties in interpretation beyond standard linear models.\n\n\n\n\nFirst, the coefficients are in log-odds scales, which can be hard to think about even in logistic regression. A log-odds coefficient in ordinal regression is for the change of one outcome level per change in a predictor or interaction.\n\n\n\n\nYou should show the model summary, but visualization of model predictions and their confidence intervals or standard errors is more useful for your audience (and probably for yourself). As you used the standard R treatment coding of the factors, each coefficient thus represents the difference in log-odds associated with a predictor or interaction term, beyond what would be predicted from lower-level intercepts or single-predictor coefficients or interactions.\n\n\n\n\nSecond, instead of having a single intercept as in logistic regression, there is a separate intercept for each transition between outcome levels. To get model predictions, it's simplest to use post-modeling tools like those in the emmeans package (https://cran.r-project.org/package=emmeans) recommended by @Sointu in a comment.\n\n\n\n\nYour 3-way interaction is thus the difference in log-odds for changing one outcome level between the situation with none of the 3 factors at reference levels and the situation with only 1 of them at the reference level. The coefficient of -0.10393 in log-odds scale represents odds of about 0.9. Whether its statistical significance is important in practice depends on your understanding of the subject matter.\n\n\n\n\nThis site has several entries that provide more detail and links, including Interpretation of ordinal logistic regression (https://stats.stackexchange.com/q/89474/28500) and How to understand output from R's polr function (ordered logistic regression)? (https://stats.stackexchange.com/q/7720/28500). UCLA Advanced Research Computing has pages on Ordinal Logistic Regression | R Data Analysis Examples (https://stats.oarc.ucla.edu/r/dae/ordinal-logistic-regression/) and How Do I Interpret the Coefficients in an Ordinal Logistic Regression in R? (https://stats.oarc.ucla.edu/r/faq/ologit-coefficients/). Frank Harrell provides extensive Resources for Ordinal Regression Models (https://www.fharrell.com/post/rpo/), recommending their widespread use even with data that would often be considered continuous.\n\n\n\n\nOne additional warning: there are two different ways to set up the ordinal regression. Read the documentation to know which is being used. One models the probability of having an outcome less than or equal to a specified outcome level. That seems to be used in most R implementations. The other, used in Frank Harrell's rms package (https://cran.r-project.org/package=rms), models the probability of having an outcome greater than or equal to a specified outcome level. You'll find differences in signs of intercepts depending on which is used. The emmeans package can work with either to get model predictions.", "answer_url": "https://stats.stackexchange.com/a/677210", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-18T17:51:30+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": 677183, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-18T17:51:30+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "B490DDB3-84D3-4497-83EC-D7FE79E12A5A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B490DDB3-84D3-4497-83EC-D7FE79E12A5A/view-source"}], "score": 6, "updated_at": "2026-09-18T17:51:30+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Ordinal models pose (at least) two difficulties in interpretation beyond standard linear models.

\n

First, the coefficients are in log-odds scales, which can be hard to think about even in logistic regression. A log-odds coefficient in ordinal regression is for the change of one outcome level per change in a predictor or interaction.

\n

You should show the model summary, but visualization of model predictions and their confidence intervals or standard errors is more useful for your audience (and probably for yourself). As you used the standard R treatment coding of the factors, each coefficient thus represents the difference in log-odds associated with a predictor or interaction term, beyond what would be predicted from lower-level intercepts or single-predictor coefficients or interactions.

\n

Second, instead of having a single intercept as in logistic regression, there is a separate intercept for each transition between outcome levels. To get model predictions, it's simplest to use post-modeling tools like those in the emmeans package recommended by @Sointu in a comment.

\n

Your 3-way interaction is thus the difference in log-odds for changing one outcome level between the situation with none of the 3 factors at reference levels and the situation with only 1 of them at the reference level. The coefficient of -0.10393 in log-odds scale represents odds of about 0.9. Whether its statistical significance is important in practice depends on your understanding of the subject matter.

\n

This site has several entries that provide more detail and links, including Interpretation of ordinal logistic regression and How to understand output from R's polr function (ordered logistic regression)?. UCLA Advanced Research Computing has pages on Ordinal Logistic Regression | R Data Analysis Examples and How Do I Interpret the Coefficients in an Ordinal Logistic Regression in R?. Frank Harrell provides extensive Resources for Ordinal Regression Models, recommending their widespread use even with data that would often be considered continuous.

\n

One additional warning: there are two different ways to set up the ordinal regression. Read the documentation to know which is being used. One models the probability of having an outcome less than or equal to a specified outcome level. That seems to be used in most R implementations. The other, used in Frank Harrell's rms package, models the probability of having an outcome greater than or equal to a specified outcome level. You'll find differences in signs of intercepts depending on which is used. The emmeans package can work with either to get model predictions.

\n", "answer_id": 677210, "answer_text": "Ordinal models pose (at least) two difficulties in interpretation beyond standard linear models.\n\n\n\n\nFirst, the coefficients are in log-odds scales, which can be hard to think about even in logistic regression. A log-odds coefficient in ordinal regression is for the change of one outcome level per change in a predictor or interaction.\n\n\n\n\nYou should show the model summary, but visualization of model predictions and their confidence intervals or standard errors is more useful for your audience (and probably for yourself). As you used the standard R treatment coding of the factors, each coefficient thus represents the difference in log-odds associated with a predictor or interaction term, beyond what would be predicted from lower-level intercepts or single-predictor coefficients or interactions.\n\n\n\n\nSecond, instead of having a single intercept as in logistic regression, there is a separate intercept for each transition between outcome levels. To get model predictions, it's simplest to use post-modeling tools like those in the emmeans package (https://cran.r-project.org/package=emmeans) recommended by @Sointu in a comment.\n\n\n\n\nYour 3-way interaction is thus the difference in log-odds for changing one outcome level between the situation with none of the 3 factors at reference levels and the situation with only 1 of them at the reference level. The coefficient of -0.10393 in log-odds scale represents odds of about 0.9. Whether its statistical significance is important in practice depends on your understanding of the subject matter.\n\n\n\n\nThis site has several entries that provide more detail and links, including Interpretation of ordinal logistic regression (https://stats.stackexchange.com/q/89474/28500) and How to understand output from R's polr function (ordered logistic regression)? (https://stats.stackexchange.com/q/7720/28500). UCLA Advanced Research Computing has pages on Ordinal Logistic Regression | R Data Analysis Examples (https://stats.oarc.ucla.edu/r/dae/ordinal-logistic-regression/) and How Do I Interpret the Coefficients in an Ordinal Logistic Regression in R? (https://stats.oarc.ucla.edu/r/faq/ologit-coefficients/). Frank Harrell provides extensive Resources for Ordinal Regression Models (https://www.fharrell.com/post/rpo/), recommending their widespread use even with data that would often be considered continuous.\n\n\n\n\nOne additional warning: there are two different ways to set up the ordinal regression. Read the documentation to know which is being used. One models the probability of having an outcome less than or equal to a specified outcome level. That seems to be used in most R implementations. The other, used in Frank Harrell's rms package (https://cran.r-project.org/package=rms), models the probability of having an outcome greater than or equal to a specified outcome level. You'll find differences in signs of intercepts depending on which is used. The emmeans package can work with either to get model predictions.", "answer_url": "https://stats.stackexchange.com/a/677210", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-18T17:51:30+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": 677183, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-18T17:51:30+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "B490DDB3-84D3-4497-83EC-D7FE79E12A5A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B490DDB3-84D3-4497-83EC-D7FE79E12A5A/view-source"}], "score": 6, "updated_at": "2026-09-18T17:51:30+00:00"}], "domain": "statistics", "external_links": ["https://cran.r-project.org/package=emmeans", "https://cran.r-project.org/package=rms", "https://stats.oarc.ucla.edu/r/dae/ordinal-logistic-regression/", "https://stats.oarc.ucla.edu/r/faq/ologit-coefficients/", "https://www.fharrell.com/post/rpo/"], "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": "Rae", "question_author_url": "https://stats.stackexchange.com/users/516706/rae", "question_author_user_type": "registered", "question_created_at": "2026-09-15T18:48:16+00:00", "question_html": "

I am a beginner in Ordinal Models looking for some help. I am doing a 3-factor model, primarily interested in the effect of the 3 way interaction on the results. I have to say that I come from making Linear mixed effect models and initially assumed it would largerly transfer. However, I do not know how to report the results I got, nor how to visualize it in a easy, straighforward manner.\nHere is the model I'm using in R:

\n
modelOrdinalWordCat <- clmm(Rating_Resp ~ WordCat * Group * Session + (1|participant) + (1|Word), data = completed, link = "logit")\n
\n

Rating_Resp is 5 levels; WordCat, Session and Group are all categorical with 2 levels, with Session being within group factor. Participant and word/item are random intercepts.\nI then used summary(modelOrdinalWordCat) to look at the model in a more "ANOVA" like manner, and got this print out.

\n
                                         Estimate Std. Error z value Pr(>|z|)    \nWordCat[S.NonWord]                           -0.38012    0.04136  -9.190  < 2e-16 ***\nGroupL2 Exposure                             -0.17397    0.08151  -2.134  0.03282 *\nSession2                                     -0.05367    0.03627  -1.480  0.13896   \nWordCat[S.NonWord]:GroupL2 Exposure           0.04777    0.03412   1.400  0.16141    \nWordCat[S.NonWord]:Session2                   0.05404    0.03623   1.492  0.13579    \nGroupL2 Exposure:Session2                     0.13310    0.04820   2.761  0.00576 ** \nWordCat[S.NonWord]:GroupL2 Exposure:Session2 -0.10393    0.04815  -2.159  0.03089 * \n
\n

Using just the default print out, I get this:

\n
WordCat[S.NonWord]                             GroupL2 Exposure \n-0.38012                                     -0.17397 \nSession2          WordCat[S.NonWord]:GroupL2 Exposure \n-0.05367                                      0.04777 \nWordCat[S.NonWord]:Session2                    GroupL2 Exposure:Session2 \n0.05404                                      0.13310 \nWordCat[S.NonWord]:GroupL2 Exposure:Session2 \n-0.10393 \n
\n

I can't make heads of tails of this table.\nHow do I report the results of this? Is it just : Word Type x Session x Group: estimate = -0.10, SE = 0.048, z value = -2.16, p = .031\nThanks in advance!\n(If I am completely wrong, let me have it!)

\n", "question_id": 677183, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I am a beginner in Ordinal Models looking for some help. I am doing a 3-factor model, primarily interested in the effect of the 3 way interaction on the results. I have to say that I come from making Linear mixed effect models and initially assumed it would largerly transfer. However, I do not know how to report the results I got, nor how to visualize it in a easy, straighforward manner.\nHere is the model I'm using in R:\n\n\n\n\nmodelOrdinalWordCat <- clmm(Rating_Resp ~ WordCat * Group * Session + (1|participant) + (1|Word), data = completed, link = \"logit\")\n\n\n\n\n\nRating_Resp is 5 levels; WordCat, Session and Group are all categorical with 2 levels, with Session being within group factor. Participant and word/item are random intercepts.\nI then used summary(modelOrdinalWordCat) to look at the model in a more \"ANOVA\" like manner, and got this print out.\n\n\n\n\n Estimate Std. Error z value Pr(>|z|) \nWordCat[S.NonWord] -0.38012 0.04136 -9.190 < 2e-16 ***\nGroupL2 Exposure -0.17397 0.08151 -2.134 0.03282 *\nSession2 -0.05367 0.03627 -1.480 0.13896 \nWordCat[S.NonWord]:GroupL2 Exposure 0.04777 0.03412 1.400 0.16141 \nWordCat[S.NonWord]:Session2 0.05404 0.03623 1.492 0.13579 \nGroupL2 Exposure:Session2 0.13310 0.04820 2.761 0.00576 ** \nWordCat[S.NonWord]:GroupL2 Exposure:Session2 -0.10393 0.04815 -2.159 0.03089 * \n\n\n\n\n\nUsing just the default print out, I get this:\n\n\n\n\nWordCat[S.NonWord] GroupL2 Exposure \n-0.38012 -0.17397 \nSession2 WordCat[S.NonWord]:GroupL2 Exposure \n-0.05367 0.04777 \nWordCat[S.NonWord]:Session2 GroupL2 Exposure:Session2 \n0.05404 0.13310 \nWordCat[S.NonWord]:GroupL2 Exposure:Session2 \n-0.10393 \n\n\n\n\n\nI can't make heads of tails of this table.\nHow do I report the results of this? Is it just : Word Type x Session x Group: estimate = -0.10, SE = 0.048, z value = -2.16, p = .031\nThanks in advance!\n(If I am completely wrong, let me have it!)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rae", "profile_url": "https://stats.stackexchange.com/users/516706/rae", "user_type": "registered"}, "created_at": "2026-09-15T18:48:16+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "54C1911F-DE57-4D25-88F0-822250BA5283", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/54C1911F-DE57-4D25-88F0-822250BA5283/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677183/ordinal-mixed-effect-model-with-3-factors-and-interactions-beginner-help", "split": "train", "split_group": "4e9596eab227a4c8203ea12055e6a18f2307cdda74a5c355bfd04e5dbaa03ae6", "tags": ["ordinal-data", "ordered-logit", "ordinal-logistic-regression"], "thread_id": "stats:677183", "title": "Ordinal Mixed Effect Model with 3 factors and Interactions - Beginner Help"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

Ask them, if they are more impressed if I forecast a slow-down in sales for the next year (in orange) based on what I know (the blue dots) in scenario A or B.\n\"Two

\n

If I ignore that it's a time-series and "forecast" using data including that from the future of what I'm forecasting, I'm treating a time series as any other random variable. Most people will understand that this is kind of cheating / not the problem they want to solve. In scenario B, I only get to use the sales in the past, most people will agree that this makes more sense.

\n", "answer_id": 677188, "answer_text": "Ask them, if they are more impressed if I forecast a slow-down in sales for the next year (in orange) based on what I know (the blue dots) in scenario A or B.\n[image: Two scenarios for forecasting sale, in A we know future sales, too, in B only the sales in the past; source: https://i.sstatic.net/Z4d1Pytm.png] (https://i.sstatic.net/Z4d1Pytm.png)\n\n\n\n\nIf I ignore that it's a time-series and \"forecast\" using data including that from the future of what I'm forecasting, I'm treating a time series as any other random variable. Most people will understand that this is kind of cheating / not the problem they want to solve. In scenario B, I only get to use the sales in the past, most people will agree that this makes more sense.", "answer_url": "https://stats.stackexchange.com/a/677188", "author": "Björn", "author_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T12:57:18+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": 677186, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Björn", "profile_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "user_type": "registered"}, "created_at": "2026-09-17T12:57:18+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "02F3E722-3DF0-4226-B17B-0477A480D8AE", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/02F3E722-3DF0-4226-B17B-0477A480D8AE/view-source"}], "score": 5, "updated_at": "2026-09-17T12:57:18+00:00"}, {"answer_html": "

Let's say you measure the height of a river at a particular point for 5 days and get the values:

\n

6.5 ft, 6.2ft, 6.1 ft, 6.7 ft, 6.1 ft.

\n

Then I asked you to predict what the height would be on day 6. If you answer "probably a bit more than 6 feet" that makes sense...because you are intuitively assuming that the height on day 6 will be VERY SIMILAR to the height on previous days.

\n

But that is just another way of saying that we assume that the height at a given day is strongly correlated with its height on previous days. But if that's true, then the value cannot be completely "random" (or more specifically "independent") in the way that two random people selected for participation in a political poll are assumed to be.

\n

This matters if you want to do any sort of quantitative analysis, say looking at whether the height of the river is related to some other changing trend, like the crop yield of a nearby field. Most statistical models, like regression analysis, assume that the variables you are comparing are NOT correlated with previous values in this way, and if you try to use those methods on these sorts of data they could very well give you the wrong answer.

\n

In the most egregious case a regression analysis might even tell you two trends are strongly correlated even when they have NOTHING to do with each other, and this problem gets WORSE the more data you have! This happens when both series are what we call a "random walk" - where tomorrow's value is just today's value plus or minus some random variation.

\n

To prevent this sort of thing from happening, it is important to identify the characteristics of a time series before you start analyzing it: how dependent is each value on the ones before it? Is there some overall upward or downward trend? Is there a cyclical seasonal variation that repeats over some interval? Once you have figured this stuff out, you can transform the values you are analyzing so that they can be analyzed correctly.

\n", "answer_id": 677189, "answer_text": "Let's say you measure the height of a river at a particular point for 5 days and get the values:\n\n\n\n\n6.5 ft, 6.2ft, 6.1 ft, 6.7 ft, 6.1 ft.\n\n\n\n\nThen I asked you to predict what the height would be on day 6. If you answer \"probably a bit more than 6 feet\" that makes sense...because you are intuitively assuming that the height on day 6 will be VERY SIMILAR to the height on previous days.\n\n\n\n\nBut that is just another way of saying that we assume that the height at a given day is strongly correlated with its height on previous days. But if that's true, then the value cannot be completely \"random\" (or more specifically \"independent\") in the way that two random people selected for participation in a political poll are assumed to be.\n\n\n\n\nThis matters if you want to do any sort of quantitative analysis, say looking at whether the height of the river is related to some other changing trend, like the crop yield of a nearby field. Most statistical models, like regression analysis, assume that the variables you are comparing are NOT correlated with previous values in this way, and if you try to use those methods on these sorts of data they could very well give you the wrong answer.\n\n\n\n\nIn the most egregious case a regression analysis might even tell you two trends are strongly correlated even when they have NOTHING to do with each other, and this problem gets WORSE the more data you have! This happens when both series are what we call a \"random walk\" - where tomorrow's value is just today's value plus or minus some random variation.\n\n\n\n\nTo prevent this sort of thing from happening, it is important to identify the characteristics of a time series before you start analyzing it: how dependent is each value on the ones before it? Is there some overall upward or downward trend? Is there a cyclical seasonal variation that repeats over some interval? Once you have figured this stuff out, you can transform the values you are analyzing so that they can be analyzed correctly.", "answer_url": "https://stats.stackexchange.com/a/677189", "author": "Graham Wright", "author_url": "https://stats.stackexchange.com/users/291159/graham-wright", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T13:01:38+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": 677186, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Graham Wright", "profile_url": "https://stats.stackexchange.com/users/291159/graham-wright", "user_type": "registered"}, "created_at": "2026-09-17T13:01:38+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7126F2E7-BCD0-4B9D-9F22-F3D7402743A5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7126F2E7-BCD0-4B9D-9F22-F3D7402743A5/view-source"}], "score": 7, "updated_at": "2026-09-17T13:01:38+00:00"}], "product": "statistics_qa", "question": "I work in a field (hydrology) where many practitioners (and others) treat time series as though they were a series of random variables - that is, they ignore the structure in the series and have little understanding of why it is important. Of course I know why there is a difference and what the consequences are, but most of the explanations of that I can find are mathematical - or at least mathematical enough that they are incomprehensible to non-mathematically minded people.\n\n\n\n\nSo, what are the simplest explanations of the difference that would be accessible to non-mathematicians and would make it immediately obvious that they need to be treated differently?\n\n\n\n\nI am looking for a way to be able to explain this to a lay-person and so any ideas would be much appreciated.", "record_id": "Scientific-Statistics-QA:stats:677186", "selected_answer": {"answer_html": "

Some of the comments could be answers, and are good answers. But, if you want completely non-technical, I'd use an example.

\n

Suppose you go on a diet to lose weight. You weigh yourself every day and get values say (in pounds):

\n

160 159 160 159 158 157 158 157 156

\n

Looks like you've lost a few pounds! What if we ignore the time series element?

\n

Then we have no idea if we have lost or gained weight.

\n

I think that's understandable by pretty much anyone - no calculations needed.

\n", "answer_id": 677187, "answer_text": "Some of the comments could be answers, and are good answers. But, if you want completely non-technical, I'd use an example.\n\n\n\n\nSuppose you go on a diet to lose weight. You weigh yourself every day and get values say (in pounds):\n\n\n\n\n160 159 160 159 158 157 158 157 156\n\n\n\n\nLooks like you've lost a few pounds! What if we ignore the time series element?\n\n\n\n\nThen we have no idea if we have lost or gained weight.\n\n\n\n\nI think that's understandable by pretty much anyone - no calculations needed.", "answer_url": "https://stats.stackexchange.com/a/677187", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T12:22:20+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": 677186, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-09-17T12:22:20+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "AD7F8377-51C8-4D08-9CFF-2966F61EF20D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD7F8377-51C8-4D08-9CFF-2966F61EF20D/view-source"}], "score": 12, "updated_at": "2026-09-17T12:22:20+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Some of the comments could be answers, and are good answers. But, if you want completely non-technical, I'd use an example.

\n

Suppose you go on a diet to lose weight. You weigh yourself every day and get values say (in pounds):

\n

160 159 160 159 158 157 158 157 156

\n

Looks like you've lost a few pounds! What if we ignore the time series element?

\n

Then we have no idea if we have lost or gained weight.

\n

I think that's understandable by pretty much anyone - no calculations needed.

\n", "answer_id": 677187, "answer_text": "Some of the comments could be answers, and are good answers. But, if you want completely non-technical, I'd use an example.\n\n\n\n\nSuppose you go on a diet to lose weight. You weigh yourself every day and get values say (in pounds):\n\n\n\n\n160 159 160 159 158 157 158 157 156\n\n\n\n\nLooks like you've lost a few pounds! What if we ignore the time series element?\n\n\n\n\nThen we have no idea if we have lost or gained weight.\n\n\n\n\nI think that's understandable by pretty much anyone - no calculations needed.", "answer_url": "https://stats.stackexchange.com/a/677187", "author": "Peter Flom", "author_url": "https://stats.stackexchange.com/users/686/peter-flom", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T12:22:20+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": 677186, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Peter Flom", "profile_url": "https://stats.stackexchange.com/users/686/peter-flom", "user_type": "registered"}, "created_at": "2026-09-17T12:22:20+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "AD7F8377-51C8-4D08-9CFF-2966F61EF20D", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD7F8377-51C8-4D08-9CFF-2966F61EF20D/view-source"}], "score": 12, "updated_at": "2026-09-17T12:22:20+00:00"}, {"answer_html": "

Ask them, if they are more impressed if I forecast a slow-down in sales for the next year (in orange) based on what I know (the blue dots) in scenario A or B.\n\"Two

\n

If I ignore that it's a time-series and "forecast" using data including that from the future of what I'm forecasting, I'm treating a time series as any other random variable. Most people will understand that this is kind of cheating / not the problem they want to solve. In scenario B, I only get to use the sales in the past, most people will agree that this makes more sense.

\n", "answer_id": 677188, "answer_text": "Ask them, if they are more impressed if I forecast a slow-down in sales for the next year (in orange) based on what I know (the blue dots) in scenario A or B.\n[image: Two scenarios for forecasting sale, in A we know future sales, too, in B only the sales in the past; source: https://i.sstatic.net/Z4d1Pytm.png] (https://i.sstatic.net/Z4d1Pytm.png)\n\n\n\n\nIf I ignore that it's a time-series and \"forecast\" using data including that from the future of what I'm forecasting, I'm treating a time series as any other random variable. Most people will understand that this is kind of cheating / not the problem they want to solve. In scenario B, I only get to use the sales in the past, most people will agree that this makes more sense.", "answer_url": "https://stats.stackexchange.com/a/677188", "author": "Björn", "author_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T12:57:18+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": 677186, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Björn", "profile_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "user_type": "registered"}, "created_at": "2026-09-17T12:57:18+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "02F3E722-3DF0-4226-B17B-0477A480D8AE", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/02F3E722-3DF0-4226-B17B-0477A480D8AE/view-source"}], "score": 5, "updated_at": "2026-09-17T12:57:18+00:00"}, {"answer_html": "

Let's say you measure the height of a river at a particular point for 5 days and get the values:

\n

6.5 ft, 6.2ft, 6.1 ft, 6.7 ft, 6.1 ft.

\n

Then I asked you to predict what the height would be on day 6. If you answer "probably a bit more than 6 feet" that makes sense...because you are intuitively assuming that the height on day 6 will be VERY SIMILAR to the height on previous days.

\n

But that is just another way of saying that we assume that the height at a given day is strongly correlated with its height on previous days. But if that's true, then the value cannot be completely "random" (or more specifically "independent") in the way that two random people selected for participation in a political poll are assumed to be.

\n

This matters if you want to do any sort of quantitative analysis, say looking at whether the height of the river is related to some other changing trend, like the crop yield of a nearby field. Most statistical models, like regression analysis, assume that the variables you are comparing are NOT correlated with previous values in this way, and if you try to use those methods on these sorts of data they could very well give you the wrong answer.

\n

In the most egregious case a regression analysis might even tell you two trends are strongly correlated even when they have NOTHING to do with each other, and this problem gets WORSE the more data you have! This happens when both series are what we call a "random walk" - where tomorrow's value is just today's value plus or minus some random variation.

\n

To prevent this sort of thing from happening, it is important to identify the characteristics of a time series before you start analyzing it: how dependent is each value on the ones before it? Is there some overall upward or downward trend? Is there a cyclical seasonal variation that repeats over some interval? Once you have figured this stuff out, you can transform the values you are analyzing so that they can be analyzed correctly.

\n", "answer_id": 677189, "answer_text": "Let's say you measure the height of a river at a particular point for 5 days and get the values:\n\n\n\n\n6.5 ft, 6.2ft, 6.1 ft, 6.7 ft, 6.1 ft.\n\n\n\n\nThen I asked you to predict what the height would be on day 6. If you answer \"probably a bit more than 6 feet\" that makes sense...because you are intuitively assuming that the height on day 6 will be VERY SIMILAR to the height on previous days.\n\n\n\n\nBut that is just another way of saying that we assume that the height at a given day is strongly correlated with its height on previous days. But if that's true, then the value cannot be completely \"random\" (or more specifically \"independent\") in the way that two random people selected for participation in a political poll are assumed to be.\n\n\n\n\nThis matters if you want to do any sort of quantitative analysis, say looking at whether the height of the river is related to some other changing trend, like the crop yield of a nearby field. Most statistical models, like regression analysis, assume that the variables you are comparing are NOT correlated with previous values in this way, and if you try to use those methods on these sorts of data they could very well give you the wrong answer.\n\n\n\n\nIn the most egregious case a regression analysis might even tell you two trends are strongly correlated even when they have NOTHING to do with each other, and this problem gets WORSE the more data you have! This happens when both series are what we call a \"random walk\" - where tomorrow's value is just today's value plus or minus some random variation.\n\n\n\n\nTo prevent this sort of thing from happening, it is important to identify the characteristics of a time series before you start analyzing it: how dependent is each value on the ones before it? Is there some overall upward or downward trend? Is there a cyclical seasonal variation that repeats over some interval? Once you have figured this stuff out, you can transform the values you are analyzing so that they can be analyzed correctly.", "answer_url": "https://stats.stackexchange.com/a/677189", "author": "Graham Wright", "author_url": "https://stats.stackexchange.com/users/291159/graham-wright", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T13:01:38+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": 677186, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Graham Wright", "profile_url": "https://stats.stackexchange.com/users/291159/graham-wright", "user_type": "registered"}, "created_at": "2026-09-17T13:01:38+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "7126F2E7-BCD0-4B9D-9F22-F3D7402743A5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7126F2E7-BCD0-4B9D-9F22-F3D7402743A5/view-source"}], "score": 7, "updated_at": "2026-09-17T13:01:38+00:00"}], "domain": "statistics", "external_links": ["https://i.sstatic.net/Z4d1Pytm.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": "hydrologist", "question_author_url": "https://stats.stackexchange.com/users/21167/hydrologist", "question_author_user_type": "registered", "question_created_at": "2026-09-17T07:42:41+00:00", "question_html": "

I work in a field (hydrology) where many practitioners (and others) treat time series as though they were a series of random variables - that is, they ignore the structure in the series and have little understanding of why it is important. Of course I know why there is a difference and what the consequences are, but most of the explanations of that I can find are mathematical - or at least mathematical enough that they are incomprehensible to non-mathematically minded people.

\n

So, what are the simplest explanations of the difference that would be accessible to non-mathematicians and would make it immediately obvious that they need to be treated differently?

\n

I am looking for a way to be able to explain this to a lay-person and so any ideas would be much appreciated.

\n", "question_id": 677186, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "I work in a field (hydrology) where many practitioners (and others) treat time series as though they were a series of random variables - that is, they ignore the structure in the series and have little understanding of why it is important. Of course I know why there is a difference and what the consequences are, but most of the explanations of that I can find are mathematical - or at least mathematical enough that they are incomprehensible to non-mathematically minded people.\n\n\n\n\nSo, what are the simplest explanations of the difference that would be accessible to non-mathematicians and would make it immediately obvious that they need to be treated differently?\n\n\n\n\nI am looking for a way to be able to explain this to a lay-person and so any ideas would be much appreciated.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "hydrologist", "profile_url": "https://stats.stackexchange.com/users/21167/hydrologist", "user_type": "registered"}, "created_at": "2026-09-17T07:42:41+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "C69CE7BA-AF0E-4293-B341-D468AABCDAE2", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C69CE7BA-AF0E-4293-B341-D468AABCDAE2/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-17T15:54:01+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "FF23831A-1DEA-41EC-812E-FF18BFA375F9", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/FF23831A-1DEA-41EC-812E-FF18BFA375F9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "hydrologist", "profile_url": "https://stats.stackexchange.com/users/21167/hydrologist", "user_type": "registered"}, "created_at": "2026-09-18T09:06:15+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "64F3D18E-D094-414A-B349-447B0185577D", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/64F3D18E-D094-414A-B349-447B0185577D/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677186/why-is-a-time-series-different-from-a-set-of-random-variables", "split": "train", "split_group": "d15a453ac15794d24e0854041879a6d11e5869b41249eb87348e9bc1b4de3d8f", "tags": ["time-series", "random-variable", "communication"], "thread_id": "stats:677186", "title": "Why is a time series different from a set of random variables?"}} +{"accepted_answer": {"answer_html": "

I don't think you can recover the bivariate correlation $r(y,x_1)$ from the unstandardized coefficients, unless I am missing something.

\n

We can get the standardized $\\beta$s:

\n

$$\\beta_1^* = b_1 \\cdot \\frac{SD_{x1}}{SD_y}$$

\n

The we have:

\n

$$\\begin{pmatrix} 1 & r_{12} \\\\ r_{12} & 1 \\end{pmatrix} \\begin{pmatrix} \\beta_1^* \\\\ \\beta_2^* \\end{pmatrix} = \\begin{pmatrix} r_{y1} \\\\ r_{y2} \\end{pmatrix}$$

\n

If we solve this for $r_{y1}$:

\n

$$r_{y1} = \\beta_1^* + \\beta_2^* r_{12}$$

\n

We have $\\beta_1^*$ and $\\beta_2^*$ but not $r_{12}$, so the system is underdetermined. Without $r_{12}$ we cannot recover $r_{y1}$.

\n

You can recover coefficient of determination $R^2$:

\n

$$R^2 = \\beta_1^* r_{y1} + \\beta_2^* r_{y2}$$

\n

and if the paper reports $R^2$, that gives us one additional equation but with two unknowns ($r_{y1}$ and $r_{y2}$).

\n

If the paper describes the predictors as weakly correlated, we can assume $r_{12} \\approx 0$ getting $r_{y1} \\approx \\beta_1^*$, but you cannot recover the exact value without additional information.

\n", "answer_id": 677196, "answer_text": "I don't think you can recover the bivariate correlation $r(y,x_1)$ from the unstandardized coefficients, unless I am missing something.\n\n\n\n\nWe can get the standardized $\\beta$s:\n\n\n\n\n$$\\beta_1^* = b_1 \\cdot \\frac{SD_{x1}}{SD_y}$$\n\n\n\n\nThe we have:\n\n\n\n\n$$\\begin{pmatrix} 1 & r_{12} \\\\ r_{12} & 1 \\end{pmatrix} \\begin{pmatrix} \\beta_1^* \\\\ \\beta_2^* \\end{pmatrix} = \\begin{pmatrix} r_{y1} \\\\ r_{y2} \\end{pmatrix}$$\n\n\n\n\nIf we solve this for $r_{y1}$:\n\n\n\n\n$$r_{y1} = \\beta_1^* + \\beta_2^* r_{12}$$\n\n\n\n\nWe have $\\beta_1^*$ and $\\beta_2^*$ but not $r_{12}$, so the system is underdetermined. Without $r_{12}$ we cannot recover $r_{y1}$.\n\n\n\n\nYou can recover coefficient of determination $R^2$:\n\n\n\n\n$$R^2 = \\beta_1^* r_{y1} + \\beta_2^* r_{y2}$$\n\n\n\n\nand if the paper reports $R^2$, that gives us one additional equation but with two unknowns ($r_{y1}$ and $r_{y2}$).\n\n\n\n\nIf the paper describes the predictors as weakly correlated, we can assume $r_{12} \\approx 0$ getting $r_{y1} \\approx \\beta_1^*$, but you cannot recover the exact value without additional information.", "answer_url": "https://stats.stackexchange.com/a/677196", "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-09-17T19:43:31+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": 677193, "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-09-17T19:43:31+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B08F8332-9826-45E3-8DC8-649B4E616404", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B08F8332-9826-45E3-8DC8-649B4E616404/view-source"}], "score": 8, "updated_at": "2026-09-17T19:43:31+00:00"}, "other_answers": [{"answer_html": "

First of all, there should be an assortment of threads on this site that can help you with partial / semipartial correlation coefficients vis a vis multiple regression. This might be a good place to start: https://stats.stackexchange.com/a/76819/97844. In general, you can search questions tagged correlation.

\n

Unfortunately, I don't think you'll be able to derive the raw product-moment (Pearson) correlation between $Y$ and $X_1$ from that information. Though you can write down the equation in several different ways (depending upon how the computation is carried out), you're going to need the actual data points. For example, computing from a sample, the computational formula that I used to teach to my undergrad students is:

\n

$$\nr_{xy}={\\frac {\\sum _{i}x_{i}y_{i}-n{\\bar {x}}{\\bar {y}}}{{\\sqrt {\\sum _{i}x_{i}^{2}-n{\\bar {x}}^{2}}}~{\\sqrt {\\sum _{i}y_{i}^{2}-n{\\bar {y}}^{2}}}}}\n$$

\n

So at the very least, in addition to the means ($\\bar{x}$ and $\\bar{y}$) you'd need the actual products between each $x$ and $y$ for all pairs. The denominators are the square roots of the individual $SS$ for each variable, which you might be able to work out from descriptive statistics, but again, unless you have the actual data-points, computing the numerator will be impossible.

\n

In addition, it's not clear of what use the raw correlation would be, especially if the (linear) relationship between $X_2$ and $Y$ is notable. Think of it this way, looking at the data in a two dimensional space (just $X_1$ and $Y$) can be misleading in the sense that the multiple regression model is a model of the data in a higher-dimensional space. In that space, the original linear relationship may look much different because now, a second dimension is at play, and, intuitively, you're looking at the data through a completely different lens. If the two variables are independent, then this extra complexity won't alter the raw correlation, but the main reason we use multiple regression is because we often deal with two variables that are correlated, or with an $X$ and $Y$ that have a marginal correlation, but are conditionally independent.

\n

So the bottom line is that I don't know that I would recommend trying to do what you want to do.

\n", "answer_id": 677195, "answer_text": "First of all, there should be an assortment of threads on this site that can help you with partial / semipartial correlation coefficients vis a vis multiple regression. This might be a good place to start: https://stats.stackexchange.com/a/76819/97844 (https://stats.stackexchange.com/a/76819/97844). In general, you can search questions tagged correlation (/questions/tagged/correlation).\n\n\n\n\nUnfortunately, I don't think you'll be able to derive the raw product-moment (Pearson) correlation between $Y$ and $X_1$ from that information. Though you can write down the equation in several different ways (https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#Definition) (depending upon how the computation is carried out), you're going to need the actual data points. For example, computing from a sample, the computational formula that I used to teach to my undergrad students is:\n\n\n\n\n$$\nr_{xy}={\\frac {\\sum _{i}x_{i}y_{i}-n{\\bar {x}}{\\bar {y}}}{{\\sqrt {\\sum _{i}x_{i}^{2}-n{\\bar {x}}^{2}}}~{\\sqrt {\\sum _{i}y_{i}^{2}-n{\\bar {y}}^{2}}}}}\n$$\n\n\n\n\nSo at the very least, in addition to the means ($\\bar{x}$ and $\\bar{y}$) you'd need the actual products between each $x$ and $y$ for all pairs. The denominators are the square roots of the individual $SS$ for each variable, which you might be able to work out from descriptive statistics, but again, unless you have the actual data-points, computing the numerator will be impossible.\n\n\n\n\nIn addition, it's not clear of what use the raw correlation would be, especially if the (linear) relationship between $X_2$ and $Y$ is notable. Think of it this way, looking at the data in a two dimensional space (just $X_1$ and $Y$) can be misleading in the sense that the multiple regression model is a model of the data in a higher-dimensional space. In that space, the original linear relationship may look much different because now, a second dimension is at play, and, intuitively, you're looking at the data through a completely different lens. If the two variables are independent, then this extra complexity won't alter the raw correlation, but the main reason we use multiple regression is because we often deal with two variables that are correlated, or with an $X$ and $Y$ that have a marginal correlation, but are conditionally independent.\n\n\n\n\nSo the bottom line is that I don't know that I would recommend trying to do what you want to do.", "answer_url": "https://stats.stackexchange.com/a/677195", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T19:33:22+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": 677193, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-17T19:33:22+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "8823AFBC-99DE-491B-909B-E1B60CC0F1BD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8823AFBC-99DE-491B-909B-E1B60CC0F1BD/view-source"}], "score": 6, "updated_at": "2026-09-17T19:33:22+00:00"}], "product": "statistics_qa", "question": "I am trying to derive (or at least estimate) the correlation coefficient from a paper that only reports the multivariate betas.\n\n\n\n\nFor example I have the equation $y \\sim b_1x_1 + b_2x_2$. I would like to know the correlation coefficient $r$ between $y$ and $x_1$.\n\n\n\n\nUnfortunately the paper does not report the correlation between $x_1$ and $x_2$ or $y$ and $x_2$, but does report the means and standard deviations.\n\n\n\n\nI was reading that the standardized beta is similar to the semi-partial correlation coefficient but am having trouble moving forward from there.", "record_id": "Scientific-Statistics-QA:stats:677193", "selected_answer": {"answer_html": "

I don't think you can recover the bivariate correlation $r(y,x_1)$ from the unstandardized coefficients, unless I am missing something.

\n

We can get the standardized $\\beta$s:

\n

$$\\beta_1^* = b_1 \\cdot \\frac{SD_{x1}}{SD_y}$$

\n

The we have:

\n

$$\\begin{pmatrix} 1 & r_{12} \\\\ r_{12} & 1 \\end{pmatrix} \\begin{pmatrix} \\beta_1^* \\\\ \\beta_2^* \\end{pmatrix} = \\begin{pmatrix} r_{y1} \\\\ r_{y2} \\end{pmatrix}$$

\n

If we solve this for $r_{y1}$:

\n

$$r_{y1} = \\beta_1^* + \\beta_2^* r_{12}$$

\n

We have $\\beta_1^*$ and $\\beta_2^*$ but not $r_{12}$, so the system is underdetermined. Without $r_{12}$ we cannot recover $r_{y1}$.

\n

You can recover coefficient of determination $R^2$:

\n

$$R^2 = \\beta_1^* r_{y1} + \\beta_2^* r_{y2}$$

\n

and if the paper reports $R^2$, that gives us one additional equation but with two unknowns ($r_{y1}$ and $r_{y2}$).

\n

If the paper describes the predictors as weakly correlated, we can assume $r_{12} \\approx 0$ getting $r_{y1} \\approx \\beta_1^*$, but you cannot recover the exact value without additional information.

\n", "answer_id": 677196, "answer_text": "I don't think you can recover the bivariate correlation $r(y,x_1)$ from the unstandardized coefficients, unless I am missing something.\n\n\n\n\nWe can get the standardized $\\beta$s:\n\n\n\n\n$$\\beta_1^* = b_1 \\cdot \\frac{SD_{x1}}{SD_y}$$\n\n\n\n\nThe we have:\n\n\n\n\n$$\\begin{pmatrix} 1 & r_{12} \\\\ r_{12} & 1 \\end{pmatrix} \\begin{pmatrix} \\beta_1^* \\\\ \\beta_2^* \\end{pmatrix} = \\begin{pmatrix} r_{y1} \\\\ r_{y2} \\end{pmatrix}$$\n\n\n\n\nIf we solve this for $r_{y1}$:\n\n\n\n\n$$r_{y1} = \\beta_1^* + \\beta_2^* r_{12}$$\n\n\n\n\nWe have $\\beta_1^*$ and $\\beta_2^*$ but not $r_{12}$, so the system is underdetermined. Without $r_{12}$ we cannot recover $r_{y1}$.\n\n\n\n\nYou can recover coefficient of determination $R^2$:\n\n\n\n\n$$R^2 = \\beta_1^* r_{y1} + \\beta_2^* r_{y2}$$\n\n\n\n\nand if the paper reports $R^2$, that gives us one additional equation but with two unknowns ($r_{y1}$ and $r_{y2}$).\n\n\n\n\nIf the paper describes the predictors as weakly correlated, we can assume $r_{12} \\approx 0$ getting $r_{y1} \\approx \\beta_1^*$, but you cannot recover the exact value without additional information.", "answer_url": "https://stats.stackexchange.com/a/677196", "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-09-17T19:43:31+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": 677193, "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-09-17T19:43:31+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B08F8332-9826-45E3-8DC8-649B4E616404", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B08F8332-9826-45E3-8DC8-649B4E616404/view-source"}], "score": 8, "updated_at": "2026-09-17T19:43:31+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677196, "answers": [{"answer_html": "

First of all, there should be an assortment of threads on this site that can help you with partial / semipartial correlation coefficients vis a vis multiple regression. This might be a good place to start: https://stats.stackexchange.com/a/76819/97844. In general, you can search questions tagged correlation.

\n

Unfortunately, I don't think you'll be able to derive the raw product-moment (Pearson) correlation between $Y$ and $X_1$ from that information. Though you can write down the equation in several different ways (depending upon how the computation is carried out), you're going to need the actual data points. For example, computing from a sample, the computational formula that I used to teach to my undergrad students is:

\n

$$\nr_{xy}={\\frac {\\sum _{i}x_{i}y_{i}-n{\\bar {x}}{\\bar {y}}}{{\\sqrt {\\sum _{i}x_{i}^{2}-n{\\bar {x}}^{2}}}~{\\sqrt {\\sum _{i}y_{i}^{2}-n{\\bar {y}}^{2}}}}}\n$$

\n

So at the very least, in addition to the means ($\\bar{x}$ and $\\bar{y}$) you'd need the actual products between each $x$ and $y$ for all pairs. The denominators are the square roots of the individual $SS$ for each variable, which you might be able to work out from descriptive statistics, but again, unless you have the actual data-points, computing the numerator will be impossible.

\n

In addition, it's not clear of what use the raw correlation would be, especially if the (linear) relationship between $X_2$ and $Y$ is notable. Think of it this way, looking at the data in a two dimensional space (just $X_1$ and $Y$) can be misleading in the sense that the multiple regression model is a model of the data in a higher-dimensional space. In that space, the original linear relationship may look much different because now, a second dimension is at play, and, intuitively, you're looking at the data through a completely different lens. If the two variables are independent, then this extra complexity won't alter the raw correlation, but the main reason we use multiple regression is because we often deal with two variables that are correlated, or with an $X$ and $Y$ that have a marginal correlation, but are conditionally independent.

\n

So the bottom line is that I don't know that I would recommend trying to do what you want to do.

\n", "answer_id": 677195, "answer_text": "First of all, there should be an assortment of threads on this site that can help you with partial / semipartial correlation coefficients vis a vis multiple regression. This might be a good place to start: https://stats.stackexchange.com/a/76819/97844 (https://stats.stackexchange.com/a/76819/97844). In general, you can search questions tagged correlation (/questions/tagged/correlation).\n\n\n\n\nUnfortunately, I don't think you'll be able to derive the raw product-moment (Pearson) correlation between $Y$ and $X_1$ from that information. Though you can write down the equation in several different ways (https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#Definition) (depending upon how the computation is carried out), you're going to need the actual data points. For example, computing from a sample, the computational formula that I used to teach to my undergrad students is:\n\n\n\n\n$$\nr_{xy}={\\frac {\\sum _{i}x_{i}y_{i}-n{\\bar {x}}{\\bar {y}}}{{\\sqrt {\\sum _{i}x_{i}^{2}-n{\\bar {x}}^{2}}}~{\\sqrt {\\sum _{i}y_{i}^{2}-n{\\bar {y}}^{2}}}}}\n$$\n\n\n\n\nSo at the very least, in addition to the means ($\\bar{x}$ and $\\bar{y}$) you'd need the actual products between each $x$ and $y$ for all pairs. The denominators are the square roots of the individual $SS$ for each variable, which you might be able to work out from descriptive statistics, but again, unless you have the actual data-points, computing the numerator will be impossible.\n\n\n\n\nIn addition, it's not clear of what use the raw correlation would be, especially if the (linear) relationship between $X_2$ and $Y$ is notable. Think of it this way, looking at the data in a two dimensional space (just $X_1$ and $Y$) can be misleading in the sense that the multiple regression model is a model of the data in a higher-dimensional space. In that space, the original linear relationship may look much different because now, a second dimension is at play, and, intuitively, you're looking at the data through a completely different lens. If the two variables are independent, then this extra complexity won't alter the raw correlation, but the main reason we use multiple regression is because we often deal with two variables that are correlated, or with an $X$ and $Y$ that have a marginal correlation, but are conditionally independent.\n\n\n\n\nSo the bottom line is that I don't know that I would recommend trying to do what you want to do.", "answer_url": "https://stats.stackexchange.com/a/677195", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-17T19:33:22+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": 677193, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-17T19:33:22+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "8823AFBC-99DE-491B-909B-E1B60CC0F1BD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/8823AFBC-99DE-491B-909B-E1B60CC0F1BD/view-source"}], "score": 6, "updated_at": "2026-09-17T19:33:22+00:00"}, {"answer_html": "

I don't think you can recover the bivariate correlation $r(y,x_1)$ from the unstandardized coefficients, unless I am missing something.

\n

We can get the standardized $\\beta$s:

\n

$$\\beta_1^* = b_1 \\cdot \\frac{SD_{x1}}{SD_y}$$

\n

The we have:

\n

$$\\begin{pmatrix} 1 & r_{12} \\\\ r_{12} & 1 \\end{pmatrix} \\begin{pmatrix} \\beta_1^* \\\\ \\beta_2^* \\end{pmatrix} = \\begin{pmatrix} r_{y1} \\\\ r_{y2} \\end{pmatrix}$$

\n

If we solve this for $r_{y1}$:

\n

$$r_{y1} = \\beta_1^* + \\beta_2^* r_{12}$$

\n

We have $\\beta_1^*$ and $\\beta_2^*$ but not $r_{12}$, so the system is underdetermined. Without $r_{12}$ we cannot recover $r_{y1}$.

\n

You can recover coefficient of determination $R^2$:

\n

$$R^2 = \\beta_1^* r_{y1} + \\beta_2^* r_{y2}$$

\n

and if the paper reports $R^2$, that gives us one additional equation but with two unknowns ($r_{y1}$ and $r_{y2}$).

\n

If the paper describes the predictors as weakly correlated, we can assume $r_{12} \\approx 0$ getting $r_{y1} \\approx \\beta_1^*$, but you cannot recover the exact value without additional information.

\n", "answer_id": 677196, "answer_text": "I don't think you can recover the bivariate correlation $r(y,x_1)$ from the unstandardized coefficients, unless I am missing something.\n\n\n\n\nWe can get the standardized $\\beta$s:\n\n\n\n\n$$\\beta_1^* = b_1 \\cdot \\frac{SD_{x1}}{SD_y}$$\n\n\n\n\nThe we have:\n\n\n\n\n$$\\begin{pmatrix} 1 & r_{12} \\\\ r_{12} & 1 \\end{pmatrix} \\begin{pmatrix} \\beta_1^* \\\\ \\beta_2^* \\end{pmatrix} = \\begin{pmatrix} r_{y1} \\\\ r_{y2} \\end{pmatrix}$$\n\n\n\n\nIf we solve this for $r_{y1}$:\n\n\n\n\n$$r_{y1} = \\beta_1^* + \\beta_2^* r_{12}$$\n\n\n\n\nWe have $\\beta_1^*$ and $\\beta_2^*$ but not $r_{12}$, so the system is underdetermined. Without $r_{12}$ we cannot recover $r_{y1}$.\n\n\n\n\nYou can recover coefficient of determination $R^2$:\n\n\n\n\n$$R^2 = \\beta_1^* r_{y1} + \\beta_2^* r_{y2}$$\n\n\n\n\nand if the paper reports $R^2$, that gives us one additional equation but with two unknowns ($r_{y1}$ and $r_{y2}$).\n\n\n\n\nIf the paper describes the predictors as weakly correlated, we can assume $r_{12} \\approx 0$ getting $r_{y1} \\approx \\beta_1^*$, but you cannot recover the exact value without additional information.", "answer_url": "https://stats.stackexchange.com/a/677196", "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-09-17T19:43:31+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": 677193, "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-09-17T19:43:31+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B08F8332-9826-45E3-8DC8-649B4E616404", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B08F8332-9826-45E3-8DC8-649B4E616404/view-source"}], "score": 8, "updated_at": "2026-09-17T19:43:31+00:00"}], "domain": "statistics", "external_links": ["https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#Definition"], "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": "Hank Lin", "question_author_url": "https://stats.stackexchange.com/users/212964/hank-lin", "question_author_user_type": "registered", "question_created_at": "2026-09-17T18:51:23+00:00", "question_html": "

I am trying to derive (or at least estimate) the correlation coefficient from a paper that only reports the multivariate betas.

\n

For example I have the equation $y \\sim b_1x_1 + b_2x_2$. I would like to know the correlation coefficient $r$ between $y$ and $x_1$.

\n

Unfortunately the paper does not report the correlation between $x_1$ and $x_2$ or $y$ and $x_2$, but does report the means and standard deviations.

\n

I was reading that the standardized beta is similar to the semi-partial correlation coefficient but am having trouble moving forward from there.

\n", "question_id": 677193, "question_license": "CC BY-SA 4.0", "question_score": 6, "question_text": "I am trying to derive (or at least estimate) the correlation coefficient from a paper that only reports the multivariate betas.\n\n\n\n\nFor example I have the equation $y \\sim b_1x_1 + b_2x_2$. I would like to know the correlation coefficient $r$ between $y$ and $x_1$.\n\n\n\n\nUnfortunately the paper does not report the correlation between $x_1$ and $x_2$ or $y$ and $x_2$, but does report the means and standard deviations.\n\n\n\n\nI was reading that the standardized beta is similar to the semi-partial correlation coefficient but am having trouble moving forward from there.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Hank Lin", "profile_url": "https://stats.stackexchange.com/users/212964/hank-lin", "user_type": "registered"}, "created_at": "2026-09-17T18:51:23+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "53C26E13-7399-4761-9402-23DBDAE89FF5", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/53C26E13-7399-4761-9402-23DBDAE89FF5/view-source"}, {"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-09-17T19:28:12+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "D07E9DCC-2B9A-4798-BD2D-1CB9AB439808", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D07E9DCC-2B9A-4798-BD2D-1CB9AB439808/view-source"}, {"content_license": null, "contributor": {"display_name": "kjetil b halvorsen", "profile_url": "https://stats.stackexchange.com/users/11887/kjetil-b-halvorsen", "user_type": "moderator"}, "created_at": "2026-09-17T19:42:47+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "2EFF21D0-AFBC-4342-8F34-6916D092B853", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2EFF21D0-AFBC-4342-8F34-6916D092B853/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-18T02:54:36+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "2BBD8FE2-9891-411D-93B2-B1EAD3DA4F49", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/2BBD8FE2-9891-411D-93B2-B1EAD3DA4F49/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677193/how-to-derive-the-correlation-coefficient-from-the-coefficients-in-multiple-line", "split": "train", "split_group": "7abcadccd1907fa3e7584381c8e2d8ce78f6a7c5184e86eeda5e0c027d51780a", "tags": ["correlation", "multiple-regression", "partial-correlation"], "thread_id": "stats:677193", "title": "How to derive the correlation coefficient from the coefficients in multiple linear regression?"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

The "classic" way to compare the variability of 2 sets of measurements taken on different scales is to use the CV (Coefficient of Variation (Variability), which is nothing more than $\\frac {sd} {\\bar x}$). There are even statistical tests for comparing CVs (e.g. Forkman's Test), which (obviously?) have attached assumptions.

\n

Now this works great for say, comparing the variability of highway lengths in kilometers with the variability of city street lengths taken in meters. Or even the variability of bus lengths, taken in feet, with the variability of motorcycle lengths, taken in inches (because the CV is unitless). But it will not work for comparing temperatures taken in degrees Celsius with temperatures taken in degrees Fahrenheit, or kelvin (because it is not only the scale which has changed, it is also the location, the meaning of $0$).

\n

Note that the CV is useful when the mean and sd are somehow independent parameters of the underlying distribution. E.g., for exponentially distributed data, the CV is always equal to 1 (?!). In cases when they are not independent, then directly comparing the parameters (e.g. $\\lambda$ for exponentials) makes more sense (or proportions for counts, etc...).

\n

In all the above examples, we are comparing apples with apples, just measured on different scales (with same origin).
\nIt is absolutely not clear that this is your case: you may be trying to compare apples with oranges. Do the two scales really measure the same thing? They may both say "patient satisfaction", but what "instrument(s?)" are they using? If the instruments are different (most likely?), then does comparing them even make sense? Would comparing kilometers of highway to kelvin temperatures make sense?
\nAlso, what does 100 mean? A single score on a Visual Analog Scale (VAS)? Or a sum of an unknown number of Likert scores? Or ??? What is 36? A count of positive answers on 36 questions? A sum of a different unknown number of Likert scores? Or ?? And does $0$ mean the same in the two cases? For the sum of Likert scores, there is not even a 0 (Likert scores are typically 1-5). So the 2 scales may not even have a $0$, or the same $0$. How about the questions? Were they the exact same, just scored differently, or were they different?
\nLast such scores beg the question of whether the mean and sd are even meaningful statistics: on the VAS, or counts, they would/could be. On a sum of Likert scores, many (myself included) would argue that they are not.

\n

So, while technically you could compare the CVs, w/o much more details about the 2 sets of measurements (which are in the 2 papers: maybe provide links to these 2 papers?), it is very hard to say whether this comparison would be useful.

\n", "answer_id": 677216, "answer_text": "The \"classic\" way to compare the variability of 2 sets of measurements taken on different scales is to use the CV (Coefficient of Variation (Variability), which is nothing more than $\\frac {sd} {\\bar x}$). There are even statistical tests for comparing CVs (e.g. Forkman's Test), which (obviously?) have attached assumptions.\n\n\n\n\nNow this works great for say, comparing the variability of highway lengths in kilometers with the variability of city street lengths taken in meters. Or even the variability of bus lengths, taken in feet, with the variability of motorcycle lengths, taken in inches (because the CV is unitless). But it will not work for comparing temperatures taken in degrees Celsius with temperatures taken in degrees Fahrenheit, or kelvin (because it is not only the scale which has changed, it is also the location, the meaning of $0$).\n\n\n\n\nNote that the CV is useful when the mean and sd are somehow independent parameters of the underlying distribution. E.g., for exponentially distributed data, the CV is always equal to 1 (?!). In cases when they are not independent, then directly comparing the parameters (e.g. $\\lambda$ for exponentials) makes more sense (or proportions for counts, etc...).\n\n\n\n\nIn all the above examples, we are comparing apples with apples, just measured on different scales (with same origin).\n\nIt is absolutely not clear that this is your case: you may be trying to compare apples with oranges. Do the two scales really measure the same thing? They may both say \"patient satisfaction\", but what \"instrument(s?)\" are they using? If the instruments are different (most likely?), then does comparing them even make sense? Would comparing kilometers of highway to kelvin temperatures make sense?\n\nAlso, what does 100 mean? A single score on a Visual Analog Scale (VAS)? Or a sum of an unknown number of Likert scores? Or ??? What is 36? A count of positive answers on 36 questions? A sum of a different unknown number of Likert scores? Or ?? And does $0$ mean the same in the two cases? For the sum of Likert scores, there is not even a 0 (Likert scores are typically 1-5). So the 2 scales may not even have a $0$, or the same $0$. How about the questions? Were they the exact same, just scored differently, or were they different?\n\nLast such scores beg the question of whether the mean and sd are even meaningful statistics: on the VAS, or counts, they would/could be. On a sum of Likert scores, many (myself included) would argue that they are not.\n\n\n\n\nSo, while technically you could compare the CVs, w/o much more details about the 2 sets of measurements (which are in the 2 papers: maybe provide links to these 2 papers?), it is very hard to say whether this comparison would be useful.", "answer_url": "https://stats.stackexchange.com/a/677216", "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-19T17:06:39+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": 677194, "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-19T17:06:39+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "DCF750BD-C31C-4D23-B59A-8F1B46106E82", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DCF750BD-C31C-4D23-B59A-8F1B46106E82/view-source"}, {"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-19T17:12:27+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "76BA20A6-0C8C-4C0D-9DBC-8DD8CE8823AF", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/76BA20A6-0C8C-4C0D-9DBC-8DD8CE8823AF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-19T18:03:25+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D1BF2DDF-7230-4CA9-919F-8A5E8FCE31DD", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D1BF2DDF-7230-4CA9-919F-8A5E8FCE31DD/view-source"}, {"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-19T20:16:52+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D6767CF1-3AA2-465D-8C60-05A8D265C6CB", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D6767CF1-3AA2-465D-8C60-05A8D265C6CB/view-source"}], "score": 4, "updated_at": "2026-09-19T20:16:52+00:00"}], "product": "statistics_qa", "question": "I am trying to compare the standard deviations of two samples which measure patient satisfaction on different scales. Scale 1 has a potential range from 0 to 100. Scale 2 has a potential range from 0 to 36.\n\n\n\n\nIf SD1 = A and SD2 = B, does it make sense to compare them by dividing by the potential range? Ie A / 100 vs B / 36?\n\n\n\n\nI was also reading about the coefficient of variation where instead you divide by the mean. I am not sure which makes more sense in my case.", "record_id": "Scientific-Statistics-QA:stats:677194", "selected_answer": {"answer_html": "

If the ratio of the means is not equal to about 100:36, then the ratings are probably not simply different scalings of the same underlying distribution. And if the ratio of means is the same as 100:36, you probably wouldn't be asking, and anyway you still can't be sure of much else. You need to know more about the data. For example, maybe you know these are counts of positive answers to 100 or 36 questions. Or something else that would let you make some approximate assumptions like how much of the variance within a score can be attribute to test noise. Sounds like you have an impossible task, unless you can convert both datasets back to a model of an underlying distribution. But if you just plot histograms of the data, maybe you can make a graphic comparison that makes it obvious if the spreads are very different, or makes it clear that they're not very different, without having to make a hard decision based on standard deviations.

\n

If you just want an answer to the original question of "which makes more sense", I'd say divide by the means. But then wouldn't some kind of comparison of means be a better thing to go after?

\n", "answer_id": 677200, "answer_text": "If the ratio of the means is not equal to about 100:36, then the ratings are probably not simply different scalings of the same underlying distribution. And if the ratio of means is the same as 100:36, you probably wouldn't be asking, and anyway you still can't be sure of much else. You need to know more about the data. For example, maybe you know these are counts of positive answers to 100 or 36 questions. Or something else that would let you make some approximate assumptions like how much of the variance within a score can be attribute to test noise. Sounds like you have an impossible task, unless you can convert both datasets back to a model of an underlying distribution. But if you just plot histograms of the data, maybe you can make a graphic comparison that makes it obvious if the spreads are very different, or makes it clear that they're not very different, without having to make a hard decision based on standard deviations.\n\n\n\n\nIf you just want an answer to the original question of \"which makes more sense\", I'd say divide by the means. But then wouldn't some kind of comparison of means be a better thing to go after?", "answer_url": "https://stats.stackexchange.com/a/677200", "author": "Richard Lyon", "author_url": "https://stats.stackexchange.com/users/516789/richard-lyon", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-18T02:11:37+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": 677194, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Richard Lyon", "profile_url": "https://stats.stackexchange.com/users/516789/richard-lyon", "user_type": "registered"}, "created_at": "2026-09-18T02:11:37+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "98536AC1-331C-41B5-919F-C5CA68DA8CF4", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/98536AC1-331C-41B5-919F-C5CA68DA8CF4/view-source"}], "score": 5, "updated_at": "2026-09-18T02:11:37+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

If the ratio of the means is not equal to about 100:36, then the ratings are probably not simply different scalings of the same underlying distribution. And if the ratio of means is the same as 100:36, you probably wouldn't be asking, and anyway you still can't be sure of much else. You need to know more about the data. For example, maybe you know these are counts of positive answers to 100 or 36 questions. Or something else that would let you make some approximate assumptions like how much of the variance within a score can be attribute to test noise. Sounds like you have an impossible task, unless you can convert both datasets back to a model of an underlying distribution. But if you just plot histograms of the data, maybe you can make a graphic comparison that makes it obvious if the spreads are very different, or makes it clear that they're not very different, without having to make a hard decision based on standard deviations.

\n

If you just want an answer to the original question of "which makes more sense", I'd say divide by the means. But then wouldn't some kind of comparison of means be a better thing to go after?

\n", "answer_id": 677200, "answer_text": "If the ratio of the means is not equal to about 100:36, then the ratings are probably not simply different scalings of the same underlying distribution. And if the ratio of means is the same as 100:36, you probably wouldn't be asking, and anyway you still can't be sure of much else. You need to know more about the data. For example, maybe you know these are counts of positive answers to 100 or 36 questions. Or something else that would let you make some approximate assumptions like how much of the variance within a score can be attribute to test noise. Sounds like you have an impossible task, unless you can convert both datasets back to a model of an underlying distribution. But if you just plot histograms of the data, maybe you can make a graphic comparison that makes it obvious if the spreads are very different, or makes it clear that they're not very different, without having to make a hard decision based on standard deviations.\n\n\n\n\nIf you just want an answer to the original question of \"which makes more sense\", I'd say divide by the means. But then wouldn't some kind of comparison of means be a better thing to go after?", "answer_url": "https://stats.stackexchange.com/a/677200", "author": "Richard Lyon", "author_url": "https://stats.stackexchange.com/users/516789/richard-lyon", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-18T02:11:37+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": 677194, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Richard Lyon", "profile_url": "https://stats.stackexchange.com/users/516789/richard-lyon", "user_type": "registered"}, "created_at": "2026-09-18T02:11:37+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "98536AC1-331C-41B5-919F-C5CA68DA8CF4", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/98536AC1-331C-41B5-919F-C5CA68DA8CF4/view-source"}], "score": 5, "updated_at": "2026-09-18T02:11:37+00:00"}, {"answer_html": "

The "classic" way to compare the variability of 2 sets of measurements taken on different scales is to use the CV (Coefficient of Variation (Variability), which is nothing more than $\\frac {sd} {\\bar x}$). There are even statistical tests for comparing CVs (e.g. Forkman's Test), which (obviously?) have attached assumptions.

\n

Now this works great for say, comparing the variability of highway lengths in kilometers with the variability of city street lengths taken in meters. Or even the variability of bus lengths, taken in feet, with the variability of motorcycle lengths, taken in inches (because the CV is unitless). But it will not work for comparing temperatures taken in degrees Celsius with temperatures taken in degrees Fahrenheit, or kelvin (because it is not only the scale which has changed, it is also the location, the meaning of $0$).

\n

Note that the CV is useful when the mean and sd are somehow independent parameters of the underlying distribution. E.g., for exponentially distributed data, the CV is always equal to 1 (?!). In cases when they are not independent, then directly comparing the parameters (e.g. $\\lambda$ for exponentials) makes more sense (or proportions for counts, etc...).

\n

In all the above examples, we are comparing apples with apples, just measured on different scales (with same origin).
\nIt is absolutely not clear that this is your case: you may be trying to compare apples with oranges. Do the two scales really measure the same thing? They may both say "patient satisfaction", but what "instrument(s?)" are they using? If the instruments are different (most likely?), then does comparing them even make sense? Would comparing kilometers of highway to kelvin temperatures make sense?
\nAlso, what does 100 mean? A single score on a Visual Analog Scale (VAS)? Or a sum of an unknown number of Likert scores? Or ??? What is 36? A count of positive answers on 36 questions? A sum of a different unknown number of Likert scores? Or ?? And does $0$ mean the same in the two cases? For the sum of Likert scores, there is not even a 0 (Likert scores are typically 1-5). So the 2 scales may not even have a $0$, or the same $0$. How about the questions? Were they the exact same, just scored differently, or were they different?
\nLast such scores beg the question of whether the mean and sd are even meaningful statistics: on the VAS, or counts, they would/could be. On a sum of Likert scores, many (myself included) would argue that they are not.

\n

So, while technically you could compare the CVs, w/o much more details about the 2 sets of measurements (which are in the 2 papers: maybe provide links to these 2 papers?), it is very hard to say whether this comparison would be useful.

\n", "answer_id": 677216, "answer_text": "The \"classic\" way to compare the variability of 2 sets of measurements taken on different scales is to use the CV (Coefficient of Variation (Variability), which is nothing more than $\\frac {sd} {\\bar x}$). There are even statistical tests for comparing CVs (e.g. Forkman's Test), which (obviously?) have attached assumptions.\n\n\n\n\nNow this works great for say, comparing the variability of highway lengths in kilometers with the variability of city street lengths taken in meters. Or even the variability of bus lengths, taken in feet, with the variability of motorcycle lengths, taken in inches (because the CV is unitless). But it will not work for comparing temperatures taken in degrees Celsius with temperatures taken in degrees Fahrenheit, or kelvin (because it is not only the scale which has changed, it is also the location, the meaning of $0$).\n\n\n\n\nNote that the CV is useful when the mean and sd are somehow independent parameters of the underlying distribution. E.g., for exponentially distributed data, the CV is always equal to 1 (?!). In cases when they are not independent, then directly comparing the parameters (e.g. $\\lambda$ for exponentials) makes more sense (or proportions for counts, etc...).\n\n\n\n\nIn all the above examples, we are comparing apples with apples, just measured on different scales (with same origin).\n\nIt is absolutely not clear that this is your case: you may be trying to compare apples with oranges. Do the two scales really measure the same thing? They may both say \"patient satisfaction\", but what \"instrument(s?)\" are they using? If the instruments are different (most likely?), then does comparing them even make sense? Would comparing kilometers of highway to kelvin temperatures make sense?\n\nAlso, what does 100 mean? A single score on a Visual Analog Scale (VAS)? Or a sum of an unknown number of Likert scores? Or ??? What is 36? A count of positive answers on 36 questions? A sum of a different unknown number of Likert scores? Or ?? And does $0$ mean the same in the two cases? For the sum of Likert scores, there is not even a 0 (Likert scores are typically 1-5). So the 2 scales may not even have a $0$, or the same $0$. How about the questions? Were they the exact same, just scored differently, or were they different?\n\nLast such scores beg the question of whether the mean and sd are even meaningful statistics: on the VAS, or counts, they would/could be. On a sum of Likert scores, many (myself included) would argue that they are not.\n\n\n\n\nSo, while technically you could compare the CVs, w/o much more details about the 2 sets of measurements (which are in the 2 papers: maybe provide links to these 2 papers?), it is very hard to say whether this comparison would be useful.", "answer_url": "https://stats.stackexchange.com/a/677216", "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-19T17:06:39+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": 677194, "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-19T17:06:39+00:00", "raw_file": "raw/codex_api_v1/13b5f879587b71b34c0837bee317816dcd540d0ad5983f88cf56c19d10104c79_1790825261079646600_0.json", "raw_sha256": "0a63637f2455a28a1e691dd3090d34ef9975e6c8bdc2c5c883414d7215eb5972", "revision_guid": "DCF750BD-C31C-4D23-B59A-8F1B46106E82", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DCF750BD-C31C-4D23-B59A-8F1B46106E82/view-source"}, {"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-19T17:12:27+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "76BA20A6-0C8C-4C0D-9DBC-8DD8CE8823AF", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/76BA20A6-0C8C-4C0D-9DBC-8DD8CE8823AF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-19T18:03:25+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D1BF2DDF-7230-4CA9-919F-8A5E8FCE31DD", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D1BF2DDF-7230-4CA9-919F-8A5E8FCE31DD/view-source"}, {"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-19T20:16:52+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D6767CF1-3AA2-465D-8C60-05A8D265C6CB", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D6767CF1-3AA2-465D-8C60-05A8D265C6CB/view-source"}], "score": 4, "updated_at": "2026-09-19T20:16:52+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Hank Lin", "question_author_url": "https://stats.stackexchange.com/users/212964/hank-lin", "question_author_user_type": "registered", "question_created_at": "2026-09-17T19:04:14+00:00", "question_html": "

I am trying to compare the standard deviations of two samples which measure patient satisfaction on different scales. Scale 1 has a potential range from 0 to 100. Scale 2 has a potential range from 0 to 36.

\n

If SD1 = A and SD2 = B, does it make sense to compare them by dividing by the potential range? Ie A / 100 vs B / 36?

\n

I was also reading about the coefficient of variation where instead you divide by the mean. I am not sure which makes more sense in my case.

\n", "question_id": 677194, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "I am trying to compare the standard deviations of two samples which measure patient satisfaction on different scales. Scale 1 has a potential range from 0 to 100. Scale 2 has a potential range from 0 to 36.\n\n\n\n\nIf SD1 = A and SD2 = B, does it make sense to compare them by dividing by the potential range? Ie A / 100 vs B / 36?\n\n\n\n\nI was also reading about the coefficient of variation where instead you divide by the mean. I am not sure which makes more sense in my case.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Hank Lin", "profile_url": "https://stats.stackexchange.com/users/212964/hank-lin", "user_type": "registered"}, "created_at": "2026-09-17T19:04:14+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B2BF101C-A5BE-4BCE-8874-6B809733F1CF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B2BF101C-A5BE-4BCE-8874-6B809733F1CF/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-19T17:11:03+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "27996B34-EADF-4303-B130-F62799122E1A", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/27996B34-EADF-4303-B130-F62799122E1A/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-19T17:59:01+00:00", "raw_file": "raw/codex_api_v1/59f98009db0ac38325a869c60e3993040b07f5fbd07014051415831400b70d25_1790825251781774200_0.json", "raw_sha256": "2876465103b1eeb5d593dd46b1ec52a862c1da72f8e4767e5f8ee70ff0564119", "revision_guid": "B50CFBC8-7D87-460C-ACAD-13D57C24247E", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B50CFBC8-7D87-460C-ACAD-13D57C24247E/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677194/how-to-compare-spread-dispersion-from-two-samples-using-different-scales", "split": "train", "split_group": "6f04b02c4e3cc9d9b275af91f8e3dc20a0f7d53110d9a2d38af14010668464ab", "tags": ["standard-deviation", "scales", "coefficient-of-variation"], "thread_id": "stats:677194", "title": "How to compare spread/dispersion from two samples using different scales?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I’m currently using a mixed-effects model to compare four different cell culture groups and assess whether characteristics such as firing rate differ between groups over time.\n\n\n\n\nThe main complication is that the groups have very different observation periods. Three groups were recorded every few days for approximately 100 days in vitro, whereas one group (organoids) was recorded for substantially longer, up to ~500 days in vitro. This difference is biological rather than due to missing data, as the organoids survived and remain recordable for much longer than the monolayer cultures.\n\n\n\n\nMy current model accounts for repeated measurements from the same biological culture and includes day/time as a predictor. However, I’m concerned that the much longer observation period for the organoid group could disproportionately influence the estimated group differences.\n\nWould a mixed-effects model still be appropriate in this situation? If so, what would be the most appropriate way to model or estimate the differences between groups while accounting for their unequal observation periods? I would prefer not to restricting the analysis to the common day ranges.\n\n\n\n\nAn alternative I’ve considered is simply comparing the mean values across groups, effectively ignoring days in vitro. However, this seems like it could be problematic because the characteristics change substantially over time, and the groups may have different temporal trajectories.\n\n\n\n\nI’d particularly appreciate advice on how to make a statistically valid comparison between the groups given that one group has observations extending much further in time than the others.\n\n\n\n\nWould a mixed effects model be appropriate in this case, and if yes, is there any method I can use to estimate the differences between the cell types properly despite the significantly different observation periods?\n\n\n\n\nAnother method that I’m thinking of is to just compare the mean values across the cell types to leave out the effects of div, however, this method may not be as accurate and statistically appropriate compared to using a mixed effects model", "record_id": "Scientific-Statistics-QA:stats:677217", "selected_answer": {"answer_html": "

If you expect the trajectories to differ over time among the 4 groups, include in your model an interaction term between days in vitro (DIV) and time. Without an interaction, your model would force all groups to have the same trajectory over time, which doesn't seem to comport with your understanding of the biology. Also, without an interaction, all you would compare among groups would be something related to mean firing rates, or to estimated firing rate at DIV = 0 (or at some other reference time). With an interaction term you get a separate trajectory for each group. The monolayer cultures would simply not have trajectories beyond the times that they were terminated, and you should still get a trajectory for the organoids out to 500 DIV.

\n

It would be best to model DIV flexibly, for example with a restricted cubic spline or other generalized additive model. That's a useful middle ground between a (highly unlikely) strictly linear association of firing rate with time and modeling each time point separately.

\n

Depending on your type of data, you might be able to use generalized least squares instead of a mixed model to handle the intra-group correlations. That provides more flexibility than a typical mixed model in terms of the correlation structure over time. Chapter 7 of Frank Harrell's Regression Modeling Strategies illustrates that approach. Even if you stay with a mixed model, much in that Chapter should be informative.

\n

I have some question about what you hope to gain by comparing the organoids against the monolayer cultures, as they are substantially different in geometry and biology. The above would still hold, however, if you restricted comparisons to 3 monolayer groups that were observed for different time durations.

\n", "answer_id": 677224, "answer_text": "If you expect the trajectories to differ over time among the 4 groups, include in your model an interaction term between days in vitro (DIV) and time. Without an interaction, your model would force all groups to have the same trajectory over time, which doesn't seem to comport with your understanding of the biology. Also, without an interaction, all you would compare among groups would be something related to mean firing rates, or to estimated firing rate at DIV = 0 (or at some other reference time). With an interaction term you get a separate trajectory for each group. The monolayer cultures would simply not have trajectories beyond the times that they were terminated, and you should still get a trajectory for the organoids out to 500 DIV.\n\n\n\n\nIt would be best to model DIV flexibly, for example with a restricted cubic spline (https://stats.stackexchange.com/questions/tagged/splines) or other generalized additive model (https://stats.stackexchange.com/questions/tagged/generalized-additive-model). That's a useful middle ground between a (highly unlikely) strictly linear association of firing rate with time and modeling each time point separately.\n\n\n\n\nDepending on your type of data, you might be able to use generalized least squares (https://stats.stackexchange.com/questions/tagged/generalized-least-squares) instead of a mixed model to handle the intra-group correlations. That provides more flexibility than a typical mixed model in terms of the correlation structure over time. Chapter 7 of Frank Harrell's Regression Modeling Strategies (https://hbiostat.org/rmsc/long) illustrates that approach. Even if you stay with a mixed model, much in that Chapter should be informative.\n\n\n\n\nI have some question about what you hope to gain by comparing the organoids against the monolayer cultures, as they are substantially different in geometry and biology. The above would still hold, however, if you restricted comparisons to 3 monolayer groups that were observed for different time durations.", "answer_url": "https://stats.stackexchange.com/a/677224", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-20T17:08:33+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": 677217, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-20T17:08:33+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "B4413AC5-1099-445B-BF8F-3AC6626FF967", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B4413AC5-1099-445B-BF8F-3AC6626FF967/view-source"}], "score": 3, "updated_at": "2026-09-20T17:08:33+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

If you expect the trajectories to differ over time among the 4 groups, include in your model an interaction term between days in vitro (DIV) and time. Without an interaction, your model would force all groups to have the same trajectory over time, which doesn't seem to comport with your understanding of the biology. Also, without an interaction, all you would compare among groups would be something related to mean firing rates, or to estimated firing rate at DIV = 0 (or at some other reference time). With an interaction term you get a separate trajectory for each group. The monolayer cultures would simply not have trajectories beyond the times that they were terminated, and you should still get a trajectory for the organoids out to 500 DIV.

\n

It would be best to model DIV flexibly, for example with a restricted cubic spline or other generalized additive model. That's a useful middle ground between a (highly unlikely) strictly linear association of firing rate with time and modeling each time point separately.

\n

Depending on your type of data, you might be able to use generalized least squares instead of a mixed model to handle the intra-group correlations. That provides more flexibility than a typical mixed model in terms of the correlation structure over time. Chapter 7 of Frank Harrell's Regression Modeling Strategies illustrates that approach. Even if you stay with a mixed model, much in that Chapter should be informative.

\n

I have some question about what you hope to gain by comparing the organoids against the monolayer cultures, as they are substantially different in geometry and biology. The above would still hold, however, if you restricted comparisons to 3 monolayer groups that were observed for different time durations.

\n", "answer_id": 677224, "answer_text": "If you expect the trajectories to differ over time among the 4 groups, include in your model an interaction term between days in vitro (DIV) and time. Without an interaction, your model would force all groups to have the same trajectory over time, which doesn't seem to comport with your understanding of the biology. Also, without an interaction, all you would compare among groups would be something related to mean firing rates, or to estimated firing rate at DIV = 0 (or at some other reference time). With an interaction term you get a separate trajectory for each group. The monolayer cultures would simply not have trajectories beyond the times that they were terminated, and you should still get a trajectory for the organoids out to 500 DIV.\n\n\n\n\nIt would be best to model DIV flexibly, for example with a restricted cubic spline (https://stats.stackexchange.com/questions/tagged/splines) or other generalized additive model (https://stats.stackexchange.com/questions/tagged/generalized-additive-model). That's a useful middle ground between a (highly unlikely) strictly linear association of firing rate with time and modeling each time point separately.\n\n\n\n\nDepending on your type of data, you might be able to use generalized least squares (https://stats.stackexchange.com/questions/tagged/generalized-least-squares) instead of a mixed model to handle the intra-group correlations. That provides more flexibility than a typical mixed model in terms of the correlation structure over time. Chapter 7 of Frank Harrell's Regression Modeling Strategies (https://hbiostat.org/rmsc/long) illustrates that approach. Even if you stay with a mixed model, much in that Chapter should be informative.\n\n\n\n\nI have some question about what you hope to gain by comparing the organoids against the monolayer cultures, as they are substantially different in geometry and biology. The above would still hold, however, if you restricted comparisons to 3 monolayer groups that were observed for different time durations.", "answer_url": "https://stats.stackexchange.com/a/677224", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-20T17:08:33+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": 677217, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-20T17:08:33+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "B4413AC5-1099-445B-BF8F-3AC6626FF967", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/B4413AC5-1099-445B-BF8F-3AC6626FF967/view-source"}], "score": 3, "updated_at": "2026-09-20T17:08:33+00:00"}], "domain": "statistics", "external_links": ["https://hbiostat.org/rmsc/long"], "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": "Jade", "question_author_url": "https://stats.stackexchange.com/users/512867/jade", "question_author_user_type": "registered", "question_created_at": "2026-09-20T05:48:21+00:00", "question_html": "

I’m currently using a mixed-effects model to compare four different cell culture groups and assess whether characteristics such as firing rate differ between groups over time.

\n

The main complication is that the groups have very different observation periods. Three groups were recorded every few days for approximately 100 days in vitro, whereas one group (organoids) was recorded for substantially longer, up to ~500 days in vitro. This difference is biological rather than due to missing data, as the organoids survived and remain recordable for much longer than the monolayer cultures.

\n

My current model accounts for repeated measurements from the same biological culture and includes day/time as a predictor. However, I’m concerned that the much longer observation period for the organoid group could disproportionately influence the estimated group differences.
\nWould a mixed-effects model still be appropriate in this situation? If so, what would be the most appropriate way to model or estimate the differences between groups while accounting for their unequal observation periods? I would prefer not to restricting the analysis to the common day ranges.

\n

An alternative I’ve considered is simply comparing the mean values across groups, effectively ignoring days in vitro. However, this seems like it could be problematic because the characteristics change substantially over time, and the groups may have different temporal trajectories.

\n

I’d particularly appreciate advice on how to make a statistically valid comparison between the groups given that one group has observations extending much further in time than the others.

\n

Would a mixed effects model be appropriate in this case, and if yes, is there any method I can use to estimate the differences between the cell types properly despite the significantly different observation periods?

\n

Another method that I’m thinking of is to just compare the mean values across the cell types to leave out the effects of div, however, this method may not be as accurate and statistically appropriate compared to using a mixed effects model

\n", "question_id": 677217, "question_license": "CC BY-SA 4.0", "question_score": 6, "question_text": "I’m currently using a mixed-effects model to compare four different cell culture groups and assess whether characteristics such as firing rate differ between groups over time.\n\n\n\n\nThe main complication is that the groups have very different observation periods. Three groups were recorded every few days for approximately 100 days in vitro, whereas one group (organoids) was recorded for substantially longer, up to ~500 days in vitro. This difference is biological rather than due to missing data, as the organoids survived and remain recordable for much longer than the monolayer cultures.\n\n\n\n\nMy current model accounts for repeated measurements from the same biological culture and includes day/time as a predictor. However, I’m concerned that the much longer observation period for the organoid group could disproportionately influence the estimated group differences.\n\nWould a mixed-effects model still be appropriate in this situation? If so, what would be the most appropriate way to model or estimate the differences between groups while accounting for their unequal observation periods? I would prefer not to restricting the analysis to the common day ranges.\n\n\n\n\nAn alternative I’ve considered is simply comparing the mean values across groups, effectively ignoring days in vitro. However, this seems like it could be problematic because the characteristics change substantially over time, and the groups may have different temporal trajectories.\n\n\n\n\nI’d particularly appreciate advice on how to make a statistically valid comparison between the groups given that one group has observations extending much further in time than the others.\n\n\n\n\nWould a mixed effects model be appropriate in this case, and if yes, is there any method I can use to estimate the differences between the cell types properly despite the significantly different observation periods?\n\n\n\n\nAnother method that I’m thinking of is to just compare the mean values across the cell types to leave out the effects of div, however, this method may not be as accurate and statistically appropriate compared to using a mixed effects model", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Jade", "profile_url": "https://stats.stackexchange.com/users/512867/jade", "user_type": "registered"}, "created_at": "2026-09-20T05:48:21+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "97DB7D61-A981-47AE-B277-A96D6E0909CB", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/97DB7D61-A981-47AE-B277-A96D6E0909CB/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Jade", "profile_url": "https://stats.stackexchange.com/users/512867/jade", "user_type": "registered"}, "created_at": "2026-09-20T05:56:42+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "4A2119CF-AB90-413E-816B-EFCBC545C211", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/4A2119CF-AB90-413E-816B-EFCBC545C211/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Jade", "profile_url": "https://stats.stackexchange.com/users/512867/jade", "user_type": "registered"}, "created_at": "2026-09-20T06:10:06+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "7A3CF930-6CE6-4683-8559-75A71C630B88", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7A3CF930-6CE6-4683-8559-75A71C630B88/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-20T17:11:48+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "45ACAE04-01FB-4DDA-8E02-A3127F807F7C", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/45ACAE04-01FB-4DDA-8E02-A3127F807F7C/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677217/mixed-effects-model-with-unequal-observation-periods-between-groups", "split": "train", "split_group": "f0b32e09d060376517a78e33c3995b1c0b7ccc78d3c44ef1524e0cefa6d89684", "tags": ["mixed-model", "biostatistics"], "thread_id": "stats:677217", "title": "Mixed-effects model with unequal observation periods between groups"}} +{"accepted_answer": {"answer_html": "

No you can not estimate the $\\theta_i$ variance for $k = 1$. The relevant concept is the beta-binomial distribution(https://en.wikipedia.org/wiki/Beta-binomial_distribution). Now we are keeping $\\mu$ fixed and just consider $\\alpha + \\beta$ as a variable then for very large $\\alpha + \\beta$ this basically just the binomial distribution while if it's close to $0$ you end up with basically a Bernoulli-distribution over $\\{0, k\\}$. Of course for $k = 1$ those two are the same thing so there's no way to distinguish any $\\alpha + \\beta$ as long as they have same $\\mu$.

\n

Here's a plot in R:

\n
library(extraDistr)\npars <- exp(seq(-10, 10, length.out = 10))\nmu <- 0.6\nk <- 10\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = "b", \n     col = "red", lwd = 4, ylim = c(0, mu), main = paste0("k = ", k))\nfor(par in pars){\n  points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = "b")\n}\n\nk <- 1\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = "b", \n     col = "red", lwd = 4, ylim = c(0, mu), main = paste0("k = ", k))\nfor(par in pars){\n  points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = "b")\n}\n\n
\n

\"plot\n\"plot

\n", "answer_id": 677231, "answer_text": "No you can not estimate the $\\theta_i$ variance for $k = 1$. The relevant concept is the beta-binomial distribution(https://en.wikipedia.org/wiki/Beta-binomial_distribution (https://en.wikipedia.org/wiki/Beta-binomial_distribution)). Now we are keeping $\\mu$ fixed and just consider $\\alpha + \\beta$ as a variable then for very large $\\alpha + \\beta$ this basically just the binomial distribution while if it's close to $0$ you end up with basically a Bernoulli-distribution over $\\{0, k\\}$. Of course for $k = 1$ those two are the same thing so there's no way to distinguish any $\\alpha + \\beta$ as long as they have same $\\mu$.\n\n\n\n\nHere's a plot in R:\n\n\n\n\nlibrary(extraDistr)\npars <- exp(seq(-10, 10, length.out = 10))\nmu <- 0.6\nk <- 10\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = \"b\", \n col = \"red\", lwd = 4, ylim = c(0, mu), main = paste0(\"k = \", k))\nfor(par in pars){\n points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = \"b\")\n}\n\nk <- 1\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = \"b\", \n col = \"red\", lwd = 4, ylim = c(0, mu), main = paste0(\"k = \", k))\nfor(par in pars){\n points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = \"b\")\n}\n\n\n\n\n\n\n[image: plot k = 10 from R-Code, one extrem being just 0.4 at 0 and 0.6 at 10, the other fits the binomial; source: https://i.sstatic.net/cWGh2esg.png] (https://i.sstatic.net/cWGh2esg.png)\n[image: plot k = 1 from R-Code, just the same line from 0.4 to 0.6; source: https://i.sstatic.net/BHmL9Quz.png] (https://i.sstatic.net/BHmL9Quz.png)", "answer_url": "https://stats.stackexchange.com/a/677231", "author": "Lukas Lohse", "author_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-21T21:48:52+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": 677226, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lukas Lohse", "profile_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "user_type": "registered"}, "created_at": "2026-09-21T21:48:52+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "315A6811-DCF0-437C-A1D7-8721F8646961", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/315A6811-DCF0-437C-A1D7-8721F8646961/view-source"}], "score": 2, "updated_at": "2026-09-21T21:48:52+00:00"}, "other_answers": [{"answer_html": "

After thinking about this, I think I know how to do this. When $k=1$, it is possible to estimate the population mean but it is impossible to estimate the variance of the population.

\n

However, it is possible to estimate the variance of the mean estimator at $k=1$.

\n

Let each unit have $\\theta_i \\overset{iid}{\\sim} \\text{Beta}(\\alpha,\\beta)$ with density $f(\\theta)$. Each unit is observed once ($k=1$), so $y_i \\mid \\theta_i \\sim \\text{Bernoulli}(\\theta_i)$:

\n
    \n
  • $\\mu = E[\\theta_i]$ — population mean (the target) and is $\\mu = \\frac{\\alpha}{\\alpha+\\beta}$
  • \n
\n
    \n
  • $\\tau^2 = \\operatorname{Var}(\\theta_i)$ — population variance and is = $\\tau^2 = \\frac{\\mu(1-\\mu)}{\\alpha+\\beta+1}$
  • \n
\n
    \n
  • $\\sigma_y^2 = \\operatorname{Var}(y_i)$
  • \n
\n

For a single unit, the Bernoulli distribution:\n$$P(y\\mid\\theta) = \\theta^{y}(1-\\theta)^{1-y}.$$

\n

To marginalize the distribution:

\n

$$P(y_i=1) = \\int_0^1 \\theta\\, f(\\theta)\\,d\\theta = E[\\theta_i] = \\mu$$\n$$\\qquad P(y_i=0) = \\int_0^1 (1-\\theta)\\, f(\\theta)\\,d\\theta = 1-\\mu.$$

\n

$$y_i \\sim \\text{Bernoulli}(\\mu) = P(y_i = y) = \\mu^{y}(1-\\mu)^{1-y}$$

\n

The iid assumption makes it easy to extend this to $n$ machines:

\n

$$P(y_1,\\dots,y_n \\mid \\theta_1,\\dots,\\theta_n) = \\prod_{i=1}^n \\theta_i^{y_i}(1-\\theta_i)^{1-y_i}.$$

\n

$$P(y_1,\\dots,y_n) = \\int\\!\\!\\cdots\\!\\!\\int \\prod_{i=1}^n \\Big[\\theta_i^{y_i}(1-\\theta_i)^{1-y_i} f(\\theta_i)\\Big]\\, d\\theta_1\\cdots d\\theta_n.$$

\n

$$P(y_1,\\dots,y_n) = \\int_0^1 \\theta_1^{y_1}(1-\\theta_1)^{1-y_1}f(\\theta_1)\\,d\\theta_1 \\times \\cdots \\times \\int_0^1 \\theta_n^{y_n}(1-\\theta_n)^{1-y_n}f(\\theta_n)\\,d\\theta_n.$$

\n

$$P(y_1,\\dots,y_n) = \\prod_{i=1}^n \\mu^{y_i}(1-\\mu)^{1-y_i} \\quad\\Longrightarrow\\quad y_1,\\dots,y_n \\overset{iid}{\\sim} \\text{Bernoulli}(\\mu).$$

\n

Next, we can see $\\bar y$ is unbiased:

\n

$$E[y_i\\mid\\theta_i] = 1\\cdot\\theta_i + 0\\cdot(1-\\theta_i) = \\theta_i$$\n$$E[y_i] = E\\big[\\,E[y_i\\mid\\theta_i]\\,\\big] = E[\\theta_i] = \\mu.$$\n$$E[\\bar y] = \\frac1n\\sum_{i=1}^n E[y_i] = \\frac1n\\cdot n\\mu = \\mu$$

\n

Now for the variance:

\n

$$\\sigma_y^2 = \\text{Var}(y_i) = \\underbrace{E[\\text{Var}(y_i\\mid\\theta_i)]}_{\\text{within}} + \\underbrace{\\text{Var}(E[y_i\\mid\\theta_i])}_{\\text{between}} = E[\\theta_i(1-\\theta_i)] + \\tau^2.$$

\n

$$\\tau^2 = E[\\theta_i^2] - \\mu^2$$\n$$\\sigma_y^2 = \\big(\\mu - E[\\theta_i^2]\\big) + \\big(E[\\theta_i^2] - \\mu^2\\big) = \\mu(1-\\mu).$$

\n

For variance of the mean (0 covariance):

\n

$$\\text{Var}(\\bar y) = \\frac{1}{n^2}\\sum_{i=1}^n \\text{Var}(y_i) = \\frac{1}{n^2}\\cdot n\\sigma_y^2 = \\frac{\\sigma_y^2}{n} = \\frac{\\mu(1-\\mu)}{n}.$$

\n

Finally, we can see that $S^2$ is unbiased for $\\sigma_y^2$.

\n

The sample variance is:\n$$S^2 = \\frac{1}{n-1}\\sum_{i=1}^n (y_i-\\bar y)^2.$$

\n
    \n
  • $\\bar y = \\frac1n\\sum_i y_i$ means $\\sum_i y_i = n\\bar y$.
  • \n
  • A constant $\\mu$ summed $n$ times is $n\\mu$.
  • \n
\n

$$\\sum_{i=1}^n (y_i-\\mu) = \\sum_i y_i - n\\mu = n\\bar y - n\\mu = n(\\bar y-\\mu).$$

\n
    \n
  • $y_i - \\bar y = (y_i-\\mu) - (\\bar y-\\mu)$:\n$$\\sum_i (y_i-\\bar y)^2 = \\sum_i (y_i-\\mu)^2 \\;-\\; 2(\\bar y-\\mu)\\underbrace{\\sum_i (y_i-\\mu)}_{=\\,n(\\bar y-\\mu)} \\;+\\; n(\\bar y-\\mu)^2.$$
  • \n
\n

$$\\sum_i (y_i-\\bar y)^2 = \\sum_i (y_i-\\mu)^2 - n(\\bar y-\\mu)^2.$$

\n
    \n
  • $E[(y_i-\\mu)^2] = \\sigma_y^2$
  • \n
  • $E[(\\bar y-\\mu)^2] = \\text{Var}(\\bar y) = \\sigma_y^2/n$
  • \n
\n

Therefore\n$$E\\Big[\\sum_i (y_i-\\bar y)^2\\Big] = n\\sigma_y^2 - n\\cdot\\frac{\\sigma_y^2}{n} = (n-1)\\sigma_y^2 \\quad\\Longrightarrow\\quad E[S^2] = \\sigma_y^2$$

\n

For 0/1 data, $y_i^2 = y_i$, and $S^2$ simplifies to $\\dfrac{n}{n-1}\\,\\bar y(1-\\bar y)$.

\n

So it seems that at $k=1$, we can estimate the population mean and variance of the mean estimator.

\n", "answer_id": 677265, "answer_text": "After thinking about this, I think I know how to do this. When $k=1$, it is possible to estimate the population mean but it is impossible to estimate the variance of the population.\n\n\n\n\nHowever, it is possible to estimate the variance of the mean estimator at $k=1$.\n\n\n\n\nLet each unit have $\\theta_i \\overset{iid}{\\sim} \\text{Beta}(\\alpha,\\beta)$ with density $f(\\theta)$. Each unit is observed once ($k=1$), so $y_i \\mid \\theta_i \\sim \\text{Bernoulli}(\\theta_i)$:\n\n\n\n\n\n$\\mu = E[\\theta_i]$ — population mean (the target) and is $\\mu = \\frac{\\alpha}{\\alpha+\\beta}$\n\n\n\n\n\n\n$\\tau^2 = \\operatorname{Var}(\\theta_i)$ — population variance and is = $\\tau^2 = \\frac{\\mu(1-\\mu)}{\\alpha+\\beta+1}$\n\n\n\n\n\n\n$\\sigma_y^2 = \\operatorname{Var}(y_i)$\n\n\n\n\n\nFor a single unit, the Bernoulli distribution:\n$$P(y\\mid\\theta) = \\theta^{y}(1-\\theta)^{1-y}.$$\n\n\n\n\nTo marginalize the distribution:\n\n\n\n\n$$P(y_i=1) = \\int_0^1 \\theta\\, f(\\theta)\\,d\\theta = E[\\theta_i] = \\mu$$\n$$\\qquad P(y_i=0) = \\int_0^1 (1-\\theta)\\, f(\\theta)\\,d\\theta = 1-\\mu.$$\n\n\n\n\n$$y_i \\sim \\text{Bernoulli}(\\mu) = P(y_i = y) = \\mu^{y}(1-\\mu)^{1-y}$$\n\n\n\n\nThe iid assumption makes it easy to extend this to $n$ machines:\n\n\n\n\n$$P(y_1,\\dots,y_n \\mid \\theta_1,\\dots,\\theta_n) = \\prod_{i=1}^n \\theta_i^{y_i}(1-\\theta_i)^{1-y_i}.$$\n\n\n\n\n$$P(y_1,\\dots,y_n) = \\int\\!\\!\\cdots\\!\\!\\int \\prod_{i=1}^n \\Big[\\theta_i^{y_i}(1-\\theta_i)^{1-y_i} f(\\theta_i)\\Big]\\, d\\theta_1\\cdots d\\theta_n.$$\n\n\n\n\n$$P(y_1,\\dots,y_n) = \\int_0^1 \\theta_1^{y_1}(1-\\theta_1)^{1-y_1}f(\\theta_1)\\,d\\theta_1 \\times \\cdots \\times \\int_0^1 \\theta_n^{y_n}(1-\\theta_n)^{1-y_n}f(\\theta_n)\\,d\\theta_n.$$\n\n\n\n\n$$P(y_1,\\dots,y_n) = \\prod_{i=1}^n \\mu^{y_i}(1-\\mu)^{1-y_i} \\quad\\Longrightarrow\\quad y_1,\\dots,y_n \\overset{iid}{\\sim} \\text{Bernoulli}(\\mu).$$\n\n\n\n\nNext, we can see $\\bar y$ is unbiased:\n\n\n\n\n$$E[y_i\\mid\\theta_i] = 1\\cdot\\theta_i + 0\\cdot(1-\\theta_i) = \\theta_i$$\n$$E[y_i] = E\\big[\\,E[y_i\\mid\\theta_i]\\,\\big] = E[\\theta_i] = \\mu.$$\n$$E[\\bar y] = \\frac1n\\sum_{i=1}^n E[y_i] = \\frac1n\\cdot n\\mu = \\mu$$\n\n\n\n\nNow for the variance:\n\n\n\n\n$$\\sigma_y^2 = \\text{Var}(y_i) = \\underbrace{E[\\text{Var}(y_i\\mid\\theta_i)]}_{\\text{within}} + \\underbrace{\\text{Var}(E[y_i\\mid\\theta_i])}_{\\text{between}} = E[\\theta_i(1-\\theta_i)] + \\tau^2.$$\n\n\n\n\n$$\\tau^2 = E[\\theta_i^2] - \\mu^2$$\n$$\\sigma_y^2 = \\big(\\mu - E[\\theta_i^2]\\big) + \\big(E[\\theta_i^2] - \\mu^2\\big) = \\mu(1-\\mu).$$\n\n\n\n\nFor variance of the mean (0 covariance):\n\n\n\n\n$$\\text{Var}(\\bar y) = \\frac{1}{n^2}\\sum_{i=1}^n \\text{Var}(y_i) = \\frac{1}{n^2}\\cdot n\\sigma_y^2 = \\frac{\\sigma_y^2}{n} = \\frac{\\mu(1-\\mu)}{n}.$$\n\n\n\n\nFinally, we can see that $S^2$ is unbiased for $\\sigma_y^2$.\n\n\n\n\nThe sample variance is:\n$$S^2 = \\frac{1}{n-1}\\sum_{i=1}^n (y_i-\\bar y)^2.$$\n\n\n\n\n\n$\\bar y = \\frac1n\\sum_i y_i$ means $\\sum_i y_i = n\\bar y$.\n\n\n\n\nA constant $\\mu$ summed $n$ times is $n\\mu$.\n\n\n\n\n\n$$\\sum_{i=1}^n (y_i-\\mu) = \\sum_i y_i - n\\mu = n\\bar y - n\\mu = n(\\bar y-\\mu).$$\n\n\n\n\n\n$y_i - \\bar y = (y_i-\\mu) - (\\bar y-\\mu)$:\n$$\\sum_i (y_i-\\bar y)^2 = \\sum_i (y_i-\\mu)^2 \\;-\\; 2(\\bar y-\\mu)\\underbrace{\\sum_i (y_i-\\mu)}_{=\\,n(\\bar y-\\mu)} \\;+\\; n(\\bar y-\\mu)^2.$$\n\n\n\n\n\n$$\\sum_i (y_i-\\bar y)^2 = \\sum_i (y_i-\\mu)^2 - n(\\bar y-\\mu)^2.$$\n\n\n\n\n\n$E[(y_i-\\mu)^2] = \\sigma_y^2$\n\n\n\n\n$E[(\\bar y-\\mu)^2] = \\text{Var}(\\bar y) = \\sigma_y^2/n$\n\n\n\n\n\nTherefore\n$$E\\Big[\\sum_i (y_i-\\bar y)^2\\Big] = n\\sigma_y^2 - n\\cdot\\frac{\\sigma_y^2}{n} = (n-1)\\sigma_y^2 \\quad\\Longrightarrow\\quad E[S^2] = \\sigma_y^2$$\n\n\n\n\nFor 0/1 data, $y_i^2 = y_i$, and $S^2$ simplifies to $\\dfrac{n}{n-1}\\,\\bar y(1-\\bar y)$.\n\n\n\n\nSo it seems that at $k=1$, we can estimate the population mean and variance of the mean estimator.", "answer_url": "https://stats.stackexchange.com/a/677265", "author": "adamkostanov", "author_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-25T17:44:30+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": 677226, "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-25T17:44:30+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "A2509D36-CE80-4C0F-BA28-5077E22D040B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A2509D36-CE80-4C0F-BA28-5077E22D040B/view-source"}], "score": 0, "updated_at": "2026-09-25T17:44:30+00:00"}], "product": "statistics_qa", "question": "Here is a hierarchical data generating process:\n\n\n\n\n\n\n\n(Population) Layer 1: $$\\theta_i \\overset{\\text{iid}}{\\sim} \\text{Beta}(\\alpha,\\ \\beta), \\qquad i = 1, \\dots, n$$\n\n\n\n\n(Individual) Layer 2: $$y_{ij} \\mid \\theta_i \\overset{\\text{iid}}{\\sim} \\text{Bernoulli}(\\theta_i), \\qquad j = 1, \\dots, k$$\n\n\n\n\n\n\n\nThere are two cases - Case 1 is where you sample 1 observation per subject and Case 2 where you sample multiple observations per subject:\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/wine4qeY.png] (https://i.sstatic.net/wine4qeY.png)\n\n\n\n\nI am only interested in estimating the population level mean and variance. Can this still be done in Case 1?\n\n\n\n\nI am guessing that there will be no problems doing this for Case 2. For Case 1, I am guessing there won't be any problems for estimating the population level mean, but I am not sure if the population level variance can still be estimated since we do not observe variation at the individual level (regardless of whether moments are used or MLE).\n\n\n\n\n\n\n\nset.seed(42)\nn <- 20\nk <- 10\nalpha <- 3\nbeta <- 2 \nmu <- alpha / (alpha + beta) \n\nsubjects <- factor(paste(\"Subject\", 1:n), levels = paste(\"Subject\", n:1))\n\n# one theta (true probability) per subject \ntheta <- numeric(n)\nfor (i in 1:n) {\n theta[i] <- rbeta(1, alpha, beta)\n}\n\n# Case 1 \ncase1 <- numeric(n)\nfor (i in 1:n) {\n case1[i] <- rbinom(1, 1, theta[i]) \n}\n\n# Case 2 \ncase2 <- matrix(NA, nrow = k, ncol = n) \nfor (i in 1:n) {\n for (j in 1:k) {\n case2[j, i] <- rbinom(1, 1, theta[i])\n }\n}\n\nd1 <- data.frame(subject = subjects, true = theta, meas = case1)\nd2 <- data.frame(subject = rep(subjects, each = k),\n true = rep(theta, each = k),\n meas = as.vector(case2))\nred2 <- data.frame(subject = subjects, true = theta)", "record_id": "Scientific-Statistics-QA:stats:677226", "selected_answer": {"answer_html": "

No you can not estimate the $\\theta_i$ variance for $k = 1$. The relevant concept is the beta-binomial distribution(https://en.wikipedia.org/wiki/Beta-binomial_distribution). Now we are keeping $\\mu$ fixed and just consider $\\alpha + \\beta$ as a variable then for very large $\\alpha + \\beta$ this basically just the binomial distribution while if it's close to $0$ you end up with basically a Bernoulli-distribution over $\\{0, k\\}$. Of course for $k = 1$ those two are the same thing so there's no way to distinguish any $\\alpha + \\beta$ as long as they have same $\\mu$.

\n

Here's a plot in R:

\n
library(extraDistr)\npars <- exp(seq(-10, 10, length.out = 10))\nmu <- 0.6\nk <- 10\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = "b", \n     col = "red", lwd = 4, ylim = c(0, mu), main = paste0("k = ", k))\nfor(par in pars){\n  points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = "b")\n}\n\nk <- 1\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = "b", \n     col = "red", lwd = 4, ylim = c(0, mu), main = paste0("k = ", k))\nfor(par in pars){\n  points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = "b")\n}\n\n
\n

\"plot\n\"plot

\n", "answer_id": 677231, "answer_text": "No you can not estimate the $\\theta_i$ variance for $k = 1$. The relevant concept is the beta-binomial distribution(https://en.wikipedia.org/wiki/Beta-binomial_distribution (https://en.wikipedia.org/wiki/Beta-binomial_distribution)). Now we are keeping $\\mu$ fixed and just consider $\\alpha + \\beta$ as a variable then for very large $\\alpha + \\beta$ this basically just the binomial distribution while if it's close to $0$ you end up with basically a Bernoulli-distribution over $\\{0, k\\}$. Of course for $k = 1$ those two are the same thing so there's no way to distinguish any $\\alpha + \\beta$ as long as they have same $\\mu$.\n\n\n\n\nHere's a plot in R:\n\n\n\n\nlibrary(extraDistr)\npars <- exp(seq(-10, 10, length.out = 10))\nmu <- 0.6\nk <- 10\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = \"b\", \n col = \"red\", lwd = 4, ylim = c(0, mu), main = paste0(\"k = \", k))\nfor(par in pars){\n points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = \"b\")\n}\n\nk <- 1\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = \"b\", \n col = \"red\", lwd = 4, ylim = c(0, mu), main = paste0(\"k = \", k))\nfor(par in pars){\n points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = \"b\")\n}\n\n\n\n\n\n\n[image: plot k = 10 from R-Code, one extrem being just 0.4 at 0 and 0.6 at 10, the other fits the binomial; source: https://i.sstatic.net/cWGh2esg.png] (https://i.sstatic.net/cWGh2esg.png)\n[image: plot k = 1 from R-Code, just the same line from 0.4 to 0.6; source: https://i.sstatic.net/BHmL9Quz.png] (https://i.sstatic.net/BHmL9Quz.png)", "answer_url": "https://stats.stackexchange.com/a/677231", "author": "Lukas Lohse", "author_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-21T21:48:52+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": 677226, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lukas Lohse", "profile_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "user_type": "registered"}, "created_at": "2026-09-21T21:48:52+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "315A6811-DCF0-437C-A1D7-8721F8646961", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/315A6811-DCF0-437C-A1D7-8721F8646961/view-source"}], "score": 2, "updated_at": "2026-09-21T21:48:52+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677231, "answers": [{"answer_html": "

No you can not estimate the $\\theta_i$ variance for $k = 1$. The relevant concept is the beta-binomial distribution(https://en.wikipedia.org/wiki/Beta-binomial_distribution). Now we are keeping $\\mu$ fixed and just consider $\\alpha + \\beta$ as a variable then for very large $\\alpha + \\beta$ this basically just the binomial distribution while if it's close to $0$ you end up with basically a Bernoulli-distribution over $\\{0, k\\}$. Of course for $k = 1$ those two are the same thing so there's no way to distinguish any $\\alpha + \\beta$ as long as they have same $\\mu$.

\n

Here's a plot in R:

\n
library(extraDistr)\npars <- exp(seq(-10, 10, length.out = 10))\nmu <- 0.6\nk <- 10\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = "b", \n     col = "red", lwd = 4, ylim = c(0, mu), main = paste0("k = ", k))\nfor(par in pars){\n  points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = "b")\n}\n\nk <- 1\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = "b", \n     col = "red", lwd = 4, ylim = c(0, mu), main = paste0("k = ", k))\nfor(par in pars){\n  points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = "b")\n}\n\n
\n

\"plot\n\"plot

\n", "answer_id": 677231, "answer_text": "No you can not estimate the $\\theta_i$ variance for $k = 1$. The relevant concept is the beta-binomial distribution(https://en.wikipedia.org/wiki/Beta-binomial_distribution (https://en.wikipedia.org/wiki/Beta-binomial_distribution)). Now we are keeping $\\mu$ fixed and just consider $\\alpha + \\beta$ as a variable then for very large $\\alpha + \\beta$ this basically just the binomial distribution while if it's close to $0$ you end up with basically a Bernoulli-distribution over $\\{0, k\\}$. Of course for $k = 1$ those two are the same thing so there's no way to distinguish any $\\alpha + \\beta$ as long as they have same $\\mu$.\n\n\n\n\nHere's a plot in R:\n\n\n\n\nlibrary(extraDistr)\npars <- exp(seq(-10, 10, length.out = 10))\nmu <- 0.6\nk <- 10\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = \"b\", \n col = \"red\", lwd = 4, ylim = c(0, mu), main = paste0(\"k = \", k))\nfor(par in pars){\n points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = \"b\")\n}\n\nk <- 1\ny <- 0:k\n\nplot(y, dbinom(y, prob = mu, size = k), type = \"b\", \n col = \"red\", lwd = 4, ylim = c(0, mu), main = paste0(\"k = \", k))\nfor(par in pars){\n points(y, dbbinom(y, alpha = mu*par, beta = (1-mu)* par, size = k), type = \"b\")\n}\n\n\n\n\n\n\n[image: plot k = 10 from R-Code, one extrem being just 0.4 at 0 and 0.6 at 10, the other fits the binomial; source: https://i.sstatic.net/cWGh2esg.png] (https://i.sstatic.net/cWGh2esg.png)\n[image: plot k = 1 from R-Code, just the same line from 0.4 to 0.6; source: https://i.sstatic.net/BHmL9Quz.png] (https://i.sstatic.net/BHmL9Quz.png)", "answer_url": "https://stats.stackexchange.com/a/677231", "author": "Lukas Lohse", "author_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-21T21:48:52+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": 677226, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Lukas Lohse", "profile_url": "https://stats.stackexchange.com/users/341520/lukas-lohse", "user_type": "registered"}, "created_at": "2026-09-21T21:48:52+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "315A6811-DCF0-437C-A1D7-8721F8646961", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/315A6811-DCF0-437C-A1D7-8721F8646961/view-source"}], "score": 2, "updated_at": "2026-09-21T21:48:52+00:00"}, {"answer_html": "

After thinking about this, I think I know how to do this. When $k=1$, it is possible to estimate the population mean but it is impossible to estimate the variance of the population.

\n

However, it is possible to estimate the variance of the mean estimator at $k=1$.

\n

Let each unit have $\\theta_i \\overset{iid}{\\sim} \\text{Beta}(\\alpha,\\beta)$ with density $f(\\theta)$. Each unit is observed once ($k=1$), so $y_i \\mid \\theta_i \\sim \\text{Bernoulli}(\\theta_i)$:

\n
    \n
  • $\\mu = E[\\theta_i]$ — population mean (the target) and is $\\mu = \\frac{\\alpha}{\\alpha+\\beta}$
  • \n
\n
    \n
  • $\\tau^2 = \\operatorname{Var}(\\theta_i)$ — population variance and is = $\\tau^2 = \\frac{\\mu(1-\\mu)}{\\alpha+\\beta+1}$
  • \n
\n
    \n
  • $\\sigma_y^2 = \\operatorname{Var}(y_i)$
  • \n
\n

For a single unit, the Bernoulli distribution:\n$$P(y\\mid\\theta) = \\theta^{y}(1-\\theta)^{1-y}.$$

\n

To marginalize the distribution:

\n

$$P(y_i=1) = \\int_0^1 \\theta\\, f(\\theta)\\,d\\theta = E[\\theta_i] = \\mu$$\n$$\\qquad P(y_i=0) = \\int_0^1 (1-\\theta)\\, f(\\theta)\\,d\\theta = 1-\\mu.$$

\n

$$y_i \\sim \\text{Bernoulli}(\\mu) = P(y_i = y) = \\mu^{y}(1-\\mu)^{1-y}$$

\n

The iid assumption makes it easy to extend this to $n$ machines:

\n

$$P(y_1,\\dots,y_n \\mid \\theta_1,\\dots,\\theta_n) = \\prod_{i=1}^n \\theta_i^{y_i}(1-\\theta_i)^{1-y_i}.$$

\n

$$P(y_1,\\dots,y_n) = \\int\\!\\!\\cdots\\!\\!\\int \\prod_{i=1}^n \\Big[\\theta_i^{y_i}(1-\\theta_i)^{1-y_i} f(\\theta_i)\\Big]\\, d\\theta_1\\cdots d\\theta_n.$$

\n

$$P(y_1,\\dots,y_n) = \\int_0^1 \\theta_1^{y_1}(1-\\theta_1)^{1-y_1}f(\\theta_1)\\,d\\theta_1 \\times \\cdots \\times \\int_0^1 \\theta_n^{y_n}(1-\\theta_n)^{1-y_n}f(\\theta_n)\\,d\\theta_n.$$

\n

$$P(y_1,\\dots,y_n) = \\prod_{i=1}^n \\mu^{y_i}(1-\\mu)^{1-y_i} \\quad\\Longrightarrow\\quad y_1,\\dots,y_n \\overset{iid}{\\sim} \\text{Bernoulli}(\\mu).$$

\n

Next, we can see $\\bar y$ is unbiased:

\n

$$E[y_i\\mid\\theta_i] = 1\\cdot\\theta_i + 0\\cdot(1-\\theta_i) = \\theta_i$$\n$$E[y_i] = E\\big[\\,E[y_i\\mid\\theta_i]\\,\\big] = E[\\theta_i] = \\mu.$$\n$$E[\\bar y] = \\frac1n\\sum_{i=1}^n E[y_i] = \\frac1n\\cdot n\\mu = \\mu$$

\n

Now for the variance:

\n

$$\\sigma_y^2 = \\text{Var}(y_i) = \\underbrace{E[\\text{Var}(y_i\\mid\\theta_i)]}_{\\text{within}} + \\underbrace{\\text{Var}(E[y_i\\mid\\theta_i])}_{\\text{between}} = E[\\theta_i(1-\\theta_i)] + \\tau^2.$$

\n

$$\\tau^2 = E[\\theta_i^2] - \\mu^2$$\n$$\\sigma_y^2 = \\big(\\mu - E[\\theta_i^2]\\big) + \\big(E[\\theta_i^2] - \\mu^2\\big) = \\mu(1-\\mu).$$

\n

For variance of the mean (0 covariance):

\n

$$\\text{Var}(\\bar y) = \\frac{1}{n^2}\\sum_{i=1}^n \\text{Var}(y_i) = \\frac{1}{n^2}\\cdot n\\sigma_y^2 = \\frac{\\sigma_y^2}{n} = \\frac{\\mu(1-\\mu)}{n}.$$

\n

Finally, we can see that $S^2$ is unbiased for $\\sigma_y^2$.

\n

The sample variance is:\n$$S^2 = \\frac{1}{n-1}\\sum_{i=1}^n (y_i-\\bar y)^2.$$

\n
    \n
  • $\\bar y = \\frac1n\\sum_i y_i$ means $\\sum_i y_i = n\\bar y$.
  • \n
  • A constant $\\mu$ summed $n$ times is $n\\mu$.
  • \n
\n

$$\\sum_{i=1}^n (y_i-\\mu) = \\sum_i y_i - n\\mu = n\\bar y - n\\mu = n(\\bar y-\\mu).$$

\n
    \n
  • $y_i - \\bar y = (y_i-\\mu) - (\\bar y-\\mu)$:\n$$\\sum_i (y_i-\\bar y)^2 = \\sum_i (y_i-\\mu)^2 \\;-\\; 2(\\bar y-\\mu)\\underbrace{\\sum_i (y_i-\\mu)}_{=\\,n(\\bar y-\\mu)} \\;+\\; n(\\bar y-\\mu)^2.$$
  • \n
\n

$$\\sum_i (y_i-\\bar y)^2 = \\sum_i (y_i-\\mu)^2 - n(\\bar y-\\mu)^2.$$

\n
    \n
  • $E[(y_i-\\mu)^2] = \\sigma_y^2$
  • \n
  • $E[(\\bar y-\\mu)^2] = \\text{Var}(\\bar y) = \\sigma_y^2/n$
  • \n
\n

Therefore\n$$E\\Big[\\sum_i (y_i-\\bar y)^2\\Big] = n\\sigma_y^2 - n\\cdot\\frac{\\sigma_y^2}{n} = (n-1)\\sigma_y^2 \\quad\\Longrightarrow\\quad E[S^2] = \\sigma_y^2$$

\n

For 0/1 data, $y_i^2 = y_i$, and $S^2$ simplifies to $\\dfrac{n}{n-1}\\,\\bar y(1-\\bar y)$.

\n

So it seems that at $k=1$, we can estimate the population mean and variance of the mean estimator.

\n", "answer_id": 677265, "answer_text": "After thinking about this, I think I know how to do this. When $k=1$, it is possible to estimate the population mean but it is impossible to estimate the variance of the population.\n\n\n\n\nHowever, it is possible to estimate the variance of the mean estimator at $k=1$.\n\n\n\n\nLet each unit have $\\theta_i \\overset{iid}{\\sim} \\text{Beta}(\\alpha,\\beta)$ with density $f(\\theta)$. Each unit is observed once ($k=1$), so $y_i \\mid \\theta_i \\sim \\text{Bernoulli}(\\theta_i)$:\n\n\n\n\n\n$\\mu = E[\\theta_i]$ — population mean (the target) and is $\\mu = \\frac{\\alpha}{\\alpha+\\beta}$\n\n\n\n\n\n\n$\\tau^2 = \\operatorname{Var}(\\theta_i)$ — population variance and is = $\\tau^2 = \\frac{\\mu(1-\\mu)}{\\alpha+\\beta+1}$\n\n\n\n\n\n\n$\\sigma_y^2 = \\operatorname{Var}(y_i)$\n\n\n\n\n\nFor a single unit, the Bernoulli distribution:\n$$P(y\\mid\\theta) = \\theta^{y}(1-\\theta)^{1-y}.$$\n\n\n\n\nTo marginalize the distribution:\n\n\n\n\n$$P(y_i=1) = \\int_0^1 \\theta\\, f(\\theta)\\,d\\theta = E[\\theta_i] = \\mu$$\n$$\\qquad P(y_i=0) = \\int_0^1 (1-\\theta)\\, f(\\theta)\\,d\\theta = 1-\\mu.$$\n\n\n\n\n$$y_i \\sim \\text{Bernoulli}(\\mu) = P(y_i = y) = \\mu^{y}(1-\\mu)^{1-y}$$\n\n\n\n\nThe iid assumption makes it easy to extend this to $n$ machines:\n\n\n\n\n$$P(y_1,\\dots,y_n \\mid \\theta_1,\\dots,\\theta_n) = \\prod_{i=1}^n \\theta_i^{y_i}(1-\\theta_i)^{1-y_i}.$$\n\n\n\n\n$$P(y_1,\\dots,y_n) = \\int\\!\\!\\cdots\\!\\!\\int \\prod_{i=1}^n \\Big[\\theta_i^{y_i}(1-\\theta_i)^{1-y_i} f(\\theta_i)\\Big]\\, d\\theta_1\\cdots d\\theta_n.$$\n\n\n\n\n$$P(y_1,\\dots,y_n) = \\int_0^1 \\theta_1^{y_1}(1-\\theta_1)^{1-y_1}f(\\theta_1)\\,d\\theta_1 \\times \\cdots \\times \\int_0^1 \\theta_n^{y_n}(1-\\theta_n)^{1-y_n}f(\\theta_n)\\,d\\theta_n.$$\n\n\n\n\n$$P(y_1,\\dots,y_n) = \\prod_{i=1}^n \\mu^{y_i}(1-\\mu)^{1-y_i} \\quad\\Longrightarrow\\quad y_1,\\dots,y_n \\overset{iid}{\\sim} \\text{Bernoulli}(\\mu).$$\n\n\n\n\nNext, we can see $\\bar y$ is unbiased:\n\n\n\n\n$$E[y_i\\mid\\theta_i] = 1\\cdot\\theta_i + 0\\cdot(1-\\theta_i) = \\theta_i$$\n$$E[y_i] = E\\big[\\,E[y_i\\mid\\theta_i]\\,\\big] = E[\\theta_i] = \\mu.$$\n$$E[\\bar y] = \\frac1n\\sum_{i=1}^n E[y_i] = \\frac1n\\cdot n\\mu = \\mu$$\n\n\n\n\nNow for the variance:\n\n\n\n\n$$\\sigma_y^2 = \\text{Var}(y_i) = \\underbrace{E[\\text{Var}(y_i\\mid\\theta_i)]}_{\\text{within}} + \\underbrace{\\text{Var}(E[y_i\\mid\\theta_i])}_{\\text{between}} = E[\\theta_i(1-\\theta_i)] + \\tau^2.$$\n\n\n\n\n$$\\tau^2 = E[\\theta_i^2] - \\mu^2$$\n$$\\sigma_y^2 = \\big(\\mu - E[\\theta_i^2]\\big) + \\big(E[\\theta_i^2] - \\mu^2\\big) = \\mu(1-\\mu).$$\n\n\n\n\nFor variance of the mean (0 covariance):\n\n\n\n\n$$\\text{Var}(\\bar y) = \\frac{1}{n^2}\\sum_{i=1}^n \\text{Var}(y_i) = \\frac{1}{n^2}\\cdot n\\sigma_y^2 = \\frac{\\sigma_y^2}{n} = \\frac{\\mu(1-\\mu)}{n}.$$\n\n\n\n\nFinally, we can see that $S^2$ is unbiased for $\\sigma_y^2$.\n\n\n\n\nThe sample variance is:\n$$S^2 = \\frac{1}{n-1}\\sum_{i=1}^n (y_i-\\bar y)^2.$$\n\n\n\n\n\n$\\bar y = \\frac1n\\sum_i y_i$ means $\\sum_i y_i = n\\bar y$.\n\n\n\n\nA constant $\\mu$ summed $n$ times is $n\\mu$.\n\n\n\n\n\n$$\\sum_{i=1}^n (y_i-\\mu) = \\sum_i y_i - n\\mu = n\\bar y - n\\mu = n(\\bar y-\\mu).$$\n\n\n\n\n\n$y_i - \\bar y = (y_i-\\mu) - (\\bar y-\\mu)$:\n$$\\sum_i (y_i-\\bar y)^2 = \\sum_i (y_i-\\mu)^2 \\;-\\; 2(\\bar y-\\mu)\\underbrace{\\sum_i (y_i-\\mu)}_{=\\,n(\\bar y-\\mu)} \\;+\\; n(\\bar y-\\mu)^2.$$\n\n\n\n\n\n$$\\sum_i (y_i-\\bar y)^2 = \\sum_i (y_i-\\mu)^2 - n(\\bar y-\\mu)^2.$$\n\n\n\n\n\n$E[(y_i-\\mu)^2] = \\sigma_y^2$\n\n\n\n\n$E[(\\bar y-\\mu)^2] = \\text{Var}(\\bar y) = \\sigma_y^2/n$\n\n\n\n\n\nTherefore\n$$E\\Big[\\sum_i (y_i-\\bar y)^2\\Big] = n\\sigma_y^2 - n\\cdot\\frac{\\sigma_y^2}{n} = (n-1)\\sigma_y^2 \\quad\\Longrightarrow\\quad E[S^2] = \\sigma_y^2$$\n\n\n\n\nFor 0/1 data, $y_i^2 = y_i$, and $S^2$ simplifies to $\\dfrac{n}{n-1}\\,\\bar y(1-\\bar y)$.\n\n\n\n\nSo it seems that at $k=1$, we can estimate the population mean and variance of the mean estimator.", "answer_url": "https://stats.stackexchange.com/a/677265", "author": "adamkostanov", "author_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-25T17:44:30+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": 677226, "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-25T17:44:30+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "A2509D36-CE80-4C0F-BA28-5077E22D040B", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A2509D36-CE80-4C0F-BA28-5077E22D040B/view-source"}], "score": 0, "updated_at": "2026-09-25T17:44:30+00:00"}], "domain": "statistics", "external_links": ["https://en.wikipedia.org/wiki/Beta-binomial_distribution", "https://i.sstatic.net/BHmL9Quz.png", "https://i.sstatic.net/cWGh2esg.png", "https://i.sstatic.net/wine4qeY.png"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "adamkostanov", "question_author_url": "https://stats.stackexchange.com/users/512554/adamkostanov", "question_author_user_type": "registered", "question_created_at": "2026-09-21T00:41:19+00:00", "question_html": "

Here is a hierarchical data generating process:

\n
\n

(Population) Layer 1: $$\\theta_i \\overset{\\text{iid}}{\\sim} \\text{Beta}(\\alpha,\\ \\beta), \\qquad i = 1, \\dots, n$$

\n

(Individual) Layer 2: $$y_{ij} \\mid \\theta_i \\overset{\\text{iid}}{\\sim} \\text{Bernoulli}(\\theta_i), \\qquad j = 1, \\dots, k$$

\n
\n

There are two cases - Case 1 is where you sample 1 observation per subject and Case 2 where you sample multiple observations per subject:

\n

\"enter

\n

I am only interested in estimating the population level mean and variance. Can this still be done in Case 1?

\n

I am guessing that there will be no problems doing this for Case 2. For Case 1, I am guessing there won't be any problems for estimating the population level mean, but I am not sure if the population level variance can still be estimated since we do not observe variation at the individual level (regardless of whether moments are used or MLE).

\n
\n
set.seed(42)\nn <- 20\nk <- 10\nalpha <- 3\nbeta <- 2                \nmu <- alpha / (alpha + beta)          \n\nsubjects <- factor(paste("Subject", 1:n), levels = paste("Subject", n:1))\n\n# one theta (true probability) per subject \ntheta <- numeric(n)\nfor (i in 1:n) {\n    theta[i] <- rbeta(1, alpha, beta)\n}\n\n# Case 1 \ncase1 <- numeric(n)\nfor (i in 1:n) {\n    case1[i] <- rbinom(1, 1, theta[i])       \n}\n\n# Case 2 \ncase2 <- matrix(NA, nrow = k, ncol = n)    \nfor (i in 1:n) {\n    for (j in 1:k) {\n        case2[j, i] <- rbinom(1, 1, theta[i])\n    }\n}\n\nd1 <- data.frame(subject = subjects, true = theta, meas = case1)\nd2 <- data.frame(subject = rep(subjects, each = k),\n                 true    = rep(theta, each = k),\n                 meas    = as.vector(case2))\nred2 <- data.frame(subject = subjects, true = theta)\n
\n", "question_id": 677226, "question_license": "CC BY-SA 4.0", "question_score": 2, "question_text": "Here is a hierarchical data generating process:\n\n\n\n\n\n\n\n(Population) Layer 1: $$\\theta_i \\overset{\\text{iid}}{\\sim} \\text{Beta}(\\alpha,\\ \\beta), \\qquad i = 1, \\dots, n$$\n\n\n\n\n(Individual) Layer 2: $$y_{ij} \\mid \\theta_i \\overset{\\text{iid}}{\\sim} \\text{Bernoulli}(\\theta_i), \\qquad j = 1, \\dots, k$$\n\n\n\n\n\n\n\nThere are two cases - Case 1 is where you sample 1 observation per subject and Case 2 where you sample multiple observations per subject:\n\n\n\n\n[image: enter image description here; source: https://i.sstatic.net/wine4qeY.png] (https://i.sstatic.net/wine4qeY.png)\n\n\n\n\nI am only interested in estimating the population level mean and variance. Can this still be done in Case 1?\n\n\n\n\nI am guessing that there will be no problems doing this for Case 2. For Case 1, I am guessing there won't be any problems for estimating the population level mean, but I am not sure if the population level variance can still be estimated since we do not observe variation at the individual level (regardless of whether moments are used or MLE).\n\n\n\n\n\n\n\nset.seed(42)\nn <- 20\nk <- 10\nalpha <- 3\nbeta <- 2 \nmu <- alpha / (alpha + beta) \n\nsubjects <- factor(paste(\"Subject\", 1:n), levels = paste(\"Subject\", n:1))\n\n# one theta (true probability) per subject \ntheta <- numeric(n)\nfor (i in 1:n) {\n theta[i] <- rbeta(1, alpha, beta)\n}\n\n# Case 1 \ncase1 <- numeric(n)\nfor (i in 1:n) {\n case1[i] <- rbinom(1, 1, theta[i]) \n}\n\n# Case 2 \ncase2 <- matrix(NA, nrow = k, ncol = n) \nfor (i in 1:n) {\n for (j in 1:k) {\n case2[j, i] <- rbinom(1, 1, theta[i])\n }\n}\n\nd1 <- data.frame(subject = subjects, true = theta, meas = case1)\nd2 <- data.frame(subject = rep(subjects, each = k),\n true = rep(theta, each = k),\n meas = as.vector(case2))\nred2 <- data.frame(subject = subjects, true = theta)", "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-21T00:41:19+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "C1F4E2FF-471E-47A5-928D-F6B0A4681FF3", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C1F4E2FF-471E-47A5-928D-F6B0A4681FF3/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "kjetil b halvorsen", "profile_url": "https://stats.stackexchange.com/users/11887/kjetil-b-halvorsen", "user_type": "moderator"}, "created_at": "2026-09-21T04:23:57+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "19D572A4-437C-42C9-8FEE-FD0F08D0BE8B", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/19D572A4-437C-42C9-8FEE-FD0F08D0BE8B/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-21T04:41:49+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "AD8437EA-1725-4DAB-8174-F56009F767F0", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD8437EA-1725-4DAB-8174-F56009F767F0/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-22T01:12:54+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "75227B37-0244-4E58-846B-06B8FB1C54FF", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/75227B37-0244-4E58-846B-06B8FB1C54FF/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677226/is-variance-still-estimable-when-you-observe-a-single-observation-per-subject", "split": "train", "split_group": "9dd25a7f286d352daa4453c364e35088a292dc3acf798487781b158dd5e6996b", "tags": ["probability", "sampling", "estimation", "mean"], "thread_id": "stats:677226", "title": "Is variance still estimable when you observe a single observation per subject?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I am running an experiment in which 1 participant is randomized multiple times to different treatments, and we are assessing the effect of treatment on blood pressure (BP).\n\n\n\n\nThe data collection protocol is as follows:\n\n\n\n\n• BP is measured every day at two time points: 12:00 and 20:00, for approximately 3 months.\n\n\n\n\n• At each time point, BP is measured twice, exactly 1 minute apart.\n\n\n\n\nData structure\n\n\n\n\n\n\n\n\n\nday\ntime\nrep\ndatetime\nSBP\n\n\n\n\n\n\n\n\n\t1\n\t12:00\n\t1\n\t2026-01-01 12:00\n\t122\n\n\n\n\n\n\n\t1\n\t12:00\n\t2\n\t2026-01-01 12:01\n\t121\n\n\n\n\n\n\n\t1\n\t20:00\n\t1\n\t2026-01-01 20:00\n\t128\n\n\n\n\n\n\n\t1\n\t20:00\n\t2\n\t2026-01-01 20:01\n\t127\n\n\n\n\n\n\n\t2\n\t12:00\n\t1\n\t2026-01-02 12:00\n\t120\n\n\n\n\n\n\n\t2\n\t12:00\n\t2\n\t2026-01-02 12:01\n\t119\n\n\n\n\n\n\n\t2\n\t20:00\n\t1\n\t2026-01-02 20:00\n\t130\n\n\n\n\n\n\n\t2\n\t20:00\n\t2\n\t2026-01-02 20:01\n\t129\n\n\n\n\n\n\n\n\n\nI then calculate elapsed time from the first observation:\n\n\n\n\ndat$t_elapsed <- as.numeric(\n difftime(dat$datetime, min(dat$datetime), units = \"days\")\n)\nThis\n\n\n\n\n\ngives approximately:\n0, 0.00069, 0.3333, 0.3340,\n1, 1.00069, 1.3333, 1.3340, ...\ni.e., the actual elapsed time between observations, expressed in days.\n\n\n\n\nI was considering the following model:\n\n\n\n\nmodel <- gls(\n SBP ~ treatment + day,\n correlation = corCAR1(form = ~ t_elapsed),\n data = dat\n)\n\n\n\n\n\nQuestions\n\n\n\n\n\nIs calculating t_elapsed an appropriate way to specify the time variable for corCAR1()?\n\n\n\n\nMore generally, is CAR(1) an appropriate correlation structure for these data, given that I have both very closely spaced repeated measurements (1 minute apart) and measurements separated by approximately 8 or 16 hours?\n\n\n\n\nWould you recommend an alternative correlation structure or modeling strategy for this design?\n\n\n\n\n\nThank you!", "record_id": "Scientific-Statistics-QA:stats:677242", "selected_answer": {"answer_html": "

I would treat the 2 observations that are only 1 minute apart as technical replicates that are unlikely to differ biologically. Average them and the associated measurement times instead of using them separately. That removes your concern about the corCAR1 correlation structure.

\n

If day is treated as continuous, your model implicitly assumes it has a linear association with BP. That's unlikely to hold. If it's treated as a factor, you have a lot of coefficients to estimate. Flexible fitting with regression splines or other generalized additive models is a good intermediate choice for modeling time.

\n

The model also assumes that associations of day and treatment with BP are additive. Is that likely, based on your understanding of the subject matter? If not, include an interaction between them.

\n

I don't see an advantage to using day as a time scale in addition to t_elapsed. I'd just use t_elapsed as the predictor for time scale, as that includes information about day.

\n

I suspect that there will be a circadian difference between 1200 and 2000 hours. The model should take that into account.

\n

Chapter 7 of Frank Harrell's Regression Modeling Strategies covers generalized least squares for this type of study in some detail. Read it before you go any farther in your analysis.

\n", "answer_id": 677249, "answer_text": "I would treat the 2 observations that are only 1 minute apart as technical replicates that are unlikely to differ biologically. Average them and the associated measurement times instead of using them separately. That removes your concern about the corCAR1 correlation structure.\n\n\n\n\nIf day is treated as continuous, your model implicitly assumes it has a linear association with BP. That's unlikely to hold. If it's treated as a factor, you have a lot of coefficients to estimate. Flexible fitting with regression splines or other generalized additive models is a good intermediate choice for modeling time.\n\n\n\n\nThe model also assumes that associations of day and treatment with BP are additive. Is that likely, based on your understanding of the subject matter? If not, include an interaction between them.\n\n\n\n\nI don't see an advantage to using day as a time scale in addition to t_elapsed. I'd just use t_elapsed as the predictor for time scale, as that includes information about day.\n\n\n\n\nI suspect that there will be a circadian difference between 1200 and 2000 hours. The model should take that into account.\n\n\n\n\nChapter 7 of Frank Harrell's Regression Modeling Strategies (https://hbiostat.org/rmsc/long) covers generalized least squares for this type of study in some detail. Read it before you go any farther in your analysis.", "answer_url": "https://stats.stackexchange.com/a/677249", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-23T20:10:25+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": 677242, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-23T20:10:25+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "49CEC78F-CB41-47B6-A537-4E122B99B13A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/49CEC78F-CB41-47B6-A537-4E122B99B13A/view-source"}], "score": 3, "updated_at": "2026-09-23T20:10:25+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

I would treat the 2 observations that are only 1 minute apart as technical replicates that are unlikely to differ biologically. Average them and the associated measurement times instead of using them separately. That removes your concern about the corCAR1 correlation structure.

\n

If day is treated as continuous, your model implicitly assumes it has a linear association with BP. That's unlikely to hold. If it's treated as a factor, you have a lot of coefficients to estimate. Flexible fitting with regression splines or other generalized additive models is a good intermediate choice for modeling time.

\n

The model also assumes that associations of day and treatment with BP are additive. Is that likely, based on your understanding of the subject matter? If not, include an interaction between them.

\n

I don't see an advantage to using day as a time scale in addition to t_elapsed. I'd just use t_elapsed as the predictor for time scale, as that includes information about day.

\n

I suspect that there will be a circadian difference between 1200 and 2000 hours. The model should take that into account.

\n

Chapter 7 of Frank Harrell's Regression Modeling Strategies covers generalized least squares for this type of study in some detail. Read it before you go any farther in your analysis.

\n", "answer_id": 677249, "answer_text": "I would treat the 2 observations that are only 1 minute apart as technical replicates that are unlikely to differ biologically. Average them and the associated measurement times instead of using them separately. That removes your concern about the corCAR1 correlation structure.\n\n\n\n\nIf day is treated as continuous, your model implicitly assumes it has a linear association with BP. That's unlikely to hold. If it's treated as a factor, you have a lot of coefficients to estimate. Flexible fitting with regression splines or other generalized additive models is a good intermediate choice for modeling time.\n\n\n\n\nThe model also assumes that associations of day and treatment with BP are additive. Is that likely, based on your understanding of the subject matter? If not, include an interaction between them.\n\n\n\n\nI don't see an advantage to using day as a time scale in addition to t_elapsed. I'd just use t_elapsed as the predictor for time scale, as that includes information about day.\n\n\n\n\nI suspect that there will be a circadian difference between 1200 and 2000 hours. The model should take that into account.\n\n\n\n\nChapter 7 of Frank Harrell's Regression Modeling Strategies (https://hbiostat.org/rmsc/long) covers generalized least squares for this type of study in some detail. Read it before you go any farther in your analysis.", "answer_url": "https://stats.stackexchange.com/a/677249", "author": "EdM", "author_url": "https://stats.stackexchange.com/users/28500/edm", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-23T20:10:25+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": 677242, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "EdM", "profile_url": "https://stats.stackexchange.com/users/28500/edm", "user_type": "registered"}, "created_at": "2026-09-23T20:10:25+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "49CEC78F-CB41-47B6-A537-4E122B99B13A", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/49CEC78F-CB41-47B6-A537-4E122B99B13A/view-source"}], "score": 3, "updated_at": "2026-09-23T20:10:25+00:00"}], "domain": "statistics", "external_links": ["https://hbiostat.org/rmsc/long"], "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": "jtjtjtjt", "question_author_url": "https://stats.stackexchange.com/users/393112/jtjtjtjt", "question_author_user_type": "registered", "question_created_at": "2026-09-23T09:07:44+00:00", "question_html": "

I am running an experiment in which 1 participant is randomized multiple times to different treatments, and we are assessing the effect of treatment on blood pressure (BP).

\n

The data collection protocol is as follows:

\n

• BP is measured every day at two time points: 12:00 and 20:00, for approximately 3 months.

\n

• At each time point, BP is measured twice, exactly 1 minute apart.

\n

Data structure

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
daytimerepdatetimeSBP
112:0012026-01-01 12:00122
112:0022026-01-01 12:01121
120:0012026-01-01 20:00128
120:0022026-01-01 20:01127
212:0012026-01-02 12:00120
212:0022026-01-02 12:01119
220:0012026-01-02 20:00130
220:0022026-01-02 20:01129
\n

I then calculate elapsed time from the first observation:

\n
dat$t_elapsed <- as.numeric(\n  difftime(dat$datetime, min(dat$datetime), units = "days")\n)\nThis\n
\n

gives approximately:\n0, 0.00069, 0.3333, 0.3340,\n1, 1.00069, 1.3333, 1.3340, ...\ni.e., the actual elapsed time between observations, expressed in days.

\n

I was considering the following model:

\n
model <- gls(\n  SBP ~ treatment + day,\n  correlation = corCAR1(form = ~ t_elapsed),\n  data = dat\n)\n
\n

Questions

\n
    \n
  1. Is calculating t_elapsed an appropriate way to specify the time variable for corCAR1()?
  2. \n
  3. More generally, is CAR(1) an appropriate correlation structure for these data, given that I have both very closely spaced repeated measurements (1 minute apart) and measurements separated by approximately 8 or 16 hours?
  4. \n
  5. Would you recommend an alternative correlation structure or modeling strategy for this design?
  6. \n
\n

Thank you!

\n", "question_id": 677242, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "I am running an experiment in which 1 participant is randomized multiple times to different treatments, and we are assessing the effect of treatment on blood pressure (BP).\n\n\n\n\nThe data collection protocol is as follows:\n\n\n\n\n• BP is measured every day at two time points: 12:00 and 20:00, for approximately 3 months.\n\n\n\n\n• At each time point, BP is measured twice, exactly 1 minute apart.\n\n\n\n\nData structure\n\n\n\n\n\n\n\n\n\nday\ntime\nrep\ndatetime\nSBP\n\n\n\n\n\n\n\n\n\t1\n\t12:00\n\t1\n\t2026-01-01 12:00\n\t122\n\n\n\n\n\n\n\t1\n\t12:00\n\t2\n\t2026-01-01 12:01\n\t121\n\n\n\n\n\n\n\t1\n\t20:00\n\t1\n\t2026-01-01 20:00\n\t128\n\n\n\n\n\n\n\t1\n\t20:00\n\t2\n\t2026-01-01 20:01\n\t127\n\n\n\n\n\n\n\t2\n\t12:00\n\t1\n\t2026-01-02 12:00\n\t120\n\n\n\n\n\n\n\t2\n\t12:00\n\t2\n\t2026-01-02 12:01\n\t119\n\n\n\n\n\n\n\t2\n\t20:00\n\t1\n\t2026-01-02 20:00\n\t130\n\n\n\n\n\n\n\t2\n\t20:00\n\t2\n\t2026-01-02 20:01\n\t129\n\n\n\n\n\n\n\n\n\nI then calculate elapsed time from the first observation:\n\n\n\n\ndat$t_elapsed <- as.numeric(\n difftime(dat$datetime, min(dat$datetime), units = \"days\")\n)\nThis\n\n\n\n\n\ngives approximately:\n0, 0.00069, 0.3333, 0.3340,\n1, 1.00069, 1.3333, 1.3340, ...\ni.e., the actual elapsed time between observations, expressed in days.\n\n\n\n\nI was considering the following model:\n\n\n\n\nmodel <- gls(\n SBP ~ treatment + day,\n correlation = corCAR1(form = ~ t_elapsed),\n data = dat\n)\n\n\n\n\n\nQuestions\n\n\n\n\n\nIs calculating t_elapsed an appropriate way to specify the time variable for corCAR1()?\n\n\n\n\nMore generally, is CAR(1) an appropriate correlation structure for these data, given that I have both very closely spaced repeated measurements (1 minute apart) and measurements separated by approximately 8 or 16 hours?\n\n\n\n\nWould you recommend an alternative correlation structure or modeling strategy for this design?\n\n\n\n\n\nThank you!", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "jtjtjtjt", "profile_url": "https://stats.stackexchange.com/users/393112/jtjtjtjt", "user_type": "registered"}, "created_at": "2026-09-23T09:07:44+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "F6683031-BCCB-4D54-BBE3-456E3642AC0F", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F6683031-BCCB-4D54-BBE3-456E3642AC0F/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-24T01:29:33+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "4E6C2681-2FA3-4F04-87F3-25F3A9004AFC", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/4E6C2681-2FA3-4F04-87F3-25F3A9004AFC/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677242/modeling-within-day-and-across-day-correlations-using-car1-with-repeated-measu", "split": "train", "split_group": "f33a429b362ffdcdd327a936bb1a7b486e9a3a3e1d3c84d34deb198a0b0393f5", "tags": ["lme4-nlme", "autoregressive", "generalized-least-squares"], "thread_id": "stats:677242", "title": "Modeling within-day and across-day correlations using CAR(1) with repeated measurements"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I have been tasked with understanding why normalized residuals between R and Stata are different when using mixed models (i.e. the nlme package in R).\n\n\n\n\nWhat I have found is that the residuals are both theoretically computed the same way: norm_residuals = sigma^(-1) * Lambda^(-1/2) * residuals\n\n\n\n\nThis is based on the works of José C. Pinheiro and Douglas M. Bates. The nlme package in R references their book \"Mixed effects models in S and S-PLUS\" (2000), while Stata references their article \"Computational Methods for Multilevel Modelling\" (1998) (see page 575 of \"STATA MULTILEVEL MIXED-EFFECTS REFERENCE MANUAL RELEASE 19 (https://www.stata.com/manuals/me.pdf). The terminology is a bit confusing, as 'normalized' residuals in R are called 'standardized' residuals in stata, which is not to be confused with 'Pearson' residuals, which is what R considers 'standardized').\n\n\n\n\nHowever, the way the matrix square root is computed is different between the two programs. The result can have a rather significant impact on whether or not the normalized residuals actually seem to follow a normal distribution.\n\n\n\n\nThe way R computes the matrix square root is through the Cholesky decomposition A = L*L^T (using the chol function from FORTRAN77). I cannot access the source code for Stata, but it seems like Stata uses Cholesky decomposition as well, however using a Cholesky decomposition algorithm starting at \"the bottom right\" of the matrix instead of \"the top left\" such that A = L^T * L. Using these two methods for Cholesky decomposition, I have been able to recreate the normalised residuals from R and Stata respectively.\n\n\n\n\nWhen using QQ-plots on the normalized residuals calculated with R and those calculated with Stata, the two results plots imply different conclusions about the normality of the residuals.\n\n\n\n\nIn principle, could one not use several different methods for Cholesky decomposition to compute a matrix square root and therefore come to significantly different conclusions? Would it therefore not be preferable to use eigenvalue decomposition to compute a matrix square root as opposed to Cholesky decomposition? One reason I believe EVD would be better is that it does not require transposing one \"square root\", i.e. we have directly that A^(1/2) * A^(1/2) = A.\n\n\n\n\nHere, I have added an example:\n\n\n\n\nratlong <- read.csv(\"ratlong.csv\") |>\n mutate(Rat = factor(Rat), Group = as_factor(Group)) |>\n mutate(time = as.factor(as.numeric(time)))\n\nmodel <- gls(Weight ~ time*Group,\n correlation = corSymm(form = ~ as.integer(time) | Rat),\n weights = varIdent(form = ~ 1 | time),\n na.action = na.exclude,\n method = \"REML\",\n data = ratlong)\n\nsummary(model)\nparameters(model)\ngetVarCov(model)\n\ntmp <- mutate(\n ratlong,\n fit = fitted(model),\n response = residuals(model, type = \"r\"),\n pearson = residuals(model, type = \"p\"),\n norm_res_R = residuals(model, type = \"n\"),\n norm_res_stata = c(\n -.3343025, .5268827, .4992422, .0732094, .8447663,\n -.3185105, -.2071171, 1.274912, .7114518, 1.215278,\n -.5135215, .0203645, -.5228509, -.8512383, 1.808096,\n .4581496, -1.22478, -.9106107, -.7130803, .2519478,\n .3804444, .2287333, .9784756, -.3758776, -.7113822,\n -1.475303, -1.399477, -1.504103, 1.288807, -.5631775,\n .473786, -.4318775, .5628197, -1.065117, -1.452405,\n .9371732, 1.274058, .9912707, .9466597, -.4890752,\n .1423321, .311183, -.8122606, -.5272216, -1.526507,\n .2497523, .9020303, -.556895, .5124069, .6224594,\n .8534008, -1.234297, .7109886, 1.567964, .3556911,\n 1.202434, -.9995003, .4767818, .8310238, -.1630251,\n -.7255811, -.987914, 1.937267, -1.758109, .6521003,\n -1.101692, 2.462107, .2542622, .8310238, -.1630251,\n -1.298645, -.3421695, -1.104759, .5448185, 1.170816,\n -1.124267, .0387734, .6711161, -.8830101, -.385332,\n .2229622, -.5032972, .0853191, 1.314626, -1.200457,\n 2.574736, .5105642, -1.381145, -.8254197, 1.170816,\n -.5026115, -.0627333, -.9601486, -1.083703, -1.27456,\n -.1007365, 1.118466, -.6896819, -.5392144, -.1630251)\n)\n\n# Here we observe that the pearson residual is approximately equal to the \n# normalized at time 1 for R and time 5 for stata\ntmp$pearson[seq(5, nrow(ratlong), 5)] - \n tmp$norm_res_stata[seq(5, nrow(ratlong), 5)]\ntmp$pearson[seq(1, nrow(ratlong), 5)] - \n tmp$norm_res_R[seq(1, nrow(ratlong), 5)]\n\n\n\n\n\nAccording to the nmle package (retrieved from github (https://github.com/cran/nlme)), the residuals are computed as such:\n\n\n\n\n#### from residuals.gls\nval <- object$residuals\nif (type != \"response\") {\n val <- val/attr(val, \"std\")\n lab <- \"Standardized residuals\"\n if (type == \"normalized\") {\nif (!is.null(cSt <- object$modelStruct$corStruct)) {\n ## normalize according to inv-trans factor\n val <- recalc(cSt, list(Xy = as.matrix(val)))$Xy[, 1]\n lab <- \"Normalized residuals\"\n }\n }\n}\n \n#### from recalc.corSymm\nrecalc.corSymm <- function(object, conLin, ...)\n{\n val <-\n .C(symm_recalc,\n Xy = as.double(conLin[[\"Xy\"]]),\n as.integer(unlist(Dim(object))),\n as.integer(ncol(conLin[[\"Xy\"]])),\n as.double(as.vector(object)),\n as.integer(unlist(getCovariate(object))),\n as.integer(attr(object, \"maxCov\")),\n logLik = double(1))[c(\"Xy\", \"logLik\")]\n conLin[[\"Xy\"]][] <- val[[\"Xy\"]]\n conLin[[\"logLik\"]] <- conLin[[\"logLik\"]] + val[[\"logLik\"]]\n conLin\n}\n \n#### from symm_recalc (written in C)\nvoid\nsymm_recalc(double *Xy, int *pdims, int *ZXcol, double *pars,\n int *time, int *maxC, double *logdet)\n{\n int N = pdims[0], M = pdims[1], *len = pdims + 4, *start = len + M, i;\n double *crr = R_Calloc(*maxC * (*maxC - 1) / 2, double);\n /* parameters assumed in unconstrained form */\n symm_fullCorr(pars, maxC, crr); /* get all correlations (not correlation \n matrix) */\n for(i = 0; i < M; i++) {\n double *Factor = R_Calloc((len[i] * len[i]), double);\n symm_fact(crr, time + start[i], &len[i], maxC, Factor, logdet);\n mult_mat(Xy + start[i], N, Factor, len[i], len[i], len[i],\n Xy + start[i], N, *ZXcol);\n R_Free(Factor);\n }\n R_Free(crr);\n}\n \n#### from symm_fact (also written in C)\nstatic void\nsymm_fact(double *crr, int *time, int *n, int *maxC, double *mat,\n double *logdet)\n{\n int job = 11L, info, i, nsq = *n * (*n), np1 = *n + 1;\n double *work = R_Calloc(*n, double), *work1 = R_Calloc(nsq, double);\n symm_mat(crr, time, n, maxC, mat); /* make full symmetric correlation \n matrix for individual i */\n F77_CALL(chol) (mat, n, n, mat, &info); /* Cholesky decomposition */\n for(i = 0; i < *n; i++) {\n work1[i * np1] = 1; /* set diag to 1 in empty matrix (i.e. create \n identity matrix) */\n F77_CALL(dtrsl) (mat, n, n, work1 + i * (*n), &job, &info); /* solves \n linear system given triangular matrix */\n *logdet -= log(fabs(mat[i * np1]));\n }\n Memcpy(mat, work1, nsq); \n R_Free(work); R_Free(work1);\n}\n\n\n\n\n\nI then manually computed the normalized residuals in R, through a regular Cholesky decomposition (same as t(chol) in R), through a \"reverse\" Cholesky decomposition and through EVD.\n\n\n\n\n# regular Cholesky algorithm (same as t(chol) for base R's chol function)\n regChol <- function(A){\n n = nrow(A)\n L = matrix(0,n,n)\n for (j in 1:n){\n if (j == 1){\n L[j,j] = sqrt(A[j,j])\n } else{\n L[j,j] = sqrt(A[j,j] - sum(L[j,1:(j-1)]^2))\n }\n if (j == 1){\n for (i in (j+1):n){\n L[i,j] = A[i,j]/L[j,j]\n }\n } else if (j < n){\n for (i in (j+1):n){\n L[i,j] = (A[i,j]-sum(L[i,1:(j-1)]*L[j,1:(j-1)]))/L[j,j]\n }\n }\n }\n return(L)\n }\n \n # reverse Cholesky algorithm\n revChol <- function(A){\n n = nrow(A)\n L = matrix(0,n,n)\n for (j in n-0:(n-1)){\n if (j == n){\n L[j,j] = sqrt(A[j,j])\n } else{\n L[j,j] = sqrt(A[j,j] - sum(L[(j+1):n,j]^2))\n }\n if (j == n){\n for (i in n-(n-j+1):(n-1)){\n L[j,i] = A[j,i]/L[j,j]\n }\n } else if (j > 1){\n for (i in n-(n-j+1):(n-1)){\n L[j,i] = (A[j,i]-sum(L[(j+1):n,i]*L[(j+1):n,j]))/L[j,j]\n }\n }\n }\n return(L)\n }\n \ncorMat <- model$modelStruct$corStruct #correlation structure of type corSymm\n \npdims <- as.integer(unlist(Dim(corMat))) #dimensions of correlation matrices\ncorMatFull <- corMatrix(corMat) #full correlation matrix\n ############################################################################\n#### Compute normalized residuals\n\n# `Using reverse Cholesky decomposition (gives same values as stata)\n\nnormres1 = 1:pdims[2]\nfor (i in 1:pdims[2]){\n dim <- pdims[i+4] #observations for individual i\n dim2 <- (pdims[i+4+pdims[2]]+1) #total observations up to individual i\n A <- matrix(unlist(corMatFull[i]), ncol = dim) # correlation matrix\n L <- revChol(A) # lower triangular / square root\n invSqLambda <- solve(t(L)) # invert L -- if regular Cholesky: use solve(L)\n normres1[dim2:(dim2 + dim-1)] <- \n invSqLambda %*% tmp$pearson[dim2:(dim2 + dim-1)] \n # multiply inverse square root with standardized residuals\n}\nt(L) %*% L #returns correlation matrix A given reversed Cholesky\n\n#Using regular Cholesky decomposition (gives same values as R)\nnormres2 = 1:pdims[2]\nfor (i in 1:pdims[2]){\n dim <- pdims[i+4] #observations for individual i\n dim2 <- (pdims[i+4+pdims[2]]+1) #total observations up to individual i\n A <- matrix(unlist(corMatFull[i]), ncol = dim) #correlation matrix\n L <- t(chol(A)) \n # lower triangular / square root -- note that regChol(A) = t(chol(A))\n invSqLambda <- solve(L) # invert L -- if regular Cholesky: use solve(L)\n normres2[dim2:(dim2 + dim-1)] <- \n invSqLambda %*% tmp$pearson[dim2:(dim2 + dim-1)] \n # multiply inverse square root with standardized residuals\n}\nL %*% t(L) #returns correlation matrix given standard Cholesky\n\n# Using EVD\nnormres3 = 1:pdims[2]\nfor (i in 1:pdims[2]){\n dim <- pdims[i+4] # observations for individual i\n dim2 <- (pdims[i+4+pdims[2]]+1) # total observations up to individual i\n A <- matrix(unlist(corMatFull[i]), ncol = dim) # correlation matrix\n E <- eigen(A) # EVD eigenvalue decomposition\n sqrtA <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors) \n# matrix square root\n invSqLambda <- solve(sqrtA) # invert sqrtA\n normres3[dim2:(dim2 + dim-1)] <- \ninvSqLambda %*% tmp$pearson[dim2:(dim2 + dim-1)] \n # multiply inverse square root with standardized residuals\n}\n\nround(normres1 - tmp$norm_res_stata, digits = 5) \n# approx 0 when using reverse Cholesky\nround(normres2 - tmp$norm_res_R, digits = 15) \n # approx 0 when using regular Cholesky\n \n##### will add qqplots/histograms with results in a couple of days\n\n\n\n\n\nThe results on the rat-example imply a left or a right-skew (Stata and R respecitvely) when compared to the standard normal, i.e. they may lead to different conlclusions about the model fit (I have an example, wherein the difference is more pronounced, but I do not want to break GDPR rules. Maybe someone can find a better example?). Using EVD, there does not seem to be as much of a skew to one side or the other.\n\n\n\n\n[image: QQ-plot of normalized residuals with each method compared to standard normal; source: https://i.sstatic.net/65PG6zuB.png] (https://i.sstatic.net/65PG6zuB.png)\n\n\n\n\n[image: Histogram of normalized residuals with each method compared to standard normal; source: https://i.sstatic.net/XWUljnac.png] (https://i.sstatic.net/XWUljnac.png)\n\n\n\n\nThe figures are created via:\n\n\n\n\nplot1 <- ggplot(as.data.frame(tmp$norm_res_stata), aes(sample = tmp$norm_res_stata)) +\n stat_qq() +\n geom_abline(slope = 1, intercept = 0) + \n labs(y = \"normalized residuals stata\")\nplot2 <- ggplot(as.data.frame(tmp$norm_res_R), aes(sample = tmp$norm_res_R)) +\n stat_qq() +\n geom_abline(slope = 1, intercept = 0) + \n labs(y = \"normalized residuals R\")\nplot3 <- ggplot(as.data.frame(normres3), aes(sample = normres3)) +\n stat_qq() +\n geom_abline(slope = 1, intercept = 0) + \n labs(y = \"normalized residuals EVD\")\ngrid.arrange(plot1, plot2, plot3, ncol = 3)\n\nplot1 <- ggplot(as.data.frame(tmp$norm_res_stata), aes(x = tmp$norm_res_stata)) +\n geom_histogram(aes(y =..density..), binwidth = 0.4, color = \"black\", fill = \"white\") + \n stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +\n labs(x = \"normalised residuals stata (reverse Cholesky)\")\nplot2 <- ggplot(as.data.frame(tmp$norm_res_R), aes(x = tmp$norm_res_R)) +\n geom_histogram(aes(y =..density..), binwidth = 0.4, color = \"black\", fill = \"white\") + \n stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +\n labs(x = \"normalised residuals R (standard Cholesky)\")\nplot3 <- ggplot(as.data.frame(normres3), aes(x = normres3)) +\n geom_histogram(aes(y =..density..), binwidth = 0.4, color = \"black\", fill = \"white\") + \n stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +\n labs(x = \"normalised residuals EVD\")\ngrid.arrange(plot1, plot2, plot3, ncol = 3)\n\n\n\n\n\nThe log from the Stata-code is given here:\n\n\n\n\n. \n. \n. import delim \"ratlong.csv\", clear \n(encoding automatically selected: ISO-8859-1)\n(5 vars, 100 obs)\n\n. \n. mixed weight b1.group##b0.time || rat: , reml baselev nocons res(un, t(time))\n\nPerforming gradient-based optimization: \nIteration 0: Log restricted-likelihood = -346.35796 (not concave)\nIteration 1: Log restricted-likelihood = -284.80839 (not concave)\nIteration 2: Log restricted-likelihood = -281.13028 \nIteration 3: Log restricted-likelihood = -278.4598 \nIteration 4: Log restricted-likelihood = -276.85378 \nIteration 5: Log restricted-likelihood = -276.76319 \nIteration 6: Log restricted-likelihood = -276.76264 \nIteration 7: Log restricted-likelihood = -276.76264 \n\nComputing standard errors ...\n\nMixed-effects REML regression Number of obs = 100\nGroup variable: rat Number of groups = 20\n Obs per group:\n min = 5\n avg = 5.0\n max = 5\n Wald chi2(9) = 1277.34\nLog restricted-likelihood = -276.76264 Prob > chi2 = 0.0000\n\n------------------------------------------------------------------------------\n weight | Coefficient Std. err. z P>|z| [95% conf. interval]\n-------------+----------------------------------------------------------------\n group |\n 1 | 0 (base)\n 3 | .7 2.270827 0.31 0.758 -3.75074 5.15074\n |\n time |\n 0 | 0 (base)\n 1 | 24.5 1.61744 15.15 0.000 21.32988 27.67012\n 2 | 52 2.045184 25.43 0.000 47.99151 56.00849\n 3 | 76.1 3.11002 24.47 0.000 70.00447 82.19553\n 4 | 106.6 4.073561 26.17 0.000 98.61597 114.584\n |\n group#time |\n 3 1 | -2.9 2.287405 -1.27 0.205 -7.383232 1.583232\n 3 2 | -10.9 2.892328 -3.77 0.000 -16.56886 -5.231142\n 3 3 | -22.4 4.398233 -5.09 0.000 -31.02038 -13.77962\n 3 4 | -37.1 5.760885 -6.44 0.000 -48.39113 -25.80887\n |\n _cons | 54 1.605717 33.63 0.000 50.85285 57.14715\n------------------------------------------------------------------------------\n\n------------------------------------------------------------------------------\n Random-effects parameters | Estimate Std. err. [95% conf. interval]\n-----------------------------+------------------------------------------------\nrat: (empty) |\n-----------------------------+------------------------------------------------\nResidual: Unstructured |\n var(e0) | 25.78329 8.592901 13.41698 49.54749\n var(e1) | 77.81102 25.92904 40.49434 149.5161\n var(e2) | 85.31105 28.41546 44.41058 163.8793\n var(e3) | 127.9611 42.64015 66.59387 245.8791\n var(e4) | 182.1112 60.70111 94.75779 349.9921\n cov(e0,e1) | 38.7166 13.95059 11.37394 66.05925\n cov(e0,e2) | 34.63327 13.73195 7.719139 61.5474\n cov(e0,e3) | 28.51106 15.09849 -1.081436 58.10355\n cov(e0,e4) | 20.97774 16.87309 -12.09292 54.04839\n cov(e1,e2) | 71.47769 25.52878 21.44219 121.5132\n cov(e1,e3) | 56.73882 27.02632 3.768207 109.7094\n cov(e1,e4) | 42.8555 29.78855 -15.52898 101.24\n cov(e2,e3) | 89.65551 32.42749 26.09881 153.2122\n cov(e2,e4) | 86.18887 35.69784 16.22239 156.1553\n cov(e3,e4) | 136.2 48.21199 41.70625 230.6938\n------------------------------------------------------------------------------\nLR test vs. linear model: chi2(14) = 139.19 Prob > chi2 = 0.0000\n\nNote: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If this is not true, then the\n reported test is conservative.\n\n. \n. predict res, rstandard\n\n. \n. list rat time res, sepby(rat)\n\n +------------------------+\n | rat time res |\n |------------------------|\n 1. | 1 0 -.3343025 |\n 2. | 1 1 .5268827 |\n 3. | 1 2 .4992422 |\n 4. | 1 3 .0732094 |\n 5. | 1 4 .8447663 |\n |------------------------|\n 6. | 2 0 -.3185105 |\n 7. | 2 1 -.2071171 |\n 8. | 2 2 1.274912 |\n 9. | 2 3 .7114518 |\n 10. | 2 4 1.215278 |\n |------------------------|\n 11. | 3 0 -.5135215 |\n 12. | 3 1 .0203645 |\n 13. | 3 2 -.5228509 |\n 14. | 3 3 -.8512383 |\n 15. | 3 4 1.808096 |\n |------------------------|\n 16. | 4 0 .4581496 |\n 17. | 4 1 -1.22478 |\n 18. | 4 2 -.9106107 |\n 19. | 4 3 -.7130803 |\n 20. | 4 4 .2519478 |\n |------------------------|\n 21. | 5 0 .3804444 |\n 22. | 5 1 .2287333 |\n 23. | 5 2 .9784756 |\n 24. | 5 3 -.3758776 |\n 25. | 5 4 -.7113822 |\n |------------------------|\n 26. | 6 0 -1.475303 |\n 27. | 6 1 -1.399477 |\n 28. | 6 2 -1.504103 |\n 29. | 6 3 1.288807 |\n 30. | 6 4 -.5631775 |\n |------------------------|\n 31. | 7 0 .473786 |\n 32. | 7 1 -.4318775 |\n 33. | 7 2 .5628197 |\n 34. | 7 3 -1.065117 |\n 35. | 7 4 -1.452405 |\n |------------------------|\n 36. | 8 0 .9371732 |\n 37. | 8 1 1.274058 |\n 38. | 8 2 .9912707 |\n 39. | 8 3 .9466597 |\n 40. | 8 4 -.4890752 |\n |------------------------|\n 41. | 9 0 .1423321 |\n 42. | 9 1 .311183 |\n 43. | 9 2 -.8122606 |\n 44. | 9 3 -.5272216 |\n 45. | 9 4 -1.526507 |\n |------------------------|\n 46. | 10 0 .2497523 |\n 47. | 10 1 .9020303 |\n 48. | 10 2 -.556895 |\n 49. | 10 3 .5124069 |\n 50. | 10 4 .6224594 |\n |------------------------|\n 51. | 18 0 .8534008 |\n 52. | 18 1 -1.234297 |\n 53. | 18 2 .7109886 |\n 54. | 18 3 1.567964 |\n 55. | 18 4 .3556911 |\n |------------------------|\n 56. | 19 0 1.202434 |\n 57. | 19 1 -.9995003 |\n 58. | 19 2 .4767818 |\n 59. | 19 3 .8310238 |\n 60. | 19 4 -.1630251 |\n |------------------------|\n 61. | 20 0 -.7255811 |\n 62. | 20 1 -.987914 |\n 63. | 20 2 1.937267 |\n 64. | 20 3 -1.758109 |\n 65. | 20 4 .6521003 |\n |------------------------|\n 66. | 21 0 -1.101692 |\n 67. | 21 1 2.462107 |\n 68. | 21 2 .2542622 |\n 69. | 21 3 .8310238 |\n 70. | 21 4 -.1630251 |\n |------------------------|\n 71. | 22 0 -1.298645 |\n 72. | 22 1 -.3421695 |\n 73. | 22 2 -1.104759 |\n 74. | 22 3 .5448185 |\n 75. | 22 4 1.170816 |\n |------------------------|\n 76. | 23 0 -1.124267 |\n 77. | 23 1 .0387734 |\n 78. | 23 2 .6711161 |\n 79. | 23 3 -.8830101 |\n 80. | 23 4 -.385332 |\n |------------------------|\n 81. | 24 0 .2229622 |\n 82. | 24 1 -.5032972 |\n 83. | 24 2 .0853191 |\n 84. | 24 3 1.314626 |\n 85. | 24 4 -1.200457 |\n |------------------------|\n 86. | 25 0 2.574736 |\n 87. | 25 1 .5105642 |\n 88. | 25 2 -1.381145 |\n 89. | 25 3 -.8254197 |\n 90. | 25 4 1.170816 |\n |------------------------|\n 91. | 26 0 -.5026115 |\n 92. | 26 1 -.0627333 |\n 93. | 26 2 -.9601486 |\n 94. | 26 3 -1.083703 |\n 95. | 26 4 -1.27456 |\n |------------------------|\n 96. | 27 0 -.1007365 |\n 97. | 27 1 1.118466 |\n 98. | 27 2 -.6896819 |\n 99. | 27 3 -.5392144 |\n100. | 27 4 -.1630251 |\n +------------------------+\n\n\n\n\n\nI found out the data example I was working with was RatWeight from package heplots, although I was given simply given the \"ratlong.csv\"-file, which is a heavily manipulated and reordered version of RatWeight, so if you want to reproduce it, here is how (I hope you will bear with me):\n\n\n\n\nrat <- RatWeight\nnames(rat) <- c(\"Group\", \"Weight0\", \"Weight1\", \"Weight2\", \"Weight3\", \"Weight4\")\nrat$Group <- factor(rat$Group, levels = c(\"Control\", \"Thyroxin\", \"Thiouracil\"))\nrat <- rat[order(rat$Group),]\nrat <- cbind(data.frame(Rat=1:27), rat) |>\n mutate(Rat = factor(Rat))\nrat <- subset(rat, Group != \"Thyroxin\")\nratlong <- rat |> gather(time, Weight, Weight0:Weight4) |>\n separate(time, c(\"W\", \"time\"), sep = 6) |>\n mutate(time = as.factor(as.numeric(time))) |>\n mutate(Group = as.factor(as.numeric(Group))) |>\n mutate(Weight = as.double(Weight))\nratlong <- ratlong[with(ratlong, order(Rat, time, Group)),]\nratlong$Weight[89:90] <- c(116,140)\nwrite.csv(ratlong, \"ratlong.csv\", row.names = FALSE)\n\n\n\n\n\nPackages used in general:\n\n\n\n\nlibrary(lme4)\nlibrary(nlme)\nlibrary(haven)\nlibrary(dplyr)\nlibrary(heplots)\nlibrary(parameters)\nlibrary(tidyverse)\nlibrary(gridExtra)\nlibrary(ggplot2)", "record_id": "Scientific-Statistics-QA:stats:677243", "selected_answer": {"answer_html": "

Upon further testing, it seems like all methods of normalizing the residuals will approximate uncorrelated standard normal distributions in large samples. In smaller samples, the difference between methods can look quite stark, but that does not make any of the methods less valid than any other. The most likely reason, as to why some datasets and their corresponding models look like they have a better fit using Stata (reverse Cholesky) as opposed to R (standard Cholesky), when examining their normalized residuals, is not due to any deficiency of either program but rather due to the random spread of the residuals, falling in such a way that one method is perceived to be more effective. If given several datasets, where a mixed model is a good fit, I now believe it is equally likely, between R and Stata, which program will give more accurate-looking normalized residuals.

\n

One of the tests I did is the following, wherein I measured the effectiveness of normalization by the closeness to the first 4 moments of the standard normal distribution. I did this for some arbitrary variance-covariance covariance matrix, used to repeatedly simulate N residuals, M number of times.

\n
library(gridExtra)\nlibrary(nlme)\nlibrary("mvtnorm")\nlibrary("ggplot2")\nlibrary("dplyr")\nlibrary(moments)\n\n#on large sample tests, all methods look very similar.\n#on small samples there is a distinction, where EVD tends to lie in between the other 2 methods\n#but this is NOT ALWAYS the case\n\nrevChol <- function(A){\n  n = nrow(A)\n  L = matrix(0,n,n)\n  for (j in n-0:(n-1)){\n    if (j == n){\n      L[j,j] = sqrt(A[j,j])\n    } else{\n      L[j,j] = sqrt(A[j,j] - sum(L[(j+1):n,j]^2))\n    }\n    if (j == n){\n      for (i in n-(n-j+1):(n-1)){\n        L[j,i] = A[j,i]/L[j,j]\n      }\n    } else if (j > 1){\n      for (i in n-(n-j+1):(n-1)){\n        L[j,i] = (A[j,i]-sum(L[(j+1):n,i]*L[(j+1):n,j]))/L[j,j]\n      }\n    }\n  }\n  return(L)\n}\n\n################################################################################\n### repeated small sample simulations\n\n\n\nSigma <- matrix(c(5,3,  3,7), byrow = TRUE, nrow = 2)\n\nN = 100\nM = 10000\nmeans <- matrix(0, M, 12)\nvariances <- matrix(0, M, 12)\nskewnesses <- matrix(0, M, 12)\nkurtosises <- matrix(0, M, 12)\nfor (i in 1:M){\n  y <- rmvnorm(N, sigma = Sigma)\n  \n  # compute normalized residuals for true sigma\n  L <- chol(Sigma) |> t()\n  y_tilde_stdChol <- apply(y, MARGIN = 1, FUN = function(y0){\n    solve(L)%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  L_alt <- revChol(Sigma)\n  y_tilde_revChol <- apply(y, MARGIN = 1, FUN = function(y0){\n    t(solve(L_alt))%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  E <- eigen(Sigma)\n  sqrtSig <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors)\n  y_tilde_EVD <- apply(y, MARGIN = 1, FUN = function(y0){\n    solve(sqrtSig)%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  # compute normalized residuals for sigma hat\n  Sig_hat <- var(y)\n  \n  L <- chol(Sig_hat) |> t()\n  y_tilde_stdChol2 <- apply(y, MARGIN = 1, FUN = function(y0){\n    solve(L)%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  L_alt <- revChol(Sig_hat)\n  y_tilde_revChol2 <- apply(y, MARGIN = 1, FUN = function(y0){\n    t(solve(L_alt))%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  E <- eigen(Sig_hat)\n  sqrtSig <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors)\n  y_tilde_EVD2 <- apply(y, MARGIN = 1, FUN = function(y0){\n    solve(sqrtSig)%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  means[i,1:3] <- c(mean(y_tilde_stdChol$V1), mean(y_tilde_revChol$V1), mean(y_tilde_EVD$V1))\n  means[i,4:6] <- c(mean(y_tilde_stdChol$V2), mean(y_tilde_revChol$V2), mean(y_tilde_EVD$V2))\n  means[i,7:9] <- c(mean(y_tilde_stdChol2$V1), mean(y_tilde_revChol2$V1), mean(y_tilde_EVD2$V1))\n  means[i,10:12] <- c(mean(y_tilde_stdChol2$V2), mean(y_tilde_revChol2$V2), mean(y_tilde_EVD2$V2))\n  \n  variances[i,1:3] <- c(var(y_tilde_stdChol$V1), var(y_tilde_revChol$V1), var(y_tilde_EVD$V1))\n  variances[i,4:6] <- c(var(y_tilde_stdChol$V2), var(y_tilde_revChol$V2), var(y_tilde_EVD$V2))\n  variances[i,7:9] <- c(var(y_tilde_stdChol2$V1), var(y_tilde_revChol2$V1), var(y_tilde_EVD2$V1))\n  variances[i,10:12] <- c(var(y_tilde_stdChol2$V2), var(y_tilde_revChol2$V2), var(y_tilde_EVD2$V2))\n  \n  skewnesses[i,1:3] <- c(skewness(y_tilde_stdChol$V1)$Skewness, skewness(y_tilde_revChol$V1)$Skewness, skewness(y_tilde_EVD$V1)$Skewness)\n  skewnesses[i,4:6] <- c(skewness(y_tilde_stdChol$V2)$Skewness, skewness(y_tilde_revChol$V2)$Skewness, skewness(y_tilde_EVD$V2)$Skewness)\n  skewnesses[i,7:9] <- c(skewness(y_tilde_stdChol2$V1)$Skewness, skewness(y_tilde_revChol2$V1)$Skewness, skewness(y_tilde_EVD2$V1)$Skewness)\n  skewnesses[i,10:12] <- c(skewness(y_tilde_stdChol2$V2)$Skewness, skewness(y_tilde_revChol2$V2)$Skewness, skewness(y_tilde_EVD2$V2)$Skewness)\n  \n  kurtosises[i,1:3] <- c(kurtosis(y_tilde_stdChol$V1)$Kurtosis, kurtosis(y_tilde_revChol$V1)$Kurtosis, kurtosis(y_tilde_EVD$V1)$Kurtosis)\n  kurtosises[i,4:6] <- c(kurtosis(y_tilde_stdChol$V2)$Kurtosis, kurtosis(y_tilde_revChol$V2)$Kurtosis, kurtosis(y_tilde_EVD$V2)$Kurtosis)\n  kurtosises[i,7:9] <- c(kurtosis(y_tilde_stdChol2$V1)$Kurtosis, kurtosis(y_tilde_revChol2$V1)$Kurtosis, kurtosis(y_tilde_EVD2$V1)$Kurtosis)\n  kurtosises[i,10:12] <- c(kurtosis(y_tilde_stdChol2$V2)$Kurtosis, kurtosis(y_tilde_revChol2$V2)$Kurtosis, kurtosis(y_tilde_EVD2$V2)$Kurtosis)\n  \n  print(i)\n}\n\n#record which methods have the lowest, middle and highest mean for each vector and each simulation\nmeanorder <- cbind(cbind(t(apply(abs(means[,1:3]),1,order)),\n                         t(apply(abs(means[,4:6]),1,order)),\n                         t(apply(abs(means[,7:9]),1,order)),\n                         t(apply(abs(means[,10:12]),1,order))))\n\n#record which methods have the variance closest to 1 for each vector and each simulation\nvarorder <- cbind(cbind(t(apply(abs(1-variances[,1:3]),1,order)),\n                        t(apply(abs(1-variances[,4:6]),1,order)),\n                        t(apply(abs(1-variances[,7:9]),1,order)),\n                        t(apply(abs(1-variances[,10:12]),1,order))))\n\n#record which methods have the lowest, middle and highest skewness for each vector and each simulation\nskeworder <- cbind(cbind(t(apply(abs(skewnesses[,1:3]),1,order)), \n                         t(apply(abs(skewnesses[,4:6]),1,order)), \n                         t(apply(abs(skewnesses[,7:9]),1,order)), \n                         t(apply(abs(skewnesses[,10:12]),1,order))))\n\n#record which methods have the lowest, middle and highest (excess) kurtosis for each vector and each simulation\nkurtorder <- cbind(cbind(t(apply(abs(kurtosises[,1:3]),1,order)), \n                         t(apply(abs(kurtosises[,4:6]),1,order)), \n                         t(apply(abs(kurtosises[,7:9]),1,order)), \n                         t(apply(abs(kurtosises[,10:12]),1,order))))\n\n#specify that "method 1" is standard Cholesky, "method 2" is reverse Cholesky and "method 3" is EVD\nrename <- function(V){\n  V <- data.frame(V) %>% mutate(\n    across(\n      .cols = everything(),\n      .fns = ~ case_when(\n        .x == 1 ~ 'stdChol',\n        .x == 2 ~ 'revChol',\n        .x == 3 ~ 'EVD',\n        TRUE ~ as.character(.x)\n      )\n    )\n  )\n}\nmeanorder <- rename(meanorder)\nvarorder <- rename(varorder)\nskeworder <- rename(skeworder)\nkurtorder <- rename(kurtorder)\n\n#plots\npM1 <- meanorder |>\n  ggplot(aes(x = X1)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. mean of norm-res-v1", x = "method (true Sigma)")\npM2 <- meanorder |>\n  ggplot(aes(x = X4)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. mean of norm-res-v2", x = "method (true Sigma)")\npM3 <- meanorder |>\n  ggplot(aes(x = X7)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. mean of norm-res-v1", x = "method (Sigma-hat)")\npM4 <- meanorder |>\n  ggplot(aes(x = X10)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. mean of norm-res-v2", x = "method (Sigma-hat)")\n\npV1 <- varorder |>\n  ggplot(aes(x = X1)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "var closest to 1 for norm-res-v1", x = "method (true Sigma)")\npV2 <- varorder |>\n  ggplot(aes(x = X4)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "var closest to 1 for norm-res-v2", x = "method (true Sigma)")\npV3 <- varorder |>\n  ggplot(aes(x = X7)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "var closest to 1 for norm-res-v1", x = "method (Sigma-hat)")\npV4 <- varorder |>\n  ggplot(aes(x = X10)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "var closest to 1 for norm-res-v2", x = "method (Sigma-hat)")\n\npS1 <- skeworder |>\n  ggplot(aes(x = X1)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. skew of norm-res-v1", x = "method (true Sigma)")\npS2 <- skeworder |>\n  ggplot(aes(x = X4)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. skew of norm-res-v2", x = "method (true Sigma)")\npS3 <- skeworder |>\n  ggplot(aes(x = X7)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. skew of norm-res-v1", x = "method (Sigma-hat)")\npS4 <- skeworder |>\n  ggplot(aes(x = X10)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. skew of norm-res-v2", x = "method (Sigma-hat)")\n\npK1 <- kurtorder |>\n  ggplot(aes(x = X1)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. kurt. of norm-res-v1", x = "method (true Sigma)")\npK2 <- kurtorder |>\n  ggplot(aes(x = X4)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. kurt. of norm-res-v2", x = "method (true Sigma)")\npK3 <- kurtorder |>\n  ggplot(aes(x = X7)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. kurt. of norm-res-v1", x = "method (Sigma-hat)")\npK4 <- kurtorder |>\n  ggplot(aes(x = X10)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. kurt. of norm-res-v2", x = "method (Sigma-hat)")\n\n\ngrid.arrange(pM1, pV1, pS1, pK1,\n             pM2, pV2, pS2, pK2,\n             pM3, pV3, pS3, pK3,\n             pM4, pV4, pS4, pK4, ncol = 4)\n
\n", "answer_id": 677304, "answer_text": "Upon further testing, it seems like all methods of normalizing the residuals will approximate uncorrelated standard normal distributions in large samples. In smaller samples, the difference between methods can look quite stark, but that does not make any of the methods less valid than any other. The most likely reason, as to why some datasets and their corresponding models look like they have a better fit using Stata (reverse Cholesky) as opposed to R (standard Cholesky), when examining their normalized residuals, is not due to any deficiency of either program but rather due to the random spread of the residuals, falling in such a way that one method is perceived to be more effective. If given several datasets, where a mixed model is a good fit, I now believe it is equally likely, between R and Stata, which program will give more accurate-looking normalized residuals.\n\n\n\n\nOne of the tests I did is the following, wherein I measured the effectiveness of normalization by the closeness to the first 4 moments of the standard normal distribution. I did this for some arbitrary variance-covariance covariance matrix, used to repeatedly simulate N residuals, M number of times.\n\n\n\n\nlibrary(gridExtra)\nlibrary(nlme)\nlibrary(\"mvtnorm\")\nlibrary(\"ggplot2\")\nlibrary(\"dplyr\")\nlibrary(moments)\n\n#on large sample tests, all methods look very similar.\n#on small samples there is a distinction, where EVD tends to lie in between the other 2 methods\n#but this is NOT ALWAYS the case\n\nrevChol <- function(A){\n n = nrow(A)\n L = matrix(0,n,n)\n for (j in n-0:(n-1)){\n if (j == n){\n L[j,j] = sqrt(A[j,j])\n } else{\n L[j,j] = sqrt(A[j,j] - sum(L[(j+1):n,j]^2))\n }\n if (j == n){\n for (i in n-(n-j+1):(n-1)){\n L[j,i] = A[j,i]/L[j,j]\n }\n } else if (j > 1){\n for (i in n-(n-j+1):(n-1)){\n L[j,i] = (A[j,i]-sum(L[(j+1):n,i]*L[(j+1):n,j]))/L[j,j]\n }\n }\n }\n return(L)\n}\n\n################################################################################\n### repeated small sample simulations\n\n\n\nSigma <- matrix(c(5,3, 3,7), byrow = TRUE, nrow = 2)\n\nN = 100\nM = 10000\nmeans <- matrix(0, M, 12)\nvariances <- matrix(0, M, 12)\nskewnesses <- matrix(0, M, 12)\nkurtosises <- matrix(0, M, 12)\nfor (i in 1:M){\n y <- rmvnorm(N, sigma = Sigma)\n \n # compute normalized residuals for true sigma\n L <- chol(Sigma) |> t()\n y_tilde_stdChol <- apply(y, MARGIN = 1, FUN = function(y0){\n solve(L)%*%y0\n }) |>\n t() |>\n as_tibble()\n \n L_alt <- revChol(Sigma)\n y_tilde_revChol <- apply(y, MARGIN = 1, FUN = function(y0){\n t(solve(L_alt))%*%y0\n }) |>\n t() |>\n as_tibble()\n \n E <- eigen(Sigma)\n sqrtSig <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors)\n y_tilde_EVD <- apply(y, MARGIN = 1, FUN = function(y0){\n solve(sqrtSig)%*%y0\n }) |>\n t() |>\n as_tibble()\n \n # compute normalized residuals for sigma hat\n Sig_hat <- var(y)\n \n L <- chol(Sig_hat) |> t()\n y_tilde_stdChol2 <- apply(y, MARGIN = 1, FUN = function(y0){\n solve(L)%*%y0\n }) |>\n t() |>\n as_tibble()\n \n L_alt <- revChol(Sig_hat)\n y_tilde_revChol2 <- apply(y, MARGIN = 1, FUN = function(y0){\n t(solve(L_alt))%*%y0\n }) |>\n t() |>\n as_tibble()\n \n E <- eigen(Sig_hat)\n sqrtSig <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors)\n y_tilde_EVD2 <- apply(y, MARGIN = 1, FUN = function(y0){\n solve(sqrtSig)%*%y0\n }) |>\n t() |>\n as_tibble()\n \n means[i,1:3] <- c(mean(y_tilde_stdChol$V1), mean(y_tilde_revChol$V1), mean(y_tilde_EVD$V1))\n means[i,4:6] <- c(mean(y_tilde_stdChol$V2), mean(y_tilde_revChol$V2), mean(y_tilde_EVD$V2))\n means[i,7:9] <- c(mean(y_tilde_stdChol2$V1), mean(y_tilde_revChol2$V1), mean(y_tilde_EVD2$V1))\n means[i,10:12] <- c(mean(y_tilde_stdChol2$V2), mean(y_tilde_revChol2$V2), mean(y_tilde_EVD2$V2))\n \n variances[i,1:3] <- c(var(y_tilde_stdChol$V1), var(y_tilde_revChol$V1), var(y_tilde_EVD$V1))\n variances[i,4:6] <- c(var(y_tilde_stdChol$V2), var(y_tilde_revChol$V2), var(y_tilde_EVD$V2))\n variances[i,7:9] <- c(var(y_tilde_stdChol2$V1), var(y_tilde_revChol2$V1), var(y_tilde_EVD2$V1))\n variances[i,10:12] <- c(var(y_tilde_stdChol2$V2), var(y_tilde_revChol2$V2), var(y_tilde_EVD2$V2))\n \n skewnesses[i,1:3] <- c(skewness(y_tilde_stdChol$V1)$Skewness, skewness(y_tilde_revChol$V1)$Skewness, skewness(y_tilde_EVD$V1)$Skewness)\n skewnesses[i,4:6] <- c(skewness(y_tilde_stdChol$V2)$Skewness, skewness(y_tilde_revChol$V2)$Skewness, skewness(y_tilde_EVD$V2)$Skewness)\n skewnesses[i,7:9] <- c(skewness(y_tilde_stdChol2$V1)$Skewness, skewness(y_tilde_revChol2$V1)$Skewness, skewness(y_tilde_EVD2$V1)$Skewness)\n skewnesses[i,10:12] <- c(skewness(y_tilde_stdChol2$V2)$Skewness, skewness(y_tilde_revChol2$V2)$Skewness, skewness(y_tilde_EVD2$V2)$Skewness)\n \n kurtosises[i,1:3] <- c(kurtosis(y_tilde_stdChol$V1)$Kurtosis, kurtosis(y_tilde_revChol$V1)$Kurtosis, kurtosis(y_tilde_EVD$V1)$Kurtosis)\n kurtosises[i,4:6] <- c(kurtosis(y_tilde_stdChol$V2)$Kurtosis, kurtosis(y_tilde_revChol$V2)$Kurtosis, kurtosis(y_tilde_EVD$V2)$Kurtosis)\n kurtosises[i,7:9] <- c(kurtosis(y_tilde_stdChol2$V1)$Kurtosis, kurtosis(y_tilde_revChol2$V1)$Kurtosis, kurtosis(y_tilde_EVD2$V1)$Kurtosis)\n kurtosises[i,10:12] <- c(kurtosis(y_tilde_stdChol2$V2)$Kurtosis, kurtosis(y_tilde_revChol2$V2)$Kurtosis, kurtosis(y_tilde_EVD2$V2)$Kurtosis)\n \n print(i)\n}\n\n#record which methods have the lowest, middle and highest mean for each vector and each simulation\nmeanorder <- cbind(cbind(t(apply(abs(means[,1:3]),1,order)),\n t(apply(abs(means[,4:6]),1,order)),\n t(apply(abs(means[,7:9]),1,order)),\n t(apply(abs(means[,10:12]),1,order))))\n\n#record which methods have the variance closest to 1 for each vector and each simulation\nvarorder <- cbind(cbind(t(apply(abs(1-variances[,1:3]),1,order)),\n t(apply(abs(1-variances[,4:6]),1,order)),\n t(apply(abs(1-variances[,7:9]),1,order)),\n t(apply(abs(1-variances[,10:12]),1,order))))\n\n#record which methods have the lowest, middle and highest skewness for each vector and each simulation\nskeworder <- cbind(cbind(t(apply(abs(skewnesses[,1:3]),1,order)), \n t(apply(abs(skewnesses[,4:6]),1,order)), \n t(apply(abs(skewnesses[,7:9]),1,order)), \n t(apply(abs(skewnesses[,10:12]),1,order))))\n\n#record which methods have the lowest, middle and highest (excess) kurtosis for each vector and each simulation\nkurtorder <- cbind(cbind(t(apply(abs(kurtosises[,1:3]),1,order)), \n t(apply(abs(kurtosises[,4:6]),1,order)), \n t(apply(abs(kurtosises[,7:9]),1,order)), \n t(apply(abs(kurtosises[,10:12]),1,order))))\n\n#specify that \"method 1\" is standard Cholesky, \"method 2\" is reverse Cholesky and \"method 3\" is EVD\nrename <- function(V){\n V <- data.frame(V) %>% mutate(\n across(\n .cols = everything(),\n .fns = ~ case_when(\n .x == 1 ~ 'stdChol',\n .x == 2 ~ 'revChol',\n .x == 3 ~ 'EVD',\n TRUE ~ as.character(.x)\n )\n )\n )\n}\nmeanorder <- rename(meanorder)\nvarorder <- rename(varorder)\nskeworder <- rename(skeworder)\nkurtorder <- rename(kurtorder)\n\n#plots\npM1 <- meanorder |>\n ggplot(aes(x = X1)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. mean of norm-res-v1\", x = \"method (true Sigma)\")\npM2 <- meanorder |>\n ggplot(aes(x = X4)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. mean of norm-res-v2\", x = \"method (true Sigma)\")\npM3 <- meanorder |>\n ggplot(aes(x = X7)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. mean of norm-res-v1\", x = \"method (Sigma-hat)\")\npM4 <- meanorder |>\n ggplot(aes(x = X10)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. mean of norm-res-v2\", x = \"method (Sigma-hat)\")\n\npV1 <- varorder |>\n ggplot(aes(x = X1)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"var closest to 1 for norm-res-v1\", x = \"method (true Sigma)\")\npV2 <- varorder |>\n ggplot(aes(x = X4)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"var closest to 1 for norm-res-v2\", x = \"method (true Sigma)\")\npV3 <- varorder |>\n ggplot(aes(x = X7)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"var closest to 1 for norm-res-v1\", x = \"method (Sigma-hat)\")\npV4 <- varorder |>\n ggplot(aes(x = X10)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"var closest to 1 for norm-res-v2\", x = \"method (Sigma-hat)\")\n\npS1 <- skeworder |>\n ggplot(aes(x = X1)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. skew of norm-res-v1\", x = \"method (true Sigma)\")\npS2 <- skeworder |>\n ggplot(aes(x = X4)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. skew of norm-res-v2\", x = \"method (true Sigma)\")\npS3 <- skeworder |>\n ggplot(aes(x = X7)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. skew of norm-res-v1\", x = \"method (Sigma-hat)\")\npS4 <- skeworder |>\n ggplot(aes(x = X10)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. skew of norm-res-v2\", x = \"method (Sigma-hat)\")\n\npK1 <- kurtorder |>\n ggplot(aes(x = X1)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. kurt. of norm-res-v1\", x = \"method (true Sigma)\")\npK2 <- kurtorder |>\n ggplot(aes(x = X4)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. kurt. of norm-res-v2\", x = \"method (true Sigma)\")\npK3 <- kurtorder |>\n ggplot(aes(x = X7)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. kurt. of norm-res-v1\", x = \"method (Sigma-hat)\")\npK4 <- kurtorder |>\n ggplot(aes(x = X10)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. kurt. of norm-res-v2\", x = \"method (Sigma-hat)\")\n\n\ngrid.arrange(pM1, pV1, pS1, pK1,\n pM2, pV2, pS2, pK2,\n pM3, pV3, pS3, pK3,\n pM4, pV4, pS4, pK4, ncol = 4)", "answer_url": "https://stats.stackexchange.com/a/677304", "author": "Michael", "author_url": "https://stats.stackexchange.com/users/517013/michael", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-30T10:48:26+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": 677243, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-30T10:48:26+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "26D2264C-CE23-455D-B111-D7C569BDFF44", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/26D2264C-CE23-455D-B111-D7C569BDFF44/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-30T10:53:50+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "77058962-D9B4-4D5E-BA55-FC2DD80B5B36", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/77058962-D9B4-4D5E-BA55-FC2DD80B5B36/view-source"}], "score": 2, "updated_at": "2026-09-30T10:53:50+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

Upon further testing, it seems like all methods of normalizing the residuals will approximate uncorrelated standard normal distributions in large samples. In smaller samples, the difference between methods can look quite stark, but that does not make any of the methods less valid than any other. The most likely reason, as to why some datasets and their corresponding models look like they have a better fit using Stata (reverse Cholesky) as opposed to R (standard Cholesky), when examining their normalized residuals, is not due to any deficiency of either program but rather due to the random spread of the residuals, falling in such a way that one method is perceived to be more effective. If given several datasets, where a mixed model is a good fit, I now believe it is equally likely, between R and Stata, which program will give more accurate-looking normalized residuals.

\n

One of the tests I did is the following, wherein I measured the effectiveness of normalization by the closeness to the first 4 moments of the standard normal distribution. I did this for some arbitrary variance-covariance covariance matrix, used to repeatedly simulate N residuals, M number of times.

\n
library(gridExtra)\nlibrary(nlme)\nlibrary("mvtnorm")\nlibrary("ggplot2")\nlibrary("dplyr")\nlibrary(moments)\n\n#on large sample tests, all methods look very similar.\n#on small samples there is a distinction, where EVD tends to lie in between the other 2 methods\n#but this is NOT ALWAYS the case\n\nrevChol <- function(A){\n  n = nrow(A)\n  L = matrix(0,n,n)\n  for (j in n-0:(n-1)){\n    if (j == n){\n      L[j,j] = sqrt(A[j,j])\n    } else{\n      L[j,j] = sqrt(A[j,j] - sum(L[(j+1):n,j]^2))\n    }\n    if (j == n){\n      for (i in n-(n-j+1):(n-1)){\n        L[j,i] = A[j,i]/L[j,j]\n      }\n    } else if (j > 1){\n      for (i in n-(n-j+1):(n-1)){\n        L[j,i] = (A[j,i]-sum(L[(j+1):n,i]*L[(j+1):n,j]))/L[j,j]\n      }\n    }\n  }\n  return(L)\n}\n\n################################################################################\n### repeated small sample simulations\n\n\n\nSigma <- matrix(c(5,3,  3,7), byrow = TRUE, nrow = 2)\n\nN = 100\nM = 10000\nmeans <- matrix(0, M, 12)\nvariances <- matrix(0, M, 12)\nskewnesses <- matrix(0, M, 12)\nkurtosises <- matrix(0, M, 12)\nfor (i in 1:M){\n  y <- rmvnorm(N, sigma = Sigma)\n  \n  # compute normalized residuals for true sigma\n  L <- chol(Sigma) |> t()\n  y_tilde_stdChol <- apply(y, MARGIN = 1, FUN = function(y0){\n    solve(L)%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  L_alt <- revChol(Sigma)\n  y_tilde_revChol <- apply(y, MARGIN = 1, FUN = function(y0){\n    t(solve(L_alt))%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  E <- eigen(Sigma)\n  sqrtSig <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors)\n  y_tilde_EVD <- apply(y, MARGIN = 1, FUN = function(y0){\n    solve(sqrtSig)%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  # compute normalized residuals for sigma hat\n  Sig_hat <- var(y)\n  \n  L <- chol(Sig_hat) |> t()\n  y_tilde_stdChol2 <- apply(y, MARGIN = 1, FUN = function(y0){\n    solve(L)%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  L_alt <- revChol(Sig_hat)\n  y_tilde_revChol2 <- apply(y, MARGIN = 1, FUN = function(y0){\n    t(solve(L_alt))%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  E <- eigen(Sig_hat)\n  sqrtSig <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors)\n  y_tilde_EVD2 <- apply(y, MARGIN = 1, FUN = function(y0){\n    solve(sqrtSig)%*%y0\n  }) |>\n    t() |>\n    as_tibble()\n  \n  means[i,1:3] <- c(mean(y_tilde_stdChol$V1), mean(y_tilde_revChol$V1), mean(y_tilde_EVD$V1))\n  means[i,4:6] <- c(mean(y_tilde_stdChol$V2), mean(y_tilde_revChol$V2), mean(y_tilde_EVD$V2))\n  means[i,7:9] <- c(mean(y_tilde_stdChol2$V1), mean(y_tilde_revChol2$V1), mean(y_tilde_EVD2$V1))\n  means[i,10:12] <- c(mean(y_tilde_stdChol2$V2), mean(y_tilde_revChol2$V2), mean(y_tilde_EVD2$V2))\n  \n  variances[i,1:3] <- c(var(y_tilde_stdChol$V1), var(y_tilde_revChol$V1), var(y_tilde_EVD$V1))\n  variances[i,4:6] <- c(var(y_tilde_stdChol$V2), var(y_tilde_revChol$V2), var(y_tilde_EVD$V2))\n  variances[i,7:9] <- c(var(y_tilde_stdChol2$V1), var(y_tilde_revChol2$V1), var(y_tilde_EVD2$V1))\n  variances[i,10:12] <- c(var(y_tilde_stdChol2$V2), var(y_tilde_revChol2$V2), var(y_tilde_EVD2$V2))\n  \n  skewnesses[i,1:3] <- c(skewness(y_tilde_stdChol$V1)$Skewness, skewness(y_tilde_revChol$V1)$Skewness, skewness(y_tilde_EVD$V1)$Skewness)\n  skewnesses[i,4:6] <- c(skewness(y_tilde_stdChol$V2)$Skewness, skewness(y_tilde_revChol$V2)$Skewness, skewness(y_tilde_EVD$V2)$Skewness)\n  skewnesses[i,7:9] <- c(skewness(y_tilde_stdChol2$V1)$Skewness, skewness(y_tilde_revChol2$V1)$Skewness, skewness(y_tilde_EVD2$V1)$Skewness)\n  skewnesses[i,10:12] <- c(skewness(y_tilde_stdChol2$V2)$Skewness, skewness(y_tilde_revChol2$V2)$Skewness, skewness(y_tilde_EVD2$V2)$Skewness)\n  \n  kurtosises[i,1:3] <- c(kurtosis(y_tilde_stdChol$V1)$Kurtosis, kurtosis(y_tilde_revChol$V1)$Kurtosis, kurtosis(y_tilde_EVD$V1)$Kurtosis)\n  kurtosises[i,4:6] <- c(kurtosis(y_tilde_stdChol$V2)$Kurtosis, kurtosis(y_tilde_revChol$V2)$Kurtosis, kurtosis(y_tilde_EVD$V2)$Kurtosis)\n  kurtosises[i,7:9] <- c(kurtosis(y_tilde_stdChol2$V1)$Kurtosis, kurtosis(y_tilde_revChol2$V1)$Kurtosis, kurtosis(y_tilde_EVD2$V1)$Kurtosis)\n  kurtosises[i,10:12] <- c(kurtosis(y_tilde_stdChol2$V2)$Kurtosis, kurtosis(y_tilde_revChol2$V2)$Kurtosis, kurtosis(y_tilde_EVD2$V2)$Kurtosis)\n  \n  print(i)\n}\n\n#record which methods have the lowest, middle and highest mean for each vector and each simulation\nmeanorder <- cbind(cbind(t(apply(abs(means[,1:3]),1,order)),\n                         t(apply(abs(means[,4:6]),1,order)),\n                         t(apply(abs(means[,7:9]),1,order)),\n                         t(apply(abs(means[,10:12]),1,order))))\n\n#record which methods have the variance closest to 1 for each vector and each simulation\nvarorder <- cbind(cbind(t(apply(abs(1-variances[,1:3]),1,order)),\n                        t(apply(abs(1-variances[,4:6]),1,order)),\n                        t(apply(abs(1-variances[,7:9]),1,order)),\n                        t(apply(abs(1-variances[,10:12]),1,order))))\n\n#record which methods have the lowest, middle and highest skewness for each vector and each simulation\nskeworder <- cbind(cbind(t(apply(abs(skewnesses[,1:3]),1,order)), \n                         t(apply(abs(skewnesses[,4:6]),1,order)), \n                         t(apply(abs(skewnesses[,7:9]),1,order)), \n                         t(apply(abs(skewnesses[,10:12]),1,order))))\n\n#record which methods have the lowest, middle and highest (excess) kurtosis for each vector and each simulation\nkurtorder <- cbind(cbind(t(apply(abs(kurtosises[,1:3]),1,order)), \n                         t(apply(abs(kurtosises[,4:6]),1,order)), \n                         t(apply(abs(kurtosises[,7:9]),1,order)), \n                         t(apply(abs(kurtosises[,10:12]),1,order))))\n\n#specify that "method 1" is standard Cholesky, "method 2" is reverse Cholesky and "method 3" is EVD\nrename <- function(V){\n  V <- data.frame(V) %>% mutate(\n    across(\n      .cols = everything(),\n      .fns = ~ case_when(\n        .x == 1 ~ 'stdChol',\n        .x == 2 ~ 'revChol',\n        .x == 3 ~ 'EVD',\n        TRUE ~ as.character(.x)\n      )\n    )\n  )\n}\nmeanorder <- rename(meanorder)\nvarorder <- rename(varorder)\nskeworder <- rename(skeworder)\nkurtorder <- rename(kurtorder)\n\n#plots\npM1 <- meanorder |>\n  ggplot(aes(x = X1)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. mean of norm-res-v1", x = "method (true Sigma)")\npM2 <- meanorder |>\n  ggplot(aes(x = X4)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. mean of norm-res-v2", x = "method (true Sigma)")\npM3 <- meanorder |>\n  ggplot(aes(x = X7)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. mean of norm-res-v1", x = "method (Sigma-hat)")\npM4 <- meanorder |>\n  ggplot(aes(x = X10)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. mean of norm-res-v2", x = "method (Sigma-hat)")\n\npV1 <- varorder |>\n  ggplot(aes(x = X1)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "var closest to 1 for norm-res-v1", x = "method (true Sigma)")\npV2 <- varorder |>\n  ggplot(aes(x = X4)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "var closest to 1 for norm-res-v2", x = "method (true Sigma)")\npV3 <- varorder |>\n  ggplot(aes(x = X7)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "var closest to 1 for norm-res-v1", x = "method (Sigma-hat)")\npV4 <- varorder |>\n  ggplot(aes(x = X10)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "var closest to 1 for norm-res-v2", x = "method (Sigma-hat)")\n\npS1 <- skeworder |>\n  ggplot(aes(x = X1)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. skew of norm-res-v1", x = "method (true Sigma)")\npS2 <- skeworder |>\n  ggplot(aes(x = X4)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. skew of norm-res-v2", x = "method (true Sigma)")\npS3 <- skeworder |>\n  ggplot(aes(x = X7)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. skew of norm-res-v1", x = "method (Sigma-hat)")\npS4 <- skeworder |>\n  ggplot(aes(x = X10)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. skew of norm-res-v2", x = "method (Sigma-hat)")\n\npK1 <- kurtorder |>\n  ggplot(aes(x = X1)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. kurt. of norm-res-v1", x = "method (true Sigma)")\npK2 <- kurtorder |>\n  ggplot(aes(x = X4)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. kurt. of norm-res-v2", x = "method (true Sigma)")\npK3 <- kurtorder |>\n  ggplot(aes(x = X7)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. kurt. of norm-res-v1", x = "method (Sigma-hat)")\npK4 <- kurtorder |>\n  ggplot(aes(x = X10)) +\n  geom_histogram(stat="count",fill = "white", color = "black") +\n  labs(y = "smallest abs. kurt. of norm-res-v2", x = "method (Sigma-hat)")\n\n\ngrid.arrange(pM1, pV1, pS1, pK1,\n             pM2, pV2, pS2, pK2,\n             pM3, pV3, pS3, pK3,\n             pM4, pV4, pS4, pK4, ncol = 4)\n
\n", "answer_id": 677304, "answer_text": "Upon further testing, it seems like all methods of normalizing the residuals will approximate uncorrelated standard normal distributions in large samples. In smaller samples, the difference between methods can look quite stark, but that does not make any of the methods less valid than any other. The most likely reason, as to why some datasets and their corresponding models look like they have a better fit using Stata (reverse Cholesky) as opposed to R (standard Cholesky), when examining their normalized residuals, is not due to any deficiency of either program but rather due to the random spread of the residuals, falling in such a way that one method is perceived to be more effective. If given several datasets, where a mixed model is a good fit, I now believe it is equally likely, between R and Stata, which program will give more accurate-looking normalized residuals.\n\n\n\n\nOne of the tests I did is the following, wherein I measured the effectiveness of normalization by the closeness to the first 4 moments of the standard normal distribution. I did this for some arbitrary variance-covariance covariance matrix, used to repeatedly simulate N residuals, M number of times.\n\n\n\n\nlibrary(gridExtra)\nlibrary(nlme)\nlibrary(\"mvtnorm\")\nlibrary(\"ggplot2\")\nlibrary(\"dplyr\")\nlibrary(moments)\n\n#on large sample tests, all methods look very similar.\n#on small samples there is a distinction, where EVD tends to lie in between the other 2 methods\n#but this is NOT ALWAYS the case\n\nrevChol <- function(A){\n n = nrow(A)\n L = matrix(0,n,n)\n for (j in n-0:(n-1)){\n if (j == n){\n L[j,j] = sqrt(A[j,j])\n } else{\n L[j,j] = sqrt(A[j,j] - sum(L[(j+1):n,j]^2))\n }\n if (j == n){\n for (i in n-(n-j+1):(n-1)){\n L[j,i] = A[j,i]/L[j,j]\n }\n } else if (j > 1){\n for (i in n-(n-j+1):(n-1)){\n L[j,i] = (A[j,i]-sum(L[(j+1):n,i]*L[(j+1):n,j]))/L[j,j]\n }\n }\n }\n return(L)\n}\n\n################################################################################\n### repeated small sample simulations\n\n\n\nSigma <- matrix(c(5,3, 3,7), byrow = TRUE, nrow = 2)\n\nN = 100\nM = 10000\nmeans <- matrix(0, M, 12)\nvariances <- matrix(0, M, 12)\nskewnesses <- matrix(0, M, 12)\nkurtosises <- matrix(0, M, 12)\nfor (i in 1:M){\n y <- rmvnorm(N, sigma = Sigma)\n \n # compute normalized residuals for true sigma\n L <- chol(Sigma) |> t()\n y_tilde_stdChol <- apply(y, MARGIN = 1, FUN = function(y0){\n solve(L)%*%y0\n }) |>\n t() |>\n as_tibble()\n \n L_alt <- revChol(Sigma)\n y_tilde_revChol <- apply(y, MARGIN = 1, FUN = function(y0){\n t(solve(L_alt))%*%y0\n }) |>\n t() |>\n as_tibble()\n \n E <- eigen(Sigma)\n sqrtSig <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors)\n y_tilde_EVD <- apply(y, MARGIN = 1, FUN = function(y0){\n solve(sqrtSig)%*%y0\n }) |>\n t() |>\n as_tibble()\n \n # compute normalized residuals for sigma hat\n Sig_hat <- var(y)\n \n L <- chol(Sig_hat) |> t()\n y_tilde_stdChol2 <- apply(y, MARGIN = 1, FUN = function(y0){\n solve(L)%*%y0\n }) |>\n t() |>\n as_tibble()\n \n L_alt <- revChol(Sig_hat)\n y_tilde_revChol2 <- apply(y, MARGIN = 1, FUN = function(y0){\n t(solve(L_alt))%*%y0\n }) |>\n t() |>\n as_tibble()\n \n E <- eigen(Sig_hat)\n sqrtSig <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors)\n y_tilde_EVD2 <- apply(y, MARGIN = 1, FUN = function(y0){\n solve(sqrtSig)%*%y0\n }) |>\n t() |>\n as_tibble()\n \n means[i,1:3] <- c(mean(y_tilde_stdChol$V1), mean(y_tilde_revChol$V1), mean(y_tilde_EVD$V1))\n means[i,4:6] <- c(mean(y_tilde_stdChol$V2), mean(y_tilde_revChol$V2), mean(y_tilde_EVD$V2))\n means[i,7:9] <- c(mean(y_tilde_stdChol2$V1), mean(y_tilde_revChol2$V1), mean(y_tilde_EVD2$V1))\n means[i,10:12] <- c(mean(y_tilde_stdChol2$V2), mean(y_tilde_revChol2$V2), mean(y_tilde_EVD2$V2))\n \n variances[i,1:3] <- c(var(y_tilde_stdChol$V1), var(y_tilde_revChol$V1), var(y_tilde_EVD$V1))\n variances[i,4:6] <- c(var(y_tilde_stdChol$V2), var(y_tilde_revChol$V2), var(y_tilde_EVD$V2))\n variances[i,7:9] <- c(var(y_tilde_stdChol2$V1), var(y_tilde_revChol2$V1), var(y_tilde_EVD2$V1))\n variances[i,10:12] <- c(var(y_tilde_stdChol2$V2), var(y_tilde_revChol2$V2), var(y_tilde_EVD2$V2))\n \n skewnesses[i,1:3] <- c(skewness(y_tilde_stdChol$V1)$Skewness, skewness(y_tilde_revChol$V1)$Skewness, skewness(y_tilde_EVD$V1)$Skewness)\n skewnesses[i,4:6] <- c(skewness(y_tilde_stdChol$V2)$Skewness, skewness(y_tilde_revChol$V2)$Skewness, skewness(y_tilde_EVD$V2)$Skewness)\n skewnesses[i,7:9] <- c(skewness(y_tilde_stdChol2$V1)$Skewness, skewness(y_tilde_revChol2$V1)$Skewness, skewness(y_tilde_EVD2$V1)$Skewness)\n skewnesses[i,10:12] <- c(skewness(y_tilde_stdChol2$V2)$Skewness, skewness(y_tilde_revChol2$V2)$Skewness, skewness(y_tilde_EVD2$V2)$Skewness)\n \n kurtosises[i,1:3] <- c(kurtosis(y_tilde_stdChol$V1)$Kurtosis, kurtosis(y_tilde_revChol$V1)$Kurtosis, kurtosis(y_tilde_EVD$V1)$Kurtosis)\n kurtosises[i,4:6] <- c(kurtosis(y_tilde_stdChol$V2)$Kurtosis, kurtosis(y_tilde_revChol$V2)$Kurtosis, kurtosis(y_tilde_EVD$V2)$Kurtosis)\n kurtosises[i,7:9] <- c(kurtosis(y_tilde_stdChol2$V1)$Kurtosis, kurtosis(y_tilde_revChol2$V1)$Kurtosis, kurtosis(y_tilde_EVD2$V1)$Kurtosis)\n kurtosises[i,10:12] <- c(kurtosis(y_tilde_stdChol2$V2)$Kurtosis, kurtosis(y_tilde_revChol2$V2)$Kurtosis, kurtosis(y_tilde_EVD2$V2)$Kurtosis)\n \n print(i)\n}\n\n#record which methods have the lowest, middle and highest mean for each vector and each simulation\nmeanorder <- cbind(cbind(t(apply(abs(means[,1:3]),1,order)),\n t(apply(abs(means[,4:6]),1,order)),\n t(apply(abs(means[,7:9]),1,order)),\n t(apply(abs(means[,10:12]),1,order))))\n\n#record which methods have the variance closest to 1 for each vector and each simulation\nvarorder <- cbind(cbind(t(apply(abs(1-variances[,1:3]),1,order)),\n t(apply(abs(1-variances[,4:6]),1,order)),\n t(apply(abs(1-variances[,7:9]),1,order)),\n t(apply(abs(1-variances[,10:12]),1,order))))\n\n#record which methods have the lowest, middle and highest skewness for each vector and each simulation\nskeworder <- cbind(cbind(t(apply(abs(skewnesses[,1:3]),1,order)), \n t(apply(abs(skewnesses[,4:6]),1,order)), \n t(apply(abs(skewnesses[,7:9]),1,order)), \n t(apply(abs(skewnesses[,10:12]),1,order))))\n\n#record which methods have the lowest, middle and highest (excess) kurtosis for each vector and each simulation\nkurtorder <- cbind(cbind(t(apply(abs(kurtosises[,1:3]),1,order)), \n t(apply(abs(kurtosises[,4:6]),1,order)), \n t(apply(abs(kurtosises[,7:9]),1,order)), \n t(apply(abs(kurtosises[,10:12]),1,order))))\n\n#specify that \"method 1\" is standard Cholesky, \"method 2\" is reverse Cholesky and \"method 3\" is EVD\nrename <- function(V){\n V <- data.frame(V) %>% mutate(\n across(\n .cols = everything(),\n .fns = ~ case_when(\n .x == 1 ~ 'stdChol',\n .x == 2 ~ 'revChol',\n .x == 3 ~ 'EVD',\n TRUE ~ as.character(.x)\n )\n )\n )\n}\nmeanorder <- rename(meanorder)\nvarorder <- rename(varorder)\nskeworder <- rename(skeworder)\nkurtorder <- rename(kurtorder)\n\n#plots\npM1 <- meanorder |>\n ggplot(aes(x = X1)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. mean of norm-res-v1\", x = \"method (true Sigma)\")\npM2 <- meanorder |>\n ggplot(aes(x = X4)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. mean of norm-res-v2\", x = \"method (true Sigma)\")\npM3 <- meanorder |>\n ggplot(aes(x = X7)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. mean of norm-res-v1\", x = \"method (Sigma-hat)\")\npM4 <- meanorder |>\n ggplot(aes(x = X10)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. mean of norm-res-v2\", x = \"method (Sigma-hat)\")\n\npV1 <- varorder |>\n ggplot(aes(x = X1)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"var closest to 1 for norm-res-v1\", x = \"method (true Sigma)\")\npV2 <- varorder |>\n ggplot(aes(x = X4)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"var closest to 1 for norm-res-v2\", x = \"method (true Sigma)\")\npV3 <- varorder |>\n ggplot(aes(x = X7)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"var closest to 1 for norm-res-v1\", x = \"method (Sigma-hat)\")\npV4 <- varorder |>\n ggplot(aes(x = X10)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"var closest to 1 for norm-res-v2\", x = \"method (Sigma-hat)\")\n\npS1 <- skeworder |>\n ggplot(aes(x = X1)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. skew of norm-res-v1\", x = \"method (true Sigma)\")\npS2 <- skeworder |>\n ggplot(aes(x = X4)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. skew of norm-res-v2\", x = \"method (true Sigma)\")\npS3 <- skeworder |>\n ggplot(aes(x = X7)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. skew of norm-res-v1\", x = \"method (Sigma-hat)\")\npS4 <- skeworder |>\n ggplot(aes(x = X10)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. skew of norm-res-v2\", x = \"method (Sigma-hat)\")\n\npK1 <- kurtorder |>\n ggplot(aes(x = X1)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. kurt. of norm-res-v1\", x = \"method (true Sigma)\")\npK2 <- kurtorder |>\n ggplot(aes(x = X4)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. kurt. of norm-res-v2\", x = \"method (true Sigma)\")\npK3 <- kurtorder |>\n ggplot(aes(x = X7)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. kurt. of norm-res-v1\", x = \"method (Sigma-hat)\")\npK4 <- kurtorder |>\n ggplot(aes(x = X10)) +\n geom_histogram(stat=\"count\",fill = \"white\", color = \"black\") +\n labs(y = \"smallest abs. kurt. of norm-res-v2\", x = \"method (Sigma-hat)\")\n\n\ngrid.arrange(pM1, pV1, pS1, pK1,\n pM2, pV2, pS2, pK2,\n pM3, pV3, pS3, pK3,\n pM4, pV4, pS4, pK4, ncol = 4)", "answer_url": "https://stats.stackexchange.com/a/677304", "author": "Michael", "author_url": "https://stats.stackexchange.com/users/517013/michael", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-30T10:48:26+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": 677243, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-30T10:48:26+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "26D2264C-CE23-455D-B111-D7C569BDFF44", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/26D2264C-CE23-455D-B111-D7C569BDFF44/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-30T10:53:50+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "77058962-D9B4-4D5E-BA55-FC2DD80B5B36", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/77058962-D9B4-4D5E-BA55-FC2DD80B5B36/view-source"}], "score": 2, "updated_at": "2026-09-30T10:53:50+00:00"}], "domain": "statistics", "external_links": ["https://github.com/cran/nlme", "https://i.sstatic.net/65PG6zuB.png", "https://i.sstatic.net/XWUljnac.png", "https://www.stata.com/manuals/me.pdf"], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Michael", "question_author_url": "https://stats.stackexchange.com/users/517013/michael", "question_author_user_type": "registered", "question_created_at": "2026-09-23T09:39:51+00:00", "question_html": "

I have been tasked with understanding why normalized residuals between R and Stata are different when using mixed models (i.e. the nlme package in R).

\n

What I have found is that the residuals are both theoretically computed the same way: norm_residuals = sigma^(-1) * Lambda^(-1/2) * residuals

\n

This is based on the works of José C. Pinheiro and Douglas M. Bates. The nlme package in R references their book "Mixed effects models in S and S-PLUS" (2000), while Stata references their article "Computational Methods for Multilevel Modelling" (1998) (see page 575 of "STATA MULTILEVEL MIXED-EFFECTS REFERENCE MANUAL RELEASE 19. The terminology is a bit confusing, as 'normalized' residuals in R are called 'standardized' residuals in stata, which is not to be confused with 'Pearson' residuals, which is what R considers 'standardized').

\n

However, the way the matrix square root is computed is different between the two programs. The result can have a rather significant impact on whether or not the normalized residuals actually seem to follow a normal distribution.

\n

The way R computes the matrix square root is through the Cholesky decomposition A = L*L^T (using the chol function from FORTRAN77). I cannot access the source code for Stata, but it seems like Stata uses Cholesky decomposition as well, however using a Cholesky decomposition algorithm starting at "the bottom right" of the matrix instead of "the top left" such that A = L^T * L. Using these two methods for Cholesky decomposition, I have been able to recreate the normalised residuals from R and Stata respectively.

\n

When using QQ-plots on the normalized residuals calculated with R and those calculated with Stata, the two results plots imply different conclusions about the normality of the residuals.

\n

In principle, could one not use several different methods for Cholesky decomposition to compute a matrix square root and therefore come to significantly different conclusions? Would it therefore not be preferable to use eigenvalue decomposition to compute a matrix square root as opposed to Cholesky decomposition? One reason I believe EVD would be better is that it does not require transposing one "square root", i.e. we have directly that A^(1/2) * A^(1/2) = A.

\n

Here, I have added an example:

\n
ratlong <- read.csv("ratlong.csv") |>\n  mutate(Rat = factor(Rat), Group = as_factor(Group)) |>\n  mutate(time = as.factor(as.numeric(time)))\n\nmodel <- gls(Weight ~ time*Group,\n                 correlation = corSymm(form = ~ as.integer(time) | Rat),\n                 weights = varIdent(form = ~ 1 | time),\n                 na.action = na.exclude,\n                 method = "REML",\n                 data = ratlong)\n\nsummary(model)\nparameters(model)\ngetVarCov(model)\n\ntmp <- mutate(\n  ratlong,\n  fit = fitted(model),\n  response = residuals(model, type = "r"),\n  pearson = residuals(model, type = "p"),\n  norm_res_R = residuals(model, type = "n"),\n  norm_res_stata = c(\n    -.3343025, .5268827, .4992422, .0732094, .8447663,\n    -.3185105, -.2071171, 1.274912, .7114518, 1.215278,\n    -.5135215, .0203645, -.5228509, -.8512383, 1.808096,\n    .4581496, -1.22478, -.9106107, -.7130803, .2519478,\n    .3804444, .2287333, .9784756, -.3758776, -.7113822,\n    -1.475303, -1.399477, -1.504103, 1.288807, -.5631775,\n    .473786, -.4318775, .5628197, -1.065117, -1.452405,\n    .9371732, 1.274058, .9912707, .9466597, -.4890752,\n    .1423321, .311183, -.8122606, -.5272216, -1.526507,\n    .2497523, .9020303, -.556895, .5124069, .6224594,\n    .8534008, -1.234297, .7109886, 1.567964, .3556911,\n    1.202434, -.9995003, .4767818, .8310238, -.1630251,\n    -.7255811, -.987914, 1.937267, -1.758109, .6521003,\n    -1.101692, 2.462107, .2542622, .8310238, -.1630251,\n    -1.298645, -.3421695, -1.104759, .5448185, 1.170816,\n    -1.124267, .0387734, .6711161, -.8830101, -.385332,\n    .2229622, -.5032972, .0853191, 1.314626, -1.200457,\n    2.574736, .5105642, -1.381145, -.8254197, 1.170816,\n    -.5026115, -.0627333, -.9601486, -1.083703, -1.27456,\n    -.1007365, 1.118466, -.6896819, -.5392144, -.1630251)\n)\n\n# Here we observe that the pearson residual is approximately equal to the \n# normalized at time 1 for R and time 5 for stata\ntmp$pearson[seq(5, nrow(ratlong), 5)] - \n           tmp$norm_res_stata[seq(5, nrow(ratlong), 5)]\ntmp$pearson[seq(1, nrow(ratlong), 5)] - \n           tmp$norm_res_R[seq(1, nrow(ratlong), 5)]\n
\n

According to the nmle package (retrieved from github), the residuals are computed as such:

\n
#### from residuals.gls\nval <- object$residuals\nif (type != \"response\") {\n  val <- val/attr(val, \"std\")\n  lab <- \"Standardized residuals\"\n  if (type == \"normalized\") {\nif (!is.null(cSt <- object$modelStruct$corStruct)) {\n  ## normalize according to inv-trans factor\n  val <- recalc(cSt, list(Xy = as.matrix(val)))$Xy[, 1]\n      lab <- "Normalized residuals"\n    }\n  }\n}\n    \n#### from recalc.corSymm\nrecalc.corSymm <- function(object, conLin, ...)\n{\n  val <-\n    .C(symm_recalc,\n       Xy = as.double(conLin[["Xy"]]),\n       as.integer(unlist(Dim(object))),\n       as.integer(ncol(conLin[["Xy"]])),\n       as.double(as.vector(object)),\n       as.integer(unlist(getCovariate(object))),\n       as.integer(attr(object, "maxCov")),\n       logLik = double(1))[c("Xy", "logLik")]\n  conLin[["Xy"]][] <- val[["Xy"]]\n  conLin[["logLik"]] <- conLin[["logLik"]] + val[["logLik"]]\n  conLin\n}\n    \n#### from symm_recalc (written in C)\nvoid\nsymm_recalc(double *Xy, int *pdims, int *ZXcol, double *pars,\n            int *time, int *maxC, double *logdet)\n{\n  int N = pdims[0], M = pdims[1], *len = pdims + 4, *start = len + M, i;\n  double *crr = R_Calloc(*maxC * (*maxC - 1) / 2, double);\n  /* parameters assumed in unconstrained form */\n    symm_fullCorr(pars, maxC, crr); /* get all correlations (not correlation \n      matrix) */\n  for(i = 0; i < M;  i++) {\n    double *Factor = R_Calloc((len[i] * len[i]), double);\n    symm_fact(crr, time + start[i], &len[i], maxC, Factor, logdet);\n    mult_mat(Xy + start[i], N, Factor, len[i], len[i], len[i],\n             Xy + start[i], N, *ZXcol);\n    R_Free(Factor);\n  }\n  R_Free(crr);\n}\n    \n#### from symm_fact (also written in C)\nstatic void\nsymm_fact(double *crr, int *time, int *n, int *maxC, double *mat,\n          double *logdet)\n{\n  int job = 11L, info, i, nsq = *n * (*n), np1 = *n + 1;\n  double *work = R_Calloc(*n, double), *work1 = R_Calloc(nsq, double);\n  symm_mat(crr, time, n, maxC, mat); /* make full symmetric correlation \n    matrix for individual i */\n  F77_CALL(chol) (mat, n, n, mat, &info); /* Cholesky decomposition */\n  for(i = 0; i < *n; i++) {\n    work1[i * np1] = 1; /* set diag to 1 in empty matrix (i.e. create \n      identity matrix) */\n    F77_CALL(dtrsl) (mat, n, n, work1 + i * (*n), &job, &info); /* solves \n       linear system given triangular matrix */\n    *logdet -= log(fabs(mat[i * np1]));\n  }\n  Memcpy(mat, work1, nsq); \n  R_Free(work); R_Free(work1);\n}\n
\n

I then manually computed the normalized residuals in R, through a regular Cholesky decomposition (same as t(chol) in R), through a "reverse" Cholesky decomposition and through EVD.

\n
# regular Cholesky algorithm (same as t(chol) for base R's chol function)\n        regChol <- function(A){\n          n = nrow(A)\n          L = matrix(0,n,n)\n          for (j in 1:n){\n            if (j == 1){\n              L[j,j] = sqrt(A[j,j])\n            } else{\n              L[j,j] = sqrt(A[j,j] - sum(L[j,1:(j-1)]^2))\n            }\n            if (j == 1){\n              for (i in (j+1):n){\n                L[i,j] = A[i,j]/L[j,j]\n              }\n            } else if (j < n){\n              for (i in (j+1):n){\n                L[i,j] = (A[i,j]-sum(L[i,1:(j-1)]*L[j,1:(j-1)]))/L[j,j]\n              }\n            }\n          }\n          return(L)\n        }\n        \n        # reverse Cholesky algorithm\n        revChol <- function(A){\n          n = nrow(A)\n          L = matrix(0,n,n)\n          for (j in n-0:(n-1)){\n            if (j == n){\n              L[j,j] = sqrt(A[j,j])\n            } else{\n              L[j,j] = sqrt(A[j,j] - sum(L[(j+1):n,j]^2))\n            }\n            if (j == n){\n              for (i in n-(n-j+1):(n-1)){\n                L[j,i] = A[j,i]/L[j,j]\n              }\n            } else if (j > 1){\n              for (i in n-(n-j+1):(n-1)){\n                L[j,i] = (A[j,i]-sum(L[(j+1):n,i]*L[(j+1):n,j]))/L[j,j]\n              }\n            }\n          }\n          return(L)\n        }\n        \ncorMat <- model$modelStruct$corStruct #correlation structure of type corSymm\n        \npdims <- as.integer(unlist(Dim(corMat))) #dimensions of correlation matrices\ncorMatFull <- corMatrix(corMat) #full correlation matrix\n             ############################################################################\n#### Compute normalized residuals\n\n# `Using reverse Cholesky decomposition (gives same values as stata)\n\nnormres1 = 1:pdims[2]\nfor (i in 1:pdims[2]){\n  dim <- pdims[i+4] #observations for individual i\n  dim2 <- (pdims[i+4+pdims[2]]+1) #total observations up to individual i\n  A <- matrix(unlist(corMatFull[i]), ncol = dim) # correlation matrix\n  L <- revChol(A) # lower triangular / square root\n  invSqLambda <- solve(t(L)) # invert L  --  if regular Cholesky: use solve(L)\n  normres1[dim2:(dim2 + dim-1)] <- \n    invSqLambda %*% tmp$pearson[dim2:(dim2 + dim-1)] \n    # multiply inverse square root with standardized residuals\n}\nt(L) %*% L #returns correlation matrix A given reversed Cholesky\n\n#Using regular Cholesky decomposition (gives same values as R)\nnormres2 = 1:pdims[2]\nfor (i in 1:pdims[2]){\n  dim <- pdims[i+4] #observations for individual i\n  dim2 <- (pdims[i+4+pdims[2]]+1) #total observations up to individual i\n  A <- matrix(unlist(corMatFull[i]), ncol = dim) #correlation matrix\n  L <- t(chol(A)) \n     # lower triangular / square root  --  note that regChol(A) = t(chol(A))\n  invSqLambda <- solve(L) # invert L  --  if regular Cholesky: use solve(L)\n  normres2[dim2:(dim2 + dim-1)] <- \n    invSqLambda %*% tmp$pearson[dim2:(dim2 + dim-1)] \n    # multiply inverse square root with standardized residuals\n}\nL %*% t(L) #returns correlation matrix given standard Cholesky\n\n# Using EVD\nnormres3 = 1:pdims[2]\nfor (i in 1:pdims[2]){\n  dim <- pdims[i+4] # observations for individual i\n  dim2 <- (pdims[i+4+pdims[2]]+1) # total observations up to individual i\n  A <- matrix(unlist(corMatFull[i]), ncol = dim) # correlation matrix\n  E <- eigen(A) # EVD eigenvalue decomposition\n  sqrtA <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors) \n# matrix square root\n  invSqLambda <- solve(sqrtA) # invert sqrtA\n  normres3[dim2:(dim2 + dim-1)] <- \ninvSqLambda %*% tmp$pearson[dim2:(dim2 + dim-1)] \n    # multiply inverse square root with standardized residuals\n}\n\nround(normres1 - tmp$norm_res_stata, digits = 5) \n# approx 0 when using reverse Cholesky\nround(normres2 - tmp$norm_res_R, digits = 15) \n    # approx 0 when using regular Cholesky\n    \n##### will add qqplots/histograms with results in a couple of days\n
\n

The results on the rat-example imply a left or a right-skew (Stata and R respecitvely) when compared to the standard normal, i.e. they may lead to different conlclusions about the model fit (I have an example, wherein the difference is more pronounced, but I do not want to break GDPR rules. Maybe someone can find a better example?). Using EVD, there does not seem to be as much of a skew to one side or the other.

\n

\"QQ-plot

\n

\"Histogram

\n

The figures are created via:

\n
plot1 <- ggplot(as.data.frame(tmp$norm_res_stata), aes(sample = tmp$norm_res_stata)) +\n  stat_qq() +\n  geom_abline(slope = 1, intercept = 0) + \n  labs(y = "normalized residuals stata")\nplot2 <- ggplot(as.data.frame(tmp$norm_res_R), aes(sample = tmp$norm_res_R)) +\n  stat_qq() +\n  geom_abline(slope = 1, intercept = 0) + \n  labs(y = "normalized residuals R")\nplot3 <- ggplot(as.data.frame(normres3), aes(sample = normres3)) +\n  stat_qq() +\n  geom_abline(slope = 1, intercept = 0) + \n  labs(y = "normalized residuals EVD")\ngrid.arrange(plot1, plot2, plot3, ncol = 3)\n\nplot1 <- ggplot(as.data.frame(tmp$norm_res_stata), aes(x = tmp$norm_res_stata)) +\n  geom_histogram(aes(y =..density..), binwidth = 0.4, color = "black", fill = "white") + \n  stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +\n  labs(x = "normalised residuals stata (reverse Cholesky)")\nplot2 <- ggplot(as.data.frame(tmp$norm_res_R), aes(x = tmp$norm_res_R)) +\n  geom_histogram(aes(y =..density..), binwidth = 0.4, color = "black", fill = "white") + \n  stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +\n  labs(x = "normalised residuals R (standard Cholesky)")\nplot3 <- ggplot(as.data.frame(normres3), aes(x = normres3)) +\n  geom_histogram(aes(y =..density..), binwidth = 0.4, color = "black", fill = "white") + \n  stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +\n  labs(x = "normalised residuals EVD")\ngrid.arrange(plot1, plot2, plot3, ncol = 3)\n
\n

The log from the Stata-code is given here:

\n
. \n. \n. import delim "ratlong.csv", clear \n(encoding automatically selected: ISO-8859-1)\n(5 vars, 100 obs)\n\n. \n. mixed weight b1.group##b0.time || rat: , reml baselev nocons res(un, t(time))\n\nPerforming gradient-based optimization: \nIteration 0:  Log restricted-likelihood = -346.35796  (not concave)\nIteration 1:  Log restricted-likelihood = -284.80839  (not concave)\nIteration 2:  Log restricted-likelihood = -281.13028  \nIteration 3:  Log restricted-likelihood =  -278.4598  \nIteration 4:  Log restricted-likelihood = -276.85378  \nIteration 5:  Log restricted-likelihood = -276.76319  \nIteration 6:  Log restricted-likelihood = -276.76264  \nIteration 7:  Log restricted-likelihood = -276.76264  \n\nComputing standard errors ...\n\nMixed-effects REML regression                       Number of obs    =     100\nGroup variable: rat                                 Number of groups =      20\n                                                    Obs per group:\n                                                                 min =       5\n                                                                 avg =     5.0\n                                                                 max =       5\n                                                    Wald chi2(9)     = 1277.34\nLog restricted-likelihood = -276.76264              Prob > chi2      =  0.0000\n\n------------------------------------------------------------------------------\n      weight | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]\n-------------+----------------------------------------------------------------\n       group |\n          1  |          0  (base)\n          3  |         .7   2.270827     0.31   0.758     -3.75074     5.15074\n             |\n        time |\n          0  |          0  (base)\n          1  |       24.5    1.61744    15.15   0.000     21.32988    27.67012\n          2  |         52   2.045184    25.43   0.000     47.99151    56.00849\n          3  |       76.1    3.11002    24.47   0.000     70.00447    82.19553\n          4  |      106.6   4.073561    26.17   0.000     98.61597     114.584\n             |\n  group#time |\n        3 1  |       -2.9   2.287405    -1.27   0.205    -7.383232    1.583232\n        3 2  |      -10.9   2.892328    -3.77   0.000    -16.56886   -5.231142\n        3 3  |      -22.4   4.398233    -5.09   0.000    -31.02038   -13.77962\n        3 4  |      -37.1   5.760885    -6.44   0.000    -48.39113   -25.80887\n             |\n       _cons |         54   1.605717    33.63   0.000     50.85285    57.14715\n------------------------------------------------------------------------------\n\n------------------------------------------------------------------------------\n  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]\n-----------------------------+------------------------------------------------\nrat:                 (empty) |\n-----------------------------+------------------------------------------------\nResidual: Unstructured       |\n                     var(e0) |   25.78329   8.592901      13.41698    49.54749\n                     var(e1) |   77.81102   25.92904      40.49434    149.5161\n                     var(e2) |   85.31105   28.41546      44.41058    163.8793\n                     var(e3) |   127.9611   42.64015      66.59387    245.8791\n                     var(e4) |   182.1112   60.70111      94.75779    349.9921\n                  cov(e0,e1) |    38.7166   13.95059      11.37394    66.05925\n                  cov(e0,e2) |   34.63327   13.73195      7.719139     61.5474\n                  cov(e0,e3) |   28.51106   15.09849     -1.081436    58.10355\n                  cov(e0,e4) |   20.97774   16.87309     -12.09292    54.04839\n                  cov(e1,e2) |   71.47769   25.52878      21.44219    121.5132\n                  cov(e1,e3) |   56.73882   27.02632      3.768207    109.7094\n                  cov(e1,e4) |    42.8555   29.78855     -15.52898      101.24\n                  cov(e2,e3) |   89.65551   32.42749      26.09881    153.2122\n                  cov(e2,e4) |   86.18887   35.69784      16.22239    156.1553\n                  cov(e3,e4) |      136.2   48.21199      41.70625    230.6938\n------------------------------------------------------------------------------\nLR test vs. linear model: chi2(14) = 139.19               Prob > chi2 = 0.0000\n\nNote: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If this is not true, then the\n      reported test is conservative.\n\n. \n. predict res, rstandard\n\n. \n. list rat time res, sepby(rat)\n\n     +------------------------+\n     | rat   time         res |\n     |------------------------|\n  1. |   1      0   -.3343025 |\n  2. |   1      1    .5268827 |\n  3. |   1      2    .4992422 |\n  4. |   1      3    .0732094 |\n  5. |   1      4    .8447663 |\n     |------------------------|\n  6. |   2      0   -.3185105 |\n  7. |   2      1   -.2071171 |\n  8. |   2      2    1.274912 |\n  9. |   2      3    .7114518 |\n 10. |   2      4    1.215278 |\n     |------------------------|\n 11. |   3      0   -.5135215 |\n 12. |   3      1    .0203645 |\n 13. |   3      2   -.5228509 |\n 14. |   3      3   -.8512383 |\n 15. |   3      4    1.808096 |\n     |------------------------|\n 16. |   4      0    .4581496 |\n 17. |   4      1    -1.22478 |\n 18. |   4      2   -.9106107 |\n 19. |   4      3   -.7130803 |\n 20. |   4      4    .2519478 |\n     |------------------------|\n 21. |   5      0    .3804444 |\n 22. |   5      1    .2287333 |\n 23. |   5      2    .9784756 |\n 24. |   5      3   -.3758776 |\n 25. |   5      4   -.7113822 |\n     |------------------------|\n 26. |   6      0   -1.475303 |\n 27. |   6      1   -1.399477 |\n 28. |   6      2   -1.504103 |\n 29. |   6      3    1.288807 |\n 30. |   6      4   -.5631775 |\n     |------------------------|\n 31. |   7      0     .473786 |\n 32. |   7      1   -.4318775 |\n 33. |   7      2    .5628197 |\n 34. |   7      3   -1.065117 |\n 35. |   7      4   -1.452405 |\n     |------------------------|\n 36. |   8      0    .9371732 |\n 37. |   8      1    1.274058 |\n 38. |   8      2    .9912707 |\n 39. |   8      3    .9466597 |\n 40. |   8      4   -.4890752 |\n     |------------------------|\n 41. |   9      0    .1423321 |\n 42. |   9      1     .311183 |\n 43. |   9      2   -.8122606 |\n 44. |   9      3   -.5272216 |\n 45. |   9      4   -1.526507 |\n     |------------------------|\n 46. |  10      0    .2497523 |\n 47. |  10      1    .9020303 |\n 48. |  10      2    -.556895 |\n 49. |  10      3    .5124069 |\n 50. |  10      4    .6224594 |\n     |------------------------|\n 51. |  18      0    .8534008 |\n 52. |  18      1   -1.234297 |\n 53. |  18      2    .7109886 |\n 54. |  18      3    1.567964 |\n 55. |  18      4    .3556911 |\n     |------------------------|\n 56. |  19      0    1.202434 |\n 57. |  19      1   -.9995003 |\n 58. |  19      2    .4767818 |\n 59. |  19      3    .8310238 |\n 60. |  19      4   -.1630251 |\n     |------------------------|\n 61. |  20      0   -.7255811 |\n 62. |  20      1    -.987914 |\n 63. |  20      2    1.937267 |\n 64. |  20      3   -1.758109 |\n 65. |  20      4    .6521003 |\n     |------------------------|\n 66. |  21      0   -1.101692 |\n 67. |  21      1    2.462107 |\n 68. |  21      2    .2542622 |\n 69. |  21      3    .8310238 |\n 70. |  21      4   -.1630251 |\n     |------------------------|\n 71. |  22      0   -1.298645 |\n 72. |  22      1   -.3421695 |\n 73. |  22      2   -1.104759 |\n 74. |  22      3    .5448185 |\n 75. |  22      4    1.170816 |\n     |------------------------|\n 76. |  23      0   -1.124267 |\n 77. |  23      1    .0387734 |\n 78. |  23      2    .6711161 |\n 79. |  23      3   -.8830101 |\n 80. |  23      4    -.385332 |\n     |------------------------|\n 81. |  24      0    .2229622 |\n 82. |  24      1   -.5032972 |\n 83. |  24      2    .0853191 |\n 84. |  24      3    1.314626 |\n 85. |  24      4   -1.200457 |\n     |------------------------|\n 86. |  25      0    2.574736 |\n 87. |  25      1    .5105642 |\n 88. |  25      2   -1.381145 |\n 89. |  25      3   -.8254197 |\n 90. |  25      4    1.170816 |\n     |------------------------|\n 91. |  26      0   -.5026115 |\n 92. |  26      1   -.0627333 |\n 93. |  26      2   -.9601486 |\n 94. |  26      3   -1.083703 |\n 95. |  26      4    -1.27456 |\n     |------------------------|\n 96. |  27      0   -.1007365 |\n 97. |  27      1    1.118466 |\n 98. |  27      2   -.6896819 |\n 99. |  27      3   -.5392144 |\n100. |  27      4   -.1630251 |\n     +------------------------+\n
\n

I found out the data example I was working with was RatWeight from package heplots, although I was given simply given the "ratlong.csv"-file, which is a heavily manipulated and reordered version of RatWeight, so if you want to reproduce it, here is how (I hope you will bear with me):

\n
rat <- RatWeight\nnames(rat) <- c("Group", "Weight0", "Weight1", "Weight2", "Weight3", "Weight4")\nrat$Group <- factor(rat$Group, levels = c("Control", "Thyroxin", "Thiouracil"))\nrat <- rat[order(rat$Group),]\nrat <- cbind(data.frame(Rat=1:27), rat) |>\n  mutate(Rat = factor(Rat))\nrat <- subset(rat, Group != "Thyroxin")\nratlong <- rat |> gather(time, Weight, Weight0:Weight4) |>\n  separate(time, c("W", "time"), sep = 6) |>\n  mutate(time = as.factor(as.numeric(time))) |>\n  mutate(Group = as.factor(as.numeric(Group))) |>\n  mutate(Weight = as.double(Weight))\nratlong <- ratlong[with(ratlong, order(Rat, time, Group)),]\nratlong$Weight[89:90] <- c(116,140)\nwrite.csv(ratlong, "ratlong.csv", row.names = FALSE)\n
\n

Packages used in general:

\n
library(lme4)\nlibrary(nlme)\nlibrary(haven)\nlibrary(dplyr)\nlibrary(heplots)\nlibrary(parameters)\nlibrary(tidyverse)\nlibrary(gridExtra)\nlibrary(ggplot2)\n
\n", "question_id": 677243, "question_license": "CC BY-SA 4.0", "question_score": 5, "question_text": "I have been tasked with understanding why normalized residuals between R and Stata are different when using mixed models (i.e. the nlme package in R).\n\n\n\n\nWhat I have found is that the residuals are both theoretically computed the same way: norm_residuals = sigma^(-1) * Lambda^(-1/2) * residuals\n\n\n\n\nThis is based on the works of José C. Pinheiro and Douglas M. Bates. The nlme package in R references their book \"Mixed effects models in S and S-PLUS\" (2000), while Stata references their article \"Computational Methods for Multilevel Modelling\" (1998) (see page 575 of \"STATA MULTILEVEL MIXED-EFFECTS REFERENCE MANUAL RELEASE 19 (https://www.stata.com/manuals/me.pdf). The terminology is a bit confusing, as 'normalized' residuals in R are called 'standardized' residuals in stata, which is not to be confused with 'Pearson' residuals, which is what R considers 'standardized').\n\n\n\n\nHowever, the way the matrix square root is computed is different between the two programs. The result can have a rather significant impact on whether or not the normalized residuals actually seem to follow a normal distribution.\n\n\n\n\nThe way R computes the matrix square root is through the Cholesky decomposition A = L*L^T (using the chol function from FORTRAN77). I cannot access the source code for Stata, but it seems like Stata uses Cholesky decomposition as well, however using a Cholesky decomposition algorithm starting at \"the bottom right\" of the matrix instead of \"the top left\" such that A = L^T * L. Using these two methods for Cholesky decomposition, I have been able to recreate the normalised residuals from R and Stata respectively.\n\n\n\n\nWhen using QQ-plots on the normalized residuals calculated with R and those calculated with Stata, the two results plots imply different conclusions about the normality of the residuals.\n\n\n\n\nIn principle, could one not use several different methods for Cholesky decomposition to compute a matrix square root and therefore come to significantly different conclusions? Would it therefore not be preferable to use eigenvalue decomposition to compute a matrix square root as opposed to Cholesky decomposition? One reason I believe EVD would be better is that it does not require transposing one \"square root\", i.e. we have directly that A^(1/2) * A^(1/2) = A.\n\n\n\n\nHere, I have added an example:\n\n\n\n\nratlong <- read.csv(\"ratlong.csv\") |>\n mutate(Rat = factor(Rat), Group = as_factor(Group)) |>\n mutate(time = as.factor(as.numeric(time)))\n\nmodel <- gls(Weight ~ time*Group,\n correlation = corSymm(form = ~ as.integer(time) | Rat),\n weights = varIdent(form = ~ 1 | time),\n na.action = na.exclude,\n method = \"REML\",\n data = ratlong)\n\nsummary(model)\nparameters(model)\ngetVarCov(model)\n\ntmp <- mutate(\n ratlong,\n fit = fitted(model),\n response = residuals(model, type = \"r\"),\n pearson = residuals(model, type = \"p\"),\n norm_res_R = residuals(model, type = \"n\"),\n norm_res_stata = c(\n -.3343025, .5268827, .4992422, .0732094, .8447663,\n -.3185105, -.2071171, 1.274912, .7114518, 1.215278,\n -.5135215, .0203645, -.5228509, -.8512383, 1.808096,\n .4581496, -1.22478, -.9106107, -.7130803, .2519478,\n .3804444, .2287333, .9784756, -.3758776, -.7113822,\n -1.475303, -1.399477, -1.504103, 1.288807, -.5631775,\n .473786, -.4318775, .5628197, -1.065117, -1.452405,\n .9371732, 1.274058, .9912707, .9466597, -.4890752,\n .1423321, .311183, -.8122606, -.5272216, -1.526507,\n .2497523, .9020303, -.556895, .5124069, .6224594,\n .8534008, -1.234297, .7109886, 1.567964, .3556911,\n 1.202434, -.9995003, .4767818, .8310238, -.1630251,\n -.7255811, -.987914, 1.937267, -1.758109, .6521003,\n -1.101692, 2.462107, .2542622, .8310238, -.1630251,\n -1.298645, -.3421695, -1.104759, .5448185, 1.170816,\n -1.124267, .0387734, .6711161, -.8830101, -.385332,\n .2229622, -.5032972, .0853191, 1.314626, -1.200457,\n 2.574736, .5105642, -1.381145, -.8254197, 1.170816,\n -.5026115, -.0627333, -.9601486, -1.083703, -1.27456,\n -.1007365, 1.118466, -.6896819, -.5392144, -.1630251)\n)\n\n# Here we observe that the pearson residual is approximately equal to the \n# normalized at time 1 for R and time 5 for stata\ntmp$pearson[seq(5, nrow(ratlong), 5)] - \n tmp$norm_res_stata[seq(5, nrow(ratlong), 5)]\ntmp$pearson[seq(1, nrow(ratlong), 5)] - \n tmp$norm_res_R[seq(1, nrow(ratlong), 5)]\n\n\n\n\n\nAccording to the nmle package (retrieved from github (https://github.com/cran/nlme)), the residuals are computed as such:\n\n\n\n\n#### from residuals.gls\nval <- object$residuals\nif (type != \"response\") {\n val <- val/attr(val, \"std\")\n lab <- \"Standardized residuals\"\n if (type == \"normalized\") {\nif (!is.null(cSt <- object$modelStruct$corStruct)) {\n ## normalize according to inv-trans factor\n val <- recalc(cSt, list(Xy = as.matrix(val)))$Xy[, 1]\n lab <- \"Normalized residuals\"\n }\n }\n}\n \n#### from recalc.corSymm\nrecalc.corSymm <- function(object, conLin, ...)\n{\n val <-\n .C(symm_recalc,\n Xy = as.double(conLin[[\"Xy\"]]),\n as.integer(unlist(Dim(object))),\n as.integer(ncol(conLin[[\"Xy\"]])),\n as.double(as.vector(object)),\n as.integer(unlist(getCovariate(object))),\n as.integer(attr(object, \"maxCov\")),\n logLik = double(1))[c(\"Xy\", \"logLik\")]\n conLin[[\"Xy\"]][] <- val[[\"Xy\"]]\n conLin[[\"logLik\"]] <- conLin[[\"logLik\"]] + val[[\"logLik\"]]\n conLin\n}\n \n#### from symm_recalc (written in C)\nvoid\nsymm_recalc(double *Xy, int *pdims, int *ZXcol, double *pars,\n int *time, int *maxC, double *logdet)\n{\n int N = pdims[0], M = pdims[1], *len = pdims + 4, *start = len + M, i;\n double *crr = R_Calloc(*maxC * (*maxC - 1) / 2, double);\n /* parameters assumed in unconstrained form */\n symm_fullCorr(pars, maxC, crr); /* get all correlations (not correlation \n matrix) */\n for(i = 0; i < M; i++) {\n double *Factor = R_Calloc((len[i] * len[i]), double);\n symm_fact(crr, time + start[i], &len[i], maxC, Factor, logdet);\n mult_mat(Xy + start[i], N, Factor, len[i], len[i], len[i],\n Xy + start[i], N, *ZXcol);\n R_Free(Factor);\n }\n R_Free(crr);\n}\n \n#### from symm_fact (also written in C)\nstatic void\nsymm_fact(double *crr, int *time, int *n, int *maxC, double *mat,\n double *logdet)\n{\n int job = 11L, info, i, nsq = *n * (*n), np1 = *n + 1;\n double *work = R_Calloc(*n, double), *work1 = R_Calloc(nsq, double);\n symm_mat(crr, time, n, maxC, mat); /* make full symmetric correlation \n matrix for individual i */\n F77_CALL(chol) (mat, n, n, mat, &info); /* Cholesky decomposition */\n for(i = 0; i < *n; i++) {\n work1[i * np1] = 1; /* set diag to 1 in empty matrix (i.e. create \n identity matrix) */\n F77_CALL(dtrsl) (mat, n, n, work1 + i * (*n), &job, &info); /* solves \n linear system given triangular matrix */\n *logdet -= log(fabs(mat[i * np1]));\n }\n Memcpy(mat, work1, nsq); \n R_Free(work); R_Free(work1);\n}\n\n\n\n\n\nI then manually computed the normalized residuals in R, through a regular Cholesky decomposition (same as t(chol) in R), through a \"reverse\" Cholesky decomposition and through EVD.\n\n\n\n\n# regular Cholesky algorithm (same as t(chol) for base R's chol function)\n regChol <- function(A){\n n = nrow(A)\n L = matrix(0,n,n)\n for (j in 1:n){\n if (j == 1){\n L[j,j] = sqrt(A[j,j])\n } else{\n L[j,j] = sqrt(A[j,j] - sum(L[j,1:(j-1)]^2))\n }\n if (j == 1){\n for (i in (j+1):n){\n L[i,j] = A[i,j]/L[j,j]\n }\n } else if (j < n){\n for (i in (j+1):n){\n L[i,j] = (A[i,j]-sum(L[i,1:(j-1)]*L[j,1:(j-1)]))/L[j,j]\n }\n }\n }\n return(L)\n }\n \n # reverse Cholesky algorithm\n revChol <- function(A){\n n = nrow(A)\n L = matrix(0,n,n)\n for (j in n-0:(n-1)){\n if (j == n){\n L[j,j] = sqrt(A[j,j])\n } else{\n L[j,j] = sqrt(A[j,j] - sum(L[(j+1):n,j]^2))\n }\n if (j == n){\n for (i in n-(n-j+1):(n-1)){\n L[j,i] = A[j,i]/L[j,j]\n }\n } else if (j > 1){\n for (i in n-(n-j+1):(n-1)){\n L[j,i] = (A[j,i]-sum(L[(j+1):n,i]*L[(j+1):n,j]))/L[j,j]\n }\n }\n }\n return(L)\n }\n \ncorMat <- model$modelStruct$corStruct #correlation structure of type corSymm\n \npdims <- as.integer(unlist(Dim(corMat))) #dimensions of correlation matrices\ncorMatFull <- corMatrix(corMat) #full correlation matrix\n ############################################################################\n#### Compute normalized residuals\n\n# `Using reverse Cholesky decomposition (gives same values as stata)\n\nnormres1 = 1:pdims[2]\nfor (i in 1:pdims[2]){\n dim <- pdims[i+4] #observations for individual i\n dim2 <- (pdims[i+4+pdims[2]]+1) #total observations up to individual i\n A <- matrix(unlist(corMatFull[i]), ncol = dim) # correlation matrix\n L <- revChol(A) # lower triangular / square root\n invSqLambda <- solve(t(L)) # invert L -- if regular Cholesky: use solve(L)\n normres1[dim2:(dim2 + dim-1)] <- \n invSqLambda %*% tmp$pearson[dim2:(dim2 + dim-1)] \n # multiply inverse square root with standardized residuals\n}\nt(L) %*% L #returns correlation matrix A given reversed Cholesky\n\n#Using regular Cholesky decomposition (gives same values as R)\nnormres2 = 1:pdims[2]\nfor (i in 1:pdims[2]){\n dim <- pdims[i+4] #observations for individual i\n dim2 <- (pdims[i+4+pdims[2]]+1) #total observations up to individual i\n A <- matrix(unlist(corMatFull[i]), ncol = dim) #correlation matrix\n L <- t(chol(A)) \n # lower triangular / square root -- note that regChol(A) = t(chol(A))\n invSqLambda <- solve(L) # invert L -- if regular Cholesky: use solve(L)\n normres2[dim2:(dim2 + dim-1)] <- \n invSqLambda %*% tmp$pearson[dim2:(dim2 + dim-1)] \n # multiply inverse square root with standardized residuals\n}\nL %*% t(L) #returns correlation matrix given standard Cholesky\n\n# Using EVD\nnormres3 = 1:pdims[2]\nfor (i in 1:pdims[2]){\n dim <- pdims[i+4] # observations for individual i\n dim2 <- (pdims[i+4+pdims[2]]+1) # total observations up to individual i\n A <- matrix(unlist(corMatFull[i]), ncol = dim) # correlation matrix\n E <- eigen(A) # EVD eigenvalue decomposition\n sqrtA <- E$vectors %*% sqrt(diag(E$values)) %*% t(E$vectors) \n# matrix square root\n invSqLambda <- solve(sqrtA) # invert sqrtA\n normres3[dim2:(dim2 + dim-1)] <- \ninvSqLambda %*% tmp$pearson[dim2:(dim2 + dim-1)] \n # multiply inverse square root with standardized residuals\n}\n\nround(normres1 - tmp$norm_res_stata, digits = 5) \n# approx 0 when using reverse Cholesky\nround(normres2 - tmp$norm_res_R, digits = 15) \n # approx 0 when using regular Cholesky\n \n##### will add qqplots/histograms with results in a couple of days\n\n\n\n\n\nThe results on the rat-example imply a left or a right-skew (Stata and R respecitvely) when compared to the standard normal, i.e. they may lead to different conlclusions about the model fit (I have an example, wherein the difference is more pronounced, but I do not want to break GDPR rules. Maybe someone can find a better example?). Using EVD, there does not seem to be as much of a skew to one side or the other.\n\n\n\n\n[image: QQ-plot of normalized residuals with each method compared to standard normal; source: https://i.sstatic.net/65PG6zuB.png] (https://i.sstatic.net/65PG6zuB.png)\n\n\n\n\n[image: Histogram of normalized residuals with each method compared to standard normal; source: https://i.sstatic.net/XWUljnac.png] (https://i.sstatic.net/XWUljnac.png)\n\n\n\n\nThe figures are created via:\n\n\n\n\nplot1 <- ggplot(as.data.frame(tmp$norm_res_stata), aes(sample = tmp$norm_res_stata)) +\n stat_qq() +\n geom_abline(slope = 1, intercept = 0) + \n labs(y = \"normalized residuals stata\")\nplot2 <- ggplot(as.data.frame(tmp$norm_res_R), aes(sample = tmp$norm_res_R)) +\n stat_qq() +\n geom_abline(slope = 1, intercept = 0) + \n labs(y = \"normalized residuals R\")\nplot3 <- ggplot(as.data.frame(normres3), aes(sample = normres3)) +\n stat_qq() +\n geom_abline(slope = 1, intercept = 0) + \n labs(y = \"normalized residuals EVD\")\ngrid.arrange(plot1, plot2, plot3, ncol = 3)\n\nplot1 <- ggplot(as.data.frame(tmp$norm_res_stata), aes(x = tmp$norm_res_stata)) +\n geom_histogram(aes(y =..density..), binwidth = 0.4, color = \"black\", fill = \"white\") + \n stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +\n labs(x = \"normalised residuals stata (reverse Cholesky)\")\nplot2 <- ggplot(as.data.frame(tmp$norm_res_R), aes(x = tmp$norm_res_R)) +\n geom_histogram(aes(y =..density..), binwidth = 0.4, color = \"black\", fill = \"white\") + \n stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +\n labs(x = \"normalised residuals R (standard Cholesky)\")\nplot3 <- ggplot(as.data.frame(normres3), aes(x = normres3)) +\n geom_histogram(aes(y =..density..), binwidth = 0.4, color = \"black\", fill = \"white\") + \n stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +\n labs(x = \"normalised residuals EVD\")\ngrid.arrange(plot1, plot2, plot3, ncol = 3)\n\n\n\n\n\nThe log from the Stata-code is given here:\n\n\n\n\n. \n. \n. import delim \"ratlong.csv\", clear \n(encoding automatically selected: ISO-8859-1)\n(5 vars, 100 obs)\n\n. \n. mixed weight b1.group##b0.time || rat: , reml baselev nocons res(un, t(time))\n\nPerforming gradient-based optimization: \nIteration 0: Log restricted-likelihood = -346.35796 (not concave)\nIteration 1: Log restricted-likelihood = -284.80839 (not concave)\nIteration 2: Log restricted-likelihood = -281.13028 \nIteration 3: Log restricted-likelihood = -278.4598 \nIteration 4: Log restricted-likelihood = -276.85378 \nIteration 5: Log restricted-likelihood = -276.76319 \nIteration 6: Log restricted-likelihood = -276.76264 \nIteration 7: Log restricted-likelihood = -276.76264 \n\nComputing standard errors ...\n\nMixed-effects REML regression Number of obs = 100\nGroup variable: rat Number of groups = 20\n Obs per group:\n min = 5\n avg = 5.0\n max = 5\n Wald chi2(9) = 1277.34\nLog restricted-likelihood = -276.76264 Prob > chi2 = 0.0000\n\n------------------------------------------------------------------------------\n weight | Coefficient Std. err. z P>|z| [95% conf. interval]\n-------------+----------------------------------------------------------------\n group |\n 1 | 0 (base)\n 3 | .7 2.270827 0.31 0.758 -3.75074 5.15074\n |\n time |\n 0 | 0 (base)\n 1 | 24.5 1.61744 15.15 0.000 21.32988 27.67012\n 2 | 52 2.045184 25.43 0.000 47.99151 56.00849\n 3 | 76.1 3.11002 24.47 0.000 70.00447 82.19553\n 4 | 106.6 4.073561 26.17 0.000 98.61597 114.584\n |\n group#time |\n 3 1 | -2.9 2.287405 -1.27 0.205 -7.383232 1.583232\n 3 2 | -10.9 2.892328 -3.77 0.000 -16.56886 -5.231142\n 3 3 | -22.4 4.398233 -5.09 0.000 -31.02038 -13.77962\n 3 4 | -37.1 5.760885 -6.44 0.000 -48.39113 -25.80887\n |\n _cons | 54 1.605717 33.63 0.000 50.85285 57.14715\n------------------------------------------------------------------------------\n\n------------------------------------------------------------------------------\n Random-effects parameters | Estimate Std. err. [95% conf. interval]\n-----------------------------+------------------------------------------------\nrat: (empty) |\n-----------------------------+------------------------------------------------\nResidual: Unstructured |\n var(e0) | 25.78329 8.592901 13.41698 49.54749\n var(e1) | 77.81102 25.92904 40.49434 149.5161\n var(e2) | 85.31105 28.41546 44.41058 163.8793\n var(e3) | 127.9611 42.64015 66.59387 245.8791\n var(e4) | 182.1112 60.70111 94.75779 349.9921\n cov(e0,e1) | 38.7166 13.95059 11.37394 66.05925\n cov(e0,e2) | 34.63327 13.73195 7.719139 61.5474\n cov(e0,e3) | 28.51106 15.09849 -1.081436 58.10355\n cov(e0,e4) | 20.97774 16.87309 -12.09292 54.04839\n cov(e1,e2) | 71.47769 25.52878 21.44219 121.5132\n cov(e1,e3) | 56.73882 27.02632 3.768207 109.7094\n cov(e1,e4) | 42.8555 29.78855 -15.52898 101.24\n cov(e2,e3) | 89.65551 32.42749 26.09881 153.2122\n cov(e2,e4) | 86.18887 35.69784 16.22239 156.1553\n cov(e3,e4) | 136.2 48.21199 41.70625 230.6938\n------------------------------------------------------------------------------\nLR test vs. linear model: chi2(14) = 139.19 Prob > chi2 = 0.0000\n\nNote: The reported degrees of freedom assumes the null hypothesis is not on the boundary of the parameter space. If this is not true, then the\n reported test is conservative.\n\n. \n. predict res, rstandard\n\n. \n. list rat time res, sepby(rat)\n\n +------------------------+\n | rat time res |\n |------------------------|\n 1. | 1 0 -.3343025 |\n 2. | 1 1 .5268827 |\n 3. | 1 2 .4992422 |\n 4. | 1 3 .0732094 |\n 5. | 1 4 .8447663 |\n |------------------------|\n 6. | 2 0 -.3185105 |\n 7. | 2 1 -.2071171 |\n 8. | 2 2 1.274912 |\n 9. | 2 3 .7114518 |\n 10. | 2 4 1.215278 |\n |------------------------|\n 11. | 3 0 -.5135215 |\n 12. | 3 1 .0203645 |\n 13. | 3 2 -.5228509 |\n 14. | 3 3 -.8512383 |\n 15. | 3 4 1.808096 |\n |------------------------|\n 16. | 4 0 .4581496 |\n 17. | 4 1 -1.22478 |\n 18. | 4 2 -.9106107 |\n 19. | 4 3 -.7130803 |\n 20. | 4 4 .2519478 |\n |------------------------|\n 21. | 5 0 .3804444 |\n 22. | 5 1 .2287333 |\n 23. | 5 2 .9784756 |\n 24. | 5 3 -.3758776 |\n 25. | 5 4 -.7113822 |\n |------------------------|\n 26. | 6 0 -1.475303 |\n 27. | 6 1 -1.399477 |\n 28. | 6 2 -1.504103 |\n 29. | 6 3 1.288807 |\n 30. | 6 4 -.5631775 |\n |------------------------|\n 31. | 7 0 .473786 |\n 32. | 7 1 -.4318775 |\n 33. | 7 2 .5628197 |\n 34. | 7 3 -1.065117 |\n 35. | 7 4 -1.452405 |\n |------------------------|\n 36. | 8 0 .9371732 |\n 37. | 8 1 1.274058 |\n 38. | 8 2 .9912707 |\n 39. | 8 3 .9466597 |\n 40. | 8 4 -.4890752 |\n |------------------------|\n 41. | 9 0 .1423321 |\n 42. | 9 1 .311183 |\n 43. | 9 2 -.8122606 |\n 44. | 9 3 -.5272216 |\n 45. | 9 4 -1.526507 |\n |------------------------|\n 46. | 10 0 .2497523 |\n 47. | 10 1 .9020303 |\n 48. | 10 2 -.556895 |\n 49. | 10 3 .5124069 |\n 50. | 10 4 .6224594 |\n |------------------------|\n 51. | 18 0 .8534008 |\n 52. | 18 1 -1.234297 |\n 53. | 18 2 .7109886 |\n 54. | 18 3 1.567964 |\n 55. | 18 4 .3556911 |\n |------------------------|\n 56. | 19 0 1.202434 |\n 57. | 19 1 -.9995003 |\n 58. | 19 2 .4767818 |\n 59. | 19 3 .8310238 |\n 60. | 19 4 -.1630251 |\n |------------------------|\n 61. | 20 0 -.7255811 |\n 62. | 20 1 -.987914 |\n 63. | 20 2 1.937267 |\n 64. | 20 3 -1.758109 |\n 65. | 20 4 .6521003 |\n |------------------------|\n 66. | 21 0 -1.101692 |\n 67. | 21 1 2.462107 |\n 68. | 21 2 .2542622 |\n 69. | 21 3 .8310238 |\n 70. | 21 4 -.1630251 |\n |------------------------|\n 71. | 22 0 -1.298645 |\n 72. | 22 1 -.3421695 |\n 73. | 22 2 -1.104759 |\n 74. | 22 3 .5448185 |\n 75. | 22 4 1.170816 |\n |------------------------|\n 76. | 23 0 -1.124267 |\n 77. | 23 1 .0387734 |\n 78. | 23 2 .6711161 |\n 79. | 23 3 -.8830101 |\n 80. | 23 4 -.385332 |\n |------------------------|\n 81. | 24 0 .2229622 |\n 82. | 24 1 -.5032972 |\n 83. | 24 2 .0853191 |\n 84. | 24 3 1.314626 |\n 85. | 24 4 -1.200457 |\n |------------------------|\n 86. | 25 0 2.574736 |\n 87. | 25 1 .5105642 |\n 88. | 25 2 -1.381145 |\n 89. | 25 3 -.8254197 |\n 90. | 25 4 1.170816 |\n |------------------------|\n 91. | 26 0 -.5026115 |\n 92. | 26 1 -.0627333 |\n 93. | 26 2 -.9601486 |\n 94. | 26 3 -1.083703 |\n 95. | 26 4 -1.27456 |\n |------------------------|\n 96. | 27 0 -.1007365 |\n 97. | 27 1 1.118466 |\n 98. | 27 2 -.6896819 |\n 99. | 27 3 -.5392144 |\n100. | 27 4 -.1630251 |\n +------------------------+\n\n\n\n\n\nI found out the data example I was working with was RatWeight from package heplots, although I was given simply given the \"ratlong.csv\"-file, which is a heavily manipulated and reordered version of RatWeight, so if you want to reproduce it, here is how (I hope you will bear with me):\n\n\n\n\nrat <- RatWeight\nnames(rat) <- c(\"Group\", \"Weight0\", \"Weight1\", \"Weight2\", \"Weight3\", \"Weight4\")\nrat$Group <- factor(rat$Group, levels = c(\"Control\", \"Thyroxin\", \"Thiouracil\"))\nrat <- rat[order(rat$Group),]\nrat <- cbind(data.frame(Rat=1:27), rat) |>\n mutate(Rat = factor(Rat))\nrat <- subset(rat, Group != \"Thyroxin\")\nratlong <- rat |> gather(time, Weight, Weight0:Weight4) |>\n separate(time, c(\"W\", \"time\"), sep = 6) |>\n mutate(time = as.factor(as.numeric(time))) |>\n mutate(Group = as.factor(as.numeric(Group))) |>\n mutate(Weight = as.double(Weight))\nratlong <- ratlong[with(ratlong, order(Rat, time, Group)),]\nratlong$Weight[89:90] <- c(116,140)\nwrite.csv(ratlong, \"ratlong.csv\", row.names = FALSE)\n\n\n\n\n\nPackages used in general:\n\n\n\n\nlibrary(lme4)\nlibrary(nlme)\nlibrary(haven)\nlibrary(dplyr)\nlibrary(heplots)\nlibrary(parameters)\nlibrary(tidyverse)\nlibrary(gridExtra)\nlibrary(ggplot2)", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-23T09:39:51+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "7BC8F667-EB32-47A1-A802-2154A3633C12", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7BC8F667-EB32-47A1-A802-2154A3633C12/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-23T17:05:33+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "2EFBF184-EFA4-4618-B902-9EB0CF6CDAD1", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2EFBF184-EFA4-4618-B902-9EB0CF6CDAD1/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-23T18:51:05+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "CFD9707D-EF4E-4CBF-A2FA-FC17B82ADC40", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CFD9707D-EF4E-4CBF-A2FA-FC17B82ADC40/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-23T21:15:18+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "DDCD4DF6-217B-4BCA-B9AB-A089EF38A03D", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/DDCD4DF6-217B-4BCA-B9AB-A089EF38A03D/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-23T21:24:18+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "3E87BF4C-CB4D-492F-89AD-9AAEF44DF12F", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/3E87BF4C-CB4D-492F-89AD-9AAEF44DF12F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-23T21:36:28+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "2160C566-F067-48AE-8E37-5DC1331F1A3F", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2160C566-F067-48AE-8E37-5DC1331F1A3F/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-23T21:51:58+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "30322FB2-132C-405E-8E54-9D57208C3C4C", "revision_number": 7, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/30322FB2-132C-405E-8E54-9D57208C3C4C/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "kjetil b halvorsen", "profile_url": "https://stats.stackexchange.com/users/11887/kjetil-b-halvorsen", "user_type": "moderator"}, "created_at": "2026-09-24T00:39:52+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "A600B7A7-BD08-4855-A958-0D2321246CA5", "revision_number": 8, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/A600B7A7-BD08-4855-A958-0D2321246CA5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-25T07:33:22+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "F655028C-4705-4B3D-BB65-71C57A6831E2", "revision_number": 9, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F655028C-4705-4B3D-BB65-71C57A6831E2/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael", "profile_url": "https://stats.stackexchange.com/users/517013/michael", "user_type": "registered"}, "created_at": "2026-09-25T10:01:55+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "7549E095-451B-4062-AE3C-66AA61B7671C", "revision_number": 10, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/7549E095-451B-4062-AE3C-66AA61B7671C/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677243/normalized-residuals-in-mixed-models-r-nlme-vs-stata", "split": "train", "split_group": "598fe845d8f6ec9dfd2ba93f72b05bd7499c42da4f6a46494a772e71b8f59550", "tags": ["r", "mixed-model", "residuals", "stata", "normalization"], "thread_id": "stats:677243", "title": "Normalized residuals in mixed models, R (nlme) vs Stata"}} +{"accepted_answer": {"answer_html": "

UPDATE

\n

I realized I didn't really address the crux of your question, which seems to be about fitting a logistic regression to obtain predicted probabilities and using those predictions to construct an ROC curve. Whatever means you use to create predictions / classifications is really up to you. Logistic regression in this case would probably work out ok because you're not likely to overfit with your continuous single predictor. You may end up with a poor classifier in terms of discrimination, but you can still do it. The issue that the statistician may be talking about is how to obtain good predicted probabilities from a small sample. ROC itself is not an asymptotic method, but the usual MLE methods for logistic regression are. Firth regression will produce biased estimates, which will be fine for prediction, but I don't think you'd need to use that method unless you have complete separation. If there is any overlap in the distribution of widths between the two groups, then you won't have an issue with MLE.

\n

Below I discuss the other part: two-sample comparisons with the binary variable as the grouping variable v. logistic regression with the binary variable as the outcome.

\n
\n

As usual, @whuber has provided an excellent answer to this question. Note that results will be slightly different as they're not all equivalent, whereas if you performed linear regression with a binary predictor and a continuous outcome, the results are just a re-parameterized version of a $t$-test in that case. From Whuber's answer:

\n
\n

A t-test detects whether the average ages differ between no-and yes-respondents in the population. A logistic regression estimates how the response rate varies by age. As such it is more flexible and capable of supplying more detailed information than the t-test is. On the other hand, it tends to be less powerful than the t-test for the basic purpose of detecting a difference between the average ages in the groups.

\n
\n

I wanted to further illustrate this in a small sample, where the data generating process is Poisson (though with a very large $\\lambda$). Here's a little simulation in R:

\n
## generate the data\nset.seed(86709) \n## Poisson, not normal!\ng1 <- rpois(n = 12, lambda = 25)\ng2 <- rpois(n = 11, lambda = 20)\noutcome <- c(rep(1, 12), rep(0, 11))\nwidth <- c(g1,g2)\nd <- data.frame(outcome, width)\n\nm <- glm(outcome ~ width, family = binomial, data = d)\nt.test(width ~ outcome, var.equal = TRUE) # ordinary\nt.test(width ~ outcome, var.equal = FALSE) # Welch\nwilcox.test(x = g1, y = g2) # Mann-Whitney\n
\n

You'll note that the $p$-values among the two t.test calls and wilcox.test are very very close (in order: $0.0037, 0.0036, 0.0026$). This remains true even with different seeds. So at least, numerically, without a normally distributed data generating process, the three two-sample tests agree quite well. That is, no need to use Shapiro-Wilk if you don't want to.

\n

Now, the logistic regression is quite different. In this case, the $p$-value is larger ($0.0276$), and of course, we're testing something very different from the other three tests. We've now parameterized the problem as predicting the log-odds of being a responder as a (linear) function of width. The qualitative answer is the same: greater width associates with greater log-odds of response, but that's just how I generated the data.

\n

It's not immediately obvious to me why the logistic model has lower power, except for the oft-quoted rules of thumb for avoiding overfitting. My intuition is that it has something to do with the differences in how standard errors are computed in the two cases. I will edit once I get to the bottom of that!

\n", "answer_id": 677263, "answer_text": "UPDATE\n\n\n\n\nI realized I didn't really address the crux of your question, which seems to be about fitting a logistic regression to obtain predicted probabilities and using those predictions to construct an ROC curve. Whatever means you use to create predictions / classifications is really up to you. Logistic regression in this case would probably work out ok because you're not likely to overfit with your continuous single predictor. You may end up with a poor classifier in terms of discrimination, but you can still do it. The issue that the statistician may be talking about is how to obtain good predicted probabilities from a small sample. ROC itself is not an asymptotic method, but the usual MLE methods for logistic regression are. Firth regression will produce biased estimates, which will be fine for prediction, but I don't think you'd need to use that method unless you have complete separation. If there is any overlap in the distribution of widths between the two groups, then you won't have an issue with MLE.\n\n\n\n\nBelow I discuss the other part: two-sample comparisons with the binary variable as the grouping variable v. logistic regression with the binary variable as the outcome.\n\n\n\n\n\n\n\nAs usual, @whuber has provided an excellent answer to this question (https://stats.stackexchange.com/a/159203/97844). Note that results will be slightly different as they're not all equivalent, whereas if you performed linear regression with a binary predictor and a continuous outcome, the results are just a re-parameterized version of a $t$-test in that case. From Whuber's answer:\n\n\n\n\n\n\n\nA t-test detects whether the average ages differ between no-and yes-respondents in the population. A logistic regression estimates how the response rate varies by age. As such it is more flexible and capable of supplying more detailed information than the t-test is. On the other hand, it tends to be less powerful than the t-test for the basic purpose of detecting a difference between the average ages in the groups.\n\n\n\n\n\n\n\nI wanted to further illustrate this in a small sample, where the data generating process is Poisson (though with a very large $\\lambda$). Here's a little simulation in R:\n\n\n\n\n## generate the data\nset.seed(86709) \n## Poisson, not normal!\ng1 <- rpois(n = 12, lambda = 25)\ng2 <- rpois(n = 11, lambda = 20)\noutcome <- c(rep(1, 12), rep(0, 11))\nwidth <- c(g1,g2)\nd <- data.frame(outcome, width)\n\nm <- glm(outcome ~ width, family = binomial, data = d)\nt.test(width ~ outcome, var.equal = TRUE) # ordinary\nt.test(width ~ outcome, var.equal = FALSE) # Welch\nwilcox.test(x = g1, y = g2) # Mann-Whitney\n\n\n\n\n\nYou'll note that the $p$-values among the two t.test calls and wilcox.test are very very close (in order: $0.0037, 0.0036, 0.0026$). This remains true even with different seeds. So at least, numerically, without a normally distributed data generating process, the three two-sample tests agree quite well. That is, no need to use Shapiro-Wilk if you don't want to.\n\n\n\n\nNow, the logistic regression is quite different. In this case, the $p$-value is larger ($0.0276$), and of course, we're testing something very different from the other three tests. We've now parameterized the problem as predicting the log-odds of being a responder as a (linear) function of width. The qualitative answer is the same: greater width associates with greater log-odds of response, but that's just how I generated the data.\n\n\n\n\nIt's not immediately obvious to me why the logistic model has lower power, except for the oft-quoted rules of thumb for avoiding overfitting (https://stats.stackexchange.com/a/45764/97844). My intuition is that it has something to do with the differences in how standard errors are computed in the two cases. I will edit once I get to the bottom of that!", "answer_url": "https://stats.stackexchange.com/a/677263", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-25T13:44:43+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": 677262, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T13:44:43+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D364CE58-9CC7-407D-B6A6-CA7B48039B16", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D364CE58-9CC7-407D-B6A6-CA7B48039B16/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T13:54:35+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "311A980C-8FF9-4553-B91E-EB438CA49CF5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/311A980C-8FF9-4553-B91E-EB438CA49CF5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T15:56:42+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "63585334-0D98-4386-B087-8A28FC121807", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/63585334-0D98-4386-B087-8A28FC121807/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T17:46:48+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D32B7BD3-C3DC-4992-8803-1AE622335BD6", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D32B7BD3-C3DC-4992-8803-1AE622335BD6/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T19:02:37+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "FEC7CF2B-92E8-41E2-A10B-658E5657A289", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FEC7CF2B-92E8-41E2-A10B-658E5657A289/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-27T15:15:15+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "64ED3E27-F5FD-4A41-AA22-C4265D46E82F", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/64ED3E27-F5FD-4A41-AA22-C4265D46E82F/view-source"}], "score": 7, "updated_at": "2026-09-27T15:15:15+00:00"}, "other_answers": [], "product": "statistics_qa", "question": "I'm writing my medical thesis and I want to test our research group's hypothesis that the width of the foramen magnum can predict response or non-response to a certain surgical intervention in a neurological disease. The sample is however quite small (only 23 patients) so any biological signal whould have to be quite strong to cut through the noise.\n\n\n\n\nI asked stats support who wanted me to \"find some exact version of the ROC analysis, some analogue to Fisher's exact test\", but I can't really find anything like that in the literature. Generative AI tends to point me towards Mann-Whitney U-tests, exact logistic regression and/or Firth regression, but cannot point me towards any supporting literature.\n\n\n\n\nIntuitively that's not a bad idea. I might test if the FM width is normally distributed with Shapiro-Wilk, then test for differences with t-test/U-test depending on distribution and only then proceed towards ROC-analyses/logistic regression if an interesting pattern emerges.\n\n\n\n\nBut I will have to motivate the chosen approach formally. Is there an actual recommended approach? Is there any literature discussing the pros and cons of different strategies given this particular dilemma?", "record_id": "Scientific-Statistics-QA:stats:677262", "selected_answer": {"answer_html": "

UPDATE

\n

I realized I didn't really address the crux of your question, which seems to be about fitting a logistic regression to obtain predicted probabilities and using those predictions to construct an ROC curve. Whatever means you use to create predictions / classifications is really up to you. Logistic regression in this case would probably work out ok because you're not likely to overfit with your continuous single predictor. You may end up with a poor classifier in terms of discrimination, but you can still do it. The issue that the statistician may be talking about is how to obtain good predicted probabilities from a small sample. ROC itself is not an asymptotic method, but the usual MLE methods for logistic regression are. Firth regression will produce biased estimates, which will be fine for prediction, but I don't think you'd need to use that method unless you have complete separation. If there is any overlap in the distribution of widths between the two groups, then you won't have an issue with MLE.

\n

Below I discuss the other part: two-sample comparisons with the binary variable as the grouping variable v. logistic regression with the binary variable as the outcome.

\n
\n

As usual, @whuber has provided an excellent answer to this question. Note that results will be slightly different as they're not all equivalent, whereas if you performed linear regression with a binary predictor and a continuous outcome, the results are just a re-parameterized version of a $t$-test in that case. From Whuber's answer:

\n
\n

A t-test detects whether the average ages differ between no-and yes-respondents in the population. A logistic regression estimates how the response rate varies by age. As such it is more flexible and capable of supplying more detailed information than the t-test is. On the other hand, it tends to be less powerful than the t-test for the basic purpose of detecting a difference between the average ages in the groups.

\n
\n

I wanted to further illustrate this in a small sample, where the data generating process is Poisson (though with a very large $\\lambda$). Here's a little simulation in R:

\n
## generate the data\nset.seed(86709) \n## Poisson, not normal!\ng1 <- rpois(n = 12, lambda = 25)\ng2 <- rpois(n = 11, lambda = 20)\noutcome <- c(rep(1, 12), rep(0, 11))\nwidth <- c(g1,g2)\nd <- data.frame(outcome, width)\n\nm <- glm(outcome ~ width, family = binomial, data = d)\nt.test(width ~ outcome, var.equal = TRUE) # ordinary\nt.test(width ~ outcome, var.equal = FALSE) # Welch\nwilcox.test(x = g1, y = g2) # Mann-Whitney\n
\n

You'll note that the $p$-values among the two t.test calls and wilcox.test are very very close (in order: $0.0037, 0.0036, 0.0026$). This remains true even with different seeds. So at least, numerically, without a normally distributed data generating process, the three two-sample tests agree quite well. That is, no need to use Shapiro-Wilk if you don't want to.

\n

Now, the logistic regression is quite different. In this case, the $p$-value is larger ($0.0276$), and of course, we're testing something very different from the other three tests. We've now parameterized the problem as predicting the log-odds of being a responder as a (linear) function of width. The qualitative answer is the same: greater width associates with greater log-odds of response, but that's just how I generated the data.

\n

It's not immediately obvious to me why the logistic model has lower power, except for the oft-quoted rules of thumb for avoiding overfitting. My intuition is that it has something to do with the differences in how standard errors are computed in the two cases. I will edit once I get to the bottom of that!

\n", "answer_id": 677263, "answer_text": "UPDATE\n\n\n\n\nI realized I didn't really address the crux of your question, which seems to be about fitting a logistic regression to obtain predicted probabilities and using those predictions to construct an ROC curve. Whatever means you use to create predictions / classifications is really up to you. Logistic regression in this case would probably work out ok because you're not likely to overfit with your continuous single predictor. You may end up with a poor classifier in terms of discrimination, but you can still do it. The issue that the statistician may be talking about is how to obtain good predicted probabilities from a small sample. ROC itself is not an asymptotic method, but the usual MLE methods for logistic regression are. Firth regression will produce biased estimates, which will be fine for prediction, but I don't think you'd need to use that method unless you have complete separation. If there is any overlap in the distribution of widths between the two groups, then you won't have an issue with MLE.\n\n\n\n\nBelow I discuss the other part: two-sample comparisons with the binary variable as the grouping variable v. logistic regression with the binary variable as the outcome.\n\n\n\n\n\n\n\nAs usual, @whuber has provided an excellent answer to this question (https://stats.stackexchange.com/a/159203/97844). Note that results will be slightly different as they're not all equivalent, whereas if you performed linear regression with a binary predictor and a continuous outcome, the results are just a re-parameterized version of a $t$-test in that case. From Whuber's answer:\n\n\n\n\n\n\n\nA t-test detects whether the average ages differ between no-and yes-respondents in the population. A logistic regression estimates how the response rate varies by age. As such it is more flexible and capable of supplying more detailed information than the t-test is. On the other hand, it tends to be less powerful than the t-test for the basic purpose of detecting a difference between the average ages in the groups.\n\n\n\n\n\n\n\nI wanted to further illustrate this in a small sample, where the data generating process is Poisson (though with a very large $\\lambda$). Here's a little simulation in R:\n\n\n\n\n## generate the data\nset.seed(86709) \n## Poisson, not normal!\ng1 <- rpois(n = 12, lambda = 25)\ng2 <- rpois(n = 11, lambda = 20)\noutcome <- c(rep(1, 12), rep(0, 11))\nwidth <- c(g1,g2)\nd <- data.frame(outcome, width)\n\nm <- glm(outcome ~ width, family = binomial, data = d)\nt.test(width ~ outcome, var.equal = TRUE) # ordinary\nt.test(width ~ outcome, var.equal = FALSE) # Welch\nwilcox.test(x = g1, y = g2) # Mann-Whitney\n\n\n\n\n\nYou'll note that the $p$-values among the two t.test calls and wilcox.test are very very close (in order: $0.0037, 0.0036, 0.0026$). This remains true even with different seeds. So at least, numerically, without a normally distributed data generating process, the three two-sample tests agree quite well. That is, no need to use Shapiro-Wilk if you don't want to.\n\n\n\n\nNow, the logistic regression is quite different. In this case, the $p$-value is larger ($0.0276$), and of course, we're testing something very different from the other three tests. We've now parameterized the problem as predicting the log-odds of being a responder as a (linear) function of width. The qualitative answer is the same: greater width associates with greater log-odds of response, but that's just how I generated the data.\n\n\n\n\nIt's not immediately obvious to me why the logistic model has lower power, except for the oft-quoted rules of thumb for avoiding overfitting (https://stats.stackexchange.com/a/45764/97844). My intuition is that it has something to do with the differences in how standard errors are computed in the two cases. I will edit once I get to the bottom of that!", "answer_url": "https://stats.stackexchange.com/a/677263", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-25T13:44:43+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": 677262, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T13:44:43+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D364CE58-9CC7-407D-B6A6-CA7B48039B16", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D364CE58-9CC7-407D-B6A6-CA7B48039B16/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T13:54:35+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "311A980C-8FF9-4553-B91E-EB438CA49CF5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/311A980C-8FF9-4553-B91E-EB438CA49CF5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T15:56:42+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "63585334-0D98-4386-B087-8A28FC121807", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/63585334-0D98-4386-B087-8A28FC121807/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T17:46:48+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D32B7BD3-C3DC-4992-8803-1AE622335BD6", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D32B7BD3-C3DC-4992-8803-1AE622335BD6/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T19:02:37+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "FEC7CF2B-92E8-41E2-A10B-658E5657A289", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FEC7CF2B-92E8-41E2-A10B-658E5657A289/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-27T15:15:15+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "64ED3E27-F5FD-4A41-AA22-C4265D46E82F", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/64ED3E27-F5FD-4A41-AA22-C4265D46E82F/view-source"}], "score": 7, "updated_at": "2026-09-27T15:15:15+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677263, "answers": [{"answer_html": "

UPDATE

\n

I realized I didn't really address the crux of your question, which seems to be about fitting a logistic regression to obtain predicted probabilities and using those predictions to construct an ROC curve. Whatever means you use to create predictions / classifications is really up to you. Logistic regression in this case would probably work out ok because you're not likely to overfit with your continuous single predictor. You may end up with a poor classifier in terms of discrimination, but you can still do it. The issue that the statistician may be talking about is how to obtain good predicted probabilities from a small sample. ROC itself is not an asymptotic method, but the usual MLE methods for logistic regression are. Firth regression will produce biased estimates, which will be fine for prediction, but I don't think you'd need to use that method unless you have complete separation. If there is any overlap in the distribution of widths between the two groups, then you won't have an issue with MLE.

\n

Below I discuss the other part: two-sample comparisons with the binary variable as the grouping variable v. logistic regression with the binary variable as the outcome.

\n
\n

As usual, @whuber has provided an excellent answer to this question. Note that results will be slightly different as they're not all equivalent, whereas if you performed linear regression with a binary predictor and a continuous outcome, the results are just a re-parameterized version of a $t$-test in that case. From Whuber's answer:

\n
\n

A t-test detects whether the average ages differ between no-and yes-respondents in the population. A logistic regression estimates how the response rate varies by age. As such it is more flexible and capable of supplying more detailed information than the t-test is. On the other hand, it tends to be less powerful than the t-test for the basic purpose of detecting a difference between the average ages in the groups.

\n
\n

I wanted to further illustrate this in a small sample, where the data generating process is Poisson (though with a very large $\\lambda$). Here's a little simulation in R:

\n
## generate the data\nset.seed(86709) \n## Poisson, not normal!\ng1 <- rpois(n = 12, lambda = 25)\ng2 <- rpois(n = 11, lambda = 20)\noutcome <- c(rep(1, 12), rep(0, 11))\nwidth <- c(g1,g2)\nd <- data.frame(outcome, width)\n\nm <- glm(outcome ~ width, family = binomial, data = d)\nt.test(width ~ outcome, var.equal = TRUE) # ordinary\nt.test(width ~ outcome, var.equal = FALSE) # Welch\nwilcox.test(x = g1, y = g2) # Mann-Whitney\n
\n

You'll note that the $p$-values among the two t.test calls and wilcox.test are very very close (in order: $0.0037, 0.0036, 0.0026$). This remains true even with different seeds. So at least, numerically, without a normally distributed data generating process, the three two-sample tests agree quite well. That is, no need to use Shapiro-Wilk if you don't want to.

\n

Now, the logistic regression is quite different. In this case, the $p$-value is larger ($0.0276$), and of course, we're testing something very different from the other three tests. We've now parameterized the problem as predicting the log-odds of being a responder as a (linear) function of width. The qualitative answer is the same: greater width associates with greater log-odds of response, but that's just how I generated the data.

\n

It's not immediately obvious to me why the logistic model has lower power, except for the oft-quoted rules of thumb for avoiding overfitting. My intuition is that it has something to do with the differences in how standard errors are computed in the two cases. I will edit once I get to the bottom of that!

\n", "answer_id": 677263, "answer_text": "UPDATE\n\n\n\n\nI realized I didn't really address the crux of your question, which seems to be about fitting a logistic regression to obtain predicted probabilities and using those predictions to construct an ROC curve. Whatever means you use to create predictions / classifications is really up to you. Logistic regression in this case would probably work out ok because you're not likely to overfit with your continuous single predictor. You may end up with a poor classifier in terms of discrimination, but you can still do it. The issue that the statistician may be talking about is how to obtain good predicted probabilities from a small sample. ROC itself is not an asymptotic method, but the usual MLE methods for logistic regression are. Firth regression will produce biased estimates, which will be fine for prediction, but I don't think you'd need to use that method unless you have complete separation. If there is any overlap in the distribution of widths between the two groups, then you won't have an issue with MLE.\n\n\n\n\nBelow I discuss the other part: two-sample comparisons with the binary variable as the grouping variable v. logistic regression with the binary variable as the outcome.\n\n\n\n\n\n\n\nAs usual, @whuber has provided an excellent answer to this question (https://stats.stackexchange.com/a/159203/97844). Note that results will be slightly different as they're not all equivalent, whereas if you performed linear regression with a binary predictor and a continuous outcome, the results are just a re-parameterized version of a $t$-test in that case. From Whuber's answer:\n\n\n\n\n\n\n\nA t-test detects whether the average ages differ between no-and yes-respondents in the population. A logistic regression estimates how the response rate varies by age. As such it is more flexible and capable of supplying more detailed information than the t-test is. On the other hand, it tends to be less powerful than the t-test for the basic purpose of detecting a difference between the average ages in the groups.\n\n\n\n\n\n\n\nI wanted to further illustrate this in a small sample, where the data generating process is Poisson (though with a very large $\\lambda$). Here's a little simulation in R:\n\n\n\n\n## generate the data\nset.seed(86709) \n## Poisson, not normal!\ng1 <- rpois(n = 12, lambda = 25)\ng2 <- rpois(n = 11, lambda = 20)\noutcome <- c(rep(1, 12), rep(0, 11))\nwidth <- c(g1,g2)\nd <- data.frame(outcome, width)\n\nm <- glm(outcome ~ width, family = binomial, data = d)\nt.test(width ~ outcome, var.equal = TRUE) # ordinary\nt.test(width ~ outcome, var.equal = FALSE) # Welch\nwilcox.test(x = g1, y = g2) # Mann-Whitney\n\n\n\n\n\nYou'll note that the $p$-values among the two t.test calls and wilcox.test are very very close (in order: $0.0037, 0.0036, 0.0026$). This remains true even with different seeds. So at least, numerically, without a normally distributed data generating process, the three two-sample tests agree quite well. That is, no need to use Shapiro-Wilk if you don't want to.\n\n\n\n\nNow, the logistic regression is quite different. In this case, the $p$-value is larger ($0.0276$), and of course, we're testing something very different from the other three tests. We've now parameterized the problem as predicting the log-odds of being a responder as a (linear) function of width. The qualitative answer is the same: greater width associates with greater log-odds of response, but that's just how I generated the data.\n\n\n\n\nIt's not immediately obvious to me why the logistic model has lower power, except for the oft-quoted rules of thumb for avoiding overfitting (https://stats.stackexchange.com/a/45764/97844). My intuition is that it has something to do with the differences in how standard errors are computed in the two cases. I will edit once I get to the bottom of that!", "answer_url": "https://stats.stackexchange.com/a/677263", "author": "Rick Hass", "author_url": "https://stats.stackexchange.com/users/97844/rick-hass", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-25T13:44:43+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": 677262, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T13:44:43+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D364CE58-9CC7-407D-B6A6-CA7B48039B16", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D364CE58-9CC7-407D-B6A6-CA7B48039B16/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T13:54:35+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "311A980C-8FF9-4553-B91E-EB438CA49CF5", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/311A980C-8FF9-4553-B91E-EB438CA49CF5/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T15:56:42+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "63585334-0D98-4386-B087-8A28FC121807", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/63585334-0D98-4386-B087-8A28FC121807/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T17:46:48+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D32B7BD3-C3DC-4992-8803-1AE622335BD6", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D32B7BD3-C3DC-4992-8803-1AE622335BD6/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-25T19:02:37+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "FEC7CF2B-92E8-41E2-A10B-658E5657A289", "revision_number": 5, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/FEC7CF2B-92E8-41E2-A10B-658E5657A289/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Rick Hass", "profile_url": "https://stats.stackexchange.com/users/97844/rick-hass", "user_type": "registered"}, "created_at": "2026-09-27T15:15:15+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "64ED3E27-F5FD-4A41-AA22-C4265D46E82F", "revision_number": 6, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/64ED3E27-F5FD-4A41-AA22-C4265D46E82F/view-source"}], "score": 7, "updated_at": "2026-09-27T15:15:15+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Magnus", "question_author_url": "https://stats.stackexchange.com/users/91971/magnus", "question_author_user_type": "registered", "question_created_at": "2026-09-25T12:51:07+00:00", "question_html": "

I'm writing my medical thesis and I want to test our research group's hypothesis that the width of the foramen magnum can predict response or non-response to a certain surgical intervention in a neurological disease. The sample is however quite small (only 23 patients) so any biological signal whould have to be quite strong to cut through the noise.

\n

I asked stats support who wanted me to "find some exact version of the ROC analysis, some analogue to Fisher's exact test", but I can't really find anything like that in the literature. Generative AI tends to point me towards Mann-Whitney U-tests, exact logistic regression and/or Firth regression, but cannot point me towards any supporting literature.

\n

Intuitively that's not a bad idea. I might test if the FM width is normally distributed with Shapiro-Wilk, then test for differences with t-test/U-test depending on distribution and only then proceed towards ROC-analyses/logistic regression if an interesting pattern emerges.

\n

But I will have to motivate the chosen approach formally. Is there an actual recommended approach? Is there any literature discussing the pros and cons of different strategies given this particular dilemma?

\n", "question_id": 677262, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "I'm writing my medical thesis and I want to test our research group's hypothesis that the width of the foramen magnum can predict response or non-response to a certain surgical intervention in a neurological disease. The sample is however quite small (only 23 patients) so any biological signal whould have to be quite strong to cut through the noise.\n\n\n\n\nI asked stats support who wanted me to \"find some exact version of the ROC analysis, some analogue to Fisher's exact test\", but I can't really find anything like that in the literature. Generative AI tends to point me towards Mann-Whitney U-tests, exact logistic regression and/or Firth regression, but cannot point me towards any supporting literature.\n\n\n\n\nIntuitively that's not a bad idea. I might test if the FM width is normally distributed with Shapiro-Wilk, then test for differences with t-test/U-test depending on distribution and only then proceed towards ROC-analyses/logistic regression if an interesting pattern emerges.\n\n\n\n\nBut I will have to motivate the chosen approach formally. Is there an actual recommended approach? Is there any literature discussing the pros and cons of different strategies given this particular dilemma?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Magnus", "profile_url": "https://stats.stackexchange.com/users/91971/magnus", "user_type": "registered"}, "created_at": "2026-09-25T12:51:07+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "1AFA5A57-BDDE-474E-91DC-1D2E2378AE47", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/1AFA5A57-BDDE-474E-91DC-1D2E2378AE47/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-25T12:59:42+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "64F69FAD-C7B9-4C46-B108-F7598EB068D1", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/64F69FAD-C7B9-4C46-B108-F7598EB068D1/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-25T21:01:14+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "C4BCF8DD-9A97-4832-BA8D-BAF89A4AF37C", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/C4BCF8DD-9A97-4832-BA8D-BAF89A4AF37C/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677262/binary-response-variable-with-one-continuous-independent-variable-in-small-sampl", "split": "train", "split_group": "1e66b45b615abb7305245529ef0b62a715e6d164ab6bdac80764f20b0da6fe64", "tags": ["binary-data", "small-sample"], "thread_id": "stats:677262", "title": "Binary response variable with one continuous independent variable in small sample?"}} +{"accepted_answer": {"answer_html": "

I think you can find the mean and variance of $\\bar y$ analytically. Clearly $\\mathbb E[\\bar y]=\\frac{\\alpha}{\\alpha+\\beta}$ and, using the law of total variance $$\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{nk(\\alpha+\\beta)^2} \\frac{\\alpha+\\beta+n}{\\alpha+\\beta+1} = \\frac{1}{nk}E[\\bar y]\\left(1-E[\\bar y]\\right) \\frac{\\alpha+\\beta+k}{\\alpha+\\beta+1}.$$

\n

Since $\\alpha\\ge 0, \\beta\\ge 0, 0 \\le E[\\bar y]\\le 1$, you can then say $$\\operatorname{Var}(\\bar y) \\le \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right) \\le \\frac1{4n}.$$

\n

For given $nk$, you will minimise $\\operatorname{Var}(\\bar y)$ when $k$ is as small as possible, i.e. when $k=1$ and $n=nk$, at which point $\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{n(\\alpha+\\beta)^2}= \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right)$, again bounded above by $\\frac1{4n}$. As discussed on your previous question, having $k=1$ would make it impossible to estimate $\\alpha$ and $\\beta$ separately.

\n

So using $k=1$ together with $n$ large enough to make $\\frac1{4n}$ small enough to meet your needs as an upper bound for $\\operatorname{Var}(\\bar y)$ should work well.

\n
\n

Here is an illustrative simulation in R confirming these (with minor simulation noise) for $\\alpha=2$, $\\beta=3$ and $nk=12$

\n
yhatsim <- function(alpha, beta, n, k){\n  thetai <- rbeta(n, alpha, beta)\n  sum(rbinom(n, k, thetai)) / (n * k) \n  }\nyhat <- function(alpha, beta, n, k, cases=10^6){\n  simyhat <- replicate(cases, yhatsim(alpha, beta, n, k))\n  c(simulatedmean=mean(simyhat), \n    expectedmean=alpha/(alpha+beta), \n    simulatedvar=var(simyhat),\n    expectedvar=alpha*beta/(alpha+beta)^2*(alpha+beta+k)/(alpha+beta+1)/(n*k))\n  }\n\n\nset.seed(2026)\n\nyhat(alpha=2, beta=3, n=12, k=1)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#     0.4000867     0.4000000     0.0199709     0.0200000 \n\nyhat(alpha=2, beta=3, n=6, k=2)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.39994625    0.40000000    0.02330732    0.02333333 \n\nyhat(alpha=2, beta=3, n=4, k=3)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#   0.40013683    0.40000000    0.02668078    0.02666667 \n\nyhat(alpha=2, beta=3, n=3, k=4)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.39973175    0.40000000    0.03001747    0.03000000 \n\nyhat(alpha=2, beta=3, n=2, k=6)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.40039333    0.40000000    0.03666519    0.03666667 \n\nyhat(alpha=2, beta=3, n=1, k=12)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.39992283    0.40000000    0.05659828    0.05666667 \n
\n", "answer_id": 677268, "answer_text": "I think you can find the mean and variance of $\\bar y$ analytically. Clearly $\\mathbb E[\\bar y]=\\frac{\\alpha}{\\alpha+\\beta}$ and, using the law of total variance $$\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{nk(\\alpha+\\beta)^2} \\frac{\\alpha+\\beta+n}{\\alpha+\\beta+1} = \\frac{1}{nk}E[\\bar y]\\left(1-E[\\bar y]\\right) \\frac{\\alpha+\\beta+k}{\\alpha+\\beta+1}.$$\n\n\n\n\nSince $\\alpha\\ge 0, \\beta\\ge 0, 0 \\le E[\\bar y]\\le 1$, you can then say $$\\operatorname{Var}(\\bar y) \\le \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right) \\le \\frac1{4n}.$$\n\n\n\n\nFor given $nk$, you will minimise $\\operatorname{Var}(\\bar y)$ when $k$ is as small as possible, i.e. when $k=1$ and $n=nk$, at which point $\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{n(\\alpha+\\beta)^2}= \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right)$, again bounded above by $\\frac1{4n}$. As discussed on your previous question (https://stats.stackexchange.com/q/677226/2958), having $k=1$ would make it impossible to estimate $\\alpha$ and $\\beta$ separately.\n\n\n\n\nSo using $k=1$ together with $n$ large enough to make $\\frac1{4n}$ small enough to meet your needs as an upper bound for $\\operatorname{Var}(\\bar y)$ should work well.\n\n\n\n\n\n\n\nHere is an illustrative simulation in R confirming these (with minor simulation noise) for $\\alpha=2$, $\\beta=3$ and $nk=12$\n\n\n\n\nyhatsim <- function(alpha, beta, n, k){\n thetai <- rbeta(n, alpha, beta)\n sum(rbinom(n, k, thetai)) / (n * k) \n }\nyhat <- function(alpha, beta, n, k, cases=10^6){\n simyhat <- replicate(cases, yhatsim(alpha, beta, n, k))\n c(simulatedmean=mean(simyhat), \n expectedmean=alpha/(alpha+beta), \n simulatedvar=var(simyhat),\n expectedvar=alpha*beta/(alpha+beta)^2*(alpha+beta+k)/(alpha+beta+1)/(n*k))\n }\n\n\nset.seed(2026)\n\nyhat(alpha=2, beta=3, n=12, k=1)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.4000867 0.4000000 0.0199709 0.0200000 \n\nyhat(alpha=2, beta=3, n=6, k=2)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.39994625 0.40000000 0.02330732 0.02333333 \n\nyhat(alpha=2, beta=3, n=4, k=3)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.40013683 0.40000000 0.02668078 0.02666667 \n\nyhat(alpha=2, beta=3, n=3, k=4)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.39973175 0.40000000 0.03001747 0.03000000 \n\nyhat(alpha=2, beta=3, n=2, k=6)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.40039333 0.40000000 0.03666519 0.03666667 \n\nyhat(alpha=2, beta=3, n=1, k=12)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.39992283 0.40000000 0.05659828 0.05666667", "answer_url": "https://stats.stackexchange.com/a/677268", "author": "Henry", "author_url": "https://stats.stackexchange.com/users/2958/henry", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-26T14:10:23+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": 677266, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Henry", "profile_url": "https://stats.stackexchange.com/users/2958/henry", "user_type": "registered"}, "created_at": "2026-09-26T14:10:23+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "C96EACA9-97B0-4929-B972-DA5D20ED4759", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C96EACA9-97B0-4929-B972-DA5D20ED4759/view-source"}], "score": 4, "updated_at": "2026-09-26T14:10:23+00:00"}, "other_answers": [{"answer_html": "

I would not go through mean and variance here. Your model for data generation is based on $\\alpha$ and $\\beta$ right? So why not work with them? Your population variable $\\theta$, as per your model is beta-distirbuted, so why not work with beta-likelihood? The problem is that sample variance and sample mean of a beta-distributed variable set, such as $\\{\\theta_i\\}$, are not independent variables, so you should not estimate them independently of each other.

\n

If I had a sample $\\{y_{ij}\\}$ I would estimate it like this:

\n
    \n
  1. Have variables $u$, $v$, and take $\\frac{\\alpha}{\\alpha+\\beta}=expit\\left(u\\right)=\\frac{1}{1+\\exp\\left(-u\\right)}$, $\\alpha=softplus(v)=\\log\\left(1+\\exp(v)\\right)$
  2. \n
  3. $\\sum_{j}y_{ij}=y_i\\sim BetaBinomial\\left(k, \\alpha,\\beta\\right)$
  4. \n
\n

Optimise jointly $u,v$ (maximum likelihood).

\n

So your sample size calculation would be a wrap-around for this procedure, i.e. select, $n, k$ etc. It may be slower, but not too slow with your numbers. But it will be giving correct estimates even when $\\theta$ is close to the edges for the given variance (and thus cannot be treated as normal).

\n
\n

If you want to stick to variance and mean, you should be honest with yourself and state $\\theta_i \\sim Normal\\left(\\mu,\\sigma^2\\right)$. If you get reasonable numbers, good, if not then you know your approximation is not suitable

\n", "answer_id": 677267, "answer_text": "I would not go through mean and variance here. Your model for data generation is based on $\\alpha$ and $\\beta$ right? So why not work with them? Your population variable $\\theta$, as per your model is beta-distirbuted, so why not work with beta-likelihood? The problem is that sample variance and sample mean of a beta-distributed variable set, such as $\\{\\theta_i\\}$, are not independent variables, so you should not estimate them independently of each other.\n\n\n\n\nIf I had a sample $\\{y_{ij}\\}$ I would estimate it like this:\n\n\n\n\n\nHave variables $u$, $v$, and take $\\frac{\\alpha}{\\alpha+\\beta}=expit\\left(u\\right)=\\frac{1}{1+\\exp\\left(-u\\right)}$, $\\alpha=softplus(v)=\\log\\left(1+\\exp(v)\\right)$\n\n\n\n\n$\\sum_{j}y_{ij}=y_i\\sim BetaBinomial\\left(k, \\alpha,\\beta\\right)$\n\n\n\n\n\nOptimise jointly $u,v$ (maximum likelihood).\n\n\n\n\nSo your sample size calculation would be a wrap-around for this procedure, i.e. select, $n, k$ etc. It may be slower, but not too slow with your numbers. But it will be giving correct estimates even when $\\theta$ is close to the edges for the given variance (and thus cannot be treated as normal).\n\n\n\n\n\n\n\nIf you want to stick to variance and mean, you should be honest with yourself and state $\\theta_i \\sim Normal\\left(\\mu,\\sigma^2\\right)$. If you get reasonable numbers, good, if not then you know your approximation is not suitable", "answer_url": "https://stats.stackexchange.com/a/677267", "author": "Cryo", "author_url": "https://stats.stackexchange.com/users/275239/cryo", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-26T12:24:08+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": 677266, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Cryo", "profile_url": "https://stats.stackexchange.com/users/275239/cryo", "user_type": "registered"}, "created_at": "2026-09-26T12:24:08+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D52BEFB1-287A-4A8F-B3B4-FF67FD14E1AD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D52BEFB1-287A-4A8F-B3B4-FF67FD14E1AD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Cryo", "profile_url": "https://stats.stackexchange.com/users/275239/cryo", "user_type": "registered"}, "created_at": "2026-09-26T12:33:54+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "24348886-EE3F-4779-9F2E-6DF7895E9D85", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/24348886-EE3F-4779-9F2E-6DF7895E9D85/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-09-26T13:34:16+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "57B9D992-5586-4BC1-9973-DD3482A5AA98", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/57B9D992-5586-4BC1-9973-DD3482A5AA98/view-source"}], "score": 5, "updated_at": "2026-09-26T13:34:16+00:00"}], "product": "statistics_qa", "question": "Here is a hierarchical data generating process (DGP):\n\n\n\n\n\n\n\n(Population) Layer 1: $$\\theta_i \\overset{\\text{iid}}{\\sim} \\text{Beta}(\\alpha,\\ \\beta), \\qquad i = 1, \\dots, n$$\n\n\n\n\n(Individual) Layer 2: $$y_{ij} \\mid \\theta_i \\overset{\\text{iid}}{\\sim} \\text{Bernoulli}(\\theta_i), \\qquad j = 1, \\dots, k$$\n\n\n\n\n\n\n\n$$\\mu = E[\\theta_i], \\qquad \\tau^2 = \\operatorname{Var}(\\theta_i)$$\n\n\n\n\nUsing a sample, my purpose is only to estimate the mean and the variance of the mean estimator. I want to know what values of $n$ and $k$ I should select to get good results (I know this hugely subjective) such that $nk$ is minimized (assume that increasing $n$ by 1 costs the same as increase $k$ by 1).\n\n\n\n\nAfter doing some research, it seems the best way to handle this question is by a simulation study. Assuming $\\alpha,\\ \\beta$ are known, I could sample from the DGP for different combinations of $n$ and $k$ and record the average length of the confidence intervals and average coverage rate at each combination. Since the mean estimator is unbiased regardless of the choice in $n$ or $k$, I could use average CI length and average coverage rate to make sure I am not getting a misleadingly good coverage rate at the expense of a large CI.\n\n\n\n\nHere is how I plan to do this in R (I wrote the code to focus on readability instead of speed - I use a moment based estimator and consider different true combinations of parameters):\n\n\n\n\nset.seed(2026)\n\nmu_vals <- c(0.01, 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 0.99)\nn_var <- 10\nn_vals <- c(5, 15, 30, 50, 100, 200)\nk_vals <- c(1, 2, 3, 4, 5, 6)\nR <- 2000\nconf <- 0.95\n\nscenarios <- data.frame()\n\nfor (mu in mu_vals) {\n max_var <- mu * (1 - mu)\n for (v in 1:n_var) {\n tau2 <- (v / (n_var + 1)) * max_var\n scenarios <- rbind(scenarios, data.frame(mu = mu, tau2 = tau2))\n }\n}\n\n\ncalc_mean <- function(ybar_i) {\n mean(ybar_i)\n}\n\ncalc_var_of_mean <- function(ybar_i) {\n n <- length(ybar_i)\n var(ybar_i) / n\n}\n\ncalc_coverage <- function(lower, upper, mu) {\n mean(lower <= mu & mu <= upper)\n}\n\ncalc_avg_ci_length <- function(lower, upper) {\n mean(upper - lower)\n}\n\nresults <- data.frame()\n\nfor (s in 1:nrow(scenarios)) {\n\n mu <- scenarios$mu[s]\n tau2 <- scenarios$tau2[s]\n\n alpha_plus_beta <- mu * (1 - mu) / tau2 - 1\n alpha <- mu * alpha_plus_beta\n beta <- (1 - mu) * alpha_plus_beta\n\n cat(sprintf(\"Scenario %d of %d: mu = %.2f, tau2 = %.4f\\n\",\n s, nrow(scenarios), mu, tau2))\n\n for (n in n_vals) {\n for (k in k_vals) {\n\n estimates <- numeric(R)\n var_estimates <- numeric(R)\n lower <- numeric(R)\n upper <- numeric(R)\n\n t_crit <- qt(1 - (1 - conf) / 2, df = n - 1)\n\n for (r in 1:R) {\n\n theta <- rbeta(n, alpha, beta)\n\n ybar_i <- numeric(n)\n for (i in 1:n) {\n y <- rbinom(k, size = 1, prob = theta[i])\n ybar_i[i] <- mean(y)\n }\n\n est <- calc_mean(ybar_i)\n v_est <- calc_var_of_mean(ybar_i)\n\n estimates[r] <- est\n var_estimates[r] <- v_est\n lower[r] <- est - t_crit * sqrt(v_est)\n upper[r] <- est + t_crit * sqrt(v_est)\n }\n\n true_var_of_mean <- (tau2 + (mu * (1 - mu) - tau2) / k) / n\n\n results <- rbind(results, data.frame(\n mu = mu,\n tau2 = tau2,\n n = n,\n k = k,\n avg_estimate = mean(estimates),\n true_var_of_mean = true_var_of_mean,\n sim_var_of_mean = var(estimates),\n avg_est_var_of_mean = mean(var_estimates),\n coverage = calc_coverage(lower, upper, mu),\n avg_ci_length = calc_avg_ci_length(lower, upper)\n ))\n }\n }\n}\n\n\n\n\n\nWhen visualized, the results look like this (direct upload was not working - however it seems to show that when $n$ and $k$ are both large, for many cases, we get high coverage and smaller CI lengths on average): https://imgur.com/a/tgHbtLz (https://imgur.com/a/tgHbtLz)\n\n\n\n\nThe tricky part now is to try and guess what the true value of $\\alpha,\\ \\beta$ might be. If I can get some knowledge of this beforehand (e.g. possible range), I could try to determine what $n,k$ to use if I want average CI length and average coverage rate to be within certain ranges.\n\n\n\n\nI am looking for feedback on my methodology. Should I have done this a different way?", "record_id": "Scientific-Statistics-QA:stats:677266", "selected_answer": {"answer_html": "

I think you can find the mean and variance of $\\bar y$ analytically. Clearly $\\mathbb E[\\bar y]=\\frac{\\alpha}{\\alpha+\\beta}$ and, using the law of total variance $$\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{nk(\\alpha+\\beta)^2} \\frac{\\alpha+\\beta+n}{\\alpha+\\beta+1} = \\frac{1}{nk}E[\\bar y]\\left(1-E[\\bar y]\\right) \\frac{\\alpha+\\beta+k}{\\alpha+\\beta+1}.$$

\n

Since $\\alpha\\ge 0, \\beta\\ge 0, 0 \\le E[\\bar y]\\le 1$, you can then say $$\\operatorname{Var}(\\bar y) \\le \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right) \\le \\frac1{4n}.$$

\n

For given $nk$, you will minimise $\\operatorname{Var}(\\bar y)$ when $k$ is as small as possible, i.e. when $k=1$ and $n=nk$, at which point $\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{n(\\alpha+\\beta)^2}= \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right)$, again bounded above by $\\frac1{4n}$. As discussed on your previous question, having $k=1$ would make it impossible to estimate $\\alpha$ and $\\beta$ separately.

\n

So using $k=1$ together with $n$ large enough to make $\\frac1{4n}$ small enough to meet your needs as an upper bound for $\\operatorname{Var}(\\bar y)$ should work well.

\n
\n

Here is an illustrative simulation in R confirming these (with minor simulation noise) for $\\alpha=2$, $\\beta=3$ and $nk=12$

\n
yhatsim <- function(alpha, beta, n, k){\n  thetai <- rbeta(n, alpha, beta)\n  sum(rbinom(n, k, thetai)) / (n * k) \n  }\nyhat <- function(alpha, beta, n, k, cases=10^6){\n  simyhat <- replicate(cases, yhatsim(alpha, beta, n, k))\n  c(simulatedmean=mean(simyhat), \n    expectedmean=alpha/(alpha+beta), \n    simulatedvar=var(simyhat),\n    expectedvar=alpha*beta/(alpha+beta)^2*(alpha+beta+k)/(alpha+beta+1)/(n*k))\n  }\n\n\nset.seed(2026)\n\nyhat(alpha=2, beta=3, n=12, k=1)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#     0.4000867     0.4000000     0.0199709     0.0200000 \n\nyhat(alpha=2, beta=3, n=6, k=2)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.39994625    0.40000000    0.02330732    0.02333333 \n\nyhat(alpha=2, beta=3, n=4, k=3)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#   0.40013683    0.40000000    0.02668078    0.02666667 \n\nyhat(alpha=2, beta=3, n=3, k=4)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.39973175    0.40000000    0.03001747    0.03000000 \n\nyhat(alpha=2, beta=3, n=2, k=6)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.40039333    0.40000000    0.03666519    0.03666667 \n\nyhat(alpha=2, beta=3, n=1, k=12)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.39992283    0.40000000    0.05659828    0.05666667 \n
\n", "answer_id": 677268, "answer_text": "I think you can find the mean and variance of $\\bar y$ analytically. Clearly $\\mathbb E[\\bar y]=\\frac{\\alpha}{\\alpha+\\beta}$ and, using the law of total variance $$\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{nk(\\alpha+\\beta)^2} \\frac{\\alpha+\\beta+n}{\\alpha+\\beta+1} = \\frac{1}{nk}E[\\bar y]\\left(1-E[\\bar y]\\right) \\frac{\\alpha+\\beta+k}{\\alpha+\\beta+1}.$$\n\n\n\n\nSince $\\alpha\\ge 0, \\beta\\ge 0, 0 \\le E[\\bar y]\\le 1$, you can then say $$\\operatorname{Var}(\\bar y) \\le \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right) \\le \\frac1{4n}.$$\n\n\n\n\nFor given $nk$, you will minimise $\\operatorname{Var}(\\bar y)$ when $k$ is as small as possible, i.e. when $k=1$ and $n=nk$, at which point $\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{n(\\alpha+\\beta)^2}= \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right)$, again bounded above by $\\frac1{4n}$. As discussed on your previous question (https://stats.stackexchange.com/q/677226/2958), having $k=1$ would make it impossible to estimate $\\alpha$ and $\\beta$ separately.\n\n\n\n\nSo using $k=1$ together with $n$ large enough to make $\\frac1{4n}$ small enough to meet your needs as an upper bound for $\\operatorname{Var}(\\bar y)$ should work well.\n\n\n\n\n\n\n\nHere is an illustrative simulation in R confirming these (with minor simulation noise) for $\\alpha=2$, $\\beta=3$ and $nk=12$\n\n\n\n\nyhatsim <- function(alpha, beta, n, k){\n thetai <- rbeta(n, alpha, beta)\n sum(rbinom(n, k, thetai)) / (n * k) \n }\nyhat <- function(alpha, beta, n, k, cases=10^6){\n simyhat <- replicate(cases, yhatsim(alpha, beta, n, k))\n c(simulatedmean=mean(simyhat), \n expectedmean=alpha/(alpha+beta), \n simulatedvar=var(simyhat),\n expectedvar=alpha*beta/(alpha+beta)^2*(alpha+beta+k)/(alpha+beta+1)/(n*k))\n }\n\n\nset.seed(2026)\n\nyhat(alpha=2, beta=3, n=12, k=1)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.4000867 0.4000000 0.0199709 0.0200000 \n\nyhat(alpha=2, beta=3, n=6, k=2)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.39994625 0.40000000 0.02330732 0.02333333 \n\nyhat(alpha=2, beta=3, n=4, k=3)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.40013683 0.40000000 0.02668078 0.02666667 \n\nyhat(alpha=2, beta=3, n=3, k=4)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.39973175 0.40000000 0.03001747 0.03000000 \n\nyhat(alpha=2, beta=3, n=2, k=6)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.40039333 0.40000000 0.03666519 0.03666667 \n\nyhat(alpha=2, beta=3, n=1, k=12)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.39992283 0.40000000 0.05659828 0.05666667", "answer_url": "https://stats.stackexchange.com/a/677268", "author": "Henry", "author_url": "https://stats.stackexchange.com/users/2958/henry", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-26T14:10:23+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": 677266, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Henry", "profile_url": "https://stats.stackexchange.com/users/2958/henry", "user_type": "registered"}, "created_at": "2026-09-26T14:10:23+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "C96EACA9-97B0-4929-B972-DA5D20ED4759", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C96EACA9-97B0-4929-B972-DA5D20ED4759/view-source"}], "score": 4, "updated_at": "2026-09-26T14:10:23+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677268, "answers": [{"answer_html": "

I would not go through mean and variance here. Your model for data generation is based on $\\alpha$ and $\\beta$ right? So why not work with them? Your population variable $\\theta$, as per your model is beta-distirbuted, so why not work with beta-likelihood? The problem is that sample variance and sample mean of a beta-distributed variable set, such as $\\{\\theta_i\\}$, are not independent variables, so you should not estimate them independently of each other.

\n

If I had a sample $\\{y_{ij}\\}$ I would estimate it like this:

\n
    \n
  1. Have variables $u$, $v$, and take $\\frac{\\alpha}{\\alpha+\\beta}=expit\\left(u\\right)=\\frac{1}{1+\\exp\\left(-u\\right)}$, $\\alpha=softplus(v)=\\log\\left(1+\\exp(v)\\right)$
  2. \n
  3. $\\sum_{j}y_{ij}=y_i\\sim BetaBinomial\\left(k, \\alpha,\\beta\\right)$
  4. \n
\n

Optimise jointly $u,v$ (maximum likelihood).

\n

So your sample size calculation would be a wrap-around for this procedure, i.e. select, $n, k$ etc. It may be slower, but not too slow with your numbers. But it will be giving correct estimates even when $\\theta$ is close to the edges for the given variance (and thus cannot be treated as normal).

\n
\n

If you want to stick to variance and mean, you should be honest with yourself and state $\\theta_i \\sim Normal\\left(\\mu,\\sigma^2\\right)$. If you get reasonable numbers, good, if not then you know your approximation is not suitable

\n", "answer_id": 677267, "answer_text": "I would not go through mean and variance here. Your model for data generation is based on $\\alpha$ and $\\beta$ right? So why not work with them? Your population variable $\\theta$, as per your model is beta-distirbuted, so why not work with beta-likelihood? The problem is that sample variance and sample mean of a beta-distributed variable set, such as $\\{\\theta_i\\}$, are not independent variables, so you should not estimate them independently of each other.\n\n\n\n\nIf I had a sample $\\{y_{ij}\\}$ I would estimate it like this:\n\n\n\n\n\nHave variables $u$, $v$, and take $\\frac{\\alpha}{\\alpha+\\beta}=expit\\left(u\\right)=\\frac{1}{1+\\exp\\left(-u\\right)}$, $\\alpha=softplus(v)=\\log\\left(1+\\exp(v)\\right)$\n\n\n\n\n$\\sum_{j}y_{ij}=y_i\\sim BetaBinomial\\left(k, \\alpha,\\beta\\right)$\n\n\n\n\n\nOptimise jointly $u,v$ (maximum likelihood).\n\n\n\n\nSo your sample size calculation would be a wrap-around for this procedure, i.e. select, $n, k$ etc. It may be slower, but not too slow with your numbers. But it will be giving correct estimates even when $\\theta$ is close to the edges for the given variance (and thus cannot be treated as normal).\n\n\n\n\n\n\n\nIf you want to stick to variance and mean, you should be honest with yourself and state $\\theta_i \\sim Normal\\left(\\mu,\\sigma^2\\right)$. If you get reasonable numbers, good, if not then you know your approximation is not suitable", "answer_url": "https://stats.stackexchange.com/a/677267", "author": "Cryo", "author_url": "https://stats.stackexchange.com/users/275239/cryo", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-26T12:24:08+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": 677266, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Cryo", "profile_url": "https://stats.stackexchange.com/users/275239/cryo", "user_type": "registered"}, "created_at": "2026-09-26T12:24:08+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D52BEFB1-287A-4A8F-B3B4-FF67FD14E1AD", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D52BEFB1-287A-4A8F-B3B4-FF67FD14E1AD/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Cryo", "profile_url": "https://stats.stackexchange.com/users/275239/cryo", "user_type": "registered"}, "created_at": "2026-09-26T12:33:54+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "24348886-EE3F-4779-9F2E-6DF7895E9D85", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/24348886-EE3F-4779-9F2E-6DF7895E9D85/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-09-26T13:34:16+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "57B9D992-5586-4BC1-9973-DD3482A5AA98", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/57B9D992-5586-4BC1-9973-DD3482A5AA98/view-source"}], "score": 5, "updated_at": "2026-09-26T13:34:16+00:00"}, {"answer_html": "

I think you can find the mean and variance of $\\bar y$ analytically. Clearly $\\mathbb E[\\bar y]=\\frac{\\alpha}{\\alpha+\\beta}$ and, using the law of total variance $$\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{nk(\\alpha+\\beta)^2} \\frac{\\alpha+\\beta+n}{\\alpha+\\beta+1} = \\frac{1}{nk}E[\\bar y]\\left(1-E[\\bar y]\\right) \\frac{\\alpha+\\beta+k}{\\alpha+\\beta+1}.$$

\n

Since $\\alpha\\ge 0, \\beta\\ge 0, 0 \\le E[\\bar y]\\le 1$, you can then say $$\\operatorname{Var}(\\bar y) \\le \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right) \\le \\frac1{4n}.$$

\n

For given $nk$, you will minimise $\\operatorname{Var}(\\bar y)$ when $k$ is as small as possible, i.e. when $k=1$ and $n=nk$, at which point $\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{n(\\alpha+\\beta)^2}= \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right)$, again bounded above by $\\frac1{4n}$. As discussed on your previous question, having $k=1$ would make it impossible to estimate $\\alpha$ and $\\beta$ separately.

\n

So using $k=1$ together with $n$ large enough to make $\\frac1{4n}$ small enough to meet your needs as an upper bound for $\\operatorname{Var}(\\bar y)$ should work well.

\n
\n

Here is an illustrative simulation in R confirming these (with minor simulation noise) for $\\alpha=2$, $\\beta=3$ and $nk=12$

\n
yhatsim <- function(alpha, beta, n, k){\n  thetai <- rbeta(n, alpha, beta)\n  sum(rbinom(n, k, thetai)) / (n * k) \n  }\nyhat <- function(alpha, beta, n, k, cases=10^6){\n  simyhat <- replicate(cases, yhatsim(alpha, beta, n, k))\n  c(simulatedmean=mean(simyhat), \n    expectedmean=alpha/(alpha+beta), \n    simulatedvar=var(simyhat),\n    expectedvar=alpha*beta/(alpha+beta)^2*(alpha+beta+k)/(alpha+beta+1)/(n*k))\n  }\n\n\nset.seed(2026)\n\nyhat(alpha=2, beta=3, n=12, k=1)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#     0.4000867     0.4000000     0.0199709     0.0200000 \n\nyhat(alpha=2, beta=3, n=6, k=2)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.39994625    0.40000000    0.02330732    0.02333333 \n\nyhat(alpha=2, beta=3, n=4, k=3)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#   0.40013683    0.40000000    0.02668078    0.02666667 \n\nyhat(alpha=2, beta=3, n=3, k=4)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.39973175    0.40000000    0.03001747    0.03000000 \n\nyhat(alpha=2, beta=3, n=2, k=6)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.40039333    0.40000000    0.03666519    0.03666667 \n\nyhat(alpha=2, beta=3, n=1, k=12)\n# simulatedmean  expectedmean  simulatedvar   expectedvar \n#    0.39992283    0.40000000    0.05659828    0.05666667 \n
\n", "answer_id": 677268, "answer_text": "I think you can find the mean and variance of $\\bar y$ analytically. Clearly $\\mathbb E[\\bar y]=\\frac{\\alpha}{\\alpha+\\beta}$ and, using the law of total variance $$\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{nk(\\alpha+\\beta)^2} \\frac{\\alpha+\\beta+n}{\\alpha+\\beta+1} = \\frac{1}{nk}E[\\bar y]\\left(1-E[\\bar y]\\right) \\frac{\\alpha+\\beta+k}{\\alpha+\\beta+1}.$$\n\n\n\n\nSince $\\alpha\\ge 0, \\beta\\ge 0, 0 \\le E[\\bar y]\\le 1$, you can then say $$\\operatorname{Var}(\\bar y) \\le \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right) \\le \\frac1{4n}.$$\n\n\n\n\nFor given $nk$, you will minimise $\\operatorname{Var}(\\bar y)$ when $k$ is as small as possible, i.e. when $k=1$ and $n=nk$, at which point $\\operatorname{Var}(\\bar y) = \\frac{\\alpha \\beta}{n(\\alpha+\\beta)^2}= \\frac{1}{n}E[\\bar y]\\left(1-E[\\bar y]\\right)$, again bounded above by $\\frac1{4n}$. As discussed on your previous question (https://stats.stackexchange.com/q/677226/2958), having $k=1$ would make it impossible to estimate $\\alpha$ and $\\beta$ separately.\n\n\n\n\nSo using $k=1$ together with $n$ large enough to make $\\frac1{4n}$ small enough to meet your needs as an upper bound for $\\operatorname{Var}(\\bar y)$ should work well.\n\n\n\n\n\n\n\nHere is an illustrative simulation in R confirming these (with minor simulation noise) for $\\alpha=2$, $\\beta=3$ and $nk=12$\n\n\n\n\nyhatsim <- function(alpha, beta, n, k){\n thetai <- rbeta(n, alpha, beta)\n sum(rbinom(n, k, thetai)) / (n * k) \n }\nyhat <- function(alpha, beta, n, k, cases=10^6){\n simyhat <- replicate(cases, yhatsim(alpha, beta, n, k))\n c(simulatedmean=mean(simyhat), \n expectedmean=alpha/(alpha+beta), \n simulatedvar=var(simyhat),\n expectedvar=alpha*beta/(alpha+beta)^2*(alpha+beta+k)/(alpha+beta+1)/(n*k))\n }\n\n\nset.seed(2026)\n\nyhat(alpha=2, beta=3, n=12, k=1)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.4000867 0.4000000 0.0199709 0.0200000 \n\nyhat(alpha=2, beta=3, n=6, k=2)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.39994625 0.40000000 0.02330732 0.02333333 \n\nyhat(alpha=2, beta=3, n=4, k=3)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.40013683 0.40000000 0.02668078 0.02666667 \n\nyhat(alpha=2, beta=3, n=3, k=4)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.39973175 0.40000000 0.03001747 0.03000000 \n\nyhat(alpha=2, beta=3, n=2, k=6)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.40039333 0.40000000 0.03666519 0.03666667 \n\nyhat(alpha=2, beta=3, n=1, k=12)\n# simulatedmean expectedmean simulatedvar expectedvar \n# 0.39992283 0.40000000 0.05659828 0.05666667", "answer_url": "https://stats.stackexchange.com/a/677268", "author": "Henry", "author_url": "https://stats.stackexchange.com/users/2958/henry", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-26T14:10:23+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": 677266, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Henry", "profile_url": "https://stats.stackexchange.com/users/2958/henry", "user_type": "registered"}, "created_at": "2026-09-26T14:10:23+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "C96EACA9-97B0-4929-B972-DA5D20ED4759", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C96EACA9-97B0-4929-B972-DA5D20ED4759/view-source"}], "score": 4, "updated_at": "2026-09-26T14:10:23+00:00"}], "domain": "statistics", "external_links": ["https://imgur.com/a/tgHbtLz"], "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-25T19:59:10+00:00", "question_html": "

Here is a hierarchical data generating process (DGP):

\n
\n

(Population) Layer 1: $$\\theta_i \\overset{\\text{iid}}{\\sim} \\text{Beta}(\\alpha,\\ \\beta), \\qquad i = 1, \\dots, n$$

\n

(Individual) Layer 2: $$y_{ij} \\mid \\theta_i \\overset{\\text{iid}}{\\sim} \\text{Bernoulli}(\\theta_i), \\qquad j = 1, \\dots, k$$

\n
\n

$$\\mu = E[\\theta_i], \\qquad \\tau^2 = \\operatorname{Var}(\\theta_i)$$

\n

Using a sample, my purpose is only to estimate the mean and the variance of the mean estimator. I want to know what values of $n$ and $k$ I should select to get good results (I know this hugely subjective) such that $nk$ is minimized (assume that increasing $n$ by 1 costs the same as increase $k$ by 1).

\n

After doing some research, it seems the best way to handle this question is by a simulation study. Assuming $\\alpha,\\ \\beta$ are known, I could sample from the DGP for different combinations of $n$ and $k$ and record the average length of the confidence intervals and average coverage rate at each combination. Since the mean estimator is unbiased regardless of the choice in $n$ or $k$, I could use average CI length and average coverage rate to make sure I am not getting a misleadingly good coverage rate at the expense of a large CI.

\n

Here is how I plan to do this in R (I wrote the code to focus on readability instead of speed - I use a moment based estimator and consider different true combinations of parameters):

\n
set.seed(2026)\n\nmu_vals <- c(0.01, 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 0.99)\nn_var   <- 10\nn_vals  <- c(5, 15, 30, 50, 100, 200)\nk_vals  <- c(1, 2, 3, 4, 5, 6)\nR       <- 2000\nconf    <- 0.95\n\nscenarios <- data.frame()\n\nfor (mu in mu_vals) {\n  max_var <- mu * (1 - mu)\n  for (v in 1:n_var) {\n    tau2 <- (v / (n_var + 1)) * max_var\n    scenarios <- rbind(scenarios, data.frame(mu = mu, tau2 = tau2))\n  }\n}\n\n\ncalc_mean <- function(ybar_i) {\n  mean(ybar_i)\n}\n\ncalc_var_of_mean <- function(ybar_i) {\n  n <- length(ybar_i)\n  var(ybar_i) / n\n}\n\ncalc_coverage <- function(lower, upper, mu) {\n  mean(lower <= mu & mu <= upper)\n}\n\ncalc_avg_ci_length <- function(lower, upper) {\n  mean(upper - lower)\n}\n\nresults <- data.frame()\n\nfor (s in 1:nrow(scenarios)) {\n\n  mu   <- scenarios$mu[s]\n  tau2 <- scenarios$tau2[s]\n\n  alpha_plus_beta <- mu * (1 - mu) / tau2 - 1\n  alpha <- mu * alpha_plus_beta\n  beta  <- (1 - mu) * alpha_plus_beta\n\n  cat(sprintf("Scenario %d of %d: mu = %.2f, tau2 = %.4f\\n",\n              s, nrow(scenarios), mu, tau2))\n\n  for (n in n_vals) {\n    for (k in k_vals) {\n\n      estimates     <- numeric(R)\n      var_estimates <- numeric(R)\n      lower         <- numeric(R)\n      upper         <- numeric(R)\n\n      t_crit <- qt(1 - (1 - conf) / 2, df = n - 1)\n\n      for (r in 1:R) {\n\n        theta <- rbeta(n, alpha, beta)\n\n        ybar_i <- numeric(n)\n        for (i in 1:n) {\n          y <- rbinom(k, size = 1, prob = theta[i])\n          ybar_i[i] <- mean(y)\n        }\n\n        est   <- calc_mean(ybar_i)\n        v_est <- calc_var_of_mean(ybar_i)\n\n        estimates[r]     <- est\n        var_estimates[r] <- v_est\n        lower[r]         <- est - t_crit * sqrt(v_est)\n        upper[r]         <- est + t_crit * sqrt(v_est)\n      }\n\n      true_var_of_mean <- (tau2 + (mu * (1 - mu) - tau2) / k) / n\n\n      results <- rbind(results, data.frame(\n        mu                  = mu,\n        tau2                = tau2,\n        n                   = n,\n        k                   = k,\n        avg_estimate        = mean(estimates),\n        true_var_of_mean    = true_var_of_mean,\n        sim_var_of_mean     = var(estimates),\n        avg_est_var_of_mean = mean(var_estimates),\n        coverage            = calc_coverage(lower, upper, mu),\n        avg_ci_length       = calc_avg_ci_length(lower, upper)\n      ))\n    }\n  }\n}\n
\n

When visualized, the results look like this (direct upload was not working - however it seems to show that when $n$ and $k$ are both large, for many cases, we get high coverage and smaller CI lengths on average): https://imgur.com/a/tgHbtLz

\n

The tricky part now is to try and guess what the true value of $\\alpha,\\ \\beta$ might be. If I can get some knowledge of this beforehand (e.g. possible range), I could try to determine what $n,k$ to use if I want average CI length and average coverage rate to be within certain ranges.

\n

I am looking for feedback on my methodology. Should I have done this a different way?

\n", "question_id": 677266, "question_license": "CC BY-SA 4.0", "question_score": 6, "question_text": "Here is a hierarchical data generating process (DGP):\n\n\n\n\n\n\n\n(Population) Layer 1: $$\\theta_i \\overset{\\text{iid}}{\\sim} \\text{Beta}(\\alpha,\\ \\beta), \\qquad i = 1, \\dots, n$$\n\n\n\n\n(Individual) Layer 2: $$y_{ij} \\mid \\theta_i \\overset{\\text{iid}}{\\sim} \\text{Bernoulli}(\\theta_i), \\qquad j = 1, \\dots, k$$\n\n\n\n\n\n\n\n$$\\mu = E[\\theta_i], \\qquad \\tau^2 = \\operatorname{Var}(\\theta_i)$$\n\n\n\n\nUsing a sample, my purpose is only to estimate the mean and the variance of the mean estimator. I want to know what values of $n$ and $k$ I should select to get good results (I know this hugely subjective) such that $nk$ is minimized (assume that increasing $n$ by 1 costs the same as increase $k$ by 1).\n\n\n\n\nAfter doing some research, it seems the best way to handle this question is by a simulation study. Assuming $\\alpha,\\ \\beta$ are known, I could sample from the DGP for different combinations of $n$ and $k$ and record the average length of the confidence intervals and average coverage rate at each combination. Since the mean estimator is unbiased regardless of the choice in $n$ or $k$, I could use average CI length and average coverage rate to make sure I am not getting a misleadingly good coverage rate at the expense of a large CI.\n\n\n\n\nHere is how I plan to do this in R (I wrote the code to focus on readability instead of speed - I use a moment based estimator and consider different true combinations of parameters):\n\n\n\n\nset.seed(2026)\n\nmu_vals <- c(0.01, 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 0.99)\nn_var <- 10\nn_vals <- c(5, 15, 30, 50, 100, 200)\nk_vals <- c(1, 2, 3, 4, 5, 6)\nR <- 2000\nconf <- 0.95\n\nscenarios <- data.frame()\n\nfor (mu in mu_vals) {\n max_var <- mu * (1 - mu)\n for (v in 1:n_var) {\n tau2 <- (v / (n_var + 1)) * max_var\n scenarios <- rbind(scenarios, data.frame(mu = mu, tau2 = tau2))\n }\n}\n\n\ncalc_mean <- function(ybar_i) {\n mean(ybar_i)\n}\n\ncalc_var_of_mean <- function(ybar_i) {\n n <- length(ybar_i)\n var(ybar_i) / n\n}\n\ncalc_coverage <- function(lower, upper, mu) {\n mean(lower <= mu & mu <= upper)\n}\n\ncalc_avg_ci_length <- function(lower, upper) {\n mean(upper - lower)\n}\n\nresults <- data.frame()\n\nfor (s in 1:nrow(scenarios)) {\n\n mu <- scenarios$mu[s]\n tau2 <- scenarios$tau2[s]\n\n alpha_plus_beta <- mu * (1 - mu) / tau2 - 1\n alpha <- mu * alpha_plus_beta\n beta <- (1 - mu) * alpha_plus_beta\n\n cat(sprintf(\"Scenario %d of %d: mu = %.2f, tau2 = %.4f\\n\",\n s, nrow(scenarios), mu, tau2))\n\n for (n in n_vals) {\n for (k in k_vals) {\n\n estimates <- numeric(R)\n var_estimates <- numeric(R)\n lower <- numeric(R)\n upper <- numeric(R)\n\n t_crit <- qt(1 - (1 - conf) / 2, df = n - 1)\n\n for (r in 1:R) {\n\n theta <- rbeta(n, alpha, beta)\n\n ybar_i <- numeric(n)\n for (i in 1:n) {\n y <- rbinom(k, size = 1, prob = theta[i])\n ybar_i[i] <- mean(y)\n }\n\n est <- calc_mean(ybar_i)\n v_est <- calc_var_of_mean(ybar_i)\n\n estimates[r] <- est\n var_estimates[r] <- v_est\n lower[r] <- est - t_crit * sqrt(v_est)\n upper[r] <- est + t_crit * sqrt(v_est)\n }\n\n true_var_of_mean <- (tau2 + (mu * (1 - mu) - tau2) / k) / n\n\n results <- rbind(results, data.frame(\n mu = mu,\n tau2 = tau2,\n n = n,\n k = k,\n avg_estimate = mean(estimates),\n true_var_of_mean = true_var_of_mean,\n sim_var_of_mean = var(estimates),\n avg_est_var_of_mean = mean(var_estimates),\n coverage = calc_coverage(lower, upper, mu),\n avg_ci_length = calc_avg_ci_length(lower, upper)\n ))\n }\n }\n}\n\n\n\n\n\nWhen visualized, the results look like this (direct upload was not working - however it seems to show that when $n$ and $k$ are both large, for many cases, we get high coverage and smaller CI lengths on average): https://imgur.com/a/tgHbtLz (https://imgur.com/a/tgHbtLz)\n\n\n\n\nThe tricky part now is to try and guess what the true value of $\\alpha,\\ \\beta$ might be. If I can get some knowledge of this beforehand (e.g. possible range), I could try to determine what $n,k$ to use if I want average CI length and average coverage rate to be within certain ranges.\n\n\n\n\nI am looking for feedback on my methodology. Should I have done this a different way?", "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-25T19:59:10+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "BDACA524-F3A6-491A-880E-A6871C920AE2", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/BDACA524-F3A6-491A-880E-A6871C920AE2/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-25T20:06:02+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "AD0D55CA-D20D-43CE-AF14-F3B414CC07CC", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD0D55CA-D20D-43CE-AF14-F3B414CC07CC/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-26T14:16:51+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "33D7D8BE-907F-442F-B2B0-F7C572555835", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/33D7D8BE-907F-442F-B2B0-F7C572555835/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-26T17:38:27+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "CAC7EE3C-CE9C-4299-BF6B-07246FC0E1C1", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CAC7EE3C-CE9C-4299-BF6B-07246FC0E1C1/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677266/how-to-set-up-a-simulation-study", "split": "train", "split_group": "21d3364431200c413f5adef6742bd9555e0cb33cda58781dfab79e3d31d1b7fb", "tags": ["r", "sampling", "estimation"], "thread_id": "stats:677266", "title": "How to set up a simulation study?"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "Why are the holding times of a Markov chain assumed to follow a geometric distribution? Is this actually an assumption, or does it follow from the Markov property?", "record_id": "Scientific-Statistics-QA:stats:677269", "selected_answer": {"answer_html": "

It follows from the Markov property. The conditional distribution of the next state given the present state does not depend on the past, i.e. does not depend on the state at any earlier time. Thus the probability of remaining in the same state that the process is now in, at the next moment in time, does not depend on how long it's been there. Only the geometric distribution has such memorylessness.

\n", "answer_id": 677283, "answer_text": "It follows from the Markov property. The conditional distribution of the next state given the present state does not depend on the past, i.e. does not depend on the state at any earlier time. Thus the probability of remaining in the same state that the process is now in, at the next moment in time, does not depend on how long it's been there. Only the geometric distribution has such memorylessness.", "answer_url": "https://stats.stackexchange.com/a/677283", "author": "Michael Hardy", "author_url": "https://stats.stackexchange.com/users/5176/michael-hardy", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-27T21:59:15+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": 677269, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael Hardy", "profile_url": "https://stats.stackexchange.com/users/5176/michael-hardy", "user_type": "registered"}, "created_at": "2026-09-27T21:59:15+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "859402CF-B42F-4124-88CA-F38145ABEEAF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/859402CF-B42F-4124-88CA-F38145ABEEAF/view-source"}], "score": 2, "updated_at": "2026-09-27T21:59:15+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

It follows from the Markov property. The conditional distribution of the next state given the present state does not depend on the past, i.e. does not depend on the state at any earlier time. Thus the probability of remaining in the same state that the process is now in, at the next moment in time, does not depend on how long it's been there. Only the geometric distribution has such memorylessness.

\n", "answer_id": 677283, "answer_text": "It follows from the Markov property. The conditional distribution of the next state given the present state does not depend on the past, i.e. does not depend on the state at any earlier time. Thus the probability of remaining in the same state that the process is now in, at the next moment in time, does not depend on how long it's been there. Only the geometric distribution has such memorylessness.", "answer_url": "https://stats.stackexchange.com/a/677283", "author": "Michael Hardy", "author_url": "https://stats.stackexchange.com/users/5176/michael-hardy", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-27T21:59:15+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": 677269, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Michael Hardy", "profile_url": "https://stats.stackexchange.com/users/5176/michael-hardy", "user_type": "registered"}, "created_at": "2026-09-27T21:59:15+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "859402CF-B42F-4124-88CA-F38145ABEEAF", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/859402CF-B42F-4124-88CA-F38145ABEEAF/view-source"}], "score": 2, "updated_at": "2026-09-27T21:59:15+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": false, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "Ole Willa", "question_author_url": "https://stats.stackexchange.com/users/517112/ole-willa", "question_author_user_type": "registered", "question_created_at": "2026-09-26T20:31:44+00:00", "question_html": "

Why are the holding times of a Markov chain assumed to follow a geometric distribution? Is this actually an assumption, or does it follow from the Markov property?

\n", "question_id": 677269, "question_license": "CC BY-SA 4.0", "question_score": 4, "question_text": "Why are the holding times of a Markov chain assumed to follow a geometric distribution? Is this actually an assumption, or does it follow from the Markov property?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ole Willa", "profile_url": "https://stats.stackexchange.com/users/517112/ole-willa", "user_type": "registered"}, "created_at": "2026-09-26T20:31:44+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "E18FB371-67BE-41D2-9737-1F45AFD4B012", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/E18FB371-67BE-41D2-9737-1F45AFD4B012/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-27T22:02:54+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "BA0B0FCE-2A27-4832-8E84-03A65477D228", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/BA0B0FCE-2A27-4832-8E84-03A65477D228/view-source"}, {"content_license": null, "contributor": {"display_name": "kjetil b halvorsen", "profile_url": "https://stats.stackexchange.com/users/11887/kjetil-b-halvorsen", "user_type": "moderator"}, "created_at": "2026-09-28T00:02:36+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "2A878A71-A31E-47E5-B6CF-62734A8F8485", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2A878A71-A31E-47E5-B6CF-62734A8F8485/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-28T14:57:39+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "66126477-B349-418B-A316-1B652D39B4AF", "revision_number": 3, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/66126477-B349-418B-A316-1B652D39B4AF/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Nick Cox", "profile_url": "https://stats.stackexchange.com/users/22047/nick-cox", "user_type": "registered"}, "created_at": "2026-09-28T16:41:03+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "BB47246E-6715-427C-B5D6-80DC27DC7AB4", "revision_number": 4, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/BB47246E-6715-427C-B5D6-80DC27DC7AB4/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677269/why-is-the-distribution-of-markov-chain-a-geometric-distribution", "split": "train", "split_group": "727ed7977cd2fc8286895d1b3dd3bd2f9900264b2926027dd133c24b57acd5a9", "tags": ["stochastic-processes", "markov-process"], "thread_id": "stats:677269", "title": "Why is the distribution of Markov chain a geometric distribution?"}} +{"accepted_answer": null, "other_answers": [{"answer_html": "

There's a number of reasons and plus points for a fixed effects model. Firstly, purely didactically for teaching purpsoes, it's mathematically straightforward and it sometimes is easiest to build your intuition starting simple before adding further complexity. However, there's also good points for it in actual practice.

\n

Even when there is heterogeneity, it still provides a valid and more powerful test for whether there is a treatment effect, at all. Of course, when it's the correct model and there is just no or only not very meaningful treatment effect heterogeneity, the fixed effects model will be more efficient in terms of other things (like RMSE of the estimated treatment effect, much narrower confidence interval despite nominal coverage etc.). Where exactly the line is where it performs better is hard to say (of course you could answer that through simulation.

\n

Plus, unless you go Bayesian, it's really hard to do anything sensible in a random effects model with very few studies (good luck estimation a between trial variability from 2 or 3 studies).

\n

And let's be honest people are also very inconsistent about what they do with random effects models. E.g. what do most people seem to estimate? The inference about the mean of the random effects distribution, instead of the predictive distribution for an new unseen study. And all of that is assuming the variability between studies is a random thing that could go either way when we move to actual clinical practice, for which we are giving recommendations. In specific situations it could well be clear that it's not random. In fact, very little usually is done to explain between study variability when in fact design or study population features might very well explain differences...

\n", "answer_id": 677292, "answer_text": "There's a number of reasons and plus points for a fixed effects model. Firstly, purely didactically for teaching purpsoes, it's mathematically straightforward and it sometimes is easiest to build your intuition starting simple before adding further complexity. However, there's also good points for it in actual practice.\n\n\n\n\nEven when there is heterogeneity, it still provides a valid and more powerful test for whether there is a treatment effect, at all. Of course, when it's the correct model and there is just no or only not very meaningful treatment effect heterogeneity, the fixed effects model will be more efficient in terms of other things (like RMSE of the estimated treatment effect, much narrower confidence interval despite nominal coverage etc.). Where exactly the line is where it performs better is hard to say (of course you could answer that through simulation.\n\n\n\n\nPlus, unless you go Bayesian, it's really hard to do anything sensible in a random effects model with very few studies (good luck estimation a between trial variability from 2 or 3 studies).\n\n\n\n\nAnd let's be honest people are also very inconsistent about what they do with random effects models. E.g. what do most people seem to estimate? The inference about the mean of the random effects distribution, instead of the predictive distribution for an new unseen study. And all of that is assuming the variability between studies is a random thing that could go either way when we move to actual clinical practice, for which we are giving recommendations. In specific situations it could well be clear that it's not random. In fact, very little usually is done to explain between study variability when in fact design or study population features might very well explain differences...", "answer_url": "https://stats.stackexchange.com/a/677292", "author": "Björn", "author_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-28T17:36:50+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": 677279, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Björn", "profile_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "user_type": "registered"}, "created_at": "2026-09-28T17:36:50+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "CCB64628-E88B-4456-94DC-CB2F955D77AE", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CCB64628-E88B-4456-94DC-CB2F955D77AE/view-source"}], "score": 3, "updated_at": "2026-09-28T17:36:50+00:00"}], "product": "statistics_qa", "question": "Reading the texts on this it really starts to feel like the common-effects model is some historical artifact and for some reason it is seen as a baseline that you must mentally argue against. Really to me it is starting to feel like a completely inferior model. I know roughly of the different arguments for and against the two models, and the concern that using the Q statistic to determine heterogeneity is dubious. But isn't the biggest concern: What is the point of using the common-effect model, when the random-effects reduces to common in case of no heterogeneity? Beyond a toy model is the assumption even defensible anyway? Even if the true heterogeneity was tiny, it is not zero in practice. Or is the point that we want to force it to be zero because we have strong reasons to believe so? Reading some texts it seems like authors are short of saying we should NEVER use it, and are only discussing it because some people still seem to use it.\n\n\n\n\nMy point is: Why is “common effect versus random effects” presented as a substantive modeling fork in the first place, rather than common effect being treated as a degenerate special case or a diagnostic/reference calculation?\n\n\n\n\nWhat am I missing? Or is the point simply that the common-effect model or i guess then plural effects, is to be used in say subgroup analysis?", "record_id": "Scientific-Statistics-QA:stats:677279", "selected_answer": {"answer_html": "

If the true effects are indeed homogeneous, then you will lose some efficiency by using a random-effects model, because tau^2 will be estimated to be larger than 0 in roughly 50% of the cases (hopefully not by much, but still). Of course, using the model a priori then makes a rather strong assumption, but this may be justified when the studies are very similar to begin with.

\n

However, when I teach meta-analysis, I essentially just discuss the common-effect model didactically as a stepping stone to the random-effects model. There is, however, also the fixed-effects model, which (when using weighted estimation) is fitted in the exact same way as the common-effect model, but it has a completely different interpretation and does not assume homogeneity, that is, it estimates the (weighted) average of the true effects of the $k$ studies included in a meta-analysis (i.e., it provides a conditional inference about the set of studies included in the meta-analysis). See here for further details.

\n", "answer_id": 677290, "answer_text": "If the true effects are indeed homogeneous, then you will lose some efficiency by using a random-effects model, because tau^2 will be estimated to be larger than 0 in roughly 50% of the cases (hopefully not by much, but still). Of course, using the model a priori then makes a rather strong assumption, but this may be justified when the studies are very similar to begin with.\n\n\n\n\nHowever, when I teach meta-analysis, I essentially just discuss the common-effect model didactically as a stepping stone to the random-effects model. There is, however, also the fixed-effects model, which (when using weighted estimation) is fitted in the exact same way as the common-effect model, but it has a completely different interpretation and does not assume homogeneity, that is, it estimates the (weighted) average of the true effects of the $k$ studies included in a meta-analysis (i.e., it provides a conditional inference about the set of studies included in the meta-analysis). See here (https://wviechtb.github.io/metafor/reference/misc-models.html) for further details.", "answer_url": "https://stats.stackexchange.com/a/677290", "author": "Wolfgang", "author_url": "https://stats.stackexchange.com/users/1934/wolfgang", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-28T09:54:12+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": 677279, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Wolfgang", "profile_url": "https://stats.stackexchange.com/users/1934/wolfgang", "user_type": "registered"}, "created_at": "2026-09-28T09:54:12+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D79D5DD2-C98E-49F5-936B-70DC0A9ABB30", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D79D5DD2-C98E-49F5-936B-70DC0A9ABB30/view-source"}], "score": 4, "updated_at": "2026-09-28T09:54:12+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

If the true effects are indeed homogeneous, then you will lose some efficiency by using a random-effects model, because tau^2 will be estimated to be larger than 0 in roughly 50% of the cases (hopefully not by much, but still). Of course, using the model a priori then makes a rather strong assumption, but this may be justified when the studies are very similar to begin with.

\n

However, when I teach meta-analysis, I essentially just discuss the common-effect model didactically as a stepping stone to the random-effects model. There is, however, also the fixed-effects model, which (when using weighted estimation) is fitted in the exact same way as the common-effect model, but it has a completely different interpretation and does not assume homogeneity, that is, it estimates the (weighted) average of the true effects of the $k$ studies included in a meta-analysis (i.e., it provides a conditional inference about the set of studies included in the meta-analysis). See here for further details.

\n", "answer_id": 677290, "answer_text": "If the true effects are indeed homogeneous, then you will lose some efficiency by using a random-effects model, because tau^2 will be estimated to be larger than 0 in roughly 50% of the cases (hopefully not by much, but still). Of course, using the model a priori then makes a rather strong assumption, but this may be justified when the studies are very similar to begin with.\n\n\n\n\nHowever, when I teach meta-analysis, I essentially just discuss the common-effect model didactically as a stepping stone to the random-effects model. There is, however, also the fixed-effects model, which (when using weighted estimation) is fitted in the exact same way as the common-effect model, but it has a completely different interpretation and does not assume homogeneity, that is, it estimates the (weighted) average of the true effects of the $k$ studies included in a meta-analysis (i.e., it provides a conditional inference about the set of studies included in the meta-analysis). See here (https://wviechtb.github.io/metafor/reference/misc-models.html) for further details.", "answer_url": "https://stats.stackexchange.com/a/677290", "author": "Wolfgang", "author_url": "https://stats.stackexchange.com/users/1934/wolfgang", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-28T09:54:12+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": 677279, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Wolfgang", "profile_url": "https://stats.stackexchange.com/users/1934/wolfgang", "user_type": "registered"}, "created_at": "2026-09-28T09:54:12+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D79D5DD2-C98E-49F5-936B-70DC0A9ABB30", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D79D5DD2-C98E-49F5-936B-70DC0A9ABB30/view-source"}], "score": 4, "updated_at": "2026-09-28T09:54:12+00:00"}, {"answer_html": "

There's a number of reasons and plus points for a fixed effects model. Firstly, purely didactically for teaching purpsoes, it's mathematically straightforward and it sometimes is easiest to build your intuition starting simple before adding further complexity. However, there's also good points for it in actual practice.

\n

Even when there is heterogeneity, it still provides a valid and more powerful test for whether there is a treatment effect, at all. Of course, when it's the correct model and there is just no or only not very meaningful treatment effect heterogeneity, the fixed effects model will be more efficient in terms of other things (like RMSE of the estimated treatment effect, much narrower confidence interval despite nominal coverage etc.). Where exactly the line is where it performs better is hard to say (of course you could answer that through simulation.

\n

Plus, unless you go Bayesian, it's really hard to do anything sensible in a random effects model with very few studies (good luck estimation a between trial variability from 2 or 3 studies).

\n

And let's be honest people are also very inconsistent about what they do with random effects models. E.g. what do most people seem to estimate? The inference about the mean of the random effects distribution, instead of the predictive distribution for an new unseen study. And all of that is assuming the variability between studies is a random thing that could go either way when we move to actual clinical practice, for which we are giving recommendations. In specific situations it could well be clear that it's not random. In fact, very little usually is done to explain between study variability when in fact design or study population features might very well explain differences...

\n", "answer_id": 677292, "answer_text": "There's a number of reasons and plus points for a fixed effects model. Firstly, purely didactically for teaching purpsoes, it's mathematically straightforward and it sometimes is easiest to build your intuition starting simple before adding further complexity. However, there's also good points for it in actual practice.\n\n\n\n\nEven when there is heterogeneity, it still provides a valid and more powerful test for whether there is a treatment effect, at all. Of course, when it's the correct model and there is just no or only not very meaningful treatment effect heterogeneity, the fixed effects model will be more efficient in terms of other things (like RMSE of the estimated treatment effect, much narrower confidence interval despite nominal coverage etc.). Where exactly the line is where it performs better is hard to say (of course you could answer that through simulation.\n\n\n\n\nPlus, unless you go Bayesian, it's really hard to do anything sensible in a random effects model with very few studies (good luck estimation a between trial variability from 2 or 3 studies).\n\n\n\n\nAnd let's be honest people are also very inconsistent about what they do with random effects models. E.g. what do most people seem to estimate? The inference about the mean of the random effects distribution, instead of the predictive distribution for an new unseen study. And all of that is assuming the variability between studies is a random thing that could go either way when we move to actual clinical practice, for which we are giving recommendations. In specific situations it could well be clear that it's not random. In fact, very little usually is done to explain between study variability when in fact design or study population features might very well explain differences...", "answer_url": "https://stats.stackexchange.com/a/677292", "author": "Björn", "author_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-28T17:36:50+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": 677279, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Björn", "profile_url": "https://stats.stackexchange.com/users/86652/bj%c3%b6rn", "user_type": "registered"}, "created_at": "2026-09-28T17:36:50+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "CCB64628-E88B-4456-94DC-CB2F955D77AE", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/CCB64628-E88B-4456-94DC-CB2F955D77AE/view-source"}], "score": 3, "updated_at": "2026-09-28T17:36:50+00:00"}], "domain": "statistics", "external_links": ["https://wviechtb.github.io/metafor/reference/misc-models.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": "anonim123", "question_author_url": "https://stats.stackexchange.com/users/512047/anonim123", "question_author_user_type": "registered", "question_created_at": "2026-09-27T13:43:00+00:00", "question_html": "

Reading the texts on this it really starts to feel like the common-effects model is some historical artifact and for some reason it is seen as a baseline that you must mentally argue against. Really to me it is starting to feel like a completely inferior model. I know roughly of the different arguments for and against the two models, and the concern that using the Q statistic to determine heterogeneity is dubious. But isn't the biggest concern: What is the point of using the common-effect model, when the random-effects reduces to common in case of no heterogeneity? Beyond a toy model is the assumption even defensible anyway? Even if the true heterogeneity was tiny, it is not zero in practice. Or is the point that we want to force it to be zero because we have strong reasons to believe so? Reading some texts it seems like authors are short of saying we should NEVER use it, and are only discussing it because some people still seem to use it.

\n

My point is: Why is “common effect versus random effects” presented as a substantive modeling fork in the first place, rather than common effect being treated as a degenerate special case or a diagnostic/reference calculation?

\n

What am I missing? Or is the point simply that the common-effect model or i guess then plural effects, is to be used in say subgroup analysis?

\n", "question_id": 677279, "question_license": "CC BY-SA 4.0", "question_score": 3, "question_text": "Reading the texts on this it really starts to feel like the common-effects model is some historical artifact and for some reason it is seen as a baseline that you must mentally argue against. Really to me it is starting to feel like a completely inferior model. I know roughly of the different arguments for and against the two models, and the concern that using the Q statistic to determine heterogeneity is dubious. But isn't the biggest concern: What is the point of using the common-effect model, when the random-effects reduces to common in case of no heterogeneity? Beyond a toy model is the assumption even defensible anyway? Even if the true heterogeneity was tiny, it is not zero in practice. Or is the point that we want to force it to be zero because we have strong reasons to believe so? Reading some texts it seems like authors are short of saying we should NEVER use it, and are only discussing it because some people still seem to use it.\n\n\n\n\nMy point is: Why is “common effect versus random effects” presented as a substantive modeling fork in the first place, rather than common effect being treated as a degenerate special case or a diagnostic/reference calculation?\n\n\n\n\nWhat am I missing? Or is the point simply that the common-effect model or i guess then plural effects, is to be used in say subgroup analysis?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "anonim123", "profile_url": "https://stats.stackexchange.com/users/512047/anonim123", "user_type": "registered"}, "created_at": "2026-09-27T13:43:00+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "2F37521C-BD6B-4510-8AEC-C188AF431BE9", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/2F37521C-BD6B-4510-8AEC-C188AF431BE9/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "anonim123", "profile_url": "https://stats.stackexchange.com/users/512047/anonim123", "user_type": "registered"}, "created_at": "2026-09-27T13:50:31+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "F8AB1D75-8A0F-4AED-AD19-4921506BC4B7", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F8AB1D75-8A0F-4AED-AD19-4921506BC4B7/view-source"}, {"content_license": null, "contributor": {"display_name": "[deleted/unavailable user]", "profile_url": null, "user_type": "does_not_exist"}, "created_at": "2026-09-28T14:33:29+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "ED90A7B7-7815-4F25-A07B-31AD428A4141", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/ED90A7B7-7815-4F25-A07B-31AD428A4141/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677279/what-is-even-the-point-of-the-common-effect-model-in-meta-analysis", "split": "train", "split_group": "c009a6840531627dc515fd773db2da4f7b2549a912a539c7078b96e80dba858c", "tags": ["meta-analysis"], "thread_id": "stats:677279", "title": "What is even the point of the common-effect model in meta-analysis?"}} +{"accepted_answer": {"answer_html": "

I'm not sure how much this helps (actually I don't know your course and what exactly it was there that you didn't understand), but one key thing to understand about PCA is that PCA conceptualises "information" as variance, i.e., it tries to find the linear combination of variables that has most variance (where the linear coefficients are normed to 1 because otherwise multiplying a linear combination with a large constant would produce a larger variance, which doesn't help with finding informative directions in the data) in order to represent the data.

\n

This would be the first PC, further ones solve the same maximisation problem under the side condition that linear combinations should be orthogonal to the PCs already found earlier (in order to provide "orthogonal" information to the PCs that were already there).

\n

In order to provide dimension reduction, you'd consider the first $q<p$ PCs, where $p$ is the number of variables in the data. There is no "objective" method how to choose $q$ and no underlying model that assumes that there is a "true" $q$. Often $q=2$ is chosen just for the reason to visualise the data on a 2-d surface like a screen. There is also a theorem that shows that the sum of the variances of all variables (total variation) is equal to the sum of variances of all PCs, so that it makes sense to compute a "percentage of variance explained" by the first $q$ PCs, and another way to choose $q$ is to explain a large percentage, 90% or so. Note that the definition of PCAs implies that always the first PC explains most variance, the second one second most and so on.

\n

PCA just solves the explained optimisation problem, so there is nothing to "test". It does what it is supposed to do by its definition, and whether you want this or not in a given situation is up to you. Of course you may want a 2-d representation and then decide that the first two PCs are not good enough anyway if they only explain 30% of the variance (which can easily happen with high dimensional data), but this is up to you and whether such decisions make sense really depends on what you want to use the PCA results for.

\n

It is very legitimate to question whether variance is a good/appropriate measure of "information". One can easily find situations where one could argue that this is not the case, so this shouldn't be taken for granted. You just have to accept that it's the definition of PCA that variance is maximised. Historically this was maybe the first idea how "information in the data" of a single variable could be formalised, and it was friendly for computation (very important in the old days), so people would use it. To what extent this gives you the information that you need about the data on lower dimensions depends on the data and what exactly you want to do with them. Experience shows that PCs are often but not always good at showing the most relevant information. This may not be a satisfactory statement, but this is how it is. Also, in case the first PCs are not so good, there are lots of alternatives how to extract low-d information from high-d data, but it isn't at all obvious which one is best (no single one will be best in general), so PCA is often a first shot at the problem, even if not necessarily the best.

\n

One important thing to understand about this is that if you have variables with strongly different variance, particularly if they have different measurement units and values of different variables are not comparable, PCA may be dominated by high variance variables and more or less ignore low variance variables, which may be inappropriate if it doesn't make sense to compare the variances of the variables and take them as indication for "information", as is often the case. In such a situation (i.e., more often than not) one would as a standard run PCA on standardised variables, or, equivalently, on the correlation matrix rather than the covariance matrix of the data.

\n", "answer_id": 677284, "answer_text": "I'm not sure how much this helps (actually I don't know your course and what exactly it was there that you didn't understand), but one key thing to understand about PCA is that PCA conceptualises \"information\" as variance, i.e., it tries to find the linear combination of variables that has most variance (where the linear coefficients are normed to 1 because otherwise multiplying a linear combination with a large constant would produce a larger variance, which doesn't help with finding informative directions in the data) in order to represent the data.\n\n\n\n\nThis would be the first PC, further ones solve the same maximisation problem under the side condition that linear combinations should be orthogonal to the PCs already found earlier (in order to provide \"orthogonal\" information to the PCs that were already there).\n\n\n\n\nIn order to provide dimension reduction, you'd consider the first $qI'm not sure how much this helps (actually I don't know your course and what exactly it was there that you didn't understand), but one key thing to understand about PCA is that PCA conceptualises "information" as variance, i.e., it tries to find the linear combination of variables that has most variance (where the linear coefficients are normed to 1 because otherwise multiplying a linear combination with a large constant would produce a larger variance, which doesn't help with finding informative directions in the data) in order to represent the data.

\n

This would be the first PC, further ones solve the same maximisation problem under the side condition that linear combinations should be orthogonal to the PCs already found earlier (in order to provide "orthogonal" information to the PCs that were already there).

\n

In order to provide dimension reduction, you'd consider the first $q<p$ PCs, where $p$ is the number of variables in the data. There is no "objective" method how to choose $q$ and no underlying model that assumes that there is a "true" $q$. Often $q=2$ is chosen just for the reason to visualise the data on a 2-d surface like a screen. There is also a theorem that shows that the sum of the variances of all variables (total variation) is equal to the sum of variances of all PCs, so that it makes sense to compute a "percentage of variance explained" by the first $q$ PCs, and another way to choose $q$ is to explain a large percentage, 90% or so. Note that the definition of PCAs implies that always the first PC explains most variance, the second one second most and so on.

\n

PCA just solves the explained optimisation problem, so there is nothing to "test". It does what it is supposed to do by its definition, and whether you want this or not in a given situation is up to you. Of course you may want a 2-d representation and then decide that the first two PCs are not good enough anyway if they only explain 30% of the variance (which can easily happen with high dimensional data), but this is up to you and whether such decisions make sense really depends on what you want to use the PCA results for.

\n

It is very legitimate to question whether variance is a good/appropriate measure of "information". One can easily find situations where one could argue that this is not the case, so this shouldn't be taken for granted. You just have to accept that it's the definition of PCA that variance is maximised. Historically this was maybe the first idea how "information in the data" of a single variable could be formalised, and it was friendly for computation (very important in the old days), so people would use it. To what extent this gives you the information that you need about the data on lower dimensions depends on the data and what exactly you want to do with them. Experience shows that PCs are often but not always good at showing the most relevant information. This may not be a satisfactory statement, but this is how it is. Also, in case the first PCs are not so good, there are lots of alternatives how to extract low-d information from high-d data, but it isn't at all obvious which one is best (no single one will be best in general), so PCA is often a first shot at the problem, even if not necessarily the best.

\n

One important thing to understand about this is that if you have variables with strongly different variance, particularly if they have different measurement units and values of different variables are not comparable, PCA may be dominated by high variance variables and more or less ignore low variance variables, which may be inappropriate if it doesn't make sense to compare the variances of the variables and take them as indication for "information", as is often the case. In such a situation (i.e., more often than not) one would as a standard run PCA on standardised variables, or, equivalently, on the correlation matrix rather than the covariance matrix of the data.

\n", "answer_id": 677284, "answer_text": "I'm not sure how much this helps (actually I don't know your course and what exactly it was there that you didn't understand), but one key thing to understand about PCA is that PCA conceptualises \"information\" as variance, i.e., it tries to find the linear combination of variables that has most variance (where the linear coefficients are normed to 1 because otherwise multiplying a linear combination with a large constant would produce a larger variance, which doesn't help with finding informative directions in the data) in order to represent the data.\n\n\n\n\nThis would be the first PC, further ones solve the same maximisation problem under the side condition that linear combinations should be orthogonal to the PCs already found earlier (in order to provide \"orthogonal\" information to the PCs that were already there).\n\n\n\n\nIn order to provide dimension reduction, you'd consider the first $q= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": 677284, "answers": [{"answer_html": "

I'm not sure how much this helps (actually I don't know your course and what exactly it was there that you didn't understand), but one key thing to understand about PCA is that PCA conceptualises "information" as variance, i.e., it tries to find the linear combination of variables that has most variance (where the linear coefficients are normed to 1 because otherwise multiplying a linear combination with a large constant would produce a larger variance, which doesn't help with finding informative directions in the data) in order to represent the data.

\n

This would be the first PC, further ones solve the same maximisation problem under the side condition that linear combinations should be orthogonal to the PCs already found earlier (in order to provide "orthogonal" information to the PCs that were already there).

\n

In order to provide dimension reduction, you'd consider the first $q<p$ PCs, where $p$ is the number of variables in the data. There is no "objective" method how to choose $q$ and no underlying model that assumes that there is a "true" $q$. Often $q=2$ is chosen just for the reason to visualise the data on a 2-d surface like a screen. There is also a theorem that shows that the sum of the variances of all variables (total variation) is equal to the sum of variances of all PCs, so that it makes sense to compute a "percentage of variance explained" by the first $q$ PCs, and another way to choose $q$ is to explain a large percentage, 90% or so. Note that the definition of PCAs implies that always the first PC explains most variance, the second one second most and so on.

\n

PCA just solves the explained optimisation problem, so there is nothing to "test". It does what it is supposed to do by its definition, and whether you want this or not in a given situation is up to you. Of course you may want a 2-d representation and then decide that the first two PCs are not good enough anyway if they only explain 30% of the variance (which can easily happen with high dimensional data), but this is up to you and whether such decisions make sense really depends on what you want to use the PCA results for.

\n

It is very legitimate to question whether variance is a good/appropriate measure of "information". One can easily find situations where one could argue that this is not the case, so this shouldn't be taken for granted. You just have to accept that it's the definition of PCA that variance is maximised. Historically this was maybe the first idea how "information in the data" of a single variable could be formalised, and it was friendly for computation (very important in the old days), so people would use it. To what extent this gives you the information that you need about the data on lower dimensions depends on the data and what exactly you want to do with them. Experience shows that PCs are often but not always good at showing the most relevant information. This may not be a satisfactory statement, but this is how it is. Also, in case the first PCs are not so good, there are lots of alternatives how to extract low-d information from high-d data, but it isn't at all obvious which one is best (no single one will be best in general), so PCA is often a first shot at the problem, even if not necessarily the best.

\n

One important thing to understand about this is that if you have variables with strongly different variance, particularly if they have different measurement units and values of different variables are not comparable, PCA may be dominated by high variance variables and more or less ignore low variance variables, which may be inappropriate if it doesn't make sense to compare the variances of the variables and take them as indication for "information", as is often the case. In such a situation (i.e., more often than not) one would as a standard run PCA on standardised variables, or, equivalently, on the correlation matrix rather than the covariance matrix of the data.

\n", "answer_id": 677284, "answer_text": "I'm not sure how much this helps (actually I don't know your course and what exactly it was there that you didn't understand), but one key thing to understand about PCA is that PCA conceptualises \"information\" as variance, i.e., it tries to find the linear combination of variables that has most variance (where the linear coefficients are normed to 1 because otherwise multiplying a linear combination with a large constant would produce a larger variance, which doesn't help with finding informative directions in the data) in order to represent the data.\n\n\n\n\nThis would be the first PC, further ones solve the same maximisation problem under the side condition that linear combinations should be orthogonal to the PCs already found earlier (in order to provide \"orthogonal\" information to the PCs that were already there).\n\n\n\n\nIn order to provide dimension reduction, you'd consider the first $qI have taken a course in PCA and it couldn't be more vague.

\n

They used terms like lower dimension that preserves the most information etc. But all that terminology gave me absolutely no idea about what's going on. Like what is the formal problem and what hypotheses are assumed to solve it.

\n

I have been looking into it a few days now and the only conclusion I came to is that: we are probably trying to figure out linear combinations of random variables such that the distribution of a lower number of those combos approximates the distribution of the whole dimension "in some sense". Could someone provide a clarification?

\n

How do people just absorb this kind of thing? Maybe I have a pedagogical flaw. I am sorry if this was unclear.

\n", "question_id": 677280, "question_license": "CC BY-SA 4.0", "question_score": 1, "question_text": "I have taken a course in PCA and it couldn't be more vague.\n\n\n\n\nThey used terms like lower dimension that preserves the most information etc. But all that terminology gave me absolutely no idea about what's going on. Like what is the formal problem and what hypotheses are assumed to solve it.\n\n\n\n\nI have been looking into it a few days now and the only conclusion I came to is that: we are probably trying to figure out linear combinations of random variables such that the distribution of a lower number of those combos approximates the distribution of the whole dimension \"in some sense\". Could someone provide a clarification?\n\n\n\n\nHow do people just absorb this kind of thing? Maybe I have a pedagogical flaw. I am sorry if this was unclear.", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Beautiful Lands", "profile_url": "https://stats.stackexchange.com/users/517165/beautiful-lands", "user_type": "registered"}, "created_at": "2026-09-27T15:22:18+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "F0523DD7-B7C2-4EE4-8B18-99DA54196D8E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/F0523DD7-B7C2-4EE4-8B18-99DA54196D8E/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Beautiful Lands", "profile_url": "https://stats.stackexchange.com/users/517165/beautiful-lands", "user_type": "registered"}, "created_at": "2026-09-27T15:24:02+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "0738B0B9-AC5B-41AA-9E47-6113FC0A0902", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/0738B0B9-AC5B-41AA-9E47-6113FC0A0902/view-source"}, {"content_license": null, "contributor": {"display_name": "whuber", "profile_url": "https://stats.stackexchange.com/users/919/whuber", "user_type": "moderator"}, "created_at": "2026-09-27T16:41:40+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "16B74449-CFCD-4E99-BF76-3976289570B7", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/16B74449-CFCD-4E99-BF76-3976289570B7/view-source"}, {"content_license": null, "contributor": {"display_name": "Community", "profile_url": "https://stats.stackexchange.com/users/-1/community", "user_type": "moderator"}, "created_at": "2026-09-27T23:02:45+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "B6D11FAD-23D1-446D-B7C1-EA8BB84512FC", "revision_number": null, "revision_type": "vote_based", "revision_url": "https://stats.stackexchange.com/revisions/B6D11FAD-23D1-446D-B7C1-EA8BB84512FC/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677280/i-am-confused-about-pca", "split": "train", "split_group": "abcccd3bcf67c7b861ea6414c6c95469c47085500cd19d20be1246657809bc1e", "tags": ["pca"], "thread_id": "stats:677280", "title": "I am confused about PCA"}} +{"accepted_answer": null, "other_answers": [], "product": "statistics_qa", "question": "I'm trying to decide which GLMM distribution is best for my data.\n\n\n\n\nI want to determine how plant_trait_a and plant_trait_b affect beetle seed damage.\n\n\n\n\nThere were two levels of plant_trait_a and two levels of plant_trait_b that made up 4 treatment groups. We selected 20 plant_genotypes for our field experiment, each treatment group had 5. Each plant genotype was planted 3 times, in 3 different planting_blocks.\n\n\n\n\nWe collected 56-100 seeds per plot (plot=planting_blockxplant_genotype combination); most had 100 seeds, but 4 plots had less than 100 seeds available. I then counted the number of beetle damaged seeds (seeds_beetle_damaged) in each sample.\n\n\n\n\n#preview of seeddamage\n year planting_block plant_genotype plant_trait_a plant_trait_b seeds_total seeds_beetle_damaged prop_beetle_damaged\n1 2024 1 1 yes short 100 59 0.59000000\n2 2024 1 2 yes short 84 7 0.08333333\n3 2024 1 3 yes short 69 30 0.43478261\n4 2024 1 4 yes short 100 22 0.22000000\n5 2024 1 5 yes short 100 36 0.36000000\n6 2024 1 6 no short 100 15 0.15000000\n7 2024 1 7 no short 100 8 0.08000000\n8 2024 1 8 no short 100 10 0.10000000\n9 2024 1 9 no short 100 10 0.10000000\n10 2024 1 10 no short 100 2 0.02000000\n\n\nseeddamage<-structure(list(year = c(2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2025L, 2025L, \n 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, \n 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L), planting_block = c(1L, \n 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, \n 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, \n 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, \n 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), plant_genotype = c(1L, \n 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, \n 16L, 17L, 18L, 19L, 20L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, \n 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 16L, 17L, \n 18L, 19L, 20L, 11L, 12L, 14L, 15L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, \n 3L, 4L, 5L), plant_trait_a = c(\"yes\", \"yes\", \"yes\", \"yes\", \"yes\", \n \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \"yes\", \"yes\", \"yes\", \"yes\", \n \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \"yes\", \"yes\", \"yes\", \"yes\", \n \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \"yes\", \"yes\", \"yes\", \"yes\", \n \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \n \"yes\", \"yes\", \"yes\", \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \"yes\", \n \"yes\", \"yes\", \"yes\"), plant_trait_b = c(\"short\", \"short\", \"short\", \n \"short\", \"short\", \"short\", \"short\", \"short\", \"short\", \"short\", \n \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \n \"long\", \"long\", \"short\", \"short\", \"short\", \"short\", \"short\", \n \"short\", \"short\", \"short\", \"short\", \"short\", \"long\", \"long\", \n \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \n \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \n \"long\", \"short\", \"short\", \"short\", \"short\", \"short\", \"short\", \n \"short\", \"short\", \"short\", \"short\"), seeds_total = c(100L, 84L, \n 69L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 71L, \n 100L, 100L, 100L, 100L, 100L, 100L, 56L, 100L, 100L, 100L, 100L, \n 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, \n 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, \n 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, \n 100L, 100L), seeds_beetle_damaged = c(59L, 7L, 30L, 22L, 36L, \n 15L, 8L, 10L, 10L, 2L, 25L, 6L, 0L, 24L, 21L, 10L, 13L, 10L, \n 14L, 0L, 13L, 19L, 18L, 15L, 28L, 7L, 3L, 11L, 0L, 2L, 15L, 9L, \n 11L, 24L, 44L, 0L, 0L, 0L, 5L, 9L, 8L, 3L, 2L, 3L, 3L, 9L, 0L, \n 8L, 3L, 6L, 2L, 5L, 5L, 4L, 9L, 4L, 7L, 0L, 6L), prop_beetle_damaged = c(0.59, \n 0.0833333333333333, 0.434782608695652, 0.22, 0.36, 0.15, 0.08, \n 0.1, 0.1, 0.02, 0.25, 0.06, 0, 0.24, 0.21, 0.1, 0.13, 0.1, 0.14, \n 0, 0.13, 0.19, 0.18, 0.15, 0.28, 0.07, 0.03, 0.11, 0, 0.02, 0.15, \n 0.09, 0.11, 0.24, 0.44, 0, 0, 0, 0.05, 0.09, 0.08, 0.03, 0.02, \n 0.03, 0.03, 0.09, 0, 0.08, 0.03, 0.06, 0.02, 0.05, 0.05, 0.04, \n 0.09, 0.04, 0.07, 0, 0.06)), row.names = c(NA, 59L), class = \"data.frame\")\n\n\n\n\n\n\n1. Binomial GLMM\n\n\n\n\nI first ran a binomial model with the glmmtmb package in R. My y variable was modeled as a binomial outcome that represented the number of beetle damaged seeds per plot. My fixed effects were plant_trait_a and plant_trait_b and I set planting_block as a random effect.\n\n\n\n\nUsing the DHARMa package I checked the residuals plots then tested for overdispersion and zero-inflation. I found that there was significant overdispersion (dispersion = 1.9633, p-value < 2.2e-16) and zero-inflation (ratioObsSim = 8.2305, p-value < 2.2e-16).\n\n\n\n\nlibrary(tidyverse)\nlibrary(glmmTMB)\nlibrary(DHARMa)\n\nset.seed(42)\nbeetle<-glmmTMB(cbind(seeds_beetle_damaged, seeds_total-seeds_beetle_damaged) ~ plant_trait_a*plant_trait_b + (1|planting_block),\n family=binomial, data=seeddamage)\nsummary(beetle)\n#AIC BIC logLik -2*log(L) df.resid \n# 566.2 576.6 -278.1 556.2 54 \n\nresidbeetle<-simulateResiduals(fittedModel=beetle)\nplot(residbeetle)\n#left plot or QQ plot residuals was S shaped\n#right plot looked ok: Levene test for homogeneity of variance was n.s. and within group deviation from uniformity was n.s.\n\n#check dispersion and zero inflation\ntestDispersion(residbeetle) \n#dispersion = 1.9633, p-value < 2.2e-16, significant overdispersion\n#see plot, red line is far to the right of predicted values\n\ntestZeroInflation(residbeetle)\n#ratioObsSim = 8.2305, p-value < 2.2e-16, significant zero inflation\n\n\n\n\n\n\n2. Zero-inflated beta binomial\n\n\n\n\nNext I ran a zero-inflated beta binomial model using the same fixed and random effects. I read online that the beta binomial distribution can address overdispersion in binomial models. Compared to the binomial model, the left side residuals plot (QQ plot) looked better - no longer S-shaped, data points were closer to red diagonal line. The p-value from the dispersion test was nonsignificant (dispersion = 1.3461, p-value = 0.096).\n\n\n\n\nbeetle2<-glmmTMB(cbind(seeds_beetle_damaged, seeds_total-seeds_beetle_damaged) ~ plant_trait_a*plant_trait_b + (1|planting_block),\n family=betabinomial, ziformula = ~ 1, data=seeddamage)\nsummary(beetle2)\n# AIC BIC logLik -2*log(L) df.resid \n# 391.6 406.1 -188.8 377.6 52 \n\nresidbeetle2<-simulateResiduals(fittedModel=beetle2)\nplot(residbeetle2)\n#both residuals plots look good\n\n#check dispersion and zero inflation\ntestDispersion(residbeetle2) # Tests for over/underdispersion\n#dispersion = 1.3461, p-value = 0.096\n\n\n\n\n\n\n3.Zero-inflated beta\n\n\n\n\nI shared the results from the zero-inflated beta binomal model with a stats consultant at my university who uses SAS and has mostly worked with binomial GLMs. He said he's only seen one textbook mention the beta binomial distribution, and that since it's not as common as other distributions he is skeptical of the results.\n\n\n\n\nSo I decided to try running a model with a zero-inflated beta distribution. This seems somewhat more common than the beta binomial. I used the same fixed and random effects, but the y variable was changed to the proportion of beetle damaged seeds per sample (prop_beetle_damaged). The residuals plots looked good and the dispersion value was nonsignificant (dispersion = 1.3836, p-value = 0.056)\n\n\n\n\nbeetle3<-glmmTMB(prop_beetle_damaged ~ plant_trait_a*plant_trait_b + (1|planting_block),\n family=beta_family(), ziformula = ~ 1, data=seeddamage)\nsummary(beetle3)\n# AIC BIC logLik -2*log(L) df.resid \n# -75.6 -61.1 44.8 -89.6 52 \n\nresidbeetle3<-simulateResiduals(fittedModel=beetle3)\nplot(residbeetle3)\n#residuals plots look good\n\n#check dispersion and zero inflation\ntestDispersion(residbeetle3) # Tests for over/underdispersion\n#dispersion = 1.3836, p-value = 0.056\n\n\n\n\n\n\nWhich model seems most appropriate for my data? I've read that when deciding between models with different distributions, the one with the lowest AIC value is the best fit. So should I go with the zero-inflated beta model?", "record_id": "Scientific-Statistics-QA:stats:677298", "selected_answer": {"answer_html": "

I think a non Z-I beta-binomial looks perfectly adequate, and I personally would push back against your stats consultant — in particular, the Beta distribution (which assumes a continuous distribution of outcomes between 0 and 1) is the wrong direction to go with data that have a known integer denominator (total number of seeds in your case). (That said, with a large denominator the binomial variance decreases and the differences between binomial and beta-binomial become less important.) I hope to come back and post a more complete answer later ...

\n", "answer_id": 677305, "answer_text": "I think a non Z-I beta-binomial looks perfectly adequate, and I personally would push back against your stats consultant — in particular, the Beta distribution (which assumes a continuous distribution of outcomes between 0 and 1) is the wrong direction to go with data that have a known integer denominator (total number of seeds in your case). (That said, with a large denominator the binomial variance decreases and the differences between binomial and beta-binomial become less important.) I hope to come back and post a more complete answer later ...", "answer_url": "https://stats.stackexchange.com/a/677305", "author": "Ben Bolker", "author_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-30T16:30:37+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": 677298, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-09-30T16:30:37+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "AD4B46E9-D946-4A17-BABC-04F3EE32D07E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD4B46E9-D946-4A17-BABC-04F3EE32D07E/view-source"}], "score": 1, "updated_at": "2026-09-30T16:30:37+00:00"}, "selection_rule": "accepted; otherwise maximum score >= 1, tie lowest ID; no correctness label", "split": "train", "thread": {"accepted_answer_id": null, "answers": [{"answer_html": "

I think a non Z-I beta-binomial looks perfectly adequate, and I personally would push back against your stats consultant — in particular, the Beta distribution (which assumes a continuous distribution of outcomes between 0 and 1) is the wrong direction to go with data that have a known integer denominator (total number of seeds in your case). (That said, with a large denominator the binomial variance decreases and the differences between binomial and beta-binomial become less important.) I hope to come back and post a more complete answer later ...

\n", "answer_id": 677305, "answer_text": "I think a non Z-I beta-binomial looks perfectly adequate, and I personally would push back against your stats consultant — in particular, the Beta distribution (which assumes a continuous distribution of outcomes between 0 and 1) is the wrong direction to go with data that have a known integer denominator (total number of seeds in your case). (That said, with a large denominator the binomial variance decreases and the differences between binomial and beta-binomial become less important.) I hope to come back and post a more complete answer later ...", "answer_url": "https://stats.stackexchange.com/a/677305", "author": "Ben Bolker", "author_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "author_user_type": "registered", "content_license": "CC BY-SA 4.0", "created_at": "2026-09-30T16:30:37+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": 677298, "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "Ben Bolker", "profile_url": "https://stats.stackexchange.com/users/2126/ben-bolker", "user_type": "registered"}, "created_at": "2026-09-30T16:30:37+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "AD4B46E9-D946-4A17-BABC-04F3EE32D07E", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/AD4B46E9-D946-4A17-BABC-04F3EE32D07E/view-source"}], "score": 1, "updated_at": "2026-09-30T16:30:37+00:00"}], "domain": "statistics", "external_links": [], "medical_sensitive": true, "patient_specific": false, "provenance": {"attribution_required": true, "collected_at": "2026-10-01T03:27:03.428408+00:00", "license": "CC BY-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-sa/4.0/", "raw_file": "raw/codex_api_v1/774052c18cd9e8fa951e893347bfa3c1a85e743fc46ec4667572002cadb10cbf_1790825224163423600_0.json", "raw_sha256": "fe4dd06d3de6c0b1bb33ba88aee0ed4284118e01f76a58dcdce220a4946329b2", "source_api": "Stack Exchange API 2.3", "source_url": "https://api.stackexchange.com/2.3/search/advanced?answers=1&filter=withbody&order=desc&page=1&pagesize=100&site=stats&sort=creation", "transformation": "API HTML retained; mechanical HTML-to-text; no LLM rewriting"}, "question_author": "glew", "question_author_url": "https://stats.stackexchange.com/users/517245/glew", "question_author_user_type": "registered", "question_created_at": "2026-09-29T20:13:50+00:00", "question_html": "

I'm trying to decide which GLMM distribution is best for my data.

\n

I want to determine how plant_trait_a and plant_trait_b affect beetle seed damage.

\n

There were two levels of plant_trait_a and two levels of plant_trait_b that made up 4 treatment groups. We selected 20 plant_genotypes for our field experiment, each treatment group had 5. Each plant genotype was planted 3 times, in 3 different planting_blocks.

\n

We collected 56-100 seeds per plot (plot=planting_blockxplant_genotype combination); most had 100 seeds, but 4 plots had less than 100 seeds available. I then counted the number of beetle damaged seeds (seeds_beetle_damaged) in each sample.

\n
#preview of seeddamage\n   year planting_block plant_genotype plant_trait_a plant_trait_b seeds_total seeds_beetle_damaged prop_beetle_damaged\n1  2024              1              1           yes         short         100                   59          0.59000000\n2  2024              1              2           yes         short          84                    7          0.08333333\n3  2024              1              3           yes         short          69                   30          0.43478261\n4  2024              1              4           yes         short         100                   22          0.22000000\n5  2024              1              5           yes         short         100                   36          0.36000000\n6  2024              1              6            no         short         100                   15          0.15000000\n7  2024              1              7            no         short         100                    8          0.08000000\n8  2024              1              8            no         short         100                   10          0.10000000\n9  2024              1              9            no         short         100                   10          0.10000000\n10 2024              1             10            no         short         100                    2          0.02000000\n\n\nseeddamage<-structure(list(year = c(2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n                                    2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n                                    2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n                                    2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n                                    2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2025L, 2025L, \n                                    2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, \n                                    2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L), planting_block = c(1L, \n                                                                                                                1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, \n                                                                                                                1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, \n                                                                                                                2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, \n                                                                                                                3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), plant_genotype = c(1L, \n                                                                                                                                                                            2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, \n                                                                                                                                                                            16L, 17L, 18L, 19L, 20L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, \n                                                                                                                                                                            10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 16L, 17L, \n                                                                                                                                                                            18L, 19L, 20L, 11L, 12L, 14L, 15L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, \n                                                                                                                                                                            3L, 4L, 5L), plant_trait_a = c("yes", "yes", "yes", "yes", "yes", \n                                                                                                                                                                                                           "no", "no", "no", "no", "no", "yes", "yes", "yes", "yes", "yes", \n                                                                                                                                                                                                           "no", "no", "no", "no", "no", "yes", "yes", "yes", "yes", "yes", \n                                                                                                                                                                                                           "no", "no", "no", "no", "no", "yes", "yes", "yes", "yes", "yes", \n                                                                                                                                                                                                           "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "yes", \n                                                                                                                                                                                                           "yes", "yes", "yes", "no", "no", "no", "no", "no", "yes", "yes", \n                                                                                                                                                                                                           "yes", "yes", "yes"), plant_trait_b = c("short", "short", "short", \n                                                                                                                                                                                                                                                   "short", "short", "short", "short", "short", "short", "short", \n                                                                                                                                                                                                                                                   "long", "long", "long", "long", "long", "long", "long", "long", \n                                                                                                                                                                                                                                                   "long", "long", "short", "short", "short", "short", "short", \n                                                                                                                                                                                                                                                   "short", "short", "short", "short", "short", "long", "long", \n                                                                                                                                                                                                                                                   "long", "long", "long", "long", "long", "long", "long", "long", \n                                                                                                                                                                                                                                                   "long", "long", "long", "long", "long", "long", "long", "long", \n                                                                                                                                                                                                                                                   "long", "short", "short", "short", "short", "short", "short", \n                                                                                                                                                                                                                                                   "short", "short", "short", "short"), seeds_total = c(100L, 84L, \n                                                                                                                                                                                                                                                                                                        69L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 71L, \n                                                                                                                                                                                                                                                                                                        100L, 100L, 100L, 100L, 100L, 100L, 56L, 100L, 100L, 100L, 100L, \n                                                                                                                                                                                                                                                                                                        100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, \n                                                                                                                                                                                                                                                                                                        100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, \n                                                                                                                                                                                                                                                                                                        100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, \n                                                                                                                                                                                                                                                                                                        100L, 100L), seeds_beetle_damaged = c(59L, 7L, 30L, 22L, 36L, \n                                                                                                                                                                                                                                                                                                                                              15L, 8L, 10L, 10L, 2L, 25L, 6L, 0L, 24L, 21L, 10L, 13L, 10L, \n                                                                                                                                                                                                                                                                                                                                              14L, 0L, 13L, 19L, 18L, 15L, 28L, 7L, 3L, 11L, 0L, 2L, 15L, 9L, \n                                                                                                                                                                                                                                                                                                                                              11L, 24L, 44L, 0L, 0L, 0L, 5L, 9L, 8L, 3L, 2L, 3L, 3L, 9L, 0L, \n                                                                                                                                                                                                                                                                                                                                              8L, 3L, 6L, 2L, 5L, 5L, 4L, 9L, 4L, 7L, 0L, 6L), prop_beetle_damaged = c(0.59, \n                                                                                                                                                                                                                                                                                                                                                                                                                       0.0833333333333333, 0.434782608695652, 0.22, 0.36, 0.15, 0.08, \n                                                                                                                                                                                                                                                                                                                                                                                                                       0.1, 0.1, 0.02, 0.25, 0.06, 0, 0.24, 0.21, 0.1, 0.13, 0.1, 0.14, \n                                                                                                                                                                                                                                                                                                                                                                                                                       0, 0.13, 0.19, 0.18, 0.15, 0.28, 0.07, 0.03, 0.11, 0, 0.02, 0.15, \n                                                                                                                                                                                                                                                                                                                                                                                                                       0.09, 0.11, 0.24, 0.44, 0, 0, 0, 0.05, 0.09, 0.08, 0.03, 0.02, \n                                                                                                                                                                                                                                                                                                                                                                                                                       0.03, 0.03, 0.09, 0, 0.08, 0.03, 0.06, 0.02, 0.05, 0.05, 0.04, \n                                                                                                                                                                                                                                                                                                                                                                                                                       0.09, 0.04, 0.07, 0, 0.06)), row.names = c(NA, 59L), class = "data.frame")\n\n
\n

1. Binomial GLMM

\n

I first ran a binomial model with the glmmtmb package in R. My y variable was modeled as a binomial outcome that represented the number of beetle damaged seeds per plot. My fixed effects were plant_trait_a and plant_trait_b and I set planting_block as a random effect.

\n

Using the DHARMa package I checked the residuals plots then tested for overdispersion and zero-inflation. I found that there was significant overdispersion (dispersion = 1.9633, p-value < 2.2e-16) and zero-inflation (ratioObsSim = 8.2305, p-value < 2.2e-16).

\n
library(tidyverse)\nlibrary(glmmTMB)\nlibrary(DHARMa)\n\nset.seed(42)\nbeetle<-glmmTMB(cbind(seeds_beetle_damaged, seeds_total-seeds_beetle_damaged) ~ plant_trait_a*plant_trait_b + (1|planting_block),\n                family=binomial, data=seeddamage)\nsummary(beetle)\n#AIC       BIC    logLik -2*log(L)  df.resid \n#    566.2     576.6    -278.1     556.2        54 \n\nresidbeetle<-simulateResiduals(fittedModel=beetle)\nplot(residbeetle)\n#left plot or QQ plot residuals was S shaped\n#right plot looked ok: Levene test for homogeneity of variance was n.s. and within group deviation from uniformity was n.s.\n\n#check dispersion and zero inflation\ntestDispersion(residbeetle) \n#dispersion = 1.9633, p-value < 2.2e-16, significant overdispersion\n#see plot, red line is far to the right of predicted values\n\ntestZeroInflation(residbeetle)\n#ratioObsSim = 8.2305, p-value < 2.2e-16, significant zero inflation\n\n
\n

2. Zero-inflated beta binomial

\n

Next I ran a zero-inflated beta binomial model using the same fixed and random effects. I read online that the beta binomial distribution can address overdispersion in binomial models. Compared to the binomial model, the left side residuals plot (QQ plot) looked better - no longer S-shaped, data points were closer to red diagonal line. The p-value from the dispersion test was nonsignificant (dispersion = 1.3461, p-value = 0.096).

\n
beetle2<-glmmTMB(cbind(seeds_beetle_damaged, seeds_total-seeds_beetle_damaged) ~ plant_trait_a*plant_trait_b + (1|planting_block),\n                 family=betabinomial, ziformula = ~ 1, data=seeddamage)\nsummary(beetle2)\n# AIC       BIC    logLik -2*log(L)  df.resid \n#    391.6     406.1    -188.8     377.6        52 \n\nresidbeetle2<-simulateResiduals(fittedModel=beetle2)\nplot(residbeetle2)\n#both residuals plots look good\n\n#check dispersion and zero inflation\ntestDispersion(residbeetle2)  # Tests for over/underdispersion\n#dispersion = 1.3461, p-value = 0.096\n\n
\n

3.Zero-inflated beta

\n

I shared the results from the zero-inflated beta binomal model with a stats consultant at my university who uses SAS and has mostly worked with binomial GLMs. He said he's only seen one textbook mention the beta binomial distribution, and that since it's not as common as other distributions he is skeptical of the results.

\n

So I decided to try running a model with a zero-inflated beta distribution. This seems somewhat more common than the beta binomial. I used the same fixed and random effects, but the y variable was changed to the proportion of beetle damaged seeds per sample (prop_beetle_damaged). The residuals plots looked good and the dispersion value was nonsignificant (dispersion = 1.3836, p-value = 0.056)

\n
beetle3<-glmmTMB(prop_beetle_damaged ~ plant_trait_a*plant_trait_b + (1|planting_block),\n                 family=beta_family(), ziformula = ~ 1, data=seeddamage)\nsummary(beetle3)\n# AIC       BIC    logLik -2*log(L)  df.resid \n#    -75.6     -61.1      44.8     -89.6        52 \n\nresidbeetle3<-simulateResiduals(fittedModel=beetle3)\nplot(residbeetle3)\n#residuals plots look good\n\n#check dispersion and zero inflation\ntestDispersion(residbeetle3)  # Tests for over/underdispersion\n#dispersion = 1.3836, p-value = 0.056\n\n
\n

Which model seems most appropriate for my data? I've read that when deciding between models with different distributions, the one with the lowest AIC value is the best fit. So should I go with the zero-inflated beta model?

\n", "question_id": 677298, "question_license": "CC BY-SA 4.0", "question_score": 0, "question_text": "I'm trying to decide which GLMM distribution is best for my data.\n\n\n\n\nI want to determine how plant_trait_a and plant_trait_b affect beetle seed damage.\n\n\n\n\nThere were two levels of plant_trait_a and two levels of plant_trait_b that made up 4 treatment groups. We selected 20 plant_genotypes for our field experiment, each treatment group had 5. Each plant genotype was planted 3 times, in 3 different planting_blocks.\n\n\n\n\nWe collected 56-100 seeds per plot (plot=planting_blockxplant_genotype combination); most had 100 seeds, but 4 plots had less than 100 seeds available. I then counted the number of beetle damaged seeds (seeds_beetle_damaged) in each sample.\n\n\n\n\n#preview of seeddamage\n year planting_block plant_genotype plant_trait_a plant_trait_b seeds_total seeds_beetle_damaged prop_beetle_damaged\n1 2024 1 1 yes short 100 59 0.59000000\n2 2024 1 2 yes short 84 7 0.08333333\n3 2024 1 3 yes short 69 30 0.43478261\n4 2024 1 4 yes short 100 22 0.22000000\n5 2024 1 5 yes short 100 36 0.36000000\n6 2024 1 6 no short 100 15 0.15000000\n7 2024 1 7 no short 100 8 0.08000000\n8 2024 1 8 no short 100 10 0.10000000\n9 2024 1 9 no short 100 10 0.10000000\n10 2024 1 10 no short 100 2 0.02000000\n\n\nseeddamage<-structure(list(year = c(2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, \n 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2024L, 2025L, 2025L, \n 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, \n 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L, 2025L), planting_block = c(1L, \n 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, \n 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, \n 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, \n 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), plant_genotype = c(1L, \n 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, \n 16L, 17L, 18L, 19L, 20L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, \n 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 16L, 17L, \n 18L, 19L, 20L, 11L, 12L, 14L, 15L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, \n 3L, 4L, 5L), plant_trait_a = c(\"yes\", \"yes\", \"yes\", \"yes\", \"yes\", \n \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \"yes\", \"yes\", \"yes\", \"yes\", \n \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \"yes\", \"yes\", \"yes\", \"yes\", \n \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \"yes\", \"yes\", \"yes\", \"yes\", \n \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \n \"yes\", \"yes\", \"yes\", \"no\", \"no\", \"no\", \"no\", \"no\", \"yes\", \"yes\", \n \"yes\", \"yes\", \"yes\"), plant_trait_b = c(\"short\", \"short\", \"short\", \n \"short\", \"short\", \"short\", \"short\", \"short\", \"short\", \"short\", \n \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \n \"long\", \"long\", \"short\", \"short\", \"short\", \"short\", \"short\", \n \"short\", \"short\", \"short\", \"short\", \"short\", \"long\", \"long\", \n \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \n \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \"long\", \n \"long\", \"short\", \"short\", \"short\", \"short\", \"short\", \"short\", \n \"short\", \"short\", \"short\", \"short\"), seeds_total = c(100L, 84L, \n 69L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 71L, \n 100L, 100L, 100L, 100L, 100L, 100L, 56L, 100L, 100L, 100L, 100L, \n 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, \n 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, \n 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, \n 100L, 100L), seeds_beetle_damaged = c(59L, 7L, 30L, 22L, 36L, \n 15L, 8L, 10L, 10L, 2L, 25L, 6L, 0L, 24L, 21L, 10L, 13L, 10L, \n 14L, 0L, 13L, 19L, 18L, 15L, 28L, 7L, 3L, 11L, 0L, 2L, 15L, 9L, \n 11L, 24L, 44L, 0L, 0L, 0L, 5L, 9L, 8L, 3L, 2L, 3L, 3L, 9L, 0L, \n 8L, 3L, 6L, 2L, 5L, 5L, 4L, 9L, 4L, 7L, 0L, 6L), prop_beetle_damaged = c(0.59, \n 0.0833333333333333, 0.434782608695652, 0.22, 0.36, 0.15, 0.08, \n 0.1, 0.1, 0.02, 0.25, 0.06, 0, 0.24, 0.21, 0.1, 0.13, 0.1, 0.14, \n 0, 0.13, 0.19, 0.18, 0.15, 0.28, 0.07, 0.03, 0.11, 0, 0.02, 0.15, \n 0.09, 0.11, 0.24, 0.44, 0, 0, 0, 0.05, 0.09, 0.08, 0.03, 0.02, \n 0.03, 0.03, 0.09, 0, 0.08, 0.03, 0.06, 0.02, 0.05, 0.05, 0.04, \n 0.09, 0.04, 0.07, 0, 0.06)), row.names = c(NA, 59L), class = \"data.frame\")\n\n\n\n\n\n\n1. Binomial GLMM\n\n\n\n\nI first ran a binomial model with the glmmtmb package in R. My y variable was modeled as a binomial outcome that represented the number of beetle damaged seeds per plot. My fixed effects were plant_trait_a and plant_trait_b and I set planting_block as a random effect.\n\n\n\n\nUsing the DHARMa package I checked the residuals plots then tested for overdispersion and zero-inflation. I found that there was significant overdispersion (dispersion = 1.9633, p-value < 2.2e-16) and zero-inflation (ratioObsSim = 8.2305, p-value < 2.2e-16).\n\n\n\n\nlibrary(tidyverse)\nlibrary(glmmTMB)\nlibrary(DHARMa)\n\nset.seed(42)\nbeetle<-glmmTMB(cbind(seeds_beetle_damaged, seeds_total-seeds_beetle_damaged) ~ plant_trait_a*plant_trait_b + (1|planting_block),\n family=binomial, data=seeddamage)\nsummary(beetle)\n#AIC BIC logLik -2*log(L) df.resid \n# 566.2 576.6 -278.1 556.2 54 \n\nresidbeetle<-simulateResiduals(fittedModel=beetle)\nplot(residbeetle)\n#left plot or QQ plot residuals was S shaped\n#right plot looked ok: Levene test for homogeneity of variance was n.s. and within group deviation from uniformity was n.s.\n\n#check dispersion and zero inflation\ntestDispersion(residbeetle) \n#dispersion = 1.9633, p-value < 2.2e-16, significant overdispersion\n#see plot, red line is far to the right of predicted values\n\ntestZeroInflation(residbeetle)\n#ratioObsSim = 8.2305, p-value < 2.2e-16, significant zero inflation\n\n\n\n\n\n\n2. Zero-inflated beta binomial\n\n\n\n\nNext I ran a zero-inflated beta binomial model using the same fixed and random effects. I read online that the beta binomial distribution can address overdispersion in binomial models. Compared to the binomial model, the left side residuals plot (QQ plot) looked better - no longer S-shaped, data points were closer to red diagonal line. The p-value from the dispersion test was nonsignificant (dispersion = 1.3461, p-value = 0.096).\n\n\n\n\nbeetle2<-glmmTMB(cbind(seeds_beetle_damaged, seeds_total-seeds_beetle_damaged) ~ plant_trait_a*plant_trait_b + (1|planting_block),\n family=betabinomial, ziformula = ~ 1, data=seeddamage)\nsummary(beetle2)\n# AIC BIC logLik -2*log(L) df.resid \n# 391.6 406.1 -188.8 377.6 52 \n\nresidbeetle2<-simulateResiduals(fittedModel=beetle2)\nplot(residbeetle2)\n#both residuals plots look good\n\n#check dispersion and zero inflation\ntestDispersion(residbeetle2) # Tests for over/underdispersion\n#dispersion = 1.3461, p-value = 0.096\n\n\n\n\n\n\n3.Zero-inflated beta\n\n\n\n\nI shared the results from the zero-inflated beta binomal model with a stats consultant at my university who uses SAS and has mostly worked with binomial GLMs. He said he's only seen one textbook mention the beta binomial distribution, and that since it's not as common as other distributions he is skeptical of the results.\n\n\n\n\nSo I decided to try running a model with a zero-inflated beta distribution. This seems somewhat more common than the beta binomial. I used the same fixed and random effects, but the y variable was changed to the proportion of beetle damaged seeds per sample (prop_beetle_damaged). The residuals plots looked good and the dispersion value was nonsignificant (dispersion = 1.3836, p-value = 0.056)\n\n\n\n\nbeetle3<-glmmTMB(prop_beetle_damaged ~ plant_trait_a*plant_trait_b + (1|planting_block),\n family=beta_family(), ziformula = ~ 1, data=seeddamage)\nsummary(beetle3)\n# AIC BIC logLik -2*log(L) df.resid \n# -75.6 -61.1 44.8 -89.6 52 \n\nresidbeetle3<-simulateResiduals(fittedModel=beetle3)\nplot(residbeetle3)\n#residuals plots look good\n\n#check dispersion and zero inflation\ntestDispersion(residbeetle3) # Tests for over/underdispersion\n#dispersion = 1.3836, p-value = 0.056\n\n\n\n\n\n\nWhich model seems most appropriate for my data? I've read that when deciding between models with different distributions, the one with the lowest AIC value is the best fit. So should I go with the zero-inflated beta model?", "revision_attribution": [{"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "glew", "profile_url": "https://stats.stackexchange.com/users/517245/glew", "user_type": "registered"}, "created_at": "2026-09-29T20:13:50+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "D8B5E82E-0E38-4027-9C48-93E1F5E3D662", "revision_number": 1, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/D8B5E82E-0E38-4027-9C48-93E1F5E3D662/view-source"}, {"content_license": "CC BY-SA 4.0", "contributor": {"display_name": "glew", "profile_url": "https://stats.stackexchange.com/users/517245/glew", "user_type": "registered"}, "created_at": "2026-09-30T15:18:51+00:00", "raw_file": "raw/codex_api_v1/ab5f4cd7f0a10bde5970354a9b213efcc81e232042487437e8579705d4ca6a20_1790825258916612700_0.json", "raw_sha256": "4cf167c399d03b9ae013b65260fcb4e38139c42cfc70aba4807f070550c1768e", "revision_guid": "C946D7BE-B64A-4585-AC40-0C1885066383", "revision_number": 2, "revision_type": "single_user", "revision_url": "https://stats.stackexchange.com/revisions/C946D7BE-B64A-4585-AC40-0C1885066383/view-source"}], "source_site": "stats", "source_url": "https://stats.stackexchange.com/questions/677298/need-help-deciding-what-zero-inflated-glmm-to-use-beta-binomial-or-beta-binom", "split": "train", "split_group": "3123c426022f04d2481edd65d05980cf35eac64127fe7532f97efe75c659bca6", "tags": ["binomial-distribution", "glmm", "beta-distribution", "glmmtmb", "beta-binomial-distribution"], "thread_id": "stats:677298", "title": "Need help deciding what zero-inflated GLMM to use: beta, binomial, or beta binomial"}}