[英]What is the difference between x^2 and I(x^2) in R?
What is the difference between these two models in R? 这两个模型在R中有什么区别?
model1 <- glm(y~ x + x^2, family=binomial(link=logit), weights=numbers))
model2 <- glm(y~ x + I(x^2),family=binomial(link=logit), weights=numbers))
Also what is the equvalent of I(x^2)
in SAS? SAS中的
I(x^2)
等价是什么?
The I()
function means 'as is' whereas the ^n
(to the power of n) operator means 'include these variables and all interactions up to n way' I()
函数的意思是“原样”,而^n
(以^n
的幂为单位)的意思是“包括这些变量和所有交互,直到n种方式”
This means: 这意味着:
I(X^2)
is literally regressing Y against X squared and I(X^2)
实际上使Y相对于X平方回归
X^2
means include X and the 2 way interaction of X but since it is only one variable there is no interaction so it returns only itself ie X. Note that in your formula you say X + X^2
which translates to X + X
which in the formula syntax is only taken into account once. X^2
表示包括X和X的双向交互作用,但由于它只是一个变量,因此没有交互作用,因此它仅返回自身,即X。请注意,在公式中您说X + X^2
转换为X + X
在公式语法中只考虑一次。 Ie one of the two Xs will be removed. 即两个X之一将被删除。
Demonstration: 示范:
Y <- runif(100)
X2 <- runif(100)
df <- data.frame(Y,X1,X2)
b <- lm( Y ~ X2 + X2^2 + X2,data=df)
> b
Call:
lm(formula = Y ~ X2 + X2^2 + X2, data = df)
Coefficients:
(Intercept) X2
0.48470 0.05098
a <- lm( Y ~ X2 + I(X2^2),data=df)
> a
Call:
lm(formula = Y ~ X2 + I(X2^2), data = df)
Coefficients:
(Intercept) X2 I(X2^2)
0.47545 0.11339 -0.06682
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.