2

I am new in Tableau, I am trying to write R Script for ARIMA model but I am getting error.

I wrote this code

SCRIPT_REAL("
    library(forecast)
    data <- ts(.arg2,start=c(2003,1),frequency=12);
    ARIMAfit <- auto.arima(log10(data),approximation=FALSE,trace=FALSE);
    fcast <- forecast(ARIMAfit,h=5);

",

ATTR( MONTH( [New] ) ), SUM( [Number of Tractor Sold] ) )

Tableau is showing The "calculation is valid" but once I am trying to plot my predicted result its showing..

the result returned by the script function is of an unexpected type

Any kind of help or snipped code will be very helpfull for me. Thanks...

anindya
  • 61
  • 1
  • 12
  • You probably need to return the result as the last line of your result. So just add an fcast at the bottom. – lmkirvan Jun 17 '16 at 11:19
  • @lmkirvan can you please show me how to add fcast at bottom of the code? it will be very helpful for me as I am completely new in tableau script. – anindya Jun 17 '16 at 11:25
  • I'm on my phone but I believe you are return to tableau the last line of your code which is an assignment statement. You want to return the actual vector of numbers that you assign. So simply add a line that would print the vector to the console. Here I think you've saved it as fcast (or some part of the fcast object). – lmkirvan Jun 17 '16 at 11:32
  • let me know if that doesn't work and I'll test when I'm in front of a computer. – lmkirvan Jun 17 '16 at 12:07
  • @lmkirvan no its not working.Thanks.. – anindya Jun 17 '16 at 12:17
  • result of `forecast` is an object of class forecast so no known by Tableau. You must return something numeric so I guess ` forecast(ARIMAfit,h=5)$fitted` for the forecasts themselves – Eric Lecoutre Jun 17 '16 at 14:43
  • You seen this [link](http://stackoverflow.com/questions/20210504/r-times-series-arima-model-forecasting-daily-data?rq=1) – vhadalgi Jun 21 '16 at 05:58

1 Answers1

0

Try this it will work;

SCRIPT_REAL("
    library(forecast)
    data <- ts(.arg1,start=c(2003,1),frequency=12);
    ARIMAfit <- auto.arima(log10(data),approximation=FALSE,trace=FALSE);
    fcast <- forecast(ARIMAfit,h=5);", SUM( [Number of Tractor Sold] ) )

Also if you want you can add rmse and mae results -

please find example below-

SCRIPT_STR(
"rmse <- function(error){    sqrt(mean(error^2))} 
mae <- function(error){    mean(abs(error))}
tsfa1 = ts(.arg1,frequency=12,start = c(2012,6))

library(forecast)
fit1 = Arima(tsfa1, order=c(0,0,0),seasonal=c(1,1,0), include.mean = FALSE,include.drift=TRUE)
fcast<- forecast(fit1)
paste(fcast$fit, fcast$residuals, sep='~')",SUM([NET]))
Matt
  • 74,352
  • 26
  • 153
  • 180
girish
  • 56
  • 2