check whether regression slopes are different between 3 groups

11 views (last 30 days)
Hi there,
I have read some very helpful questions / answers that deal with the comparison of regression slopes obtained from several groups. I though still have some uncertainties and would like to ask for some guidance.
OK below is the relevant code. I'd like to compare regression slopes obtained from robustfit (3 groups).
constxxx: simply refers to the number of subjects and their data entries for the respective group.
newData1.data(1:32,1): is the predictor.
Particularly, I had to add a zero to linhyptest ([0 0 1 0; 0 0 0 1]) to make it work, I assume it's because a constant has been added by robustfit. I also believe the (X = [x, (g==2).*x, (g==3).*x]) does not need to be shifted as the the constant is added later. Finally, my understanding is that the result, if significant, would indicate an interaction.
Could anyone comment on my procedure please. Thanks very much in advance.
Best,
Torsten
g = [ones(const300,1); 2*ones(const400,1); 3*ones(const500,1)];
X = [x, (g==2).*x, (g==3).*x];
[b,s2] = robustfit(X,newData1.data(1:32,1));
[p,F] = linhyptest(b, s2.covb, [0;0], [0 0 1 0; 0 0 0 1], s2.dfe);

Accepted Answer

Tom Lane
Tom Lane on 7 Nov 2012
Your code looks right to me.
If you have a recent version of the Statistics Toolbox, your job would be somewhat simpler if you put your data into a dataset array, then used LinearModel.fit with the 'robust' option, then used the anova method. But your approach is fine as well.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!