
Re: Regression function and r squared
Sunny Talwar May 3, 2017 8:45 AM (in response to Santana Ngantcheu )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
Santana Ngantcheu May 3, 2017 8:50 AM (in response to Sunny Talwar )yes that worked for me.
but it is much easier with the new version of Qlik sense.
now i've got this
R.ScriptEval('lm(q$Invest ~ q$RegInnen)$fitted' , Avg(ADI_Skaliert) as Invest, RegInnen)
and it works perfectly. The only problem is that I am not able to extract the r squared of the regression for this regression
Regrads
Santana

Re: Regression function and r squared
Rodolfo Souza Nov 1, 2017 2:20 PM (in response to Santana Ngantcheu )try:
R.ScriptEval('summary(lm(q$Invest ~ q$RegInnen))$r.square' , Avg(ADI_Skaliert) as Invest, RegInnen)
it brings the r square in R, but I wasn't able to handle the R return. I could plot a bar chart with dimension equal to record number.



Re: Regression function and r squared
Adam Karolewski Nov 2, 2017 4:35 AM (in response to Santana Ngantcheu )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).