Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
HSPrim
Contributor
Contributor

Forecasting with ARIMA models in Qlikview using SSE-R plugin

I installed the SSE-R plugin and it works in the R_BasicExample file in the plugin directory.

Now I'm trying to use the plugin to forecast revenue.

I've got a chart in Qlikview which displays the transaction revenue per week with the following expression: 

 

SUM([Transaction Revenue])

 

The required code in R to make a forecast:

 

Revenue.ts = ts(Transaction_Revenue, start=c(2016,1), end=c(2018,52), frequency = 52)
Revenue.arima = auto.arima(Revenue.ts)
Revenue.fc = forecast(Revenue.arima, h=52)

Now the question: How do I make the predictions in Qlikview, using the R script? Github gives the following function setup: 

<EngineSSEName>.<FunctionName>(Script [,Parameter...])

But I'm unsure what is needed to get this working. Do I need to place this code in the expression of the graph or in the script of the document? Is there any other code needed to get this working?

Hopefully someone is able to help me. If you need more information, please tell me.

Thanks in advance.

 

Labels (6)
1 Reply
Billpete002
Contributor II
Contributor II

Hi,

I figured out how to do this so hopefully this helps you and others who are attempting at unlocking the power of R in QS:

//Using the Airline Passengers data from R:

R.ScriptEval(
'library(dplyr);'&
'library(forecast);'&
'data = ts(na.omit(q$Measure),start = c(1949, 1), end = c(1960, 12), frequency = 12);' &
'fit = auto.arima(data);' &
'res = forecast(fit, level = 0.95, h = $(Flights));' &
'resmean <- as.double(res$mean);' &
'results <- append(data, resmean);' &
'results',
Sum(Passengers) as Measure,
TravelDate as TravelDate
)

 

This will produce the MEAN of the ARIMA. You will need to change as.double(res$mean) if you want to user the UPPER or LOWER results from the ARIMA. The reason for the append is to keep it within the same chart and at the same time period. Simply organize which how your data is displayed (first/last) will determine which lines are shown. If you have removed 0 values the actuals line will stop (in my case) at December 1960 for the forecast lines to work.

One thing I am still working on is making the dates variables so when someone selects different time periods the forecast still works.

Some notes I have found from this exercise:

It is important to use the & symbol whenever you produce a new line of code in QLIK otherwise it WILL NOT WORK! Even if the validator says it is OK!

QLIKSENSE needs something to be returned in a format that it recognizes so I have changed the output to a double. Otherwise nothing got returned at Qlik didn't know how to interpret the results.