vars<-c('a','b','c','d')
library(gregmisc)
indexes<-unique(apply(combinations(length(vars), length(vars), repeats=T), 1, unique))
gen.form<-function(x) as.formula(paste('~',paste( vars[x],collapse='+')))
formulas<-lapply(indexes, gen.form)
formulas
Генерирует:
R> формулы
[[1]] ~ a
[[2]] ~ a + b
[[3]] ~ a + c
[[4]] ~ a + d
[[5]] ~ a + b + c
[[6]] ~ a + b + d
[[7]] ~ a + c + d
[[8]] ~ a + b + c + d
[[9]] ~ b
[[10]] ~ b + c
[[11]] ~ b + d
[[12]] ~ b + c + d
[[13]] ~ c
[[14]] ~ c + d
[[15]] ~ d