0
library(astsa)
library(forecast)
globtemp
trend <- tslm(globtemp~I(trend^2)+trend)
autoplot(cbind(globtemp,trend$fitted), lwd=1)

How do I extrapolate here? I'd like to draw the "trend line" line further, up to let's say 2031.

enter image description here

I tried using solution from this question:

predict(trend, data.frame(date=seq(as.Date("2021-01-01"), by="1 year", length.out=10)), interval = "prediction")

but it only warned me that Warning message: 'newdata' had 10 rows but variables found have 136 rows and gave some gibberish results.

blahblah
  • 1,161
  • 2
  • 14
  • 30

1 Answers1

1

Answer

Use forecast::forecast:

forecast(trend)

This returns an object with predicted values for subsequent years as well as confidence intervals that you can then use to create a plot.

If you want to forecast further into the future, say, 50 years:

forecast(trend, h = 50)

By default, it allows you to plot the forecast with plot:

plot(forecast(trend, h = 50))

enter image description here

slamballais
  • 3,161
  • 3
  • 18
  • 29