3 Replies Latest reply on Mar 26, 2014 11:25 AM by jordan.bunker

    How do I perform a t-test using R?

    Chris Dunham

      I've created the following calculated field:


      script_real("ttest <- t.test(.arg1,.arg2,var.equal=T);ttest$p.value",sum([Rating]),sum([Competitor]))


      Rating and Competitor are each a vector of integers (1-10, stored as real)


      The R code is correct (it's simple and I've tested it). I am confused by the need to pass aggregated values to R. My function requires 2 vectors. I tried SUM, which produced wildly incorrect results, as I would expect. What is the work-around here?

        • 1. Re: How do I perform a t-test using R?

          Hi Chris,


          Since SCRIPT functions are table calculations, all measures within the formula must be passed as aggregates. If the calculation is occurring at the row-level of the data, you can use ATTR() to aggregate the measure for the purposes of the calculation.


          Hope that helps! Would love to hear back!


          - Jordan

          • 2. Re: How do I perform a t-test using R?
            Chris Dunham



            Thank you for the answer. I am having a hard time figuring out what I need to do here. As I understand it, there is no way to perform this type of test as R does it - by taking in 2 vectors, calculating a mean, standard deviation, etc., then producing a p-value.


            Would I have to calculate the various inputs above in Tableau and create a custom function in R to give the p-value? (this is more complex than I'd like this process to be). The issue with trying to do everything in Tableau is that it's not possible to reference a t-distribution, as you can in Excel with TINV(confidence level, degrees of freedom) to attain a critical value for comparison.


            If there is some workaround in Tableau to pass a vector into R, I would love to learn the trick.



            • 3. Re: How do I perform a t-test using R?

              Hey Chris,


              To be very honest, I'm not very familiar with R, and my stats knowledge is limited, however the following blog post by Bora Beran contains a workbook that demonstrates using R to perform a t-test and calculate an R value:


              Statistical testing in Tableau with R « Bora Beran


              Downloading the workbook and playing with it might get you started in the right direction. Good luck!


              - Jordan