Skip to content

Setting base level ignored when interacting categorical variables. #267

Description

@miguelborrero5

High level description

reg ignores contrasts base setting for a particular categorical variable if this variable is interacted with some other regressor.

MWE

df = DataFrame(y = rand(100), x1 = categorical(rand(1:3, 100)), x2 = categorical(rand(1:3, 100)))
# Regression of y ~ x1 using x1 = 2 as base
reg(df, @formula(y ~ x1); contrasts = Dict(:x1 => DummyCoding(base = 2)))
# Regression of y ~ x1&x2 using x1 = 2 as base 
reg(df, @formula(y ~ x1&x2); contrasts = Dict(:x1 => DummyCoding(base = 2)))

The first regression does set x1=2 as the base level, as expected. However, the second regression just sets the interaction of the highest value for each each x1 and x2 as the base level. One could always re-normalize to the desired based level but shouldn't be an easy way to set a base level in the latter case too?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions