[R] Linear regression equation and coefficient matrix

Greg Snow Greg.Snow at imail.org
Wed Aug 18 23:35:03 CEST 2010


Well you already have the correlation matrix, so you can just work from there.  One of the profound equations in statistics is that r^2=r^2, meaning that to get r2 (as you call it, assuming you mean the coefficient of determination) just square the elements of the correlation matrix.

To get regression slopes, one equation is just b=s_y/s_x * r, so use the var function to get variances, diag to pull out just the diagonal, sqrt to get the standard deviations and then either matrix multiplication or the sweep function to multiply (divide) the correlations by the appropriate standard deviations and you will have a matrix of slopes.

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


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of ashz
> Sent: Wednesday, August 18, 2010 8:43 AM
> To: r-help at r-project.org
> Subject: Re: [R] Linear regression equation and coefficient matrix
> 
> 
> Hi,
> 
> Thanks, the cor() works.
> 
> Regarding the simple linear regression equation (mainly, the slope
> parameter) and r2. I think I was not writing it well. I need to do it
> just
> for the columns. If I have a, b, c, d columns I wish to compute the
> relation
> of there data,  e.g., between a-b, a-c, a-d, b-a, b-c, b-d, etc.
> 
> I hope it is clear now and an help will be great.
> 
> Thanks.
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Linear-
> regression-equation-and-coefficient-matrix-tp2329804p2329948.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