RedDoorAnalytics/survsim

`survsim_msm`: Informative Error Message Needed (`tdefunc()`)

Opened this issue · 0 comments

Win11, Stata 17.0 MP6, survsim 4.0.10

I was jumping back and forth between stcox and survsim and accidentally used the former's texp() syntax for the latter--I typed tdefunc("ln(_t)") instead of tdefunc("ln({t})"). However, the error message I received when simulating via survsim msm didn't pinpoint this as the issue:

              totalhf1():  3200  conformability error
       survsim_msm_sim():     -  function returned error
            _mm_callf1():     -  function returned error
              mm_callf():     -  function returned error
       survsim_mm_root():     -  function returned error
           survsim_msm():     -  function returned error
                 <istmt>:     -  function returned error

A more informative error message would help, especially because Mata kicking the error means set trace-ing won't easily reveal the true problem.

(As an aside: running the same code via survsim parametric doesn't throw an error at all, which obfuscated matters. Only after rereading the survsim parametric help file again, after I'd found the issue, made me realize that tdefunc() isn't a parsed option for that survsim variant.)

MWE

clear *
set seed 1283169888
set obs 8000

gen double x1 = rnormal()
gen double x2 = rnormal()

//****************************************************************************** 
global opts = "dist(w) lambda(0.5) gamma(1.25)"
global tvc1 = "tde(x2 -0.1) tdefunction(ln(_t))"

* msm - throws error
cap noi survsim t type fail, ///    
    hazard1($opts covariate(x1 -0.65 x2 0.4) $tvc1) ///
    hazard2($opts covariate(x1 0.3   x2 0.5)) ///
    maxtime(100)
    
mata mata clear // to ensure starting from clean slate [GH issue #2]
    
* parametric - no error    
survsim t fail, ///    
    $opts covariate(x1 -0.65 x2 0.4) $tvc1