Skip to content

Rename wts to weights and allow passing variable name to it - #631

Merged
nalimilan merged 4 commits into
masterfrom
nl/weightsarg
Apr 21, 2026
Merged

nalimilan merged 4 commits into
masterfrom
nl/weightsarg

Conversation

@nalimilan

@nalimilan nalimilan commented Jan 3, 2026 •

Copy link
Copy Markdown
Member

This is particularly useful when some observations are dropped because of missing values. Also rename some internal arguments and variables.

Drop support for non-AbstractWeights (which was deprecated in 1.9.1) but continue printing a helpful error message.

Illustration:

julia> using StableRNGs, DataFrames, StatsBase, GLM

julia> data = DataFrame(y = rand(StableRNG(1), 100), x = randn(StableRNG(2), 100), weights = repeat([1, 2, 3, 4], 25));

julia> data.weights = aweights(data.weights);

julia> lm(@formula(y ~ x), data, weights=:weights)
LinearModel

y ~ 1 + x

Coefficients:
──────────────────────────────────────────────────────────────────────────
                  Coef.  Std. Error      t  Pr(>|t|)  Lower 95%  Upper 95%
──────────────────────────────────────────────────────────────────────────
(Intercept)   0.51673     0.0270707  19.09    <1e-34   0.463009  0.570451
x            -0.0478667   0.0308395  -1.55    0.1239  -0.109067  0.0133333
──────────────────────────────────────────────────────────────────────────

julia> # Case that is cumbersome to run without this PR

julia> data.x = allowmissing(data.x);

julia> data.x[1] = missing;

julia> lm(@formula(y ~ x), data, weights=:weights)
LinearModel

y ~ 1 + x

Coefficients:
──────────────────────────────────────────────────────────────────────────
                  Coef.  Std. Error      t  Pr(>|t|)  Lower 95%  Upper 95%
──────────────────────────────────────────────────────────────────────────
(Intercept)   0.516777    0.0272632  18.96    <1e-33   0.462667  0.570886
x            -0.0479698   0.0312247  -1.54    0.1277  -0.109942  0.0140026
──────────────────────────────────────────────────────────────────────────

Supersedes #570
Fixes #255
Fixes #350

Cc: @gragusa

This is particularly useful when some observations are dropped because
of missing values. Also rename some internal arguments and variables.

Drop support for non-`AbstractWeights` (which was deprecated in 1.9.1) but
continue printing a helpful error message.
@nalimilan
nalimilan requested a review from andreasnoack January 3, 2026 15:52
@nalimilan nalimilan added this to the Release 2.0 milestone Jan 3, 2026
@codecov

codecov Bot commented Jan 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.20%. Comparing base (ab7dea3) to head (848a41c).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #631      +/-   ##
==========================================
+ Coverage   96.95%   97.20%   +0.24%     
==========================================
  Files           8        8              
  Lines        1215     1216       +1     
==========================================
+ Hits         1178     1182       +4     
+ Misses         37       34       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andreasnoack

Copy link
Copy Markdown
Member

and allow passing variable name to it

It would be useful with an example of that here in the PR.

@nalimilan

Copy link
Copy Markdown
Member Author

Good idea. Done.

@andreasnoack

Copy link
Copy Markdown
Member

Did you add it as a test? I think it would be useful to see an example in the top post here.

@nalimilan

Copy link
Copy Markdown
Member Author

I put it in the manual. Is that what you mean?

@andreasnoack

Copy link
Copy Markdown
Member

It would make it easier to understand the PR is the top post included an example.

@nalimilan

Copy link
Copy Markdown
Member Author

Ah OK got it. I've added the example from the manual to the top post.

@nalimilan
nalimilan merged commit e1438c5 into master Apr 21, 2026
11 checks passed
@nalimilan
nalimilan deleted the nl/weightsarg branch April 21, 2026 15:37
@nalimilan

Copy link
Copy Markdown
Member Author

Thanks!

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.

Change wts keyword argument name to weights wts option doesn't automatically subset when a DataFrame has missing values

2 participants