Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with survfitJM #104

Closed
huyendn opened this issue Aug 10, 2023 · 5 comments
Closed

issue with survfitJM #104

huyendn opened this issue Aug 10, 2023 · 5 comments

Comments

@huyendn
Copy link

huyendn commented Aug 10, 2023

I got this error when trying to fit the dynamic prediction
Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
I know this error occurs when the categorical only has 1 level. However, if we do prediction for one patient, a categorical could have only 1 level for that patient. In your example code (https://erandrinopoulou.github.io/EducationalCorner_JMpred/) , the data for the patient for prediction has some categorical with one level. Could you please help look into this?

@drizopoulos
Copy link
Owner

drizopoulos commented Aug 10, 2023 via email

@huyendn
Copy link
Author

huyendn commented Aug 10, 2023

Thanks for the fast response. I just tried predict function in JMbayes2 with jm object and still got the same message error.

predSurv <- predict(jointm1.bayes, newdata = newdata_5, process = "event",

  •                 return_newdata = TRUE)
    

Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels

@huyendn
Copy link
Author

huyendn commented Aug 15, 2023

Hello,

Do you know what might possibly cause this issue?

Thank you

@zoezhang106
Copy link

Hi,

I encountered the same problem recently and solved by converting categorical variables to factors. You may also want to check if each of the factors is with 2 or more levels.

Hope this helps.

@ellenerickson
Copy link

Make sure in "newdata_5" you are defining your factor variables to have two levels even if you're predicting with only one level. For example, if you have 2 time points and your categorical variable is gender, define it as:

newdata_5$gender <- factor(c('female','female'), levels = c('female','male'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants