【发布时间】:2026-02-18 09:05:01
【问题描述】:
线性模型的摘要使用某些字符串来表示其输出中的系数,例如:
summary(lm(
target ~ some.bool + some.factor + some.factor*some.value +
some.factor:some.other,
data.frame(target=rnorm(100), some.bool=sample(c(T, F), 100, T),
some.factor=sample(c('Y', 'N', 'M'), 100, T), some.value=rnorm(100),
some.other=rnorm(100))))
生成一个带有名称的表:
some.boolTRUE,
some.factorN,
some.factorY,
some.value,
some.factorN:some.value,
some.factorY:some.value,
some.factorM:some.other,
some.factorN:some.other,
some.factorY:some.other.
如何以编程方式找出表格的哪些行对应于输入公式的哪些项?我想获得一些映射,例如:
`some.boolTRUE` → some.bool
`some.factorN`: → some.factor, some.factor*some.value
`some.factorY`: → some.factor, some.factor*some.value
`some.value`: → some.factor*some.value
`some.factorN:some.value`: → some.factor*some.value
`some.factorN:some.other`: → some.factor:some.other
我的目标是为结果准备一种特定的表示形式,其中线性回归的数据按输入项分组。
【问题讨论】:
-
也许您需要查阅统计文本。 FWIW,
x*y是x + y + x:y的简写。 -
@RomanLuštrik:我知道。我只想将行与用户输入的术语匹配,无论用户输入什么,以编程方式。
-
您能否详细说明一下输入和预期输出到底是什么以及为什么需要它?
-
@Roland:谢谢你的建议,我添加了一个例子和我的目标。