Closed MetzgerSK closed 1 year ago
@MetzgerSK apologies for the (super) late reply, but thank you already for taking the time to raise this and the other issues! I will work through them in the coming weeks.
Also really nice that you mention writing of unit tests for the Stata equivalent - we (together with @hputter ) would also like to start doing the same for {mstate}
in R.. will probably start trying some things out with {tinytest}
😃
@MetzgerSK thank you again for raising this and the other issues.
Commit 09f421f addresses this issue and #15 . The main change is (and we will have to make this explicit in documentation too) to return an error if coxph()
object fed into msfit()
does not contain a strata()
in the formula. The {survival}
package should remain the tool of choice for prediction for models without strata.
It is however fair to accommodate the edge case of a strata with just one level (it works for that now); we may perhaps add a warning at a later stage.
@MetzgerSK thank you again for raising this and the other issues.
Of course, thanks for putting together and maintaining the package.
I know of one more (potential?) issue for which I've been meaning to file a report. I'll go ahead and do that within the next few hours, before I forget.
R: 4.1.3 64-bit, mstate: 0.3.2, survival: 3.3.0, Win10
Problem
For a non-parametric Cox model with a single stratum defined by its specified
strata()
variable,msfit
produces an error:Problem's Source
The issue is
msfit
's lines 159–161:Prior to these lines,
sf0
containssummary(survfit(object))
.sf0$strata
evaluates toNULL
when thestrata()
term's variable has only one level. Thus,as.numeric(sf0$strata))
returns with length 0, whereas every other quantity in the to-be-formed data frame has length != 0.Context
This model's an odd edge case, to be sure. I'm not sure how many people would run into this issue in practice. For me, I was writing unit tests for
mstate
's Stata equivalent, and some of those tests involve comparing R-mstate
output with Stata's equivalent. The comparison code's written to work with both non-parametric and semi-parametric model specifications, which is the only reason I stumbled across the issue.Nevertheless, I didn't see anything in
msfit
's help file about this specific situation, nor did I see any open or closed GitHub issues about it, so I wanted to bring it to your attention.MWE