3 Replies Latest reply on Jan 6, 2020 10:11 AM by Nathan Mannheimer

    Rserve Error: "expected 4 values; 0 values were returned."

    Kate Bulger

      I am trying to use R to calculate the Fisher's Test on two proportions.

       

      My calculation is :

       

      SCRIPT_real

      (

      '

      PassMatrix <- matrix(c(.arg1,.arg2, .arg3, .arg4), nrow = 2)

      results <- fisher.test(PassMatrix, workspace = 2e5, simulate.p.value=TRUE)

      as.numeric(unname(results$estimate));

      '

      ,[Total Passing from reference] //window_max

      ,[Total Model Passing Interviews] //arg2

      ,[Total Not Passing from reference] //window_max

      ,[Total Model Not-Passing Interviews] //arg4

      )

       

      The calculations being passed as parameters all work (they are in the view to confirm). However, I am getting the following error:

       

      Unexpected number of results returned by SCRIPT function. Function expected 4 values; 0 values were returned.

       

      Any ideas? The code works in R (you need to run install.packages("exact2x2") to use fisher.test).

       

      Thanks!

        • 1. Re: Rserve Error: "expected 4 values; 0 values were returned."
          Nathan Mannheimer

          Hi Kate,

           

          It's a little difficult to say without seeing your specific visualization, but what I suspect is happening here is that the aggregation in the viz is causing different data to be sent to R than in the normal R code, resulting in no values being returned. What do you see if you write your final return value in your code out to a CSV?

           

          Also if you can share the viz or workbook that would be helpful too.

           

          Sincerely,

          Nathan

          • 2. Re: Rserve Error: "expected 4 values; 0 values were returned."
            Kate Bulger

            Hi Nathan-

             

            So I pivoted and tried this in Python (using scipy's fisher test) and am getting an error as well. It's interesting, if I just write in raw numbers, the calculation works.

             

            e.g.:

             

            SCRIPT_REAL(

            "

            import scipy.stats as stats

            oddsratio, pvalue = stats.fisher_exact(([[8, 2], [1, 5]]))

            return pvalue

            "

            ,sum([Profit])

            ,sum([Profit])

            ,sum([Profit])

            ,sum([Profit])

            )

            But, if I actually try to pass aggregate measures (in this example sum([Profit]) into the table, I get this error

            "Error processing script

            ValueError : The input `table` must be of shape (2, 2)."

             

            e.g.

            SCRIPT_REAL(

            "

            import scipy.stats as stats

            oddsratio, pvalue = stats.fisher_exact(([[_arg1, _arg2], [_arg3, _arg4]]))

            return pvalue

            "

            ,sum([Profit])

            ,sum([Profit])

            ,sum([Profit])

            ,sum([Profit])

            )

            Using just the Sample Super Store data source.

            • 3. Re: Rserve Error: "expected 4 values; 0 values were returned."
              Nathan Mannheimer

              Ah the issue here is that the variables from Tableau are being passed as a Python list or R vector. You need to extract the values from these data structures with an index ie this will work:

               

              SCRIPT_REAL(

              "

              import scipy.stats as stats

              oddsratio, pvalue = stats.fisher_exact(([[_arg1[0], _arg2[0]], [_arg3[0], _arg4[0]]]))

              return pvalue

              "

              ,sum([Profit])

              ,sum([Profit])

              ,sum([Profit])

              ,sum([Profit])

              )