title: Predict Future values using polynomial regression in R
body: <p>Was trying to predict the future value of a sample using polynomial regression in R. The y values within the sample forms a wave pattern.
  For example  </p>
  
  <pre><code>x = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
  y= 1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4
  </code></pre>
  
  <p>But when the graph is plotted for future values the resultant <code>y</code> values was completely different from what was expected. Instead of a wave pattern, was getting a graph where the <code>y</code> values keep increasing.</p>
  
  <pre><code>futurY = 17,18,19,20,21,22
  </code></pre>
  
  <p>Tried different degrees of polynomial regression, but the predicted results for <code>futurY</code> were drastically different from what was expected</p>
  
  <p>Following is the sample R code which was used to get the results</p>
  
  <pre><code>dfram &lt;- data.frame('x'=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16))
  dfram$y &lt;- c(1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4)
  plot(dfram,dfram$y,type="l", lwd=3)
  pred &lt;- data.frame('x'=c(17,18,19,20,21,22))
  myFit &lt;- lm(y ~ poly(x,5), data=dfram)
  newdata &lt;- predict(myFit, pred)
  print(newdata)
  plot(pred[,1],data.frame(newdata)[,1],type="l",col="red", lwd=3)
  </code></pre>
  
  <p>Is this the correct technique to be used for predicting the unknown future y values OR should I be using other techniques like forecasting?</p>