Skip to content

Commit

Permalink
Fix bug with predict(mm::TableRegressionModel, data; kwargs...) (#126)
Browse files Browse the repository at this point in the history
Makes `predict` work even when the dependent (left-hand side) variables are not in the new data table.

* Fix bug with predict(mm::TableRegressionModel, data; kwargs...)

* Bump version number from "0.6.0" to "0.6.1"
  • Loading branch information
DilumAluthge authored and kleinschmidt committed Jun 29, 2019
1 parent 36da26a commit 3891ba6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
@@ -1,6 +1,6 @@
name = "StatsModels"
uuid = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
version = "0.6.0"
version = "0.6.1"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
2 changes: 1 addition & 1 deletion src/statsmodel.jl
Expand Up @@ -159,7 +159,7 @@ function StatsBase.predict(mm::TableRegressionModel, data; kwargs...)
throw(ArgumentError("expected data in a Table, got $(typeof(data))"))

f = mm.mf.f
cols, nonmissings = missing_omit(columntable(data), f)
cols, nonmissings = missing_omit(columntable(data), f.rhs)
new_x = modelcols(f.rhs, cols)
y_pred = predict(mm.model, reshape(new_x, size(new_x, 1), :);
kwargs...)
Expand Down
8 changes: 8 additions & 0 deletions test/statsmodel.jl
Expand Up @@ -110,6 +110,14 @@ Base.show(io::IO, m::DummyModTwo) = println(io, m.msg)
@test_throws KeyError predict(m2, d3)
# @test_throws ArgumentError predict(m2, d3)

## predict with dataframe that doesn't have the dependent variable
d4 = deepcopy(d)
deletecols!(d4, [:y])
@test predict(m, d4) == predict(m, d)

## attempting to fit with d4 should fail since it doesn't have :y
@test_throws ErrorException fit(DummyMod, f, d4)

## fit with contrasts specified
d[:x2p] = CategoricalVector{Union{Missing, Int}}(d[:x2])
f3 = @formula(y ~ x1p + x2p)
Expand Down

2 comments on commit 3891ba6

@kleinschmidt
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/1666

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" 3891ba6137566f16912ef584f525413f150a8314
git push origin v0.6.1

Please sign in to comment.