# Specification and interpretation of interaction terms using glm()

I am fitting a logistic model to data using the glm function in R. I have attempted to specify interaction terms in two ways:

fit1 <- glm(y ~ x*z, family = "binomial", data = myData)
fit2 <- glm(y ~ x/z, family = "binomial", data = myData)


I have 3 questions:

1) What is the difference between specifying my interaction terms as x*z compared to x/d?

When I call summary(fit1) the report includes results for the intercept, x, z, and x:z while summary(fit2) only includes results for intercept, x, and x:z.

I did look at Section 11.1 in "An Introduction to R" but couldn't understand the meaning.

2) How do I interpret the fit equation mathematically? Specifically, how do I interpret the interaction terms formulaically?

Moving to math instead of R, do I interpret the equation as: logit(y) = (intercept) + (coeff_x)*x + (coeff_z)*x + (coeff_xz)*x*z ?

This interpration may differ in the two specifications fit1 and fit2. What is the interpretation of each?

3) Assuming the above interpretation is correct, how to I fit the model of x*(1/z) in R? Do I need to just create another column with these values?

-
This may be clearer if you give a sample of myData. Do you mean to have x/d in fit2? or x/z –  mnel Oct 30 '12 at 10:42
@mnel I meant to have x/z. I just corrected it. –  user1785104 Oct 30 '12 at 17:03

## migrated from stackoverflow.comOct 31 '12 at 1:13

This question came from our site for professional and enthusiast programmers.

x/z expands to x + x:z and so far I have used this only to model nested random effects.

set.seed(42)
x <- rnorm(100)
z <- rnorm(100)
y <- sample(c(0,1),100,TRUE)

fit2 <- glm(y ~ x/z, family = "binomial")
fit3 <- glm(y ~ x + z %in% x, family = "binomial")
identical(summary(fit2)$coefficients,summary(fit3)$coefficients)
#TRUE
fit4 <- glm(y ~ x + x:z, family = "binomial")
identical(summary(fit2)$coefficients,summary(fit4)$coefficients)
#TRUE

fit5 <- glm(y ~ I(x/z), family = "binomial")
a <- x/z
fit6 <- glm(y ~ a, family = "binomial")
all.equal(summary(fit5)$coefficients,summary(fit6)$coefficients)
#[1] "Attributes: < Component 2: Component 1: 1 string mismatch >"
#which means that only the rownames don't match, but values are identical

-