predict() and newdata - How does this work?
<p>Someone recently posted a question on this paper here: <a href="https://static.googleusercontent.com/media/www.google.com/en//googleblogs/pdfs/google_predicting_the_present.pdf" rel="nofollow">https://static.googleusercontent.com/media/www.google.com/en//googleblogs/pdfs/google_predicting_the_present.pdf</a></p>

<p>The R code of the paper can be found at the very end of the paper. Essentially, the paper investigates one-month ahead predictions of sales through search queries. I think I understood the model and method, but there's one detail that puzzles me. It's the part:</p>

<pre><code>1 ##### Divide data by two parts - model fitting &amp; prediction
dat1 = mdat[1:(nrow(mdat)-1), ]
dat2 = mdat[nrow(mdat), ]

2 ##### Fit Model;
fit = lm(log(sales) ~ log(s1) + log(s12) + trends1, data=dat1);
summary(fit)
</code></pre>

<p>and:</p>

<pre><code>3 #### Prediction for the next month;
predict.fit = predict(fit, newdata=dat2, se.fit=TRUE);
</code></pre>

<p>I do understand, that <code>dat2</code> in (1) is only the last row from <code>mdat</code>. (2) means that the regression model is applied to everything but the last row in the dataset.</p>

<p>But why is <code>newdata=dat2</code> in the prediction model of (3) being used and what does it mean? Why the last row only?</p>