1 Reply Latest reply on Sep 27, 2016 3:19 AM by Bora Beran

# Multiple Linear Regression using R

Hi All,

Currently, I am working on lm() and predict() function under Tableau. My goal is to predict Y based on new inputs (from parameter filter). The script looks like this:

SCRIPT_REAL( "

x1=.arg1;

x2=.arg2;

x3=.arg3;

x4=.arg4;

x5=.arg5;

x6=.arg6;

x7=.arg7;

y=.arg8;

x=data.frame(x1,x2,x3,x4,x5,x6,x7);

fit = lm( y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7, data=x);

dat = data.frame(x1=.arg9, x2=.arg10, x3=.arg11, x4=.arg12, x5=.arg13, x6=.arg14, x7=.arg15);

predict(fit, dat, interval = 'prediction')[1]"

, SUM([Company Type Value]), SUM([Education Level value]), SUM([Industry Type Value]), SUM([Job Category Value]),

SUM([Job Level N Value]), SUM([Location Value]), SUM([Years Of Experience]), SUM([Monthly Salary]),

SUM([Company Type Filter]), SUM([Education Level Filter]), SUM([Industry Filter]), SUM([Job Category Filter]), SUM([Job Level Filter])

, SUM([Location Filter]), SUM([YOE Filter]))

Actually, I found no error and got a single return Y value but the value seems to be wrong. Another problem is, the return value didnt change if I input totally different value in my parameter as inputs.
I have browsed some references including through Bora Beran blog but still I couldnt solve my problem.. Hope you can give some feedback shortly.. Thanks

• ###### 1. Re: Multiple Linear Regression using R

The formula above will return one value from prediction interval.

If you're trying to make a prediction, is there any reason not to use type = "response" instead of interval="prediction"   ?