I am trying to use a dataset with no null values to use in logistic regression model in tableau integrated with R
I tried to create calculated fields using this code:
SCRIPT_REAL('mydata <- data.frame(Am=.arg1, Mpg=.arg2, Cyl=.arg3);
model <- glm(Am ~ Mpg + Cyl, data = mydata, family = binomial(logit));
prob <- predict(model,type = "response")',
AVG(FLOAT([Am])),AVG([Mpg]),AVG([Cyl]))
Am: the values are either manual or automatic, Mpg and Cyl are decimal values such as 25.6, 37.45,..
when I tried it shows to me the error message shown in the picture
First of all, I would need to convert the values in Am column to binary, such as "manual" = 0 and "automatic" = 1. to be able to do so I have to create another calculated field and name it Am_m and it is as the following:-
IF [Am]='Manual'
THEN "0"
ELSE "1"
END
then a small modification I have to do in the above-mentioned code as the following:-
SCRIPT_REAL('mydata <- data.frame(Am_m=as.numeric(.arg1), Mpg=.arg2, Cyl=.arg3, Hp=.arg4, Wt=.arg5);
Logistic_reg <- glm(Am_m ~ Mpg + Cyl + Hp + Wt, data = mydata, family = "binomial");
glmm <- predict(Logistic_reg, newdata = mydata, type = "response")',
AVG(FLOAT([Am_m])),AVG([Mpg]),AVG([Cyl]),AVG([Hp]),AVG([Wt]))
which is converting Am_m to be numeric.