Skip to content

Rearrange linear regression sections#431

Merged
d-morrison merged 8 commits intomainfrom
copilot/rearrange-linear-regression-sections
Apr 10, 2026
Merged

Rearrange linear regression sections#431
d-morrison merged 8 commits intomainfrom
copilot/rearrange-linear-regression-sections

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

  • Move "Categorical covariates with more than two levels" and "Ordinal covariates" sections into "Understanding Gaussian Linear Regression Models"
  • Move "Goodness of Fit", "Diagnostics", and "Model Selection" under a new single parent section called "Assessing model fit"
  • Merge with main branch (which split Linear-models-overview.qmd into subfiles)
  • Resolve merge conflicts: reorganize using subfile structure from main
    • Updated Linear-models-overview.qmd to use {{< include >}} directives with the correct structure
    • Demoted headers in _sec_linreg_categorical.qmd, _sec_linreg_gof.qmd, _sec_linreg_diagnostics.qmd, _sec_linreg_model_selection.qmd, _sec_linreg_ordinal.qmd by one level
  • Move categorical/ordinal subsections from Linear-models-overview.qmd into _sec_linreg_understanding.qmd
  • Move Goodness of fit/Diagnostics/Model selection subsections from Linear-models-overview.qmd into new _sec_linreg_assess.qmd subfile
  • Fix CI failure: plot_PIs_and_CIs was defined in _sec_linreg_gof.qmd but used in _sec_linreg_prediction.qmd which now comes before gof in the section order. Moved definition to _sec_linreg_prediction.qmd.
  • Lint passes (only pre-existing issues)

Copilot AI linked an issue Apr 10, 2026 that may be closed by this pull request
…inal into Understanding LMs, group goodness of fit/diagnostics/model selection under Assessing model fit

Agent-Logs-Url: https://github.com/d-morrison/rme/sessions/2640c9c0-d0e3-4c08-a9e1-506e9f9ea53f

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copilot AI changed the title [WIP] Rearrange linear regression sections for improved clarity Rearrange linear regression sections Apr 10, 2026
Copilot AI requested a review from d-morrison April 10, 2026 09:21
@d-morrison
Copy link
Copy Markdown
Owner

@copilot resolve merge conflicts

…cture from main

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 10, 2026

@copilot resolve merge conflicts

Resolved in commit 2ebae7c. The main branch had split Linear-models-overview.qmd into subfiles (PR #434), so I merged those changes in and applied the reorganization to the new subfile structure:

  • Linear-models-overview.qmd now uses {{< include >}} directives with the correct section hierarchy
  • Headers in _sec_linreg_categorical.qmd, _sec_linreg_gof.qmd, _sec_linreg_diagnostics.qmd, _sec_linreg_model_selection.qmd, and _sec_linreg_ordinal.qmd were demoted by one level to fit their new nesting

Comment thread Linear-models-overview.qmd Outdated
Comment thread Linear-models-overview.qmd Outdated
…e _sec_linreg_assess.qmd for assessing model fit subsections

Agent-Logs-Url: https://github.com/d-morrison/rme/sessions/04f5a981-b328-4b54-b877-dd0c5e665850

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copilot AI requested a review from d-morrison April 10, 2026 20:05
@d-morrison
Copy link
Copy Markdown
Owner

…ction.qmd so it's defined before its first use

Agent-Logs-Url: https://github.com/d-morrison/rme/sessions/87923ea1-e789-445b-a0dc-37d8bb3247fe

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 10, 2026

@copilot fix https://github.com/d-morrison/rme/actions/runs/24261777610/job/70848709563?pr=431

Fixed in commit d62a233. The CI failure was caused by plot_PIs_and_CIs being defined in _sec_linreg_gof.qmd but called in _sec_linreg_prediction.qmd, which now comes before gof in the section ordering. Moved the function definition to _sec_linreg_prediction.qmd so it's defined before its first use in both prediction and gof.

@github-actions
Copy link
Copy Markdown
Contributor

PR Preview Action v1.8.1
🚀 Preview available at: https://d-morrison.github.io/rme/pr-preview/pr-431/

Built to branch gh-pages at 2026-04-10 21:07 UTC.

@d-morrison d-morrison marked this pull request as ready for review April 10, 2026 21:15
Copilot AI review requested due to automatic review settings April 10, 2026 21:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reorganizes the linear regression Quarto content to match the new subfile structure from main, grouping related material under more coherent parent sections and fixing an ordering issue with a shared plotting helper.

Changes:

  • Moves categorical/ordinal covariate material under “Understanding Gaussian Linear Regression Models”.
  • Creates a new “Assessing model fit” parent section to group goodness-of-fit, diagnostics, and model selection.
  • Relocates plot_PIs_and_CIs into the prediction section so it’s defined before later uses.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Linear-models-overview.qmd Replaces several top-level sections with a single “Assessing model fit” include to reflect the new structure.
_sec_linreg_understanding.qmd Adds includes for categorical and ordinal covariate subfiles under the “Understanding” section.
_sec_linreg_prediction.qmd Adds the plot_PIs_and_CIs helper earlier in the document to resolve ordering.
_sec_linreg_assess.qmd New subfile that groups GOF, diagnostics, and model selection under one parent section.
_sec_linreg_gof.qmd Demotes headings and removes the local plot_PIs_and_CIs definition after reorg.
_sec_linreg_diagnostics.qmd Demotes headings to fit under the new “Assessing model fit” hierarchy.
_sec_linreg_model_selection.qmd Demotes headings to fit under the new “Assessing model fit” hierarchy.
_sec_linreg_categorical.qmd Demotes headings to fit under the new “Understanding” hierarchy.
_sec_linreg_ordinal.qmd Demotes a callout header to fit under the new “Understanding” hierarchy.

Comment on lines +190 to +202
plot_PIs_and_CIs <- function(model, data) {
cis <- model |>
predict(interval = "confidence") |>
suppressWarnings() |>
tibble::as_tibble()
names(cis) <- paste("ci", names(cis), sep = "_")

preds <- model |>
predict(interval = "predict") |>
suppressWarnings() |>
tibble::as_tibble()
names(preds) <- paste("pred", names(preds), sep = "_")
dplyr::bind_cols(bw, cis, preds) |>
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plot_PIs_and_CIs() currently ignores its data argument and instead hard-codes bw in bind_cols(). This makes the function behave incorrectly for any dataset other than bw, and can also break if the model’s effective rows differ from bw (e.g., na.action), since predict() is called without newdata. Use the provided data argument consistently (including passing it as newdata to predict() and binding data, not bw), and consider allowing the function to work with the piped call style used later in the GOF section.

Suggested change
plot_PIs_and_CIs <- function(model, data) {
cis <- model |>
predict(interval = "confidence") |>
suppressWarnings() |>
tibble::as_tibble()
names(cis) <- paste("ci", names(cis), sep = "_")
preds <- model |>
predict(interval = "predict") |>
suppressWarnings() |>
tibble::as_tibble()
names(preds) <- paste("pred", names(preds), sep = "_")
dplyr::bind_cols(bw, cis, preds) |>
plot_PIs_and_CIs <- function(data, model = NULL) {
if (is.null(model)) {
rlang::abort("`model` must be supplied to `plot_PIs_and_CIs()`.")
}
if (!inherits(data, "data.frame") && inherits(model, "data.frame")) {
tmp <- data
data <- model
model <- tmp
}
cis <- model |>
predict(newdata = data, interval = "confidence") |>
suppressWarnings() |>
tibble::as_tibble()
names(cis) <- paste("ci", names(cis), sep = "_")
preds <- model |>
predict(newdata = data, interval = "predict") |>
suppressWarnings() |>
tibble::as_tibble()
names(preds) <- paste("pred", names(preds), sep = "_")
dplyr::bind_cols(data, cis, preds) |>

Copilot uses AI. Check for mistakes.
Comment thread _sec_linreg_gof.qmd
Comment on lines +194 to 197
### Null Deviance

Similarly, the *least* complicated model we could fit would have only one mean parameter, an intercept:

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this section, the later figure chunk (lm0 |> plot_PIs_and_CIs()) will fail if plot_PIs_and_CIs requires a data argument (as in its current definition). Update the call to pass the dataset explicitly (e.g., lm0 |> plot_PIs_and_CIs(bw)), or make the helper accept a default data value that works for the null-model plot.

Copilot uses AI. Check for mistakes.
If there are more than two observed values, we can't just use a single variable with 0s and 1s.

##
###
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an empty section header (### with no title). This will render as a blank heading and may add an empty entry to the table of contents / navigation. Replace it with a meaningful heading (or remove it if it’s only meant as spacing).

Suggested change
###
### Example: `iris`

Copilot uses AI. Check for mistakes.
@d-morrison d-morrison merged commit e47b4db into main Apr 10, 2026
7 of 8 checks passed
@d-morrison d-morrison deleted the copilot/rearrange-linear-regression-sections branch April 10, 2026 21:23
Copilot AI added a commit that referenced this pull request Apr 10, 2026
- Update plot_PIs_and_CIs() to use data argument consistently:
  - Change signature to (data, model = NULL)
  - Add null check for model
  - Add argument-swap guard for backward compatibility
  - Use newdata = data in predict() calls
  - Use data instead of hard-coded bw in bind_cols()
- Fix lm0 |> plot_PIs_and_CIs() call to pass bw explicitly
- Fix empty ### section header to ### Example: iris

Agent-Logs-Url: https://github.com/d-morrison/rme/sessions/e7bcda97-e3b1-42c7-beff-b66ce7e22140

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copilot AI mentioned this pull request Apr 10, 2026
4 tasks
d-morrison added a commit that referenced this pull request Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rearrange linear regression sections

3 participants