title: Assess prediction models by calculating mean squared prediction error
body: <p>I'm trying to compare two different prediction models by calculating mean squared prediction error.</p>
  
  <p>Here is the link to the dataset <a href="https://github.com/user59036/first" rel="nofollow noreferrer">earnings.csv dataset</a></p>
  
  <ol>
  <li><p>Use 2000-2006 years of data as the training dataset and 2007-2008 data as the testing dataset. </p></li>
  <li><p>Use both decompose() and stl() function in R to decompose the time series into trend, seasonal and error components.</p></li>
  <li><p>Use lm() function in R to fit a linear model to the trend component. Then predict the monthly earnings for the year of 2007-2008.Compare the predictions under the two methods with the test dataset, both graphically and by calculating the sample mean squared prediction error (MSPE).</p></li>
  <li><p>Discuss about the stochastic properties of the error term of the two different decompose methods.</p></li>
  </ol>
  
  <p>Here is my R code:</p>
  
  <pre><code>Data &lt;-read.table("earnings.csv",header = T,sep=",")
  tsData &lt;- ts(Data$X,start = 2000, frequency = 12)
  plot(tsData,xlab= "Month",ylab = "Earnings")
  tsData = log(tsData)
  
  trainingSet = window(tsData,start=2000,end=c(2006,12))
  testSet = window(tsData,start=2007,end=c(2008,12))
  decompTS =decompose(trainingSet)
  stltraining = stl(trainingSet,s.window = "periodic")
  
  lm1 = lm(trainingSet~decompTS$trend)
  lm1
  
  lm2 = lm(trainingSet~stltraining$time.series[,2])
  lm2
  
  
  decompTest=(decompose(testSet))$trend
  pred1=lm1$coefficients*decompTest
  pred2=predict(lm2,decompTest)
  plot(pred1)
  plot(pred2)
  
  mspe1=mean((testSet-pred1)^2)
  </code></pre>
  
  <p>The value I got for mspe1 is null. What did I do wrong here? Thanks for any help</p>