JuliaStats / Survival.jl

Survival analysis in Julia
MIT License
73 stars 22 forks source link

How add mixed effects to a cox model? #55

Open casasgomezuribarri opened 1 year ago

casasgomezuribarri commented 1 year ago

I want to add random effects to my Cox model formulation, and I have noticed that

cox1 = coxph(@formula(event ~ A + B + C + (1|D)), data) 

produces the following error:

ERROR: MethodError: no method matching |(::Int64, ::String) Closest candidates are: |(::Any, ::Any, ::Any, ::Any...) at operators.jl:591 |(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at int.jl:365 |(::T, ::CEnum.Cenum{S}) where {T<:Integer, S<:Integer} at ~/.julia/packages/CEnum/Bqafi/src/operators.jl:13

but this syntax is allowed in @formula (i.e., the following works fine):

@formula(event ~ A + B + C + (1|D))

I assume mixed effects aren't supported in coxph?

For reference, random effects in survival analysis are often referred to as 'frailty terms' (in fact, I think in R they are added as frailty(D) as opposed to 1|D, but I'm not sure.

Is this something that is supported but I'm just doing it wrong?

casasgomezuribarri commented 1 year ago

further reference, in case it's helpful:

https://stats.oarc.ucla.edu/r/dae/mixed-effects-cox-regression/

ararslan commented 8 months ago

Hi @casasgomezuribarri, apologies for the delayed response. Mixed effects are not currently supported by this package though it's something I'd like to incorporate eventually.