Regstats : Multiple regression/comparing regression slopes

19 views (last 30 days)
Hi,
I want to compare the regression slopes of 3 data sets. Apparently you have to set some dummy variables =0/1 and regress against them to do this.
So I tried to do it using regstats but I can't get regstats to work with several regressors.
I tried the following :
X =
% the "real" regressor (1 2 3) repeated 3 times (one for each set)
1
2
3
1
2
3
1
2
3
Z12 =
% the first dummy regressor (1 if data is from set number 2)
0
0
0
1
1
1
0
0
0
Z20 =
% second dummy regressor (1 if data is from group 3)
0
0
0
0
0
0
1
1
1
V=[X,Z12,Z20]
V =
% all three regressors put together in one matrix
1 0 0
2 0 0
3 0 0
1 1 0
2 1 0
3 1 0
1 0 1
2 0 1
3 0 1
Y=2+3*X+4*Z12+5*Z20*X'
Y =
% fake dataset to see if regstats would give me the right coefficients
35
38
41
39
42
45
35
38
41
then i tried
s=regstats(Y,V,'interactions','all')
and got the following warnings
Warning: Matrix is singular to working precision.
> In regstats at 180
Warning: Matrix is singular to working precision.
> In regstats at 195
and none of the numbers is correct i get a lot of NaNs and Inf for example
>> s.beta
ans =
NaN
NaN
NaN
NaN
NaN
NaN
Inf
I don't have any clue on what is wrong with the code I tried. I have never used regstats before. Any idea on what I could do ?
Thank you very much for your help !
  3 Comments
laurie
laurie on 17 Mar 2012
thank you for your answer
sorry about the stray character. the output version is the right one. i don't know what a lagged value is.
i am doing this because i have 3 sets of data y1,y2, and y3, and i want to compare the slopes of their respective regressions against x. (are the slopes equal or not?).
i think my problem is very similar to this one here
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270278
but i am struggling to understand the method.
Oleg Komarov
Oleg Komarov on 17 Mar 2012
The thread you found is a good one, follow it thoroughly and pay attention to details, for example .* is different from *

Sign in to comment.

Accepted Answer

Oleg Komarov
Oleg Komarov on 16 Mar 2012
Your data (in copy-pastable form):
X = [1;2;3;1;2;3;1;2;3];
Z12 = [0;0;0;1;1;1;0;0;0];
Z20 = [0;0;0;0;0;0;1;1;1];
V = [X,Z12,Z20];
Y = 2 + 3*X + 4*Z12 + 5*Z20'*X;
Setting the model to 'interaction' gives this matrix:
x2fx(V,'interaction')
1 1 0 0 0 0 0
1 2 0 0 0 0 0
1 3 0 0 0 0 0
1 1 1 0 1 0 0
1 2 1 0 2 0 0
1 3 1 0 3 0 0
1 1 0 1 0 1 0
1 2 0 1 0 2 0
1 3 0 1 0 3 0
Is this what you're looking for? (Not likely). To understand what's going on with the choice of the model read the documentation of x2fx, which is used by regstats.

More Answers (1)

laurie
laurie on 17 Mar 2012
Thanks you very much, it worked fine !! :-)
Just checking : if regstats gives a p-value > criterium for one regressor, it means that the coefficient for this regressor is probably 0 right ? Also, should'nt the criterium be adjusted to the number of regressors ?
  1 Comment
Oleg Komarov
Oleg Komarov on 17 Mar 2012
You usually read things like, the p-values are too high, thus the coefficients are not statistically significant at any conentional level (where the conventional levels are 5% or 1%).
A p-value is the (smallest) probability to observe a value that is different from the null just by chance.
Rephrasing, a p-value is the percentage of values you would erroneously accept (when they should be considered as the null).
In regressions, the p-value of single coefficients is ususally the t-test against the null of 0.
So, say you have a coefficient of 0.32 and the question you want to ask is: "is it truly 0.32 or should I consider it as 0?"
Suppose you get a p-value of 9.81%. It says that the probability of 0.32 being a 0 is 9.81%.
Now, are you willing to accept such a risk? Usually, the threshold is 5%, thus observing a p-value lower than the threshold is good sign.
DISCLAIMER: I am abusing the words truly and accept.
Truly is with respect to the assumed distribution for your parameters and you NEVER accept the NULL but you fail to reject it.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!