s-news
[Top] [All Lists]

Re: extracting rows of $coefficients by variable name?

To: s-news@lists.biostat.wustl.edu
Subject: Re: extracting rows of $coefficients by variable name?
From: "Biggerstaff, Brad J." <bkb5@cdc.gov>
Date: Fri, 23 May 2003 11:17:18 -0400
Cc: "'ccleland@optonline.net'" <ccleland@optonline.net>
Easier just to use the coef() extractor with the approriate name for
subscripting:

> x <- glm(Result~Test*SwabSite,data=sub.dat,family=binomial)
> xs <- summary(x)
> coef(xs)
                   Value Std. Error    t value 
  (Intercept)  2.2899864  0.3699669  6.1897064
         Test -2.4512546  0.4279627 -5.7277291
     SwabSite  0.3368489  0.5585084  0.6031223
Test:SwabSite  1.5902032  0.6695218  2.3751327
>
> coef(xs)["Test",]
     Value Std. Error   t value 
 -2.451255  0.4279627 -5.727729
>
> coef(xs)["Test:SwabSite",]
    Value Std. Error  t value 
 1.590203  0.6695218 2.375133



Brad Biggerstaff, Ph.D. 
(970) 221-6473 ... BBiggerstaff@cdc.gov 


-----Original Message-----
From: Chuck Cleland [mailto:ccleland@optonline.net] 
Sent: Friday, May 23, 2003 9:12 AM
To: Steve Sullivan
Cc: s-news@lists.biostat.wustl.edu
Subject: Re: [S] extracting rows of $coefficients by variable name?

Steve Sullivan wrote:
> Is there a handy way to extract information from a summarized lm or glm 
> object's $coefficients by variable name?  I want to pull out only the 
> coefficient estimate, SE, t-value and p-value for a particular variable 
> (my treatment indicator).

Steve:
   You could use use subscripting on the returned matrix with 
grep() to isolate the row by name.  Here is an example:

my.lm <- lm(Y ~ ., data = mydata)

summary(my.lm)$coefficients[grep("COND", 
row.names(summary(my.lm)$coefficients)),]

where "COND" matches a particular coefficient name

hope this helps,

Chuck Cleland


--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>