Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to do a model II regression with intercept of zero

Subject: How to do a model II regression with intercept of zero

From: Liqing

Date: 20 Mar, 2008 16:52:02

Message: 1 of 4

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 re-used 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/(n-1));
sigy = sqrt(Sv2/(n-1));
 
% 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-------------------

Subject: How to do a model II regression with intercept of zero

From: Star Strider

Date: 21 Mar, 2008 00:12:01

Message: 2 of 4

"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 re-used 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/(n-1));
> sigy = sqrt(Sv2/(n-1));
>
> % 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 zero-intercept 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 second-order polynomial with a zero intercept, it
becomes:

y = B(1)*x + B(2)*x^2

The rest is straightforward.



Have fun!

Star Strider

Subject: How to do a model II regression with intercept of zero

From: Liqing

Date: 21 Mar, 2008 01:49:02

Message: 3 of 4

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 re-used 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/(n-1));
> > sigy = sqrt(Sv2/(n-1));
> >
> > % 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 zero-intercept 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 second-order polynomial with a zero intercept, it
> becomes:
>
> y = B(1)*x + B(2)*x^2
>
> The rest is straightforward.
>
>
>
> Have fun!
>
> Star Strider
>
>
>
>

Subject: How to do a model II regression with intercept of zero

From: Liqing

Date: 21 Mar, 2008 02:59:02

Message: 4 of 4

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 re-used 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/(n-1));
> > > sigy = sqrt(Sv2/(n-1));
> > >
> > > % 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 zero-intercept 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 second-order polynomial with a zero intercept, it
> > becomes:
> >
> > y = B(1)*x + B(2)*x^2
> >
> > The rest is straightforward.
> >
> >
> >
> > Have fun!
> >
> > Star Strider
> >
> >
> >
> >
>

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us