s-news
[Top] [All Lists]

Re: difference between the fitted values calculated by the

To: Jo.Jiao@csiro.au
Subject: Re: difference between the fitted values calculated by the
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Fri, 20 Feb 2004 07:58:04 +0000 (GMT)
Cc: s-news@wubios.wustl.edu
In-reply-to: <DFF82EE1A56CB24698934FE115EFDAD1050543@exqld2-bne.qld.csiro.au>
On Fri, 20 Feb 2004 Jo.Jiao@csiro.au wrote:

> Hi, here is a simple question about linear regression. Just say I have
> fitted a simple regression model: y=b0 + b1*X The estimates of b0 and
> b1are bo_hat and b1_hat. I have noted that the fitted values calculated
> using the function fitted.values are differenct from those calculated
> using bo_hat+ b1_hat*X . The difference between the two kinds of fitted
> values is not big, but I suppose they shall be exactly the same. Can
> someone give me a clue?

You are doing a numerical calculation two different ways, so I would not 
expect them to be _exactly_ the same.  Did you use the coefficients as 
printed, or the stored values?  (The printed values are rounded.)

It helps enormously to give an example of such a claim.  Here is my 
attempt to reproduce it:

> x <- 1:25
> y <- 10+x+rnorm(25)
> fit <- lm(y ~ x)
> fit
Call:
lm(formula = y ~ x)

Coefficients:
 (Intercept)        x
    10.09406 1.002956

Degrees of freedom: 25 total; 23 residual
Residual standard error: 1.038494
> z <- drop(cbind(1, x) %*% coef(fit))
> range(z - fitted(fit))
[1] 0.00000e+00 1.24345e-14

so the numbers differ by around the precision of the calculations
(.Machine$double.eps times their size).

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>