How To Find Coefficients Of Multiple Linear Regression
Published: 30 Oct 2020 Last Modified Date: 08 Jul 2022
Question
How to find coefficients of multiple linear regression
Environment
Tableau Desktop
Answer
Use Rserve:
Rserve installation:
Download and Install R. Click here to find the file and instructions on downloading R.
Download and Install Rserve.You will need to install an Rserve for Tableau to connect to in order to utilize the new script functions. In the R console, enter the following commands: install.packages("Rserve") library(Rserve) Rserve()
Go to the Help menu and select "Manage R Connection".
Enter a server name of "Localhost" (or "127.0.0.1") and a port of "6311".
Click on the “Test Connection” button to make sure everything runs smoothly. You should see a successful message. Click OK to close
Calculations for two input explanatory variables(Quantity and discount) and one response variable:
Create a calculated field like following for the Intercept: SCRIPT_REAL("a<-.arg1;b<-.arg2;c<-.arg3; reg<- lm(a~b+c); reg$coeff[[1]]", Sum([Profit]),Sum([Quantity]),Sum([Discount]))
Create a calculated field like following for the Slope of first input factor i.e for Quantity in this example SCRIPT_REAL("a<-.arg1;b<-.arg2;c<-.arg3; reg<- lm(a~b+c); reg$coeff[[2]]", Sum([Profit]),Sum([Quantity]),Sum([Discount]))
Create a calculated field like following for the Slope of second input factor i.e for Discount in this example SCRIPT_REAL("a<-.arg1;b<-.arg2;c<-.arg3; reg<- lm(a~b+c); reg$coeff[[3]]", Sum([Profit]),Sum([Quantity]),Sum([Discount]))
Thank you for providing your feedback on the effectiveness of the article.