我有三个数字变量A
, B
和C
。我正在尝试创建一个线性模型,能够预测A
。我使用的表达式是B*C
的乘积,以预测A
; 然而,当查看输出时,我无法得到我的方程,因为我得到了一个多余的变量,我不知道它是什么。
以下是我的代码:
MyData<-read.csv("...", header = T)
head(MyData,6)
str(MyData)
#Linear Model
#Expersion A= B*C
Model1<-lm(MyData$A~MyData$B*MyData$C)
summary(Model1)
str(MyData)
的输出结果
> str(MyData)
'data.frame': 6 obs. of 3 variables:
$ A: num 2.5 3.4 2.7 3.6 2.5 2.1
$ B: num 0.01 0.02 0.015 0.017 0.018 0.01
$ C: num 0.1 0.2 0.27 0.19 0.17 0.16
< p > summary(Model1)
的输出结果
Call:
lm(formula = MyData$A ~ MyData$B * MyData$C)
Residuals:
1 2 3 4 5 6
-0.03945 -0.08386 -0.13925 0.67703 -0.40055 -0.01393
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.473 5.774 0.948 0.443
MyData$B -222.431 454.508 -0.489 0.673
MyData$C -26.482 36.222 -0.731 0.541
MyData$B:MyData$C 1938.961 2679.207 0.724 0.544
Residual standard error: 0.5688 on 2 degrees of freedom
Multiple R-squared: 0.6149, Adjusted R-squared: 0.03723
F-statistic: 1.064 on 3 and 2 DF, p-value: 0.5178
lm
使用Wilkinson-Rogers符号,因此"*"
表示迭代,是根据输出结果进行的,对吗? 如果是这样,我该如何使用我的两个变量的乘积创建模型?
lm(y〜x1 * x2)
与lm(y〜x1 + x2 + x1:x2)
是相同的。请注意,冒号在公式语法中表示“乘积”。如果您只想要交互作用,请仅使用冒号:lm(y〜x1:x2)
。 - DanYMyData$B:MyData$C
。因此,如果我将Model1
公式替换为Model1<-lm(MyData$A~B:C)
,实际的线性方程应该是A=EstimateB:C*(B*C) + Intercept
,对吗? - Perro