Adrian Vance Custer
2000-Jun-21 19:10 UTC
[R] converting a string to an element in a function call
Hello everyone,
I'm trying to write a function that will step through a vector of strings
and
evaluate the contribution to the R-squared of each in turn. I suspect this is
related to the anova(model) call but not quite sure how and anova() is order
dependent so I have to step through orders anyhow.
The issue is that I pass a vector of strings to the function and want to use it
as:
update(.~.+ do.something.to.the.string(vector.argument.of.strings[i])
or in the code below
update(.~.+unknown(facvec[i]))
I've tried a whole bunch of things I don't understand
parse(),as.expession()
and the as.name() below but none seem to work.
Here is the function I am using:
function(facvec,base.lm){
if ( missing(facvec) || missing(base.lm) ){
cat("This script assesses the contribution of terms in a lm
model.\n")
cat(" It expects a vector of names and a lm.object to update.\n")
cat(" as in script.name(facvec,base.lm).\n")
stop()
}
a_0
i_0
base.r2_summary(base.lm)$r.squared
for (i in 1:length(facvec)){
a[i]_c(fac=summary(update(base.lm,.~.+as.name(facvec[i])))$r.squared-base.r2)
i_i+1
}
return(a)
}
Thanks for any help,
adrian
acuster at nature.berkeley.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Lumley
2000-Jun-21 19:38 UTC
[R] converting a string to an element in a function call
On Wed, 21 Jun 2000, Adrian Vance Custer wrote:> Hello everyone, >> The issue is that I pass a vector of strings to the function and want to use it > as: > > update(.~.+ do.something.to.the.string(vector.argument.of.strings[i]) > or in the code below > update(.~.+unknown(facvec[i]))There's probably a way to do this more directly, but you can use substitute() to update the formula. update(model,substitute(.~.+new,list(new=as.name(facvec[i])))) -thomas Thomas Lumley Assistant Professor, Biostatistics University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._