From: Nuc User on
"Tom Lane" <tlane(a)mathworks.com> wrote in message <hkukrp$hvn$1(a)fred.mathworks.com>...
> > Thanks for the reply Tom. I'm actually a complete beginner to both matlab
> > and this type of statistical analysis. I am having a pretty hard time
> > understanding how to use those two functions actually. Is there nothing
> > like the aoctool where I can just plug the two distributions in and get a
> > p-value out? Is there perhaps another program with which I can do this?
> > Thanks for your input.
>
> I didn't notice this question from last week until I just saw your more
> recent post.
>
> There is nothing like aoctool for nonlinear or higher-order fits. But there
> are other things such as nlinfit and nlintool.
>
> My question for you is: when you say you want to test whether two fits are
> different between groups, what difference do you want to test for? Examples
> include:
>
> 1. y = f(x,b) in one group and y = f(x.b)+c in the other, for a constant
> difference
>
> 2. y = f(x,b1) in one group and y = f(x,b2) in the other, for potentially
> completely different parameters but the same model
>
> 3. y = f(x,b1) in one group and y = g(x,b2) in the other, for completely
> different model forms.
>
> Whatever type of difference you want to model, it's likely MATLAB can help
> with it but it's also likely that it will involve something beyond
> interation with a GUI. But I can try to point you in the right direction.
>
> -- Tom
>


Hi Tom,
Thanks so much for your responses! Would you mind if I gave a little more detail about my specific situation to make it more clear? Here is the paradigm:

I have 3 variables: 1 dependent (A) and 2 independent (B and C).
A and B are interval measurements (maybe even ratio) and so I can plot A as a function of B.
C is a nominal variable, so it cannot be put on any continuous axis.
I have constructed a curve of A vs B for each condition in C. I now want to compare these curves to each other to see if C produces a significant effect on A.

If the relationship between A and B were linear, I would simply use aoctool, but it is not. As far as I understand, aoctool would perform a linear analysis of covariance which would indicate a significant interaction if the curves were significantly different (which takes into account slope and intercept). I want a comparable measure for nonlinear relationships. So in response to your previous question, I would be looking for a constant difference OR completely different parameters, at the same time.

There might not be an easy gui way to do this, but I feel there must be a way to do such an analysis as the logic is exactly the same as in linear ancova. The only difference is the model for the analysis.

Again, thanks so much for your advice with this issue.
From: Nuc User on
Just wanted to push this up in case it got lost. Thanks
From: Tom Lane on
> If the relationship between A and B were linear, I would simply use
> aoctool, but it is not. As far as I understand, aoctool would perform a
> linear analysis of covariance which would indicate a significant
> interaction if the curves were significantly different (which takes into
> account slope and intercept). I want a comparable measure for nonlinear
> relationships. So in response to your previous question, I would be
> looking for a constant difference OR completely different parameters, at
> the same time.

If I do anocova on the Fisher iris data with x and y the first two
measurements, then the test for the separate-slopes model vs. the
common-slopes model has F=10.2, p=1e-4. Here's an illustration of how I can
reproduce that using nlinfit. First I fit a model with separate intercepts
but a common slope. I compute the sum of squared residuals and the degrees
of freedom.

load fisheriris
x = meas(:,1);
y = meas(:,2);
n = length(y);
g = grp2idx(species);
X = [x g];
f = @(b,x) dummyvar(x(:,2))*b(1:3)' + x(:,1)*b(4);
b = nlinfit(X,y,f,[1 1 1 1]);
r = y - f(b,X);
ssr1 = sum(r.^2);
df1 = length(b);

Now I fit a model with separate slopes and intercepts, and its sum of
squared residuals and degrees of freedom.

g = grp2idx(species);
X = [x g];
f = @(b,x) dummyvar(x(:,2))*b(1:3)' + x(:,1).*(dummyvar(x(:,2))*b(4:6)');
b1 = nlinfit(X,y,f,[1 1 1 1 1 1]);
r = y - f(b1,X);
ssr2 = sum(r.^2);
df2 = length(b1);

Now I can construct the F statistic to test the difference of these by
comparing it to the residuals from the more general model, and I compute its
p-value.

F = ((ssr1-ssr2)/(df2-df1)) / (ssr2/(n-df2))
p = 1 - fcdf(F,df2-df1,n-df2)

If you are new to MATLAB you may find this confusing, but the basic idea is
to fit two models, with one a special case of the other. Here the first is a
special case of the second with all three slopes forced to be the same. Then
use an F test to see if the difference between them is significant.

This would have been somewhat simpler if I were just testing completely
different sets of parameters. Then I could fit one model to the entire data
set, and fit that same model separately to each group. This example is more
complicated because I was trying to reproduce the F statistic where one of
the models had one parameter (intercept) vary across groups while the other
(slope) did not.

There would be another approach using the linhyptest function if you wanted
to try that.

-- Tom


From: Nuc User on
> If I do anocova on the Fisher iris data with x and y the first two
> measurements, then the test for the separate-slopes model vs. the
> common-slopes model has F=10.2, p=1e-4. Here's an illustration of how I can
> reproduce that using nlinfit. First I fit a model with separate intercepts
> but a common slope. I compute the sum of squared residuals and the degrees
> of freedom.
>
> load fisheriris
> x = meas(:,1);
> y = meas(:,2);
> n = length(y);
> g = grp2idx(species);
> X = [x g];
> f = @(b,x) dummyvar(x(:,2))*b(1:3)' + x(:,1)*b(4);
> b = nlinfit(X,y,f,[1 1 1 1]);
> r = y - f(b,X);
> ssr1 = sum(r.^2);
> df1 = length(b);
>
> Now I fit a model with separate slopes and intercepts, and its sum of
> squared residuals and degrees of freedom.
>
> g = grp2idx(species);
> X = [x g];
> f = @(b,x) dummyvar(x(:,2))*b(1:3)' + x(:,1).*(dummyvar(x(:,2))*b(4:6)');
> b1 = nlinfit(X,y,f,[1 1 1 1 1 1]);
> r = y - f(b1,X);
> ssr2 = sum(r.^2);
> df2 = length(b1);
>
> Now I can construct the F statistic to test the difference of these by
> comparing it to the residuals from the more general model, and I compute its
> p-value.
>
> F = ((ssr1-ssr2)/(df2-df1)) / (ssr2/(n-df2))
> p = 1 - fcdf(F,df2-df1,n-df2)
>
> If you are new to MATLAB you may find this confusing, but the basic idea is
> to fit two models, with one a special case of the other. Here the first is a
> special case of the second with all three slopes forced to be the same. Then
> use an F test to see if the difference between them is significant.
>
> This would have been somewhat simpler if I were just testing completely
> different sets of parameters. Then I could fit one model to the entire data
> set, and fit that same model separately to each group. This example is more
> complicated because I was trying to reproduce the F statistic where one of
> the models had one parameter (intercept) vary across groups while the other
> (slope) did not.
>
> There would be another approach using the linhyptest function if you wanted
> to try that.
>
> -- Tom
>

That's a little complicated but I guess I get the general idea. I looked at the data though, and it's fairly linear. It also seems like if we're looking for slopes, we're still dealing with linear models. So I guess the issue is like this. Imagine I'm trying to compare the following curves to see if they are significantly different:

f(x1)=.01x^3
f(x2)=.03x^3
f(x3)=.01x^3+x

All these are significantly different curves, but if you were to try and fit a linear curve to them to do a linear ancova you would get 2 of them to be not significantly different depending on how you chose to fit the data. That's why I'm looking for something that doesn't look at "slope" but at the actual model. Or is this what your example is doing and I'm just not understanding?

Thanks again!
From: Tom Lane on
> All these are significantly different curves, but if you were to try and
> fit a linear curve to them to do a linear ancova you would get 2 of them
> to be not significantly different depending on how you chose to fit the
> data. That's why I'm looking for something that doesn't look at "slope"
> but at the actual model. Or is this what your example is doing and I'm
> just not understanding?

Sorry for the delay in replying.

Yes, I used nlinfit so that you could fit any models, including the ones you
mentioned. It's true I chose to use a linear model with an intercept and
slope, just so I could demonstrate how I reproduced the F and p values that
aoctool displays. But you can carry out similar steps with your models.

-- Tom