Qlik Community

Qlik Server Side Extensions Discussions

Discussion Board for collaboration on Server-Side Extensions and Advanced Analytics Integration.

Not applicable

R integration: time series forecast append

Hi everyone,

I am trying to append a forecasted time series to a line chart of closing values for a stock. Qlik Sense gives me  'erroe: client specified an invalid argument'. I don't understand what I'm getting wrong. Many thanks for your help.

R.ScriptEval('library(forecast);data<-ts(na.omit(q$Variable1),frequency=1);fit<-auto.arima(data); res<-forecast(fit, level=0.95, h=q$vForecastPeriods); n <- length(q$Variable1); fore <- append(q$Variable1[(q$vForecastPeriods - 1):n],res$mean,after= n - q$vForecastPeriods); $fore;', Sum(Close) as Variable1, vForecastPeriods) 

Tags (3)
1 Solution

Accepted Solutions
bvk
Contributor II

Re: R integration: time series forecast append

Hi Stan,

First, you're using a variable in your expression, you may want to try:

R.ScriptEval('library(forecast);'&

    'data<-ts(na.omit(q$Variable1),frequency=1);'&

    'fit<-auto.arima(data);'&

    'res<-forecast(fit, level=0.95, h=q$vForecastPeriods); '&

    'n <- length(q$Variable1); '&

    'fore <- append(q$Variable1[(q$vForecastPeriods - 1):n],res$mean,after= n - q$vForecastPeriods); '&

    '$fore;',

    Sum(Close) as Variable1,

    $(vForecastPeriods) as  vForecastPeriods )



Second, to help you in troubleshooting check the logs for SSE2Rserve, this should give you an indication of what is wrong in the script.


Regards,

Bas

6 Replies
bvk
Contributor II

Re: R integration: time series forecast append

Hi Stan,

Currently, the R extension expects the same number of rows as a result. So you will need to add empty rows for the forecast values into the data that you send to R.

Regards,

Bas.

Not applicable

Re: R integration: time series forecast append

Hi Bas,

Thanks for the advice. I thought that's exactly what I'm doing above: sending in TS to R with its original length and retrieving TS - ForecastPeriods + Forecasts. Further thoughts are appreciated.

bvk
Contributor II

Re: R integration: time series forecast append

Hi Stan,

First, you're using a variable in your expression, you may want to try:

R.ScriptEval('library(forecast);'&

    'data<-ts(na.omit(q$Variable1),frequency=1);'&

    'fit<-auto.arima(data);'&

    'res<-forecast(fit, level=0.95, h=q$vForecastPeriods); '&

    'n <- length(q$Variable1); '&

    'fore <- append(q$Variable1[(q$vForecastPeriods - 1):n],res$mean,after= n - q$vForecastPeriods); '&

    '$fore;',

    Sum(Close) as Variable1,

    $(vForecastPeriods) as  vForecastPeriods )



Second, to help you in troubleshooting check the logs for SSE2Rserve, this should give you an indication of what is wrong in the script.


Regards,

Bas

Not applicable

Re: R integration: time series forecast append

Hi Bas,

Many thanks. It was solved by


$(vForecastPeriods) as  vForecastPeriods


However, I received error with $fore. I just took that $ out of your code and it worked like a charm.


Thanks again!


PS. Any ideas on how to integrate a fan chart are welcome. 

Partner
Partner

Re: R integration: time series forecast append

Hi Stan,

Can i have your sample for this? im facing difficulties of mapping back the appended value back with dimension.

Thanks.

namrata_nm
New Contributor

Re: R integration: time series forecast append

Hi Bas,

I am a beginner in Qlik and R.

As you mentioned, that we need need to add empty rows for the forecast values that is sent to R, can you please let me know how can that be done ? And wont it hamper the other visualizations in Qlik ?

Thanks in Advance.

Regards,

Namrata