Skip to content
Prev 301502 / 398503 Next

Working with Numbers generated from Regression Output

On Jul 27, 2012, at 3:10 AM, Krunal Nanavati wrote:

            
The summary function returns a complex list object. You can see that  
list structure with this code:

#Using the example in help(lm)
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D90 <- lm(weight ~ group - 1) # omitting intercept

str(summary(lm.D90))

What you see at the console whaen you type summary(lm.D90) is somewhat  
different. It is the result of another function, print.summary(). It  
is not a visible function so when you type its name you get:

 > print.summary.lm
Error: object 'print.summary.lm' not found

But it has to be there and I took an educated guess that it was in the  
stats package and can see it by using the triple-colon infix function:

stats:::print.summary.lm

You could wrap 'as.character' around the summary object:

as.character( summary(lm.D90))

I'm guessing you do not really want all of that complexity and would  
probably be better served by learning the proper extractor functions  
for regression or summary.lm arguments linked from the help(lm) page  
in the "See Also" section;

?lm
?coef
?vcov
?fitted
?residuals
?terms

Notice that the extractor functions will return different objects from  
the model object than they do from the summary object:

 > coef( lm.D90)
groupCtl groupTrt
    5.032    4.661

 > coef( summary(lm.D90) )
          Estimate Std. Error  t value     Pr(>|t|)
groupCtl    5.032  0.2202177 22.85012 9.547128e-15
groupTrt    4.661  0.2202177 21.16542 3.615345e-14
As an example, copy the output of the three lines following the  
console call to "coef( summary(lm.D90) )" into an Excel spreadsheet.  
If the copied three cells should remain highlighted. Now click the  
Data menu and pick the "Text to Columns... " item and accept the  
defaults in  the which should be "fixed" in the fist dialog,  and the  
correct locations for the cell splits in the next ones.  You should  
now get the results split into cells. Sometimes you need to adjust the  
guesses that the program makes for where you want splits to occur, but  
the little fixed-import dialog is fairly handy, so you should learn  
it. But ... further such questions are off-topic for this list, and  
you should be getting you instructions on an Excel forum.

Also read:

http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows

(Note: I'm not a regular user of R or Excel on Windows, but I believe  
the actions on the  Excel for Mac 2011 should very similar to the  
behavior I dimly remember in the Windows version. I'm also old enough  
to remember the several years when Excel only existed on the Mac, but  
in those years I was using GLIM.)