【发布时间】:2021-07-05 07:28:51
【问题描述】:
我正在尝试在 R 中做一个线性模型。我有 24 个实验(完整的因子分析)。我在这个模型上有 3 个因素。但是,密度因子有 3 个级别(B、M、A)。我知道不需要出现 DensityB,因为如果 DensityM 和 DensityA 的值为 0,则会间接激活 DensityB。但是在交互中我们需要 DensityB:MatS。因为如果我们有 MatN,我们可以使用 0 激活它。但是会发生这种情况:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.35500 0.06094 5.826 2.03e-05 ***
Thickness2 0.11516 0.04606 2.500 0.02294 *
DensityM -0.05080 0.07978 -0.637 0.53279
DensityA -0.24315 0.07978 -3.048 0.00728 **
MatS 0.22882 0.07978 2.868 0.01066 *
**DensityM:MatS** -0.21393 0.11283 -1.896 0.07509 .
**DensityA:MatS** -0.27452 0.11283 -2.433 0.02631 *
当我不使用这个重新排序因子的水平时,它不会发生:
df$Density = factor(df$Density, levels=c("B", "M", "A"))
当我不使用它时,这些是结果:
(Intercept) 0.11185 0.06094 1.835 0.08399 .
Thickness2 0.11516 0.04606 2.500 0.02294 *
DensityB 0.24315 0.07978 3.048 0.00728 **
DensityM 0.19235 0.07978 2.411 0.02751 *
**DensityA:MatS** -0.04570 0.07978 -0.573 0.57426
**DensityB:MatS** 0.22882 0.07978 2.868 0.01066 *
**DensityM:MatS** 0.01489 0.07978 0.187 0.85412
他们是正确的。
为什么重新排列因子的水平会改变这种交互?我需要重新排序级别,因为我希望 DensistyM 和 DensityA 出现在线性模型中(并且 DensityB 作为较低级别;所以如果 DensityM 和 DensityA 的值为 0,则激活 DensistyB)。
调整后的平方R与线性模型的p值相同。
谢谢!
【问题讨论】:
-
这不是一个真正的编程问题,因此应该在 stackexchange 上。但无论哪种方式,原因与密度缺乏 1 级的原因(正如你提到的)相同。在这种情况下,
MatS的“添加”效果来自MatS的基本级别。 (如果Density的所有其他级别都为零,则这是有效级别)。所以它就在那里。它只是没有“写出来”。
标签: r statistics refactoring linear-regression interaction