Solved – Specification and interpretation of interaction terms using glm()

generalized linear modelinteractioninterpretationr

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.

  1. 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 interpretation may differ in the two specifications fit1 and fit2. What is the interpretation of each?

  1. 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?

Best Answer

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