Your R script is indeed a Table Calculation that works
on a view with a granularity of the dimensions combination:
[Patient Type] - [Hospital] - [Unique Patient Visit Identifier].
One should retain the same granularity on each view
to get the results as expected -- even if a particular field,
say [Unique Patient Visit Identifier], doesn't need to be shown.
Further aggregating (averaging) the results returned from R
requires Nested Table Calculations. Moreover, a subsequent
Table Calc Filter is required to show only one Mark on a view
per Patient Type & Hospital.
Please find the attached wb.
Hope it could help.
Thanks Yuri! Still don't get the use of the If First() == 0 function but it seems to have worked. Thanks again.
if first()==0 ... is a Table Calculation Filter (inside a calculation itself),
which effectively filters only the first row in a Table Calc Partition.
A Partition is defined by every unique value combinations
of all Dimensions on a view, which are not included in Addressing
(so they stay on the Partitioning) for a particular Table Calculation.
Hope this helps.
Thanks Yuri, makes sense. Last quick question if I may...apologies again for being a bit of a newbie with R so not sure about how to do certain things. Here's my GLM Model Script in Tableau that Predicts Admissions based on several predictor variables. In the script below, how do I output the results, ie odds ratios, standard errors and coefficients into an external file...say an Excel or CSV File. I've seen the function Write in R but I've tried it a few times and can't get the syntax to work. If you could add the necessary code below to export the results to a file called summary.csv on my C Drive, that would be great!
admitstatus <- .arg1
age <- as.factor(.arg2)
triagecode <- as.factor(.arg3)
cci_score <- .arg4
gender <- as.factor(.arg5)
fit <- glm(admitstatus ~ age + triagecode + cci_score + gender,family = binomial(logit))
prob <- predict(fit,type = 'response')
avg([Admit Status] ),attr([Age Group]),attr([Triagecode]), avg([Cci Score Without Age]), ATTR([Gender])