Skip to content

Commit

Permalink
Fix bug in model_response. Need to to call eltype on data columns
Browse files Browse the repository at this point in the history
and not the symbol representing it.
  • Loading branch information
andreasnoack committed Jan 15, 2018
1 parent 8caee95 commit 058048d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/modelframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ Extract the response column, if present. `DataVector` or
"""
function StatsBase.model_response(mf::ModelFrame)
if mf.terms.response
T = Missings.T(eltype(mf.terms.eterms[1]))
convert(Array{T}, mf.df[mf.terms.eterms[1]])
_response = mf.df[mf.terms.eterms[1]]
T = Missings.T(eltype(_response))
convert(Array{T}, _response)
else
error("Model formula one-sided")
end
Expand Down
3 changes: 1 addition & 2 deletions test/modelmatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ x3 = [13.:16;]
x4 = [17.:20;]
f = @formula(y ~ x1 + x2)
mf = ModelFrame(f, d)
## @test mm.response_colnames == ["y"] # nope: no response_colnames
@test coefnames(mf) == ["(Intercept)","x1","x2"]
## @test model_response(mf) == transpose([1. 2 3 4]) # fails: Int64 vs. Float64
@test model_response(mf) == [1:4;]
mm = ModelMatrix(mf)
smm = ModelMatrix{sparsetype}(mf)
@test mm.m[:,1] == ones(4)
Expand Down

0 comments on commit 058048d

Please sign in to comment.