4 Replies Latest reply: Nov 2, 2017 4:35 AM by Adam Karolewski RSS

    Regression function and r squared

    Santana Ngantcheu


      do you know how to write a regression function and the r squared of the regression in the new Qlik Sense 3.2 SR3?

      The way I used to do it in the old version is not working anymore.

      The following is how i used to write the regression function.

      R.ScriptEval('fitted.values(lm(.arg2 ~ .arg1))' , RegInnen, Avg(ADI_Skaliert))




        • Re: Regression function and r squared
          Sunny Talwar

          This was something which worked for you in Qlik Sense?

          R.ScriptEval('fitted.values(lm(.arg2 ~ .arg1))' , RegInnen, Avg(ADI_Skaliert))

          • Re: Regression function and r squared
            Adam Karolewski

            I confirm Rodolfo answer. The result however depends where you want to have your number - in table, chart per each row of the data or in text box (recommended). In tabel or in chart you need to use rep function to repeat it in every row:

            R.ScriptEval('rep(summary(lm(q$Invest ~ q$RegInnen))$r.square,length(q$RegInnen))' , Avg(ADI_Skaliert) as Invest, RegInnen). This is my result for some numbers:

            In text box you shall qoute it like this (I hope it works but I do not know exact form of your data below):

            Aggr(R.ScriptEval('rep(summary(lm(q$Invest ~ q$RegInnen))$r.square,length(q$RegInnen))' , Avg(Total <RegInnen> ADI_Skaliert) as Invest, RegInnen),RegInnen)


            And last, why not to use qlik function LINEST_R2? In this case it might work (for fitted values R is more comfortable).