Hello,
I'm trying to do some forecasting that goes beyond Tableau's built in forecasting capabilities but running into some problems. When I apply this formula (bold is the important part):
SCRIPT_STR("library(forecast);
predict_data <- .arg1;
log_ts <- ts(log(predict_data),frequency=52);
diff_ts=diff(log_ts); ⌗make data stationary
length=length(diff_ts)-1;
predict_data2=diff_ts[1:length]; ⌗ignore latest y count
regressors=data.frame(summer=.arg2[2:(length+1)],fall=.arg3[2:(length+1)], winter=.arg4[2:(length+1)], nwd=.arg5[2:(length+1)]); # get explanatory variable data
xreg=cbind(summer=model.matrix(~as.factor(regressors$summer)),fall=regressors$fall, winter=regressors$winter, nwd=regressors$nwd); ⌗make matrix of explanatory variables
xreg=xreg[,-1]; ⌗exclude intercept
modArima=auto.arima(predict_data2,xreg=xreg); ⌗dynamic regression model
season=strsplit(.arg6, ",")[[1]]; ⌗create vector of dummy variables from [Season] string season.num=as.numeric(season); ⌗convery dummy variables to numeric x=append(season.num, min(.arg7); ⌗append dummy variables with [# of NWD] for prediction vector
mat=matrix(x,nrow=1); ⌗xreg requires matrix
fcast=forecast(modArima,xreg=mat,h=1);
paste(predict_data[(length-1)]exp(fcast$lower)[1,1],predict_data[(length-1)]exp(fcast$upper)[1,1],sep='~') ⌗transform back and grab 80 PI", sum([y]),sum([Summer]),sum([Fall]),sum([Winter]),sum([NWD]),[Season],[# of NWD])
I get this error:
Error in base::parse(text = .cmd) : <text>:12:0:unexpected end of input
10: modArima=auto.arima(predict_data2,xreg=xreg); ⌗dynamic regression model
11: season=strsplit(.arg6,
^
[Season] is a string parameter that can take on the value of "0,0,0" "0,1,0" "1,0,0" or "0,0,1". What is weird to me is that when I try out the bolded part of the script in R, I have no issues at all.
Anyone know what could be causing the problem in Tableau? Thanks!
Sorry I can not post a workbook as the data is private.
It looks like you might have a problem with your Parameter actually being a vector of duplicate values like this question Re: Problem passing string parameter to R. But, I'd need a workbook to be sure.
Does your forecast work if you hard code Season rather than pass a parameter?
