Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cox regression broke with latest StatsModels master #10

Closed
piever opened this issue Mar 10, 2019 · 5 comments · Fixed by JuliaStats/StatsModels.jl#106 or #17
Closed

Cox regression broke with latest StatsModels master #10

piever opened this issue Mar 10, 2019 · 5 comments · Fixed by JuliaStats/StatsModels.jl#106 or #17

Comments

@piever
Copy link
Contributor

piever commented Mar 10, 2019

Not sure what's happening (unfortunately I don't remember any more what manipulations StatsModels does to fit before calling fit with arrays):

julia> using Survival, DataFrames, StatsModels

julia> df = DataFrame(x = rand(4), y = EventTime.(rand(4), rand(Bool, 4)))
4×2 DataFrame
│ Row │ x        │ y         │
│     │ Float64  │ EventTim │
├─────┼──────────┼───────────┤
│ 10.8276010.662955+ │
│ 20.9095570.0749414 │
│ 30.3798720.0578822 │
│ 40.1221070.712976  │

julia> fit(CoxModel, @formula(y ~ x), df)
ERROR: MethodError: no method matching fit(::Type{CoxModel}, ::Array{Float64,2}, ::Array{Float64,2})
Closest candidates are:
  fit(::Type{Histogram}, ::Any...; kwargs...) at /home/pietro/.julia/dev/StatsBase/src/hist.jl:319
  fit(::StatisticalModel, ::Any...) at /home/pietro/.julia/dev/StatsBase/src/statmodels.jl:151
  fit(::Type{T<:RegressionModel}, ::FormulaTerm, ::Any, ::Any...; contrasts, kwargs...) where T<:RegressionModel at /home/pietro/.julia/dev/StatsModels/src/statsmodel.jl:82
  ...
Stacktrace:
 [1] #fit#57(::Dict{Symbol,Any}, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}}, ::Function, ::Type{CoxModel}, ::FormulaTerm{Term,Term}, ::DataFrame) at /home/pietro/.julia/dev/StatsModels/src/statsmodel.jl:88
 [2] fit(::Type{CoxModel}, ::FormulaTerm{Term,Term}, ::DataFrame) at /home/pietro/.julia/dev/StatsModels/src/statsmodel.jl:82
 [3] top-level scope at none:0
@ararslan
Copy link
Member

Hm, I probably should have been paying more attention to the details of the changes in JuliaStats/StatsModels.jl#71 so that I would know how to adapt this package. 😬

@kleinschmidt
Copy link
Member

What's happened here is that the EventTime type is treated as a categorical term since it's not <:Number. Teh hacky/quick and dirty way to deal with this is to use @formula(identity(y) ~ x). That way the y vector is copied through unchanged (elementwise).

I think the way to fix this is to define some special handling of these types, either here or in StatsModels itself. Currently there are only two types of "concrete terms" defined in statsmodels: continuous and categorical. Maybe a third basic type like IdentityTerm, and then define a method for schema(t::Term, x::AbstractVector{<:EventTime}) = IdentityTerm(t) in this package.

@ararslan
Copy link
Member

For now I've opted to add an upper bound on StatsModels to this package.

@ararslan
Copy link
Member

@kleinschmidt, you said that JuliaStats/StatsModels.jl#106 partially fixes this; what's left to be done? Should this remain open for now?

@kleinschmidt kleinschmidt reopened this Jun 27, 2019
@kleinschmidt
Copy link
Member

It's in #17. Let me double check that it works...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants