hputter / mstate

https://hputter.github.io/mstate/
7 stars 5 forks source link

`msfit`: `hlp` Dimension Issue #16

Closed MetzgerSK closed 2 years ago

MetzgerSK commented 2 years ago

R: 4.1.3 64-bit, mstate: 0.3.2, survival: 3.3.1, Win11

Problem

For a Cox model with one transition, msfit throws the following error:

Error in hlp[, 1] : incorrect number of dimensions

Problem's Source

Lines 300–303 are at fault. Those lines read:

varHaz <- data.frame(time = rep(untimes, n2 * (n2 + 1)/2), varHaz = varHaz,
    trans1 = rep(hlp[, 1], rep(nt, n2 * (n2 + 1)/2)), trans2 = rep(hlp[,
        2], rep(nt, n2 * (n2 + 1)/2)))

trans1's code is the specific culprit, but trans2's code would throw the same error, if trans1 didn't exist:

Error in hlp[, 2] : incorrect number of dimensions

Turns out, hlp is a matrix when it's first created (lines 297–298):

Browse[2]> hlp
     [,1] [,2]
[1,]    1    1
Browse[2]> str(hlp)
 int [1, 1:2] 1 1

If you run lines 300–303 at this point, they run fine.

The problem seems to be line 299. After you run this line, hlp becomes a vector:

Browse[2]> hlp
[1] 1 1
Browse[2]> str(hlp)
 int [1:2] 1 1

If you run lines 300–303 after line 299, you now get Error in hlp[, 1]....

MWE

See #15's MWE. The first msfit call in that example throws this error.

edbonneville commented 2 years ago

Solved by pull request #17 .