Re: [R] fitted values are different from manually calculating

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Tue, 19 Feb 2008 15:57:25 +0100

why do you say this? Check for instance the following code:

x1 <- runif(100, -5, 5)
x2 <- rnorm(100)
x3 <- rep(0:1, each = 50)

y <- 2 + 0.5 * x1 + 2 * x2 - 3 * x3 + rnorm(100)

fit <- lm(y ~ x1 + x2 + x3)

all.equal(

    as.vector(fitted(fit)),
    as.vector(model.matrix(fit) %*% coef(fit)) )

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> Hello,
>
> on a simple linear model the values produced from the fitted(model)
> function
> are difference from manually calculating on calc. Will anyone have a
> clue...
> or any insights on how fitted function calculates the values? Thank
> you.
>
> --
> -- Yianni
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 19 Feb 2008 - 15:00:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Feb 2008 - 15:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive