0

I have run a negative binomial model. I am trying to get a preduction using my final model:

> # prediction and GOF
>     str(epilepsy_reduced)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   58 obs. of  4 variables:
 $ treatment   : num  0 0 0 0 0 0 0 0 0 0 ...
 $ age         : int  31 30 25 36 22 29 31 42 37 28 ...
 $ seizure.rate: int  3 3 5 4 21 7 2 12 5 0 ...
 $ ID          : int  1 2 3 4 5 6 7 8 9 10 ...
>     
>     placebo_patient <- data.frame(treatment=as.numeric(0), age=as.integer(30))
>     progabide_patient <- data.frame(treatment=as.numeric(1), age=as.integer(30))
>     
>     str(placebo_patient)
'data.frame':   1 obs. of  2 variables:
 $ treatment: num 0
 $ age      : int 30
>     str(progabide_patient)
'data.frame':   1 obs. of  2 variables:
 $ treatment: num 1
 $ age      : int 30
>     
>     age30 <- predict(epilepsy_reduced, newdata=placebo_patient, type="response")
Error in UseMethod("predict") : 
  no applicable method for 'predict' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
>     age30
Error: object 'age30' not found

What is causing this error ?

user1607
  • 531
  • 7
  • 28
  • 1
    Have you run a model in order to predict? – LyzandeR Apr 26 '18 at 14:14
  • 1
    You can't predict from a data.frame. You need to first run `glm()` to build your model, then you predict from the model. When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. `str()` is not as helpful as a `dput()`. – MrFlick Apr 26 '18 at 14:44

0 Answers0