Hi Star,
Thank you for your suggestions. Sorry but I have little
statistic knowledge. I wonder if you could give me more
details about how to modify my code?
I appreciate your time very much!
"Liqing " <liqingj@gmail.com> wrote in message
<frv46e$bts$1@fred.mathworks.com>...
> Dear Star Strider,
>
> It rocks! Thank you so much for the awesome suggestions.
>
> Have a nice weekend!
>
>
> Sincerely,
>
> LQ
>
>
>
> "Star Strider" <skystriderDELETETHIS@ieee.net> wrote in
> message <fruugh$bso$1@fred.mathworks.com>...
> > "Liqing " <liqingj@gmail.com> wrote in message
> > <fru4ni$b7v$1@fred.mathworks.com>...
> > > I'm trying to do a model II regression for two columns of
> > > data X, Y with same units.
> > >
> > > How can I set the intercept to be zero? Thank you.
> > >
> > > Below is the function that I used:
> > >
> > > %
> > >
> > > function [m,b,r,sm,sb]=model2(X,Y)
> > > % Determine the size of the vector
> > >
> > > n = length(X);
> > >
> > > % Calculate sums and other reused expressions
> > > Sx = sum(X);
> > > Sy = sum(Y);
> > > xbar = Sx/n;
> > > ybar = Sy/n;
> > > U = X  xbar;
> > > V = Y  ybar;
> > >
> > > Suv = sum(U .* V);
> > > Su2 = sum(U .^2);
> > > Sv2 = sum(V .^2);
> > >
> > > sigx = sqrt(Su2/(n1));
> > > sigy = sqrt(Sv2/(n1));
> > >
> > > % Calculate m, b, r, sm, and sb
> > >
> > > m = (Sv2  Su2 + sqrt(((Sv2  Su2)^2) + (4 * Suv^2)))/(2
> > * Suv);
> > > b = ybar  m * xbar;
> > > r = Suv / sqrt(Su2 * Sv2);
> > >
> > > sm = (m/r) * sqrt((1  r^2)/n);
> > > sb1 = (sigy  sigx * m)^2;
> > > sb2 = (2 * sigx * sigy) + ((xbar^2 * m * (1 + r))/r^2);
> > > sb = sqrt((sb1 + ((1  r) * m * sb2))/n);
> > >
> > > %the end
> >
> >
> >
> > You have to set up your model with an intercept of zero.
> > For instance, you current model appears to be:
> >
> > y = m*x + b
> >
> > and you set up your ordinary least squares model
> > appropriately. The problem is that you want “b” to always
> > equal zero.
> >
> > To “force” a zerointercept you need to restate your model
> > to:
> >
> > y = m*x
> >
> > setting “b” explicitly to zero. The only difference is
> > that you will now only estimate one parameter.
> >
> > This also works for other models. For instance, if you
> > want a secondorder polynomial with a zero intercept, it
> > becomes:
> >
> > y = B(1)*x + B(2)*x^2
> >
> > The rest is straightforward.
> >
> >
> >
> > Have fun!
> >
> > Star Strider
> >
> >
> >
> >
>
