Search code examples
rregressionmixed-modelsinteractiondummy-variable

How to extract beta coefficients for interaction effect in R?


I am examining the interaction between a continuous variable (bloodq) and a categorical variable with three levels (ER, RB, and WB). In order to see how the betas differ across tissue types, I would like to know the tissue-specific betas for all three tissue types. Output only shows betas for WB and RB, since ER is set as referent group. How could I extract beta for RB as well?


Solution

  • Not sure I have totally understood your question, what I understood is that you are wondering why there is no "Bloodq*ER" interaction coefficient.

    You give the answer in your question: ER is the reference level, and adding such an interaction term in the model would raise exact collinearity issues, as: Bloodq == Bloodq*ER + Bloodq*RB + Bloodq*WB (where ER == 1 if Tissue == "ER", 0 otherwise etc.)

    Thus, removing Bloodq from your model should make the Bloodq*ER coefficient appear.

    For instance, try this:

    n <- 100
    df <- data.frame(s1 = runif(n), s2 = sample(factor(c("A", "B")), n, replace = TRUE), y = runif(n))
    lm(y ~ s1 + s1:s2, data = df)
    lm(y ~ s1:s2, data = df)
    

    You can see that the first model has only the s1:s2B interaction while the second one has s1:s2A and s1:s2B.