error in Time series with random drift

Hello,

I wanted to check the forecast data by using training and test method using random walk with drift method. however i received an error

###########Splitting data into training and test data sets############
TS_Train <- window(FCL_forecasttimeseries, start=c(2012,14), end=c(2017,24), freq=24)

TS_Test <- window(FCL_forecasttimeseries, start=c(2018,1), freq=24)

TS_Train
TS_Test

autoplot(TS_Train, series = "Train")+ autolayer(TS_Test, series = "Test") + ggtitle("FCL rates Training & Test data") + xlab("periods")+ylab("Rates")+ guides(colour=guide_legend(title = "Forecast"))

#############FORECASTING MAEHODS ############
###########R1.Random walk with drift forecasting (using Log value) for Test & Training data#########

fit_decomposelog <- stl(log10(TS_Train), s.window = "p")
fit_decomposelog
TS_Train_stl <- forecast(fit_decomposelog, method = "rwdrift", h=36) ##### (h=36)No. of periods that you want to forecast######
plot(TS_Train_stl)
TS_Train_stl

########Accuracy measures: RMSE and MAPE using RWD#########
vec2 <- 10^(cbind(log10(TS_Test), as.data.frame(forecast(fit_decomposelog, method = "rwdrift", h=36)[,1])))

the error states:
Error in forecast(fit_decomposelog, method = "rwdrift", h = 36)[, 1] :
incorrect number of dimensions

Can you please help me with this

thank you

Sachin

Hi @SachinNataraj,
Looks like your right parentheses are not in the correct position to extract the first column of the data frame. Try this:

vec2 <- 10^(cbind(log10(TS_Test), 
                  as.data.frame(forecast(fit_decomposelog, 
                                         method = "rwdrift",
                                         h=36))[,1]))

HTH

Hi @DavoWW

I received new error
Error in .cbind.ts(list(...), .makeNamesTs(...), dframe = FALSE, union = TRUE) :
non-time series not of the correct length

Have a look at the size (length, number of rows) of your intermediate objects to see if they match. People on this forum can't do that because we don't have your data.
HTH

is there any way i can share the data?

You can run
dput(FCL_forecasttimeseries)
and then copy/paste the output here. BUT, have you checked those intermediate structures to see if the answer is obvious....?

here is the data

dput(FCL_forecasttimeseries)
structure(c(869L, 869L, 869L, 869L, 869L, 869L, 739L, 739L, 771L,
771L, 771L, 771L, 719L, 719L, 719L, 719L, 724L, 724L, 741L, 741L,
667L, 667L, 673L, 673L, 615L, 615L, 725L, 725L, 605L, 605L, 592L,
592L, 518L, 512L, 512L, 515L, 515L, 508L, 508L, 508L, 508L, 508L,
508L, 654L, 654L, 651L, 651L, 660L, 660L, 659L, 512L, 512L, 512L,
512L, 533L, 533L, 553L, 553L, 637L, 557L, 557L, 557L, 557L, 576L,
576L, 620L, 620L, 581L, 581L, 603L, 603L, 583L, 583L, 591L, 591L,
581L, 581L, 592L, 592L, 535L, 401L, 401L, 401L, 401L, 401L, 401L,
409L, 409L, 409L, 409L, 409L, 369L, 369L, 367L, 367L, 352L, 352L,
306L, 306L, 292L, 292L, 293L, 293L, 291L, 291L, 269L, 269L, 268L,
268L, 296L, 296L, 306L, 306L, 452L, 452L, 443L, 590L, 897L, 991L,
1591L, 1591L, 1537L, 1331L, 1325L, 1250L, 1226L, 1050L, 1050L,
875L, 875L, 862L, 736L, 685L, 516L, 741L, 698L, 516L, 696L, 515L,
689L, 751L, 580L, 537L, 537L, 537L, 537L, 576L, 576L, 576L, 540L,
540L, 557L, 557L, 556L, 556L, 514L, 483L, 517L, 429L, 429L, 429L,
429L, 439L, 439L, 442L, 442L, 414L, 414L, 739L, 771L, 771L, 771L,
771L, 719L, 719L, 719L, 719L, 358L), .Tsp = c(2012.54166666667,
2019.91666666667, 24), class = "ts")

yes i have checked the intermediate structure is correct.

Alli want to see is that to compare the forecasted data and the actual data.

@DavoWW

here is the decompose code

########Decompose with ERROR bar (if Trend & seasonality is significant or not)#############
fit_decomposelog <-stl(log10(FCL_forecasttimeseries),s.window = "periodic" )
plot(fit_decomposelog)

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