# Forecasting with xreg=snaive

Hi guys!

I'm trying to make a forecastmachine in r but got stuck.

I try to predict a dynamic regression model using the temperature per month.
To predict the temperature of '21 I want to use the snaive () function. But how do I apply this in the forecast () with regression.

This may seem a bit messy, that is because it is part of an (almost) automated code.

``````START<-	c(2014,1)
Fq<-	12

liters<-data[,"Liters"]
temp<-	data[,"Tempratuur"]
tsl<-	ts(liters, frequency=Fq, start=START)

X1<-	6			        #length test set
X2<-	length(tsl)-(X1-1)	#Length training set
Y<-	    12			        #Length forecast
``````

dput(temp) and dput(liters) are at the bottom

Now the code

``````reg1<-		  ts(temp, frequency=Fq, start=START)
reg1training<-subset(reg1, end=length(tsl)-X1)
reg1test<-	  subset(reg1, start=X2)

lamb<-        BoxCox.lambda(training)

txt<- auto.arima(training, xreg=reg1training,
lambda=lamb, stepwise=FALSE)

#> Series: training
#> Regression with ARIMA(0,1,1)(0,1,1)[12] errors
#> Box Cox transformation: lambda= -0.1176994
#>
#> Coefficients:
#>           ma1     sma1    xreg
#>       -0.6507  -0.4964  0.1057
#> s.e.   0.0897   0.1514  0.0188
#>
#> sigma^2 estimated as 0.09377:  log likelihood=-15.75
#> AIC=39.49   AICc=40.16   BIC=48.19

ntxt<-	Arima(tsl,
order=arimaorder(txt)[1:3],
seasonal=arimaorder(txt)[4:6],
lambda=lamb)

#> Series: tsl
#> Regression with ARIMA(0,1,1)(0,1,1)[12] errors
#> Box Cox transformation: lambda= -0.1176994
#>
#> Coefficients:
#>           ma1     sma1  tempratuur
#>       -0.6870  -0.4226      0.0939
#> s.e.   0.0779   0.1587      0.0188
#>
#> sigma^2 estimated as 0.1023:  log likelihood=-19.79
#> AIC=47.58   AICc=48.18   BIC=56.63
``````

So what i would like now is something like this:

``````reg<-snaive(ts(temp, frequency=Fq, start=START),h=Y)

forecast(ntxt,xreg=reg)
``````

But that gives

``````#>Error in forecast.forecast_ARIMA(ntxt, xreg = reg) :
#>  xreg should be a numeric matrix or a numeric vector
``````

.
.
.
.
.
.
.
.

``````> dput(liters)
structure(list(test = c(7.21032258064516, 17.2285714285714, 76.3225806451613,
84.37, 215.516129032258, 431.293333333333, 745.207741935484,
539.334193548387, 655.362, 367.974193548387, 236.646666666667,
450.588387096774, 43.5716129032258, 66.04, 276.847741935484,
282.619333333333, 566.998709677419, 1095.84266666667, 1187.29161290323,
1726.45161290323, 1228.92, 655.529032258065, 746.288666666667,
2058.73548387097, 51.2283870967742, 215.889655172414, 440.936129032258,
546.156, 1347.63935483871, 1996.08933333333, 1990.58709677419,
2641.42451612903, 2540.032, 1096.66451612903, 422.928, 1732.26838709677,
71.0477419354839, 182.357142857143, 396.425806451613, 1027.65,
1599.73935483871, 3255.12866666667, 2865.75483870968, 3925.91612903226,
2232.9, 2148.5264516129, 873.73, 1782.78580645161, 354.518709677419,
15.81, 397.767096774194, 1355.744, 2438.12903225806, 3957.012,
5153.51612903226, 4435.99483870968, 3508.008, 1976.56516129032,
986.362, 3491.30322580645, 333.44, 359.325, 1176.71806451613,
1387.1, 1956.2064516129, 4006.08, 5792.94967741935, 6212.12903225807,
4270.84, 2047.86903225806, 714.922666666667, 3568.59870967742,
442.003225806452, 378.063448275862, 706.285161290323, 307.008,
712.175483870968, 2856.568, 2208.59612903226, 3378.91806451613,
2642.112, 1065.01161290323, 141.542666666667, 2720.94967741935
)), row.names = c(NA, -84L), class = c("tbl_df", "tbl", "data.frame"
))
``````
``````> dput(temp)
structure(list(tempratuur = c(4.50645161290323, 5.74285714285714,
7.33870967741935, 10.8166666666667, 12.6774193548387, 15.4033333333333,
19.4064516129032, 16.0516129032258, 15.83, 13.141935483871, 7.68333333333333,
4.65483870967742, 3.89032258064516, 3.175, 5.81612903225806,
7.55666666666667, 11.0741935483871, 14.0133333333333, 17.358064516129,
17.9838709677419, 13.3, 9.93225806451613, 9.54333333333333, 8.93548387096774,
3.28387096774194, 4.15172413793103, 4.80322580645161, 7.78, 13.6677419354839,
15.6433333333333, 17.4612903225806, 17.1967741935484, 17.4933333333333,
9.7741935483871, 5.34, 4.98064516129032, 1.55806451612903, 4.10714285714286,
7.45161290322581, 7.75, 13.6032258064516, 16.4566666666667, 17.058064516129,
16.7774193548387, 13.7833333333333, 12.9741935483871, 7.15, 4.6258064516129,
4.61612903225806, 0.221428571428571, 3.54516129032258, 10.8633333333333,
15.6290322580645, 15.93, 19.0870967741935, 18.0032258064516,
14.6533333333333, 12.1709677419355, 6.43, 6.06129032258064, 3.36129032258064,
5.70357142857143, 7.18387096774194, 9.7, 10.7483870967742, 17.12,
18.0129032258065, 18.2709677419355, 14.5266666666667, 11.0935483870968,
6.29333333333333, 5.63225806451613, 6.05483870967742, 6.38620689655172,
6.06774193548387, 9.36, 11.5612903225806, 16.6466666666667, 15.958064516129,
19.6677419354839, 14.8266666666667, 11.1870967741935, 8.52666666666667,
5.06129032258064)), row.names = c(NA, -84L), class = c("tbl_df",
"tbl", "data.frame"))
``````
``````suppressPackageStartupMessages({
library(forecast)
})

liters <- c(
7.21032258064516, 17.2285714285714, 76.3225806451613,
84.37, 215.516129032258, 431.293333333333, 745.207741935484,
539.334193548387, 655.362, 367.974193548387, 236.646666666667,
450.588387096774, 43.5716129032258, 66.04, 276.847741935484,
282.619333333333, 566.998709677419, 1095.84266666667, 1187.29161290323,
1726.45161290323, 1228.92, 655.529032258065, 746.288666666667,
2058.73548387097, 51.2283870967742, 215.889655172414, 440.936129032258,
546.156, 1347.63935483871, 1996.08933333333, 1990.58709677419,
2641.42451612903, 2540.032, 1096.66451612903, 422.928, 1732.26838709677,
71.0477419354839, 182.357142857143, 396.425806451613, 1027.65,
1599.73935483871, 3255.12866666667, 2865.75483870968, 3925.91612903226,
2232.9, 2148.5264516129, 873.73, 1782.78580645161, 354.518709677419,
15.81, 397.767096774194, 1355.744, 2438.12903225806, 3957.012,
5153.51612903226, 4435.99483870968, 3508.008, 1976.56516129032,
986.362, 3491.30322580645, 333.44, 359.325, 1176.71806451613,
1387.1, 1956.2064516129, 4006.08, 5792.94967741935, 6212.12903225807,
4270.84, 2047.86903225806, 714.922666666667, 3568.59870967742,
442.003225806452, 378.063448275862, 706.285161290323, 307.008,
712.175483870968, 2856.568, 2208.59612903226, 3378.91806451613,
2642.112, 1065.01161290323, 141.542666666667, 2720.94967741935
)

temp <- c(
4.50645161290323, 5.74285714285714,
7.33870967741935, 10.8166666666667, 12.6774193548387, 15.4033333333333,
19.4064516129032, 16.0516129032258, 15.83, 13.141935483871, 7.68333333333333,
4.65483870967742, 3.89032258064516, 3.175, 5.81612903225806,
7.55666666666667, 11.0741935483871, 14.0133333333333, 17.358064516129,
17.9838709677419, 13.3, 9.93225806451613, 9.54333333333333, 8.93548387096774,
3.28387096774194, 4.15172413793103, 4.80322580645161, 7.78, 13.6677419354839,
15.6433333333333, 17.4612903225806, 17.1967741935484, 17.4933333333333,
9.7741935483871, 5.34, 4.98064516129032, 1.55806451612903, 4.10714285714286,
7.45161290322581, 7.75, 13.6032258064516, 16.4566666666667, 17.058064516129,
16.7774193548387, 13.7833333333333, 12.9741935483871, 7.15, 4.6258064516129,
4.61612903225806, 0.221428571428571, 3.54516129032258, 10.8633333333333,
15.6290322580645, 15.93, 19.0870967741935, 18.0032258064516,
14.6533333333333, 12.1709677419355, 6.43, 6.06129032258064, 3.36129032258064,
5.70357142857143, 7.18387096774194, 9.7, 10.7483870967742, 17.12,
18.0129032258065, 18.2709677419355, 14.5266666666667, 11.0935483870968,
6.29333333333333, 5.63225806451613, 6.05483870967742, 6.38620689655172,
6.06774193548387, 9.36, 11.5612903225806, 16.6466666666667, 15.958064516129,
19.6677419354839, 14.8266666666667, 11.1870967741935, 8.52666666666667,
5.06129032258064
)

START <- c(2014, 1)
Fq <- 12

tsl <- ts(liters, start = START, frequency = Fq)

X1 <- 6 # length test set
X2 <- length(tsl) - (X1 - 1) # Length training set
Y <- 12 # Length forecast

reg1 <- ts(temp, start = START, frequency = Fq)
reg1training <- subset(reg1, end = length(tsl) - X1)
reg1test <- subset(reg1, start = X2)

lamb <- BoxCox.lambda(reg1training)

txt <- auto.arima(reg1training,
xreg = reg1training,
lambda = lamb, stepwise = FALSE
)

reg <- snaive(ts(temp, start=START,frequency=Fq))

forecast(reg, horizon = 3) %>% autoplot()
``````

1 Like

Not exactly what I'm trying to achieve.
I will clarify the problem.

I'm trying forecast the time series 'tsl', with the temperature (temp) of the previous year as a regression component. And with the best ARIMA orders, found using the training set.

With:

``````txt<-	auto.arima(training, xreg=reg1training,
lambda=lamb, stepwise=FALSE)

ntxt<-	Arima(tsl,
order=arimaorder(txt)[1:3],
seasonal=arimaorder(txt)[4:6],
lambda=lamb)
``````

And what i want to forecast is:

``````forecast(ntxt, xreg=snaive(temp,h=12))
``````

Or something like that.

Thanks!

It is just that ambiguity that a minimal reproducible example `reprex` is designed to clarify. Come back with a fully specified problem that includes all objects, starting with` training`. Less reverse engineering of the problem offers the possibilities of more attempts at an answer.

Okay lets try!

``````> dput(liters)
structure(list(Liters = c(93.6128027191616, 147.535759807393,
238.634754284096, 162.547797762357, 238.386914034839, 407.909644526271,
465.08993060473, 427.701458716896, 487.997450786008, 420.407874238776,
424.868998725393, 485.30661379408, 117.016003398952, 184.419699759241,
298.29344285512, 203.184747202946, 297.983642543549, 509.887055657839,
581.362413255913, 534.62682339612, 609.99681348251, 525.50984279847,
531.086248406741, 606.6332672426, 140.419204078742, 221.303639711089,
357.952131426144, 243.821696643535, 357.580371052259, 611.864466789407,
697.634895907095, 641.552188075343, 731.996176179012, 630.611811358165,
637.30349808809, 727.95992069112, 163.822404758533, 258.187579662937,
417.610819997168, 284.458646084124, 417.177099560969, 713.841877920974,
813.907378558278, 748.477552754567, 853.995538875513, 735.713779917859,
743.520747769438, 849.28657413964, 416, 665, 1137, 511, 1659,
1053, 804, 1097, 887, 990, 1638, 1045, 628, 1641, 2101, 2556,
4409, 3793, 3732, 3607, 5318, 4445, 6362, 8662, 1600, 1861, 3502,
1524, 665, 2675, 4600, 3376, 3578, 2439, 2000, 4000)), row.names = c(NA,
-84L), class = c("tbl_df", "tbl", "data.frame"))

> dput(temp)
structure(list(tempratuur = c(4.50645161290323, 5.74285714285714,
7.33870967741935, 10.8166666666667, 12.6774193548387, 15.4033333333333,
19.4064516129032, 16.0516129032258, 15.83, 13.141935483871, 7.68333333333333,
4.65483870967742, 3.89032258064516, 3.175, 5.81612903225806,
7.55666666666667, 11.0741935483871, 14.0133333333333, 17.358064516129,
17.9838709677419, 13.3, 9.93225806451613, 9.54333333333333, 8.93548387096774,
3.28387096774194, 4.15172413793103, 4.80322580645161, 7.78, 13.6677419354839,
15.6433333333333, 17.4612903225806, 17.1967741935484, 17.4933333333333,
9.7741935483871, 5.34, 4.98064516129032, 1.55806451612903, 4.10714285714286,
7.45161290322581, 7.75, 13.6032258064516, 16.4566666666667, 17.058064516129,
16.7774193548387, 13.7833333333333, 12.9741935483871, 7.15, 4.6258064516129,
4.61612903225806, 0.221428571428571, 3.54516129032258, 10.8633333333333,
15.6290322580645, 15.93, 19.0870967741935, 18.0032258064516,
14.6533333333333, 12.1709677419355, 6.43, 6.06129032258064, 3.36129032258064,
5.70357142857143, 7.18387096774194, 9.7, 10.7483870967742, 17.12,
18.0129032258065, 18.2709677419355, 14.5266666666667, 11.0935483870968,
6.29333333333333, 5.63225806451613, 6.05483870967742, 6.38620689655172,
6.06774193548387, 9.36, 11.5612903225806, 16.6466666666667, 15.958064516129,
19.6677419354839, 14.8266666666667, 11.1870967741935, 8.52666666666667,
5.06129032258064)), row.names = c(NA, -84L), class = c("tbl_df",
"tbl", "data.frame"))
``````

And the minimal code, up to the problem is:

``````data<-		read_excel("path to file")

START<-	c(2014,1) 		#Start maand data
Fq<-	12			    #Frequentie bij maandelijkse data

liters<-data[,"Liters"]
temp<-	data[,"Tempratuur"]
tsl<-	ts(liters, frequency=Fq, start=START)

X1<-	6			        #Lengte testdata
X2<-	length(tsl)-(X1-1)	#Lengte trainingsdata
Y<-	12			            #Lengte voorspelling

training<-	subset(tsl,end=length(tsl)-X1)
test<-		subset(tsl,start=X2)

lamb<-		BoxCox.lambda(training)

reg1<-		    ts(temp, frequency=Fq, start=START)
reg1training<-	subset(reg1, end=length(tsl)-X1)
reg1test<-	    subset(reg1, start=X2)

txt<-	auto.arima(training, xreg=reg1training,
lambda=lamb, stepwise=FALSE)

ntxt<-	Arima(tsl,
order=arimaorder(txt)[1:3],
seasonal=arimaorder(txt)[4:6],
lambda=lamb)

``````

And then i want to forecast the time series "tsl", with the temperature (temp) of the previous year as a regression component. And the "ntxt" as forecast model.

Thanks

Applying the output of one model to a another is beyond my ken. Here's what I'd do, instead

``````suppressPackageStartupMessages({
library(forecast)
library(ggplot2)
})

liters <- c(
7.21032258064516, 17.2285714285714, 76.3225806451613,
84.37, 215.516129032258, 431.293333333333, 745.207741935484,
539.334193548387, 655.362, 367.974193548387, 236.646666666667,
450.588387096774, 43.5716129032258, 66.04, 276.847741935484,
282.619333333333, 566.998709677419, 1095.84266666667, 1187.29161290323,
1726.45161290323, 1228.92, 655.529032258065, 746.288666666667,
2058.73548387097, 51.2283870967742, 215.889655172414, 440.936129032258,
546.156, 1347.63935483871, 1996.08933333333, 1990.58709677419,
2641.42451612903, 2540.032, 1096.66451612903, 422.928, 1732.26838709677,
71.0477419354839, 182.357142857143, 396.425806451613, 1027.65,
1599.73935483871, 3255.12866666667, 2865.75483870968, 3925.91612903226,
2232.9, 2148.5264516129, 873.73, 1782.78580645161, 354.518709677419,
15.81, 397.767096774194, 1355.744, 2438.12903225806, 3957.012,
5153.51612903226, 4435.99483870968, 3508.008, 1976.56516129032,
986.362, 3491.30322580645, 333.44, 359.325, 1176.71806451613,
1387.1, 1956.2064516129, 4006.08, 5792.94967741935, 6212.12903225807,
4270.84, 2047.86903225806, 714.922666666667, 3568.59870967742,
442.003225806452, 378.063448275862, 706.285161290323, 307.008,
712.175483870968, 2856.568, 2208.59612903226, 3378.91806451613,
2642.112, 1065.01161290323, 141.542666666667, 2720.94967741935
)

temp <- c(
4.50645161290323, 5.74285714285714,
7.33870967741935, 10.8166666666667, 12.6774193548387, 15.4033333333333,
19.4064516129032, 16.0516129032258, 15.83, 13.141935483871, 7.68333333333333,
4.65483870967742, 3.89032258064516, 3.175, 5.81612903225806,
7.55666666666667, 11.0741935483871, 14.0133333333333, 17.358064516129,
17.9838709677419, 13.3, 9.93225806451613, 9.54333333333333, 8.93548387096774,
3.28387096774194, 4.15172413793103, 4.80322580645161, 7.78, 13.6677419354839,
15.6433333333333, 17.4612903225806, 17.1967741935484, 17.4933333333333,
9.7741935483871, 5.34, 4.98064516129032, 1.55806451612903, 4.10714285714286,
7.45161290322581, 7.75, 13.6032258064516, 16.4566666666667, 17.058064516129,
16.7774193548387, 13.7833333333333, 12.9741935483871, 7.15, 4.6258064516129,
4.61612903225806, 0.221428571428571, 3.54516129032258, 10.8633333333333,
15.6290322580645, 15.93, 19.0870967741935, 18.0032258064516,
14.6533333333333, 12.1709677419355, 6.43, 6.06129032258064, 3.36129032258064,
5.70357142857143, 7.18387096774194, 9.7, 10.7483870967742, 17.12,
18.0129032258065, 18.2709677419355, 14.5266666666667, 11.0935483870968,
6.29333333333333, 5.63225806451613, 6.05483870967742, 6.38620689655172,
6.06774193548387, 9.36, 11.5612903225806, 16.6466666666667, 15.958064516129,
19.6677419354839, 14.8266666666667, 11.1870967741935, 8.52666666666667,
5.06129032258064
)

whole <- data.frame(liters,temp)
train  <- ts(whole[1:58,])
test <- whole[59:84,]
all_ts <- ts(whole, start = c(2014), frequency = 12)
test_ts <- ts(test, start = c(2018,11), frequency = 12)
train_ts  <- ts(train, start = c(2014,1), frequency = 12)
tslm_fit <- tslm(liters ~ temp, data = train_ts)

autoplot(all_ts) + theme_minimal()
``````

``````summary(tslm_fit)
#>
#> Call:
#> tslm(formula = liters ~ temp, data = train_ts)
#>
#> Residuals:
#>      Min       1Q   Median       3Q      Max
#> -1901.23  -482.62   -33.65   378.42  2557.63
#>
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)
#> (Intercept)  -425.51     273.41  -1.556    0.125
#> temp          158.30      23.05   6.868 5.73e-09 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 930.7 on 56 degrees of freedom
#> Multiple R-squared:  0.4572, Adjusted R-squared:  0.4475
#> F-statistic: 47.16 on 1 and 56 DF,  p-value: 5.725e-09

autoplot(train_ts) +
autolayer(fitted(tslm_fit), series="Fitted") +
xlab("Year") + ylab("") +
guides(colour=guide_legend(title=" ")) +
theme_minimal()
``````

``````checkresiduals(tslm_fit)
``````

``````#>
#>  Breusch-Godfrey test for serial correlation of order up to 12
#>
#> data:  Residuals from Linear regression model
#> LM test = 44.549, df = 12, p-value = 1.231e-05

fc <- forecast(tslm_fit, newdata = BoxCox(test, lambda = "auto"), h = 24)

autoplot(fc) + theme_minimal()
``````

``````accuracy(fc, test)
#>                        ME     RMSE      MAE        MPE      MAPE     MASE
#> Training set 2.086884e-14  914.552  668.842 -154.08863 281.94293 1.097699
#> Test set     1.002845e+03 1644.351 1150.569   12.52536  68.91025 1.888306
#>                   ACF1
#> Training set 0.7562458
#> Test set            NA
``````
1 Like

Thanks for the time and effort, but unfortunately it is not the right solution yet.

``````> dput(liters)
structure(list(Liters = c(93.6128027191616, 147.535759807393,
238.634754284096, 162.547797762357, 238.386914034839, 407.909644526271,
465.08993060473, 427.701458716896, 487.997450786008, 420.407874238776,
424.868998725393, 485.30661379408, 117.016003398952, 184.419699759241,
298.29344285512, 203.184747202946, 297.983642543549, 509.887055657839,
581.362413255913, 534.62682339612, 609.99681348251, 525.50984279847,
531.086248406741, 606.6332672426, 140.419204078742, 221.303639711089,
357.952131426144, 243.821696643535, 357.580371052259, 611.864466789407,
697.634895907095, 641.552188075343, 731.996176179012, 630.611811358165,
637.30349808809, 727.95992069112, 163.822404758533, 258.187579662937,
417.610819997168, 284.458646084124, 417.177099560969, 713.841877920974,
813.907378558278, 748.477552754567, 853.995538875513, 735.713779917859,
743.520747769438, 849.28657413964, 416, 665, 1137, 511, 1659,
1053, 804, 1097, 887, 990, 1638, 1045, 628, 1641, 2101, 2556,
4409, 3793, 3732, 3607, 5318, 4445, 6362, 8662, 1600, 1861, 3502,
1524, 665, 2675, 4600, 3376, 3578, 2439, 2000, 4000)), row.names = c(NA,
-84L), class = c("tbl_df", "tbl", "data.frame"))

> dput(temp)
structure(list(tempratuur = c(4.50645161290323, 5.74285714285714,
7.33870967741935, 10.8166666666667, 12.6774193548387, 15.4033333333333,
19.4064516129032, 16.0516129032258, 15.83, 13.141935483871, 7.68333333333333,
4.65483870967742, 3.89032258064516, 3.175, 5.81612903225806,
7.55666666666667, 11.0741935483871, 14.0133333333333, 17.358064516129,
17.9838709677419, 13.3, 9.93225806451613, 9.54333333333333, 8.93548387096774,
3.28387096774194, 4.15172413793103, 4.80322580645161, 7.78, 13.6677419354839,
15.6433333333333, 17.4612903225806, 17.1967741935484, 17.4933333333333,
9.7741935483871, 5.34, 4.98064516129032, 1.55806451612903, 4.10714285714286,
7.45161290322581, 7.75, 13.6032258064516, 16.4566666666667, 17.058064516129,
16.7774193548387, 13.7833333333333, 12.9741935483871, 7.15, 4.6258064516129,
4.61612903225806, 0.221428571428571, 3.54516129032258, 10.8633333333333,
15.6290322580645, 15.93, 19.0870967741935, 18.0032258064516,
14.6533333333333, 12.1709677419355, 6.43, 6.06129032258064, 3.36129032258064,
5.70357142857143, 7.18387096774194, 9.7, 10.7483870967742, 17.12,
18.0129032258065, 18.2709677419355, 14.5266666666667, 11.0935483870968,
6.29333333333333, 5.63225806451613, 6.05483870967742, 6.38620689655172,
6.06774193548387, 9.36, 11.5612903225806, 16.6466666666667, 15.958064516129,
19.6677419354839, 14.8266666666667, 11.1870967741935, 8.52666666666667,
5.06129032258064)), row.names = c(NA, -84L), class = c("tbl_df",
"tbl", "data.frame"))

START<-	c(2014,1) 		#Start maand data
Fq<-	12			    #Frequentie bij maandelijkse data

liters<-data[,"Liters"]
temp<-	data[,"Tempratuur"]
tsl<-	ts(liters, frequency=Fq, start=START)

X1<-	6			        #Length of test set
X2<-	length(tsl)-(X1-1)	#Length training set
Y<-	12			            #Lengte of forcast

training<-	subset(tsl,end=length(tsl)-X1)
test<-		subset(tsl,start=X2)

lamb<-		BoxCox.lambda(training)

reg1<-		    ts(temp, frequency=Fq, start=START)
reg1training<-	subset(reg1, end=length(tsl)-X1)
reg1test<-	    subset(reg1, start=X2)

txt<-	auto.arima(training, xreg=reg1training,
lambda=lamb, stepwise=FALSE)

ntxt<-	Arima(tsl,
order=arimaorder(txt)[1:3],
seasonal=arimaorder(txt)[4:6],
lambda=lamb)
``````

As far as i know the code is correct up to here.

But now i want to make a new time series, lets call it "nreg" to forecast "tsl".
The model I want to use to forecast is "ntxt".

Something like this:

``````ts_temp<-ts(temp, start=START, frequency=Fq)
nreg<-snaive(ts_temp, Y)
forecast(ntxt,xreg=nreg)
``````

Is this possible?

If so how?

Thanks

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.