[R] pulling items out of a lm() call

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Mon May 1 13:04:16 CEST 2006


probably all.vars() could be useful in this case, e.g.,

m1 <- lm(y ~ female + I(age^2) + female:black + (age + 
education)*female)
all.vars(formula(m1))


Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm



----- Original Message ----- 
From: "Andrew Gelman" <gelman at stat.columbia.edu>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, May 01, 2006 12:46 PM
Subject: [R] pulling items out of a lm() call


>I want to write a function to standardize regression predictors, 
>which
> will require me to do some character-string manipulation to parse 
> the
> variables in a call to lm() or glm().
>
> For example, consider the call
> lm (y ~ female + I(age^2) + female:black + (age + 
> education)*female).
>
> I want to be able to parse this to pick out the input variables
> ("female", "age", "black", "education").  Then I can transform these 
> as
> appropriate (to get "z.female", "z.age", etc), feed them back into 
> the
> lm() function, and go from there.
>
> Does anyone know an easy way to pull out the variables?  I basically
> have to parse out the symbols "+", ":", "*", and " ", but there's 
> also
> the problem of handling parentheses and the I() operator.
>
> Thanks!
> Andrew
>
> -- 
> Andrew Gelman
> Professor, Department of Statistics
> Professor, Department of Political Science
> gelman at stat.columbia.edu
> www.stat.columbia.edu/~gelman
>
> Statistics department office:
>  Social Work Bldg (Amsterdam Ave at 122 St), Room 1016
>  212-851-2142
> Political Science department office:
>  International Affairs Bldg (Amsterdam Ave at 118 St), Room 731
>  212-854-7075
>
> Mailing address:
>  1255 Amsterdam Ave, Room 1016
>  Columbia University
>  New York, NY 10027-5904
>  212-851-2142
>  (fax) 212-851-2164
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm




More information about the R-help mailing list