Skip to content

Expand linear models modules across all chapters - #7

Open
meibujun wants to merge 1 commit into
masterfrom
codex/design-julia-code-for-linear-models
Open

Expand linear models modules across all chapters#7
meibujun wants to merge 1 commit into
masterfrom
codex/design-julia-code-for-linear-models

Conversation

@meibujun

Copy link
Copy Markdown
Owner

Summary

  • add dedicated Julia modules for diagnostics, model selection, prediction, variance components, Bayesian analysis, and computational strategies to mirror every chapter of the linear models notes
  • extend the top-level LinearModels loader and comprehensive example script to orchestrate workflows across all ten chapters with detailed Chinese commentary

Testing

  • not run (Julia executable unavailable in container)

https://chatgpt.com/codex/tasks/task_e_68d8c8bf56ac8321bad7704f1d7b05ec

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +37 to +45
function generalized_inverse_solution(X::AbstractMatrix{<:Real}, y::AbstractVector)
F = svd(X)
tol = maximum(size(X)) * eps() * maximum(F.S)
idx = F.S .> tol
Sinv = zeros(eltype(F.S), length(F.S))
Sinv[idx] .= 1 ./ F.S[idx]
β̂ = F.Vt' * Diagonal(Sinv) * F.U' * y
κ = isempty(F.S) ? 0.0 : maximum(F.S[idx]) / minimum(F.S[idx])
return β̂, κ

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P1] Guard generalized inverse against rank-zero matrices

The pseudoinverse fallback assumes at least one singular value exceeds the tolerance. When the design matrix is completely singular (all singular values ≤ tol), idx is empty and the calls to maximum(F.S[idx])/minimum(F.S[idx]) throw an error instead of returning the minimum-norm solution. This causes least_squares_estimator to fail precisely in the degenerate cases it was supposed to handle. Short-circuit the empty set before computing the condition number or return a zero vector with κ=Inf.

Useful? React with 👍 / 👎.

Comment on lines +40 to +43
diff = C * β̂ .- d
middle = C * (design.X' * design.X) \ C'
q = rank(C)
fstat = (diff' * (middle \ diff)) / q / mse

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P0] F-test builds constraint quadratic form with wrong operator precedence

The matrix for the quadratic form is defined as middle = C * (design.X' * design.X) \ C'. Because \ binds tighter than *, this evaluates as (C * (design.X' * design.X)) \ C', producing a DimensionMismatch for the common case size(C,1) ≠ size(C,2) and making the hypothesis test unusable. The intended quantity is C * ((design.X' * design.X) \ C') (i.e., C * (X'X)⁻¹ * C'). Parenthesize the solve or compute the inverse explicitly so rectangular constraint matrices work.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant