Calculating the same coefficients using same data in Matlab and SPSS
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Tim Bennett
2012년 10월 18일
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
2012년 10월 18일
Just obtained the same coefficient outputs from both methods so the matlab code works fine. Thanks for your help anyway Star Strider.
답변 (1개)
Wayne King
2012년 10월 18일
편집: Wayne King
2012년 10월 18일
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
Tim Bennett
2012년 10월 18일
Yes, i've just obtained the same coefficient outputs from both methods so the matlab code works fine. Thanks for your help.
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!