s-news
[Top] [All Lists]

Re: Want standard error of a lm slope

To: David Parkhurst <parkhurs@imap.iu.edu>, s-news@lists.biostat.wustl.edu
Subject: Re: Want standard error of a lm slope
From: "Richard M. Heiberger" <rmh@temple.edu>
Date: Sat, 3 Dec 2005 22:42:23 -0500
My first guess is that your loop is over the wrong item.
Here is your code repeated, with spacing around the arrows
and tilde for improved legibility.

   regr <- lm(withrand ~ when)
   b1 <- regr$coefficients[2]
   se.b1 <- summary(regr)$coefficients[2,2]

Your last two lines can be replaced by the single line
   coef(summary(regr))[2,1:2]


Assuming you have two matrices, and want to regress respective
columns of y and x,

y <- matrix(rnorm(50), 10, 5)
x <- matrix(rnorm(50), 10, 5)

b.se <- matrix(0, 2, 5,
               dimnames=list(1:2, c("Value", "Std. Error")))
for (i in 1:5)
   bs.e[i,] <- coef(summary(lm(y[,i] ~ x[,i])))[2, 1:2]
b.se

The results are stored in a matrix so you can index into them.

<Prev in Thread] Current Thread [Next in Thread>
  • Re: Want standard error of a lm slope, Richard M. Heiberger <=