No method matching predict
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.
: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?
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)
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?
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.
Note also that this is presently only implemented for lm, so glm would also have to be implemented
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.
Alright, I will take one of these actions within the week(-end hopefully).
https://github.com/JuliaStats/DataFrames.jl/pull/1160
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.
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?
I'll define that function for GLM and see if it works :-)
It was just that in GLM I could only find it defined for LinPredModel
So any update here?
Several bindings relate to DataFrame seem still missing...
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.