[R] interaction terms in formula of lm or glm
Christos Hatzis
christos at silicoinsights.com
Mon Apr 17 06:18:22 CEST 2006
If you want the quadratic term, you need to pass it as an argument in
function I():
y ~ 1 + V1 + V3 + I(V3^2)
This is documented in ?formula
-Christos
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Luke
Sent: Monday, April 17, 2006 12:08 AM
To: R-help at stat.math.ethz.ch
Subject: [R] interaction terms in formula of lm or glm
I would like to include pairwise interaction terms for lm(). For example, I
want to include the quadratic term of variable "V3".
> my.formula
y ~ 1 + V1 + V3 + V3:V3
> my.data
y V1 V2 V3
1 31 1 42 140
2 32 0 43 120
3 33 0 57 150
4 34 0 55 132
> foo <- lm(my.formula, data = my.data)
> foo$coefficients
(Intercept) V1 V3
29.47368421 -2.15789474 0.02631579
Why do the foo coefficients not include V3:V3 ?
I thought that the variable "V3:V3" has the values of squares of V3
elements, that is,
V3:V3
140*140
120*120
....
Am I wrong?
If I specify a fouth varaible "V4" with square values of V3, and the formula
is y ~ 1 + V1 + V3 + V4, it seems that the foo will give me different in and
out-sample predictions.
-Luke
[[alternative HTML version deleted]]
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list