Richard M. Heiberger
2025-Mar-29 22:12 UTC
[R] [External] Creating model formulas programmatically
> somenames <- c("Heigh", "Ho", "Silver", "Away") > as.formula(paste("~(",paste(somenames, collapse="+"),")^2"))~(Heigh + Ho + Silver + Away)^2>> On Mar 29, 2025, at 14:30, Bert Gunter <bgunter.4567 at gmail.com> wrote: > > somenames <- c("Heigh", "Ho", "Silver", "Away")
Thanks, Rich. I thought of that, too, but it violates the spirit of my restraints (to avoid character strings), which I unfortunately did not clearly articulate. So my apologies for that failure. My concern is that with more complex model formula, using as.formula, etc. to parse/convert character strings can get a bit hairy. But in most cases, as here maybe, it may be perfectly fine. So think of my post as mostly my attempt to learn some new tricks rather than to solve a useful problem. I hope this is not unfair to the list. Cheers, Bert On Sat, Mar 29, 2025 at 3:12?PM Richard M. Heiberger <rmh at temple.edu> wrote:> > somenames <- c("Heigh", "Ho", "Silver", "Away") > > as.formula(paste("~(",paste(somenames, collapse="+"),")^2")) > ~(Heigh + Ho + Silver + Away)^2 > > > > > On Mar 29, 2025, at 14:30, Bert Gunter <bgunter.4567 at gmail.com> wrote: > > > > somenames <- c("Heigh", "Ho", "Silver", "Away") > > >[[alternative HTML version deleted]]