Calculating the same coefficients using same data in Matlab and SPSS
Show older comments
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
Star Strider
on 16 Oct 2012
The data do not seem to be available online (they may be proprietary to SPSS), so it's impossible to reproduce your regression.
Tim Bennett
on 17 Oct 2012
Tim Bennett
on 17 Oct 2012
Star Strider
on 17 Oct 2012
It's a .sav file. I can open it but it's encoded in a way I can't figure out, . Maybe you could post the headers and perhaps about 15 lines of data here, or choose a different data file.
In the interim, I suggest you look at how the data files are organised to see if you're presenting the same data to both SPSS and MATLAB in the way that MATLAB expects.
Tim Bennett
on 18 Oct 2012
I'll send each column of data (the top 10 data points each)through for each variable if thats o.k to keep things simple. The x (predictor variables) and y (outcome variable) data for both SPSS and Matlab are in column vectors [10 x 1]. x1 = advertising budget x2 = airplay x3 = band attractiveness
My outcome variable is: y = record sales
Using the following Matlab code:
X = [ones(length(x1),1) x1 x2 x3];
I obtain the following coefficients from the data set sent though using B = X\y;
-67.9982, 0.0466, 4.6682, 17.8968,
in a [4 x 1] vector
I'll send through the coefficients from SPSS for this data set asap.
Thanks
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
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.
Answers (1)
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
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.
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!