R 公式中的星号 (*) 与冒号 (:)
Asterisk (*) vs. colon (:) in R formulas
在R公式中添加交互项时,我一直认为*
和:
是同一个意思。例如:
amount_of_gas ~ temperature*gas_type
amount_of_gas ~ temperature:gas_type
但是,既然我已经开始使用广义线性模型(glm()
在 R 中),当我在两者之间切换时,我发现它们会产生不同的分数、不同的估计等。有人可以向我解释为什么会这样吗? R中的stats
包有问题吗?
##更新##
2021 年 4 月 26 日
自从我问这个问题以来已经有 4.5 年左右的时间了,我不断收到通知说它仍然有很多流量。
这是简短的答案:y~x*z 基本上意味着:y~x+z+x:z 而 y~x:z 只是 x 和 z 的相互作用(如下面的答案所述)
来自help(formula)
:
In addition to ‘+’ and ‘:’, a number of other operators are useful
in model formulae. The ‘*’ operator denotes factor crossing:
‘a*b’ interpreted as ‘a+b+a:b’.
在R公式中添加交互项时,我一直认为*
和:
是同一个意思。例如:
amount_of_gas ~ temperature*gas_type
amount_of_gas ~ temperature:gas_type
但是,既然我已经开始使用广义线性模型(glm()
在 R 中),当我在两者之间切换时,我发现它们会产生不同的分数、不同的估计等。有人可以向我解释为什么会这样吗? R中的stats
包有问题吗?
##更新## 2021 年 4 月 26 日
自从我问这个问题以来已经有 4.5 年左右的时间了,我不断收到通知说它仍然有很多流量。 这是简短的答案:y~x*z 基本上意味着:y~x+z+x:z 而 y~x:z 只是 x 和 z 的相互作用(如下面的答案所述)
来自help(formula)
:
In addition to ‘+’ and ‘:’, a number of other operators are useful
in model formulae. The ‘*’ operator denotes factor crossing:
‘a*b’ interpreted as ‘a+b+a:b’.