Returning to unscaled intercept in linear regression

22 views (last 30 days)
Hi All,
how to get back to unscaled intercept in linear regression?
I'm using two design matrices X and X_scaled. In order to get unscaled regression coefficients, one needs to divide them by max(X(:))- min(X(:))
Scaled model returns another value (-1.307) for intercept which is OK, but how to return to initial model intercept~2.0?
rng('default');
rng(55);
format long;
N = 10;
x1 = sort(normrnd(0,1,[N,1]));
x2 = sort(normrnd(0,1,[N,1]));
x3 = sort(normrnd(0,1,[N,1]));
X = [ones(N,1),[x1,x2,x3]];
X_scaled = [ones(N,1),rescale([x1,x2,x3])]; % scale data
d = max(X(:))- min(X(:)); % max min difference
c = min(X(:)); % min value
Y = 2.0 - 2*x1 + x2 + 3*x3 + normrnd(0,0.01,[N,1]);
b_non = regress(Y,X)
b_scl = regress(Y,X_scaled)
b_scl(2:end)/d % same as b_non
b_non =
2.007266981563815
-1.987076881796996
0.974380009650480
3.009017653647185
b_scl =
-1.307643136965880
-9.200068490333340
4.511331648269810
13.931604134582450
ans =
-1.987076881796994
0.974380009650479
3.009017653647182
Thanks!

Answers (1)

Himanshu
Himanshu on 27 Sep 2023
Hello,
I understand that you are trying to rescale the intercept of a scaled linear regression model to match the original unscaled model. The confusion arises because while the regression coefficients can be rescaled by dividing by the range of the dataset, the intercept does not follow the same rule.
To convert the intercept of the scaled model back to the equivalent value for the unscaled model, you need to account for the effect of the scaling transformation on the zero point. Specifically, you need to subtract the sum of the scaled coefficients multiplied by the minimum values of the respective variables (or the mean values, if you used mean-centering for scaling), and then add back the original intercept.
You can refer to the below steps:
% Step 1: Multiply coefficients by min values
product = b_scl(2:end) .* min([x1,x2,x3]);
% Step 2: Sum the products
sum_product = sum(product);
% Step 3: Subtract from scaled intercept
intercept_scaled = b_scl(1) - sum_product;
You can refer to the below documentation to learn more about Linear Regression and Scaling of variables in MATLAB.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!