I'm attempting to connect Tableau to a logistic regression I've run in R. It works in R, but I cannot get the code to work in Tableau.
The specific error is: "Error in base::parse(text = .cmd) : :1:32: unexpected symbol 1: dat <- data.frame(DEP_VAR=.arg1, IND_VAR1 ^"
Tableau script:
SCRIPT_REAL('dat <- data.frame(DEP_VAR=.arg1, IND_VAR1=.arg2,
IND_VAR2=.arg3, IND_VAR3=.arg4);
model <- glm(DEP_VAR~IND_VAR1+IND_VAR2+IND_VAR3, data =
dat, family = binomial(link = "logit"));
prob <- predict(model,newdata=dat,type="response")',
AVG([DEP_VAR]), AVG([IND_VAR1]), AVG([IND_VAR2]), AVG([IND_VAR3]))
Any help is very much appreciated.
Thanks, B
OK, so I figured it out after much trial and tribulation :D
I was messing around with different R scripts, just to see if I could get them to work in Tableau. I got a linear regression to work and noticed I needed to specify that the values I wanted to bring into Tableau were the "fitted.values" output from the function. I applied this to my logistical regression and was able to make it work. The script from Tableau is as follows:
SCRIPT_REAL('
model <- glm(DEP_VAR~IND_VAR1+IND_VAR2+IND_VAR3, family = binomial(link =
"logit"));
model$fitted.values
',
AVG([DEP_VAR]), AVG([IND_VAR1]), AVG([IND_VAR2]), AVG([IND_VAR3]))
So simple! I feel a bit foolish, but I'm very new to R, so I don't blame myself too much :)