[R] Linear regression equation and coefficient matrix

Greg Snow Greg.Snow at imail.org
Thu Aug 19 18:40:23 CEST 2010

Here is a quick example:

c1 <- cor(iris[,-5])
s1 <- sqrt(diag(var(iris[,-5])))

betas <- diag( s1 ) %*% c1 %*% diag( 1/s1 )

# now compare:

coef( lm( Sepal.Length ~ Sepal.Width, data=iris ) )[2]

But if you cannot work that out on your own, then you really should review linear algebra and linear model theory.

Also when dealing with us "absent minded professor" types (I now have adjunct status at 2 universities, can I rationalize being twice as absent minded now?) it is best to include some context in your post (quote some of the previous conversation) to help us remember which of many discussions we have been part of recently you are asking about.

Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of ashz
> Sent: Thursday, August 19, 2010 3:02 AM
> To: r-help at r-project.org
> Subject: Re: [R] Linear regression equation and coefficient matrix
> Dear Greg,
> Thanks for the tip. As I am new in R can you please provide me a script
> how
> do to so. It will help my learning process.
> Thanks,
> Asher
> --
> View this message in context: http://r.789695.n4.nabble.com/Linear-
> regression-equation-and-coefficient-matrix-tp2329804p2330867.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> 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.

More information about the R-help mailing list