Replication of chisq.test function in Tableau with R
Adrian Gigi Dec 14, 2018 6:11 AM@@@Hi there,
1. Tableau version 2018.3
2. Packaged workbook included (also some screenshots)
3. "Finally, and you might have seen this comment elsewhere, forget Excel. Don't try to make Tableau behave like Excel. They are very different paradigms. If you want Excel behavior, use Excel!"
 I know and you're definitely right, but I have to know if it's possible!
I'm very new to Tableau and have limited to zero statistical knowledge. But I'm with my back against the wall and after a few days of hard work trying to figure this out, so I desperately need help.
What I have to do is to replicate an Excel chisq.test formula in Tableau. I read in this forum the solutions proposed by @Bora Beran and @Scott Tennican and I looked over their examples (and others), but can't adapt them to my needs.
I need a formula for the pvalue field in the attached workbook. Right now in there is an R script which doesn't work (although testing it in RGui with raw numbers gives the same results as Excel, this is why I took this path), but I'm happy with any other solution. Also, I don't need the intermediate fields (obs_yes, obs_no, exp_yes, exp_no), I just tried to have as many check points as possible (and they match with the Excel values, but I have a felling that it has to be done with a different approach).
This is the existing R script, which returns NaN for all rows:
SCRIPT_REAL("
obs_yes = .arg1;
obs_no = .arg2;
exp_yes = .arg3;
exp_no = .arg4;
if ( !is.na(obs_yes) && !is.na(obs_no) && !is.na(exp_yes) && !is.na(exp_no)) {
ChiSq = chisq.test(c(obs_yes,obs_no), p=c(exp_yes,exp_no), rescale.p=TRUE);
ChiSq$p.value;
} else {
{NaN};
}
"
,[obs_yes],[obs_no],[exp_yes],[exp_no])
Any help / encouragement / good word is welcomed, as I said I'm really down now...
Thank you for your time!
Adrian

test.twbx 23.8 KB

tableau_R_chisq.test_formula.PNG 30.7 KB

tableau.PNG 93.9 KB

excel_R_chisq.test.PNG 41.6 KB

excel_formulas.PNG 81.8 KB