KNOWLEDGE BASE

## How To Find Coefficients Of Multiple Linear Regression

Published: 30 Oct 2020
Last Modified Date: 02 Nov 2020

### Question

How to find coefficients of multiple linear regression

### Environment

• Tableau Desktop

### Answer

Use Rserve:

Rserve installation:
1. Download and Install R. Click here to find the file and instructions on downloading R.
2. 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()
3. Connect Tableau to the R Server. Once Rserve is installed, open Tableau Desktop and follow the steps below or watch this video on how to integrate R and Tableau.
1. Go to the Help menu and select "Manage R Connection".
2. Enter a server name of "Localhost" (or "127.0.0.1") and a port of "6311".
3. 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 :
1. Create a calculated field like following for the Intercept:                                                                                                                                                                                                      SCRIPT_REAL("a<-.arg1;b<-.arg2;c<-.arg3; reg<- lm(a~b+c); reg\$coeff[]", Sum([Profit]),Sum([Quantity]),Sum([Discount]))
2. 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[]", Sum([Profit]),Sum([Quantity]),Sum([Discount]))
3. 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[]", Sum([Profit]),Sum([Quantity]),Sum([Discount]))

Did this article resolve the issue?