0

I am able to forecast using Forecast() function in tableau. I have daily hourly data(demand electricity). Previously i was using following code:

SCRIPT_REAL("library(forecast);
    jjearnts <- msts(.arg1, seasonal.periods=c(24, 7*24, 365*24));
    fit <- tbats(jjearnts);
    fcast <- forecast(fit,h=.arg2[1]);
    n<-length(.arg1);
    append(.arg1[(.arg2[1]+1):n],fcast$mean, after = n-.arg2[1])",
    SUM([ Load demand(electricity)]),[ Parameter])

The above code works but it lacks some dummy predictors. So i tried following code:

SCRIPT_REAL("library(forecast);
    modelfitsample <- data.frame(.arg1,Weekday=rep(1:7,7);
    xreg <- cbind(Weekday=model.matrix(~as.factor(modelfitsample$Weekday));
    xreg <- xreg[,-1];
    colnames(xreg) <- c("Mon","Tue","Wed","Thu","Fri","Sat");
    jjearnts <-ts(modelfitsample$.arg1,frequency=24*365,start=c(2008,90));
    fcast <- forecast(jjearnts, h=.arg2[1]);
    n<-length(.arg1);
    append(.arg1[(.arg2[1]+1):n],fcast$mean, after = n-.arg2[1])",
    SUM([Load demand(electricity)]),[ Parameter])

This code is not working

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Thanks for editing....i am waiting for reply :( – peter stockel Jul 04 '15 at 08:14
  • To run a second code is very important to me ...Help me guys!! – peter stockel Jul 04 '15 at 11:36
  • (1) Do you get an error msg or what's "not working"? (2) You should provide a dataset, so that people can reproduce the error and play with the code. – lukeA Jul 04 '15 at 15:28
  • I have no issue to share the data...actually the second code is not correct so i was unable to run....i have hours of 4 year data...by seeing second code any expert can easily find the mistakes... – peter stockel Jul 04 '15 at 16:46
  • Well, seems not. Or do you see any answers? Maybe you have to escape the `"`s -> `c(\"Mon\"...)` or make it `c('Mon'...)`. The people who you call experts probably don't use Tableau... – lukeA Jul 04 '15 at 17:00
  • Yes..u r right They use R...i asked the same question to Tableau community they replied"code is related to R not of tableau" actually i am simply read some functions of R and do them in tableau..i dont know who will ans this........pls share yr email id so i can share u data – peter stockel Jul 04 '15 at 17:40
  • lukeA i made the correction"mon" >'mon'....now code is valid when i run i find "Error in base::parse(text = .cmd) : :2:58: unexpected ';' 1: library(forecast); 2: modelfitsample <- data.frame(.arg1,Weekday=rep(1:7,7); ^" – peter stockel Jul 04 '15 at 18:08
  • make it `data.frame(.arg1,Weekday=rep(1:7,7));` (missing bracket). – lukeA Jul 04 '15 at 18:15
  • ok..after adding bracket...still prompting "Error in base::parse(text = .cmd) : :3:75: unexpected ';' 2: modelfitsample <- data.frame(.arg1,Weekday=rep(1:7,7)); 3: xreg <- cbind(Weekday=model.matrix(~as.factor(modelfitsample$Weekday)); ^" – peter stockel Jul 04 '15 at 18:34
  • There's another missing bracket: `cbind(Weekday=model.matrix(~as.factor(modelfitsample$Weekday)));` – lukeA Jul 04 '15 at 19:07
  • lukeA finally code is running..but results us showing constant value..to simplfy this i take day wise data for 4 years and giving f=52 ,.and my code is SCRIPT_REAL("library(forecast); modelfitsample <- data.frame(.arg1,Weekday=rep(1:7,400)); xreg <- cbind(Weekday=model.matrix(~as.factor(modelfitsample$Weekday))); xreg <- xreg[,-1]; jjearnts <-ts(modelfitsample$.arg1,frequency=52,start=c(2006,90)); fcast <- forecast(jjearnts, h=.arg2[1]); n<-length(.arg1); append(.arg1[(.arg2[1]+1):n],fcast$mean, after = n-.arg2[1])", SUM([demand]),[PeriodsToForecast]) – peter stockel Jul 05 '15 at 07:49
  • this also results constant pattern for long time...i am unable to attach file or image........i thought provinding (1:7,7) will give day wise data to mon tues wed thr...sat sundy....it will recognize weeknd pattern but where is the problem i dont know?? – peter stockel Jul 05 '15 at 08:06
  • Forget about Tableau for a moment. I recommend you to upload yor data set, or a sample of it enough to reproduce your problem to dropbox or th. Or point to a similar data set on the web - there are several electricity data sets. Then open up a new question describing your new problem to the R folks using a [reproducible example code](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). (I.e. ready to copy/paste + run + throw your error). Chances are low to get answers without reproducible code... I know you don't want to share the data, but anyway.. – lukeA Jul 05 '15 at 09:16
  • i can share u ..provide yr email id... – peter stockel Jul 05 '15 at 09:23
  • I've no issue in sharing my email address. Besides I got not much experience in forecasting time series data. So again: Post a reproducible example with sample data publicly and get used to the SO habbits. Or accept getting no answers here. It's as simple as that. – lukeA Jul 05 '15 at 09:27

0 Answers0