An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101229/96638f61/attachment.pl>
as.object: function doesn't exist but I wish it did
3 messages · Patrick McKann, Gabor Grothendieck, Uwe Ligges
On Wed, Dec 29, 2010 at 12:31 PM, Patrick McKann <pcmckann at gmail.com> wrote:
I seem to come to this problem alot, and I can find my way out of it with a
loop, but I wish, and wonder if there is a better way. ?Here's an example
(lmer1-5 are a series of lmer objects):
?bs=data.frame(bic=BIC(lmer1,lmer2,lmer3,lmer4,lmer5)$BIC)
?rownames(bs)=c('lmer1','lmer2','lmer3','lmer4','lmer5')
?best=rownames(bs)[bs==min(bs)]
best
[1] "lmer5"
This tells me that lmer5 is the model with the lowest BIC. ?I want to start
working with lmer5 as the best model, such as fixef(best) to get the fixed
effect estimates from lmer5. ?I tried best=as.object('lmer5') but of course
this doesn't work because that is not a real function.
Does anybody see what I'm getting at? ?If so, do you know a way to do this
without a loop or series of if statements?
If you are asking how to turn a string into a variable its a FAQ! http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-turn-a-string-into-a-variable_003f
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Not sure what you really want, my best guess is you are looking for get(): best <- get(best) Uwe Ligges
On 29.12.2010 18:31, Patrick McKann wrote:
I seem to come to this problem alot, and I can find my way out of it with a
loop, but I wish, and wonder if there is a better way. Here's an example
(lmer1-5 are a series of lmer objects):
bs=data.frame(bic=BIC(lmer1,lmer2,lmer3,lmer4,lmer5)$BIC)
rownames(bs)=c('lmer1','lmer2','lmer3','lmer4','lmer5')
best=rownames(bs)[bs==min(bs)]
best
[1] "lmer5"
This tells me that lmer5 is the model with the lowest BIC. I want to start
working with lmer5 as the best model, such as fixef(best) to get the fixed
effect estimates from lmer5. I tried best=as.object('lmer5') but of course
this doesn't work because that is not a real function.
Does anybody see what I'm getting at? If so, do you know a way to do this
without a loop or series of if statements?
Thank you!
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.