Closed MetzgerSK closed 1 year ago
Thanks for spotting this - indeed x = TRUE
in the coxph()
call should not have any impact on later msfit()
calls.. for now the (unelegant!) solution in 09f421f is to simply set object[["x"]]
to NULL in cases where x = TRUE
.
R: 4.1.3 64-bit, mstate: 0.3.2, survival: 3.3.1, Win11
Problem
msfit
will throw an error ifcoxph
hasx=TRUE
, but the model has astrata()
term:The problem arises in an otherwise vanilla situation: the model has no weights or offset, and
coxph(..., y=TRUE)
(the default).Problem's Source
The
mf
object isn't created in this situation.msfit
referencesmf
in line 206 (and 211, fortype=="right"
instead oftype=="counting"
):The problem originates in
msfit
's lines 20–25:With the
coxph
default (coxph(..., x=FALSE)
),is.null(object[["x"]])
usually evaluates toTRUE
. Theif
gets triggered, regardless of the truth of the other four "or" statements in theif()
's conditional.mf
is generated without issue.However, if
coxph(..., x=TRUE)
,is.null(object[["x"]])
evaluates toFALSE
. The other four "or"ed terms in theif()
also evaluate toFALSE
, in this situation:y=TRUE
by default forcoxph
, and the model has no weights or offset. Theelse
gets triggered instead of theif
, andmf
's never generated. Instead, its value is set toNULL
.mf
's contents only get referenced post-line 25 bymsfit
if there's astrata()
term (has.strata==TRUE
), hence the issue only arising in this context.MWE