0

I would like to find the predicted values from my glm.nb model. But it is returning errors. This was not fixed when I made the input dataframe to predict 3 columns of dates called date, date2 and date3. The output I want is a vector of 100 predicted values. Model-fitting data should positive count data and dates.

model_nb <- glm.nb(cases ~ date, date2, date3, data=data)

dates <- seq(50,100,length=100)
preds3 <- predict(model_nb, newdata=data.frame(date=dates), se.fit=TRUE, type='response')

The error message is:

Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : variable lengths differ (found for 'date2')

MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • Is your model meant to have three date predictors? If so the syntax should probably be `model_nb <- glm.nb(cases ~ date + date2 + date3, data=data)`. And if this new model syntax is correct then you will need `date`, `date2` and `date3` in the `newdata` in your `predict` call – user20650 Jan 19 '21 at 01:44
  • i tried that but it didn't work. can you specify the exact input format of the three variables? – engelbrekt Jan 19 '21 at 01:46

1 Answers1

0

I solved this by reframing the dates in terms of each other in the original model.