Calculating the same coefficients using same data in Matlab and SPSS

4 views (last 30 days)
I'm trying to obtain the same coefficients from Matlab and SPSS using the same data set from an SPSS text book to determine whether my code is correct in Matlab.
My predictor varibables are as follows: x1 = advertising budget x2 = airplay x3 = aesthetics
My outcome variable is: y = record sales
The equation in SPSS uses the following equation: y = (b0 + b1x1 + b2x2 + b3x3) + error
where b0 and b1, b2, b3 are the regression coefficients the following coefficients were obtained in SPSS:
b1 = 0.578 b2 = 0.599 b3 = 0.326
Using the following Matlab code:
X = [ones(length(x1),1) x1 x2 x3];
I obtain the following coefficients from the same data set using B = X\y;
20.7809 0.0862 3.309 10.2938
which as you can see is considerably different.
Any help would be appreciated.
  7 Comments
Tim Bennett
Tim Bennett on 18 Oct 2012
outcome data (y):
270, 220, 170, 70, 210, 200, 300, 290, 70, 150,
x1 data:
1188.19, 574.51, 568.95, 471.81, 537.35, 514.07, 174.09, 1720.81, 611.48, 251.19,
x2 data:
33, 44, 19, 20, 22, 21, 40, 32, 20, 24,
x3 data
7, 5, 5, 1, 9, 7, 7, 7, 2, 8,
Tim Bennett
Tim Bennett on 18 Oct 2012
Just obtained the same coefficient outputs from both methods so the matlab code works fine. Thanks for your help anyway Star Strider.

Sign in to comment.

Answers (1)

Wayne King
Wayne King on 18 Oct 2012
Edited: Wayne King on 18 Oct 2012
I'm not sure what is going on in SPSS because I don't use that, but I can tell you that repeating the above in R and MATLAB gives the same coefficients.
Here is the output I get in R:
Call:
lm(formula = y ~ x1 + x2 + x3)
Coefficients:
(Intercept) x1 x2 x3
-68.00038 0.04661 4.66820 17.89690
Here is the coefficient vector I get in MATLAB:
beta = [ -67.9982
0.0466
4.6682
17.8968]
  1 Comment
Tim Bennett
Tim Bennett on 18 Oct 2012
Yes, i've just obtained the same coefficient outputs from both methods so the matlab code works fine. Thanks for your help.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!