3 Replies Latest reply on Nov 28, 2018 1:42 PM by Adam Yansick

# How to get Adj. R-Squared of Linear Model using the R integration

Howdy,

I have ran into a bit of a conundrum. We are using the R integration with our tableau dashboards to better represent our linear models (models used loosely here). An example of one of our R scripts is below:

SCRIPT_REAL("mydata <- data.frame(cbind(solved=.arg1, mttr=.arg2, avgReplies=.arg3, avgReopen=.arg4));

fit <-lm(solved[-78] ~ mttr[-78] + avgReplies[-78] + avgReopen[-78], data=mydata);

mydata\$solved[78]<-predict(fit,list(mttr=.arg5[4], avgReplies=.arg6[4], avgReopen=.arg7[4]));

mydata\$solved",count([Solved At]),AVG([Full Resolution Time In Minutes]/60/24),AVG([Replies]),AVG([Reopens]), [What If - MTTR],[What If - Replies],[What If - Reopens])

We fit this model as a line graph and then compare it to actual, use parameters, all sorts of fun stuff.

Now the issue I am having is that I'd like to display some of the summary data from this model (R squared, adj. R-Squared, etc). Usually I grab this from R itself using just: summary(lm(speed~dist, cars))\$adj.r.squared (for example). But I am having trouble with getting the calculation to actually spit out any of the values - I'm really only interested in one value.

This is the calculation that I have been trying to get to work:

SCRIPT_int("mydata <- data.frame(cbind(solved=.arg1, mttr=.arg2, avgReplies=.arg3, avgReopen=.arg4));

summary(lm(solved[-78] ~ mttr[-78] + avgReplies[-78] + avgReopen[-78], data=mydata)\$adj.r.squared"

,count([Solved At]),AVG([Full Resolution Time In Minutes]/60/24),AVG([Replies]),AVG([Reopens]))

Please let me know where I might have gone wrong.

• ###### 1. Re: How to get Adj. R-Squared of Linear Model using the R integration

Have a moment to check this out Bora Beran?

• ###### 2. Re: How to get Adj. R-Squared of Linear Model using the R integration

Hi Clayton,

This should work without any problems in Tableau. I don't see anything wrong in your R code.

summary(yourModelHere)\$adj.r.squared will return a single value and Tableau will replicate it for however many rows you have in your view.

Is the problem 1) you are getting an error 2) you are not getting a value at all 3) you are getting N values but you only want to display it once ?

If you could clarify, it would help in finding the solution.

Thanks,

Bora

• ###### 3. Re: How to get Adj. R-Squared of Linear Model using the R integration

Has anyone managed to solve this problem? I'm curious about the same thing.