Hi there,
I am having a strange error while trying to make prediction from a fitted model.
I have a dataset from a discrete choice experiment where each doctor evaluates a set of patients with different characteristics, and make a treatment choice for each patient.
The structure of my data is like this:
> str(dcefull2)
'data.frame': 350 obs. of 28 variables:
$ id : Factor w/ 25 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
$ choice : Factor w/ 3 levels "stop","half",..: 2 3 2 2 2 2 2 2 2 3 ...
$ response : Factor w/ 2 levels "Good response",..: 1 2 2 2 2 1 2 2 1 1 ...
$ resist_profile : Factor w/ 3 levels "MDR-TB","MDR-TB + PZA + EMB resis",..: 3 2 2 3 3 2 1 2 3 3 ...
$ ambu_regimen : Factor w/ 2 levels "BPaLM","Standard": 2 2 2 2 1 2 2 2 2 1 ...
$ expo_his : Factor w/ 2 levels "No exposure",..: 2 1 1 1 2 2 2 1 2 1 ...
$ resist_prob : num 2.8 0.8 1.8 1.8 1.8 1.8 2.8 0.8 2.8 0.8 ...
$ cred_interval : Factor w/ 2 levels "Wide","Narrow": 2 2 2 1 2 2 2 1 1 1 ...
I fitted an ordered logit model with treatment choice (ordinal variable with 3 categories) as a function of patient characteristics and doctor id as a random intercept:
random_model_off3 <- clmm2(choice ~ response + resist_prob*resist_profile + resist_prob*ambu_regimen + resist_prob*expo_his + resist_prob*cred_interval, random = id, data=dcefull2, Hess = TRUE, nAGQ = 10)
Then I made a new dataset with all dependent variables. I varied the "resist_prob" and "cred_interval" but fixed all other variables at one value.
The structure of my new data is like this:
> 'data.frame': 2002 obs. of 6 variables:
$ response : Factor w/ 1 level "Good response": 1 1 1 1 1 1 1 1 1 1 ...
$ resist_profile: Factor w/ 1 level "MDR-TB": 1 1 1 1 1 1 1 1 1 1 ...
$ cred_interval : Factor w/ 2 levels "Wide","Narrow": 1 2 1 2 1 2 1 2 1 2 ...
$ ambu_regimen : Factor w/ 1 level "BPaLM": 1 1 1 1 1 1 1 1 1 1 ...
$ expo_his : Factor w/ 1 level "No exposure": 1 1 1 1 1 1 1 1 1 1 ...
$ resist_prob : num 0 0 0.004 0.004 0.008 0.008 0.012 0.012 0.016 0.016 ...
I tried to make prediction of probability for each category of treatment choice based on the new dataset:
predict(random_model_off3, newdata = newdat2)
And I received this error
Error in eval(predvars, data, env) : object 'choice' not found
I found it very strange because "choice" is the dependent variable that I am trying to predict. I cannot figure out how to solve this error.
I greatly appreciate your help!