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

Error in Terms when no intercept is requested #574

Closed
andreasnoack opened this issue Apr 6, 2014 · 11 comments
Closed

Error in Terms when no intercept is requested #574

andreasnoack opened this issue Apr 6, 2014 · 11 comments

Comments

@andreasnoack
Copy link
Member

This does not work

df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"]);
ModelMatrix(ModelFrame(A~B-1, df))
ERROR: no method convert(Type{Expr}, Array{Any,1})
 in unshift! at array.jl:511
 in Terms at /Users/andreasnoackjensen/.julia/v0.3/DataFrames/src/formula/formula.jl:145
 in ModelFrame at /Users/andreasnoackjensen/.julia/v0.3/DataFrames/src/formula/formula.jl:174

but this does

julia> ModelMatrix(ModelFrame(A~B+(-1), df))
ModelMatrix{Float64}(4x1 Array{Float64,2}:
 1.0
 0.0
 0.0
 1.0,[1])
@ararslan
Copy link
Member

This has been fixed now, hasn't it?

@nalimilan
Copy link
Member

Still doesn't work AFAICT (even after converting B to a CategoricalArray).

@kleinschmidt
Copy link
Contributor

It's the -1 that's the issue I think. +0 should work (and have the same effect).

@nalimilan
Copy link
Member

But do we still want to support -1?

@ararslan
Copy link
Member

ararslan commented Oct 1, 2016

It might make more sense to have a single, consistent means of requesting no intercept, and IMO +0 is nicer than -1.

@kleinschmidt
Copy link
Contributor

I agree. And, in fact, we might go so far as to make no intercept the default, so you'd need to explicitly have +1 to add an intercept.

@ararslan
Copy link
Member

ararslan commented Oct 1, 2016

On the one hand, I like that because it requires being explicit (which is almost always a good thing) and will require people to think harder about the exact model they're fitting, but on the other hand I think it could be surprising for some people since implicit intercept is the default in R, SAS, and likely others as well. So... I'm undecided on that, but leaning toward +1 require +1.

@dmbates
Copy link
Contributor

dmbates commented Oct 1, 2016

I think that forcing the user to use an explicit +1 is a good idea. The fact that earlier languages made the intercept the default doesn't mean that the choice is appropriate now. Including 1 + in the formula is just a matter of typing a few characters. @StefanKarpinski has mentioned before that having 1 + x == x and 0 + x != x in the formula language looks like a wart.

@nalimilan
Copy link
Member

We've had that discuss in many different places already, but I'll restate my preferred solution: require people to either say 1 + or 0 +, else raise an error with an explanation. That's the only way to get rid of the implicit intercept without trapping people into fitting weird models.

@ararslan
Copy link
Member

ararslan commented Oct 2, 2016

+1 to Milan's proposal. And if we end up not doing that, +1 to Doug's.

@johnmyleswhite
Copy link
Contributor

Explicitness is good by me, so I like Milan's solution.

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

No branches or pull requests

6 participants