corentin-dev / smmR

GNU General Public License v3.0
3 stars 2 forks source link

Incorrect handling of absorbing states #3

Open aeleuteri opened 3 months ago

aeleuteri commented 3 months ago

I tried estimating a model for some data which has an absorbing state, and the estimation fails because of faulty normalisation of the transition matrix. In the following, there are two transient states (1,2) and one absorbing state (3). For example, the following snippet of code, with test data which mimics the structure of the data I have, fails: testseq<-list(c('1','1','2','3'),c('2','2','2','3'),c('2','1','2','3')) fitsmm(sequences = testseq, states = c('1','2','3'), type.sojourn = "f",distr="dweibull")

The warnings (understandable due to the structure of the data) and error I get: Some transitions from state i to state j are not observed: (i = "3" to j = "1"), (i = "3" to j = "2"), (i = "1" to j = "3") Error in smmparametric(states = states, init = rep.int(x = 1/s, times = s), : 'ptrans' is not a matrix with numeric values

I identified the source of error in the .normalizePtrans() function. The input to the function is: [,1] [,2] [,3] [1,] 0.00 1 0.00 [2,] 0.25 0 0.75 [3,] 0.00 0 0.00

The output is: [,1] [,2] [,3] [1,] 0.00 1 0.00 [2,] 0.25 0 0.75 [3,] NaN NaN NaN

So the function introduces NaNs, which induce failure of the smmparametric function.

For comparison, I ran the estimSM function from the SMM package, and it doesn't fail, but it produces the warnings: Warning messages: 1: In .comptage(J, L, S, Kmax) : Warning : missing transitions 2: In .comptage(J, L, S, Kmax) : Warning : missing letters

Looking at the estimated Ptrans (same as the one produced by fitsmm), it seems correct, but I am wary of the overall results due to the above warnings.

So, my question is: are the libraries designed to handle absorbing states?

Thanks, Antonio

corentin-dev commented 2 months ago

Thank you for your question and your interest in the package.

So far smmR is not designed to handle absorbing states. We will look into it for a future version, we will ping you through this issue when it is done.

SMM is a previous version that smmR is replacing. It was not designed to handle absorbing states as well, so the warnings you get are "normal".