Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206786

Can not choose number of periods for forecasting any other than variable length

$
0
0

I want to predict a time series from a model I estimate with tslm from the forecast package. Here is some data:

x <- ts(rnorm(120,0,3) + 1:120 + 20*sin(2*pi*(1:120)/12), frequency=12, start= c(2000, 01, 01))
y <- ts(x + rnorm(length(x)), frequency=12, start= c(2000, 01, 01))
df <- data.frame(y, x)

So we have an (independent) variable x with some pattern and a (dependent) variable y which appears to be a noisy version of x. I fit the model like this:

fit <- tslm(y ~ trend + season + x, df)

summary(fit) looks okay, since x is highly significant and estimate is close to 1. But running forecast(fit, h=20) gives me an error:

... variable lengths differ (found for 'x') ...

forecast(fit, h= length(x)) works (although plot(forecast(fit, h= length(x))) looks very strange, but this is an other question).


Viewing all articles
Browse latest Browse all 206786

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>