0
First I'm going to give you some starter code:
library(ggplot2)
y = c(0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 3, 0, 6, 2, 8, 16, 21, 39, 48, 113, 92, 93 ,127, 159, 137, 46, 238, 132 ,124, 185 ,171, 250, 250 ,187, 119 ,151, 292, 94, 281, 146, 163 ,104, 156, 272, 273, 212, 210, 135, 187, 208, 310, 276 ,235, 246, 190, 232, 254, 446,
314, 402 ,276, 279, 386 ,402, 238, 581, 434, 159, 261, 356, 440, 498, 495, 462 ,306, 233, 396, 331, 418, 293 ,431 ,300, 222, 222, 479 ,501, 702
,790, 681)
x = 1:length(y)
Now, I'm trying to predict the 90th data point will be using polynomial regression, wherein the data, #1 is 0, and #89 is 681. I've tested my model and I've decided that a polynomial curve to the 8th degree is the perfect fit.
I've tried the code predict(formula=y~poly(x,8),90) and it's giving some strange error (which doesn't make sense to me) about how there is no applicable method.
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "c('double', 'numeric')"
Why doesn't this work? After scouring countless R documentations, blogs and forums, it seemed to me that this should work properly.
What does work, instead? I've tried other ways of using the predict method, and I think that this is the closest solution to what I want: The predicted value for the 90th data point.
Any other suggestions? I'm not sure that my model is the best, and I would welcome any suggestions you may have. For example, you may argue that it's better to use a 6th degree than an 8th degree polynomial for modeling, and if you have a valid reason, I would agree with you.
Thank you!