GLM.jl icon indicating copy to clipboard operation
GLM.jl copied to clipboard

No method matching predict

Open mthorrell opened this issue 8 years ago • 14 comments

I'm new to Julia, so I may be doing something wrong. But the following code pulled basically straight from the example on Github doesn't run for me.

using GLM
using DataFrames
data = DataFrame(X=[1,2,3], Y=[2,4,7])
OLS = glm(Y ~ X, data, Normal(), IdentityLink())
newX = DataFrame(X=[2,3,4])
predict(OLS, newX, :confint)

I get

ERROR: MethodError: no method matching predict(::GLM.GeneralizedLinearModel{GLM.GlmResp{Array{Float64,1},Distributions.Normal{Float64},GLM.IdentityLink},GLM.DensePredChol{Float64,Base.LinAlg.Cholesky{Float64,Array{Float64,2}}}}, ::DataFrames.DataFrame, ::Symbol)
Closest candidates are:
  predict(::DataFrames.DataFrameRegressionModel{M,T}, ::Any...; kwargs...)
...

This also occurs if I remove :confint.

mthorrell avatar Feb 10 '17 04:02 mthorrell

:confint isn't supported yet when passing a DataFrame (cf. https://github.com/JuliaStats/GLM.jl/pull/171). I don't get an error if I remove that argument. Can you post the error you get in that case?

nalimilan avatar Feb 10 '17 09:02 nalimilan

Interesting, it does work for me now.

In any case, this is on the GLM Github homepage (https://github.com/JuliaStats/GLM.jl). Perhaps that should be edited?

 julia> newX = DataFrame(X=[2,3,4]);
 julia> predict(OLS, newX, :confint)

mthorrell avatar Feb 10 '17 14:02 mthorrell

Right, that was introduced a little too early in https://github.com/JuliaStats/GLM.jl/pull/171.

@mkborregaard We should either add support for this in DataFrames soon, or revert that addition temporarily. What do you think?

nalimilan avatar Feb 10 '17 14:02 nalimilan

Are you asking me to add it to DataFrames? I might be able to find the time, but I didn't have a look at the DataFrames code for this yet.

mkborregaard avatar Feb 10 '17 14:02 mkborregaard

Note also that this is presently only implemented for lm, so glm would also have to be implemented

mkborregaard avatar Feb 10 '17 14:02 mkborregaard

Adding this should be pretty easy, you just need to adapt the signature in src/statmodels/statsmodel.jl. Else, just revert that example in README.

nalimilan avatar Feb 10 '17 14:02 nalimilan

Alright, I will take one of these actions within the week(-end hopefully).

mkborregaard avatar Feb 10 '17 14:02 mkborregaard

https://github.com/JuliaStats/DataFrames.jl/pull/1160

mkborregaard avatar Feb 12 '17 20:02 mkborregaard

That only fixes the method that supplies newX. I can't seem to work out where predict without newX is located? That should also have a method with confidence intervals. Thanks.

mkborregaard avatar Feb 12 '17 21:02 mkborregaard

It's defined via @delegate: https://github.com/mkborregaard/DataFrames.jl/blob/bb8c64a9b8e56e2ad40ba80d151fb36df14090ca/src/statsmodels/statsmodel.jl#L68 AFAICT it should redirect predict(m::DataFrameRegressionModel, interval_type, level) to predict(m::StatModel, interval_type, level). Doesn't it?

nalimilan avatar Feb 13 '17 09:02 nalimilan

I'll define that function for GLM and see if it works :-)

mkborregaard avatar Feb 13 '17 09:02 mkborregaard

It was just that in GLM I could only find it defined for LinPredModel

mkborregaard avatar Feb 13 '17 09:02 mkborregaard

So any update here?

Several bindings relate to DataFrame seem still missing...

findmyway avatar Dec 28 '17 14:12 findmyway

My bad conscience comes back to bite me. I had a working PR ( https://github.com/JuliaData/DataFrames.jl/pull/1160 ) but then never added the extra tests necessary for merging. I'll see if it isn't easy to rebase on current master.

mkborregaard avatar Jan 02 '18 08:01 mkborregaard