Expand linear models modules across all chapters - #7
Conversation
There was a problem hiding this comment.
💡 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
| 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 β̂, κ |
There was a problem hiding this comment.
[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 👍 / 👎.
| diff = C * β̂ .- d | ||
| middle = C * (design.X' * design.X) \ C' | ||
| q = rank(C) | ||
| fstat = (diff' * (middle \ diff)) / q / mse |
There was a problem hiding this comment.
[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 👍 / 👎.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68d8c8bf56ac8321bad7704f1d7b05ec