假设有一些data.frame foo_data_frame,有人想通过其他一些列来查找目标列Y的回归。为此,通常使用一些公式和模型。例如:
linear_model <- lm(Y ~ FACTOR_NAME_1 + FACTOR_NAME_2, foo_data_frame)
如果公式是静态编码的,那很好。如果希望从具有恒定数量因变量(例如2)的多个模型中扎根,可以将其视为:
for (i in seq_len(factor_number)) {
for (j in seq(i + 1, factor_number)) {
linear_model <- lm(Y ~ F1 + F2, list(Y=foo_data_frame$Y,
F1=foo_data_frame[[i]],
F2=foo_data_frame[[j]]))
# linear_model further analyzing...
}
}
我的问题是,当程序运行期间变量数动态变化时,如何产生相同的影响?
for (number_of_factors in seq_len(5)) {
# Then root over subsets with #number_of_factors cardinality.
for (factors_subset in all_subsets_with_fixed_cardinality) {
# Here I want to fit model with factors from factors_subset.
linear_model <- lm(Does R provide smth to write here?)
}
}