jwb133 / smcfcs

R package implementing Substantive Model Compatible Fully Conditional Specification Multiple Imputation
11 stars 8 forks source link

Error: object "imputations" not found when using smcfcs Surv() #27

Open hao-jiasi opened 1 month ago

hao-jiasi commented 1 month ago

Hello! Recently I ran smcfcs using "coxph" for the substantive model:

imp_init <- smcfcs(MIdf,
                   smtype="coxph", 
                   smformula="Surv(time_mort, event_mort) ~ age_1 + agesq_1  + chol_1 + education", 
                   method=c("", "", "norm", "age_1*age_1", "norm", "mlogit"),
                   predictorMatrix=MIpredMatrix, # an array initiated with mice::make.predictorMatrix, and I further modified it. All variables have assigned predictors.
                   rjlimit=2000,
                   m=2, 
                   numit=20)

Immediately I ran into an error:

Error in eval(temp, environment(formula$terms), parent.frame()) : object 'imputations' not found

After trying everything (e.g., if the data frame and variables were in the right type, and checked methods and prediction matrix), it still did not work. I could not find similar posts to solve this issue either. Could you please help with the reasons for this error and possible solutions?

Many thanks!!

jwb133 commented 1 month ago

I'm sorry I cannot see what the problem could be with this. Is it possible you can share a sample dataset along with the code that reproduces the problem? Otherwise it is pretty tricky to diagnose.

Alternatively, I would suggest reducing your dataset down to just one or or two of the covariates, and (hopefully) get it running. Then add back in covariates and see at which point it breaks - this may give a clue as to which variable is causing the problem and why.

hao-jiasi commented 1 month ago

Thank you for your prompt response!!
I have tried excluding covariates, but it reports the same error even with only one covariate age_1. Additionally, 1) the error always comes at the very first variable which needs to be imputed; 2) although I do have repeated measurements to impute (not included in the substantive model already), the total number of variables is not crazy (N= ~100 wide format, while N_patient= ~8000).
Very unfortunately I am not allowed to share the data... But based on my description, are there any possibilities in your mind that I could try myself?

jwb133 commented 1 month ago

Sorry, I really can't think of what is causing it.

Can you reproduce the error with a simulated dataset that has the same characteristics (or indeed reproduce it at all with a simulated dataset)?

Otherwise, you could install the package source code using devtools package, then call the function after using devtools::load_all(). This would enable you to see where in the R source file the error is occurring. But without knowing too much about how the program is coded it could be tough to figure out the problem.

Sorry.

hao-jiasi commented 1 month ago

I see. I can surely try them out. It might take some time for me to provide a simulated dataset that has the same characteristics. So we might leave this issue open for now and I will get back to you!
Thanks for your help!

tom-metherell commented 4 days ago

I had the same problem but I think I've found a fix – see #28.

jwb133 commented 4 days ago

Tom's proposed fix has now been incorporated. Please try installing the development version:

install.packages("devtools")

devtools::install_github("jwb133/smcfcs")

and see if this resolves the issue.