I was trying to apply the Bayesian first order Markov model (from this link) to a binary longitudinal data set that I have.
However, I am getting the following error when I tried to use soprobMarkovOrdm() get the state occupancy probabilities (SOP):
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
Using the uprobB() function from the reference link above (with modifications in order to adapt it to my data), I was able to locate the cause of this error. It is caused by the application of the predict() functions to calculate the post time 1 conditional probabilities (i.e. pp <- predict(fit, edata, type='fitted.ind', posterior.summary='all') ) as edata has more than 2 row of data (since the outcome has 2 levels).
I was able to get the uprobB() function to run by replacing:
Hi there,
I was trying to apply the Bayesian first order Markov model (from this link) to a binary longitudinal data set that I have.
However, I am getting the following error when I tried to use
soprobMarkovOrdm()
get the state occupancy probabilities (SOP):Using the
uprobB()
function from the reference link above (with modifications in order to adapt it to my data), I was able to locate the cause of this error. It is caused by the application of thepredict()
functions to calculate the post time 1 conditional probabilities (i.e.pp <- predict(fit, edata, type='fitted.ind', posterior.summary='all')
) asedata
has more than 2 row of data (since the outcome has 2 levels).I was able to get the
uprobB()
function to run by replacing:with the following (plus additional modifications, see
uprobB_new()
below with comment# my modification
)Here are the code I use for this analysis along with a sub-sample of my data