Skip to content

Commit

Permalink
Merge 7c19d1c into 3891ba6
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinschmidt committed Jul 18, 2019
2 parents 3891ba6 + 7c19d1c commit 82de335
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
@@ -1,6 +1,6 @@
name = "StatsModels"
uuid = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
version = "0.6.1"
version = "0.6.2"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
11 changes: 8 additions & 3 deletions src/modelframe.jl
Expand Up @@ -172,11 +172,16 @@ end

Base.size(mm::ModelMatrix, dim...) = size(mm.m, dim...)

asgn(f::FormulaTerm) = asgn(f.rhs)
asgn(mt::MatrixTerm) = asgn(mt.terms)
asgn(t) = mapreduce(((i,t), ) -> i*ones(width(t)),
append!,
enumerate(vectorize(t)),
init=Int[])

function ModelMatrix{T}(mf::ModelFrame) where T<:AbstractMatrix{<:AbstractFloat}
mat = modelmatrix(mf)
asgn = mapreduce((it)->first(it)*ones(width(last(it))), append!,
enumerate(vectorize(mf.f.rhs)), init=Int[])
ModelMatrix(convert(T, mat), asgn)
ModelMatrix(convert(T, mat), asgn(mf.f))
end

ModelMatrix(mf::ModelFrame) = ModelMatrix{Matrix{Float64}}(mf)
13 changes: 13 additions & 0 deletions test/modelframe.jl
@@ -0,0 +1,13 @@
@testset "ModelFrame (legacy API)" begin

@testset "#133" begin
df = (x = rand(12),
y = categorical(repeat(1:3, inner=4)),
z = categorical(repeat(1:2, outer=6)));
f = @formula(x ~ y * z);
mf = ModelFrame(f, df)
mm = ModelMatrix(mf)
@test mm.assign == [1, 2, 2, 3, 4, 4]
end

end
1 change: 1 addition & 0 deletions test/runtests.jl
Expand Up @@ -13,6 +13,7 @@ my_tests = ["formula.jl",
"temporal_terms.jl",
"schema.jl",
"modelmatrix.jl",
"modelframe.jl",
"statsmodel.jl",
"contrasts.jl",
"extension.jl"]
Expand Down

0 comments on commit 82de335

Please sign in to comment.