Categorische en interactietermen

Generalized Linear Models in Python

Ita Cirovic Donev

Data Science Consultant

Categorische variabelen

  • Eenvoudige binaire variabele
    • Yes, No
  • Nominale variabelen
    • Kleur: red, green, blue
  • Ordinale variabelen
    • Opleidingsniveau: Education1, Education2,...,Education4
Generalized Linear Models in Python

Covariantieanalyse

  • Verklarende variabelen

    • $x_1$: categorisch (binair)
    • $x_2$: continu
  • Logistisch model $$ \text{logit}(y=1|X)=\beta_0 + \beta_1x_1 + \beta_2x_2 $$

Generalized Linear Models in Python

Covariantieanalyse

  • Verklarende variabelen
    • $x_1$: categorisch (binair)
    • $x_2$: continu
  • Logistisch model $$ \text{logit}(y=1|\color{red}{X})=\beta_0 + \beta_1\color{red}{x_1} + \beta_2\color{red}{x_2} $$
Generalized Linear Models in Python

Covariantieanalyse

  • Verklarende variabelen
    • $x_1$: categorisch (binair)
    • $x_2$: continu
  • Logistisch model $$ \text{logit}(y=1|X)=\beta_0 + \beta_1\color{red}{x_1} + \beta_2x_2 $$

  • Als $x_1=0$ dan $$ \text{logit}(y=1|\color{red}{x_1=0},x_2)=\beta_0 + \color{red}{0} + \beta_2x_2 $$

Generalized Linear Models in Python

Covariantieanalyse

  • Verklarende variabelen
    • $x_1$: categorisch (binair)
    • $x_2$: continu
  • Logistisch model $$ \text{logit}(y=1|X)=\beta_0 + \beta_1\color{red}{x_1} + \beta_2x_2 $$

  • Als $x_1=0$ dan $$ \text{logit}(y=1|x_1=0,x_2)=\beta_0 + 0 + \beta_2x_2 $$

  • Als $x_1 = 1$ dan $$ \text{logit}(y=1|\color{red}{x_1=1},x_2)=\beta_0 + \color{red}{\beta_1} + \beta_2x_2 $$ $$ \text{logit}(y=1|\color{red}{x_1=1},x_2)=(\beta_0 + \color{red}{\beta_1}) + \beta_2x_2 $$

Generalized Linear Models in Python

Aannames

Visualisatie zonder interactie met evenwijdige lijnen.

Generalized Linear Models in Python

Aannames

Verschil in intercept zonder interactie gemarkeerd.

Generalized Linear Models in Python

Aannames

Model zonder interactie

Niet-evenwijdige lijnen leiden tot een model met interactietermen.

Generalized Linear Models in Python

Interacties

  • Oneven hellingen $\rightarrow$ interactie aanwezig
  • Het effect van $x_1$ op $y$ hangt af van het niveau van $x_2$ en omgekeerd
  • Logistisch model met interacties $$ \text{logit}(y=1|X)=\beta_0 + \beta_1x_1 + \beta_2x_2 + \color{red}{\beta_3x_1x_2} $$
Generalized Linear Models in Python

Interacties

  • Oneven hellingen $\rightarrow$ interactie aanwezig
  • Het effect van $x_1$ op $y$ hangt af van het niveau van $x_2$ en omgekeerd
  • Logistisch model met interacties $$ \text{logit}(y=1|X)=\beta_0 + \beta_1x_1 + \beta_2x_2 + \beta_3x_1x_2 $$

  • Als $x_1=0$ dan $$ \text{logit}(y=1|\color{red}{x_1=0},x_2)=\beta_0 + \color{red}{0} + \beta_2x_2 + \color{red}{0} $$

Generalized Linear Models in Python

Interacties

  • Oneven hellingen $\rightarrow$ interactie aanwezig
  • Het effect van $x_1$ op $y$ hangt af van het niveau van $x_2$ en omgekeerd
  • Logistisch model met interacties $$ \text{logit}(y=1|X)=\beta_0 + \beta_1x_1 + \beta_2x_2 + \beta_3x_1x_2 $$

  • Als $x_1=0$ dan $$ \text{logit}(y=1|x_1=0,x_2)=\beta_0 + \beta_2x_2 $$

  • Als $x_1 = 1$ dan $$ \text{logit}(y=1|\color{red}{x_1=1},x_2)=\beta_0 + \color{red}{\beta_1} + \beta_2x_2 + \color{red}{\beta_3}x_2 $$ $$ \text{logit}(y=1|\color{red}{x_1=1},x_2)=(\beta_0 + \color{red}{\beta_1}) + (\beta_2 + \color{red}{\beta_3})x_2 $$

Generalized Linear Models in Python

Interacties

  • Oneven hellingen $\rightarrow$ interactie aanwezig
  • Het effect van $x_1$ op $y$ hangt af van het niveau van $x_2$ en omgekeerd
  • Logistisch model met interacties $$ \text{logit}(y=1|X)=\beta_0 + \beta_1x_1 + \beta_2x_2 + \beta_3x_1x_2 $$

  • Als $x_1=0$ dan $$ \text{logit}(y=1|x_1=0,x_2)=\color{red}{\beta_0} + \color{red}{\beta_2}x_2 $$

  • Als $x_1 = 1$ dan $$ \text{logit}(y=1|x_1=1,x_2)=\beta_0 + \beta_1 + \beta_2x_2 + \beta_3x_2 $$ $$ \text{logit}(y=1|x_1=1,x_2)=\color{red}{(\beta_0 + \beta_1)} + \color{red}{(\beta_2 + \beta_3)}x_2 $$

Generalized Linear Models in Python

Interacties visualiseren

Weergave van model met interactieterm (niet-evenwijdige lijnen).

Interacties maken mogelijk:

  • verschillend intercept en helling voor $x_1$
  • $\beta_1$: verschil tussen de twee intercepten
  • $\beta_3$: verschil tussen de twee hellingen
Generalized Linear Models in Python

Interactie­typen

  • binair $\times$ binair
  • binair $\times$ categorisch
  • binair $\times$ continu
  • continu $\times$ categorisch
  • continu $\times$ continu
  • categorisch $\times$ categorisch
  • interacties met >2 variabelen
Generalized Linear Models in Python

Laten we oefenen!

Generalized Linear Models in Python

Preparing Video For Download...