Open
Conversation
Observations with zero weights have to be skipped for probability and analytic weights. Values have been checked against R. Avoid duplication by using a single method for all `LinPredModel`s (though this means we cannot call `nobs` from functions which don't get passed the full model). Also fix name of internal function `link`, which actually returns the distribution.
nalimilan
commented
Jan 11, 2026
| @test dof_residual(lmod) == dof_residual(glmod) == sum(!iszero, wts) - 2 | ||
| @test deviance(lmod) ≈ deviance(glmod) ≈ 24.500813008130084 | ||
| @test coef(lmod) ≈ coef(glmod) ≈ [3.6707317073170724, 0.20731707317073195] | ||
| @test stderror(lmod) ≈ stderror(glmod) ≈ [1.7617126628715203, 0.23455696986842048] |
Member
Author
There was a problem hiding this comment.
@gragusa I get slightly different standard errors with svyglm. Is this expected? Generally in my tests I got exactly the same values up to a least four decimals.
> X = 1:10
> y = c(1, 4, 6, 2, 3, 5, 6, 7, 1, 6)
> wts = c(1, 0, 4, 0, 5, 2, 6, 4, 2, 6)
> svyd <- svydesign(~1, weights=wts, data=data.frame(X=X, y=y, wts=wts))
> summary(svyglm(y ~ X, svyd))
Call:
svyglm(formula = y ~ X, design = svyd)
Survey design:
svydesign(~1, weights = wts, data = data.frame(X = X, y = y,
wts = wts))
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.6707 1.7371 2.113 0.079 .
X 0.2073 0.2313 0.896 0.405
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for gaussian family taken to be 3.500116)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #638 +/- ##
==========================================
+ Coverage 96.94% 96.96% +0.01%
==========================================
Files 8 8
Lines 1213 1219 +6
==========================================
+ Hits 1176 1182 +6
Misses 37 37 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
devmotion
reviewed
Jan 11, 2026
src/glmfit.jl
Outdated
| wts = weights(r) | ||
| d = sum(r.devresid) | ||
| return wts isa ProbabilityWeights ? d * nobs(r) / sum(wts) : d | ||
| return wts isa ProbabilityWeights ? d * sum(!iszero, wts) / sum(wts) : d |
Member
There was a problem hiding this comment.
Isn't this change unnecessary since nobs is fixed below?
Suggested change
| return wts isa ProbabilityWeights ? d * sum(!iszero, wts) / sum(wts) : d | |
| return wts isa ProbabilityWeights ? d * nobs(r) / sum(wts) : d |
Member
Author
There was a problem hiding this comment.
That was because I defined the method only on LinPredModel and not on the response object. But I've discovered that we have ModResp that covers both LMs and GLMs so I've changed the method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Observations with zero weights have to be skipped for probability and analytic weights. Values have been checked against R. Avoid duplication by using a single method for all
LinPredModels (though this means we cannot callnobsfrom functions which don't get passed the full model).Also fix name of internal function
link, which actually returns the distribution.Improves on #487. Cc: @gragusa