Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug-fix for respecting levels #91

Merged
merged 2 commits into from
Mar 26, 2019
Merged

Bug-fix for respecting levels #91

merged 2 commits into from
Mar 26, 2019

Conversation

Nosferican
Copy link
Contributor

@Nosferican Nosferican commented Mar 18, 2019

Allows contrasts to be aware of the order (especially important for ordinal features).

f = @formula(x ~ 1)
f = apply_schema(f, schema(data))
y = modelcols(f.lhs, data)
f = apply_schema(f, schema(data, Dict(:x => DummyCoding(levels = levels(data.x)))))
Copy link
Member

Choose a reason for hiding this comment

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

Passing levels here is redundant and defeats the point of using a categorical array, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is redundant now, but works as a test since it errors with current master. That is just to verify that it is working as if/intended.

Copy link
Member

Choose a reason for hiding this comment

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

OK but then below you need to check that y == modelcols(f.lhs, data) == somereference (or call @test y == somereference twice).

Copy link
Member

Choose a reason for hiding this comment

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

Ah, and also better pass levels in a different order from levels and from the order of appearance, to ensure it really has an effect.

Copy link
Member

Choose a reason for hiding this comment

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

And add an unused value to levels to check that it's dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is what it is doing, it is first computing the value and storing it as y and the I test the value against the reference which is modelcols(f.lhs, data) with the formula now been updated with an explicit order by contrasts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test for unused levels was already included in the modelmatrix.jl. I put a comment on that test that it also checks correctness against non-occurring levels.

Copy link
Member

Choose a reason for hiding this comment

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

That is what it is doing, it is first computing the value and storing it as y and the I test the value against the reference which is modelcols(f.lhs, data) with the formula now been updated with an explicit order by contrasts.

Yes but this doesn't test the fact that passing levels to DummyCoding has any effect. Better check against an explicit expected array.

# Ordinal factors

data = DataFrame(x = levels!(categorical(['A', 'B', 'C', 'C'],
ordered = true),
Copy link
Member

Choose a reason for hiding this comment

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

Better not set ordered=true, as the behavior should be the same for unordered arrays. Then also change "ordinal" to "categorical" above.

@codecov-io
Copy link

codecov-io commented Mar 18, 2019

Codecov Report

Merging #91 into master will decrease coverage by 0.49%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #91     +/-   ##
=========================================
- Coverage   84.98%   84.49%   -0.5%     
=========================================
  Files           8        8             
  Lines         453      458      +5     
=========================================
+ Hits          385      387      +2     
- Misses         68       71      +3
Impacted Files Coverage Δ
src/schema.jl 83.5% <100%> (ø) ⬆️
src/traits.jl 0% <0%> (ø) ⬆️
src/terms.jl 85.08% <0%> (+0.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2617e7f...1a80235. Read the comment docs.

@Nosferican
Copy link
Contributor Author

Let me know if there is anything else or if approved.

Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

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

Thanks!

@kleinschmidt
Copy link
Member

Thanks!

@kleinschmidt kleinschmidt merged commit b29558f into JuliaStats:master Mar 26, 2019
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.

4 participants