# What is the difference between the regress function and the fitlm function

85 views (last 30 days)

Show older comments

% X = input data

% Y = outcome

% Using the fitlm command to estiamte the multiple liner regression model

lin_mdl = fitlm(X,Y);

b1 = lin_mdl.Coefficients.Estimate;

% Using the regress command to estiamte the multiple liner regression model

b = regress(Y,X)

b2 = [mean(Y) - b'*mean(X)'; b] %To estimate the intercept term

% Comparing the coefficients

[b1 b2]

The output of this function gives different results. Why is that happening? The intercept and the 13th and 14th rows are different in the two cases.

ans =

17.1356 -0.0000

-1.1637 -1.1637

0.2319 0.2319

-14.1594 -14.1594

-0.3783 -0.3783

-0.1204 -0.1204

1.1688 1.1688

0.2103 0.2103

0.1817 0.1817

-0.7232 -0.7232

0.1832 0.1832

-0.0504 -0.0504

0 17.1356

135.8924 153.0281

39.8538 39.8538

-9.4579 -9.4579

0.0452 0.0452

0.6175 0.6175

0.2658 0.2658

0.2980 0.2980

0.3391 0.3391

-0.3060 -0.3060

-0.3109 -0.3109

0.0031 0.0031

-18.0225 -18.0225

-19.0582 -19.0582

-19.5642 -19.5642

-10.1484 -10.1484

-12.0962 -12.0962

-15.1616 -15.1616

-25.3793 -25.3793

-23.5957 -23.5957

-25.5307 -25.5307

-28.9162 -28.9162

-32.5474 -32.5474

-12.9198 -12.9198

-6.3773 -6.3773

2.7314 2.7314

2.5699 2.5699

8.3264 8.3264

13.9870 13.9870

11.0497 11.0497

-20.8487 -20.8487

-12.7635 -12.7635

-13.2119 -13.2119

-17.0616 -17.0616

-18.2134 -18.2134

-11.9230 -11.9230

-26.3549 -26.3549

##### 0 Comments

### Answers (2)

Tom Lane
on 22 Feb 2016

##### 1 Comment

Myagmarsuren Sanaakhorol
on 10 Sep 2016

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!