Need the Slope and Intercept from Linear Regression using Tableau and R

1.6k Views Asked by At

I have a Dataset in Tableau, from which i need to get the Slope and Intercept of the Linear Regression best fit line using the lm() function in R.

The regression is a basic one, with just one predictor variable and one dependent. How do I handle the fact that i need to pass an aggregated value to the lm() function, even though i need to send the entire column?

With a column called 'Predictor', and another called 'Dependent', I essentially need to do this in Tableau:

fit <- lm(df$Dependent ~ df$Predictor)
return fit

Tableau does not let me do this unless I pass to it

SUM[Dependent] and SUM[Predictor]

But instead of aggregating it, i need it to work on the entire column

Thanks

1

There are 1 best solutions below

2
On

Add a dimension to any shelf, say the detail shelf, that partitions the data at the level you wish. If you want each individual row to be included in the model, use a dimension that has a unique value for each row, say some sort of row id.

BTW, you know you can perform regression models directly within Tableau, right? You don't need to call out to R just to fit a linear model.